akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void){
	int i,j,x,a[8];
	scanf("%*d");
	while(scanf("%1d%1d%1d%1d%1d%1d%1d%1d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7])!=EOF){
		for(i=0;i<8;i++){
			for(j=i;j>0;j--){
				if(a[j]>a[j-1]){x=a[j];a[j]=a[j-1];a[j-1]=x;}
				else break;
			}
		}
		printf("%d\n",(a[7]-a[0])+(a[6]-a[1])*10+(a[5]-a[2])*100+(a[4]-a[3])*1000+(a[3]-a[4])*10000+(a[2]-a[5])*100000+(a[1]-a[6])*1000000+(a[0]-a[7])*10000000);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define X first
#define Y second

const int maxn=131072+233;

int n,fa[maxn],lc[maxn],rc[maxn],w[maxn];
LL mid;

vector<pair<LL,LL> > S[maxn],tmp;

void dfs(int u)
{
	if (!lc[u])
	{
		S[u].push_back(make_pair(w[u],w[u]));
		return;
	}
	dfs(lc[u]); dfs(rc[u]);
	int i,j=-1;
	int m=(int)S[rc[u]].size()-1;
	for (i=0;i<(int)S[lc[u]].size();i++)
	{
		bool flag=0;
		while (j<m&&S[lc[u]][i].Y+S[rc[u]][j+1].X<=mid) j++,flag=1;
		if (flag)
			S[u].push_back(make_pair(S[lc[u]][i].X+w[u],S[rc[u]][j].Y+w[u]));
	}

	m=(int)S[u].size();
	for (i=0;i<m;i++)
		S[u].push_back(make_pair(S[u][i].Y,S[u][i].X));
	sort(S[u].begin(),S[u].end());
	LL last=1e15;
	tmp.clear();
	for (i=0;i<(int)S[u].size();i++)
		if (last>S[u][i].Y) last=S[u][i].Y,tmp.push_back(S[u][i]);
	S[u].clear();
	for (i=0;i<(int)tmp.size();i++)
		S[u].push_back(tmp[i]);

//	printf("S[%d]:\n",u);
//	for (i=0;i<(int)S[u].size();i++)
//		printf("%lld %lld\n",S[u][i].X,S[u][i].Y);
//	puts("");
}

bool pass()
{
//	printf("<<<pass %lld>>>\n",mid);
	int i;
	for (i=1;i<=n;i++)
		S[i].clear();
	dfs(1);
//	puts(""); puts(""); puts(""); puts(""); puts("");
	return S[1].size();
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i;
	LL L=0,R=0;
	scanf("%d",&n);
	for (i=2;i<=n;i++)
	{
		scanf("%d%d",&fa[i],&w[i]);
		if (lc[fa[i]]) rc[fa[i]]=i;
		else lc[fa[i]]=i;
		R+=w[i];
	}

	while (L<=R)
	{
		mid=(L+R)>>1;
		if (pass()) R=mid-1;
		else L=mid+1;
	}
	printf("%lld\n",L);
}


Measured memory_bytes: 29280
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;
using ull_t = unsigned long long;

int main()
{
    ull_t H, W;
    cin >> H >> W;

    ull_t n = ((W + 1) / 2) * ((H + 1) / 2) + (W / 2) * (H / 2);
    if (H == 1 or W == 1)
        n = 1;
    
    cout << n << endl;
}


Measured memory_bytes: 256
import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1) # 自分がnp.sumを利用したがどうしても正解になれなかった。なぜ？
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(s % mod)

Measured memory_bytes: 68796
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007  // 10^9+7

int candies(int arr[], int n, int k){

    ll **dp = new ll*[n+1];
    for(int i=0; i<=n; i++)
        dp[i] = new ll[k+1];

    // dp[i][j] stores the number of ways to distribute
    // 'j' candies to the first 'i' students

    // Base case: If no student, then can't distribute more than 0 candies
    //          If no candy, then can distribute all the students in only 1 way
    //          (don't give a candy to anyone)

    for(int j=1; j<=k; j++)
        dp[0][j] = 0;

    for(int i=0; i<=n; i++)
        dp[i][0] = 1;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            // We can distribute this student either 0, 1, 2, ... arr[i-1] candies
            ll cnt = 0;
            for(int z=0; z<=arr[i-1]; z++){
                // If we give this student 'z' candies
                // (only if we have enough candies),
                // then remaining students should get 'j-z' candies
                if(j-z >= 0)
                    cnt = (cnt + dp[i-1][j-z])%M;
            }
            dp[i][j] = cnt;
        }
    }
//    for(int i=0; i<=n; i++){
//        for(int j=0; j<=k; j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }
    ll ans = dp[n][k];
    for(int i=0; i<=n; i++)
        delete[] dp[i];
    delete[] dp;
    return ans;
}


int candiesOptimized(int arr[], int n, int k){

    // In the above approach, notice in the third for loop,
    // we are just taking the sum:
    // dp[i-1][j-0] + dp[i-1][j-1] + dp[i-1][j-2] + ... + dp[i-1][j-arr[i-1]]

    // We can maintain a prefix sum array of previous row
    // and then can quickly take this sum
    // between [j-arr[i-1], j]

    ll **dp = new ll*[n+1];
    for(int i=0; i<=n; i++)
        dp[i] = new ll[k+1];

    ll **prefix = new ll*[n+1];
    for(int i=0; i<=n; i++)
        prefix[i] = new ll[k+1];

    for(int j=0; j<=k; j++){
        dp[0][j] = 0;
        prefix[0][j] = 1;
    }
    for(int i=0; i<=n; i++){
        dp[i][0] = 1;
        prefix[i][0] = 1;
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            ll cnt = prefix[i-1][j];
            if(j-arr[i-1]-1 >= 0)
                cnt = ((cnt - prefix[i-1][j-arr[i-1]-1])%M + M)%M;
            dp[i][j] = cnt;
            prefix[i][j] = (prefix[i][j-1] + cnt)%M;
        }
    }
    ll ans = dp[n][k];
    for(int i=0; i<=n; i++)
        delete[] dp[i];
    delete[] dp;
    return ans;
}


int main()
{
 int n, k;
 cin>>n>>k;
 int arr[n];
 for(int i=0; i<n; i++)
    cin>>arr[i];
// int ans = candies(arr, n, k);
 int ans = candiesOptimized(arr, n, k);
 cout<<ans;
 return 0;
}



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

int main() {

	int n; cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<int> ball(n + 1, 0);
	int cnt = 0;
	for (int i = n; i >= 1; i--) {
		int tmp = 0;
		for (int j = i + i; j <= n; j += i) {			
			tmp += ball[j];
		}
		if (tmp % 2 != a[i]) {
			ball[i] = 1;
			cnt++;
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= n; i++) {
		if (ball[i] == 1) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 4720
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int p=1e9+7;
int n,f[3005],g[3005];
char s[3005];
int Add(int x,int y){return (x+=y)>=p?x-p:x;}
int Sub(int x,int y){return (x-=y)<0?x+p:x;}
int main()
{
	scanf("%d%s",&n,s+1);
	g[1]=1;
	for(int i=2;i<=n;++i){
		for(int j=1;j<=i;++j){
			if(s[i-1]=='>')f[j]=Sub(g[i-1],g[j-1]);
			else f[j]=g[j-1];
		}
		for(int j=1;j<=i;++j)
			g[j]=Add(g[j-1],f[j]);
	}
	printf("%d\n",g[n]);
	return 0;
}

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

const ll MOD = 1000000007;

int main(void) {
  string S;
  cin >> S;
  ll N = S.length();

  vector<vector<ll>> dp(N + 1, vector<ll>(13));
  dp[0][0] = 1;
  REP(i, 0, N) {
    REP(j, 0, 13) {
      if (S[i] == '?') {
        REP(d, 0, 10) {
          ll r = (j * 10 + d) % 13;
          dp[i + 1][r] += dp[i][j];
          dp[i + 1][r] %= MOD;
        }
      } else {
        ll d = S[i] - '0';
        ll r = (j * 10 + d) % 13;
        dp[i + 1][r] += dp[i][j];
        dp[i + 1][r] %= MOD;
      }
    }
  }

  cout << dp[N][5] << endl;
}

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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

string to_str(ll n) {
  return to_string(n);
}

int main() {
  int L, R, d;
  cin >> L >> R >> d;

  int ans = 0;
  rep(i, L, R+1) {
    if (i % d == 0) ans++;
  }

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


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

int main()
{
    int a,b;
    cin >> a >> b;
    
    int t = a+b;
    
    if(t>=24)
    {
        t=t-24;
    }
    
    printf("%d",t);
    
    
    
}




Measured memory_bytes: 3112
from heapq import heappush, heappop

INF = 10 ** 20
while True:
  n, m = map(int, input().split())
  if n == 0:
    break
  edges = [[] for _ in range(n * 2)]
  for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[a + n].append((b + n, c))
    edges[b].append((a, c))
    edges[b + n].append((a + n, c))
  
  for i in range(n):
    adds = []
    for to, _ in edges[i]:
      if to < n:
        for toto, _ in edges[to]:
          if toto < n and toto != i:
            adds.append((toto + n, 0))
    edges[i].extend(adds)
  edges[n - 1].append((2 * n - 1, 0))
  
  costs = [INF] * (2 * n)
  que = []
  heappush(que, (0, 0))
  while que:
    total, node = heappop(que)
    for to, cost in edges[node]:
      if costs[to] > total + cost:
        costs[to] = total + cost
        heappush(que, (total + cost, to))
  print(costs[2 * n - 1])


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<tuple<string,int,int>> A;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N;
	cin>>N;
	A.resize(N);
	for(int i=0;i<N;i++) {
		string s;
		int a;
		cin>>s>>a;
		A[i]=make_tuple(s,a,i+1);
	}
	sort(A.begin(),A.end(),[](const tuple<string,int,int> &a, const tuple<string,int,int> &b) {
		if(get<0>(a)!=get<0>(b)) return get<0>(a)<get<0>(b);
		return get<1>(a)>get<1>(b);
	});
	for(int i=0;i<N;i++) cout<<get<2>(A[i])<<'\n';
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<u64> = (0..n).map(|_| sc.read()).collect();

    let mut grundy = 0;
    for &a in &a {
        grundy ^= a;
    }

    let mut used = vec![false; n];
    for pos in (0..32).rev() {
        if grundy & (1 << pos) == 0 {
            continue;
        }
        for i in 0..n {
            if used[i] {
                continue;
            }

            let tmp = a[i] ^ (a[i] - 1);
            let check = (1 << (pos + 1)) - 1;
            if tmp == check {
                grundy ^= tmp;
                used[i] = true;
                break;
            }
        }
    }

    if grundy == 0 {
        println!(
            "{}",
            used.iter().map(|&b| if b { 1 } else { 0 }).sum::<usize>()
        );
    } else {
        println!("-1");
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n + 1), ret(n + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = n; i >= 1; --i) {
    int cur = 0;
    for (int j = i + i; j <= n; j += i) {
      cur = (cur + ret[j]) % 2;
    }
    ret[i] = (cur + a[i]) % 2;
  }
  vector<int> ans;
  for (int i = 1; i <= n; ++i) {
    if (ret[i]) ans.push_back(i);
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d%c", ans[i], " \n"[i + 1 == ans.size()]);
  }
  return 0;
}


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

const int N = 100005;
std::string s, t;
int n, m, ss[N], tt[N], q;
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> s >> t >> q, n = s.size(), m = t.size();
	for (int i = 1; i <= n; ++i)
		ss[i] = (ss[i - 1] + (s[i - 1] == 'B') + 1) % 3;
	for (int i = 1; i <= m; ++i)
		tt[i] = (tt[i - 1] + (t[i - 1] == 'B') + 1) % 3;
	while (q--) {
		int a, b, c, d; std::cin >> a >> b >> c >> d, --a, --c;
		std::cout << ((ss[b] - ss[a] - tt[d] + tt[c]) % 3 == 0 ? "YES" : "NO") << '\n';
	}
	return 0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
bool comp(const pii a, const pii b)
{
    if(a.se==b.se)
    return a.fi<b.fi;
    return a.se<b.se;
}
vector<vector<int>> dp,v;
void solve()
{
    int n,m; cin>>n>>m;
    vector<int> adj[n+1];
    vector<int> v(n+1); int x,y;
    for(int i=1;i<=n;i++)
    cin>>v[i];
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        bool check=true;
        for(auto u:adj[i])
        {
            if(v[i]<=v[u])
            check=false;
        }
        if(check)
        ans++;
    }
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 26164
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long d = sc.nextLong();
    d *=d;
    long[] x = new long[n];
    long[] y = new long[n];
    long dis = 0;
    int count=0;
    for(int i = 0;i<n;i++){
      dis = 0;
      x[i] = sc.nextLong();
      y[i] = sc.nextLong();
      dis += x[i]*x[i];
      dis += y[i]*y[i];
      if(dis<=d){
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 63880
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mk make_pair
#define pb push_back
#define vi vector<int>
#define x first
#define y second
#define ms(a,b)  memset(a, b, sizeof(a))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define M 1000005
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;int a[n+1],dp[n+1];
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0]=0;dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)dp[i]=min(dp[i-1] + abs(a[i]-a[i-1]),dp[i-2] + abs(a[i]-a[i-2]));
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+10;
const int mod=1e9+7;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

char s[N];
int n,m,f[N][N],R[N],sum[N][2];

void inc(int &a,int b) {
	a=a+b>=mod?a+b-mod:a+b;
}

int main() {
	cin>>n>>m;
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;i++) {
		R[i]=i;
		sum[i][0]=sum[i-1][0];
		sum[i][1]=sum[i-1][1];
		++sum[i][s[i]-'0'];
	}
	for(int i=1,l,r;i<=m;i++) l=gi(),r=gi(),R[l]=max(R[l],r);
	for(int i=2;i<=n;i++) R[i]=max(R[i],R[i-1]);
	f[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++) {
			if(!f[i][j]) continue;
			if(j<sum[R[i+1]][0]) inc(f[i+1][j+1],f[i][j]);
			if(i-j<sum[R[i+1]][1]) inc(f[i+1][j],f[i][j]);
		}
	cout<<f[n][sum[n][0]];
	return 0;
}


Measured memory_bytes: 34048
import java.io.*;
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args){
    
    try {
      //ローカル変数定義
      //標準入力受け取り
      Scanner scan = new Scanner(System.in);
      int N = Integer.parseInt(scan.next());
      int R = Integer.parseInt(scan.next());

      //内部レーティング算出
      if ( N <= 10) {
		R = R + ( 100 * (10 - N));
      }
      System.out.println(R);
      
    } catch (Exception e) {
      
      System.out.println("error");

    }
  }
}

Measured memory_bytes: 21716
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, h: i64, ab: [(i64, i64); n]);

    let a_max = ab.iter().map(|&x| x.0).max().unwrap();
    let mut bs = ab
        .iter()
        .map(|&x| x.1)
        .filter(|&x| a_max <= x)
        .collect::<Vec<i64>>();
    bs.sort();
    bs.reverse();

    let mut h = h;
    let mut cnt = 0;
    for &b in bs.iter() {
        h -= b;
        cnt += 1;
        if h <= 0 {
            println!("{}", cnt);
            return;
        }
    }

    if h <= 0 {
        println!("{}", cnt);
        return;
    }
    let rem = (h + a_max - 1) / a_max;
    cnt += rem;
    println!("{}", cnt);
}


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

int main(){
    int h1,h2,k1,k2,a,b,c,d;
    cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;
    int hiro = h1*a+h2*b+h1/10*c+h2/20*d;
    int ken = k1*a+k2*b+k1/10*c+k2/20*d;
    if(hiro<ken)cout<<"kenjiro"<<endl;
    else if(hiro>ken)cout<<"hiroshi"<<endl;
    else cout<<"even"<<endl;
    return 0;
}


Measured memory_bytes: 3096
def Ten_to_n(X, n):
    if (int(X / n)):
        return Ten_to_n(int(X / n), n) + str(X % n)
    return str(X % n)


def main():
    B = list(map(int, input().split()))
    #     # # [1,2,3]
    res = Ten_to_n(B[0], B[1])
    print(len(res))


main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define mod M
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e6+5;
const ll M = 1e9+7;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
ll qpow(ll a,ll b) {ll s=1;while(b){if(b&1)s=(s*a)%M;a=(a*a)%M;b>>=1;}return s; }
ll p[maxn],pp[maxn];
ll fac[maxn],inv[maxn];
void init()
{
    int n = 2e6;
	inv[1]=1;
	fac[1]=1;
	fac[0]=1;
	p[0]=1;
	pp[0]=1;
	p[1]=25;
	pp[1]=26;
	for(int i=2;i<=n;i++)
	{
		fac[i]=fac[i-1]*i%mod;
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		p[i]=p[i-1]*25%mod;
		pp[i]=pp[i-1]*26%mod;
	}
}
ll C(ll a,ll b) {return a<b?0:fac[a]*qpow(fac[b],M-2)%M*qpow(fac[a-b],M-2)%M;}
int n;
char s[maxn];
int main()
{
    fastio();
	ll ans=0;
	init();
	cin>>n>>s+1;
	int lens=strlen(s+1);
	int len = lens+n;
	for(int i=lens;i<=len;i++)
	{
		ans=(ans+((C(i-1,lens-1)*p[i-lens]%M)*pp[len-i])%M)%M;
	}
	cout<<ans<<endl;
	return 0;
 }


Measured memory_bytes: 67096
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, functools, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ; count = 0; pro = 1

n=int(input())
count=0
# @functools.lru_cache(maxsize=None)
memo=[0]*(n+1)
memo[0]=0
def func(n):
    if memo[n] or n==0:return memo[n]
    # print(n)
    # global count
    # count+=1
    # if count%10==0:print(count)
    if n==0:
        return 0
    re=inf
    k=s=1
    while 9**s<=n:
        re=min(re,func(n-9**s)+1)
        s+=1
    while 6**k<=n:
        re=min(re,func(n-6**k)+1)
        k+=1
    re=min(re,func(n-1)+1)
    memo[n]=re
    return re
    
print(func(n))
# print(memo)



Measured memory_bytes: 13812
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define dame {cout<< "0" <<"\n"; return;}
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,K,Q; cin>>N>>K>>Q;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    ll ans=INF2;

    rep(k,N){
        ll mid=A[k];
        vector<ll> X;
        vector<ll> Y;
        rep(i,N){
            if(A[i]>=mid){
                X.emplace_back(A[i]);
            }
            if(A[i]<mid or i==N-1){
                if(X.size()>=K){
                    SORT(X);
                    rep(j,X.size()-K+1){
                        Y.emplace_back(X[j]);
                    }
                }
                X.clear();
            }
        }
        if(Y.size()>=Q){
            SORT(Y);
            mini(ans,Y[Q-1]-Y[0]);
        }
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;


int main()
{
	fast;
	cin>>n;
	// cout<<(n+m-1)/m
	ll tut=1;
	while(n)
	{
		sum+=tut;
		n/=2;

		tut*=2;

	}
	cout<<sum;
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
constexpr double pi=3.14159265358979323846264338;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    n%=10;
    if(n==3)puts("bon");
    else if(n==0||n==1||n==6||n==8)puts("pon");
    else puts("hon");
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    lint k;
    cin >> k;

    if (s[0] != '1') {
        cout << s[0] << endl;
    }
    else {
        int ceil = min(k, (lint)s.size());
        rep(i, ceil) {
            if (s[i] != '1') {
                cout << s[i] << endl;
                exit(0);
            }
        }
        cout << 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long  t,r=1,r1=0,r2=0,k=0,a,b,c=0,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<pair<long long ,long long>>u;
   // vector<tuple<string,int,
     //      int>>mp;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;

    u.push_back(make_pair(a,b));
    }
    for(auto x:u)
    {
        if(x.first==x.second)
        {
            d++;
            //cout<<x.first<<endl;
        }

        else
        {
            d=0;
        }
                if(d==3)
        {
            c=1;
        }
    }



    if(c==1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    //cout<<d<<endl;

}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
string s1, s2;
int gcd(int x, int y){
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
int main(){
	int n, m;
	cin >> n >> m;
	cin >> s1 >> s2;
	int x = gcd(n, m);
	for (int i = 1; i <= x; ++ i)
		if (s1[(i - 1) * (n / x)] != s2[(i - 1) * (m / x)]){
			cout << -1 << endl;
			return 0;
		}
	cout << 1LL * n * m / x << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	vector<char> iti,ni;
	for(int i=0;i<tx-sx;i++) iti.push_back('R');
	for(int i=0;i<ty-sy;i++) iti.push_back('U');
	ni.push_back('D');
	for(int i=0;i<tx-sx+1;i++) ni.push_back('R');
	for(int i=-1;i<ty-sy;i++) ni.push_back('U');
	ni.push_back('L');

	for(int i=0;i<iti.size();i++) cout << iti[i];
	for(int i=0;i<iti.size();i++) {
		if(iti[i]=='U')cout << 'D';
		if(iti[i]=='D')cout << 'U';
		if(iti[i]=='L')cout << 'R';
		if(iti[i]=='R')cout << 'L';
	}
	for(int i=0;i<ni.size();i++) cout << ni[i];
	for(int i=0;i<ni.size();i++) {
		if(ni[i]=='U')cout << 'D';
		if(ni[i]=='D')cout << 'U';
		if(ni[i]=='L')cout << 'R';
		if(ni[i]=='R')cout << 'L';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
(defun r-solve (p l n)
 (cond
  ((< (expt 10 18) p) -1)
  ((zerop n) p)
  (t (r-solve (* p (car l)) 
            (cdr l) 
            (- n 1)))))

(defun solve (n l)
   (if (find 0 l)
      0
      (r-solve 1 l n)))

(defun main ()
  (let* ((n (read))
         (l (loop :repeat n :collect (read))))
    (princ (solve n l))))
  
(main)

Measured memory_bytes: 78380
#include<stdio.h>

int check(int g)
{

    int h = 0, k = 1;

    while(k) {
        if(g / k == 0)
            break;
        h++;
        k *= 10;
    }

    return h;
}

int main(void)
{

    int a[200], b[200], x, y, i = 0, j, p;

    while(scanf("%d %d", &x, &y) != EOF) {
        a[i] = x;
        b[i] = y;
        i++;
    }


    for(j = 0; j < i; j++) {
        p = a[j] + b[j];
        printf("%d\n", check(p));
    }

    return 0;
}

Measured memory_bytes: 600
n,x,y=map(int, input().split())
l=[0]*(n-1) 
for i in range(1,n):
    for j in range(i+1, n+1):
        l[min(j-i,abs(j-y)+abs(i-x)+1)-1]+=1 
for k in l:
    print(k)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


int main(){
    int n,a;
    cin >> n >> a;
    cout << n*n - a << endl;
}

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

signed main(void)
{
	int n;
	cin >> n;
	ll ans;
	vector<bool> search(MAX, false);
	set<int> st, e;

	rep(i, n) 
	{
		int b;
		cin >> b;
		if (!st.count(b))
			st.insert(b);
		else
			e.insert(b);
	}
	for (auto x : st)
	{
		for(ll j = 2; j * x < MAX; j++)
			search[j * x] = true;
	}
	cout << endl;
	ans = 0;
	for(auto d : e)
		st.erase(d);
	for (auto x : st)
	{
		if (!search[x])
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 13064
#include <stdio.h>

int main()
{
	int A = 0, B = 0, C = 0;
	scanf("%d %d %d", &A, &B, &C);
	if (A == B) {
		printf("%d", C);
	}
	else if (B == C) {
		printf("%d", A);
	}
	else if(A == C)
	{
		printf("%d", B);
	}
}

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

#define LL long long
#define LD long double
#define INF 1000000000
#define PR pair<int,int>
#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define pb push_back
#define mp make_pair

template<typename T> T Abs(T x) { return(x<0 ? -x : x); }

int n, k;
int h[100005];
int dp[100005];


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

	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = INF;
		for (int j = 1; i - j >= 0 && j <= k; j++) {
			Min(dp[i], dp[i-j] + Abs(h[i] - h[i-j]));
		}
	}

	cout << dp[n-1] << endl;
}

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

using namespace std;

const int maxn = 550;

char ch[maxn][maxn]; bool a[maxn][maxn], b[maxn][maxn];

int main() {
	int n, m; scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++) scanf("%s", ch[i]);
	for(int i = 0; i < n; i++) a[i][0] = 1;
	for(int i = 0; i < n; i++) b[i][(m - 1)] = 1;
	for(int i = 0; i < n; i++)
		for(int j = 1; j < m - 1; j++) {
			if(i & 1) a[i][j] = 1;
			else b[i][j] = 1;
		}
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			if(ch[i][j] == '#') a[i][j] = b[i][j] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) putchar(a[i][j] ? '#' : '.');
		puts("");
	}
	puts("");
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) putchar(b[i][j] ? '#' : '.');
		puts("");
	}
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x, n, y, i;
	scanf("%d", &n);
	if(n>=1 && n<=100){
			x=800*n;
		if(n>15){
			i=n/15;
			y=(i*200);
			printf("%d", x-y);
		}
		else{
			printf("%d", x);
		}
	}
	else{
		printf("Error");
	}
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut ds = buf.split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect::<Vec<_>>();

    ds.sort();
    let ds_min = ds[0];
    let ds_max = ds.last().unwrap();

    let mut ans = 0;
    for k in ds_min..(ds_max+1) {
        let mut lb = -1;
        let mut ub = n as isize;
        while ub - lb > 1 {
            let mid = ((lb+ub)/2) as usize;
            if ds[mid] < k {
                lb = mid as isize;
            }
            else {
                ub = mid as isize;
            }
        }
        if lb == ((n/2-1) as isize) {
            ans += 1;
        }
    }

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


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*(n+2)+(j))

int calc(int l,int r,int *cnt,int *used,int n){
  if(l>r) return 0;
  if(used[POS(l,r)]) return cnt[POS(l,r)];
  used[POS(l,r)]=1;
  cnt[POS(l,r)]+=calc(l+1,r,cnt,used,n);
  cnt[POS(l,r)]+=calc(l,r-1,cnt,used,n);
  cnt[POS(l,r)]-=calc(l+1,r-1,cnt,used,n);
  return cnt[POS(l,r)];
}

void run(void){
  int n,m,q;
  scanf("%d%d%d",&n,&m,&q);
  int *cnt=(int *)calloc((n+2)*(n+2),sizeof(int));
  int i;
  for(i=0;i<m;i++){
    int l,r;
    scanf("%d%d",&l,&r);
    cnt[POS(l,r)]++;
  }
  int *used=(int *)calloc((n+2)*(n+2),sizeof(int));
  calc(1,n,cnt,used,n);

  for(i=0;i<q;i++){
    int l,r;
    scanf("%d%d",&l,&r);
    printf("%d\n",cnt[POS(l,r)]);
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     fopen     freopen("in.txt","r",stdin)
#define     fwrite    freopen("o.txt","w",stdout)
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))

int main()
{
    double ans=100000.0,t,a,tmp,b;
    int n,ind=1;
    cin>>n>>t>>a;
    double h[n];
    f0(n) {
        cin>>h[i];
        tmp=(h[i]*0.006);
        tmp=t-tmp;
        b=abs(a-tmp);
        if(b<ans) {
                ans=b;
                ind=i+1;
        }
    }
    cout<<ind;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int64, int > Pi;
const int64 INF = 1LL << 55;
 
struct edge {
  int to, cost;
};
typedef vector< vector< edge > > Graph;
 
void Dijkstra(Graph& graph, vector< int64 >& min_cost){
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.push( make_pair( 0, 0));
  min_cost.assign(graph.size(), INF);
  *(min_cost.begin()) = 0;
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(p.first > min_cost[p.second]) continue;
    for(int i = 0; i < graph[p.second].size(); i++){
      edge& e = graph[p.second][i];
      if(e.cost + p.first > min_cost[e.to]) continue;
      min_cost[e.to] = e.cost + p.first;
      que.push(make_pair(e.cost + p.first, e.to));
    }
  }
  return;
}
 
 
int main() {
  int64 N, M, C, Sum = 0LL;
 
  cin >> N >> M >> C;
  Graph graph(N);
 
  for(int i = 0; i < M; i++){
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    graph[a].push_back((edge){b, c});
    graph[b].push_back((edge){a, c});
 
    Sum += c;
  }
  vector< int64 > min_cost;
  Dijkstra(graph, min_cost);
  vector< Pi > min_costs(min_cost.size());
  for(int i = 0; i < min_cost.size(); i++){
    min_costs[i] = make_pair( min_cost[i], i);
  }
  sort( min_costs.begin(), min_costs.end());
 
  int64 ret = INF;
  for(int i = 0; i < min_costs.size(); i++){
    int idx = min_costs[i].second;
    for(int j = 0; j < graph[idx].size(); j++){
      edge& e = graph[idx][j];
      if(min_cost[e.to] == -1) Sum -= e.cost;
    }
    ret = min( ret, Sum + min_cost[idx] * C);
    min_cost[idx] = -1;
  }
  cout << ret << endl;
}

Measured memory_bytes: 12464
#include<iostream>
#include<algorithm>
#include<map>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 500001

using namespace std;

map<string,int> getIndex;
int t,s;
bool found;
int T[MAX],S[MAX];
string type[12] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
int dc[] = {+0,+1,-1};
int dx[] = {-1,-2,+1};

void dfs(int cur_t,int cur_s)
{
  if(cur_s < 0)
    {
      if(cur_t == -1)found = true;
      return;
    }

  rep(i,3)
    {
      int music = (T[cur_t] + dc[i] + 12)%12;
      if(t <= cur_t+dx[i])continue;

      if(music == S[cur_s])
	{
dfs(cur_t+dx[i],cur_s-1);
 return;
	}
   
    }
}

bool compute()
{
  found = false;
  dfs(t-1,s-1);
  if(!found)dfs(t-2,s-1);
  return found;
}

int main()
{
  rep(i,12)getIndex[type[i]] = i;
  int N;
  while(cin >> N)
    {
      while(N--)
	{

	  cin >> t >> s;
	  string input;
	  rep(i,t)
	    {
	      cin >> input;
	      T[i] = getIndex[input];
	    }
	  rep(i,s)
	    {
	      cin >> input;
	      S[i] = getIndex[input];
	    }
	  cout << (compute()?"Yes":"No") << endl;
	}
    }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const ll N=100+5;
const ll M=100000+5;

ll n;
ll w;

ll g[N];
ll p[N];

ll dp[N][M];

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>w;
    for(ll i=1;i<=n;i++)
    {
        cin>>g[i]>>p[i];
    }
    for(ll i=0;i<N;i++)
    {
        for(ll j=0;j<M;j++)
        {
            dp[i][j]=(1LL<<60);
        }
    }
    dp[1][0]=0;
    dp[1][p[1]]=g[1];
    for(ll i=2;i<=n;i++)
    {
        dp[i][0]=0;
        for(ll j=0;j<M;j++)
        {
            dp[i][j]=dp[i-1][j];
        }
        for(ll tot=p[i];tot<M;tot++)
        {
            dp[i][tot]=min(dp[i][tot],dp[i-1][tot-p[i]]+g[i]);
           // if(tot>20) continue;
           // cout<<i<<" , "<<tot<<" : "<<dp[i-1][tot-p[i]]<<"\n";
        }
    }
    ll ans=0;
    for(ll i=0;i<M;i++)
    {
        if(dp[n][i]<=w)
        {
            ans=i;
        }
    }
    cout<<ans<<"\n";
    return 0;
}
/**

**/


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



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }

    //static long GCD(long x,long y)
    //{
    //    if (y == 0) return x;
    //    return GCD(y, x % y);
    //}

    //static long LCM(long x,long y)
    //{
    //    return x * y / GCD(x, y);
    //}

    //static int keta(int x)
    //{
    //    string s = x.ToString();
    //    return s[s.Length - 1]-'0';
    //}

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        int N = sc.intarr[0];
        if (N == 0)
        {
            wr.wri(0);
            return;
        }
        string s = "";
        while (N != 0)
        {
            if (N % 2 !=0)
            {
                N = (N - 1) / -2;
                s = "1" + s;
            }
            else
            {
                N /= -2;
                s = "0" + s;
            }
        }

        wr.wri(s);
    }


}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main() {
 	string n;
  	cin >> n;
  
  	int sum = 0;
  	for (int i = 0; i < (int) n.size(); i++) {
     	sum += n[i] - '0';
    }
  
  	sum % 9 == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 3688
from sys import exit

H, W = map(int, input().split())
s = [input() for _ in range(H)]

P = set()
Q = {(0, 0)}
QQ = set()

def add(x, y):
    if s[x][y] == '.' and (x, y) not in P:
        QQ.add((x, y))

def search_next(x, y):
    if x > 0:
        add(x-1, y)
    if x < H-1:
        add(x+1, y)
    if y > 0:
        add(x, y-1)
    if y < W-1:
        add(x, y+1)

count = 0

while True:
    count += 1
    for q in Q:
        search_next(*q)
    P = P.union(Q)
    Q = QQ
    QQ = set()
    if (H-1, W-1) in Q:
        break
    elif len(Q) == 0:
        print(-1)
        exit(0)

white = 0
for line in s:
    white += line.count('.')

print(white - count - 1)


Measured memory_bytes: 3444
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>
#include <functional>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define PI 3.14159265358979323846264338327950L

int main() {
	rep(i, 5) {
		int x;
		cin >> x;
		if (x == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}

}

Measured memory_bytes: 3620