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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 2505;
struct edge { int u,v,c; };
int dist[maxn], vis[maxn]; VI G[maxn]; vector<edge> E;

void dfs(const int u)
{
    vis[u]++;
    FOR_ALL(e,G[u]) {
        const int v = E[*e].v;
        if (!vis[v])
            dfs(v);
    }
}

int bfs(const int n)
{
    memset(vis,0,sizeof(vis));
    FOR(i,1,n+1)
        dist[i] = -inf;
    dist[1] = 0;
    queue<int> Q; Q.push(1); vis[1]++; VI cnt(n+1); cnt[1]++;
    while (Q.size()) {
        const int u = Q.front(); Q.pop(); vis[u] = 0;
        FOR_ALL(e,G[u]) {
            const int v = E[*e].v;
            const int c = E[*e].c;
            const int d = dist[u]+c;
            if (d > dist[v]) {
                dist[v] = d;
                if (!vis[v]) {
                    Q.push(v); vis[v]++; 
                    if (++cnt[v] > n)
                        return -1;                                
                }
            }
        }
    }
    return max(0,dist[n]);
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,p;
    while (cin >> n >> m >> p) {
        FOR(i,1,n+1)
            G[i].clear();
        E.resize(m);
        FOR(i,0,m) {
            int u,v,c; cin >> u >> v >> c;
            E[i].u = u; E[i].v = v; E[i].c = c-p;
            G[u].push_back(i);
        }
        VI good(n+1);
        FOR(i,1,n+1) {
            memset(vis,0,sizeof(vis));
            dfs(i);
            good[i] = vis[n];
        }
        FOR(i,1,n+1)
            G[i].clear();
        FOR(i,0,m) {
            const int u = E[i].u;
            const int v = E[i].v;
            if (good[v])
                G[u].push_back(i);
        }
        cout << bfs(n) << endl;
    }
    return 0;
}


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

class Program
{
  static void Main()
  {
    int n = int.Parse(Console.ReadLine());
    long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
    long[] b = Console.ReadLine().Split().Select(long.Parse).ToArray();
    var c = new long[n];
    for (int k = 0; k < n; k++) c[k] = a[k] - b[k];
    Array.Sort(c);
    long sum = 0;
    int i = 0;
    for (; i < n; i++)
    {
      if (c[i] >= 0) break;
      sum += -c[i];
    }
    Array.Reverse(c);
    int j = 0;
    for (; sum > 0; j++)
    {
      if (c[j] <= 0)
      {
        Console.WriteLine(-1);
        return;
      }
      sum -= c[j];
    }
    Console.WriteLine(i + j);
  }
}

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

int main()
{
  int n; cin >> n;
  int ans = 0;
  for(int i=1; i < n+1; i ++) {
    string s = to_string(i);
    if(s.size() % 2 != 0) ans++;
  }
  cout << ans << endl;;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
 #include<algorithm>
 using namespace std;
 #define N 100010
 int main(){
 int n,m,h[N],ma[N];
 cin>>n>>m;
 for(int i=1;i<=n;i++){
 cin>>h[i];
 ma[i]=0;
 }
   for(int i=0;i<m;i++){
 int a,b;
 cin>>a>>b;
 ma[a]=max(ma[a],h[b]);
 ma[b]=max(ma[b],h[a]);
 }
 int ans=0;
 for(int i=1;i<=n;i++){
 ans+=h[i]>ma[i];
}
 cout<<ans<<endl;
 }

Measured memory_bytes: 4316
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.ST << ", " << p.ND << ")";
}

template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto &e : x)
        	out << e << (&e == &*--x.end() ? "" : ", ");
	return out << '}';
}

template<class... Args> void dump(Args&&... args) {
	((cerr << args << ";  "), ...);
}
 
#ifdef DEBUG
#  define debug(x...) cerr << "[" #x "]: ", dump(x), cerr << "\n"
#else
#  define debug(...) false
#endif
 
template<class T> int size(T && a) { return (int) a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

mt19937 rng(2137);
int rd(int a, int b) {
	return uniform_int_distribution<int>(a, b)(rng);
}

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

	auto start = chrono::steady_clock::now();

	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	REP(i, n) cin >> c[i];
	vector<vector<int>> s(d, vector<int>(n));
	REP(i, d) REP(j, n) cin >> s[i][j];

	auto get_score = [&](vector<int> &ans) {
		LL score = 0;
		vector<int> last(n, -1);
		REP(i, d) {
			score += s[i][ans[i]];
			last[ans[i]] = i;
			REP(j, n) score -= c[j] * (i - last[j]);
		}
		return score;
	};

	auto get_time = [&]() {
		auto curr = chrono::steady_clock::now();
		return int(chrono::duration_cast<chrono::milliseconds>(curr - start).count());
	};

	auto init = [&]() {
		vector<int> ans(d), last(n, -1);
		REP(i, d) {
			PII opt = {0, -1};
			REP(j, n)
				opt = max(opt, {s[i][j] + c[j] * (i - last[j]), j});
			ans[i] = opt.ND;
			last[ans[i]] = i;
		}
		return ans;
	};

	vector<int> best = init();
	LL best_score = get_score(best);

	auto try_update = [&](vector<int> &cur) {
		LL new_score = get_score(cur);
		if(new_score >= best_score) {
			best = cur;
			best_score = new_score;
		}
	};

	while(get_time() <= 1950) {
		auto cur = best;
		if(get_time() <= 700 || rd(0, 1)) {
			int x = rd(0, d - 1);
			cur[x] = rd(0, 25);
		}
		else {
			int len = rd(2, 10);
			int x = rd(0, d - len);
			shuffle(cur.begin() + x, cur.begin() + x + len, rng);
		}
		try_update(cur);
	}

	for(int x : best)
		cout << x + 1 << "\n";
}


Measured memory_bytes: 3652
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int w[] = new int[n];
    int s[] = new int[n+1];
    s[0] = 0;
    int d[] = new int[n];
    for(int i=0;i<n;i++){
      w[i] = sc.nextInt();
    }
    for(int i=0;i<n;i++){      
      s[i+1]=w[i]+s[i];
    }
    for(int i=0;i<n;i++){
      d[i]=Math.abs((s[n]-s[i])-s[i]);
    }   
    Arrays.sort(d);
    System.out.println(d[0]);
    
  }
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define ll long long
int main()
{
	int n;
	int arr[1100];
	cin>>n;
	int flag=1;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]%2==0)
		{
			if(arr[i]%3!=0&&arr[i]%5!=0)
			{
				flag=0;
			}
		}
	}
	if(flag==0)
	{
		cout<<"DENIED"<<endl;
	}
	else
	{
		cout<<"APPROVED"<<endl;
	}
	return 0;
}

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

int main(void)
{
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; i++)
		cin >> l[i];

	sort(l.begin(), l.end(), greater<>());

	cout << accumulate(l.begin(), l.begin()+k, 0) << endl;
	return 0;
}


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

int main() {
	long long x;cin>>x;unordered_map<long long,int> st;
	for(int i=-3000;i<=3000;i++){
	    long long v=pow(i,5);
	    st[v]=i;
	}
	long long a,b;
	for(auto i:st){
	    long long m=x+i.first;
	    if(st.find(m)!=st.end()){
	        a=st[m];b=i.second;
	        break;
	    }
	}
	cout<<a<<" "<<b;
	return 0;
}


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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
using ll = long long;

void no() {
    cout << "Rabbit" << endl;
    exit(0);
}
bool solve() {
    string S;
    cin >> S;
    stack<char> stk;
    int N = S.size();
    REP(i, N) {
        if (i > 0 && stk.empty()) no();
        if (S[i] == 'm') {
            stk.push(S[i]);
        } else if (S[i] == 'e') {
            if (stk.empty() || stk.top() != 'm')
                no();
            else
                stk.push(S[i]);
        } else if (S[i] == 'w') {
            if (stk.empty() || stk.top() != 'e')
                no();
            else {
                stk.pop();
                stk.pop();
            }
        }
    }
    if (stk.empty()) {
        cout << "Cat" << endl;
    } else
        no();
}
signed main() { solve(); }


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

const int INF = 1001001001;
const int MAX_V = 100100;
const int MAX_N = 110;
ll dp[MAX_N][MAX_V];
ll w, weight[MAX_N], value[MAX_N];
int n;

int main() {
    cin >> n >> w;
    rep(i,n) cin >> weight[i] >> value[i];
    rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n) {
        rep(V, MAX_V){
            if(V >= value[i]) chmin(dp[i+1][V], dp[i][V-value[i]] + weight[i]);
            chmin(dp[i+1][V], dp[i][V]);
        }
    }
    ll ans = 0;
    rep(V, MAX_V){
        if(dp[n][V] <= w) ans = V;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int W, H, N;
    int x[100], y[100], a[100];

    cin >> W >> H >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i] >> a[i];
    }

    int lx = 0, rx = W, dy = 0, uy = H;
    for (int i = 0; i < N; i++)
    {
        if (a[i] == 1 && x[i] > lx)
        {
            lx = x[i];
        }
        else if (a[i] == 2 && x[i] < rx)
        {
            rx = x[i];
        }
        else if (a[i] == 3 && y[i] > dy)
        {
            dy = y[i];
        }
        else if (a[i] == 4 && y[i] < uy)
        {
            uy = y[i];
        }
    }

    if (rx - lx <= 0 || uy - dy <= 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << (rx - lx) * (uy - dy) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  connected_components
//
//  Created by ???????????? on 2017/10/22.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

#define n_max 100000

#define NIL -1

bool found;
int n;
int color[n_max];
vector<int> G[n_max];

void encode_graph_list(){
    int i, id, node, f;
    
    scanf("%d", &n);
    scanf("%d", &node);
    
    for (i = 0; i < node; i++){
        scanf("%d", &id);
        scanf("%d", &f);
        G[id].push_back(f);
        G[f].push_back(id);
    }
    
}

void dfs(int u, int c){
    color[u] = c;
    for (int v = 0; v < G[u].size(); v++){
        int t = G[u][v];
        if(color[t] == NIL){
            dfs(t, c);
        }
    }
}

void assign_color(){
    int id = 0;
    for(int i = 0; i < n; i++) color[i] = NIL;
    for(int i = 0; i < n; i++){
        if(color[i] == NIL){
            dfs(i, id++);
        }
    }
}


int main(int argc, const char * argv[]) {
    int qs, i, id, target;
    encode_graph_list();
    assign_color();
    scanf("%d", &qs);
    for (i = 0; i < qs; i++){
        scanf("%d %d", &id, &target);
        if(color[id] == color[target]) cout << "yes" <<endl;
        else cout << "no"<<endl;
    }
    return 0;
}

Measured memory_bytes: 12224
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
#define EPS 1e-9
#define tc int t; cin >> t; while(t--)
using namespace std;

int main() {
    FIO;
    ll ans = 0;
    int n; cin >> n;
    vi v(n + 1);
    map <int,int> m;
    FOR(i,1,n) {
        cin >> v[i];
        m[i - v[i]]++;
    }
    FOR(i,1,n){
        int x = i + v[i];
        if(m.find(x) == m.end()) continue;
        ans += m[x];
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 12704
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
    scanf("%d", &b[i]);

  lint op_count = 0;
  lint need_op = 0;
  for (int i = 0; i < n; ++i) {
    op_count += b[i] - a[i];
    if (b[i] < a[i]) {
      need_op += a[i] - b[i];
    } else if (b[i] % 2 != a[i] % 2) {
      ++need_op;
    }
  }

  if (op_count >= need_op && (op_count - need_op) % 2 == 0) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 384
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
 
int main()
{
    ll n;
    cin >> n;
    vector<map<char, ll>> s(n);
    rep(i, n) {
        string tmp;
        cin >> tmp;
        rep(j, tmp.size()) {
            s[i][tmp[j]]++;
        }
    }
    
    set<char> st;
    rep(i, 26) {
        bool flag = false;
        for(auto m : s) {
            if (m.find((char)'a' + i) == m.end()) {
                flag = true;
            }
        }
        if(!flag) {
            st.insert((char)'a' + i);
        }
    }
    string ret = "";
    for(auto c : st) {
        ll mi = MOD;
        for(auto m : s) {
            mi = min(mi, m[c]);
        }
        rep(i, mi) ret += {c};
    }
    print(ret);
    return 0;
}

Measured memory_bytes: 384
#=
B:
- Julia version: 
- Author: abap
- Date: 2020-01-10
=#
N = parse(readline())
S = readline()
count = 0
for i in 1:N
	s = S[i]
	if s =='A'
		if S[i+1] == 'B' && S[i+2] == 'C'
			count += 1
		end
	end
end
println(count)

Measured memory_bytes: 169048
#include <iostream>
#include <vector>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int prime[10001];

void CreatePrime(int n)
{
	rep(i,n)
	{
		prime[i] = 1;
	}

	prime[0] = prime[1] = 0;

	REP(i,2,sqrt(n))
	{
		if(prime[i])
		{
			for(int j=0;i*(j+2) < n;j++)
			{
				prime[i*(j+2)] = 0;
			}
		}
	}
}

int main()
{
	int n;
	CreatePrime(10001);

	while(cin >> n && n)
	{
		for(int i=n;i>=0;i--)
		{
			if(prime[i] && prime[i-2])
			{
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

void fnInput(int& rnPriceA, int& rnPriceB, int& rnPriceH, 
             int& rnNumA,   int& rnNumB)
{
  cin >> rnPriceA >> rnPriceB >> rnPriceH;
  cin >> rnNumA   >> rnNumB;
}

int fnMinCheck(int nPriceA, int nPriceB, int nPriceH, int nNumA, int nNumB)
{
  int nPriceMin;
  if      (nNumA < nNumB)
    nPriceMin = min( nPriceA * nNumA + nPriceB * nNumB,
                     min( (2 * nPriceH - nPriceB) * nNumA + nPriceB * nNumB,
                          2 * nPriceH * nNumB ) );
  else if (nNumA == nNumB)
    nPriceMin = min( (nPriceA + nPriceB) * nNumA, 2 * nPriceH * nNumA );
  else
    nPriceMin = min( nPriceA * nNumA + nPriceB * nNumB,
                     min( nPriceA * nNumA + (2 * nPriceH - nPriceA) * nNumB,
                          2 * nPriceH * nNumA ) );
  return nPriceMin;
}

int main()
{
  int nPriceA, nPriceB, nPriceH, nNumA, nNumB;
  
  fnInput(nPriceA, nPriceB, nPriceH, nNumA, nNumB);
  cout << fnMinCheck(nPriceA, nPriceB, nPriceH, nNumA, nNumB) << endl;

  return 0;
}

Measured memory_bytes: 256
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>

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

//const long long INF = 1LL << 60;
const int INF = 1e9;

int main()
{
	int N = 0;
	std::cin >> N;
	std::vector<int> L(N);
	rep( i, N )	std::cin >> L[i];

	int ans = 0;

	std::sort( L.begin(), L.end() );
	// 100 * 100 * 100なので、全探索して大丈夫 
	for( int a = 0; a < N; a++ )
	{
		for( int b = a+1; b < N; b++ )
		{
			if( L[a] == L[b] )
			{
				continue;
			}

			for( int c = b+1; c < N; c++ )
			{
				if( ( L[a] == L[c] ) || ( L[b] == L[c]) )
				{
					continue;
				}

				int A, B, C;
				A = L[a];
				B = L[b];
				C = L[c];

				if( ( A + B > C ) &&
					( B + C > A ) &&
				    ( C + A > B ) )
				{
					//printf( "[%d, %d, %d]\n", a+1, b+1, c+1 );
					ans++;
				}
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 3604
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0

for i in range(n-1):
    ans += b[a[i]-1]
    if a[i+1] == a[i] + 1:
        ans += c[a[i]-1]

ans += b[a[n-1]-1]

print(ans)

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

using namespace std;

typedef long long ll;
typedef pair <int, int> P;
int main(){

  ll n,d,a;
  cin >>n>>d>>a;
  vector<pair<ll,ll> >x;
  for (ll i=0; i<n; i++){
    ll x1,h1;
    cin>>x1>>h1;
    x.push_back(make_pair(x1,h1));
  }
  queue <pair<ll, ll> > q;
  ll cnt=0;
  ll damage=0;
  sort(x.begin(), x.end());


  for (ll i=0; i<n; i++){

    while(q.size() && q.front().first<x[i].first){
      damage-=q.front().second;
      q.pop();
    }
    if (x[i].second<=damage) continue;


    ll attack=ceil(double(x[i].second-damage)/a);
    cnt+=attack;
    q.push(make_pair(x[i].first+2*d,attack*a));

    damage+=attack*a;


}
cout<<cnt<<endl;
}


Measured memory_bytes: 6384
use proconio::input;

fn main() {
    input! {
        n: u64
    }

    let ans = sum(n) - sum(n/3) * 3 - sum(n/5) * 5 + sum(n/15) * 15;

    println!("{}", ans);
}

fn sum(n: u64) -> u64 {
    n * (n+1) / 2
}


Measured memory_bytes: 2136
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	long long x, y;
	cin >> x >> y;
	int ans = 0;
	while(x <= y){
		x *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int num;
	map<int, int>m;
	rep(i, 3) {
		cin >> num;
		m[num]++;
	}
	if (m[5] == 2 && m[7] == 1)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,M;
  cin >>N>>M;
     vector<int> A(N);
   for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int sum=0;
  for (int i = 0; i < N; i++) {
 sum += A[i];
}
  double S =(1.0*sum)/(4*M);
  int count =0;
for (int i = 0; i < N; i++) {
  if(A[i]>=S){
count++;
  }
}
  if(count >=M){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=100000+5;
const int INF=80000005;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
inline int add(int a,int b){return (a+=b)>=P?a-P:a;}
inline int sub(int a,int b){return (a-=b)<0?a+P:a;}
inline int mul(int a,int b){return 1LL*a*b%P;}
int n,m,R;
int r[10],p[10];
int a,b,c,f[205][205];
int main(){
    read(n),read(m),read(R);
    for (int i=1;i<=R;i++) read(r[i]);
    for (int i=1;i<=n;i++)for (int j=1;j<=n;j++) f[i][j]=INF;
    for (int i=1;i<=m;i++){
        read(a),read(b),read(c);
        if (f[a][b]==INF)f[a][b]=f[b][a]=c;
        else f[a][b]=f[b][a]=min(f[a][b],c);
    }
   for (int k=1;k<=n;k++){
        for (int i=1;i<=n;i++)if (f[i][k]!=INF){
            for (int j=1;j<=n;j++)if(f[k][j]!=INF){
                f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
            }
        }
    }
    for (int i=1;i<=R;i++) p[i]=i;
    ll ans=1LL*INF;
    do{
        int pre=r[p[1]];
        ll tmp=0;
        for (int i=2;i<=R;i++){
            tmp+=1LL*f[pre][r[p[i]]];
            pre=r[p[i]];
        }
        ans=min(ans,tmp);
    }while (next_permutation(p+1,p+1+R));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

int n = 8;
vvi f;

int count(int y, int x, int dy, int dx, int p) {
	int ny = y+dy;
	int nx = x+dx;
	int res = 0;
	while( f[ny][nx] == 3-p ) {
		res++;
		ny += dy;
		nx += dx;
	}
	if( f[ny][nx] == p ) {
		return res;
	}
	return 0;
}

void fill(int y, int x, int dy, int dx, int p) {
	int ny = y + dy;
	int nx = x + dx;
	while(f[ny][nx]==3-p) {
		ny += dy;
		nx += dx;
	}
	if( f[ny][nx] == p ) {
		ny = y + dy;
		nx = x + dx;
		while(f[ny][nx] == 3-p) {
			f[ny][nx] = p;
			ny += dy;
			nx += dx;
		}
	}
}

bool passed = false;

void solve(bool turn) {
	const int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
	const int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};

	if(turn) {
		int maxi = 0, my=0, mx=0;
		for(int y=1; y<=n; y++) {
			for(int x=1; x<=n; x++) {
				if(f[y][x] != 0) continue;
				int c = 0;
				rep(i, 8) {
					c += count(y, x, dy[i], dx[i], 1);
				}
				if(maxi < c) {
					maxi = c;
					my = y;
					mx = x;
				}
			}
		}
		if(maxi > 0) {
			passed = false;
			f[my][mx] = 1;
			rep(i, 8) {
				fill(my, mx, dy[i], dx[i], 1);
			}
			solve(!turn);
		} else {
			if(passed) return;
			passed = true;
			solve(!turn);
		}
	} else {
		int maxi = 0, my=0, mx=0;
		for(int y=n; y>=1; y--) {
			for(int x=n; x>=1; x--) {
				if(f[y][x] != 0) continue;
				int c = 0;
				rep(i, 8) {
					c += count(y, x, dy[i], dx[i], 2);
				}
				if(maxi < c) {
					maxi = c;
					my = y;
					mx = x;
				}
			}
		}
		if(maxi > 0) {
			passed = false;
			f[my][mx] = 2;
			rep(i, 8) {
				fill(my, mx, dy[i], dx[i], 2);
			}
			solve(!turn);
		} else {
			if(passed) return;
			passed = true;
			solve(!turn);
		}
	}
}

int main() {
	f.resize(n+2);
	rep(y, n+2) {
		f[y].resize(n+2);
	}
	rep(x,n+2) {
		f[0][x] = 3;
		f[n+1][x] = 3;
	}
	for(int y=1; y<=n; y++) {
		string in;
		cin >> in;
		f[y][0] = 3;
		f[y][n+1] = 3;
		for(int x=1; x<=n; x++) {
			if( in[x-1] == 'o' ) {
				f[y][x] = 1;
			} else if( in[x-1] == 'x' ) {
				f[y][x] = 2;
			} else {
				f[y][x] = 0;
			}
			//cout << f[y][x];
		}
		//cout << endl;
	}
	solve(true);
	string ch = ".ox";
	for(int y=1; y<=n; y++) {
		for(int x=1; x<=n; x++) {
			cout << ch[ f[y][x] ];
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int sum = 0;
  
  for(int i = 0; i < k; i++) {
    if(a >= 1) {
      sum = sum + 1;
      a = a - 1;
    } else if(b >= 1) {
      b = b - 1;
    } else {
      sum = sum - 1;
      c = c - 1;
    } 
  }
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int q;
  cin >> q;
  deque<int> v;
  // vector<int> output;
  int tmp;
  int tmp2;
  int tmp3;
  rep_i(i, q){
    cin >> tmp;
    if(tmp == 0){
      cin >> tmp2 >> tmp3;
      if(tmp2 == 0){
        v.push_front(tmp3);
      }else if(tmp2 == 1){
        v.push_back(tmp3);
      }
    }else if(tmp == 1){
      cin >> tmp2;
      cout << v[tmp2] << endl;
    }else{
      cin >> tmp2;
      if(tmp2 == 0){
        v.pop_front();
      }else if(tmp2 == 1){
        v.pop_back();
      }
    }
  }
}


Measured memory_bytes: 4540
n, m = map(int, input().split())
m_list = []
for i in range(m):
    m_list.append(list(map(int, input().split())))
m_list = sorted(m_list)
b_s = 0
b_e = n
cnt = 1
for i in range(m):
    a, b = m_list[i][0], m_list[i][1]
    if b_s <= a < b_e:
        if b_s < a:
            b_s = a
        if b < b_e:
            b_e = b
    else:
        cnt += 1
        b_s = a
        b_e = b
print(cnt)


Measured memory_bytes: 28660
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]

def array2d(N, M, initial=0):
    return [[initial]*M for _ in range(N)]

def copy2d(orig, N, M):
    ret = array2d(N, M)
    for i in range(N):
        for j in range(M):
            ret[i][j] = orig[i][j]
    return ret


INF = float("inf")
MOD = 10**9 + 7


def main():
    X, K, D = MAP()

    if 0 <= X and 0 <= X - K*D:
        print(X-K*D)
        return
    if X <= 0 and X + K*D <= 0:
        print(abs(X+K*D))
        return

    if (X // D) % 2 == K % 2:
        print(X % D)
    else:
        print(abs(X % D-D))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9256
n,m = (int(i) for i in input().split())
p = 10**5
x = [0]*(p+1)
for i in range(m):
    l,r = (int(i)-1 for i in input().split())
    x[l]+=1
    x[r+1]-=1
for i in range(p): x[i+1]+=x[i]
print(x.count(m))

Measured memory_bytes: 6900
s = input()
l = len(s)
idx_a = 0
idx_z = 0
for n in range(l):
    if s[l-n-1] == 'A':
        idx_a = l-n-1
    if s[n] == 'Z':
        idx_z = n
    
print(idx_z-idx_a+1)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    int k;
    cin >> k;
    cin >> s;
    if(s.length() <= k){
        cout << s;
    }else{
        s = s.substr(0, k);
        s = s + "...";
        cout << s << endl;
    }
    return 0;
}


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

int main(){
    long long q,h,s,d;
    long long n;
    cin>>q>>h>>s>>d>>n;

    long long sum=0;
    if(d<2*s && d<4*h && d<8*q){
        sum+=(n/2)*d;
        n%=2;
    }
    if(s<2*h && s<4*q){
        sum+=n*s;
        n=0;
    }
    if(h<2*q){
        sum+=2*n*h;
        n=0;
    }
    {
        sum+=4*n*q;
        n=0;
    }

    cout<<sum<<endl;
}

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


void dfs(int &ans, int n, long long x, bool three, bool five, bool seven){
    if(x>n) return;
    if(three&&five&&seven) ans++;
    dfs(ans, n, 10*x + 3, true, five, seven);
    dfs(ans, n, 10*x + 5, three, true, seven);
    dfs(ans, n, 10*x + 7, three, five, true);
}

int main(){
    int n;
    cin >> n;
    int ans = 0;
    dfs(ans, n, 0, false, false, false);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N=55;
const int MOD=1e9+7;

int n;
LL p,ans;
LL a[N][N],b[N][N],c[N][N];
void Add(LL &x,LL y)
{
	x+=y;
	if(x>=MOD) x-=MOD;
}

int main()
{
	scanf("%d%lld",&n,&p);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
		scanf("%lld",&a[i][j]);
	p--;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
		b[i][j]=a[i][j];
	while(p)
	{
		memset(c,0,sizeof(c));
		if(p&1)
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		for(int k=1;k<=n;k++)
			Add(c[i][j],a[i][k]*b[k][j]%MOD);
		if(p&1) swap(b,c);
		p>>=1;
		memset(c,0,sizeof(c));
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		for(int k=1;k<=n;k++)
			Add(c[i][j],a[i][k]*a[k][j]%MOD);
		swap(a,c);
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
		Add(ans,b[i][j]);
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
let weight n = 
  let rec iter = function
    | [] -> []
    | hd :: tl when n land hd = 0 -> iter tl
    | hd :: tl -> hd :: iter tl
  in iter [1;2;4;8;16;32;64;128;256;512]

let rec join s = function
  | [] -> ""
  | [x] -> string_of_int x
  | hd :: tl -> string_of_int hd ^ s ^ join s tl

let _ = 
  try 
    while true do
      let n = read_int () in
      let lst = weight n in
      print_endline (join " " lst)
    done
  with
    End_of_file -> ()

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

using namespace std;

int main()
{
//    vector <> vec;
//    vec.clear;
    //char a[10000],b[10000];
    string a,b;
    int n,c=0;
    cin>>a>>b;
  //  cout<< b+a+t <<endl;
//    while (t--){}
//    n=strlen(a);
    n=a.size();
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]) c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3916
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul

mod = 10 ** 9 + 7
INF = 10 ** 13
sys.setrecursionlimit(2147483647)
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
A = LI()
ret = 1
for i in range(n):
    if A[i] == 0:
        print(0)
        exit()

for i in range(n):
    ret *= A[i]
    if ret > 10 ** 18:
        print(-1)
        exit()

print(ret)





Measured memory_bytes: 95048
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    vec<int> v(5);

    for (auto & e : v)
    {
        cin >> e;
    }

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

    int ans {1000000};

    while (true)
    {
        int sum{};
        for (auto e: v)
        {
            if (sum % 10 != 0)
                sum += 10 - (sum % 10);
            sum += e;
        }

        ans = min({ans, sum});

        if (!next_permutation(v.begin(), v.end()))
        {
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> Ls(N);
  for (int i = 0; i < N; i++) {
    cin >> Ls[i];
  }
  int bounses = 0;
  int position = 0;
  for (int i = 0; i < N; i++) {
    if (position > X) {
      cout << bounses << endl;
      return 0;
    } else {
      bounses++;
      position += Ls[i];
    }
  }
  if (position > X) {
      cout << N << endl;
      return 0;
    } else {
    cout << N + 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
let readCharArray _ = stdin.ReadLine().ToCharArray()

()
|> readCharArray
|> fun a -> if (a |> Array.last) = 's' then Array.concat [ a; [| 'e'; 's' |] ] else Array.concat [ a; [| 's' |] ]
|> System.String
|> printfn "%s"


Measured memory_bytes: 29644
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    return x*y/(T)GCD(x,y);
}
int main(){
    int n,d; cin >> n >> d;
    int ans = 0;
    if (n % (2*d+1) == 0) ans = n/(2*d+1);
    else ans = n/(2*d+1) + 1;
    cout << ans << endl;
}
  



Measured memory_bytes: 256
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)

g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)

for _ in range(q): #各頂点についてcount[v]を計算
    v,val=map(int,input().split())
    cnt[v]+=val

q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
    v=q.pop()
    checked[v]=1 #頂点を見たかどうかのフラグを更新する
    for u in g[v]:
        if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
            continue
        cnt[u]+=cnt[v]
        q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる


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

static const int mod = 998244353;
inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline void inc(int &x, int y) { (x += y) >= mod && (x -= mod); }
inline int mul(int x, int y) { return 1LL * x * y % mod; }

unordered_map<string, int> dp;
int dfs(const string &s) {
  if (s.empty()) return 1;
  if (dp.find(s) != dp.end()) return dp[s];
  int n = (int)s.size();
  int &res = dp[s];
  res = dfs(s.substr(1));
  if (s[0] == '1') inc(res, res);
  for (int len = 1; len < n; ++len) {
    string f = s.substr(0, len);
    for (int i = len; i + len - 1 < n; i += len) {
      for (int j = 0; j < len; ++j) {
        if (s[i + j] == '0' && f[j] == '1') f[j] = '0';
      }
      inc(res, mul(dfs(f), dfs(s.substr(i + len))));
    }
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  cout << dfs(s) << endl;
  return 0;
}


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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = a[0];
    for (int i = 1; i < n; i++) {
        ll tmp = 1000000000000000000LL / a[i];
        if (ans > tmp) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4052
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
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 (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用コメント
  int n;
  std::cin >> n;
  if (n == 1) {
    std::cout << 1 << '\n';
    return;
  }

  int counter = 0;
  int ans;
  repf(i, 1, n + 1) {
    int tmp = 0;
    int hoge = i;
    while (hoge % 2 == 0) {
      hoge /= 2;
      tmp++;
    }
    if (chmax(counter, tmp)) {
      ans = i;
    }
  }

  std::cout << ans << '\n';

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
t = input()
t = list(t)
length = len(t)


for a in range(length-1, -1, -1):
    # 最後尾
    if t[a] == '?':
        if a == length - 1:
            t[a] = 'D'
            continue

    #a == 1
    if t[a] == '?' and a == 1:
        if t[a+1] == 'P':
            t[a] = 'D'

        elif t[a+1] == 'D':
            t[a] = 'D'

    #
    if t[a] == '?':
        if t[a+1] == 'P':
            if t[a-1] == 'P':
                t[a] = 'D'
            elif t[a-1] == 'D':
                t[a] = 'D'
            elif t[a-1] == '?':
                t[a] = 'D'

        elif t[a+1] == 'D':
            if t[a-1] == 'P':
                t[a] = 'D'
            elif t[a-1] == 'D':
                t[a] = 'P'
            elif t[a-1] == '?':
                t[a] = 'D'

print(''.join(t))


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

const long long MOD = 1000000007;

map<int, int> prime_number_factor(int n) {
    map<int, int> res;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n /= 1) res[n] = 1;
    return res;
}

int main() {
    int n;
    cin >> n;
    map<int, long long> m;

    for (int i = 2; i <= n; i++) {
        map<int, int> mi = prime_number_factor(i);
        for (auto ite: mi) {
            m[ite.first] += ite.second;
        }
    }

    long long ans = 1;
    for (auto ite: m) {
        if (ite.first == 1) continue;
        ans *= (ite.second + 1) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}   

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

int main () {
    int N;
    cin >> N;
    vector<int> botan(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
         botan.at(i) = a - 1;
    }
    int x = 0;
    for (int i = 0; i <= N; i++) {
        x = botan.at(x);
        if (x == 1) {
            cout << i + 1 << endl;
            break;
        }
        else if (i == N) {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 640
from heapq import *

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

p2 = p[:x]
q2 = q[:y]

heapify(p2)
heapify(q2)

for i in range(c):
    if r[i] <= p2[0] and r[i] <= q2[0]:
        break

    if p2[0] < q2[0]:
        heappop(p2)
        heappush(p2, r[i])
    else:
        heappop(q2)
        heappush(q2, r[i])

print(sum(p2) + sum(q2))


Measured memory_bytes: 23360
#include <iostream>
#include <map>
using namespace std;
int main(void){
    // Your code here!
    int n; cin>>n;
    map<int,int> mp;
    for(int i = 0; i < n; ++i){
        int a; cin>>a;
        if(n%2==a%2 || n-1<a){
            cout<<0<<endl;
            return 0;
        }
        ++mp[a];
    }
    if(n%2==0){
        for(pair<int,int> p:mp){
            if(p.second != 2){
                cout<<0<<endl;
                return 0;
            }
        }
    } else{
        for(pair<int,int> p:mp){
            if((p.first == 0 && p.second != 1) || (p.first != 0 && p.second != 2)){
                cout<<0<<endl;
                return 0;
            }
        }
    }
    long long res = 1;
    for(int i = 0; i < n/2; ++i){
        res = res * 2 % 1000000007;
    }
    cout << res <<endl;
}


Measured memory_bytes: 2560
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n,d,a=map(int,input().split())
# xh=[list(map(int,input().split())) for i in range(n)]
xh=[]
for i in range(n):
    xh.append(list(map(int,input().split())))
xh.sort()
r,tama=[],[0]

for i in range(n):
    x,h=xh[i]
    tmpr=bisect.bisect_left(r,x)
    h-=(tama[-1]-tama[tmpr])*a
    tmp=0
    if h>0:
        tmp=math.ceil(h/a)
    tama.append(tmp)
    tama[i+1]+=tama[i]
    r.append(x+2*d)

print(tama[-1])
# print(r)

Measured memory_bytes: 123864
using System;
using System.IO;
using System.Collections.Generic;

namespace ARC088C
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var X = ss.Next(long.Parse);
            var Y = ss.Next(long.Parse);

            var ans = 0;
            for (var i = X; i <= Y; i <<= 1) ans++;
            sw.WriteLine(ans);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13268