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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

const int INF = 1999999999;
const LL INFLL = 999999999999999LL;

Vs split_string(const string &s, char delim){
    Vs elements;
    string item;
    for(char ch : s){
        if(ch == delim){
            if(!item.empty()) elements.pb(item);
            item.clear();
        }else{
            item += ch;
        }
    }
    if(!item.empty()) elements.pb(item);
    return elements;
}

Vi incriment_bn4(Vi n){
    REPD(i,n.size()-1){
        if(n[i]+1>=4 && i>0){
            n[i]=0;
        }else{
            n[i]++;
            break;
        }
    }
    return n;
}

int main(){
    int a,b,q;
    cin>>a>>b>>q;
    Vll s(a),t(b),x(q);
    REP(i,a) cin>>s[i];
    REP(i,b) cin>>t[i];
    REP(i,q) cin>>x[i];

    s.pb(INFLL);
    s.pb(-INFLL);
    sort(ALL(s));

    t.pb(INFLL);
    t.pb(-INFLL);
    sort(ALL(t));

    REP(i,q){
        auto b = lower_bound(ALL(s),x[i]);
        auto d = lower_bound(ALL(t),x[i]);
        LL res = INFLL;
        REP(j,2){
            REP(k,2){
                LL d1 = abs(s[int(b-s.be())-j]-x[i]) + abs(t[int(d-t.be())-k] - s[int(b-s.be())-j]);
                LL d2 = abs(t[int(d-t.be())-k] - x[i]) + abs(s[int(b-s.be())-j]-t[int(d-t.be())-k]);
                res = min({res, d1, d2});
            }
        }
        cout<<res<<endl;
    }

    return 0;
}

Measured memory_bytes: 3680
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    B = [int(c) for c in input().split()]
    cnt = 0
    for i in range(N):
        each_cnt = min(A[i], B[i])
        A[i] -= each_cnt
        B[i] -= each_cnt
        cnt += each_cnt
        if B[i] != 0:
            each_cnt = min(A[i + 1], B[i])
            A[i + 1] -= each_cnt
            B[i] -= each_cnt
            cnt += each_cnt
        else:
            continue
    print(cnt)
            


if __name__ == '__main__':
    main()

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

int a[105];
int main()
{
	int n;
	bool q=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
		if(a[i]%3&&a[i]%5)
		{
			q=true;
			break;
		}
	}
	if(q) printf("DENIED");
	else printf("APPROVED");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  ren(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) ren(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    li n,m;
    cin>>n>>m;
    if(n*2>=m) cout<<m/2<<endl;
    else cout<<(m-2*n)/4+n<<endl;

    return 0;
}


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

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  vector<list<int> > L(n);
  while(q--) {
    int k, t;
    cin >> k >> t;
    if(k == 0) {
      int x;
      cin >> x;
      L[t].insert(L[t].end(), x);
    } else if(k == 1) {
      for(auto it = L[t].begin(); it != L[t].end(); ++it) {
	if(it != L[t].begin()) cout << " ";
	cout << *it;
      }
      cout << endl;
    } else if(k == 2) {
      int s;
      cin >> s;
      L[t].splice(L[t].begin(), L[s]);
      L[s].clear();
      L[s].swap(L[t]);
    } else {
      assert(false);
    }
  }
  return 0;
}



Measured memory_bytes: 18568
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    string S[3];
    rep(i,0,3)cin >> S[i];
    int cnt = 0;
    rep(i,0,N){
        set<char> st;
        st.insert(S[0][i]);
        st.insert(S[1][i]);
        st.insert(S[2][i]);
        cnt += st.size() - 1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import Data.Foldable (traverse_)

main =
  traverse_ printQQ $ do
    x <- [1..9]
    y <- [1..9]
    return (x, y)
  where
  printQQ (x, y) = putStrLn $ show x ++ "x" ++ show y ++ "=" ++ show (x * y)



Measured memory_bytes: 3616
/* 09:32 - 09 */

#include <iostream>
#include <string>

using namespace std;

int main(void) {

	string str;
	int k;
	cin >> str >> k;

	for (int i = 0; i < str.length(); ++i) {
		int dist = 0;
		if (str[i] != 'a') {
			dist = 'z' - str[i] + 1;
		}
		if (dist <= k) {
			str[i] = 'a';
			k -= dist;
		}
	}

	k = k % 26;
	if (str[str.length() - 1] - 'a' + k < 26) {
		str[str.length() - 1] += k;
	} else {
		str[str.length() - 1] -= (26 - k);
	}

	cout << str << endl;
	return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    REP(i,1<<3) {
        int res=s[0]-'0';
        REP(j,3) {
            if(i&(1<<j)) {
                res+=s[j+1]-'0';
            } else {
                res-=s[j+1]-'0';
            }
        }
        if(res==7) {
            cout<<s[0];
            REP(j,3) {
                if(i&(1<<j)) {
                    cout<<"+";
                } else {
                    cout<<"-";
                }
                cout<<s[j+1];
            }
            cout<<"=7"<<endl;
            return 0;
        }
    }
    return 0;
}


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

#define ll long long int
#define ld long double
#define clr(arr) memset(arr,0,sizeof(arr))
#define nn '\n'

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

    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n;
        double d;
        cin>>n>>d;
        int count = 0;
        double a,b;
        for(int i=0; i<n; i++)
        {
            cin>>a>>b;
            double temp = sqrt(a*a + b*b);
            if(temp<=d) count += 1;
        }
        cout<<count<<endl;
    }

    return 0;
}




Measured memory_bytes: 3760
// <------------- Template -----------------------> //


#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(2);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAX5];ll visit[]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
ll s,t,d;
ll sum = 0;
vll dist[2];

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	vll a(3);
	cin>>a[0]>>a[1]>>a[2];
	sort(all(a));
	reverse(all(a));
	cout<<10*a[0] + a[1] + a[2];
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 5980
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  vector<int> prime;		  
  for (int i=2;i<247000;i++){
    int count=0;
    int j;
    if (i%2!=0||(sqrt(i)-(int)sqrt(i))!=0){
      for (j=2;j<i/2;j++){
	if (i%j==0){
	  break;
	}
      }
    }
    if ((j==i/2||i==2||i==3)&&i!=4){
      prime.push_back(i);
    }
  }
  int n;
  while (cin>>n,n|n!=0){
    int i=0;
    int s;
    while (1){
      if (n<prime[i]){
	s=i;
	break;
      }
      i++;
    }
    int e;
    while (1){
      if (2*n<prime[i]){
	e=i-1;
	break;
      }
      i++;
    }
    cout<<e-s+1<<endl;
  }
}

Measured memory_bytes: 1348
#include <iostream>
#include<cmath>
#include<set>
#include<cstdio>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x7fffffff;
const double pi = acos(-1.0);
const int N = 3e5 + 5;
char s[N];
int a[N];
int d[N];
int main() {
	int n;
	int cnt = -INF, op;
	scanf("%d%s", &n, s+1);
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'E')a[i] = 1;
	}
	memset(d, 0, sizeof(d));
	d[1] = a[1];
	for (int i = 2; i <= n; i++)d[i] = d[i - 1] + a[i];

	for (int i = 1; i <= n; i++) {
		int temp = d[i] + d[i - 1] - i;
		if (temp > cnt) {
			cnt = temp;
			op = i;
		}
	}
	int ans;
	ans = (op - d[op - 1] - 1) + (d[n] - d[op]);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

typedef struct Edge {
    ll to, cost;
} Edge;

vector<vector<Edge>> g;
vector<bool> vi;
int k, num;

void dijkstra(vector<ll> &d, int s) {
    priority_queue<P, vector<P>, greater<P>> pq;
    d[s] = 0;
    // P<dist, v>
    pq.push({0,s});

    while (!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second;

        for(auto &&e: g[v]) {
            if (d[e.to] > d[v]+e.cost) {
                d[e.to] = d[v]+e.cost;
                pq.push({d[e.to], e.to});
            }
        }
    }
}


int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    g.resize(n);
    REP(i,n-1) {
        ll a,b,c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    int q;
    cin >> q >> k;
    --k;
    vi.resize(n, false);

    vector<ll> d(n, LINF);
    dijkstra(d, k);

    REP(i,q) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        ll ans = 0;
        ans = d[x]+d[y];
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long ll;

const int INF = 100000000;

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

    int cnt = 0;
    for (int i = min(A, B); i >= 1; i--) {
        if (A % i == 0 && B % i == 0) {
            cnt++;
        }
        if (cnt == K) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T,typename Y>
struct Rerooting{

	using F =function<T(T,T)>;
	using G =function<T(T,Y)>;

	vector<vector<int>>g;
	vector<vector<T>>dp;//dp[v][i]:頂点vを根とする部分木のi番目の有向辺に対応する値
	vector<T>ans;//答え
	const F merge;//子を根とする部分木に対して二項演算を適用する
	const G add_root;//マージしたものに根を追加するときに子に対してする計算
	const G to_root;//マージしたものに根を追加するときに根に対してする計算
	const T identity;//単位元a・e=e・a=aが成り立つe

	Rerooting(int n,const F &merge,const G &add_root,const T &identity,const G &to_root):merge(merge),add_root(add_root),identity(identity),to_root(to_root){
		g.resize(n);
		dp.resize(n);
		ans.resize(n,identity);
	}

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

	void build(int root=0){
		dfs1(root);
		dfs2(root,identity);
	}

	T dfs1(int v,int par=-1){//木dp
		T cul = identity;
		dp[v].resize(g[v].size(),identity);
		for(int i=0;i<g[v].size();++i){
			int u =g[v][i];
			if(u==par)continue;
			dp[v][i]=dfs1(u,v);
			cul=merge(cul,add_root(dp[v][i],g[v][i]));
		}
		return to_root(cul,v);
	}

	void dfs2(int v,const T &val ,int par=-1){
		for(int i=0;i<g[v].size();++i){
			if(g[v][i]==par){//値を再利用
				dp[v][i]=val;
				break;
			}
		}
		vector<T>dp_l(g[v].size()+1,identity),dp_r(g[v].size()+1,identity);
		for(int i=0;i<g[v].size();++i){//左から累積
			dp_l[i+1]=merge(dp_l[i],add_root(dp[v][i],g[v][i]));
		}
		for(int i=g[v].size()-1;i>=0;--i){//右から累積
			dp_r[i]=merge(dp_r[i+1],add_root(dp[v][i],g[v][i]));
		}

		ans[v]=to_root(dp_l[g[v].size()],v);

		for(int i=0;i<g[v].size();++i){//隣接する頂点に対して計算
			int u=g[v][i];
			if(u==par)continue;
			dfs2(u,to_root(merge(dp_l[i],dp_r[i+1]),v),v);
		}
	}
};

void solve()
{
	int n,m;
	cin>>n>>m;
	Rerooting<ll,ll>tree(n,[&](ll a,ll b){return a*b%m;},[&](ll a,ll b){return a+1;},1,[](ll a,ll b){return a;});
	rep(i,n-1){
		int x,y;
		cin>>x>>y;
		x--;y--;
		tree.add_edge(x,y);
		tree.add_edge(y,x);
	}
	tree.build();
	rep(i,n)cout<<tree.ans[i]<<"\n";
	//cout<<tree.to_root(0,0)<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 36424
// Problem : C - Vacation
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n;
	cin >> n;
	
	int dp[n][3],ans=0;
	rep(i,0,n)
	{
		int a,b,c;
		cin >>a  >> b >> c;
		if(i == 0)
			dp[0][0]=a,dp[0][1]=b,dp[0][2]=c;
		else{
			dp[i][0] = a;
			dp[i][0] += max(dp[i-1][1],dp[i-1][2]);
			dp[i][1] = b;
			dp[i][1] += max(dp[i-1][0],dp[i-1][2]);
			dp[i][2] = c;
			dp[i][2] += max(dp[i-1][1],dp[i-1][0]);
		}
		ans = max(ans,dp[i][0]);
		ans = max(ans,dp[i][1]);
		ans = max(ans,dp[i][2]);
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 5944
h, w, d = gets.split.map(&:to_i)

num = Array.new(h*w+1)
h.times do |i|
    gets.split.map(&:to_i).each_with_index do |a,index|
        num[a] = [i,index]
    end
end

dp = Array.new(h*w+1)
(h*w+1).times do |i|
    if i <= d
        dp[i] = 0
    else
        dp[i] = dp[i-d] + (num[i][0] - num[i-d][0]).abs + (num[i][1] - num[i-d][1]).abs
    end
end

gets.to_i.times do 
    l, r = gets.split.map(&:to_i)
    puts dp[r] - dp[l]
end

Measured memory_bytes: 11516
/* main code starts from line 123. */

/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second
#define pb push_back


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define EACH(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)
#define REACH(i, v) for (auto itr = (v).rbegin(); itr != (v).rend(); itr++)

#define SORT(v) sort(ALL(v))
#define GSORT(v) sort(ALL(v), greater<decltype((v).front())>())


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n-1 to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
    return a * a;
}


/* ---------- Debug ---------- */

#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;
#define testP2(a, b) cout << "(" << a << ", " << b << ")" << endl;


/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

/* ---------- Global Variance ----------- */


/* ------------- Functions -------------- */


/* ----------- Main Function ------------ */

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

    int a, b;
    cin >> a >> b;
    cout << (a <= b ? a : a - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
using namespace std;
int main() {
	while (true) {
		int n = 0;
		scanf("%d", &n);
		if (n == 0) break;
		vector<int> a;
		for (int i = 0;i < n;++i) {
			int b = 0;scanf("%d",&b );
			a.push_back(b);
		}
		sort(a.begin(), a.end());
		int num = 0;
		for (int i = 0;i < n;++i) {
			num += a[i];
		}
		num -= (a[0] + a[n - 1]);
		printf("%d\n", num/(n-2));
	}
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N;
  cin >> N;
  vector<ll> t(N+1); // t[val] = index
  rep(i, N) {
    ll x;
    cin >> x;
    t[x] = i+1;
  }

  ll ans = 0;
  set<ll> s;
  for (ll val=N; val>=1; val--) {
    {
      // 右側に最大値がある場合
      ll j, i1, i2;
      auto it = s.lower_bound(t[val]);
      if (it == s.end())
        goto END1;
      i1 = *it;
      it++;
      if (it == s.end())
        i2 = N+1;
      else
        i2 = *it;

      it = s.lower_bound(t[val]);
      if (it == s.begin()) {
        j = 0;
      } else {
        it--;
        j = *it;
      }

      // printf("right %d %dx%d\n", val, (t[val]-j) , (i2-i1));
      ans += val * (t[val]-j) * (i2-i1);
      END1: ;
    }

    {
      // 左側に最大値がある場合
      ll j2, j1, i;
      auto it = s.lower_bound(t[val]);
      if (it == s.begin()) {
        goto END2;
      }
      it--;
      j1 = *it;
      if (it == s.begin()) {
        j2 = 0;
      } else {
        it--;
        j2 = *it;
      }
      it = s.lower_bound(t[val]);
      if (it == s.end()) {
        i = N+1;
      } else {
        i = *it;
      }
      // printf("left %dx%d\n", val, (j1-j2), (i-t[val]));
      ans += val * (j1-j2) * (i-t[val]);

      END2: ;
    }

    s.insert(t[val]);
  } 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
cd = [list(map(int,input().split())) for _ in range(M)]
INF = 4*10**9+1

for i in range(N):
    ans,dist = 0,INF
    for j in range(M):
        if dist > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
            ans = j + 1
            dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long long n, p, q;
    vector<long long> v;
    
    scanf("%lld %lld %lld", &n, &p, &q);
    
    for (int i = 1; i <= n; i++){
        long long x;
        scanf("%lld", &x);
        v.push_back(x + p * i);
    }
    
    sort(v.rbegin(), v.rend());
    
    long long diff = 0;
    long long s = 0;
    for (int i = 0; i < n; i++){
        s += v[i];
        diff = max(diff, s + (long long)(i + 1) * (i + 1) * p - (long long)(i + 1) * p * (q + 2 * n));
    }
    
    printf("%lld\n", p * (n * q + n * (n - 1) / 2) + diff);
    
    return (0);
}

Measured memory_bytes: 7252
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

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

int main() {
    int n, k;
    cin >> n >> k;
    set<int> v;
    for (int j = 0; j < k; ++j) {
        int a;
        cin >> a;
        v.emplace(a+'0');
    }
    for (int i = n; ; ++i) {
        int flag = 1;
        for (auto &&a : to_string(i)) {
            for (auto &&b : v) {
                if(a == b){
                    flag = 0;
                }
            }
        }
        if(flag){
            cout << i << "\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

int main() {
    COMinit();
    ll n;
    cin >> n;
    ll a[n];
    ll sum[n];
    rep(i,n){
        cin >> a[i];
        sum[i] = a[i];
        if(i > 0)sum[i] += sum[i-1];
        sum[i] %= MOD;
    }

    ll num[n] = {};
    srep(k,1,n-1){
        num[k] = (sum[n-2] - sum[n-2-k]) - sum[k-1] + MOD * 10;
        num[k] %= MOD;
    }
    ll ans = 0;

    srep(k,1,n){
        ans += inv[k] * inv[k+1] % MOD * num[k] % MOD;
        ans %= MOD;
    }

    rep(i,n-1){
        ans += inv[n-1-i] * (a[n-1] - a[i]) % MOD;
        ans %= MOD;
    }

    ans = ans * fac[n-1] % MOD;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline int rd()
{
	int x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=100005;
int n,m,nn,a,b,f[N],fa[N],s[N],d[N],c[N];vi g[N];ll ans;
int fnd(int x){return f[x]==x?x:f[x]=fnd(f[x]);}
void dfs(int x,int p,int o)
{
	s[x]=o;
	for(int y:g[x])if(y!=p){d[y]=d[x]+1;fa[y]=x;dfs(y,x,-o);s[x]+=s[y];}
}
int main()
{
	n=rd();m=rd();
	if(n&1){puts("-1");return 0;}
	rep(i,1,n)f[i]=i;
	rep(i,1,m)
	{
		int u=rd(),v=rd();int x=fnd(u),y=fnd(v);
		if(x!=y)f[x]=y,g[u].pb(v),g[v].pb(u);else a=u,b=v;
	}
	if(!a)
	{
		dfs(1,0,1);
		if(s[1]){puts("-1");return 0;}
	}
	else
	{
		dfs(a,0,1);
		if(d[b]&1)
		{
			if(s[a]){puts("-1");return 0;}
			for(int i=b;i!=a;i=fa[i])c[++nn]=s[i],s[i]=0;
			c[++nn]=0;sort(c+1,c+nn+1);int w=c[(nn+1)/2];
			rep(i,1,nn)ans+=abs(c[i]-w);
		}
		else
		{
			if(s[a]&1){puts("-1");return 0;}
			int w=s[a]/2;ans=abs(w);s[a]=0;
			for(int i=b;i!=a;i=fa[i])s[i]-=w;
		}
	}
	rep(i,1,n)ans+=abs(s[i]);
	printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 15488
#include <stdio.h>

int main(void) {
	int i,n;
	int hi;
	int ou;
	int point;
	char buff[100];
	
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		ou = 0;
		hi = 0;
		point = 0;
		while(ou<3) {
			scanf("%s\n", buff);
			switch(buff[1]) {
				case 'I':
					hi++;
					if(hi > 3) {
						point++;
						hi = 3;
					}
				break;
				case 'O':
					point = point + hi + 1;
					hi = 0;
				break;
				case 'U':
					ou++;
				break;
			}
/*			printf("%s %d\n", buff, point);*/
		}
		printf("%d\n", point);
	}
	
	return 0;
}

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

int m[246913] = {} ;

void cal(){
	for( int i=2 ; i<246913  ; i++ ){
		for( int j=2 ; j<246913  ; j++ ){
			if( i*j < 246913 ) m[i*j] = 1 ;
			else break ;
		}
	}
}
	
int main(){
	
	int n ;
	int count ;
	
	cal();
	
	while(1){
		cin >> n ;
		if( n==0 ) break ;
		
		count = 0 ;
		for( int i=n+1 ; i<=n*2 ; i++ ){
			if( m[i] == 0 ) count++;
		}
		
		cout << count << endl ;
	}
	
return 0;
}

Measured memory_bytes: 2124
import collections

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ele_count = len(set(A))
    # print(ele_count)

    counter = collections.Counter(A)
    ans = 0
    for ele in counter.most_common()[:-(ele_count - K + 1):-1]:
        ans += ele[1]

    print(ans)


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

N,A,B = map(int,input().split())
S = input()

passed = 0
overseas = 0
for ch in S:
    if ch == 'a':
        if passed < A + B:
            print('Yes')
            passed += 1
        else:
            print('No')
    elif ch == 'b':
        if passed < A + B and overseas < B:
            print('Yes')
            passed += 1
            overseas += 1
        else:
            print('No')
    else:
        print('No')



Measured memory_bytes: 4040
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const int MOD = 1e9 + 7;
int a[21][21];

int main(){

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

    int com = (1 << N);
    vector<long long> before(com, 0);
    vector<long long> next(com, 0);
    vector<int> p(N, 0);

    before[0] = 1;

    for(int i = 0; i < N; i++){
        p[N - 1 - i] = 1;

        do{
            long long temp = 0; 
            int state = 0;
            for(int j = 0; j < N; j++){
                if(p[j] == 1){
                    state += (1 << j);
                }
            }

            for(int j = 0; j < N; j++){
                if(p[j] == 1 && a[i][j] == 1){
                    int beforeState = state - (1 << j);
                    temp = (temp + before[beforeState]) % MOD;
                }
            }

            next[state] = temp;

        }while(next_permutation(p.begin(), p.end()));

        swap(next, before);
    }

    cout << before[com - 1] << endl;

    return 0;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    int n;
    cin>>n;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    ll ans=0;
    rep(i,n){
        if(a[i]>=b[i]){
            ans+=b[i];
        }
        else{
            ans+=a[i];
            if(a[i]+a[i+1]>=b[i]){
                a[i+1]-=b[i]-a[i];                
                ans+=b[i]-a[i];
            }
            else{
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

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

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

    if(s=="RRR"){
        cout << "3" << endl;
    }else if(s=="RRS"||s=="SRR"){
        cout << "2" << endl;
    }else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR"){
        cout << "1" << endl;
    }else{
        cout << "0" << endl;
    }

    return 0;
}

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

int main() {
  int n, x, y; cin >> n >> x >> y;
  vector<int> v(n);
  for(int i = 1; i < n; i++){
    for(int j = i + 1; j < n + 1; j++){
      int tmp1 = 0, tmp2 = 1;
      tmp1 = j - i;
      if(y - j > 0){
        tmp2 += y - j;
      }else{
        tmp2 += j - y;
      }
      if(x - i > 0){
        tmp2 += x - i;
      }else{
        tmp2 += i - x;
      }
      if(tmp1 < tmp2){
        v.at(tmp1)++;
      }else{
        v.at(tmp2)++;
      }
    }
  }
  for(int i = 1; i < n; i++){
    cout << v.at(i) << endl;
  }
}


Measured memory_bytes: 384
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int K = ni();
        long[] A = nlarr(K);

        long over = 2;
        long under = 3;
        for (int i = K - 1; i >= 0; i--) {
            if (over % A[i] != 0) {
                over = (over / A[i] + 1) * A[i];
            }

            if (under % A[i] != 0) {
                under = (under / A[i] + 1) * A[i];
            }

            if (over >= under) {
                out.println("-1");
                return;
            }
        }

        out.println(over + " " + (under - 1));
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' '; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n >> m >> k;
  	if((m+k)==0){
    	dbg(0);
      return 0;
    }
 	if(n<=(m+k)) {
      	if(n<m)
          dbg(n);
      	else
          dbg(m);
    }else{
    	ll a = n%(m+k);
    	ll b = n/(m+k);
      
      ll d = (a<m?a:m);
    cout << b*m+d << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector> 
#include <float.h>
#include <cfloat>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <errno.h>
#include <cerrno>
#include <assert.h>
#include <cassert> 
#include <map>
#include <memory.h>
#include <cctype>
#include <ctype.h>
#include <math.h>
#include <vector> 
#include <cstdio> 
#include <set>
#include <string.h>
#include <stdio.h>
#include <new>
#include <ctime> 
#include <memory>
#include <cmath>
#include <queue>
#include <cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define mp make_pair 
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define pii pair<int,int>  
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std; 
int a[15];
int main(){
    int n;
    cin>>n;
    fo(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    fo(i,0,n-1){
        ans+=a[i];
    }
    ans+=a[n-1]/2;
    cout<<ans<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int x; cin >> x;
	if (x >= 400 && x < 600) cout << 8;
	else if (x >= 600 && x < 800) cout << 7;
	else if (x >= 800 && x < 1000) cout << 6;
	else if (x >= 1000 && x < 1200) cout << 5;
	else if (x >= 1200 && x < 1400) cout << 4;
	else if (x >= 1400 && x < 1600) cout << 3;
	else if (x >= 1600 && x < 1800) cout << 2;
	else cout << 1;
	return 0;
}

Measured memory_bytes: 3620
a = [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]
k = input()
print(a[int(k)-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
//#define zerol
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout  << #x << " -> "; err(x); } while (0)
void err() { cout <<  endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

const int MAXN = 1e3+5;
const LL MOD = 1e9+7;

vector<int> p;
bool nop[MAXN];

int n, a, b, c, d;

LL dp[MAXN];

int aa[MAXN*20], bb[MAXN*20];

LL C[MAXN][MAXN];

LL frac[MAXN];

LL bin(LL a, LL b, LL MOD) {
    LL res;
    for (res=1;b;a=a*a%MOD, b>>=1)
        if (b&1)
            res = res*a%MOD;
    return res;
}

LL get_inv(LL a, LL MOD) { return bin(a, MOD-2, MOD);}


LL calc(int m, int k, int i) {
    LL ans = 0;
    int ki = k * i;
    LL coff = frac[ki] * get_inv(bin(frac[i], k, MOD), MOD) %MOD * get_inv(frac[k], MOD) %MOD;
    if (min(m, ki) == 0) return coff;
    for (int i=0; i<=min(m, ki); ++i) {
        ans = (ans + C[m][i] * C[ki][i] % MOD) %MOD;
    }
    dbg(ans);
    ans = ans * coff %MOD;
    dbg(m, k, i, ki, ans);
    return ans;
}

LL test(int m, int ki) {
    LL ans = 0;
    for (int i=0; i<min(m, ki); ++i) {
        ans = (ans + C[m][i] * C[ki][i] % MOD) %MOD;

    }
    return ans;
}

LL finv[MAXN];

LL inv(int i) {
    return finv[i];
}

int main() {
    C[1][1] = 1;
    C[1][0] = 1;
    FOR (i, 2, MAXN) {
        C[i][0] = 1;
        FOR (j, 1, i+1) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
        }
    }

    frac[0] = 1;
    FOR (i, 1, MAXN) frac[i] = frac[i-1] * i %MOD;
    finv[MAXN-1] = get_inv(frac[MAXN-1], MOD);
    FORD(i, MAXN-2, -1)
        finv[i] = finv[i+1] * (i+1)%MOD;

//    for (int i=1; i<=10; ++i) {
//    for (int j=1; j<=10; ++j) {
//        printf("%lld ", test(i, j));
//    }
//    putchar('\n');
//    }

    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    int cnt = 0;
    dp[0] = 1;
    FOR (i, a, b+1) {
        FORD (j, min(i*d, n), i*c-1) {
            FOR (k, c, d+1) {
                if (j-k*i >=0 && dp[j-k*i]) {
                    LL now = bin(inv(i), k, MOD);
                    LL M = j-k*i;
                    dp[j] = (dp[j] + frac[j]*now%MOD*inv(M)%MOD*dp[M]%MOD*inv(k)%MOD)%MOD;
//                    dp[j] = (dp[j] + dp[j-k*i]*frac[j]%MOD*bin(get_inv(frac[i], MOD), c, MOD)%MOD*get_inv(frac[j-k*i], MOD)%MOD*get_inv(frac[k], MOD)%MOD) % MOD;
                } else if (j-k*i<0) break;
            }
        }
    }

    cout << dp[n] << endl;


    return 0;
}


Measured memory_bytes: 7424
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

char s[10001];
int dp[10000][100][2][2]; // 타이트하다. 크다.
int n, d;

int go(int o, int sum, int st, int bb) {
	if (o == n) return sum == 0 && bb == 0;
	if (dp[o][sum][st][bb] != -1) return dp[o][sum][st][bb];

	ll ret = sum == 0;
	for (int i = 0; i < 10; i++) 
		ret += go(o + 1, (sum + i) % d, (st && i == s[o]) ? 1 : 0, (bb || st && i > s[o] ? 1 : 0));

	ret %= MOD;
	return dp[o][sum][st][bb] = ret;
}


int main() {
	memset(dp, -1, sizeof(dp));
	scanf("%s", s);
	n = strlen(s);

	for (int i = 0; i < n; i++)
		s[i] -= '0';

	scanf("%d", &d);
	
	ll ret = 0;
	for (int i = 1; i < 10; i++) 
		ret += go(1, i % d, i == s[0], i > s[0]);

	printf("%lld", ret % MOD);
}

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

int main(){
    int a, b;

    while(cin >> a >> b){
        if(a==0 && b==0) break;
        int tsuri = b - a;
        printf("%d ", ((tsuri % 1000) % 500)/100);
        printf("%d ", (tsuri % 1000) / 500);
        printf("%d\n", tsuri / 1000);
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const lint INF = 1ll << 56;

int n, m;
int d[1001], c[1000];
lint dp[1001][1002];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		cin >> d[i];
	}
	for (int i = 0; i < m; i++){
		cin >> c[i];
	}
	
	fill_n(*dp, 1001 * 1002, INF);
	dp[0][0] = 0;
	for (int i = 0; i < m; i++){
		for (int j = 0; j <= n; j++){
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + d[j] * c[i]);
		}
	}
	
	cout << dp[m][n] << endl;
	
	return 0;
}

Measured memory_bytes: 9000
//
//$$$$$$$$$$$$$$$$$$$$$$
//$$                  $$
//$$   gyoubu_oniwa   $$
//$$                  $$
//$$$$$$$$$$$$$$$$$$$$$$
//
#include<bits/stdc++.h>
using namespace std;
#define DBG(a) if(DBGDO) cout<<#a<<':'<<a<<endl;
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()
#define pow(a,b) (pow(a,b)+0.5)

typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--) 
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];

typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<string> vs;typedef vector<vector<string>> vvs;

#define unmp unordered_map

#define PRIME ((lli)(1e9+7ll))
#define PRIME2 (998244353ll)
const lli TEN_18 = 1e18;
const lli TEN_9 = 1e9;
const lli TEN_5 = 1e5;

inline void debugORfast(int a=1,int b=1){
    if(a){
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
        #endif
    }
    if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}}

template<typename T>
void print(const T &v, int begin=-1, int end=-1, int w=2)
{
	if(begin<=end){
		if(begin==-1) fl(i,0,v.SZ) cout<<setw(w)<<v[i]<<' ';
		else if(end==-1) fl(i,begin,v.SZ) cout<<setw(w)<<v[i]<<' ';
		else fl(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;}
	else{
		if(begin==-1) flr(i,v.SZ-1,-1) cout<<setw(w)<<v[i]<<' ';
		else if(end==-1) flr(i,begin,-1) cout<<setw(w)<<v[i]<<' ';
		else flr(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;
	}
}

void pans(char v){
	switch(v){
		case 'y' : cout<<"yes"<<endl; break;
		case 'n' : cout<<"no"<<endl; break;
		case 'Y' : cout<<"Yes"<<endl; break;
		case 'N' : cout<<"No"<<endl; break;
		case 'B' : cout<<"YES"<<endl; break;
		case 'S' : cout<<"NO"<<endl; break;
	}
}

int DBGDO=0;

lli brute(){
	return 0;
}

lli solve(){
    return 0;
}

int main()
{
	debugORfast(0,1);
	//w(ttt)
	{
		lli a; cin>>a;
		cout<<(a+(a*a)+(a*a*a))<<endl;
	}
	return 0;
}


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

xy.sort()
gap = []
gap2 = []

for i in range(len(xy)):
    for j in range(len(xy)):
        gap.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])
     
gap2 = [i for i in gap if i != [0,0]] 
gap3=[]

for i in gap2:
    if i not in gap3:
        gap3.append(i)

m = 0

for i in gap3:
    rep = gap2.count(i)
    m = max(m,rep)

print(N-m)
 

Measured memory_bytes: 3572
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readInts >>= putStrLn . which "Yes" "No" . uncurry (==) . mp

Measured memory_bytes: 380
t=int(input())
taro=0
hanako=0
for i in range(t):
    S=input().split()

    if S[0]==S[1]:
        taro+=1
        hanako+=1
    elif S[0]>S[1]:
        taro+=3
    else:
        hanako+=3
print(taro,hanako)

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

using namespace std;

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

typedef long long ll;

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

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int ans = 0;
    cin >> n;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    FOR (i, 1, n) {
        if (a[i] == a[i - 1]) {
            ans++;
            i++;
        }
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256