akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(s,t) for (int s = 0; s < t; s++);
using namespace std;
using ll = long long;


int main() {
  int n,x,k;

  cin >> n >> x;

  vector<int> l(n + 1);

  l[0] = 0;

  for ( int i = 0; i < n; i++){
    cin >> k;
    l[i + 1] = l[i] + k;
  }

  int ans = 0;

  for (int i = 0; i <= n; i++){
    if (l[i] <= x){
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){ 
    int a[10];
    int ans;

    for (int i = 0; i < 4; ++i) {
        scanf("%d", &a[i]);
    }
    
    if(a[0]!=a[2]){
        ans = 1;
    }else{
        ans = 0;
    }
    
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
N=int(input())
s=input()
n=len(s)
MOD = 10**9+7
dp = [[0]*(N+n+1) for _ in range(2)]
dp[0][0] = 1
for i in range(N):
    src = i%2
    tgt = (i+1)%2
    dp[tgt][-1] = (2*dp[src][-2])%MOD
    dp[tgt][0] = sum(dp[src][0:2])%MOD
    for j in range(1,N+n):
        dp[tgt][j] = (dp[src][j-1]*2 + dp[src][j+1])%MOD
tmp = pow(2**n,MOD-2,MOD)
res = (dp[N%2][n]*tmp)%MOD
print(res)



Measured memory_bytes: 43312
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(char c: s)
        if (c == '2')
            ans += 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define ull         unsigned long long int
#define ll          long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e12+1;
const long long mod = (long long) 20437;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y,ll m){
  ll res=1;
  while(y>0){
    if(y%2) res=(x%m*res%m)%m;
    x=(x%m*x%m)%m;    
    y=y/2;
  }
  
  return res%m;
}
 
ll modinv(ll x){
  return power(x,hell-2,1);
}

ll gcd(ll a,ll b){
    while(b!=0){
		ll t=b;
		b=a%t;
		a=t;
	}
	return a;
}    
    
void fastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
} 

void solve(){
    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;
}    
    
int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
   
   while(test--)
   solve();
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
  cin >> s >> t;
  for(int i=0;i<t.size();++i)
  {
  cout << s.at(i) << t.at(i);
  }
  if(t.size()<s.size()) cout << s.at(s.size()-1);
return 0;}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxx = 2000000;
const int INF = 1 << 30;

int A[maxx + 1];
int n;
void maxHeapify(int i) {

    int left = 2 * i, right = 2 * i + 1;
    int largest;

    // 从左子结点、自身、右子结点选出值最大的结点，然后继续往下递归
    if (left <= n && A[left] > A[i])
        largest = left;
    else
        largest = i;

    if (right <= n && A[right] > A[largest])
        largest = right;

    if (largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }

}

int extract() 
{
    int maxv;
    if (n < 1)
        return -INF;
    maxv = A[1];
    A[1] = A[n--];
    maxHeapify(1);
    return maxv;
}

int insert(int key) {
    n++;
    int i = n;
    A[n] = -INF;
    if (key < A[i])
        return -INF;
    A[i] = key;
    while (i > 1 && A[i / 2] < A[i]) {
        swap(A[i], A[i / 2]);
        i /= 2;
    }

}
int main()
{
    char op[20];
    int k;
    while (scanf("%s", op) != EOF&&op[2] != 'd') {
        if (op[0] == 'i') {
            scanf("%d", &k);
            insert(k);
        }
        else {
            printf("%d\n", extract());
        }
    }
    return 0;
}


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

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

  stack<int> sknCal;
  string sCal;
  
  while (cin >> sCal)
  {
    if (sCal == "+" || sCal == "-" || sCal == "*")
    {
      int nNum1 = sknCal.top(); sknCal.pop();
      int nNum2 = sknCal.top(); sknCal.pop();
      int nRes;
      if      (sCal == "+")
        nRes = nNum2 + nNum1;
      else if (sCal == "-")
        nRes = nNum2 - nNum1;
      else if (sCal == "*")
        nRes = nNum2 * nNum1;
      else;
      
      sknCal.push(nRes);
    }
    else
    {
      int nNum = stoi(sCal);
      sknCal.push(nNum);
    }
  }

  cout << sknCal.top() << endl;
  sknCal.pop();

  return 0;
}

Measured memory_bytes: 3220
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <climits>
using namespace std;

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

typedef long long int ll;

int SURP = 1000000007;

int ceil(int a,int b){
	return (a+b-1)/b;
}

ll gcd(ll a,ll b){
	ll p;

	if (b > a){
		p = a;
		a = b;
		b = p;
	}

	while(b != 0){
		p = a % b;
		a = b;
		b = p;
	}
	return a;
}

int main(){
	ll a,b;
	cin >> a >> b;
	ll ret = LLONG_MAX;

	ll tmp1,tmp2;

	tmp1 = a;
	tmp2 = b;
	if(tmp1 <= tmp2){
		if(ret > tmp2 -tmp1) ret = tmp2 -tmp1;
	}
	tmp1 = a*(-1);
	tmp2 = b;
	if(tmp1 <= tmp2){
		if(ret > tmp2 -tmp1 + 1) ret = tmp2 -tmp1 + 1;
	}

	tmp1 = a;
	tmp2 = b*(-1);
	if(tmp1 <= tmp2){
		if(ret > tmp2 -tmp1 + 1) ret = tmp2 -tmp1 + 1;
	}

	tmp1 = a*(-1);
	tmp2 = b*(-1);
	if(tmp1 <= tmp2){
		if(ret > tmp2 -tmp1 + 2) ret = tmp2 -tmp1 + 2;
	}
	cout << ret << endl;

	return 0;
}


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

#define ll long long
#define dl double

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

    dl d=(a*b)/2.0;
    printf("%.9lf ",d);
    if(2*x==a&&2*y==b)
        cout<<1<<endl;
    else
        cout<<0<<endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfInt()
    val bulbFlags = Array(m){ listOfInt().drop(1) }.map { toFlags(n, it) }
    val pp = listOfInt()
    val MAX_TRIAL = Math.pow(2.toDouble(), n.toDouble()).toInt()

    var ans = 0

    for (i in 0 until MAX_TRIAL) {
        var failed = false

        for (j in 0 until m) {
            val on = toBinary((i and bulbFlags[j]), "").count { it == '1' }
            if (pp[j] == 0 && on % 2 != 0) failed = true
            if (pp[j] == 1 && on % 2 != 1) failed = true
        }

        if (!failed) ans++
    }

    println(ans)
}

fun toFlags(digit: Int, list: List<Int>): Int {
    val flags = Array(digit){'0'}
    list.forEach {
        flags[it-1] = '1'
    }

    var result = 0
    flags.forEachIndexed { index, c ->
        if (c == '1') {
            result += Math.pow(2.toDouble(), index.toDouble()).toInt()
        }
    }

    return result
}

fun toBinary(decimalNumber: Int, binaryString: String = "") : String {
    if (decimalNumber > 0) {
        val temp = "${binaryString}${decimalNumber%2}"
        return toBinary(decimalNumber/2, temp)
    }
    return binaryString.reversed()
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 43508
#include<stdio.h>
#include<string.h>

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/*  文字列を整数値に変換*/
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */key%M; }
int h2(int key){ return /* your task */1+(key%(M-1)); }

int find(char str[]){

    /* your task */
	long long key=0, h=0;
	key = getKey(str);
//	printf("key = %lld\n", key);
	for(int i=0; ; i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0) return 1; //H[h]とstrが同じ
		else if(strlen(H[h])==0) return 0;	//H[h]の長さが0
	}
	

}

int insert(char str[]){

    /* your task */
	long long key=0, h=0;
	key = getKey(str);
//	printf("key = %lld\n", key);
	for(int i=0; ; i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0) return 1; //H[h]とstrが同じ
		else if(strlen(H[h])==0)	//H[h]の長さが0
		{
			strcpy(H[h] ,str);	//strをH[h]にコピー
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
		scanf("%s %s", com, str);
	
		if ( com[0] == 'i' ){
			insert(str);
		} else {
	    	if (find(str)){
			printf("yes\n");
	    	} else {
			printf("no\n");
	    	}
		}
    }

    return 0;
}



Measured memory_bytes: 16052
#include <stdio.h>

int main(void) {
    int n, a;
    int _ign = scanf("%d %d", &n, &a);
    int tmp;
    if (!(tmp = (n % 500)))
        printf("Yes");
    else if (tmp <= a)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <queue>
#include <limits>
#include <vector>

using namespace std;

const int DMAX = numeric_limits<int>::max();

enum State
{
    UNVISITED,
    VISITED,
    FINISHED
};

bool isBlack[50][50];
int dist[50][50];
State states[50][50];

int main()
{
    int H, W;
    int black = 0;
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++)
        {
            if (s[j] == '#')
            {
                isBlack[i][j] = true;
                black++;
            }
            else
            {
                isBlack[i][j] = false;
            }

            dist[i][j] = DMAX;
            states[i][j] = State::UNVISITED;
        }
    }

    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    dist[0][0] = 0;
    states[0][0] = State::VISITED;

    while (!q.empty())
    {
        auto v = q.front();
        int x = v.first;
        int y = v.second;
        q.pop();
        states[x][y] = State::FINISHED;

        pair<int, int> ds[] = {
            {0, 1},
            {0, -1},
            {1, 0},
            {-1, 0},
        };
        for (const auto &dpos : ds)
        {
            int nx = x + dpos.first;
            int ny = y + dpos.second;
            if (nx < 0 || H <= nx || ny < 0 || W <= ny || isBlack[nx][ny])
                continue;

            dist[nx][ny] = min(dist[nx][ny], dist[x][y] + 1);
            if (states[nx][ny] == State::UNVISITED)
            {
                q.push(make_pair(nx, ny));
                states[nx][ny] = State::VISITED;
            }
        }
    }

    if (states[H - 1][W - 1] == State::UNVISITED)
    {
        cout << -1 << endl;
    }
    else
    {
        int score = H * W - (dist[H - 1][W - 1] + 1) - black;
        cout << score << endl;
    }

    return 0;
}

Measured memory_bytes: 256
var
H,W,i,j:Longint;
S:String;
begin
readln(H,W);
for i:=1 to H do begin
readln(S);
for j:=1 to W do begin
if copy(S,j*6-5,5)='snuke' then begin
writeln(chr(j+64),i);
end;
end;
end;
end.

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
const int maxx = 1010;
const int INF = 1 << 30;
int n, m[maxx][maxx];
int u, num, v;
int flag[maxx];

int prim() {
	// d??°????????????V-T??? p??°????????°???MST???
	int d[maxx], p[maxx];
	for (int i = 0; i < n; i++) {
		d[i] = INF;
		p[i] = -1;
		flag[i] = 0;
	}

	d[0] = 0;
	while (1) {
		int minv = INF;
		u = -1;
		// ???????????????????°???????
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && flag[i] == 0) {
				u = i;
				minv = d[i];
			}
		}

		if (u == -1)
			break;

		// ?????°???????????\MST
		flag[u] = 1;

		// ??´??°?????????????????????????????????????????´???????°???????????????????????????????
		for (int v = 0; v < n; v++) {
			if (flag[v] == 0 && m[u][v] != INF && d[v] > m[u][v]) {
				d[v] = m[u][v];
				p[v] = u;
			}
		}
	}


	int ans = 0;
	for (int i = 0; i < n; i++)
		if (p[i] != -1)
			ans += m[i][p[i]];

	return ans;
}
int main()
{
	memset(flag, 0, sizeof(flag));
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &m[i][j]);
			if (m[i][j] == -1)
				m[i][j] = INF;
		}
	}
	printf("%d\n", prim());
	return 0;
}

Measured memory_bytes: 3552
// https://atcoder.jp/contests/agc031/tasks/agc031_a
package main

import "fmt"

func main() {
	var N int
	var s string
	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &s)

	counts := map[rune]int{}
	for _, r := range s {
		counts[r] = counts[r] + 1
	}
	for r := range counts {
		counts[r] = counts[r] + 1
	}

	total := 1
	for _, c := range counts {
		total = (total * c) % (1000000000 + 7)
	}

	fmt.Println(total - 1)
}


Measured memory_bytes: 1280
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2,
                         vector<char>(W + 2, ' '));

  for (int i = 1 ; i <= H ; i++) {
    for (int j  = 1; j <= W; j++) {
      char c;
      cin >> c;
      S[i][j] = c;
    }
  }

  bool can = true;

  for (int i = 1 ; i <= H ; i++) {
    for (int j  = 1; j <= W; j++) {
      if (S[i][j] == '#') {
        if (S[i - 1][j] != '#' && S[i + 1][j] != '#'
            && S[i][j - 1] != '#' && S[i][j + 1] != '#') {
          can = false;
          break;
        }
      }
    }
    if (!can) break;
  }

  cout << (can ? "Yes" : "No") << endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
   vector<pair<pair<string,int>,int>> K;
   vector<int>p;
   for(int i=0;i<n;i++){
        string p;
       cin>>p;
       int s;
       cin>>s;
      
       K.push_back(make_pair(make_pair(p,-s),i));
   }
   sort(K.begin(),K.end());
   for(int i=0;i<n;i++){
      cout<<( K[i].second)+1<<endl;
   }

   return 0;


    
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
mod = pow(10,9) + 7
D = defaultdict(lambda:0)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))
ans = 0
for k, v in D.items():
    ans += k * (v * (n - v))
    ans %= mod
print(ans)

Measured memory_bytes: 123724
#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i=(a);i<(b);i++)
#define per(i,a,b) for(register int i=(b);i>=(a);i--)
#define For(i,a,b) for(register int i=(a);i<=(b);i++)
#define Forenska(it,c) for(register __typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long LL;
typedef pair<int,int> Pair;
typedef vector<int> vec;
const long double PI=3.14159265358979323846264338327950288;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const int MAX_N=60;
LL dp[MAX_N][MAX_N][MAX_N*MAX_N];
LL N,A,x[MAX_N];
int main()
{
	LL sum=0;
	cin>>N>>A;
	For(i,1,N)
	{
		cin>>x[i];
		sum+=x[i];
	}
	For(i,0,N)dp[i][0][0]=1;
	For(i,1,N)
	{
		For(j,1,i)
		{
			For(k,0,sum)
			{
				if(k>=x[i])dp[i][j][k]+=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k];
				else dp[i][j][k]+=dp[i-1][j][k];
			}
		}
	}
	LL ans=0;
	For(j,1,N)
	{
		ans+=dp[N][j][A*j];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 84224
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
const int N = 2e5 + 4;
int cnt[N];

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n;
   cin >> n;
   vector<int> a(n);
   for(int &x : a)
      cin >> x , cnt[x]++;
   ll ans = 0;
   for(int i = 1 ; i <= n ; ++i)
      if(cnt[i] > 1)ans += (1ll * cnt[i] * (cnt[i] - 1)) / 2ll;

   for(int x : a){
      cout << ans - cnt[x] + 1 << "\n";
   }
}

Measured memory_bytes: 3712
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll N, ll mod){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0) return Pow(A * A % mod, N / 2, mod) % mod;
    else return (A % mod) * Pow(A * A % mod, N / 2, mod) % mod;
  }
}

int main(){
  int N, P; cin >> N >> P;
  string S; cin >> S;

  if (P == 2 || P == 5){
    ll ans = 0;
    for (ll i = 0; i < N; i++){
      int now = S[i] - '0';
      if (now % P == 0){
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  ll DP[N + 1] = {};
  
  for (int i = N - 1; i >= 0; i--){
    ll now = S[i] - '0';
    now *= Pow(10, N - 1 - i, P);
    DP[i] = (DP[i + 1] + now) % P;
  }

  ll cnt[P] ={};
  for (int i = 0; i < N + 1; i++){
    cnt[DP[i]]++;
  }

  ll ans = 0;
  for (int i = 0; i < P; i++){
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2180
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const long long mod=1000000007;

long long dp[220][220][220];

vector<char> ch;

int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		char in[2];
		scanf("%s",in);
		if(in[0]!='-') ch.push_back(in[0]);
	}
	dp[0][0][0]=1;
	int s=ch.size();
	for(int n=0;n<s;n++){
		for(int i=0;i<=s;i++) for(int j=0;j<=s;j++){
			if(ch[n]=='U'){
				dp[n+1][i+1][j+1]+=dp[n][i][j];
				dp[n+1][i+1][j+1]%=mod;
				dp[n+1][i][j]+=dp[n][i][j]*i;
				dp[n+1][i][j]%=mod;
			}else{
				if(j>=1){
					dp[n+1][i][j]+=dp[n][i][j]*j;
					dp[n+1][i][j]%=mod;
					if(i>=1){
						dp[n+1][i-1][j-1]+=dp[n][i][j]*i*j;
						dp[n+1][i-1][j-1]%=mod;
					}
				}
			}
		}
	}
	printf("%lld\n",dp[s][0][0]);
	return 0;
}

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

int N;

set<string> S[11];
int cnt;

int CALL(string s) {
	int M = s.size();
	int ret = 0;
	for (int i = 0; i < M; i++) {
		ret = max(ret, s[i] - 'a'+1);
	}

	return ret;
}

int main(void) {

	cin >> N;

	S[1].insert("a");

	for (int i = 1; i <= N - 1; i++) {
		for (auto y : S[i]) {
			int H = CALL(y);
			for (int k = 0; k <= H; k++) {
				char c = 'a' + k;
				S[i + 1].insert(y + c);
			}
		}
	}

	for (auto y : S[N]) {
		cout << y << endl;
	}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,k;
  cin >> n >> k;
  vector<vector<int>> e(n);
  vector<pair<int,int>> ep(n-1);
  int a,b;
  for(int i=0;i<n-1;i++){
    cin >> a >> b;
    a--,b--;
    e[a].push_back(b);
    e[b].push_back(a);
    ep[i]={a,b};
  }
  int ans=n;
  if(k%2){
    for(int i=0;i<n-1;i++){
      queue<int> bfs;
      vector<int> dist(n,IINF);
      dist[ep[i].first]=dist[ep[i].second]=0;
      bfs.push(ep[i].first);
      bfs.push(ep[i].second);
      int count=2;
      while(!bfs.empty()){
        int now=bfs.front();
        bfs.pop();
        if(dist[now]<k/2){
          for(auto nx:e[now]){
            if(dist[nx]==IINF){
              count++;
              dist[nx]=dist[now]+1;
              bfs.push(nx);
            }
          }
        }
      }
      ans=min(ans,n-count);
    }
  }else{
    for(int i=0;i<n;i++){
      queue<int> bfs;
      vector<int> dist(n,IINF);
      dist[i]=0;
      bfs.push(i);
      int count=1;
      while(!bfs.empty()){
        int now=bfs.front();
        bfs.pop();
        if(dist[now]<k/2){
          for(auto nx:e[now]){
            if(dist[nx]==IINF){
              count++;
              dist[nx]=dist[now]+1;
              bfs.push(nx);
            }
          }
        }
      }
      ans=min(ans,n-count);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, a, N);
    vi S(2);
    REP(i, N)
    {
        S[i & 1] += max(0LL, a[i]);
    }
    if (S[0] == 0 and S[1] == 0)
    {
        ll k = max_element(ALL(a)) - a.begin();
        OUT(a[k]);
        OUT(N - 1);
        for (ll i = N - 1; i > k; --i)
        {
            OUT(i + 1);
        }
        REP(i, k)
        {
            OUT(1);
        }
        return 0;
    }
    OUT(max(S[0], S[1]));
    vi D;
    for (ll i = N - 1; i >= 0; --i)
    {
        if (a[i] <= 0 and (i & 1) == (S[0] < S[1]))
        {
            D.push_back(i);
        }
    }
    ll n = N;
    ll base = 0;
    vi ans;
    FOR(d, D)
    {
        ans.push_back(d + 1);
        if (d == n - 1)
        {
            --n;
        }
        else if (d == 0)
        {
            --n;
            base = 1;
        }
        else
        {
            n -= 2;
        }
    }
    for (ll i = n - 1; i >= 0; --i)
    {
        if (((i + base) & 1) == (S[0] >= S[1]))
        {
            ans.push_back(i + 1);
        }
    }
    OUT(ans.size());
    FOR(x, ans)
    {
        OUT(x);
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
multiset<ll> hv;
ll l[300005], r[300005], v[300005], s, ans(-(1ll<<60));
int n;
 
int main()
{
	scanf("%d", &n);
	for (int i = 0;i < 3*n;i++) scanf("%lld", v+i);
	for (int i = 0;i < 3*n;i++)
	{
		hv.insert(v[i]); s += v[i];
		if (hv.size() > n) { s -= *hv.begin(); hv.erase(hv.begin()); }
		if (hv.size() == n)
			l[i] = s;
		else
			l[i] = -(1ll<<60);
	}
	s = 0; hv.clear();
	for (int i = 3*n-1;i >= 0;i--)
	{
		hv.insert(v[i]); s += v[i];
		if (hv.size() > n) { s -= *hv.rbegin(); hv.erase(--hv.end()); }
		if (hv.size() == n)
			r[i] = s;
		else
			r[i] = 1ll<<60;
	}
	for (int i = 1;i < 3*n;i++)
		ans = max(ans, l[i-1]-r[i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 200005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, fa[MAXN], mx[MAXN], siz[MAXN], f[MAXN], f2[MAXN], ans[MAXN];
vector<int> e[MAXN];

void DFS(int u, int lim) {
	f[u] = 1;
	for (auto v : e[u]) {
		if (v == fa[u] || v > lim) continue;
		DFS(v, lim);
		f[u] += f[v];
	}
}

void DFS1(int u) {
	mx[u] = max(mx[fa[u]], u);
	siz[u] = 1;
	for (auto v : e[u]) {
		if (v == fa[u]) continue;
		fa[v] = u;
		DFS1(v);
		siz[u] += siz[v];
		f2[u] += f2[v];
	}
	if (mx[u] == u) {
		DFS(u, mx[fa[u]]);
		f2[u] = -siz[u];
	}
	if (mx[fa[u]] == fa[u]) {
		f2[u] += siz[u];
	}
}

void DFS2(int u) {
	if (u > 1) {
		ans[u] = ans[fa[u]];
		if (mx[u] == u) {
			ans[u] += f[u];
		} else if (mx[fa[u]] == fa[u]) {
			ans[u] += f2[u] - f[u];
		}
	}
	for (auto v : e[u]) {
		if (v == fa[u]) continue;
		DFS2(v);
	}
}

void init() {
	read(n);
	for (int i = 1, u, v; i < n; ++i) {
		read(u); read(v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
}

void solve() {
	DFS1(1);
	DFS2(1);
	for (int i = 2; i <= n; ++i) {
		printf("%d ", ans[i]);
	}
}

int main() {
	init();
	solve();
	return 0;
}


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

using ld = double;
using point = complex<ld>;

int main() {
    int n; cin >> n;
    vector<point> ps;
    for(int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        if(x == 0 && y == 0) continue;
        ps.emplace_back(x, y);
    }
    n = ps.size();
    sort(ps.begin(), ps.end(),
         [] (auto const& a, auto const& b) { return arg(a) < arg(b); });

    ld ans = 0;
    for(int i = 0; i < n; ++i) {
        point p = ps[i];
        ans = max(ans, abs(p));
        for(int j = 1; j < n; ++j) {
            auto const v = ps[(i + j) % n];
            if(arg(v / ps[i]) < 0) break;
            p += v;
            ans = max(ans, abs(p));
        }
    }

    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 384
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

int bfs(const vector<string> &field, int x, int y) {
  int h = field.size();
  int w = field[0].size();
  vector<vector<int>> dist(h, vector<int>(w,-1));
  queue<pair<int,int>> q;
  q.push({x,y});
  dist[x][y] = 0;

  int ans=0;
  while(!q.empty()){
    int x = q.front().first;
    int y = q.front().second;
    ans = max(ans,dist[x][y]);
    q.pop();
    for(int dir = 0; dir<4; dir++){
      int nx = x + dx[dir];
      int ny = y + dy[dir];
      if(nx<0 || ny<0 || nx>=h || ny>=w) continue;
      if(field[nx][ny] == '#') continue;
      if(dist[nx][ny] == -1){
        dist[nx][ny] = dist[x][y] + 1;
        q.push({nx,ny});
      }
    }
  }

  return ans;
}


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


  int h,w;
  cin>>h>>w;
  vector<string> field(h);
  rep(i,h){
    cin>>field[i];
  }

  int ans=0;
  for (int x = 0; x < h; ++x) {
    for (int y = 0; y < w; ++y) {
      if(field[x][y]=='#') continue;
      ans=max(ans,bfs(field,x,y));
    }
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

const long double Pi=acos(-1),e=2.718;
const int N=2e3+10, mod=1e9+7;
Matrix dp;
vector<pair<ll,ll> > a;
int n;

ll solve(int i,int l,int r){
    if(i==n)return 0;
    ll &ret=dp[i][l];
    if(ret+1)return ret;
    ret = max(solve(i+1,l+1,r)+a[i].F*abs(a[i].S-l),solve(i+1,l,r-1)+a[i].F*abs(a[i].S-r));
    return ret;
}

int main ()
{
    FASTIO
    cin >> n;
    a.resize(n);
    dp.resize(n,vector<ll>(n,-1));
    for(int i=0;i<n;i++){
        cin >> a[i].F;
        a[i].S = i;
    }
    sort(all(a),greater<pair<ll,ll>>());
    cout << solve(0,0,n-1) << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 34856
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      if (N==M){
        System.out.println("Yes");}
    else{
      System.out.println("No");}
  }
}

Measured memory_bytes: 25172
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <memory.h>
#include <map>
#include <math.h>


#pragma warning(disable:4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;
const double PI = 3.141592653589793238;
const Int INF = 999999999999;
using namespace std;

int dx[4] = { 0, -1, 0, 1 };
int dy[4] = { 1, 0, -1, 0 };

struct state{
	vector<int> A, B, C;
	int pre_a,pre_c;
	Int step;
	state() :step(0),pre_a(-1),pre_c(-1){}
};

int main()
{
	int n, m;
	while (cin >> n >> m, n&&m){
		queue<state> que;

		state s;
		REP(i,3){
			int k;
			cin >> k;
			REP(j,k){
				int a;
				cin >> a;
				if (i ==0)
					s.A.push_back(a);
				if (i == 1)
					s.B.push_back(a);
				if (i == 2)
					s.C.push_back(a);
			}
		}

		que.push(s);
		while (!que.empty()){
			state now = que.front();
			que.pop();

			if ((now.B.empty() && now.C.empty()) || (now.B.empty() && now.A.empty())){
				cout << now.step << endl;
				break;
			}

			if (now.step > m){
				cout << -1 << endl;
				break;
			}

			if (!now.A.empty() && (now.B.empty() || (now.A.back() > now.B.back()))){
				state next = now;
				if (now.pre_a != next.A.back()){
					next.B.push_back(next.A.back());
					next.pre_a = next.A.back();
					next.pre_c = -1;
					next.A.pop_back();
					++next.step;
					que.push(next);
				}
			}
			if (!now.B.empty() && (now.A.empty() || (now.A.back() < now.B.back()))){
				state next = now;
				if (now.pre_a != next.B.back()){
					next.A.push_back(next.B.back());
					next.pre_a = next.B.back();
					next.pre_c = -1;
					next.B.pop_back();
					++next.step;
					que.push(next);
				}
			}
			if (!now.B.empty() && (now.C.empty() || (now.B.back() > now.C.back()))){
				state next = now;
				if (now.pre_c != next.B.back()){
					next.C.push_back(next.B.back());
					next.pre_c = next.B.back();
					next.pre_a = -1;
					next.B.pop_back();
					++next.step;
					que.push(next);
				}
			}
			if (!now.C.empty() && (now.B.empty() || (now.B.back() < now.C.back()))){
				state next = now;
				if (now.pre_c != next.C.back()){
					next.B.push_back(next.C.back());
					next.pre_c = next.C.back();
					next.pre_a = -1;
					next.C.pop_back();
					++next.step;
					que.push(next);
				}
			}

		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int x;
    cin >> x;

    if (x >= 30) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var (N, M) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var ab = new Queue<int[]>(Enumerable.Range(0, M).Select(i => ReadLine().Split(' ').Select(int.Parse).ToArray()).OrderBy(x => x[0]));

        var ans = 0;
        var min = int.MaxValue;
        for (int i = 1; i <= N; i++)
        {
            if(min == i)
            {
                ans++;
                min = int.MaxValue;
            }

            while(0 < ab.Count && ab.Peek()[0] == i)
            {
                var (a, b) = ab.Dequeue();
                min = Math.Min(min, b);
            }
        }

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 50996
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Coder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }

    public static void Main()
    {

        var a = ReadInt();
        int[] A = ReadArray();

        double sum = 0;
        foreach(var i in A)
        {
            sum += (double)1 / i;
        }

        Console.WriteLine((double)1 / sum);

    }

}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 15;
int c[N];
int a[N][N];
int now[N];
int main()
{
	int n, m, x;
	scanf("%d%d%d", &n, &m, &x);

	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &c[i]);
		for (int j = 1; j <= m; ++j)
			scanf("%d", &a[i][j]);
	}


	int res = inf;
	for (int i = 0; i < (1 << n); ++i)
	{
		int tres = 0;
		memset(now, 0, sizeof now);
		for (int j = 0; j < n; ++j)
		{
			if (i >> j & 1)
			{
				tres += c[j + 1];
				for (int k = 1; k <= m; ++k)
					now[k] += a[j + 1][k];
			}
		}

		bool flag = true;
		for (int j = 1; j <= m; ++j)
		{
			if (now[j] < x)
				flag = false;
		}

		if (flag)
			res = min(res, tres);
	}
	
	if (res == inf)
		printf("%d\n", -1);
	else
		printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 3828
n = int(input())
li = input().split()
li = [int(s) for s in li]
l=len(li)

count = 0
flag = 1

while True:
    if flag == 1:
        for n in range(l):
            if li[n]%2 == 0:
                li[n] /= 2
            else:
                flag -= 1
                break
        if flag == 1:
            count += 1
                    
    elif flag == 0:
        break
        
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;// 1000000007;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	VLL P(A + 1,0), Q(B + 1,0), R(C + 1,0);
	for (LL a = 1; a <= A; a++)cin >> P[a];
	for (LL a = 1; a <= B; a++)cin >> Q[a];
	for (LL a = 1; a <= C; a++)cin >> R[a];
	sort(P.begin(), P.end(), [](LL a, LL b) {
		if (a == 0)return true;
		if (b == 0)return false;
		return a > b;
	});
	sort(Q.begin(), Q.end(), [](LL a, LL b) {
		if (a == 0)return true;
		if (b == 0)return false;
		return a > b;
	});
	sort(R.begin(), R.end(), [](LL a, LL b) {
		if (a == 0)return true;
		if (b == 0)return false;
		return a > b;
	});
	VLL PP(A + 1, 0), QQ(B + 1, 0), RR(C + 1, 0);
	for (LL a = 1; a <= A; a++)PP[a] = PP[a - 1] + P[a];
	for (LL a = 1; a <= B; a++)QQ[a] = QQ[a - 1] + Q[a];
	for (LL a = 1; a <= C; a++)RR[a] = RR[a - 1] + R[a];
	LL ans = 0;
	for (LL x = 0; x <= X; x++) {
		LL yb = max(X + Y - x - C, (LL)0);
		LL yu = min(X + Y - x, Y);
		if (yb > yu)continue;
		LL temp =0;
		if (yb == yu)temp = QQ[yb] + RR[X + Y - x - yb];
		else if (yu == yb + 1) {
			temp = max(QQ[yb] + RR[X + Y - x - yb], QQ[yu] + RR[X + Y - x - yu]);
		}
		else {
			LL s = yb, e = yu;
			while (e - s > 1) {
				LL m = (e + s) / 2;
				if (Q[m] - R[X + Y - x - m + 1] >= 0)s = m;
				else e = m;
			}
			temp = max(QQ[yb] + RR[X + Y - x - yb], QQ[yu] + RR[X + Y - x - yu]);
			temp = max(temp, QQ[s] + RR[X + Y - x - s]);
		}
		temp += PP[x];
		ans = max(ans, temp);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define x first
#define y second

namespace I_Wander___
{
	typedef long long ll;
	typedef std::pair<ll,ll> pii;
	const int N=233,MOD=1000000007;
	const ll INF=4000000000000000000ll;

	ll F[N];
	std::vector<pii> EF[N];

	int Q,tot;

	void dfs(pii A,int k)
	{
		EF[k].push_back(A);
		if(k+2==tot)return;

		pii B=pii(A.x+A.y,A.x);
		for(;B.x<=F[k+3];B.x+=B.y)
			dfs(B,k+1);
	}

	void initialize()
	{
		F[0]=F[1]=1;
		for(tot=1;F[tot]<INF;tot++)F[tot+1]=F[tot]+F[tot-1];
		dfs(pii(2,1),1),dfs(pii(3,1),1);
	}

	ll n,m;

	void solve()
	{
		scanf("%lld%lld",&n,&m);
		int k=std::upper_bound(F,F+tot+1,n)-F-1,dk=std::upper_bound(F,F+tot+1,m)-F-1;
		if(k==dk)k--;else k=std::min(k,dk);k+=k==0;

		ll ans=0;
		if(k==1)
		{
			if(n>m)std::swap(n,m);
			for(int i=1;i<=n;i++)
			{
				for(int j=1;j<i;j++)
					if(i%j==0)ans++;
				ans=(ans+m/i)%MOD;
			}
		}
		else 
		{
			for(auto A:EF[k-1])
			{
				if(n>=A.x && m>=A.y)
					ans=(ans+(m-A.y)/A.x)%MOD;
				if(m>=A.x && n>=A.y)
					ans=(ans+(n-A.y)/A.x)%MOD;
			}
		}
		ans=(ans%MOD+MOD)%MOD;
		printf("%d %lld\n",k,ans);
	}
}

int main()
{
//	freopen("in","r",stdin);
	I_Wander___::initialize();
	int T;
	for(scanf("%d",&T);T--;I_Wander___::solve());
	return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;


int main(){
    int n;cin >> n;
    string s;cin >> s;
    int k;cin >> k;
    for (int i = 0; i < s.length(); i++) {
        cout << (s[i]==s[k-1]?s[i]:'*');
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        if (500 * i + 100 * j + 50 * k == X) ans ++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N,M;
    vector<pair<int,int> > vote;
    vector<int> cost;
    int tmp;

    cin >> N >> M;

    cost.push_back(100000000);
    vote.push_back({0,0});

    for(int i=1; i<=N; ++i) {
        cin >> tmp;
        cost.push_back(tmp);
        vote.push_back({0,i});
    }

    for(int i=0; i<M; ++i) {
        cin >> tmp;
        int ans=0;
        while(cost[ans]>tmp) ++ans;
        ++vote[ans].first;
    }

    sort(vote.rbegin(),vote.rend());

    cout << vote[0].second << endl;

    return 0;
}

Measured memory_bytes: 3180
# include <cstdio>
# include <iostream>
# include <cstring>
# include <string>
# include <algorithm>
# include <cmath>
# define R register int
# define ll long long

using namespace std;

int x,y;

int main()
{
	scanf("%d%d",&x,&y);
	y/=2;
	x+=y;
	printf("%d",x);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

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


Measured memory_bytes: 2560
import sys


class Daise:
    def __init__(self, info_list):
        self.T = info_list[0]
        self.S = info_list[1]
        self.E = info_list[2]
        self.W = info_list[3]
        self.N = info_list[4]
        self.B = info_list[5]
    
    def change(self, axis):
        if axis == 'S':
            self.T, self.B, self.S, self.N = self.N, self.S, self.T, self.B
        
        elif axis == 'E':
            self.T, self.B, self.E, self.W = self.W, self.E, self.T, self.B
        
        elif axis == 'W':
            self.T, self.B, self.W, self.E = self.E, self.W, self.T, self.B
        
        elif axis == 'N':
            self.T, self.B, self.N, self.S = self.S, self.N, self.T, self.B
        
        elif axis == 'Turn':
            self.S, self.E, self.N, self.W = self.E, self.N, self.W, self.S
    

    def output(self):
        return [self.T, self.S, self.E, self.W, self.N, self.B]
    

    def set_info(self, top, front):
        if front in (self.T, self.B):
            self.change("S")

        while self.S != front:
            self.change('Turn')
 
        while self.T != top:
            self.change('E')



if __name__ == '__main__':
    daiseA = Daise(list(map(str, input().split())))
    daiseB = Daise(list(map(str, input().split())))
    
    for _ in range(4):
        for _ in range(4):
            if daiseA.output() == daiseB.output():
                print('Yes')
                sys.exit()
            for _ in range(4):
                if daiseA.output() == daiseB.output():
                    print('Yes')
                    sys.exit()
                daiseB.change('Turn')
            daiseB.change('S')
        daiseB.change('W')
    print('No')


Measured memory_bytes: 5576
n, ma, mb = map(int, input().split())
abc = [tuple(int(x) for x in input().split()) for _ in range(n)]

c = n * 100 + 1

m = 401

dp = [[[99999 for _ in range(m)] for _ in range(m)] for _ in range(n + 1)]

ans = 99999
dp[0][0][0] = 0
for i in range(n):
    for j in range(m):
        for k in range(m):
            if dp[i][j][k] < 9999:
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
                dp[i+1][j+abc[i][0]][k+abc[i][1]] = min(dp[i+1][j+abc[i][0]][k+abc[i][1]], dp[i][j][k] + abc[i][2])
                if (j+abc[i][0]) * mb == (k+abc[i][1]) * ma:
                    ans = min(ans, dp[i+1][j+abc[i][0]][k+abc[i][1]])

if ans == 99999:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 60004
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}

ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p&1)    res = (res * x)%m;
        x = (x * x)%m;
        p >>= 1;
    }
    return res;
}


const int N = 1e5 + 5;
ll b[N];
int main(){
    
    ll n = D(), h = D();
    
    ll mxA = -1, mxB = -1;
    
    for(int i = 0; i < n; ++i){
        mxA = max(mxA, LLD());
        mxB = max(mxB, b[i] = D());
    }
    
    sort(b, b + n, [](int s, int f){
        return f < s;
    });
    ll sum = 0;
    ll ans4 = 0;
    for(int i = 0; i < n && b[i] >= mxA && sum < h; ++i)
        sum += b[i], ++ans4;
    
    if(sum < h)
            ans4 += roundl(ceill(((h - sum) * 1.0 / mxA * 1.0)));
    
    ll ans0 = INT_MAX;
    if(max(mxA, mxB) >= h)
        ans0 = 1;
    ll totA = h / mxA;
    ll ans1 = INT_MAX;
    if(((totA - 1) * mxA + mxB) >= h || (totA * mxA >= h))
        ans1 = totA;
    ll ans2 = INT_MAX;
    if((totA + 1) * mxA >= h)
        ans2 = totA + 1;
    ans0 = min(ans0, ans4);
    printf("%lld", min(ans0, min(ans1, ans2)));
    return 0;
}


Measured memory_bytes: 1024
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

	int n = 0;
	int b = 0;
	int c = 0;

	if (a[0] == 'o') {
		n = 100;
	}
	if (a[1] == 'o') {
		b = 100;
	}
	if (a[2] == 'o') {
		c = 100;
	}

	int ans = 700 + n + b + c;
	cout << ans << endl;
}


Measured memory_bytes: 256