akhauriyash/Code-Regression huggingface dataset:
import Data.IORef
import Control.Monad
 
main :: IO()
main = getLine >> getContents >>= solve.map read.lines >>= print
 
solve :: [Int] -> IO Int
solve (x:y:xs) = do
                  a <- newIORef (y - x)
                  b <- newIORef (min x y)
                  forM_ xs $! \z -> do
                    a' <- readIORef a
                    b' <- readIORef b
                    when (z - b' > a') $! writeIORef a (z - b')
                    when (z < b')      $! writeIORef b z
                  readIORef a

Measured memory_bytes: 5576
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  cout << (N-1)/2;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll a, b, k;
  cin >> a >> b >> k;

  if (k > a) {
    b = max(0LL, b-(k-a));
  }
  a = max(0LL, a-k);

  cout <<a << " " <<  b << endl;
}


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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    ll L, R; cin >> L >> R;

    if (R - L >= 2019) cout <<  0 << endl;
    else
    {
        const int n = R-L;
        ll tmp = INF;
        for(ll i=L; i<R+1; i++)
        {
            for(ll j=L; j<R+1; j++)
            {
                if (i>j)
                {
                    tmp = min((ll)tmp, ((i%2019)*(j%2019))%2019);
                }
            }
        }
        cout << tmp << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
int main(void){
    string S, T;
    char temp;
    
    cin >> S;
    cin >> T;
    
    //文字数が違ったらOUT
    if(S.length() != T.length()){
        cout << "No" << endl;
        exit(0);
    }
    
    for(int i = 0; i < S.length(); i++){
        //比較
        if(equal(S.begin(), S.end(), T.begin())){
            cout << "Yes" << endl;
            exit(0);
        }
        //回転操作
        temp = S[S.length() - 1];
        for(int j = S.length() - 1; j > 0; j--){
            S[j] =  S[j - 1];
        }
        S[0] = temp;
    }
    
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


//naosu
long int gcd(long int a,long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


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


long int f(long int n,long int c,long int d){
  long int cnt=n/c+n/d-n/lcm(c,d);
  return n-cnt;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int MOD=1e9+7; 
  long int kai[2000000];
  long int rekai[2000000];
  
  kai[0]=1;
  kai[1]=1;
  rekai[0]=1;
  rekai[1]=1;
  for(int i=2;i<2000000;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=MOD;

    rekai[i]=rekai[i-1]*modinv(i,MOD);
    rekai[i]%=MOD;
  }
  

  long int n,a,b;
  scanf("%ld%ld%ld",&n,&a,&b);

  long int ans=modpow(2,n,MOD);
  ans+=MOD-1;
  ans%=MOD;

  long int disA=1;
  for(long int i=n;i>n-a;i--){
    disA*=i;
    disA%=MOD;
  }
  
  disA*=rekai[a];
  disA%=MOD;
  
  ans-=disA;
  ans+=MOD;
  ans%=MOD;

  long int disB=1;
  for(long int i=n;i>n-b;i--){
    disB*=i;
    disB%=MOD;
  }
  
  disB*=rekai[b];
  disB%=MOD;  

  ans-=disB;
  ans+=MOD;
  ans%=MOD;

  printf("%ld\n",ans);

  return 0;
}

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

using namespace std;

long long INF=1e15;

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

    int n;
    cin>>n;

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

    vector<long long> b(n+1);
    b[0]=0;

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

    sort(b.begin(),b.end());

    long long ans=0,t=1;

    for(int i=0;i<n;i++){
        if(b[i]==b[i+1])t++;
        else{
            ans+=t*(t-1)/2;
            t=1;
        }
    }

    ans+=t*(t-1)/2;

    cout<<ans<<endl;

}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, m;

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

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<numeric>
#include<cmath>
#include<climits>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long int> card(n);

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

    long long int min = INT_MAX;
    long long int tmp = 0;
    for(int i = 0; i < n - 1; i++){
        tmp += card[i];
        long long int ans = fabs(tmp - (sum - tmp));
        if(min > ans){
            min = ans;
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mxsize (int)1e6
#define pb push_back
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
void yn(bool check){
    if(check)	cout<<"YES\n";
    else		cout<<"NO\n";
}
ll a[200005];
bool isvalid(ll ans,ll k,ll n){
    for(int i=0;i<n;i++){
        k-=ceil(1.0*a[i]/ans)-1;
    }
    return k>=0;
}
void fun(){
    ll n,k;
    cin>>n>>k;
    fi(0,n) cin>>a[i];
    int l=1,r=(int)1e9+100,ans;
    while(l<=r){
        ll mid=l+(r-l)/2;
        if(isvalid(mid,k,n)){
            r=mid-1;
            ans=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<ans<<"\n";

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/ATOM/input.txt", "r", stdin);
        freopen("/ATOM/output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t--){
        fun();
    }
}

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

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

  string ans;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == 0) {
      if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
        ans = "Yes";
      }
      else {
        ans = "No";
        break;
      }
    }
    if (i % 2 == 1) {
      if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
        ans = "Yes";
      }
      else {
        ans = "No";
        break;
      }
    }
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int x; cin >> x;
    int cnt = 1;
    while(1){
        if(cnt * (cnt+1) / 2 >= x){
            cout << cnt << endl;
            return 0;
        }
        cnt++;
    }
    return 0;
}


Measured memory_bytes: 256
var
	K:Longint;
	L,R,M:int64;
function check(T:int64):Longint;
var
	dp:Array[1..15,0..1,0..9]of Longint;
	dpz:Array[1..15,0..1]of Longint;
	S:String;
	ls,i,j,k,l,nj,lim,sum,llim,rlim:Longint;
begin
	S:='';
	while T>0 do begin
		S:=Chr(T mod 10+48)+S;
		T:=T div 10;
	end;
	ls:=length(S);
	for i:=1 to ls+1 do for j:=0 to 1 do begin
		for k:=0 to 9 do dp[i,j,k]:=0;
		dpz[i,j]:=0;
	end;
	dpz[1,0]:=1;
	for i:=1 to ls do begin
		for j:=0 to 1 do begin
			if j=0 then lim:=ord(S[i])-48 else lim:=9;
			inc(dpz[i+1,1],dpz[i,j]);
			for l:=1 to lim do begin
				nj:=j;
				if l<lim then nj:=1;
				inc(dp[i+1,nj,l],dpz[i,j]);
			end;
			for k:=0 to 9 do begin
				llim:=k-1;if llim<0 then llim:=0;
				rlim:=k+1;if rlim>lim then rlim:=lim;
				for l:=llim to rlim do begin
					nj:=j;
					if l<lim then nj:=1;
					inc(dp[i+1,nj,l],dp[i,j,k]);
				end;
			end;
		end;
	end;
	sum:=0;
	for k:=0 to 9 do for i:=0 to 1 do begin
		inc(sum,dp[ls+1,i,k]);
	end;
	check:=sum;
end;
begin
	read(K);
	L:=0;
	R:=3234566667;
	while R-L>1 do begin
		M:=(L+R)div 2;
		if check(M)>=K then R:=M else L:=M;
	end;
	writeln(R);
end.


Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define max_n 1000000

int main(void) {

  int x;
  while(cin >> x){


    bool array[max_n];

    for(int i = 0; i < max_n; i++) {
      array[i] = true;
    }

    array[0] = false;
    array[1] = false;
    for(int i = 2; i < max_n; i++) {
      for(int j = 2; j < max_n; j++) {
        if(i * j > max_n) break;
        array[i * j] = false;
      }
    }

    int count_sosu = 0;

    for(int i = 0; i <= x; i++) {
      if(array[i] == true) count_sosu++;
    }

    cout << count_sosu << endl;
  }
  return 0;
}



Measured memory_bytes: 4064
#include <cstdio>
bool seat[100005];
int main() {
	int n, l, r, cnt = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d %d", &l, &r);
		for(int j = l; j <= r; j++) {
			if(!seat[j]) {
				cnt ++;
				seat[j] = 1;
			}
		}
	} 
	printf("%d\n", cnt);
	return 0;
} 

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

n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = ["" for _ in range(m)]
x = ["" for _ in range(m)]
for i in range(m):
    p[i],x[i] = map(int, input().split())

for drink in range(m):
    id = p[drink]
    
    ans = 0
    for i in range(n):
        if i+1 == id:
            ans += x[drink]
        else:
            ans += t[i]
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; i++)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define ll long long
#define N 100011
int a, b, k;
void playa() {
        if (a & 1) {
                a--;

        }
        a >>= 1;
        b += a;
}
void playb() {
        if (b & 1) {
                b--;
        }
        b >>= 1;
        a += b;
}
int main() {
        cin >> a>> b >> k;
        int i = 0;
        while (i++ < k) {
                if (i & 1) playa();
                else playb();
        }
        cout << a<< " "<< b;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
// " ", ' '
// std::string str;
// str = std::to_string(int i);

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N, K; cin >> N >> K;
	string S; cin >> S;

	int gp = 0;
	rep(i, N-1) {
		if(S.at(i) == S.at(i+1)) gp += 1;
	}

	int ans;
	ans = min(gp+2*K, N-1);

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


Measured memory_bytes: 512
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");



string a,b;
cin>>a>>b;
int ans=0;
forn(i,a.size())if(a[i]!=b[i])ans++;

cout<<ans;
    return 0;
  }


Measured memory_bytes: 3808
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll l,r,d;
    cin>>l>>r>>d;
    ll x=((l-1)/d),y=(r/d);
    cout<<y-x; 
    subt;
    return 0;
}

Measured memory_bytes: 3728
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))

min_dif = 1e10
ans = 0

for i in range(n):
    dif = abs(t - h[i]*0.006 -a)
    if dif < min_dif:
        min_dif = dif
        ans = i+1

print(ans)


Measured memory_bytes: 38256
K = int(input())
Seq = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(',')
print(Seq[K-1])

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
int n, m, i, j, k, t, a, b;
int main(){
	cin>>n>>a>>b;
	if((b-a)%2==0) cout<<"Alice";
	else cout<<"Borys";
	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[100000];

LL ans = 1;

void solve(){
	sort(A,A+N);
	if(N%2==0){
		LL prev_num = -1;
		for(int i=0;i<N/2;i++){
			if(A[2*i]==A[2*i+1] && A[2*i]==prev_num+2){
				prev_num = A[2*i];
				ans = (ans*2LL)%mod;
				continue;
			}
			ans = 0;
			return;
		}
	}
	if(N%2==1){
		if(A[0]!=0) return;
		LL prev_num = 0;
		for(int i=0;i<N/2;i++){
			if(A[2*i+1]==A[2*i+2] && A[2*i+1]==prev_num+2){
				prev_num = A[2*i+1];
				ans = (ans*2LL)%mod;
				continue;
			}
			ans = 0;
			return;
		}
	}
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

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

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    while(cin >> s){
        string ans;
        for (int i = 0; i < s.size(); ++i) {
            if(s[i] == '@') {
                ans += string(s[i+1]-'0', s[i+2]);
                i += 2;
            }else {
                ans += s[i];
            }
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3152
import java.util.Scanner;

class Main {

    public static long euclid (long a, long b) {
	if (b == 0) {
	    return a;
	}
	else {
	    return euclid (b, a%b);
	}
    }
    
    public static void main (String args[]) {
	Scanner scan = new Scanner(System.in);
	long a, b, G, L;

	while (scan.hasNext()) {
	    a = scan.nextLong();
	    b = scan.nextLong();

	    if (a < b) {
		long tmp = a;
		a = b;
		b = tmp;
	    }

	    G = euclid (a, b);
	    L = a*b/G;

	    System.out.println(G+" "+L);
	}
    }
}

Measured memory_bytes: 25928
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N,X,Y = map(int, input().split())
    print(min(X,Y),max(0,X + Y - N))
    
if __name__ == '__main__':
    solve()


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

using namespace std;

int main () {

    int n;
    cin >> n;
    vector<int> A(n), B(n-1);
    for(int i=0; i<n-1; i++) cin >> B[i];

    A[0] = B[0];
    A[1] = B[0];

    for(int i=2; i<n; i++){
        if(B[i-1]<B[i-2])
            A[i-1] = B[i-1], A[i] = A[i-1];
        else
            A[i] = B[i-1];
    }

    int ans = 0;
    for(int i=0; i<n; i++) ans+=A[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

struct UnionFind {
        int n;
        vector<int> parent;
        vector<int> rank;
        vector<int> num;
        int find(int x) {
                if (parent[x] == x) return  x;
                return parent[x] = find(parent[x]);
        }
        UnionFind(int n_) {
                n = n_;
                parent.resize(n);
                for (int i = 0; i < n; i ++) parent[i] = i;
                rank.assign(n, 0);
                num.assign(n, 1);
        }
        void unite(int x, int y) {
                if ((x = find(x)) != (y = find(y))) {
                        if (rank[x] < rank[y]) {
                                parent[x] = y;
                                num[y] += num[x];
                        } else {
                                parent[y] = x;
                                if (rank[x] == rank[y]) rank[x] ++;
                                num[x] += num[y];
                        }
                        n --;
                }
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int get() { return n; }
        int get(int x) { return num[find(x)]; }
};

int main() {
        int n;
        while (scanf("%d", &n), n) {
                UnionFind uf(26);
                vector<int> in_deg(26), out_deg(26);
                for (int i = 0; i < n; i ++) {
                        string s;
                        cin >> s;
                        int a = s[0] - 'a';
                        int b = s.back() - 'a';
                        in_deg[a] ++, out_deg[b] ++;
                        uf.unite(a, b);
                }
                bool ok = true;
                int cnt = 0;
                for (int i = 0; i < 26; i ++) if (in_deg[i] > 0 || out_deg[i] > 0) cnt ++;
                for (int i = 0; i < 26; i ++) {
                        if (in_deg[i] > 0 || out_deg[i] > 0) {
                                if (uf.get(i) != cnt) {
                                        ok = false;
                                        break;
                                }
                        }
                }
                for (int i = 0; i < 26; i ++) ok &= in_deg[i] == out_deg[i];
                puts(ok ? "OK" : "NG");

        }
        return 0;
}

Measured memory_bytes: 3248
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {

    static final String table[] = {"", "Man", "Oku", "Cho", "Kei", 
			     "Gai", "Jo", "Jou", "Ko", "Kan", 
			     "Sei", "Sai", "Gok", "Ggs", "Asg", 
			     "Nyt", "Fks", "Mts"};

    void solve() {

	Scanner sc = new Scanner( System.in );
	
	while (true) {

	    int m = sc.nextInt();
	    int n = sc.nextInt();
	    if ( m == 0 && n == 0 ) break;

	    ArrayList<Integer> aBlock = new ArrayList<Integer>();
	    BigInteger val = BigInteger.valueOf(m).pow(n);
	    BigInteger tts = BigInteger.valueOf(10000);

	    while (val != BigInteger.ZERO) {
		aBlock.add(val.mod(tts).intValue());
		val = val.divide(tts);
	    }

	    for (int i=aBlock.size()-1; i>=0; --i) {
		//mts以上なら自動的に数値を出力 (1,0000MtsとかはMtsが出ない)
		if (i >= table.length) 
		    System.out.print(aBlock.get(i));
		else if (aBlock.get(i) != 0) 
		    System.out.print(aBlock.get(i) + table[i]);
	    }
	    System.out.print("\n");
	}
    }

    public static void main(String[] args) { new Main().solve(); }
    
}



Measured memory_bytes: 26868
#include <stdio.h>

int main(void)
{
    long n;
    long a,b;
    scanf("%ld %ld %ld",&n,&a,&b);
    
    if (n%(a+b) <= a){
        printf("%ld\n",(n/(a+b))*a+n%(a+b));
    }
    else {
        printf("%ld\n",(n/(a+b))*a+a);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    rep(i,h) cin>>s[i];

    int a[h][w],b[h][w];
    rep(i,h){
        int cnt=0;
        rep(j,w){
            if(s[i][j]=='.'){
                cnt++;
                a[i][j]=cnt;
            }
            else{
                a[i][j]=0;
                cnt=0;
            } 
        }
    }
    rep(i,h){
        bool ok=false;
        int tmp=0;
        for(int j=w-1;j>=0;j--){
            if(ok){
                if(a[i][j]!=0){
                    a[i][j]=tmp;
                }
                else{
                    ok=false;
                }
            }
            else{
                if(a[i][j]!=0){
                    ok=true;
                    tmp=a[i][j];
                }
            }
        }
    }

    rep(i,w){
        int cnt=0;
        rep(j,h){
            if(s[j][i]=='.'){
                cnt++;
                b[j][i]=cnt;
            }
            else{
                b[j][i]=0;
                cnt=0;
            } 
        }
    }
    rep(i,w){
        bool ok=false;
        int tmp=0;
        for(int j=h-1;j>=0;j--){
            if(ok){
                if(b[j][i]!=0){
                    b[j][i]=tmp;
                }
                else{
                    ok=false;
                }
            }
            else{
                if(b[j][i]!=0){
                    ok=true;
                    tmp=b[j][i];
                }
            }
        }
    }

    int ans=0;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#') continue;
            ans=max(ans,a[i][j]+b[i][j]-1);
        }
    }
    
    cout<<ans<<endl;

}

Measured memory_bytes: 35584
/**
 * Created by hiramekun at 13:06 on 2019-09-29.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using P = pair<ll, ll>;
const ll ll_inf = ll(1e9) * ll(1e9);

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

struct edge {
    ll from, to, cost;

    edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {};
};

class DAG {
private:
    ll v;
    vector<vector<edge>> table;
    vl d;
public:
    // v: 頂点数
    explicit DAG(ll v) : v(v) {
        table.resize(v);
        d.resize(v, ll_inf);
    }

    void add(ll from, ll to, ll cost = 1) {
        edge e1(from, to, cost);
        table[from].emplace_back(e1);
    }

    // O(e * logv)
    vl dijkstra(ll s) {
        // pairを使っているのは、比較関数を利用するため
        priority_queue<P, vector<P>, greater<>> que;
        d[s] = 0;
        que.push(P(0, s));

        while (!que.empty()) {
            P p = que.top();
            que.pop();
            ll min_v = p.second;
            if (d[min_v] < p.first) continue;
            for (const auto &ele: table[min_v]) {
                if (d[ele.to] > d[min_v] + ele.cost) {
                    d[ele.to] = d[min_v] + ele.cost;
                    que.push(P(d[ele.to], ele.to));
                }
            }
        }
        return move(d);
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    DAG dag(1 << n);

    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        ll s = 0;
        rep(j, b) {
            ll c;
            cin >> c;
            c--;
            s |= 1 << c;
        }

        rep(j, 1 << n) {
            dag.add(j, j | s, a);
        }
    }
    vl ans = dag.dijkstra(0);
    if (ans.back() == ll_inf) cout << -1 << '\n';
    else cout << ans.back() << '\n';

    return 0;
}

Measured memory_bytes: 99072
class UnionFind:
    def __init__(self, n):
        self.rank = [0] * n
        self.parent = [i for i in range(n)]
        self.num = [1] * n


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]


    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.num[y] += self.num[x]
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.num[x] += self.num[y]
        else:
            self.parent[x] = y
            self.rank[y] += 1
            self.num[y] += self.num[x]


n, m = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(m)]

bridge = bridge[::-1]

nc2 = n*(n-1)//2

ans = []

uf = UnionFind(n)

res = 0
for i, (a, b) in enumerate(bridge):
    a -= 1
    b -= 1
    ans.append(nc2 - res)
    if uf.find(a) == uf.find(b):
        pass
    elif uf.num[uf.find(a)] == 1 and uf.num[uf.find(b)] == 1:
        res += 1
    else:
        if uf.num[uf.find(a)] == 1:
            res += uf.num[uf.find(b)] * (uf.num[uf.find(b)] + 1) // 2 - uf.num[uf.find(b)] * (uf.num[uf.find(b)] - 1) // 2
        elif uf.num[uf.find(b)] == 1:
            res += uf.num[uf.find(a)] * (uf.num[uf.find(a)] + 1) // 2 - uf.num[uf.find(a)] * (uf.num[uf.find(a)] - 1) // 2
        else:
            na = uf.num[uf.find(a)]
            nb = uf.num[uf.find(b)]
            res += (na + nb) * (na + nb - 1) // 2 - (na * (na - 1) // 2) - (nb * (nb - 1) // 2)
    uf.merge(a, b)

ans = ans[::-1]
for i in ans:
    print(i)


Measured memory_bytes: 39324
import sys

class MyNode:
    __slots__ = ['prev', 'next', 'val']

    def __init__(self, x):
        self.prev = None
        self.next = None
        self.val = x

class MyLinkList:
    __slots__ = ['head', 'tail']

    def __init__(self):
        self.head = None
        self.tail = None

    def generate(self):
        _node = self.head
        while True:
            if _node is None:
                break
            yield _node.val
            _node = _node.next

    def insert(self, x):
        node = MyNode(x)
        if self.head is None:
            self.head = self.tail = node
        else:
            self.head.prev = node
            node.next = self.head
            self.head = node

    def delete(self, x):
        if self.head.val == x:
            return self.deleteFirst()

        node = self.head.next
        while node.next is not None:
            if node.val == x:
                node.prev.next = node.next
                node.next.prev = node.prev
                # node.prev = None
                # node.next = None
                return True

            node = node.next

        if self.tail.val == x:
            return self.deleteLast()

        return False

    def deleteFirst(self):
        if self.head == self.tail:
            self.head = self.tail = None
            return True

        self.head = self.head.next
        # self.head.prev.next = None
        self.head.prev = None

        return True

    def deleteLast(self):
        if self.head == self.tail:
            self.head = self.tail = None
            return True

        self.tail = self.tail.prev
        # self.tail.next.prev = None
        self.tail.next = None

        return True

def _main():
    link_list = MyLinkList()

    n = int(input())
    
    for i in range(n):
        line = sys.stdin.readline()

        if line[0] == 'i':
            link_list.insert(line[7:-1])
        else:
            if line[6] == 'F':
                link_list.deleteFirst()
            elif line[6] == 'L':
                link_list.deleteLast()
            else:
                link_list.delete(line[7:-1])

    lst = [x for x in link_list.generate()]
    print(" ".join(lst))

if __name__ == '__main__':
    _main()


Measured memory_bytes: 124580
n=int(input())
list_=[]

a = [0]*n
b = [0]*n
c = [0]*n

for i in range(n):
  a[i],b[i],c[i] = map(int, input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)

for i in range(1,n):
  dpa[i] = max(dpb[i-1]+a[i], dpc[i-1]+a[i])
  dpb[i] = max(dpa[i-1]+b[i], dpc[i-1]+b[i])
  dpc[i] = max(dpa[i-1]+c[i], dpb[i-1]+c[i])
  
print(max(dpa[-1], dpb[-1], dpc[-1]))
  

Measured memory_bytes: 33220
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int n,m,k;
int sx,sy,ex,ey;
vector<vector<int> >a;
vector<vector<int> >d;
bool outboard(int x,int y){
	return x<1||x>n||y<1||y>m;
}
int main(){
	cin>>n>>m>>k;
	cin>>sx>>sy>>ex>>ey;
	vector<int>tp(m+10,INF);
	for(int i=1;i<=n+10;i++)d.pb(tp);
	for(int i=1;i<=n+10;i++)a.pb(tp);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c;
			cin>>c;
			a[i][j]=(c=='@');
		}
	}
	queue<pii>pq;
	pq.push(mp(sx,sy));
	d[sx][sy]=0;
	while(pq.size()){
		pii x=pq.front();
		pq.pop();
		int nstep=d[x.F][x.S]+1;
		for(int i=0;i<4;i++){
			for(int j=1;j<=k;j++){
				int tx=x.F+dx[i]*j,ty=x.S+dy[i]*j;
				if(outboard(tx,ty)||a[tx][ty]||d[tx][ty]<nstep)break;
				if(d[tx][ty]>nstep){
					d[tx][ty]=nstep;
					pq.push(mp(tx,ty));
				}
			}
		}
	}
	if(d[ex][ey]==INF)puts("-1");
	else cout<<d[ex][ey]<<endl;
	return 0;
}


Measured memory_bytes: 92644
#include <iostream>

using namespace std;

int main()
{
    int a[31] = { 0, 1, 2, 4 };
    for( int i=4; i<=30; ++i ) {
        a[i] = a[i-1] + a[i-2] + a[i-3];
    }

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

        cout << ( a[n] < 10 ? 1 : (( a[n] / 10 / 365 ) + ( a[n] / 10 % 365 != 0 ) )) << endl;
    }
}

Measured memory_bytes: 1160
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,K=get_i
if K.odd?
    puts (N/K)**3
else
    cnt=0
    (K/2).step(N,K) do|x|
      cnt+=1
    end
    puts (N/K)**3+cnt**3
end

Measured memory_bytes: 14364
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);

int main(){
    int n,a,b,c;
    cin>>n>>a>>b;
    c=a-b;
    int h[n];
    ll l=0, r=0;
    REP(i,n){
        cin>>h[i];
        r=max(r,(h[i]+b-1)/b);
    }
    while(l<r){
        ll m=(l+r)/2;
        ll act=0;
        REP(i,n){
            ll rem=h[i]-m*b;
            act+=(rem<0?0:(rem+c-1)/c);
        }
        if(act>m) l=m+1;
        else r=m;
    }
    cout<<l<<"\n";
    
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int rn = uniform_int_distribution<int>(0, MAXN)(rng);

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

    sort(a,a+n);

    ll res = -1, sum = 0;
    ll p[n];
    int l = 0, r = n-1;
    REP(i,n) {
        p[i++] = a[l];
        if(i >= n) break;
        p[i] = a[r];
        l++, r--;
    }

    FOR(i,1,n-1) {
        sum += abs(p[i-1] - p[i]);
    }
    if(n > 1) sum = max(sum, sum - abs(p[n-2] - p[n-1]) + abs(p[0] - p[n-1]));
    res = max(res, sum);
    sum = 0;

    l = 0, r = n-1;
    if(n > 1) swap(a[0],a[1]);
    REP(i,n) {
        p[i++] = a[l];
        if(i >= n) break;
        p[i] = a[r];
        l++, r--;
    }

    FOR(i,1,n-1) {
        sum += abs(p[i-1] - p[i]);
    }
    if(n > 1) sum = max(sum, sum - abs(p[n-2] - p[n-1]) + abs(p[0] - p[n-1]));
    res = max(res, sum);
    sum = 0;

    l = 0, r = n-1;
    if(n > 1) swap(a[0],a[1]);
    REP(i,n) {
        p[i++] = a[r];
        if(i >= n) break;
        p[i] = a[l];
        l++, r--;
    }

    FOR(i,1,n-1) {
        sum += abs(p[i-1] - p[i]);
    }
    if(n > 1) sum = max(sum, sum - abs(p[n-2] - p[n-1]) + abs(p[0] - p[n-1]));
    res = max(res, sum);
    sum = 0;

    cout<<res;
	
	
	return 0;
}






Measured memory_bytes: 1792
#include <iostream>
#include <cstdint>
#include <algorithm>

using namespace std;

long long mod = 998244353;

long long pow(long long x, long long n) { 
    long long ans = 1;
    while (n > 0) {
    if ((n & 1) == 1) {
        ans = ans * x % mod;
    }
        x = x * x % mod; //一周する度にx, x^2, x^4, x^8となる
        n >>= 1; //桁をずらす n = n >> 1
    }
    return ans;
}


long long F[300050];
long long Finv[300050];



long long combination(long long n, long long r) {
    if (r == 0) return 1;
    return ((F[n] * Finv[n-r]) % mod ) * Finv[r] % mod;
}

int main() {
    F[0] = 1;
    Finv[0] = 1;
    for (int i = 1; i <= 300000; ++i) F[i] = F[i-1] * i % mod;
    for (int i = 1; i <= 300000; ++i) Finv[i] = Finv[i-1] * pow( i,  (long long) mod - 2) % mod;

    
    long long N, A, B, K;
    cin >> N >> A >> B >> K;
    
    long long count = 0;
    for (long long i = 0; i <= N; ++i) {
        long long d = K- i * A;
        if (d >= 0 && d  % B ==0) {
            long long j = d/B;
            if (j <= N) count =  (count + combination(N, i)  * combination(N, j) % mod ) % mod;
        }
    }
    cout << count % mod<< endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)*/
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvp g;
	public:
	P DIJ(int s,int t,vi a){
		priority_queue<pip> q;
		vp d(n,{inf,0});
		d[s]={0,0};
		q.push({{0,0},s});
		while(!q.empty()){
			pip pp=q.top();q.pop();
			P p=pp.first;
			int v=pp.second,A=-p.first,B=-p.second;
			if(d[v]!=make_pair(A,B)) continue;
			for(auto i:g[v]){
				int u=i.first;
				A+=i.second,B+=a[u];
				if(d[u]>make_pair(A,B)){
					d[u]={A,B};
					q.push({{-A,-B},u});
				}
				A-=i.second,B-=a[u];
			}
		}
		return d[t];
	}
	void Init(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){g[s].push_back({t,c});}
};

int n=0,m,T;
map<string,int> mp;
vi id;
Graph g;

int f(){
	string s;
	cin>>s;
	if(mp.find(s)==mp.end()) mp[s]=n++;
	return mp[s];
}

void E(vi a,vi b){
	int S=a.size();
	for(int i=0;i<S-1;i++){
		int u=a[i],v=a[i+1];
		if(u!=v) g.add_edge(id[u]++,id[v],b[i]);
		else g.add_edge(id[u],id[u]+1,b[i]),id[u]++;
	}
	id[a[S-1]]++;
}

int main(){
	cin>>m>>T;
	int s=f(),t=f();
	vvi a(m),b(m);
	for(int i=0;i<m;i++){
		int A;
		cin>>A;
		a[i]=vi(A);
		b[i]=vi(A-1);
		for(int j=0;j<A;j++) a[i][j]=f();
		for(int j=0;j<A-1;j++) cin>>b[i][j];
	}
	vi c(n,1);
	for(int i=0;i<m;i++) for(auto j:a[i]) c[j]+=2;
	int N=0;
	for(auto i:c) N+=i;
	g.Init(N);
	id=vi(n);
	for(int i=1;i<n;i++) id[i]=id[i-1]+c[i-1];
	for(int i=0;i<m;i++){
		E(a[i],b[i]);
		reverse(a[i].begin(),a[i].end());
		reverse(b[i].begin(),b[i].end());
		E(a[i],b[i]);
	}
	vi B(N);
	for(int i=0;i<n;i++){
		B[id[i]]++;
		for(int j=(i?id[i-1]+1:0);j<id[i];j++){
			g.add_edge(j,id[i],T);
			g.add_edge(id[i],j,0);
		}
	}
	P p=g.DIJ(id[s],id[t],B);
	if(p.first==inf) cout<<-1<<endl;
	else cout<<p.first-T<<' '<<p.second-1<<endl;
}


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

#define MaxN 1000000

int prime[MaxN];
int sp[MaxN];

void siv()
{
	prime[0] = 1;
	prime[1] = 1;

	for(long long i = 2; i < MaxN;i++)
	{
		if(!prime[i])
		{
			if(!prime[(i+1)/2])
				sp[i] = 1;
			long long int j = i*i;
			while(j < MaxN)
			{
				prime[j] = 1;
				j+= i;
			}
		}
	}

	for(int i = 1;i < MaxN;i++)
		sp[i] += sp[i-1];
}

int main()
{
	int q;
	cin >> q;
	siv();
	while(q--)
	{
		int l,r;
		cin >> l >> r;
		cout << sp[r] - sp[l-1];
		cout << endl;
	}
	return 0;
}

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

int main(){
  int N,m,l,o,p,q,r,s,t,u,v,w;
  cin >> N;
  
  m = N/100;
  l = N%100;
  o = l/5;
  p = l%5;
  q = p/4;
  r = p%4;
  s = r/3;
  t = r%3;
  u = t/2;
  v = t%2;
  w = o+q+s+u+v;
  if (m >= w){
    cout << 1 << endl;
  }
  else{
  cout << 0 << endl;
  }
    
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 500000
int count;
  
struct node
{
  int key;
  int pare;
  int left;
  int right;
};
  
struct node bi[N];
  
 
  
int main(void)
{
  int n,i;
  int num;
  char comm[10];
  count=0;
  
  for(i=0;i<N;i++)
  {
    bi[i].key = -1;
    bi[i].pare = -1;
    bi[i].left = -1;
    bi[i].right = -1;
  }
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
  {
    scanf("%s",comm);
    if(strcmp(comm,"insert")==0)
    {
      scanf("%d",&num);
      insert(num);
    }
    else if(strcmp(comm,"find")==0)
    {
      scanf("%d",&num);
      find(num);
    }
    else
    {
      print();
    }
  }
  return 0;
}
 
void insert(int z)
{
  int x,y;
  int num=0;
  
  y=-1;
  x=bi[0].key;
  while(1)
  {
    if(x==-1) break;
    y = num;
 
    if(z < x){
      num = bi[num].left;
      if(num!=-1) x = bi[num].key;
      else
      {
        x=-1;
      }
    }
 
    else{
      num = bi[num].right;
      if(num!=-1) x = bi[num].key;
      else
      {
        x=-1;
      }
    }
  }
  bi[count].pare=y;
  bi[count].key=z;
  
  if(y==-1)
  {
    bi[0].key=z;
  }
  else if(z<bi[y].key)
  {
    bi[y].left = count;
  }
  else
  {
    bi[y].right = count;
  }
  
  count++;
}
  
void pre(int now)
{
  printf(" %d",bi[now].key);
  if(bi[now].left!=-1)  pre(bi[now].left);
  if(bi[now].right!=-1)  pre(bi[now].right);
}
  
void in(int now)
{
  if(bi[now].left!=-1) in(bi[now].left);
  printf(" %d",bi[now].key);
  if(bi[now].right!=-1) in(bi[now].right);
}
  
  
void print()
{
  in(0);
  printf("\n");
  pre(0);
  printf("\n");
}
  
void find(int key)
{
  int i=0;
  while(1)
  {
    if(bi[i].key==key)
    {
      printf("yes\n");
      return;
    }
    if(bi[i].pare==-1) break;
    i = bi[i].pare;
  }
  while(1)
  {
    if(bi[i].key<key)
    {
      i=bi[i].right;
      if(i==-1)
      {
        printf("no\n");
        return;
      }
    }
    else
    {
      i=bi[i].left;
      if(i==-1)
      {
        printf("no\n");
        return;
      }
    }
    if(bi[i].key==key)
    {
      printf("yes\n");
      return;
    }
  }
}

Measured memory_bytes: 8428
n = int(input())
a = list(map(int,input().split()))
m = max(a) + 1
li = [0]*m 
for x in a:
    li[x] += 1
ans = 0
for i in range(1,m):
    if li[i]: 
        if li[i]==1: 
            ans += 1 
        for j in range(i,m,i): 
            li[j] = 0
print(ans)

Measured memory_bytes: 116692