akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

class articulation {
private:
    void dfs(ll v, ll p, ll &k, vector<ll> &ret) {
        ord[v] = k++;
        low[v] = ord[v];
        ll cnt = 0;
        bool is_articulation = false;
        for(auto to: g[v]) {
            if(ord[to]==-1) {
                dfs(to, v, k, ret);
                chmin(low[v], low[to]);
                ++cnt;
                is_articulation |= p!=-1 && low[to] >= ord[v]; 
            } else if(to != p) {
                chmin(low[v], ord[to]);
            }
        }
        is_articulation |= p==-1 && cnt>1;
        if(is_articulation) ret.push_back(v);
    }
public:
    vector<vector<ll>> g;
    vector<ll> ord, low, cmp;

    articulation() {}
    articulation(ll n) : g(n), ord(n, -1), low(n) {}

    void add_edge(ll u, ll v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<ll> build() {
        ll k = 0;
        vector<ll> ret;
        REP(i, g.size()) if(ord[i]==-1) dfs(i, -1, k, ret);
        return ret;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    articulation graph(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        graph.add_edge(a, b);
    }
    auto ret = graph.build();
    sort(ALL(ret));
    for(auto i: ret) cout << i << endl;
}


Measured memory_bytes: 5300
#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=(int)(a);i<(int)(b);i++)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

typedef long long ll;

string s;
string t;

int main(){
  cin>>s>>t;
  int m = t.size();
  int level = 0;
  string bef = "";
  while(true){
    ll nextlen = (ll)bef.size() * (ll)(m+1) + m;
    if(nextlen > s.size())break;
    string cur = bef;
    REP(i,m){
      cur += t[i];
      cur += bef;
    }
    int it = 0;
    REP(i,s.size()){
      if(it<cur.size() && s[i]==cur[it])it++;
    }
    if(it!=cur.size())break;
    swap(cur, bef);
    level++;
  }
  printf("%d\n",level);
  return 0;
}


Measured memory_bytes: 3572
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[300000];

int main()
{
  _int64 sum,tot,sum1,best,tmp;
  int i,n;
  scanf("%d",&n);
  tot=0;
  for (i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    tot+=a[i];
  }
  sum=0;
  best=(1LL<<60);
  for (i=0;i+1<n;i++)
  {
    sum+=a[i];
    sum1=tot-sum;
    tmp=sum-sum1;
    if (tmp<0) tmp=-tmp;
    if (tmp<best) best=tmp;
  }
  printf("%lld\n",best);
  return 0;
}

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

int main(){
	int n;cin>>n;
	int st=0;
	string str = "No";
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		if(a==b){
			st++;
		}
		else st=0;
		if(st==3) {str="Yes";break;}
	}
	cout<<str<<endl;
}

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

int main(){
	int n,x,y,h,w;
	while(cin >> n, n!= 0){
		int ans = 0;
		for(int i = 0; i < n; i++){
			cin >> x >> y >> h >> w;
			int l = x + y + h;
			if(l <= 60 && w <= 2){
				ans += 600;
			}
			else if(l <= 80 && w <= 5){
				ans += 800;
			}
			else if(l <= 100 && w <= 10){
				ans += 1000;
			}
			else if(l <= 120 && w <= 15){
				ans += 1200;
			}
			else if(l <= 140 && w <= 20){
				ans += 1400;
			}
			else if(l <= 160 && w <= 25){
				ans += 1600;
			}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3120
#include <iostream>

using namespace std;
typedef long long lint;

void resolve()
{
    lint H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return;
    }

    lint Wdiv2 = W / 2;
    lint ans = (W % 2 == 0) ? (H * Wdiv2) : (H * Wdiv2 + (H + 1) / 2);
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
  using ll = long long;
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll B = 1;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if(B > 1000000000000000000 / A[i]){
      cout<<"-1"<<endl;
      return 0;
    }
    B *= A[i];
    if (A[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
 
    
  }
  if(B>1000000000000000000){
    cout<<-1<<endl;
    return 0;
  }
  cout << B << endl;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  char buf[3];
  int A, B, res;
  rd(A);
  rd(buf);
  rd(B);
  if(buf[0]=='+'){
    res = A +B;
  }
  else{
    res = A -B;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int A, B, res;
//   char buf[3];
//   
//   rd(A,buf,B);
//   res = A if[buf[0]=='+', +, -] B;
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int K;cin>>K;
        long long sum=0;
        for(int i=1;i<=K;i++){
            for(int j=1;j<=K;j++){
                for(int k=1;k<=K;k++){
                    sum+=__gcd(__gcd(i,j),k);
                }
            }
        }
        cout<<sum<<endl;
    }
        






Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int DP[105][10005];

int main() {
    int N, W;
    cin>>N>>W;
    int v[N], w[N];
    for(int i=0;i<N;++i){
        cin>>v[i]>>w[i];
    }
    for(int i=0;i<=W;++i){
        if(i>=w[0]){
            DP[0][i] = DP[0][i-w[0]] + v[0];
        }
    }
    for(int i=1;i<N;++i){
        for(int j=0;j<=W;++j){
            if(j>=w[i]){
                DP[i][j] = max(DP[i-1][j], DP[i][j-w[i]] + v[i]);
            }
            else{
                DP[i][j] = DP[i-1][j];
            }
        }
    }
    cout<<DP[N-1][W]<<endl;
}




Measured memory_bytes: 7004
#include<stdio.h>
#include<math.h>
using namespace std;

struct Point{double x,y;};

void koch(int n,Point a,Point b){
    if(n == 0)return;
    
    Point s,t,u;
    double th = M_PI * 60.0 / 180.0;
    
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (2.0 * b.x + 1.0 * a.x) / 3.0;
    t.y = (2.0 * b.y + 1.0 * a.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    
    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}

int main(){
    Point a,b;
    int n;
    scanf("%d",&n);
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
    
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    
    return 0;
}


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

int main(){

    ll n,a,b;
    cin >> n >> a >> b;

    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    
    ll ans=0;
    for(int i=0;i<n-1;i++){
        ans+=min((x[i+1]-x[i])*a,b);
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = x-a+b;

    if (k > x) {
      if (b-a > x) {
        System.out.println("dangerous");
        return;
      }
      System.out.println("safe");
    } else {
      System.out.println("delicious");
    }
  }

}


Measured memory_bytes: 23636
/*A*/
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	int L, R, d;
	cin >> L >> R >> d;

	int ans = 0;

	for (int i = L; i <= R; i++) {
		if (i % d == 0)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3600
//@Author: wxyww
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
#include<cmath>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int N = 1000000 + 100;
ll read() {
	ll x = 0,f = 1; char c = getchar();
	while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
	while(c >= '0' && c <= '9') {x = x * 10 + c - '0',c = getchar();}
	return x * f;
}
char s[N],t[N];
int ans;
int main() {
	scanf("%s",s + 1);
	scanf("%s",t + 1);
	for(int i = 1;i <= 3;++i) ans += s[i] == t[i];
	cout<<ans;

	return 0;
}

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

const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;

int n;
ll a[maxn],cnt2[61];
int cnt[maxn][60],sum[60];

int main()
{	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cnt2[0] = 1;
	for(int i = 1; i < 60; i++) cnt2[i] = cnt2[i - 1] * 2 % mod;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		for(int j = 0; j < 60; j++){
			cnt[i][j] = ((a[i] >> j) & 1ll);
			sum[j] += cnt[i][j];
		}
		
	}
	//cout << cnt[0][1] << " " << cnt[1][1] << " " << cnt[2][1] << endl;
	ll ans = 0;
	for(int i = 0; i < 60; ++i){
		ans = (ans + 1ll * ((1ll << i) % mod) * sum[i]  % mod * (n - sum[i]) % mod) % mod;
		//cout << ans << endl;
	}
	//assert(ans < 0);
	//if(ans < 0) while(1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 72960
using System;
using System.Linq;

namespace id_0296cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var vs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var c1 = vs[0];
            var c5 = vs[1];
            var c10 = vs[2];
            var c50 = vs[3];
            var c100 = vs[4];
            var c500 = vs[5];
            var sum = c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
            if (sum < 1000)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("1");
            }

        }
    }
}



Measured memory_bytes: 9412
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

llint h, w, Q;
llint a[2005][2005];
llint sum[2005][2005], sumw[2005][2005], sumh[2005][2005];

llint get(llint a[2005][2005], llint sx, llint sy, llint tx, llint ty)
{
	return a[tx][ty] - a[sx-1][ty] - a[tx][sy-1] + a[sx-1][sy-1];
}

int main(void)
{
	cin >> h >> w >> Q;
	char c;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c;
			a[x][y] = c%2;
		}
	}
	
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			sum[x][y] = sum[x-1][y] + sum[x][y-1] - sum[x-1][y-1] + a[x][y];
			sumw[x][y] = sumw[x-1][y] + sumw[x][y-1] - sumw[x-1][y-1];
			if(a[x][y]*a[x-1][y]) sumw[x][y]++;
			sumh[x][y] = sumh[x-1][y] + sumh[x][y-1] - sumh[x-1][y-1];
			if(a[x][y]*a[x][y-1]) sumh[x][y]++;
		}
	}
	
	llint sx, sy, tx, ty;
	for(int q = 0; q < Q; q++){
		cin >> sy >> sx >> ty >> tx;
		llint ans = get(sum, sx, sy, tx, ty);
		ans -= get(sumw, sx+1, sy, tx, ty);
		ans -= get(sumh, sx, sy+1, tx, ty);
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 128924
// ALDS_1_1_B.cpp
// Greatest Common Divisor

#include <cstdio>
using namespace std;

int gcd(int a, int b)
{
	if (a < b) { int t = a; a = b; b = t; };
	if (b == 0) return a;
	if (b == 1) return 1;
	return gcd(b, a % b);
}

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	int c = gcd(a, b);
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 2612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

int x, y, s;

int main()
{
    while (cin >> x >> y >> s)
    {
        if(x == 0 && y == 0 && s == 0)
            return 0;
        int ans = 0;

        for (int sum = 1; sum <= s; sum++)
        {
            for (int a = 1; a < sum; a++)
            {
                int b = sum - a;
                if (a > b)
                    break;
                if (a * (100 + x) / 100 + b * (100 + x) / 100 == s)
                {
                    ans = max(ans, a * (100 + y) / 100 + b * (100 + y) / 100);
                }
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll ft[200005], v[200005], h[200005], n;

void update(ll pos, ll x){
    for(ll i = pos; i <= n; i+=i&(-i))
        ft[i] = max(ft[i], x);
}

ll query(ll pos){
    ll res = 0;
    for(ll i = pos; i > 0; i-=i&(-i))
        res = max(res, ft[i]);
    return res;
}

int main(){
    
    scanf("%lld", &n);
    for(ll i = 1; i <= n; i++)
        scanf("%lld", &h[i]);
    for(ll i = 1; i <= n; i++)
        scanf("%lld", &v[i]);
    ll res = 0;
    for(ll i = 1; i <= n; i++){
        ll aux = query(h[i]-1) + v[i];
        update(h[i], aux);
        res = max(res, aux);
    }
    printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int n;

int main() {
  cin >> n;
  double ans;
  if(n%2 ==0) ans = 0.5;
  else ans = 1.0*(n+1)/ (2*n);
  cout << ans;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=998244353;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int a,int b){
    int ret=1;
    while(b){
        if(b&1)ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}
const int FACTSIZE=1111111;
int fact[FACTSIZE];
int factinv[FACTSIZE];
class FactInit{
public:
    FactInit(){
        fact[0]=1;
        for(int i=1;i<FACTSIZE;i++)fact[i]=fact[i-1]*i%mod;
        factinv[FACTSIZE-1]=mpow(fact[FACTSIZE-1],mod-2);
        for(int i=FACTSIZE-2;i>=0;i--)factinv[i]=factinv[i+1]*(i+1)%mod;
    }
}factInit;

int binomial(int n,int k){
    return fact[n]*factinv[k]%mod*factinv[n-k]%mod;
}

signed main(){
    int N,A,B,K;
    cin>>N>>A>>B>>K;
    int ans=0;
    for(int i=0;i<=N;i++){
        if(i*A>K||(K-i*A)%B||(K-i*A)/B>N)continue;
        add(ans,binomial(N,i)*binomial(N,(K-i*A)/B)%mod);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 17664
#include<iostream>
using namespace std;
int main() {
    string s, p;
    int last, chk = 1;
    cin >> s >> p;
    s = s+s;
    for (int i=0; i<s.size(); i++){
        last = i + p.size() - 1;
        if (last >= s.size()) break;
        if (s.substr(i, p.size()) == p){
            cout << "Yes" << endl;
            chk--;
            break;
        }
    }
    if (chk) cout << "No" << endl;
    return 0;
}


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

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

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=101;
int n,tot=1,ans=0;
int color[MAXN],same[MAXN];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&color[i]);
	same[1]=1;
	for(int i=1;i<n;++i)
		if(color[i]==color[i+1]) ++same[tot];
		else same[++tot]=1;
	for(int i=1;i<=tot;++i) ans+=(same[i]>>1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int area(int d, int x)
{
  return d * x * x;
}
int main(int argc, char *argv[])
{
  int i;
  int d, sum;
  while(scanf("%d", &d) != EOF)
    {
      if((600 % d) != 0)
	continue;
      
      sum = 0;
      
      for(i = 0; i < 600; i += d)
	sum += area(d, i);
      
      printf("%d\n", sum);
    }
  return 0;
}

Measured memory_bytes: 596
import math


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result



num = 1000000007
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

grad = y / x
if grad < 0.5 or grad > 2:
    print(0)
    exit()

turns = int((x + y) / 3)

total = 0
t = (x + y) // 2
u = t - min(x, y)
o = t // 3 - u

total = cmb(turns, o)
total %= num
print(total)


Measured memory_bytes: 45428
n = int(input())
h_list = [int(x) for x in input().split()]
count = 0
temp_count = 0
for i, h in enumerate(h_list[:-1]):
    if h >= h_list[i+1]:
        temp_count += 1
    else:
        count = max(count, temp_count)
        temp_count = 0
if temp_count:
    count = max(count, temp_count)
print(count)

Measured memory_bytes: 14252
#include <stdio.h>
int main() {
	int n, m, a[50], b[50], cnt;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	for (int i = 0; i < n; i++) {
		cnt = 0;
		for (int j = 0; j < m; j++) {
			if (a[j] == i + 1) cnt++;
			if (b[j] == i + 1) cnt++;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

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

int vector_finder(std::vector<string> vec, string number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main(){
    int n;
    cin >>n;
    vector<string> a;
    vector<string> b;
    map<string, int> m;
    for(int i=0;i<n;i++){
        a.push_back("");
        cin>>a[i];    
    }
     
     int max_size  =0;
    for(int i=0;i<n;i++){
    
        int res = m.count(a[i]);
        if(res ==0){
            b.push_back(a[i]);
            m.insert(make_pair(a[i], 1));
        } else {
            m[a[i]] += 1;
            
        }
        if(m[a[i]] > max_size){
            max_size = m[a[i]];
        }
    }
//    cout<<"---"<<endl;
    pair<string, int> item;
    for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    item = *it;
    if(item.second == max_size ){
        cout<<item.first<<endl;
        }
    }
    

}

Measured memory_bytes: 29296
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <int> VI;

int main() {
    int n, m;
    while ( cin >> n >> m ) {
        if ( n == 0 && m == 0 ) break;
        VI D(n+m);
        for ( int i = 0; i < n; ++ i ) {
            cin >> D[i];
        }
        for ( int i = 0; i < m; ++ i ) {
            cin >> D[n+i];
        }
        sort( D.begin(), D.end() );
        int res = 0;
        int c = 0;
        for ( int i = 0; i < n + m; ++ i ) {
            res = max( res, abs( c - D[i] ) );
            c = D[i];
        }
        cout << res << endl;
    }
	return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  bool ok = false;
  rep(i, n + 1) rep(j, m + 1) {
    ll now = i * m + j * n - i * j * 2;
    if(now == k) ok = true;
  }
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
int main()
{
    fastRead;
    int x;
    cin>>x;
    cout<<x + x*x + x*x*x<<'\n';
    return 0;
    
}

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

using namespace std;
typedef long long ll;

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	
	if(a == b){
		for(int i = 0; i < b; i++){
			printf("%d",a);
		}
		printf("\n");
	}else if(a < b){
		for(int i = 0; i < b; i++){
			printf("%d", a);
		}
		printf("\n");
	}else{
		for(int i = 0; i < a; i++){
			printf("%d", b);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] S = new char[N];
        int[] count = new int[5];
        int check =0;
        for (int i =0; i<N; i++) {
            S[i] = sc.next().charAt(0);
            if (S[i] == 'M') count[0]++;
            if (S[i] == 'A') count[1]++;
            if (S[i] == 'R') count[2]++;
            if (S[i] == 'C') count[3]++;
            if (S[i] == 'H') count[4]++;
        }
        for (int i =0; i<5; i++) {
            if (count[i] == 0) check++;
        }
        if (check >= 3) {
            System.out.println(0);
            return;
        }
        
        long ans =0;
        for (int i =0; i<=2; i++) {
            for (int j =i+1; j<=3; j++) {
                for (int k =j+1; k<=4; k++) {
                    ans += (long)count[i] * count[j] * count[k];
                }
            }
        }
        System.out.println(ans);
        
    }
}   


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

using namespace std;

const int maxn=100005;

long long dp[maxn];
long long h[maxn];
long long n;

int main () {
	
	cin >> n;
	for (int i=0; i < n; i++)
	{
		cin >> h[i];
	}
	
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for (int i=2; i < n; i++)
	{
		dp[i]=min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
	}
	
		cout << dp[n-1];
	return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
limit = [readInt() for i in range(5)]

ans = math.ceil(n/min(limit))+4
print(ans)

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

ll dat[2<<18], add[2<<18];
int segn = 1;
void init(int n){
	while(segn < n)segn *= 2;
}

inline void lazy_update(int k, int l, int r){
	dat[k] += add[k]*(r-l);
	add[k*2+1] += add[k];
	add[k*2+2] += add[k];
	add[k] = 0;
}

void update(int a, int b, int x, int k, int l, int r){
	lazy_update(k, l, r);
	if(b <= l || r <= a)return ;
	if(a <= l && r <= b){
		add[k] += x;
		lazy_update(k, l, r);
		return ;
	}
	update(a, b, x, k*2+1, l, (l+r)/2);
	update(a, b, x, k*2+2, (l+r)/2, r);
	dat[k] = dat[k*2+1]+dat[k*2+2];
}

ll get(int a, int b, int k, int l, int r){
	lazy_update(k, l, r);
	if(b <= l || r <= a)return 0;
	if(a <= l && r <= b)return dat[k];
	ll vl = get(a, b, k*2+1, l, (l+r)/2);
	ll vr = get(a, b, k*2+2, (l+r)/2, r);
	return vl+vr;
}

int main(){
	int n, q, c, s, t, x;
	scanf("%d%d", &n, &q);
	init(n);
	for(int i = 0;i < q;i++){
		scanf("%d", &c);
		if(!c){
			scanf("%d%d%d", &s, &t, &x);
			update(s-1, t, x, 0, 0, segn);
		}else{
			scanf("%d%d", &s, &t);
			ll res = get(s-1, t, 0, 0, segn);
			printf("%lld\n", res);
		}
	}
	return 0;
}


Measured memory_bytes: 7896
from itertools import product
n = int(input())
s = input()
s_dict = {"o":1, "x":-1}
flg = False
for combi in product([-1,1], repeat=2):
    state = list(combi)
    for i, _s in enumerate(s[1:], 1):
        cur = state[i]
        res = s_dict[_s] * cur * state[i-1]
        state.append(res)
    if state[0] == state[-1] and state[n-1] == state[0] * state[1] * s_dict[s[0]]:
        flg = True
        break
res = "".join(["S" if i == 1 else "W" for i in state])
if flg:
    print(res[:-1])
else:
    print(-1)

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

const int N = 1e4 + 5;
const int E = 1e7 + 10;
#define st first
#define nd second
#define make(a,b) make_pair(a,b)

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

vector<int> G[N];
bool vis[N];
int mate[N];
bool sko[N];
bool not_prime[E];

void eratos() {
	for (int i = 2; i < E; i ++) {
		if (not not_prime[i]) {
			for (int j = 2 * i; j < E; j += i) {
				not_prime[j] = true;
			}
		}
	}
}

bool dfs(int x) {
	if (vis[x]) return false;
	vis[x] = true;
	for (int y: G[x]) {
		if (mate[y] == 0 || dfs(mate[y])) {
			mate[y] = x;
			sko[x] = true;
			return true;
		}
	}
	return false;
}

int main() {
	int n;
	scanf("%d", &n);
	eratos();
	
	vector<int> data;
	for (int i = 0; i < n; i ++) {
		int a;
		scanf("%d", &a);
		data.push_back(a);
	}
	sort(data.begin(), data.end());
	int last = -1;
	vector<int> tokens;
	for (int d: data) {
		if (last < d) {
			if (last != -1) {
				tokens.push_back(last);
			}
			tokens.push_back(d);
		}
		last = d + 1;
	}
	tokens.push_back(last);
	vector<int> nodes[2];
	for (int t: tokens) {
		nodes[t % 2].push_back(t);
	}
	for (int i = 0; i < tokens.size(); i ++) {
// 		printf("%d ", tokens[i]);
	}
// 	printf("tokens \n");
	not_prime[2] = true;
	not_prime[1] = true;
	for (int i = 0; i < nodes[0].size(); i ++) {
		for (int j = 0; j < nodes[1].size(); j ++) {
			if (not not_prime[abs(nodes[0][i] - nodes[1][j])]) {
				G[i+1].push_back(j+1);
			}
		}
	}
	bool still = true;
	int wynik = 0;
	while(still) {
		still = false;
		for (int i = 0; i <= nodes[0].size(); i ++) {
			vis[i] = false;
		}
		for (int i = 1; i <= nodes[0].size(); i ++) {
			if (sko[i]) continue;
			if (dfs(i)) {
				wynik ++;
				still = true;
			}
		}
	}
	printf("%d\n", wynik + 2 * ((tokens.size() - 2 * wynik) / 2) + (nodes[0].size() - wynik) % 2);
}


Measured memory_bytes: 10368
s = str(input())
t = str(input())
n = len(s)
m = len(t)
mi = -1
if m > n:
  print("UNRESTORABLE")
  exit()
for i in range(n-m,-1,-1):
  flag = True
  for j in range(0,m):
    if t[j] != s[i+j] and s[i+j] != "?":
      flag = False
      break
  if flag:
    mi = i
    break
if mi == -1:
  print("UNRESTORABLE")
  exit()
ans = ""
i = 0
while i < n:
  if i == mi:
    ans += t
    i += m
  else:
    if s[i] == "?":
      ans += "a"
    else:
      ans += s[i]
    i += 1
print(ans)
  
  
      
    
    
  
  

Measured memory_bytes: 9060
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int takahashi, aoki;
	takahashi=(a+d-1)/d;
	aoki=(c+b-1)/b;
	if(takahashi<aoki){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var cin = GetIntArray();
            var ans = (cin[0] % 3 == 0 || cin[1] % 3 == 0 || (cin[0] + cin[1]) % 3 == 0) ? "Possible" : "Impossible";

            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for ( int i = 0 ; i < 4; i++){
    if ( s.at(i) == '+') ans++;
    else if (s.at(i) == '-') ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 998244353
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll suf[N];
ll dp[N];

main()
{
    ll n,k;
    cin>>n>>k;
    vector<pii>v;
    v.resize(k);
    for(ll i=0;i<k;i++)
    {
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end());

    dp[n]=1;
    suf[n]=1;

    for(ll i=n-1;i>=1;i--)
    {
        ll now=0;
        for(ll j=0;j<k;j++)
        {
            if(i+v[j].first>n)
                continue;
            ll l=min(n,i+v[j].first),r=min(n,i+v[j].second);
            now+=suf[l]-suf[r+1];
            now%=M;
            now=(now+M)%M;
        }
        dp[i]=now;
        suf[i]=suf[i+1]+dp[i];
        suf[i]%=M;
    }
    cout<<dp[1];
}



Measured memory_bytes: 6716
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()
t = input()

t_kinds = set(t)
dic = defaultdict(list)

for i, char in enumerate(s, 1):
	if char in t_kinds:
		dic[char].append(i)

if len(dic.keys()) < len(t_kinds):
	print(-1)
	exit()

dic_lim = defaultdict(int)
for key in dic.keys():
	dic_lim[key] = len(dic[key])

tmp = -1
ans = 0
loop_cnt = 0
for x in t:
	idx = bisect(dic[x], tmp)
	if idx == dic_lim[x]:
		tmp = dic[x][0]
		loop_cnt += 1
	else:
		tmp = dic[x][idx]
print(len(s)*loop_cnt + tmp)



Measured memory_bytes: 14916
n = list(input())
ops = ['+', '-']
flag = False
for a in ops:
    for b in ops:
        for c in ops:
            ans = n[0]+a+n[1]+b+n[2]+c+n[3]
            if eval(ans)==7:
                ans=ans+'=7'
                print(ans)
                flag = True
                break
        if flag:
            break
    if flag:
        break

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      //begin
      int a = sc.nextInt();
      int b = sc.nextInt();
      if((a + b) % 2 == 0)
        out.println((a + b) / 2);
      else
        out.println("IMPOSSIBLE");
      //end
      out.close();
   }
 
   public static PrintWriter out;
      
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
      long nextLong() {
          return Long.parseLong(next());
      }
      double nextDouble() {
          return Double.parseDouble(next());
      }
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main (){
    int N,X[100],maxim;
    cin >> N;

    for(int i = 0;i<N;i++){
        int a;
        cin >> a;
        X[i] = a;
        maxim = max(maxim,a);
    }
    int minP = 999999999;
    for (size_t i = 0; i <= maxim; i++)
    {
        int sum = 0;
        for (size_t j = 0; j < N; j++)
        {
            sum+=(X[j]-i)*(X[j]-i);
        }
        minP = min(minP,sum);
    }
    cout << minP << endl;
  
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int N, nint;
    scanf("%d", &N);
    int prv[200000], locc[N], dptable[N];
    fill_n(prv, 200000, -1);
    for (int i = 0; i < N; ++i) {
        scanf("%d", &nint);
        locc[i] = prv[nint - 1];
        prv[nint - 1] = i;
    }
    dptable[0] = 1;
    for (int i = 1; i < N; ++i) {
        dptable[i] = dptable[i - 1];
        if (locc[i] != i - 1 && locc[i] != -1) dptable[i] = (dptable[i] + dptable[locc[i]]) % 1000000007;
    }
    printf("%d", dptable[N - 1]);
    return 0;
}

Measured memory_bytes: 2560
import copy
n = int(input())
x = list(map(int, input().split()))
y = copy.deepcopy(x)
y.sort()
mid_bigger = y[int(n/2)]
mid_smaller = y[int(n/2)-1]
ans = [0]*n
for i in range(0,n):
    if (x[i]<mid_bigger):
        ans[i]=mid_bigger
    elif (x[i]>mid_smaller):
        ans[i]=mid_smaller
    elif (mid_smaller == x[i]):
        ans[i] = mid_bigger
    else:
        ans[i] = mid_smaller
print(*ans, sep='\n')

Measured memory_bytes: 27156
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[111111];
int W;

void MAIN() {
    scanf("%s", S);
    N = strlen(S);
    scanf("%d", &W);
    for (int i=0; i<N; i+=W) putchar(S[i]);
    puts("");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;



int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if((A - B) >= C){
    cout << 0 << endl;
  }
  else{
    cout << C - A + B << endl;
  }
  
}

Measured memory_bytes: 256
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1)[::-1]:
    total = i
    j = 1
    if i >= K:
        ans += 1/N
        continue
    while K > total * 2:
        total = total * 2
        j += 1
    ans += (1/N) * ((1/2) ** j)
print(ans)


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

int n;
vector<int> ans,b;

bool solve();

int main(){
    cin >> n;
    b.resize(n);
    for(int i = 0;i < n;++i)cin >> b[i];
    if(!solve())cout << -1 << endl;
    else for(int i = 0;i < n;++i)cout << ans[i] << endl;
    return 0;
}

bool solve(){
    while(b.size() > 0){
        int num = -1;
        for(int i = 0;i < b.size();++i)if(i + 1 == b[i])num = i;
        if(num == -1)return 0;
        ans.push_back(b[num]);
        b.erase(b.begin() + num);
    }
    reverse(ans.begin(),ans.end());
    return 1;
}

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

int main()
{
  int n, ans = 0;
  string a, b, c;
  cin >> n >> a >> b >> c;
  for (auto i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (a[i] == c[i] || b[i] == c[i]) {
	ans++;
      } else {
	ans += 2;
      }
    } else {
      if (a[i] != c[i]) {
	ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
s = input().split(" ");
n = int(s[0]);
m = int(s[1]);
for x in range(int(m/10000),-1,-1) :
	nokori = m - 10000*x;
	for y in range(int(nokori / 5000),-1,-1) :
		z = int((m - 10000*x -5000 * y ) / 1000);
		if x + y + z == n :
			print(x,y,z);
			break;
		elif x == 0 and y == 0 and z != n :
			print(-1,-1,-1);
	else :
		continue
	break;

Measured memory_bytes: 3064
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    int A, B;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(B % A == 0 ? A + B : B - A);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21460
import bisect
import sys
input = sys.stdin.readline
from collections import deque
def solve():
  
  n,m = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  a = deque(sorted(a))
  tmp = deque([])
  for i in range(m):
    r,l = (int(i) for i in input().split())
    tmp.append((l,r))
  tmp= deque(sorted(tmp,reverse =True))
  ans = 0
  while tmp:
    c,b = tmp.popleft()
    place = bisect.bisect_left(a,c)-1
    if place == -1:
      break
    else:
        if len(a) == 0:
           break
        for i in range(min(1+place,b)):
           a.popleft()
        ans += c*(min(1+place,b))
    #print(a)
  if a:
   ans += sum(a)
  print (ans)
solve()


Measured memory_bytes: 22580