akhauriyash/Code-Regression huggingface dataset:
from scipy.misc import comb

N = int(input())
A = list(map(int,input().split()))

dic = dict()
memo = [-1] * (N+1)
ans_vec = [-1] * (N+1) 

for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1

provisional = 0
for d in dic.values():
    if d >= 2:
        memo[d] = comb(d,2,exact=True)  
        memo[d-1] = comb(d-1,2,exact=True)   
        provisional += memo[d] 

for a in A:
    ans = 0
    t = dic[a]
    if ans_vec[t] != -1:
        print(ans_vec[t])
    else:
        if t < 2:
            print(provisional)
        else:
            ans = provisional - memo[t] 
            if t-1 >= 2:
                ans += memo[t-1]
            ans_vec[t] = ans
            print(ans)



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

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 FOR(i,m,n) for (int i = m; i < n; ++i)
#define ANS(b) if (b) cout << "First"; else cout << "Second"; cout << endl;
const int MAX = 1e5+10;
int N, K;
bool dp[MAX];
int A[111];

int main () {
  cin >> N >> K;
  dp[0] = false;
  REP (i, N) cin >> A[i];
  REP (i, K+1) if(!dp[i]){
    REP (j, N) {
      if (i + A[j] < MAX) {
        dp[i+A[j]] = true;
      }
      else break;
    }
  }
  ANS(dp[K]);
}

Measured memory_bytes: 384
import collections

def calc():
  n=int(input())
  table=[i for i in range(n+1)]
  for i in range(2,n+1):
    if table[i]<i:
      continue
    for j in range(i,n+1,i):
      table[j]=i
  ans=0
  for i in range(1,n+1):
    cnt={}
    ret=i
    while i!=1:
      prime=table[i]
      if prime in cnt:
        cnt[prime]+=1
      else:
        cnt[prime]=1
      i//=prime
    for val in cnt.values():
      ret*=val+1
    ans+=ret
  print(ans)
calc()

Measured memory_bytes: 225696
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        string h;
        forr(i,0,s.size()/2) {h=h+"hi";}
        cout << (s == h ? "Yes" : "No") << endl;       
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int P, Q, R; char C;

	while (true)
	{
		R = 0;

		for (int i = 0; i < 5; i++)
		{
			cin >> P >> Q;

			if (P == 0 && Q == 0) { return 0; }

			if (R < P + Q)
			{
				R = P + Q; C = i + 65;
			}
		}

		cout << C << ' ' << R << endl;
	}
}

Measured memory_bytes: 3056
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
string s[3] = {"hon", "pon", "bon"};
int a[10] = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string in;
  cin >> in;
  cout << s[a[(in.back() - '0')]] << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    cout << (h2*60+m2-k) - (h1*60+m1)  << endl;
}

Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        ans += h >= k;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cards = [list(map(int, input().split())) for i in range(M)]
cards = sorted(cards, key=lambda x: x[1], reverse=True)

cnt = 0
for card in cards:
    A += [card[1]]*card[0]
    cnt += card[0]
    if cnt >= N:
        break
A.sort(reverse=True)
print(sum(A[:N]))


Measured memory_bytes: 91416
n = gets.chop.to_i

a = []

n.times do
  u, k, *v = gets.chop.split.map(&:to_i)
  a << Array.new(n) { |i| (v.include?(i + 1)) ? 1 : 0 }
end

0.upto(n - 1) do |i|
  puts a[i].join(' ')
end

Measured memory_bytes: 6152
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    string s;
    cin>>s;

    if(s == "Sunny") {
        cout<<"Cloudy"<<endl;
    } else if(s == "Cloudy") {
        cout<<"Rainy"<<endl;
    } else {
        cout<<"Sunny"<<endl;
    }

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    string s1,s2,s3;
    cin>>s1>>s2;
    s3 = "";
    int k = s2.size();
  loop(i,0,k-1)
  {
      s3+=s2[i];
  }
  if(s3==s1)
    cout<<"Yes\n";
  else
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2) {
      cout << "Odd" << '\n';
    } else {
      cout  << "Even" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import numpy as np
import itertools as iters

n, m , x = list(map(int, input().split()))
c = np.empty((n, 1))
a = np.empty((n, m))

for i in range(n):
  ca = list(map(int, input().split()))
  c[i] = ca[0]
  for idx in range(m):
    a[i][idx] = ca[idx+1]

max_score = sum(a)

if 1 in (max_score < x):
  print(-1)
  exit()

min_price = 10 ** 10

for i in range(n):
  pairs = iters.combinations(range(n), i+1)
  for pair in pairs:
    price = 0
    check = np.zeros((1, m))
    for idx in pair:
      price += c[idx]
      check += a[idx]
    if 1 not in (check < x):
      if price < min_price:
        min_price = price

print(int(min_price))

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

int main(){
  int n,m,i,j,sum;
  cin >> n >> m;
  int a[n][m];
  int b[m];

  for(i=0;i<n;i++){
    
    for (j=0;j<m;j++){
      
      cin >> a[i][j];
    }
  }
  for(j=0;j<m;j++){
    cin >> b[j];
  }
  
  for (i=0;i<n;i++){
    for(j=0;j<m;j++){
      sum+=a[i][j]*b[j];
    }
    cout << sum <<endl;
    sum=0;
  }
}


Measured memory_bytes: 3108
n=int(input())
t=[int(a)*2 for a in input().split()]
v=[int(a)*2 for a in input().split()]
ma=[0]*(sum(t)+1)
a=0
for i in range(n):
  for j in range(t[i]):
    a+=1
    ma[a]=min(ma[a-1]+1,v[i])
ma[a]=0
for i in range(n)[::-1]:
  for j in range(t[i]):
    a-=1
    ma[a]=min(ma[a],ma[a+1]+1,v[i])
print((sum(ma[1:])+sum(ma[:-1]))/8)


Measured memory_bytes: 68552
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int digit = 0;
  int M = N;
  while (M != 0){
    M /= 10;
    digit++;
  }
  int ans = 0;
  if (digit % 2 == 0) {
    for (int i = 0; i < digit; i++) {
      if (i % 2 == 0) {
        ans += 9 * pow(10, i);
      }
    }
  }
  else {
    int nine = 0;
    for (int i = 0; i < digit - 1; i++) {
      if (i % 2 == 0) {
        nine += 9 * pow(10, i);
      }
    }
    ans =  nine + (N - (pow(10, digit - 1) -1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------
signed main() {
	int n;
	cin >> n;
	vector<H>a;
	for (int i = 0; i < n; i++)a.push_back(H{ read(),i + 1 });
	sort(all(a));
	cout << a[0].sc << endl;
}


Measured memory_bytes: 4996
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

alias sread = () => readln.chomp();

void main()
{
    string s = sread();
    if (s.length == 3)
    {
        writeln(s[2],s[1],s[0]);
        return;
    }
    s.writeln();
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

//
#define MN 10010
struct edge{int to,rev;ll cap,cost;
edge(int to,ll cap,ll cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}};
vector<edge> g[MN];
int V_mcf,prevv[MN],preve[MN];
ll h[MN],dist[MN];

void init(int V){
	V_mcf=V;
	rep(i,V)g[i].clear();
}

void add_edge(int from,int to,ll cap,ll cost){
	g[from].pb(edge(to,cap,cost,sz(g[to])));
	g[to].pb(edge(from,0,-cost,sz(g[from])-1));
};

ll min_cost_flow_any(int s,int t){
	ll res=0;
	fill(h,h+V_mcf,0);
	while(1){
		fill(dist,dist+V_mcf,INF);
		dist[s]=0;
		while(1){
			bool update=0;
			rep(i,V_mcf)rep(j,sz(g[i])){
				edge& e=g[i][j];
				if(e.cap>0 && dist[e.to]>dist[i]+e.cost+h[i]-h[e.to]){
					dist[e.to]=dist[i]+e.cost+h[i]-h[e.to];
					prevv[e.to]=i;
					preve[e.to]=j;
					update=1;
				}
			}
			if(!update)break;
		}
		
		if(dist[t]==INF)return res;
		rep(v,V_mcf)h[v]+=dist[v];
		if(h[t]>=0)break;
		ll d=INF;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,g[prevv[v]][preve[v]].cap);
		}
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge& e=g[prevv[v]][preve[v]];
			e.cap-=d;
			g[v][e.rev].cap+=d;
		}
	}
	return res;
}
//

int N,A[1010],B[1010];
set<int> S;
int id[1000010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N;
	rep(i,N){
		cin>>A[i]>>B[i];
		S.insert(A[i]);
		S.insert(B[i]);
	}
	int cur=N;
	foreach(it,S){
		id[*it]=cur++;
	}
	int s=cur,t=s+1;
	init(t+1);
	rep(i,N){
		add_edge(s,i,1,0);
		add_edge(i,id[A[i]],1,-B[i]);
		if(B[i]!=A[i])add_edge(i,id[B[i]],1,-A[i]);
	}
	rep2(i,N,s)add_edge(i,t,1,0);
	cout<<-min_cost_flow_any(s,t)<<endl;
}

Measured memory_bytes: 5736
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("AC\n"); else printf("WA\n");}

int Capitaljudge(char c){
    return ((int)c>=(int)'A' && (int)c<=(int)'Z');
}

int main(){
    char S[11];
    scanf("%s", S);
    int judge = 1;
    int C = 0;
    int l = strlen(S);
    for(int i=0; i<l; i++){
        if(i==0){
            if(S[i]!='A') {judge = 0; break;}
        }
        else if(i==1 || i==l-1){
            if(Capitaljudge(S[i])) {judge = 0; break;}
        }
        else{
            if(Capitaljudge(S[i])){
                if(S[i]=='C'){
                    C++;
                    if(C>1) {judge = 0; break;}
                }
                else {judge = 0; break;}
            }
        }
    }
    if(C!=1) judge = 0;
    printjudge(judge);
    return 0;
}

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

int main(void){
    string a, b;
    cin >> a >> b;
    string ans;
    ans = a+b;
    int check=0;
    int keisuu = 1;
    for(int i = ans.length()-1; i >= 0; i--){
        check += (ans[i]-48)*keisuu;
        keisuu*=10;
    }
    
   for(int i = 0; i <= 500; i++)
       if(check == i*i)
            check = 1;

    if(check==1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
            
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,m,l[10000],i,x,p,a;
	while(1){
		scanf("%d%d",&n,&m);
		p=0;
		a=0;
		if(n==0&&m==0){
			break;
		}

		for(i=0;i<1024;i++){
			l[i]=0;
		}


		for(i=0;i<n;i++){
			scanf("%d",&l[i]);
		}
		for(i=0;i<m;i++){
			scanf("%d",&x);
			p+=x+l[p+x];
			if(p>=n-1&&a==0){
				a=i+1;
			}
		}
		printf("%d\n",a);
	}
    return 0;
}

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

struct Edge {
  int from, to, cost;
};
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<Edge> es, es_rev;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;b--;
    es.push_back(Edge{a, b, c});
    es_rev.push_back(Edge{a, b, -c});
  }

  vector<long long> dist(n, 1e18);
  dist[0] = 0;
  for (int i = 0; i < 2*n; i++) {
    for (int j = 0; j < m; j++) {
      Edge& e = es_rev[j];
      int from = e.from, to = e.to;
      int cost = e.cost;
      if (dist[to] > dist[from] + e.cost) {
        dist[to] = dist[from] + e.cost;
        if (i >= n-1 && e.to == n-1) {
          cout << "inf" << endl;
          return 0;
        }
      }
    }
  }
  cout << -dist[n-1] << endl;
  return 0;
}

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

int main()
{
	
	int a,b,c ;
	
	cin >> a >> b >> c ;
	
	if( a+b >= c )
	{
		cout << "Yes" << endl ;
		//cout << "He has "<< a << " + " << b << " = " << a+b << " yen, so he can buy the " << c << "-yen toy." ;
	}
	else
	{
		cout << "No" << endl ;
		//cout << "He has "<< a << " + " << b << " = " << a+b << " yen, but he cannot buy the " << c << "-yen toy." ;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int N;
vector<pair<int,int>> T;

double dis(int i, int j){
    int dx = T[i].fi - T[j].fi;
    int dy = T[i].se - T[j].se;
    return pow(dx * dx + dy * dy, 0.5);
}

int main(){
    cin >> N;
    T.resize(N);
    for(int i = 0; i < N; i++) cin >> T[i].fi >> T[i].se;
    double sum = 0.0;
    vector<int> A(N);
    iota(all(A),0);
    do{
        for(int i = 0; i < N - 1; i++){
            sum += dis(A[i], A[i + 1]);
        }
    }while(next_permutation(all(A)));

    int f = 1;
    for(int i = 2; i <= N; i++) f *= i;
    cout << sum / f << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){

  while (u != NIL && u->key != k) {
    if (k < u->key)
    u = u->left;
    else
    u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while (x != NIL) {
          y = x;
          if (z->key < x->key)
              x = x->left;
          else
              x = x->right;
      }

  z->parent = y;

  if (y == NIL) {
          root = z;
  }else {
    if (z->key < y->key)
      y->left = z;
    else
      y->right = z;
  }
}

void inorder(Node u){
  if (u == NIL)
      return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if (u == NIL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20484
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string S;
int N, K, res;
int main(int argc, char **argv) {
    cin >> S;
    if((S[0] == S[1] && S[2] == S[3] || S[0] == S[2] && S[1] == S[3] || S[0] == S[3] && S[1] == S[2]) && 
        !(S[0] == S[1] && S[1] == S[2] && S[2] == S[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
}

Measured memory_bytes: 256
N,K = map(int,input().split())

if K%2 == 0:
	count1 = N//K
	count2 = (N+N%K)//K
	ans = count1 ** 3 + count2 ** 3 

if K%2 == 1:
	count3 = N//K
	ans = count3 ** 3

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(201,0);
    
    int ans = 0;
    for(int i = 105;i <= n;i += 2){
          for(int j = 1; j <= n;j+= 2){
                if(i % j == 0)a[i]++;
          }
    }
    for(int i = 0;i <= n;i++){
          if(a[i] == 8) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.00)

int main()
{
     int n,m;
     cin>>n>>m;
     int a[m];
     int sum=0;
     for(int i=0;i<m;++i)
     {
         cin>>a[i];
         sum+=a[i];
     }
     (n-sum<0)?cout<<-1<<endl:cout<<(n-sum)<<endl;
     return 0;
}


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

int main(){

	long long n,a,b;
	cin>>n>>a>>b;
	if(n%(a+b)>a){
		cout<<a*(n/(a+b))+a;
	}	
	else{
		cout<<( a*(n/(a+b)) + n%(a+b) );
	}
	cout<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define F first
#define S second
#define int long long

const int maxn = 310;
const int mod = 998244353;
const ll inf = 1e18;

ll pw(ll a, ll b)
{
    if(b == 0) return 1;
    ll k = pw(a,b/2); k = (k * k) % mod;
    if(b&1) k = (k * a) % mod;
    return k;
}

int dp[maxn][maxn][maxn], n, K;

signed main()
{
   // ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    string ss; cin>> ss >> K; n = ss.size();
    string s = "."; s += ss;

    for(int t = 1; t <= n; t++)
        for(int l = 1; l <= n-t+1; l++)
            for(int k = 0; k <= K; k++)
            {
                int r = l+t-1;

                if(t == 1)
                {
                    dp[l][r][k] = 1;
                    continue;
                }

                if(s[l] == s[r])
                    dp[l][r][k] = dp[l+1][r-1][k] + 2;
                else
                {
                    dp[l][r][k] = max(dp[l+1][r][k], dp[l][r-1][k]);
                    if(k)
                        dp[l][r][k] = max(dp[l][r][k], dp[l+1][r-1][k-1] + 2);
                }
            }
    cout<< dp[1][n][K];
}






Measured memory_bytes: 226816
import java.io.*;
import java.util.*;

public class Main {


	public static void solver() {
	
		int a = cin.nextInt();
		int b = cin.nextInt();
		
		cout.printf("%d %d\n", a*b, 2*(a+b));

	}	
	
	public static void main(String[] args) throws IOException {

		cin = new Scanner(System.in);
		Main.solver();
	}
		
	static Scanner     cin;
	static PrintStream cout = System.out;//標準出力
	
}

Measured memory_bytes: 17332
#include <iostream>
#include <cmath>
using namespace std;

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

	int h = S / (60 * 60);
	int m = (S % (60 * 60)) / 60;
	int s = S % 60;

	cout << h << ":" << m << ":" << s << endl;

	return 0;
}


Measured memory_bytes: 3084
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x));
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 18, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
ll n,ans[100005][3],arr[100005][3];
int main()
{
	MuhammedAly
	cin >> n;
	for(int i =0;i<n;i++)
		for(int j =0;j<3;cin >> arr[i][j++]);
	for(int i =0;i<3;i++)
		ans[0][i] = arr[0][i];
	for(int i =1;i<n;i++)
	{
		for(int j = 0;j<3;j++)
		{
			ans[i][j] = arr[i][j];
			for(int k =0;k<3;k++)
			{
				if(k == j)
					continue;
				ans[i][j] = max(ans[i][j],ans[i-1][k]+arr[i][j]);
			}
		}
	}
	ll high = 0;
	for(int i =0;i<3;i++)
		high = max(ans[n-1][i],high);
	cout << high;
	return 0;
}


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

int main(){
  int a, b, c, count, i;
  cin >> a >> b >> c;
  count = 0;
  
  for( i = a; i <= b; i++)
  {
    if(c % i == 0){
      count += 1;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3124
let asReversedString s =
  String.of_seq (List.to_seq (List.rev (List.of_seq (String.to_seq s))))

let isPrefix prefixString targetString =
  let prefixLength = String.length prefixString in
  let targetLength = String.length targetString in
  if prefixLength <= targetLength
  then
    let targetSub = String.sub targetString 0 prefixLength in
    prefixString = targetSub
  else
    false

let removePrefix prefixString targetString =
  let prefixLength = String.length prefixString in
  let targetLength = String.length targetString in
  let newTargetStart = prefixLength in 
  let newTargetLength = targetLength - prefixLength in
  String.sub targetString newTargetStart newTargetLength

let satisfy inS =
  let reversed = asReversedString inS in
  let word1 = asReversedString "dream" in
  let word2 = asReversedString "dreamer" in
  let word3 = asReversedString "erase" in
  let word4 = asReversedString "eraser" in
  let rec satisfy_aux s =
    if s = "" then true else
      if isPrefix word1 s then satisfy_aux (removePrefix word1 s) else
        if isPrefix word2 s then satisfy_aux (removePrefix word2 s) else
          if isPrefix word3 s then satisfy_aux (removePrefix word3 s) else
            if isPrefix word4 s then satisfy_aux (removePrefix word4 s) else
              false in
  satisfy_aux reversed
    

let main () =
  let s = read_line () in
  let ans = if satisfy s
            then "YES"
            else "NO" in
  (
    Printf.printf "%s" ans;
    print_newline ()
  )

let _ = main ()


Measured memory_bytes: 21348
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)

for i in range(m):
    max=heapq.heappop(a)
    heapq.heappush(a,(max*(-1)//2)*(-1))

print(sum(a)*(-1))


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

const long long INF = 1LL << 60;

int main() {
    int N, cnt = 0; cin >> N;
    vector<char> s(N);
    for (int i = 0; i < N; i++) cin >> s.at(i);
    map<char, bool> right;
    vector<int> bucket(200, 0);
    for (int i = 0; i < N; i++) {
        bucket.at(s.at(i))++;
        if (!right.count(s.at(i))) {
            right[s.at(i)] = true;
            cnt++;
        }
    }

    int ans = 0, cnt2 = 0;
    map<char, bool> left;
    for (int i = 0; i < N; i++) {
        if (bucket.at(s.at(i)) == 1) {
            cnt--; cnt2--;
        } else bucket.at(s.at(i))--;
        if (!left.count(s.at(i))) {
            left[s.at(i)] = true;
            cnt2++;
        }
        ans = max(ans, min(cnt, cnt2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ld area=(w*h);
    area/=2;
    ll f=1;
    if(x!=(w/2)||(w%2==1))
        f=0;
    if(y!=(h/2)||(h%2==1))
        f=0;
    cout<<fixed<<stp<<area<<' '<<f<<endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x[] = new int[n];
        int y[] = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        HashMap<String, Integer> s = new HashMap<String, Integer>();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    int x1 = (x[i] - x[j]);
                    int y1 = (y[i] - y[j]);
                    String input = String.valueOf(x1) + "-" + String.valueOf(y1);
                    if (s.containsKey(input)) {
                        s.put(input, s.get(input) + 1);
                    } else {
                        s.put(input, 1);
                    }
                }
            }
        }
        int max = 0;
        for (Integer val : s.values()) {
            if (max < val) {
                max = val;
            }
        }

        System.out.println(n - max);
    }
}

Measured memory_bytes: 25556
#include<iostream>
#include<string.h>

using namespace std;

int main(){
  string word;
  cin >> word;
  string def_word="";
  for(int i=0;i<word.length();++i){
  	char c = word[i];
    if(c=='B'){
    	if(def_word.length()>0) def_word.pop_back();
    }
    else{
      def_word+=c;
    }
  }
  cout << def_word << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n, k; // n是总个数，k是选择的商品数
    cin>>n>>k;
    vector<int> t;
    for(int i = 0; i < n; i++){
        int tmp;
        cin>>tmp;
        t.push_back(tmp);
    }
    sort(t.begin(),t.end());
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += t[i];
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3144
N,K = map(int,input().split())
if K % 2 != 0:
    case1 = len([n for n in range(1,N+1) if n % K ==0])
    print(case1 ** 3)
else:
    case1 = len([n for n in range(1,N+1) if n % K ==0])
    case2 = len([n for n in range(1,N+1) if n % K == K //2])
    print(case1**3 + case2**3)

Measured memory_bytes: 53104
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
enum MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    BigInt ans = 1;
    A.sort();
    foreach (a; A)
    {
        ans *= a;
        if (BigInt(10L ^^ 18) < ans)
        {
            writeln(-1);
            return;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 9020
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
int main()
{
    ll a , b , k  ,ans ;
    cin>>a>>b>>k ;
    a -= k ;
    if (a<0){
        b += a ;
        a=0 ;
    }
    if (b<0)
        b=0 ;
    cout<<a<<" "<<b ;
}




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

int main(void) {
    int n, a, b;
    cin >> n >> a >> b;

    int result = 0;
    for (int i = 1; i <= n; i++) {
        int sum = 0, tmp = i;
        for (;;) {
            sum += tmp % 10;
            tmp /= 10;
            if (tmp == 0) {
                break;
            }
        }
        if ((a <= sum) && (sum <= b)) {
            result += i;
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn main() {
    let n = read::<usize>();
    let mut graph = graph_new(n);
    let mut e = 0;
    for i in 0..n - 1 {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        add_bi_edge(&mut graph, &mut e, a, b, 1);
    }
    let mut cnts = vec![1, 1];
    let mut que = VecDeque::<(usize, usize)>::new();
    let mut visit = vec![false; n];
    que.push_back((0, 0));
    que.push_back((n - 1, 1));
    visit[0] = true;
    visit[n - 1] = true;
    while let Some((from, player)) = que.pop_front() {
        for edge in graph[from].iter() {
            if visit[edge.dest] {
                continue;
            }
            visit[edge.dest] = true;
            que.push_back((edge.dest, player));
            cnts[player] += 1;
        }
    }
    println!("{}", if cnts[0] > cnts[1] { "Fennec" } else { "Snuke" });
}


Measured memory_bytes: 22780
buf = list(map(int, input().split()))
A=buf[0]
V=buf[1]
buf2 = list(map(int, input().split()))
B=buf2[0]
W=buf2[1]
T= int(input())

if A>B:
  if B-W*T<A-V*T:
    print("NO")
  else:
    print("YES")
else:
  if B+W*T>A+V*T:
    print("NO")
  else:
    print("YES")  

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}

const char EOL = '\n';
const int MOD = 1000000007;
const int INF = 1000000001;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    FORR(i, m / n, 1) {
        int x = m - (n - 1) * i;
        if (x > 0 && x % i == 0) {
            cout << i << endl;
            return;
        }
    }
}

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

int main(){
    long long n,x=1;
    cin>>n;
    for(int i=1;i<=n;i++){
        x=x*i;
    }
    cout<<x<<endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int x = 2 * A - 1;
  int y = 2 * B - 1;
  int z = A + B;
  cout << max(max(x, y), z) << endl;
}


Measured memory_bytes: 256
function main(input = "") {
    const lines = input.split("\n");
    const header = lines[0].split(" ").map((v) => (Number(v)));
    const H = header[0], W = header[1], M = header[2];

    let arrH = new Int32Array(H);
    let arrW = new Int32Array(W);
    let grid = new Set();
    for (let i = 0; i < M; i++) {
        let arr = lines[i + 1].split(" ");
        let h = arr[0] - 1, w = arr[1] - 1;
        arrH[h]++;
        arrW[w]++;
        grid.add(h * W + w);
    }

    let maxH = arrH[0];
    let idsH = [0];
    for (let i = 0; i < H; i++) {
        let v = arrH[i];
        if (maxH < v) {
            maxH = v;
            idsH = [i]
        } else if (maxH === v) {
            idsH.push(i);
        }
    }

    let maxW = arrW[0];
    let idsW = [0];
    for (let i = 0; i < W; i++) {
        let v = arrW[i];
        if (maxW < v) {
            maxW = v;
            idsW = [i]
        } else if (maxW === v) {
            idsW.push(i);
        }
    }

    for (let h = 0; h < idsH.length; h++) {
        let idh = idsH[h];
        for (let w = 0; w < idsW.length; w++) {
            let idw = idsW[w];
            if (!grid.has(idh * W + idw)) {
                return maxH + maxW;
            }
        }
    }

    return maxH + maxW - 1;
}

//******************************
exports.main = main;

function Main(input) {
    console.log(main(input.trim()));
}

if (process.argv[2] !== "test") {
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}

Measured memory_bytes: 125340
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int k = in.nextInt();
            int n = Math.max(a, b);
            for (; k > 0; n--) {
                if (a % n == 0 && b % n == 0)
                    k--;
            }
            out.println(n + 1);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define boost ios_base::sync_with_stdio(0)
#define boost1 cin.tie(0)
#define boost2 cout.tie(0)
#define PI acos(-1.0)


int main()
{
    boost;boost1;boost2;

    ///freopen("testcase.txt","r",stdin);


    ll r;
    cin>>r;



    cout<<r*r<<endl;

    return 0;





}


Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut vs = vec![0; n+1];
    for i in 1 .. n+1 {
        vs[i] = get!();
    }
    let mut bs = vec![0; n+1];
    for i in 0 .. n {
    	let i = n - i;
        let mut j = i;
        let mut sum = 0;
        while j <= n {
            sum += bs[j];
            j += i;
        }
        if sum % 2 != vs[i] {
            bs[i] = 1;
        }
    }
    let mut ans = vec![];
    for i in 0 .. bs.len() {
        if bs[i] > 0 {
            ans.push(i);
        }
    }
	println!("{}", ans.len());
    if ans.len() == 0 {
        return;
    }
    for i in 0 .. ans.len() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}

Measured memory_bytes: 10876
#include <bits/stdc++.h>
#define cinf(n,x,y,z) for(int i=0;i<(n);i++) cin >> x[i]>>y[i]>>z[i];
typedef long long int ll;
using namespace std;

int main(){
	int n; cin >>n;
	vector<int> x(n),y(n),h(n);
	cinf(n,x,y,h);
	int sample=-1;
	for(int i=0;i<n;i++){
		if(h[i]>0){
			sample=i;
		}
	}
	ll ansx,ansy,ansh;
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			ll H=h[sample]+abs(i-x[sample])+abs(j-y[sample]);

			bool check=true;
			for(int k=0;k<n;k++){
				if(h[k]>0&&H-h[k]!=abs(i-x[k])+abs(j-y[k]))
					check=false;
				if(h[k]==0&&H>abs(i-x[k])+abs(j-y[k]))
					check=false;
			}
			if(check)ansx=i,ansy=j,ansh=H;
		}
	}
	cout << ansx << " "<< ansy << " "<< ansh<< endl;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include<cstdio>
#include<iostream>
#include <algorithm>
using namespace std;

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

int n;
int imos[86400];

void solve() {
	rep(i, n) {
		int s[3];
		int t[3];

		scanf("%d : %d : %d", &s[0], &s[1], &s[2]);
		scanf("%d : %d : %d", &t[0], &t[1], &t[2]);

		//hh:mm:ss を秒に変換
		int S = s[2] + 60 * (s[1] + s[0] * 60);
		int T = t[2] + 60 * (t[1] + t[0] * 60);

		//
		imos[S]++;

		imos[T]--;
	}
	rep(i, 86400) if (i) imos[i] += imos[i - 1];

	int ans = 0;
	rep(i, 86400) ans = max(ans, imos[i]);

	cout << ans << endl;
}

int main() {
	while (cin >> n, n) {
		rep(i, 86400)  imos[i] = 0;
		solve();
	}
}


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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N; cin >> N;
    ll ans = LL_INF;
    for(ll i = 1; i*i <= N; i++){
        if(N%i == 0){
            ll j = N/i;
            chmin(ans, i-1 + j-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256