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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector < int >P(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}

	int pMin = INT_MAX;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		pMin = min(P[i], pMin);
		if (pMin == P[i]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long int ll;

#define endl '\n'
ll h,w;
ll dp[1005][1005];
vector < string > vec;
ll mod = 1e9+7;
ll solve(ll i,ll j)
{
    if(i<0 || j<0 || i>=h || j>=w)return 0;

    if(vec[i][j]=='#')return 0;
    if(i==h-1 and j==w-1)return 1;

    if(dp[i][j]==-1)
    {

        dp[i][j] = (solve(i+1,j) + solve(i,j+1))%mod;

    }
    return dp[i][j];
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>h>>w;

    for(ll i=0;i<h;i++){
        string s;
        cin>>s;
        vec.push_back(s);
    }

    cout<<solve(0,0)<<endl;


}


Measured memory_bytes: 9344
#include<cstdio>
using namespace std;
double x,d,ans;
int i,j,k,n;
int main() {
	scanf("%d%lf%lf",&n,&x,&d);
	for (i=n;i;i--) {
		ans+=(2.0*x+(2.0*i-1.0)*d)/2.0;
		double xx=x,dd=d;
		x+=(2.0*xx+5.0*dd)/(2.0*i);
		d+=(4.0*dd)/(2.0*i);
	}
	printf("%.15lf\n",ans);
}

Measured memory_bytes: 128
import sys

[n, h] = map(int, raw_input().split())
xs = []
for _ in range(n):
    [a, b] = map(int, raw_input().split())
    xs.append((a, 1))
    xs.append((b, 0))
xs.sort(reverse=True)
c = 0
for (a, b) in xs:
    if b == 0:
        h -= a
        c += 1
        if h <= 0:
            print c
            sys.exit(0)
    else:
        d = h // a
        c += d
        h -= d * a
        if h > 0: c += 1
        print c
        sys.exit(0)


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

void solve(const string& s) {
  for (int i = 0, j = 1; j < s.size(); ++i, ++j) {
    if (s[i] == s[j]) {
      cout << (i + 1) << " " << (j + 1) << "\n";
      return;
    }
  }
  for (int i = 0, j = 2; j < s.size(); ++i, ++j) {
    if (s[i] == s[j]) {
      cout << (i + 1) << " " << (j + 1) << "\n";
      return;
    }
  }
  cout << "-1 -1\n";
}

int main() {
  string s;
  cin >> s;
  solve(s);
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;

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

	ll n, k;
	cin >> n >> k;

	cout << min(n - n / k * k, (n + k - 1) / k * k - n);

	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll a, b, c, d; cin >> a >> b>> c>> d;
    ll cnt = (a * c);
    cnt = max(cnt, a * d);
    cnt = max(cnt , a * c);
    cnt = max(cnt , b * c);
    cnt = max(cnt , b * d);
    cout << cnt << '\n';
    

}


Measured memory_bytes: 3664
<?php
list($x, $n) = ints();
$p = ints();
for ($i = 0; $i < $n; ++$i) $a[$p[$i]] = true;
$d = 0;
while (true) {
    if (!isset($a[$x - $d])) {
        $ans = $x - $d;
        break;
    }
    if (!isset($a[$x + $d])) {
        $ans = $x + $d;
        break;
    }
    $d++;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16180
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if((B - A) % 2 == 0) {
			System.out.println("Alice");
		} else {
			System.out.println("Borys");
		}
	}
}


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

int main() {
	int x = 0, y = 0;
	cin >> x >> y;
	for (int tu = 0; tu <= x; tu++) {
		int ashi = tu * 2 + (x - tu) * 4;
		if (ashi == y) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

Measured memory_bytes: 3624
s = input()

def dfs(i, f, sum):
	if i == 3:
		if sum == 7:
			print(f + '=7')
			exit()
	else:
		dfs(i + 1, f + '-' + s[i+1], sum - int(s[i+1]))
		dfs(i + 1, f + '+' + s[i+1], sum + int(s[i+1]))

dfs(0, s[0], int(s[0]))

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string s = Console.ReadLine();
            
            int n = s.Length;

            if (s[n-1] == '1' || s[0] == '0' || s[n-2] == '0')
            {
                Console.WriteLine(-1);
                return;
            }

            for (int i=0; i<(n-1)/2; i++)
            {
                if (s[i] != s[n - 2 - i])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            int count = 1;
            for (int i=0; i<n-1; i++)
            {
                int root = count;
                while (s[i] == '0')
                {
                    Console.WriteLine(root + " " + (count+1));
                    count++;
                    i++;
                }
                Console.WriteLine(root + " " + (count+1));
                count++;
            }
        }
    }

Measured memory_bytes: 16588
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CLower {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> h(n),dp(n+1);
        int ans=0;
        fr(i,n) in>>h[i];
        fr(i,n-1){
            if(h[i]>=h[i+1]) dp[i+1]=dp[i]+1;
        }
        fr(i,n) ans=max(ans,dp[i]);
        out<<ans<<endl;
    }
};

int main() {
    CLower solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn=105;
string st;
bool used[maxn];
void solve_c(){
	cin >> n;
	cin >> st;
	int ri=0;
	for (int le=1;le<=n;le++){
		if (st[le-1]==')') continue;
		for (ri=max(ri+1,le);ri<=n;ri++){
//			cout << le << ' ' << ri << endl;
			if (st[ri-1]==')'){
				used[le]=used[ri]=true;
				break;
			}
		}
	}
//	for (int i=1;i<=n;i++) cout<< used[i] << ' ';
//	cout << endl;
	string ans=st;
	for (int i=1;i<=n;i++){
		if (!used[i]){
			if (st[i-1]=='('){
				ans=ans+')';
			}else{
				ans='('+ans;
			}
		}
	}
	cout << ans;
}
int main(){
	solve_c();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
struct point{
	int x,y;
	point(int _x,int _y)
	{
		x=_x;
		y=_y;
	}
	point(){
	}
}s,t;
int dx,dy;
string ans="";
int main()
{
	scanf("%d%d%d%d",&s.x,&s.y,&t.x,&t.y);
	dx=t.x-s.x;
	dy=t.y-s.y;
	//jalan pergi
	for(int i=0;i<dx;i++)
		ans+='R';
	for(int i=0;i<dy;i++)
		ans+='U';
		
	//jalan pulang
	for(int i=0;i<dx;i++)
		ans+='L';
	for(int i=0;i<dy;i++)
		ans+='D';
	
	//jalan pergi terakhir
	
	ans+='L';
	for(int i=0;i<dy+1;i++)
		ans+='U';
	for(int i=0;i<dx+1;i++)
		ans+='R';
	ans+='D';
	//cout<<ans<<" "<<ans.length()<<endl;
	
	// jalan pulang terakhir
	
	ans+='R';
	for(int i=0;i<dy+1;i++)
		ans+='D';
	for(int i=0;i<dx+1;i++)
		ans+='L';
	ans+='U';
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

int gcd(int n, int m){

    if(m > n)  return gcd(m, n);

    int r = n % m;
    if(r == 0) return m;
    else       return gcd(m, r);
}

int main(){

    int n; cin >> n;

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

    for(int i=0; i<n-1; i++){
        a[i+1] = gcd(a[i], a[i+1]);        
    }

    cout << a[n-1];

    return 0;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for a in A:
        for i in range(1, 31):
            if a%(2**i) != 0:
                ans += i-1
                break
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 10108
import math

D, G = map(int, input().split())
pn = []
s_max = []
for i in range(1, D+1):
  p, c = map(int, input().split())
  s_max.append(100*i*p+c)
  pn.append(p)

min = 10 ** 9
for i in range(2**(D)):
  count = 0
  p_count = 0
  no_solve = []
  for j in range(D):
    if i>>j&1 == 1:
      count += s_max[j]
      p_count += pn[j]
    else:
      no_solve.append(j)
  if count >= G:
    if min > p_count:
      min = p_count
  else:
    box = math.ceil((G - count) / (100 * (no_solve[-1]+1)))
    if box < pn[no_solve[-1]]:
      p_count += box
      if min > p_count:
        min = p_count
print(min)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N,A;
  cin >> N >> A;
  N%=500;
  cout << (N<=A?"Yes":"No") << endl;
  return 0;
}


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


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define all(s) s.begin(), s.end()
#define fuck_you_scanf ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define si size()
 
const int N = 1e6 + 5;
vector<int> v[N];
int arr[N];
int ret[N];

void dfs(int sv, int par, int val)
{
    for(int x : v[sv])
    {
        if(x != par)
        {
            dfs(x, sv, val + arr[sv]);
        }
    }
    ret[sv] += val + arr[sv];
}

int32_t main()
{
    int n, q;
    cin >> n >> q;
    int t = n - 1;
    while(t--)
    {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
    while(q--)
    {
        int node, val;
        cin >> node >> val;
        arr[node] += val;
    }
    dfs(1, 0, 0);
    FOR(i, 0, n) cout << ret[i + 1] << " ";
}

Measured memory_bytes: 48128
#include <bits/stdc++.h>
#include <vector>
using namespace std;
 
int main(){
  //入力
  int M,D;
  cin>>M>>D;
  int a,b;
  int cnt=0;
  for(int i=1;i<D+1;i++){
    a = i/10;
    b = i - (a*10);  
    for(int j=1;j<M+1;j++){
      if((j == (a*b)) && a>=2 && b>=2){
        cnt++;
      }
    }
  }
  
  //出力
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
N, M, X, Y = gets.split.map(&:to_i)
Xs = gets.split.map(&:to_i)
Ys = gets.split.map(&:to_i)

puts ((X + 1 .. Y).any?{|z| Xs.max < z && Ys.min >= z} ? 'No ' : '') + 'War'

Measured memory_bytes: 3836
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


vector<bool> getSutPrimeTable(int max)
{
	vector<bool> table(max + 1);


	REP(i, 1, max + 1)
	{
		// iªjyjÅLé±ÆðÛØ
		if((i + 6) % 7 && (i + 1) % 7) continue;

		table[i] = true;
		for(int j = 6; j * j <= i; j++)
		{
			// Ù©ÌjyjÅ êÎAjyjfÅÍÈ¢
			if(table[j] && i % j == 0)
			{
				table[i] = false;
				break;
			}
		}
	}

	return table;
}

int main()
{
	vector<bool> table = getSutPrimeTable(300000);

	int n;
	while(cin >> n && n - 1)
	{
		cout << n << ":";

		for(int i = 6; i <= n; i++)
		{
			if(table[i] && n % i == 0)
				cout << " " << i;
		}

		cout << endl;
	}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int n, m;
int c[100005], vs[100005];
vector<int> g[100005];
vector<pair<int,int> > res;
struct dsu{
	vector<int> p;
	void setup(int u){
		p.assign(u + 1, -1);
	}
	int f(int u){
		return (p[u] < 0 ? u : p[u] = f(p[u]));
	}
	bool j(int u, int v){
		u = f(u), v = f(v);
		if(u == v) return false;
		if(p[u] > p[v]) swap(u, v);
		p[u] += p[v];
		p[v] = u;
		return true;
	}
}ds;
void dfs(int u, int p){
	for(int v: g[u])
		if(v != p)
			dfs(v, u);
	if(u == 1) return;
	if(c[u]) res.push_back({u, p});
	else c[p] ^= 1, res.push_back({p, u}); 
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	ds.setup(n);
	if(m&1) return cout << -1, 0;
	for(int i = 1 ; i <= m ; i ++){
		int u, v;
		cin >> u >> v;
		if(ds.j(u, v)){
			g[u].push_back(v);
			g[v].push_back(u);
		} else{
			c[u] ^= 1;
			res.push_back({u, v});
		}
	}
	dfs(1, 0);
	for(pair<int,int> e: res)
		cout << e.first << " " << e.second << endl;
}


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

using namespace std;

int main (){
   char b ;
   cin>>b;
   if ( b=='T'){
        cout<< "A";
   }
   if( b=='A'){ cout<<"T";}
   if(b=='G'){cout<<"C";}
   if ( b=='C'){cout<< "G";}
   return 0;



}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e5+10;
const ll mod=1e9+7;
int bit[MAX][33],res[MAX];
int main()
{
	int n,x,i,j,a,b,c,ans,flag;
	while(~scanf("%d%d",&n,&x))
	{
		mem(bit,0);
		for(i=0;i<n;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			bit[a][c]++;
			bit[b+1][c]--;
		}
		mem(res,0);
		for(i=1;i<=x;i++)
		{
			flag=0;
			for(j=1;j<=100000;j++)
			{
				bit[j][i]+=bit[j-1][i];
				if(bit[j][i])
				{
					if(!flag) res[j]++;
					flag=1;
				}
				else
				{
					if(flag) res[j]--;
					flag=0;
				}
			}
		}
		ans=0;
		for(i=1;i<=(int)1e5;i++)
		{
			res[i]+=res[i-1];
			ans=max(ans,res[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;

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

struct edge{int to;};
using graph = vector<vector<edge>>;

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

  string s;
  cin >> s;

  string t;
  trav(c, s) {
    if (c == '?') t += 'D';
    else t += c;
  }
  cout << t << '\n';
}


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

ll mid(vector<ll> a){
    ll n = a.size();
    if(n%2 == 0) return a[n/2]+a[(n-1)/2];
    else return a[n/2];
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll amid = mid(a);
    ll bmid = mid(b);
    int ans = 0;

    ans += bmid-amid+1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8004
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if(b <= a) cout << "delicious" << endl;
  else if(b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;

  return 0;
}


Measured memory_bytes: 256
#E
import re
s = "+"+input()
c = 0
k = [0 for i in range(6)]
while c<len(s):
    find_1 = re.search(r'^([\+\-])x\^([2-5])', s[c:])
    if find_1:
        k[int(find_1.group(2))] = int(str(find_1.group(1))+"1")
        c += find_1.end()
        continue
    find_2 = re.search(r'^([\+\-][1-9][0-9]*)x\^([2-5])', s[c:])
    if find_2:
        k[int(find_2.group(2))] = int(str(find_2.group(1)))
        c += find_2.end()
        continue
    find_3 = re.search(r'^([\+\-][1-9][0-9]*)x', s[c:])
    if find_3:
        k[1] = int(str(find_3.group(1)))
        c += find_3.end()
        continue
    find_4 = re.search(r'^([\+\-])x', s[c:])
    if find_4:
        k[1] = int(str(find_4.group(1))+"1")
        c += find_4.end()
        continue
    find_5 = re.search(r'^([\+\-][1-9][0-9]*)', s[c:])
    if find_5:
        k[0] = int(str(find_5.group(1)))
        c += find_5.end()
        continue

#print(k)
#
ans = ""
que = list(range(abs(k[0]), -abs(k[0])-1, -1))
#print(que)

while True:
    buf = [0 for i in range(6)]
    n = que[0]
    p = 5
    while(k[p] == 0): p-=1
#    print(p)
    if p==0: break
    buf[p] = k[p]
    while p>0:
        p -= 1
        buf[p] = k[p] + n * buf[p+1]
#    print(k)
#    print(buf)
    if buf[0] == 0:
        k = buf[1:]+[0]
        if n < 0:
            ans += "(x+"+str(-n)+")"
        else:
            ans += "(x"+str(-n)+")"
    else:
        que.pop(0)
print(ans)


Measured memory_bytes: 6720
MOD = 10**9+7
fac = [1]*(2020)
for i in range(2,2020) :
    fac[i] *= fac[i-1] * i

def comb(n, k) :
    a = fac[n]
    b = fac[k] * fac[n-k]
    return (a//b) % MOD


N,K = map(int,input().split())

for i in range(1,K+1) :
    a = comb(N-K+1, i)
    b = comb(K-1, i-1)
    res = (a*b) % MOD
    print(res)


Measured memory_bytes: 6004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const int maxn=3e5+5;
int n,k,tot,a[maxn],sum[maxn<<2];
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
void push_up(int rt){
	sum[rt]=max(sum[rt<<1],sum[rt<<1|1]);
}
void update(int x,int c,int l,int r,int rt){
	if(l==r){
		sum[rt]=max(sum[rt],c);
		return ;
	}
	int m=(l+r)>>1;
	if(x<=m) update(x,c,l,m,rt<<1);
	else update(x,c,m+1,r,rt<<1|1);
	push_up(rt);
}
int query(int a,int b,int l,int r,int rt){
	if(a<=l&&b>=r) return sum[rt];
	int m=(l+r)>>1;
	int ans=0;
	if(a<=m) ans=max(ans,query(a,b,l,m,rt<<1));
	if(b>m) ans=max(ans,query(a,b,m+1,r,rt<<1|1));
	return ans;
}
int main(){
    n=read(),k=read();
    for(int i=1;i<=n;i++){
        a[i]=read()+1;
        tot=max(tot,a[i]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        int tmp=query(max(1,a[i]-k),min(tot,a[i]+k),1,tot,1)+1;
        update(a[i],tmp,1,tot,1);
        ans=max(ans,tmp);
    }
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 9068
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, K = map(int, input().split())

pred_sum = 0.0
for n in range(1, N + 1):
    n2 = n
    cnt = 0
    while n2 < K:
        n2 *= 2
        cnt += 1
    pred_sum += 0.5 ** cnt
print("{:.15f}".format(pred_sum / N))


Measured memory_bytes: 7968
N, Y = map(int, input().split())
for i in range(N+1):
  for j in range(N - i + 1):
    if 10000 * i + 5000 * j + 1000 * (N-i-j) == Y:
      print('{} {} {}'.format(i,j,N-i-j))
      exit()
else:
  print('-1 -1 -1')

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

bool vis[105];

int main(void)
{
    int n,k; cin>>n>>k;
    for(int i=0;i<k;++i){
        int d; cin>>d;
        for(int j=0;j<d;++j){
            int c; cin>>c;
            vis[c] = true;
        }
    }
    int ans = 0;
    for(int i=1;i<=n;++i)
        if(!vis[i]) ++ans;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N,M,C,s,g;

void solve(){
    vector<vvi> dist(N,vvi(N,vi(C,INF)));
    vi p(C);
    vvi q(C),r(C);
    rep(i,M){
        int x,y,c,d;
        cin>>x>>y>>d>>c;
        x--; y--; c--;
        dist[x][y][c] = dist[y][x][c] = min(dist[x][y][c],d);
    }

    rep(i,C) cin>>p[i];
    rep(i,C){
        q[i].resize(p[i]-1);
        r[i].resize(p[i]);
        rep(j,p[i]-1) cin>>q[i][j];
        rep(j,p[i]){
            cin >> r[i][j];
        }
    }

    vvi pay(C,vi(20010,INF));
    rep(c,C){
        vi &v = pay[c];
        vi qc = q[c];
        vi rc = r[c];
        v[0] = 0;
        int idx = 0;
        for(int i=1;i<=20000;i++){
            v[i] = v[i-1] + rc[idx];
            if(idx < sz(qc) && i==qc[idx]) idx++;
        }
    }

    rep(c,C){
        rep(k,N) rep(i,N) rep(j,N){
            dist[i][j][c] = min(dist[i][j][c],dist[i][k][c]+dist[k][j][c]);
        }
    }

    vvi cost(N,vi(N,INF));
    rep(c,C) rep(i,N) rep(j,N){
        if(dist[i][j][c] < INF){
            cost[i][j] = min(cost[i][j],pay[c][dist[i][j][c]]);
        }
    }

    rep(k,N) rep(i,N) rep(j,N){
        cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
    }

    if(cost[s][g]==INF) cout << -1 << endl;
    else cout << cost[s][g] << endl;
}

int main(){
    while(cin>>N>>M>>C>>s>>g){
        if(N==0 && M==0 && C==0 && s==0 && g==0) break;
        s--;
        g--;
        solve();
    }
}

Measured memory_bytes: 5828
N, M = map(int, input().split())

A=[]
total=0
count=0
flag=0
for j in range(M+1):
    A.append(list(map(int, input().split())))

for i in range(2**N):
    switch=format(i,'b')
    switch=switch[::-1]+'0000000000'
    

    for a in range(M):
        for b in range(1,len(A[a])):
            
            count += int(switch[int(A[a][b])-1])
            

        if count%2!=A[M][a]:
            flag=1
        count = 0
    if flag==0:
        total +=1
    flag=0
    count=0
print(total)

Measured memory_bytes: 3064
n,m = gets.chomp.split.map(&:to_i)
s,c = m.times.map{gets.chomp.split.map(&:to_i)}.transpose
ans = -1

(0..1000).each do |i|
  next if i.to_s.size != n
  flag = true
  m.times do |j|
    if i.to_s[s[j] - 1] != c[j].to_s
      flag = false
      break
    end
  end

  if flag
    ans = i
    break
  end
end

puts ans

Measured memory_bytes: 1788
/*
 ____________________________________________________________
|                                                            |
|                   Author: ay2306                           |
|____________________________________________________________|

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
using namespace std;

const ll maxn = 1e5;

int main(){
  string fin = "";
  int n;
  V<string> a[3];
  cin >> n;
  loop(i,0,n){
  	string b;
    cin >> b;
    if(b[0] == 'B' && b[b.size()-1] == 'A')a[2].pb(b);
    else if(b[0] == 'B')a[0].pb(b);
    else if(b[b.size()-1] == 'A')a[1].pb(b);
  	else fin+=b;
  }
  while(1){
    if(fin[fin.size()-1] == 'A' && a[2].size()){
    	fin+=a[2][a[2].size()-1];
      	a[2].pop_back();
    }
  	else if(fin[fin.size()-1] == 'A' && a[0].size()){
    	fin+=a[0][a[0].size()-1];
      a[0].pop_back();
    }else if(a[1].size()){
    	fin+=a[1][a[1].size()-1];
      a[1].pop_back();
    }else if(a[2].size()){
    	fin+=a[2][a[2].size()-1];
      a[2].pop_back();
    }
    else if(a[0].size()){
    	fin+=a[0][a[0].size()-1];
      a[0].pop_back();
    }else{
    	break;
    }
  }  
  ll ans = 0;
  for(int i = 0; i < fin.size(); ++i){
  	if(fin[i] == 'A'){
    	if(i+1 < fin.size() && fin[i+1] == 'B')ans++;
    }
  }
  cout << ans;
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	int dp[n+1][3], a[n+1][3];
	for (int i=1;i<=n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	for (int i=1;i<=n;i++){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + a[i][1];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + a[i][2];
	}
	int ans = 0;
	ans = max(dp[n][0], dp[n][1]);
	ans = max(ans, dp[n][2]);
	cout<<ans;
}

Measured memory_bytes: 2688
using System;

namespace ITP_2_C{
    public class Program{
        public static void Main(string[] args){
            string[] temp = Console.ReadLine().Split(' ');
            int a = int.Parse(temp[0]);
            int b = int.Parse(temp[1]);
            int c = int.Parse(temp[2]);
            int first = 0;
            int middle = 0;
            int last = 0;

            //a??¨b???????????????
            if(a < b){
                first = a;
                middle = b;
            }else{
                first = b;
                middle = a;
            }
            //first < middle????¢????

            //c????????\??????????±?????????????
            if(c < middle){
                if(first < c){
                //???????????§?¢????
                    last = middle;
                    middle = c;
                }else{
                //???????¢????
                    last = middle;
                    middle = first;
                    first = c;
                }
            }else{
                last = c;
            }
            Console.WriteLine(first +" "+ middle +" "+ last);
        }
    }
}

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

bool my_compare(pair<string,int> a, pair<string,int> b){
    if(a.first != b.first){
        return a.first < b.first;
    }
    
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return true;
    }
}

int main(){
  int N,b;
  string a;
  using pr = pair<string,int>;
  vector<pr> vc;
  vector<pr> cp;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    cin >> a >> b;
  	vc.push_back(make_pair(a,b));
  }
  
  cp = vc;
  
  sort(vc.begin(),vc.end(),my_compare);
  
  
  for(int i = 0; i < vc.size(); i++){
      for(int j = 0; j < vc.size(); j++){
          if(vc.at(i) == cp.at(j))
            cout << j + 1 << endl;
      }
      
  }
  
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string S;
    cin >> S;

    string T = "CODEFESTIVAL2016";

    ll ans = 0;
    Rep (i, 16) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll pow_mod(ll a, ll b, ll m){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, K;
    cin >> N >> K;
    ll sum = K * (K + 1) / 2;
    (sum *= N) %= mod;
    (sum *= pow_mod(K + 1, N - 1, mod)) %= mod;
    
    vector<vector<ll>> dp(N + 2, vector<ll>(10010, 0));
    dp[N + 1][0] = 1;
    for(int i = (int)N; i >= 1; i--){
        rep(j, 5100){
            rep(k, K + 1){
                if(k <= i){
                    (dp[i][j + (k + j) / i] += dp[i + 1][j]) %= mod;
                }
                else {
                    (dp[i][j] += dp[i + 1][j]) %= mod;
                }
            }
        }
    }
    
    ll sub = 0;
    rep(i, N * N + 1){
        (sub += (dp[1][i] * i) % mod) %= mod;
    }
    
    output((sum - sub + mod) % mod);
    
    return 0;
}

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define MAX 99999999
#define LONGMAX 99999999999999
#define FI first
#define SE second

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    for(int i = 0;i <= N;i++){
        for(int j = 0;j <= M;j++){
//            cout << i << " * " << j << " = " << M*i << " + " << N*j << " - " << i*j*2 << " = " << N*j + M*i - i*j << endl;
            if(N*j + M*i - i*j*2 == K){
                cout << "Yes" << endl;
                ED
            }
        }
    }
    cout << "No" << endl;
    ED
}


Measured memory_bytes: 256
module DoublyChainedTree = struct
  let nil = -1

  type t = {
    mutable parent : int;
    mutable child : int;
    mutable bro : int;
    mutable depth : int;
  }

  let make () = { parent = nil; child = nil; bro = nil; depth = nil }
end

module T = DoublyChainedTree

let () =
  let n = read_int () in
  let t = Array.init n (fun _ -> T.make ()) in
  for _ = 0 to n - 1 do
    Scanf.scanf "%d %d " (fun id k ->
      let left_child = ref 0 in
      for j = 0 to k - 1 do
        Scanf.scanf "%d " (fun c ->
          t.(c).T.parent <- id;
          if j = 0 then t.(id).T.child <- c else t.(!left_child).T.bro <- c;
          left_child := c)
      done)
  done;
  let root = ref 0 in
  for i = 0 to n - 1 do
    if t.(i).T.parent = T.nil then root := i;
  done;
  let rec set_depth i p =
    t.(i).T.depth <- p;
    if t.(i).T.bro <> T.nil then set_depth t.(i).T.bro p;
    if t.(i).T.child <> T.nil then set_depth t.(i).T.child (p + 1);
  in
  set_depth !root 0;
  let print_tree i =
    Printf.printf "node %d: parent = %d, depth = %d, " i t.(i).T.parent t.(i).T.depth;
    print_string (if t.(i).T.parent = T.nil then "root, " else if t.(i).T.child = T.nil then "leaf, " else "internal node, ");
    print_string "[";
    let c = ref t.(i).T.child in
    while !c <> T.nil do
      if !c <> t.(i).T.child then print_string ", ";
      print_int !c;
      c := t.(!c).T.bro;
    done;
    print_endline "]"
  in
  for i = 0 to n - 1 do
    print_tree i
  done

Measured memory_bytes: 13248
#include <cstdio>


char sa[108];
char sb[108];
char sc[108];
int calc(int i) {
	int sames=0;
	if(sa[i]==sb[i]) sames++;
	if(sa[i]==sc[i]) sames++;
	if(sb[i]==sc[i]) sames++;
	if(sames==3) return 0;
	if(sames==1) return 1;
	return 2;
}

int main() {
	int N;
	scanf("%d",&N);
	scanf("%s",sa);
	scanf("%s",sb);
	scanf("%s",sc);
	int sol=0;
	for(int i=0;i<N;i++) sol+=calc(i);
	printf("%d\n",sol);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long



int main(){
  LINT N;
  cin >> N;
  LINT a[N+1];
  LINT x;
  a[0] = 0;
  REP(i, N) {
    cin >> x;
    a[i+1] = a[i] + x;
  }

  LINT ans=0;
  LINT work, num=0;
  sort(a, a+N+1);
  work = a[0];
  REP(i, N){
    ++num;
    if(work != a[i+1]){
      ans += num*(num-1)/2;
      num = 0;
      work = a[i+1];
    }
  }
  ++num;
  ans += num*(num-1)/2;
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX (1 << 17)
int n, seg[MAX * 2 - 1];
void init( int size){
  n = 1;
  while(n < size) n *= 2;
}
int query( int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return seg[k];
  int vl = query( a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = query( a, b, k * 2 + 2, (l + r) / 2, r);
  return vl + vr;
}
void update( int i, int x){
  i += n - 1;
  seg[i] += x;
  while( i > 0 ){
    i = ( i - 1 ) / 2;
    seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
  }
}
int main(){
  int size, q;
  scanf("%d %d", &size, &q);
  init(size);
  while(q--){
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if( com == 0 ) update( x - 1, y );
    else printf("%d\n", query( x - 1, y, 0, 0, n));
  }
}

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

const int MOD=1000000007;

/*素因数分解*/
/*O(sqrtN)*/
map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i=2; i*i<=n; i++) {
    while (n%i==0) {
      ++res[i];
      n/=i;
    }
  }
  if (n!=1) res[n]=1;
  return res;
}

/*繰り返し二乗法*/
/*O(logN)で乗数を返す*/
ll modpow(ll x, ll n, ll mod) {
  if (n==0) return 1;
  ll res=modpow(x*x%mod, n/2, mod);
  if (n&1) res=res*x%mod;
  return res;
}

/*フェルマーの小定理*/
/*O(logN)で逆元を返す*/
ll modinv(ll a, ll mod) {
  return modpow(a, mod-2, mod);
}

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

  //vectorAの最大公倍数
  map<int, int> X;
  rep(i, n) {
    map<int, int> f=prime_factor(A[i]);
    for (auto p : f) {
      X[p.first]=max(X[p.first], p.second);
    }
  }

  //LCMを計算
  ll LCM=1;
  for (auto p : X) {
    LCM*=modpow(p.first, p.second, MOD);
    LCM%=MOD;
  }

  ll res=0;
  rep(i, n) {
    ll tmp=LCM*modinv(A[i], MOD);
    tmp%=MOD;
    res+=tmp;
    res%=MOD;
  }
  cout<<res<<endl;
}

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

long long A,B,K;
long long takahashi,aoki;

int main() {
    cin >> A >> B >> K;

    if (K <= A) {
        takahashi = A - K;
        aoki = B;
    } else if ((K > A) && (B - (K - A) >= 0)) {
        takahashi = 0;
        aoki = B - (K - A);
    } else {
        takahashi = 0;
        aoki = 0;
    }
    cout << takahashi << " " << aoki << endl;
}


Measured memory_bytes: 256
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
r1 = {a11, a12, a13}
r2 = {a21, a22, a23}
r3 = {a31, a32, a33}
c1 = {a11, a21, a31}
c2 = {a12, a22, a32}
c3 = {a13, a23, a33}
cr1 = {a11, a22, a33}
cr2 = {a31, a22, a13}
A = [r1, r2, r3, c1, c2, c3, cr1, cr2]

n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
B = set(b)


for C in A:
    if C.issubset(B):
        print('Yes')
        quit()

print('No')



Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        println("Possible")
    } else {
        println("Impossible")
    }
}

Measured memory_bytes: 31400
#include <iostream>
#include <string>
using namespace std;
string S; long long K;
int main() {
  cin >> S >> K;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == '1') continue;
    if(i < K) {cout << S[i]; return 0;}
  }
  cout << '1';
}

Measured memory_bytes: 256
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

A,B,K = [int(x) for x in input().split()]

yakusu = defaultdict(int)

for a in range(A):
    a += 1
    if A % a == 0:
        yakusu[a] += 1
    if B >= a and B % a == 0:
        yakusu[a] += 1

nums = sorted([x for x in yakusu.keys() if yakusu[x] == 2])
print(nums[-(K)])


Measured memory_bytes: 14672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, z = 1, y = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 2; i <= n; i++) {
        if (a[i] <= a[i - 1]) y++;
        else y = 1;
        z = max(z, y);
    }
    cout << z - 1;
}


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


int main(){
	int N,K;
	cin >> N >> K;
	int x[101];
	for(int i=0;i<N;i++){
		cin >> x[i];
	}
	int answer = 0;
	for(int i=0;i<N;i++){
		answer = answer + min(x[i]*2,abs(x[i]-K)*2);
	}
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define lli long long 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fi(i,a,n) for(int i=a; i<=n; i++)
using namespace std;
int main(){
    
    fast

    	int x;
    	cin>>x;

    	if(400<= x && x <= 599) 
    	{cout<<8<<endl;}
    	else if(600<=x && x<=799) cout<<7<<endl;
    	else if(800<=x && x <= 999) cout<<6<<endl;
else if(1000<=x && x <= 1199) cout<<5<<endl;
else if(1200<=x && x <= 1399) cout<<4<<endl; 
else if(1400<=x && x <= 1599) cout<<3<<endl; 
else if(1600<=x && x <= 1799) cout<<2<<endl;
else cout<<1<<endl;  
     
}

Measured memory_bytes: 3648
using System;

namespace ABC120
{
    class A
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);

            if (B / A < C) Console.WriteLine(B / A);
            else Console.WriteLine(C);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B;
  cin >> N >> A >> B;
  if (N * A > B || N * A == B) {
    cout << B << endl;
  } else if (N * A < B){
    cout << N * A << endl;
  } else {
    cout << "error" << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(void)
{
	int a,b,sum,c;
	while(scanf("%d",&a)!=EOF)
	{
		scanf("%d",&b);
		sum= a+b;
		c=1;
		while(sum>=10)
		{
			sum=sum/10;
			c+=1;
		}
		printf("%d\n",c);
	}
	return 0;
}

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

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

  int tmp = 1;
  for(int i = 0;i < d;i++){
    tmp *= 100;
  }

  int ans = 0;
  for(int i = 0;i < n;i++){
    ans += tmp;
    if(ans % (tmp * 100) == 0){
      i--;
    }
  }


  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> h;
  int temp;
  while (std::cin >> temp)
    h.push_back(temp);
  std::sort(h.begin(), h.end());
  long sum = 0;
  int cnt = n-k;
  if (cnt > 0)
    for (int i=0; i<cnt; ++i)
      sum += h[i];
  std::cout << sum << std::endl;
  return 0;;
}

Measured memory_bytes: 1400
#include<cstdio>

#define MAX 1000007
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0 

using namespace std;
typedef long long ll;
char s[MAX];

int main(){
    int n;
    scanf("%d%s",&n,s);
    ll a=0,b=0,c=0;
    for(int i =0;i<n;i++){
        if(s[i]=='R')a++;
        if(s[i]=='G')b++;
        if(s[i]=='B')c++;
    }
    ll ans = a*b*c;
    for(int i = 0;i<n;i++){
        for(int j = i+1;j<n;j++){
            if(s[i]==s[j])continue;
            if(2*j-i<n&&s[i]!=s[2*j-i]&&s[j]!=s[2*j-i])ans--;
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 1732
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

int main() {

  int n;
  cin >> n;

  int a[n];
  rep(i, n) cin >> a[i];

  int max1 = -1, max2 = -1, cnt = 0;

  rep(i, n) {
    max1 = max(max1, a[i]);
  }

  rep(i, n) {
    if(a[i]==max1) ++cnt;
    else max2 = max(max2, a[i]);
  }

  if(cnt>1) max2 = max1;

  rep(i, n) {
    if(max1==a[i]) cout << max2 << endl;
    else cout << max1 << endl;
  }

  return 0;
}


Measured memory_bytes: 2432
def reconsruction(pre, ino):
    if 0 == len(pre):
        return []
    else:
        root = pre[0]

        partition = ino.index(root)
        l_ino = ino[0:partition]
        r_ino = ino[partition+1:]

        pre_partition = len(l_ino)+1
        l_pre = pre[1:pre_partition]
        r_pre = pre[pre_partition:]

        return reconsruction(l_pre, l_ino) + reconsruction(r_pre, r_ino) + [root]

n = int(input())

pre = list(map(int, input().split()))
ino = list(map(int, input().split()))

print(*reconsruction(pre, ino))

Measured memory_bytes: 7728
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main (void) {

    do {
        int a, l;
        cin >> a >> l;
        if (a == 0 && l ==0) { break; }

        vector<int> log_a;
        log_a.push_back(a);
        bool isEnd = false;
        int loop_cnt = 1;

        do {
            int as[l];
            for (int i=0; i<l; i++) {
                as[i] = (a == 0) ? 0 : a % 10;
                a = a / 10;
            }

            sort(as, as+l);
            int maxa=0, mina=0, newa;
            for (int j=0; j<l; j++) {
                mina += as[j] * pow(10.0, (l-1-j));
                maxa += as[j] * pow(10.0, j);
            }

            a = maxa - mina;

            for (int i=0; i<loop_cnt; i++) {
                if (log_a[i] == a) {
                    isEnd = true;
                    log_a.push_back(a);
                    cout << i << ' ' << log_a[loop_cnt] << ' ' << loop_cnt-i << endl;
                    break;
                }
            }

            log_a.push_back(a);
            loop_cnt++;
        } while (!isEnd);



    } while (true);

    return 0;
}

Measured memory_bytes: 1228
N=int(input())
s1=list(input())
s2=list(input())
i=0
beflag=0        #0…前は何もない(先頭)、1…前は横ミノ×2、2…前は縦ミノ×1
ans=1
p=10**9+7
while i<N:
    if s1[i]==s2[i]:        #もし縦ミノなら
        if beflag==0:
            ans=(ans*3)%p
        elif beflag==1:
            ans=ans
        elif beflag==2:
            ans=(ans*2)%p
        beflag=2
        i=i+1
    else:                   #それ以外は横ミノ*2を保証するはず
        if beflag==0:
            ans=(ans*6)%p
        elif beflag==1:
            ans=(ans*3)%p
        elif beflag==2:
            ans=(ans*2)%p
        beflag=1
        i=i+2
    #print(i,ans,N)
print(ans)



Measured memory_bytes: 9172
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MOD(x) ((x) % (1e9 + 7))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d\n", max(a - b * 2, 0));
	return 0;
}

Measured memory_bytes: 256