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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int64_t N, A, B, K;
    cin >> N >> A >> B >> K;
    int64_t ans = 0;
    create_mod_tables(N);
    for(int a=0; a<=N; a++){
        int64_t r = K-a*A;
        if(r%B) continue;
        int64_t b = r/B;
        if(b < 0 || b > N) continue;
        add(ans, comb_mod(N, a) * comb_mod(N, b));
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> U;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 1; i < (int)A.size(); i++) {
    if (A[i-1] == A[i]) {
      A.erase(A.begin() + (i-1));
      i--;
    }
  }
  if ((int)A.size() == 1) {
    cout << 1000 << endl;
    return 0;
  }
  if (A[0] < A[1]) {
    U.push_back(A[0]);
  }
  for (int i = 2; i < (int)A.size(); i++) {
    if (A[i-2] < A[i-1] && A[i-1] > A[i]) {
      U.push_back(A[i-1]);
    }
    if (A[i-2] > A[i-1] && A[i-1] < A[i]) {
      U.push_back(A[i-1]);
    }
  }
  if (A[A.size() - 2] < A[A.size() - 1]) {
    U.push_back(A[A.size() - 1]);
  }
  ll money = 1000;
  ll K = 0;
  for (int i = 0; i < (int)U.size(); i+=2) {
    K = money / U[i];
    money -= (money / U[i]) * U[i];
    money += K * U[i+1];
    K = 0;
  }
  cout << money << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

void solve() {
	int n, k; cin >> n >> k;
	vector<int> v(n);
	rep(i, n) {
		cin >> v[i];
	}
	if (k >= 2 * n) {
		int sum = 0;
		rep(i, n) {
			if (v[i] > 0)sum += v[i];
		}
		cout << sum << endl; return;
	}
	int ans = 0;
	if (k >= n) {
		vector<int> u = v;
		sort(u.begin(), u.end(),greater<int>());
		int sum = 0;
		rep(i, 2*n-k) {
			sum += u[i];
		}
		ans = max(ans, sum);
	}
	rep(i, n) {
		Rep(j, i, n) {
			int rest = k - i - (n - 1 - j);
			if (rest < 0)continue;
			vector<int> u;
			rep(x, n) {
				if (x<i || x>j)u.push_back(v[x]);
			}
			sort(u.begin(), u.end());
			int sum = 0;
			rep(i, u.size())sum += u[i];
			rep(i, u.size()) {
				if (u[i] > 0)break;
				if (rest > 0) {
					rest--;
					sum -= u[i];
				}
			}
			ans = max(ans, sum);
			//cout << i << " " << j << " " << sum << endl;
		}
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    long h,n;
    cin >> h >> n;
    vector<long> a(n);
    long ans = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        ans += a[i];
    }
    if(h <= ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;    
    }
    
    
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			int num = sc.nextInt();
			
			if(num == 0)break;
			
			int sum = sc.nextInt();
			int max = sum;
			
			for(int i = 1; i < num; i++){
				int n = sc.nextInt();
				
				if(sum + n < n){
					sum = n;
				}else{
					sum += n;
				}
				max = Math.max(max, sum);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 34024
<?php

list($a, $b) = fscanf(STDIN, "%d %d");
$a = trim($a);
$b = trim($b);


if($a < 0 && $b > 0 ||
	$a == 0 || $b == 0){
	$ans = "Zero\n";
}elseif($b < 0){
	if(($b - $a) % 2 == 1 ){
		$ans = "Positive\n";

	}else{
		$ans = "Negative\n";
	}
}else{
	$ans = "Positive\n";
}

echo $ans;


Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int h,a;
    while(cin>>h>>a)
    {
        if(h%a==0)
            cout<<h/a<<endl;
        else
            cout<<h/a+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 1000001
ll a[MAXN];
ll gcd(ll x, ll y) {
    if (x < y) {
        return gcd(y, x);
    }
    if (y == 0) {
        return x;
    }
    else {
        return gcd(y, x % y);
    }
}
bool is_prime[MAXN]; // 1スタート
ll primelist[MAXN]; //0スタート
//範囲の素数もカウント
int setp() {
    memset(primelist, 0, sizeof(primelist));
    memset(is_prime, true, sizeof(is_prime));
    is_prime[1] = false;
    int k = 2;
    while (k < MAXN) {
        if (is_prime[k]) {
            for (int l = k; l <= MAXN / k; l++) {
                is_prime[k * l] = false;
            }
        }
        k++;
    }
    int count = 0;
    for (int i = 1; i < MAXN; i++) {
        if (is_prime[i]) {
            primelist[count] = i;
            count++;
        }
    }
    return count;
}
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll now = a[1];
    for (int i = 1; i <= n; i++) {
        now = gcd(now, a[i]);
    }
    if (now > 1) {
        cout << "not coprime" << endl;
        return 0;
    }
    int p = setp();
    //cout << primelist[1] << endl;
    bool used[MAXN];
    memset(used, false, sizeof(used));
    for (int i = 1; i <= n; i++) {
        used[a[i]] = true;
    }
    for (int i = 0; i < p; i++) {
        int count = 0;
        int start = 1;
        while (primelist[i] * start < MAXN) {
            if (used[primelist[i] * start]) {
                count++;
            }
            if (count == 2) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            start++;
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int max = 0;
	int min = 0;
	int* x = new int[n];
	int* result = new int[n];
	int j = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		if (i == 0) {
			min = x[i];
		}
		if (max < x[i]) {
			max = x[i];
		}
		if (min > x[i]) {
			result[j] = max - min;
			j++;
			max = min = x[i];
		}
	}
	result[j] = max - min;
	int maxr = result[j];
	for (int i = j; i >=0; i--) {
		if (maxr < result[i]) {
			maxr = result[i];	
		}
	}
	if (maxr == 0) {
		int minl = x[1] - x[0];
		for (int i = 0; i < n-1; i++) {
			if (minl < (x[i + 1] - x[i])) {
				minl = x[i + 1] - x[i];
			}
		}
		maxr = minl;
	}
	cout << maxr << endl;
	return 0;
}


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


VV G;
V c;
V ans;
int i = 0;


void dfs(int u, int p=-1) {
  for (int v : G[u]) if (v != p) {
    dfs(v, u);
  }
  ans[u] = c[i];
  ++i;
}

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

  G.assign(n, V());
  c.assign(n, 0);
  ans.assign(n, 0);

  rep(i, n-1) {
    int a, b; cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin >> c;
  sort(all(c));

  dfs(0);

  ll sum = 0;
  rep(i, n-1) sum += c[i];
  cout << sum << "\n";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1408
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int a,b;
    cin>>a>>b;
    
    int c;
    int h=0;
    
    if(b==100){
        c=1000*a+b;
        for(int i=1;i<1000;i++){
            if(i*i==c){
                h=1;
            }
        }
        
    }else if(b>=10){
        c=100*a+b;
        for(int i=1;i<120;i++){
            if(i*i==c){
                h=1;
            }
        }
        
    }else{
        c=a*10+b;
        for(int i=1;i<100;i++){
        if(i*i==c){
            h=1;
        }
        }
        
    }
    
    if(h==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    
    return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define ll long long
#define rei register int
#define bl putchar(' ')
#define ed putchar('\n')
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define test std::cout<<"this:"
#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f
#define lldinf 0x3f3f3f3f3f3f3f3f
#define pai acos(-1)
#define inv inline void
#define read2(a,b) read(a),read(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define read4(a,b,c,d) read(a),read(b),read(c),read(d)
template <typename QvQ>inv read(QvQ &x)
{
    x=0;int f=1;
    char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
    x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
    if(x<0) x=-x,putchar('-');
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
using namespace std;
#define MAXN 300005
int a,b;
int main()
{
	read2(a,b);
	if(a==b) 
	{
		write(0);
		return 0;
	}
	else
	{
		int c=a+b;
		if(c&1) puts("IMPOSSIBLE");
		else write(c/2);
	}
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

ll MOD = 1000000007;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

uint64_t comb(uint64_t n, uint64_t k) {
    uint64_t r = 1;
    for (uint64_t d = 1; d <= k; ++d) {
        r *= n--;
        r %= MOD;
        r = r * modinv(d, MOD)%MOD;
        //dump(modinv(d, MOD));
    }
    //dump(r);
    return r%MOD;
}


ll comp(ll b, ll e, ll m){
    ll ans = 1;
    while(e>0){
        if((e&1) == 1) ans = (ans*b)%m;
        e >>= 1;
        b = (b*b) % m; 
    }

    return ans;
}

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

    ll ans = 0;
    ans = comp(2, n, MOD)-1;
    ans %= MOD;
    ll tmp = comb(n, a)%MOD;
    ans -= comb(n, a)%MOD;
    ans %= MOD;
    ans -= comb(n, b)%MOD;
    ans %= MOD;
    dump(comb(n,b));

    if(b==n){

    }

    if(ans<0) cout << ans+MOD << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	long long a=1;
	for (int i=2;i<=n;i++) a=a*i%1000000007;
	cout << a;
}

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

struct Card{
  char suit;
  char value;
};


int main(){
  struct Card C1[N], C2[N],p;
  int n,i,j,mini,l=0;
  char ch;

  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
  }
  for(i=0;i<n;i++){
    C2[i] = C1[i]; 
  }
  /*Bubble*/
  for(i=0;i<n;i++){
      for(j=n-1;j>i;j--){
	if(C1[j].value < C1[j-1].value){
          p = C1[j];
          C1[j] = C1[j-1];
          C1[j-1] = p;
	}
      }
  }
  /*Selection*/
    for(i=0;i<n;i++){
      mini = i;
      for(j=i;j<n;j++){
	if(C2[j].value < C2[mini].value)
	 mini = j;
       }
       p = C2[i];
       C2[i] = C2[mini];
       C2[mini] = p;
  }
    for(i=0;i<n;i++){
      printf("%c%c",C1[i].suit,C1[i].value);
      if(i != n-1)
	printf(" ");
      if(i == n-1)
	printf("\n");
    }
    printf("Stable\n");

    for(i=0;i<n;i++){
      printf("%c%c",C2[i].suit,C2[i].value);
      if(i != n-1)
	printf(" ");
      if(i == n-1)
	printf("\n"); 
    }
    for(i=0;i<n;i++){
      if(C1[i].suit != C2[i].suit)
	l = 1;
    }
    if(l==1)
      printf("Not stable\n");
    else
      printf("Stable\n");
    return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  rep(i, K) {
    if (i % 2 == 0) {
      B += A / 2;
      A /= 2;
    } else {
      A += B / 2;
      B /= 2;
    }
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 3164
#include <cstdio>
#include <iostream>

using namespace std;

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

	bool ok = false;

	for(int i = 0; i < s.size(); ++i) {
		if(s[i] == '7') {
			ok = true;
		}
	}

	if(ok) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

	return 0;
}


Measured memory_bytes: 3132
#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){
while(x->left!=NIL){
x=x->left;
}
return x;
}

Node treeSearch(Node u, int k){  
if(u==NIL || k==u->key){
return u;
}
if(k<u->key){
return treeSearch(u->left,k);
}
 else{
return treeSearch(u->right,k);
}

}

Node treeSuccessor(Node x){
Node y;  
if(x->right!=NIL){
return treeMinimum(x->right);
}
y=x->parent;
while(y!=NIL && x==y->right){
x=y;
y=y->parent;
return y;
 }
}

void treeDelete(Node z){
Node y; // node to be deleted
Node x; // child of y
if(z->left==NIL || z->right==NIL){
y=z;
}
 else{
y=treeSuccessor(z);
}
if(y->left!=NIL){
x=y->left;
}
 else{
x=y->right;
}
if(x!=NIL){
x->parent=y->parent;
}
if(y->parent==NIL){
root=x;
}
 else if(y==y->parent->left){
y->parent->left=x;
}
 else{
y->parent->right=x;
}
if(y!=z){
z->key=y->key;
}


}

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){
inorder(u->left);
printf(" %d",u->key);
inorder(u->right);
}
}
void preorder(Node u){
if(u!=NIL){
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: 19364
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    int z;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0)break;
        if(x>y){
            z=x;
            x=y;
            y=z;
        }
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3072
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// get a integer
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();
		
		int whiteRegion; // initially
		int W_MIN = 0;
		int W_MAX = W;
		int H_MIN = 0;
		int H_MAX = H;
		
		for (int i = 0; i < N; i++) {
			int plot_W = sc.nextInt();
			int plot_H = sc.nextInt();
			int a = sc.nextInt(); // 1 ~ 4
			
			if (a == 1) {
				if ( plot_W >= W_MAX) {
					W_MIN = 0;
					W_MAX = 0;
				}		
				else if ( plot_W > W_MIN && plot_W < W_MAX )
					W_MIN = plot_W;
				//System.out.println("W_MIN1 = " + W_MIN);
				//W -= plot_W; 
			}
			else if (a == 2) {
				if ( plot_W <= W_MIN) {
					W_MIN = 0;
					W_MAX = 0;
				}
				else if ( plot_W > W_MIN && plot_W < W_MAX )
					W_MAX = plot_W;
				//System.out.println("W_MAX2 = " + W_MAX);
				//W = plot_W;
			}
			else if (a == 3) {
				if ( plot_H >= H_MAX) {
					H_MIN = 0;
					H_MAX = 0;
				}
				else if ( plot_H > H_MIN && plot_H < H_MAX )
					H_MIN = plot_H;
				//System.out.println("H_MIN = " + H_MIN);
				//H -= plot_H;
			}
			else {
				if ( plot_H <= H_MIN) {
					H_MIN = 0;
					H_MAX = 0;
				}
				else if ( plot_H > H_MIN && plot_H < H_MAX )
					H_MAX = plot_H;
				//System.out.println("H_MAX = " + H_MAX);
				//H = plot_H;
			}
		}
		whiteRegion = Math.abs(W_MAX - W_MIN) * Math.abs(H_MAX - H_MIN);
		System.out.println(whiteRegion);
		sc.close();
	}
}

Measured memory_bytes: 10316
local s=io.read()

if #s==26 then
    for i=#s,2,-1 do
        if s:sub(i,i)>s:sub(i-1,i-1) then
            s=s:sub(1,i-1)
            break
        end
    end
    if #s==26 then
        print(-1)
        return
    else
        for i=97,122 do
            local c=string.char(i)
            if not s:find(c) and s:sub(#s,#s)<c then
                print(s:sub(1,#s-1)..c)
                break
            end
        end
    end
elseif #s==1 then
    for i=97,122 do
        local c=string.char(i)
        if s<c then
            print(c)
            break
        end
    end
else
    for i=97,122 do
        local c=string.char(i)
        if not s:find(c) then
            print(s..c)
            break
        end
    end
end

Measured memory_bytes: 256
N = int(input())
AB = []
CD = []
for i in range(N):
    AB.append(list(map(int,input().split())))
for i in range(N):
    CD.append(list(map(int,input().split())))

CD.sort(key=lambda x:x[0])

cnt = 0
RedDone = [0]*N
for i in range(N):
    Blue = CD[i]
    box = []
    for j in range(N):
        Red = AB[j]
        if Red[0]<Blue[0] and Red[1]<Blue[1] and RedDone[j]==0:
            box.append([Red[0],Red[1],j])
    if len(box)>0:
        maxy = -1
        cand = -1
        for k in range(len(box)):
            if RedDone[box[k][2]]==0:
                if maxy<box[k][1]:
                    cand = box[k][2]
                    maxy = box[k][1]
        cnt += 1
        RedDone[cand]=1
print(cnt)


Measured memory_bytes: 69956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,k,i,j;
  	string s;
  	cin>>n>>s>>k;
  
  	for(i=0;i<n;i++){
      cout<<(s[i]!=s[k-1]?'*':s[i]);
             
    }

  	
}

Measured memory_bytes: 256
n=int(input())
w1=input()
w2=input()
count=1
now=0
frag=True
while now<n:
  if w1[now]==w2[now]:
    if now==0:
      count*=3
    else:
      if frag:
        count*=2
      else:
        count*=1
        frag=True
    now+=1
  else:
    if now==0:
      count*=6
    else:
      if frag:
        count*=2
      else:
        count*=3
    now+=2
    frag=False
print(count%(10**9+7))
      

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K;
int x[100010], y[100010];
char c[100010];
int w[4010][4010], b[4010][4010];

int calcW(int p, int q, int r, int s) {
  int res = w[r][s];
  if (p != 0 && q != 0) res += w[p-1][q-1];
  if (p != 0) res -= w[p-1][s];
  if (q != 0) res -= w[r][q-1];
  return res;
}
int calcB(int p, int q, int r, int s) {
  int res = b[r][s];
  if (p != 0 && q != 0) res += b[p-1][q-1];
  if (p != 0) res -= b[p-1][s];
  if (q != 0) res -= b[r][q-1];
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  int K2 = K*2;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> c[i];
    x[i] %= K2;
    y[i] %= K2;
    if (c[i] == 'W') {
      w[y[i]][x[i]]++;
      w[y[i]+K2][x[i]]++;
      w[y[i]][x[i]+K2]++;
      w[y[i]+K2][x[i]+K2]++;
    } else {
      b[y[i]][x[i]]++;
      b[y[i]+K2][x[i]]++;
      b[y[i]][x[i]+K2]++;
      b[y[i]+K2][x[i]+K2]++;
    }
  }
  for (int i = 0; i < 2*K2; i++) {
    for (int j = 1; j < 2*K2; j++) {
      w[i][j] += w[i][j-1];
      b[i][j] += b[i][j-1];
    }
  }
  for (int j = 0; j < 2*K2; j++) {
    for (int i = 1; i < 2*K2; i++) {
      w[i][j] += w[i-1][j];
      b[i][j] += b[i-1][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < K2; i++) {
    for (int j = 0; j < K2; j++) {
      ans = max(ans, calcW(i, j, i+K-1, j+K-1) + calcW(i+K, j+K, i+2*K-1, j+2*K-1) + calcB(i+K, j, i+2*K-1, j+K-1) + calcB(i, j+K, i+K-1, j+2*K-1));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 126592
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	H, W := nextInt(), nextInt()
	h, w := nextInt(), nextInt()
	fmt.Println((H - h) * (W - w))
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define ROOP() while (true)

int main(){
    iostream::sync_with_stdio(false);
    
    int N;
    cin >> N;
    int a[300000];
    int sorted[300000];
    for(int i=0; i<N; i++){
        cin >> a[i];
        sorted[i] = a[i];
    }
    sort(sorted, sorted+N);

    int wrong = 0;
    for(int i=0; i<N; i++){
        if(a[i] != sorted[i]) wrong++;
    }
    if(wrong == 0){
        cout << 0 << endl;
        return 0;
    }

    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        int x,y;
        cin >> x >> y;
        x--;
        y--;

        if(a[x] != sorted[x]) wrong--;
        if(a[y] != sorted[y]) wrong--;
        swap(a[x],a[y]);
        if(a[x] != sorted[x]) wrong++;
        if(a[y] != sorted[y]) wrong++;

        if(wrong == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 5476
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
 int main(){
      int n;
      cin >> n;
      vector <int> d(n);
      rep(i,n) cin >> d[i];
      sort(d.begin(), d.end());
      int ans = d[n/2] - d[n/2-1];
      cout << ans << endl;
     return 0;
 }

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static ArrayList<ArrayList<Edge>> g = new ArrayList<>();

  public static void main(String[] args) {
    int N = sc.nextInt();
    int M = sc.nextInt();
    for (int i = 0; i < N; i++) {
      g.add(new ArrayList<>());
    }
    for (int i = 0; i < M; i++) {
      int U = sc.nextInt() - 1;
      int V = sc.nextInt() - 1;
      int S = sc.nextInt();
      g.get(U).add(new Edge(V, S));
      g.get(V).add(new Edge(U, S));
    }
    final long INF = (long) 1e18;
    long[][] v = new long[2][N];
    for (long[] a : v) {
      Arrays.fill(a, INF);
    }
    ArrayList<Integer> cur = new ArrayList<>();
    cur.add(0);
    v[0][0] = 0;
    for (int i = 1; !cur.isEmpty(); i ^= 1) {
      ArrayList<Integer> next = new ArrayList<>();
      for (int c : cur) {
        for (Edge e : g.get(c)) {
          long nv = e.s - v[i ^ 1][c];
          if (v[i][e.to] != INF) {
            if (v[i][e.to] != nv) {
              System.out.println(0);
              return;
            }
            continue;
          }
          v[i][e.to] = nv;
          next.add(e.to);
        }
      }
      cur = next;
    }
    if (v[1][0] != INF) {
      if (v[1][0] % 2 != 0 || v[1][0] <= 0) {
        System.out.println(0);
      } else {
        long x = v[1][0] / 2;
        for (int i = 0; i < N; i++) {
          if (v[1][i] - v[0][i] != x * 2) {
            System.out.println(0);
            return;
          }
          if (x + v[0][i] <= 0) {
            System.out.println(0);
            return;
          }
        }
        System.out.println(1);
      }
    } else {
      long min = 1;
      long max = INF;
      for (int i = 0; i < N; i++) {
        if (v[0][i] != INF) {
          min = Math.max(min, -v[0][i] + 1);
        } else {
          max = Math.min(max, v[1][i] - 1);
        }
      }
      System.out.println(Math.max(0, max - min + 1));
    }
  }


  static class Edge {
    int to, s;

    public Edge(int to, int s) {
      this.to = to;
      this.s = s;
    }
  }
}


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

using namespace std;
int arr[4];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin>>d;
    
    if(d==22)
        cout<<"Christmas Eve Eve Eve";
    else if(d==23)
        cout<<"Christmas Eve Eve";
    else if(d==24)
        cout<<"Christmas Eve";
    else 
        cout<<"Christmas";

    return 0;
}


Measured memory_bytes: 256
h, w, d = gets.strip.split.map(&:to_i)
a = h.times.map { gets.strip.split.map(&:to_i) }
q = gets.strip.to_i
lr = readlines.map {|line| line.strip.split.map(&:to_i) }

point_hash = {}
a.each_with_index do |line, i|
  line.each_with_index do |point, j|
    point_hash[point] = [i, j]
  end
end

cum_d = [0]*(w*h+1)
(d+1..h*w).each do |i|
  s = point_hash[i-d]
  g = point_hash[i]
  cum_d[i] = cum_d[i-d] + (s[0] - g[0]).abs + (s[1] - g[1]).abs
end

lr.each do |l, r|
  p cum_d[r]-cum_d[l]
end



Measured memory_bytes: 51604
#include<stdio.h>
#include<iostream>

using namespace std;

#define min(a,b) ((a<b)?a:b)

int main(void){
    int n,m,i,j,from,to;
    long long int a,b,c,t[100000],ans=0LL,add;
    scanf("%d%d",&n,&m);
    fill(t,t+n,0LL);
    n--;
    scanf("%d",&from);
    from--;
    for(i=1; i<m; i++){
        scanf("%d",&to);
        to--;
        if(from<to){
            for(j=from; j<to; j++){
                t[j]++;
            }
        }else{
            for(j=to; j<from; j++){
                t[j]++;
            }
        }
        from = to;
    }
    for(i=0; i<n; i++){
        scanf("%lld%lld%lld",&a,&b,&c);
        add=min(a*t[i],b*t[i]+c);
        ans+=add;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1972
#include <algorithm>
#include <bitset>
#include <complex>
#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>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, M;
        cin >> N >> M;

        auto tapi = [](int n) {
            return n * (n - 1) / 2;
        };

        Int ans = tapi(N) + tapi(M);
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=100005;
///Code begin..................................................................


int main ()
{
    int a, b;
    cin>>a>>b;
    int x=1;
    FOR(i,1,a) {
        if (x<=b) x<<=1;
        else x+=b;
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 256
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var K = one[1];
  var list = next();
  var count = 0;
  for(var i = 1; i < N; i++){
    if(list[i - 1] == list[i]){
      count++;
    }
  }
  myout(Math.min(N - 1, count + (K * 2)));
}

Measured memory_bytes: 7372
<?php
	$stdin = explode(" ", trim(fgets(STDIN)));
	$d = floor($stdin[0] / $stdin[1]);
	$r = $stdin[0] % $stdin[1];
	$f = sprintf("%f", $stdin[0] / $stdin[1]);
	echo $d . " " . $r . " " . $f . PHP_EOL;

Measured memory_bytes: 15232
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) {
      break;
    }
    vector<int> a(n);
    vector<int64_t> s(n + 1);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s[i + 1] = s[i] + a[i];
    }
    int64_t ans = 0;
    for (int i = 0; i < n - k + 1; i++) {
      ans = max(ans, s[i + k] - s[i]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3884
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	static Tree tree;
	static boolean[] visited;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int q = sc.nextInt();
		tree = new Tree(n);
		for (int i = 0; i < n - 1; i++) {
			tree.union(sc.nextInt() - 1, sc.nextInt() - 1);
		}
		for (int i = 0; i < q; i++) {
			tree.node[sc.nextInt() - 1].value += sc.nextInt();
		}
		visited = new boolean[n];
		visited[0] = true;
		dfs(0);
		for (int i = 0; i < n - 1; i++) {
			System.out.print(tree.node[i].value + " ");
		}
		System.out.println(tree.node[n - 1].value);
	}
	static void dfs(int n) {
		visited[n] = true;
		for (int key : tree.node[n].list) {
			if (!visited[key]) {
				tree.node[key].value += tree.node[n].value;
				dfs(key);
			}
		}
	}
}

class Node {
	ArrayList<Integer> list;
	int value;
	Node() {
		list = new ArrayList<>();
		value = 0;
	}
}

class Tree {
	Node[] node;
	Tree(int n) {
		node = new Node[n];
		for (int i = 0; i < n; i++) {
			node[i] = new Node();
		}
	}
	void union(int n, int m) {
		node[n].list.add(m);
		node[m].list.add(n);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 145064
# -*- coding: utf-8 -*-

N, K = map(int, input().split(" "))
c = 0
 
if K != 0:
    for b in range(K+1, N+1):
        r = N % b
        p = N // b
        s = p * (b-K)
        t = max(0, r - (K - 1))
        c += (s + t)
        
else:
    c = N ** 2

print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Fraction{int numer,denom;};
Fraction add(Fraction f1,Fraction f2){
	Fraction f = {f1.numer*f2.denom+f2.numer*f1.denom , f1.denom*f2.denom};
	return f;
}

int p,q,a,n,cnt;

void solve(Fraction f,Fraction f1,int depth){
	Fraction next;
	while(1){
		next = add(f,f1);
		if(q*next.numer <= p*next.denom)break;
		f1.denom++;
	}
	if(next.denom>a)return;
	if(q*next.numer == p*next.denom){
		cnt++;
		f1.denom++;
	}
	while(1){
		Fraction tmp = {n-depth,f1.denom};
		tmp = add(f,tmp);
		if(q*tmp.numer < p*tmp.denom)return;
		next = add(f,f1);
		if(next.denom>a)return;
		solve(next,f1,depth+1);
		f1.denom++;
	}
}

int main(void){
	while(cin>>p>>q>>a>>n,p|q|a|n){
		cnt=0;
		Fraction f = {0,1}, f1 = {1,1};
		solve(f,f1,0);
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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 ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int a;
   int cnt = 0;
   bool colors[8];
   memset(colors, false, sizeof(colors));
   for (int i = 0; i < N; i++) {
      cin >> a;
      int c = a / 400;
      if (c >= 8) cnt++;
      else colors[c] = true;
   }
   int ans = 0;
   for (int i = 0; i < 8; i++) {
      if(colors[i]) ans++;
   }
   if (ans == 0) cout << 1 << " " << cnt << endl;
   else cout << ans << " " << ans + cnt << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		String s=sc.next();
		String t=sc.next();
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		String c=sc.next();
		if(s.equals(c)){
			a--;
		}
		else if(t.equals(c)){
			b--;
		}
		
		System.out.println(a+" "+b);
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, k;
    cin >> n >> k;
    vector<P> d;
    rep(i, 0, n){
        int a, b;
        cin >> a >> b;
        d. push_back(P(a, b));
    } 
    sort(all(d));
    int ans = -1;
    int now = 0;
    rep(i, 0, n){
        if(now + d[i].second >= k){
            cout << d[i].first << endl;
            return 0;
        }
        now += d[i].second;
    }
}

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

using namespace std;

int main(){
  
  int x,y;
  cin>>x>>y;

  if(x==y) cout<<"Draw"<<endl;
  else if(min(x,y)!=1){
    if(x>y) cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
  }
  else if(min(x,y)==1){
    if(x>y) cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
  }

}


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

int main()
{
 	string s;
  	cin>>s;
  	int k = s.length();
  	int remMatches=15-k;
  	int count=0;
  	for(int i=0; i<=k-1; i++)
    {
     	if(s[i]=='o')
          	count++;
    }
  	if(count+remMatches>=8)
      	cout<<"YES";
 	else
      	cout<<"NO";
  
  	return 0;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  long long n, a, b; cin >> n >> a >> b;
  long long res;
  if (n == 1) res = a != b ? 0 : 1;
  else if(a <= b) res = (n - 2) * (b - a) + 1;
  else res = 0;
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
a=[]
for i in range(H):
    s = input()
    a.append(s)

ans = []
S=""
for i in range(W+2):
    S=S+"#"
ans.append(S)
for i in range(H):
    s = "#"
    for j in range(W):
        s = s+a[i][j]
    s = s+"#"
    ans.append(s)
ans.append(S)
for i in range(len(ans)):
    print(ans[i])

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

int main(){
  uint N;
  cin >> N;
  
  unsigned long long result = 0;
  for(uint a = 1; a < N; a++){
    uint b = (N - 1) / a;
    result += b;
  }  
  cout << result;
  return 0;
}

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

vector<int> d;
bool is_ok(int money){
    while(money){
        for(int elem: d){
            if(money % 10 == elem) return false;
        }
        money /= 10;
    }

    return true;
}

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

    int n, k;
    cin >> n >> k;
    d.resize(k);
    for(int i = 0; i < k; ++i) cin >> d[i];

    int money = n;
    while(1){
        if(is_ok(money)){
            cout << money << endl;
            return 0;
        }

        ++money;
    }

    return 0;
}

Measured memory_bytes: 3596
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=41;

int main()
{
	int n,p;

	scn(n); scn(p);

	string s;

	cin>>s;

	vector<int> fa(p,0);

	int pwr[n];

	pwr[0]=1;

	rep(i,1,n)
	pwr[i]=(1LL*pwr[i-1]*10)%p;

	int rem=0;

	fa[0]=1;

	ll ans=0;

	if(p==2 or p==5)
	{
		rep(i,0,n)
		{
			int num=(s[i]-'0');

			if(num%p==0)
			ans+=(i+1);
		}

		lpri(ans); return 0;
	}

	//if p is co-prime with 10 then only we can go with this approach, otherwise we have to 
	//seperately check for those primes, which we have done above.

	rep(i,0,n)
	{
		rem=(rem+(pwr[n-1-i]*(s[i]-'0'))%p)%p;

		ans+=fa[rem];

		fa[rem]++;
	}

	lpri(ans);
	
    return 0;
}


Measured memory_bytes: 1284
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
int a[222222];
int ia[222222];
int main()
{
	int n=io::F();
	for(register int i=1;i<=n;++i)a[i]=io::F();
	for(register int i=1;i<=n;++i)ia[a[i]]=i;
	int ans=1;
	int now=1;
	for(register int i=2;i<=n;++i)
		if(ia[i-1]<ia[i])++now,cmax(ans,now);
			else now=1;
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

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

int a[100000];

int main()
{
	int n;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	ans=gcd(a[0],a[1]);
	for(int i=2;i<n;i++)
		ans=gcd(a[i],ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

int main(){
    int N;
    cin >> N;
    for(int i = 1;i < 10;i++){
        if(N%i == 0 && N/i < 10)    {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256