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

void rev(const int a, const int b, string &s) {
    string t = s.substr(a, b - a + 1);
    reverse(t.begin(), t.end());
    s.replace(a, b - a + 1, t);  
}

int main()
{
    string s;
    int q;
    cin >> s >> q;
    string t, c;
    int a, b;
    for(int i = 0; i < q; i++) {
        cin >> t >> a >> b;
        if (t == "replace") {
            cin >> c;
            s.replace(a, b - a + 1, c);
            // cout << s << '\n';
        }
        if (t == "reverse") {
            rev(a, b, s);
            // cout << s << '\n';
        }
        if (t == "print") {
            for(int i = a; i <= b; i++)
                cout << s[i];
            cout << '\n';
        }
    }

  
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>

using namespace std;

int sum(int n){
    return n*(n+1)/2;
}
int sum_up(int s,int t){
    // s <= t and 0 <= s.
    if(s == 0){
        return sum(t);
    }else{
        return sum(t) - sum(s-1);
    }
}

int solve(int n){
    int ret = 0;
    for(int s=1;s<=n;s++){
        for(int t=s+1;t<=n;t++){
            if(sum_up(s,t) == n){
                ret++;
            }
        }
    }
    return ret;
}

int main(int argc,char** argv){
    while(true){
        int n;cin >> n;
        if(n == 0) break;
        cout << solve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;

int n;
string s1, s2;
vector<int> n2;

int func(int x, vector<int> n1){
	if(x == n) return 0;
	if(n1[x] == n2[x]){
		return func(x+1,n1);
	}
	int ret = INF;
	vector<int> tmp = n1;
	for(int i = 0; i < n-x; i++){
		if(n1[x] > n2[x]){
			for(int j = x; j < x+i+1; j++){
				tmp[j] -= n1[x]-n2[x];
				if(tmp[j] < 0) tmp[j]+=10;
			}
			ret = min(ret,func(x+1,tmp));
		} else{
			for(int j = x; j < x+i+1; j++){
				tmp[j] += n2[x]-n1[x];
				if(tmp[j] >= 10) tmp[j]-=10;
			}
			ret = min(ret,func(x+1,tmp));
		}
		tmp = n1;
	}
	return ret+1;
}

void solve(){
	cin >> s1 >> s2;
	n2.clear();
	vector<int> n1;
	rep(i,n){
		n1.push_back(s1[i]-'0');
		n2.push_back(s2[i]-'0');
	}
	cout << func(0,n1) << endl;
}

int main(){
	while(true){
		cin >> n;
		if(n == 0) break;
		solve();
	}
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll a,b,c,ans;
    cin >> a >> b >> c;
    ans = min(a+b,b+c);
    ans = min(ans,c+a);
    cout << ans << "\n";
    return 0;
}

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

#define rep(i,N) for(int i=0; i<(N); i++)
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;

int N,D;

int main(){ 

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>D;

if(N%(2*D+1)==0){
	cout<<N/(2*D+1)<<endl;
}else{
	cout<<N/(2*D+1)+1<<endl;
}

}


Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d = map(int,input().split())
div = lcm(d,c)

if div <= b:
    x_div = a//div
    y_div = b//div
    if a%div == 0:
        x_div -= 1
else:
    x_div = 0
    y_div = 0
x_c = a//c
if a%c == 0:
    x_c -=1
y_c = b//c
x_d = a//d
if a%d == 0:
    x_d -= 1
y_d = b//d
print(b-a+1+(y_div-x_div)-(y_c-x_c)-(y_d-x_d))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i,N)
  {
    cin >> x[i];
  }
  int m = 1000000000;
  m = min(X,m);
  rep(i,N)
  {
    m = min(m,x[i]);
  }
  int M = 1000000000;
  if(N==1)
  {
    cout << abs(x[0]-X) << endl;
    return 0;
  }
  rep(i,N-1)
  {
    if(x[i]==m)
    {
      continue;
    }
    M = min(M,gcd(x[i]-m,x[i+1]-m));
  }
  if(X!=m)
  {
    if(x[0]!=m)
    {
      M = min(M,gcd(x[0]-m,X-m));
    }
    else
    {
      M = min(M,gcd(x[1]-m,X-m));
    }
    
  }
  cout << M << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	int k,x; cin >> k >> x;
	Yes(k * 500 >= x);
}

Measured memory_bytes: 256
n = int(input())

a = map(int, input().split(" "))

point = 0

for i in a:
    if i % 4 == 0:
        point += 2
    elif i % 2 == 0:
        point += 1

if n % 2 == 1:
    if n <= point + 1:
        print("Yes")
    else:
        print("No")
else:
    if n <= point:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 11100
# -*- coding: utf-8 -*-

import sys
import os


def input_to_list():
    return list(map(int, input().split()))

H, W = input_to_list()
M = []
for i in range(H):
    M.append(input_to_list())

v = []
for i in range(W):
    v.append(int(input()))

# M x v
for i in range(H):
    all = 0
    for j in range(W):
        all += M[i][j] * v[j]
    print(all)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  string s;
  cin >> s;
  int cnt=0;
  REP(i,3){
    if(s[i]=='o')cnt++;
  }
  cout << 700+100*cnt << endl;
}



Measured memory_bytes: 256
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sun Mar  4 21:01:07 2018
//
package main

import (
	"fmt"
)

var N int

func main() {
	fmt.Scan(&N)

	m := map[string]int{}
	for i := 0; i < N; i++ {
		var s string
		fmt.Scan(&s)
		m[s]++
	}

	if len(m) == 3 {
		fmt.Println("Three")
	} else {
		fmt.Println("Four")
	}
}


Measured memory_bytes: 512
H,W = map(int, input().split())
B = [list(input()) for i in range(H)]

l = []

for i in range(H):
    for j in range(W):
        if B[i][j] == '#':
            l.append((i,j))

def a(l):
    n = []
    d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    for y, x in l:
        for dy, dx in d:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and B[ny][nx] == '.':
                B[ny][nx] = '#'
                n.append((ny, nx))
    return set(n)

ans = 0
while len(l) != 0:
    l = a(l)
    ans += 1
print(ans-1)

Measured memory_bytes: 142136
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
  int a,b,h,m;
  scanf("%d%d%d%d",&a,&b,&h,&m);
  double theta = (h*60+m)*5.5/180*M_PI;
  double res = sqrt(a*a + b*b - 2*a*b*cos(theta));
  printf("%.14f", res);
  return 0;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int a, b; cin >> a >> b;
	string s; cin >> s;
	if (s.size() == a + b + 1) {
		for (int i = 0; i < s.size(); i++) {
			if (i == a) {
				if (s[i] == '-');
				else goto heaven;
			}
			else if (s[i] == '0' || s[i] == '1' || s[i] == '2' || s[i] == '3' || s[i] == '4' || s[i] == '5' || s[i] == '6' || s[i] == '7' || s[i] == '8' || s[i] == '9');
			else goto heaven;
		}
		cout << "Yes\n";
		return 0;
	}
	else {
		heaven:
		cout << "No\n";
	}
}

Measured memory_bytes: 888
N = int(input())
S = list(input())

if '#' not in S:
    print(0)
elif '.' not in S:
    print(0)
else:
    l=[0 for i in range(N+1)]
    w = 0
    for i in range(N):
        if S[i] == '#':
            l[i+1] = l[i] + 1
        else:
            l[i+1] = l[i] - 1
            w += 1          

    print(min(l)+w)

Measured memory_bytes: 12740
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl d(n);
  rep(i, n) cin >> d[i];
  sort(all(d));
  cout << d[n/2]-d[n/2-1] << newl;
  return 0;
}

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

int main(){
    std::vector<int> vec(3);
    for(int i = 0; i < 3; ++i){
        std::cin >> vec.at(i);
    }

    std::sort(vec.begin(), vec.end());

    for(int i = 0; i < 3; ++i){
        std::cout << vec.at(i);
        if(i < 2){
            std::cout << " ";
        }
    }

    std::cout << std::endl;
    
    return 0;
}


Measured memory_bytes: 3148
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    string ans;
    while (A > 0 && C > 0) {
        C = C - B;
        if (C <= 0) {
            ans = "Yes";
            break;
        }
        A = A - D;
        if (A <= 0) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  string s;
  cin >> s;

  if(s[2] == s[3] &&
     s[4] == s[5]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


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

int main(){
	string s;
	cin >> s ;
	
	if (s == "Sunny") cout<< "Cloudy" << endl;
	else if (s == "Rainy") cout << "Sunny" <<endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	
	
	
	return 0;
	}

Measured memory_bytes: 256
def num(m):  # eの要素のうちm-1以上のものの個数
    return len(list((filter(lambda x: x >= m-1, e))))


N = int(input())
e = [0] * (N+1)  # その素因数がいくつあるか
for i in range(2, N+1):
    cur = i  # iを素因数分解する
    for j in range(2, i+1):
        while cur % j == 0:  # jを素因数にもつなら
            e[j] += 1  # カウントを増やす
            cur //= j
# これで素因数分解が完了


print(num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3) - 2) // 2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
#define y2 cyktxdy
typedef long long ll;
typedef vector<int> poly;
typedef vector<ll> Poly;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
const int rlen=1<<18|1,inf=0x3f3f3f3f;
const ll Inf=1e18;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline ll readl() {
  ll ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline int Read(char*s) {
  int top=0;
  char ch=gc();
  while(!isalpha(ch)&&!isdigit(ch)) ch=gc();
  while(isalpha(ch)||isdigit(ch)) s[++top]=ch,ch=gc();
  return top;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
}
using namespace modular;
template<typename T>inline void ckmax(T&a,T b) { a<b?a=b:0; }
template<typename T>inline void ckmin(T&a,T b) { a>b?a=b:0; }
template<typename T>inline T gcd(T a,T b) { T t;while(b) t=a,a=b,b=t-t/a*a;return a; }
int n,X,a[105],f[2][105][505],cur;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read(),X=read();
  for(ri i=1;i<=n;++i) a[i]=read();
  sort(a+1,a+n+1),reverse(a+1,a+n+1);
  f[cur=1][0][a[1]]=1;
  for(ri x,t=2;t<=n;++t) {
    x=a[t];
    for(ri trs,i=0;i<=n;++i) for(ri j=0;j<=X;++j) if((trs=f[cur][i][j])>0) {
      if(j+x<=X) Add(f[cur^1][i+1][j+x],mul(trs,i+2));
      Add(f[cur^1][i][j],mul(trs,j-(i+1)*(x-1)));
      for(ri k=1;k<=x&&j+k<=X;++k) {
        Add(f[cur^1][i][j+k],mul(trs,(i+1)*2));
        if(i) Add(f[cur^1][i-1][j+k],mul(trs,mul(i,x-k+1)));
      }
      f[cur][i][j]=0;
    }
    cur^=1;
  }
  cout<<f[cur][0][X];
  return 0;
}

Measured memory_bytes: 640
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let n = get!(usize);
    let mut ts = get!(String).split_whitespace().map(|i| i.parse::<usize>().unwrap() * 2).collect::<Vec<_>>();
    for i in 1..n {
        ts[i] += ts[i-1];
    }
    let vs = get!(String).split_whitespace().map(|i| i.parse::<usize>().unwrap() * 2).collect::<Vec<_>>();

    let &t_sum = ts.last().unwrap();
    let &v_max = vs.iter().max().unwrap();

    let mut tt = vec![v_max+1; t_sum+1];

    for i in 0..n {
        let s = if i == 0 { 0 } else { ts[i-1]+1 };
        for j in s..ts[i]+1 {
            tt[j] = cmp::min(tt[j], vs[i]);
        }
    }

    for i in 0..cmp::min(t_sum, v_max)+1 {
        tt[i] = cmp::min(tt[i], i);
    }
    for i in 0..n {
        let mut j = ts[i];
        let mut k = vs[i];
        loop {
            if j > t_sum || k > v_max {
                break;
            }
            tt[j] = cmp::min(tt[j], k);
            j += 1;
            k += 1;
        }
    }
    let mut j = t_sum;
    let mut k = 0;
    loop {
        tt[j] = cmp::min(tt[j], k);
        if j == 0 || k == v_max {
            break;
        }
        j -= 1;
        k += 1;
    }
    for i in 0..n-1 {
        let mut j = ts[i];
        let mut k = vs[i+1];
        if k > v_max {
            break;
        }
        loop {
            tt[j] = cmp::min(tt[j], k);
            if j == 0 || k == v_max {
                break;
            }
            j -= 1;
            k += 1;
        }
    }

    let mut s = 0;
    for i in 0..t_sum+1 {
        s += tt[i];
    }
    println!("{:.12}", (s as f64) / 4.0);
}

Measured memory_bytes: 2348
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  map<i64, i64> mp;
  for(i64 i = 2; i * i <= N; i++) {
    if(N % i == 0) {
      i64 cnt = 0;
      while(N % i == 0) {
        cnt++;
        N /= i;
      }
      mp[i] = cnt;
    }
  }
  if(N > 1) {
    mp[N] = 1;
  }
  i64 ans = 0;
  for(auto pp: mp) {
    auto p = pp.second;
    i64 ok = 0;
    i64 ng = 1e9;
    for(int i = 0; i < 50; i++) {
      i64 mid = (ok + ng) / 2;
      if(mid * (mid + 1) / 2 <= p) {
        ok = mid;
      }
      else {
        ng = mid;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int a, b, x;
    cin >> a >> b >> x;
    
    if (a + b - x  <= b && x < a+b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

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

#define M 1000000
#define NIL (-1)
#define L 12
char H[M][L];

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;
    else return 0;
}

long long getKey(char str[]) {
    int len = strlen(str);
    long long sum = 0, p = 1, i;
    for(i=0; i<len; ++i) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) {return key%M;}
int h2(int key) {return 1+(key%(M-1));}

int find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for(i=0; ; ++i) {
        h = (h1(key)+i*h2(key))%M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for(i=0; ; ++i) {
        h = (h1(key)+i*h2(key))%M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) {
            strcpy(H[h], str);
            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: 13452
var
	N,i,j:Longint;
	ans:int64;
begin
	read(N);
	j:=round(sqrt(N));
	if j*j>N then dec(j);
	for i:=1 to j do inc(ans,(N div i)*(N div i+1)*i-i*i*i);
	writeln(ans);
end.

Measured memory_bytes: 1376
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n = INT()
A = LIST()
B = LIST()
C = LIST()
ans = 0
for i in range(n-1):
  if A[i]+1 == A[i+1]:
    ans += C[A[i]-1]
print(ans + sum(B))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll N, A, B;
  cin >> N >> A >> B;
  ll d = N / (A + B);
  ll m = N % (A + B);
  ll ans = A * d + min(A, m);
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n; cin >> n;
  if(n<=111) cout << 111 << endl;
  if(n>111 && n<=222) cout << 222 << endl;
  if(n>222 && n<=333) cout << 333 << endl;
  if(n>333 && n<=444) cout << 444 << endl;
  if(n>444 && n<=555) cout << 555 << endl;
  if(n>555 && n<=666) cout << 666 << endl;
  if(n>666 && n<=777) cout << 777 << endl;
  if(n>777 && n<=888) cout << 888 << endl;
  if(n>888) cout << 999 << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        sc.close();
        int res = 1;
        for(int i=0;i<n-1;i++){
            if(s[i]!=s[i+1])res++;
        }
        System.out.println(res);
    }
    
}

Measured memory_bytes: 28396
n=int(input())
def f(n):
    six=(n+1)//2
    five=n-six
    return 6*six+5*five
l,r,ans=0,10**18,-1
while(l<=r):
    m=(l+r)//2
    if(f(m)>=n):
        ans=m
        r=m-1
    else:
        l=m+1
print(ans)


Measured memory_bytes: 9144
import sys

MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())
s1, s2 = sys.stdin.read().split()

def main():
    if s1[0] == s2[0]:
        i = 1
        res = 3
        flag = 0
    else:
        i = 2
        res = 6
        flag = 1
    
    while i < n:
        if s1[i] == s2[i]:
            if flag:
                res *= 1
            else:
                res = res * 2 % MOD
            flag = 0
            i += 1
        else:
            if flag:
                res = res * 3 % MOD
            else:
                res = res * 2 % MOD
            flag = 1
            i += 2
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


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

long long mod_pow(long long x, long long n){
	if(n == 0) return 1;
	long long res = mod_pow(x*x % MOD, n / 2);
	if(n & 1) res = res*x % MOD;
	return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  map<int,int> pf;
  rep(i,n){
    map<int,int> tmp=prime_factor(a[i]);
    for(auto j: tmp){
      pf[j.first]=max(pf[j.first],j.second);
    }
  }
  ll l=1;
  for(auto i: pf){
    l=l*mod_pow(i.first,i.second)%MOD;
  }
  int ans=0;
  rep(i,n){
    ans+=l*modinv(a[i],MOD)%MOD;
    ans%=MOD;
  }
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 768
(* O(n) *)
let solve n t a hs =
  List.fold_left
    (fun ((mi, min_i), i) h ->
      let d = abs_float (float_of_int t -. 0.006 *. float_of_int h -. float_of_int a) in
      if d < mi then
        ((d, i), i + 1)
      else
        ((mi, min_i), i + 1))
    ((max_float, -1), 1)
    hs |> fst |> snd

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  let n = read_int () in
  match read_ints () with
  | [t; a] -> read_ints () |> solve n t a |> string_of_int |> print_endline
  | _ -> ()

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  if (n < k) {
    puts("0");
    return;
  }
  n -= k;
  const i32 mod = 1000000007;
  i32 *dp = (i32 *) calloc (n + 1, sizeof (i32));
  dp[0] = 1;
  for (i32 i = 1; i <= k; ++i) {
    for (i32 j = i; j <= n; ++j) {
      dp[j] += dp[j - i];
      dp[j] %= mod;
    }
  }
  printf ("%" PRIi32 "\n", dp[n]);
}

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



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

int main()
{
	string s,t;
	cin>>s>>t;
	
	long long int count = 0;
	
	for(long long int i=0;i<s.length();i++)
	{
		if(s[i] != t[i])
		{
			count++;
		}
	}
	
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<cmath>
#include<unordered_map>
#include<vector>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
const int inf = (1e18)+7;
const int neginf = -1*((int)1e17 ) + 7 ; 

int32_t main() {
    fastio
   
    int n,k,q;
    cin>>n>>k>>q;
    
    int arr[q];
    
    fo(i,q)
        cin>>arr[i];
    
    int brr[n];
    
    fo(i,n)
        brr[i] = k;
    
    for(int i=0;i<q;++i)
        brr[arr[i]-1]++;
    
    fo(i,n)
        brr[i]-=q;
    
    fo(i,n)
    {
        if(brr[i]>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    
    
    

        
        
        
    
            
        
       
        
        
        
    
     
    
    
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << ", ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << " ]" ;
}

#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
#define sz(a) (ll)(a).size()
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)
#define pi 3.141592653589793238462643

void solve(){
    string s;
    cin >> s;
    ll sum = 0;
    loop(i,0,sz(s)){
        sum += s[i] - '0';
    }
    if(sum % 9 == 0){
        print("Yes");
    }
    else print("No");
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


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

#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;

int const N=1e6+100;
ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
int const BN = 31;

ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}

ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}

ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

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

	int n;
	cin>>n;
	vector<double> arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	sort(all(arr));
	for(int i=0; i<n-1; i++){
		arr[i+1]=(arr[i]+arr[i+1])*0.5;
	}
	cout<<fixed<<setprecision(6)<<arr[n-1]<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
N, K = map(int, input().split())

e = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

col = [-1 for i in range(N)]
col[0] = 0
MOD = 10 ** 9 + 7


def dfs(i, ans, depth):
    # if depth == 0:
    #     num = K
    if depth == 1:
        num = K - 1
    else:
        num = K - 2
    for v in e[i]:
        if col[v] == -1:
            col[v] = 0
            ans = (ans * num) % MOD
            num -= 1
            ans = dfs(v, ans, depth+1)

    return ans


print(dfs(0, K, 1))


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

int main() 
{
    int N;
    float ans = 0.0, A;
    cin >> N;
    for(int i=1;i<=N;i++) {
        cin >> A;
        ans += 1.0/A;
    }
    ans = 1.0/ans;
    cout << setprecision(16) << ans << endl;
    return 0;
}


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

int main(){
    string n;
    cin >> n;
    if(n[0]=='7' || n[1]=='7' || n[2]=='7'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0 ;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    ll n,money=1000,t=0;
    cin>>n;
    vi a(n);
    vector<bool>b(n,false),c(n,false);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n-1){
        ll m;
        REP(j,i,n-1){
            if(a[j]>=a[j+1]){
                m=j;
                break;
            }
        }
        i=max(i,m);
        b[m]=true;
        //cout<<m<<endl;
    }
    rep(i,n-1){
        if(a[i]<a[i+1])c[i]=true;
    }
    rep(i,n){
        if(b[i]&&t!=0){
            money+=t*a[i];
            t=0;
        }else{
            if(money>=a[i]&&c[i]){
                t=money/a[i];
                money-=t*a[i];
            }
        }
        if(i==n-1){
            money+=t*a[i];
            t=0;
        }
        //cout<<b[i]<<":"<<money<<":"<<t<<endl;
    }
    cout<<money<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3648
N=int(input())
come=input()
come=come.split()
come_list=[]
for i in come:
    come_list.append(int(i)) 
rank=[]
for i in range(N):
    rank.append(0)
count=1

for i in come_list:
    rank[i-1]=count
    count+=1


out_put=str(rank[0])

for i in rank[1:]:
    out_put+=" "+str(i)

print(out_put)

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double ang_a = (30 * h) + (m / 2);
  double ang_b = 6*m;

  double ang = abs(ang_a - ang_b);
  if (ang > 180)
  {
    ang = 360 - ang;
  }
  
  double rad = (ang / 180) * M_PI;

  double length = sqrt(a*a + b*b - 2*a*b*cos(rad));
  
  cout << fixed << setprecision(12);
  cout << length << endl;
  
  return 0;
}

Measured memory_bytes: 4236
#include <iostream>
#include <vector>

int main () {
    int N;
    std::cin >> N;
    std::vector<double> v;
    double tmp_v;
    for (int i = 0; i < N; i++)
    {
        std::cin >> tmp_v;
        v.push_back(tmp_v);
    }

    std::sort(v.begin(), v.end());
    // std::sort(v.begin(), v.end(), std::greater<double>());
    // for (int i = 0; i < N; i++)
    // {
    //     std::cout << v[i] << std::endl;
    // }

    double s = (v[0] + v[1]) / 2;
    for (int i = 2; i < N; i++)
    {
        s = (s + v[i]) / 2;
    }

    std::cout << s << std::endl;
}


Measured memory_bytes: 888
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var Ai = new string[N];
            for (var i = 0; i < N; ++i)
                Ai[i] = ReadLine();
            var Bi = new string[M];
            for (var i = 0; i < M; ++i)
                Bi[i] = ReadLine();
            for (var n = 0; n < N - M + 1; ++n)
            {
                for (var i = 0; i < N - M + 1; ++i)//yoko
                {
                    var flg = true;
                    for (var m = 0; m < M; ++m)//tate
                    {
                        if (Ai[n + m].Substring(i, (int)M) != Bi[m])
                            flg = false;
                    }
                    if (flg)
                    {
                        WriteLine("Yes");
                        return;
                    }
                }
            }
            WriteLine("No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int kotae = 0;
	rep(i, A + 1) {
		rep(ii, B + 1) {
			rep(iii, C + 1) {
				if (i * 500 + ii * 100 + iii * 50 == X) kotae++;
			}

		}


	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n=n_in()

from collections import defaultdict

memo=defaultdict(list)
for i in range(n):
    a,b=l_in()
    memo[a].append((i,True))
    memo[b].append((i,False))
    


left=set()
mid=set()
right=set(range(n))


lazy=set()

res_left=-1
res_right=-1

res2_left=-1
res2_right=-1

for x in sorted(memo.keys()):
    for i in lazy:
        mid.remove(i)
        left.add(i)
    lazy.clear()
    
    for i, is_a in memo[x]:
        if is_a:
            right.remove(i)
            mid.add(i)
        else:
            lazy.add(i)
            
    if n%2 == 0:
        m = n//2-1

        # n//2
        if len(mid) >= 1 and len(left) <= m and len(right) <= m+1:
            if res_left == -1:
                res_left = x
            res_right = x
            
        # n//2 + 1
        if len(mid) >= 1 and len(left) <= m+1 and len(right) <= m:
            if res2_left == -1:
                res2_left = x
            res2_right = x
    else:
        m = (n-1)//2
        if len(mid) >= 1 and len(left) <= m and len(right) <= m:
            if res_left == -1:
                res_left = x
            res_right = x

if n%2 == 0:
    print(res_right-res_left+res2_right-res2_left+1)
else:
    print(res_right-res_left+1)


Measured memory_bytes: 191400
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int N = 3010;
const int mod = 998244353;
int dp[N][N];
int a[N];

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

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

	// dp[i][j]
	// first i number, sum of T is j
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= m; j++) {
			if (dp[i][j] == 0) continue;
			// not in S, not int T
			add(dp[i + 1][j], dp[i][j]);
			// in S, not int T
			add(dp[i + 1][j], dp[i][j]);
			// in T
			if (j + a[i + 1] <= m) add(dp[i + 1][j + a[i + 1]], dp[i][j]);
		}

	cout << dp[n][m] << endl;
	return 0;
}


Measured memory_bytes: 38512
char out[1001];
char buf[100];
sz,k;
H,W,A,B;
main()
{
	read(0,buf,100);
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		H=H*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		W=W*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		A=A*10+k-'0';
	}
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		B=B*10+k-'0';
	}
	for(int j=0;j<A;++j)out[j]='0';
	for(int j=A;j<W;++j)out[j]='1';
	out[W]='\n';
	for(int i=0;i<B;++i)
	{
		write(1,out,W+1);
	}
	for(int j=0;j<A;++j)out[j]='1';
	for(int j=A;j<W;++j)out[j]='0';
	for(int i=B;i<H;++i)
	{
		write(1,out,W+1);
	}
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    number, k = list(map(int, input().split()))
    count = 0

    # See:
    # https://img.atcoder.jp/arc091/editorial.pdf
    # https://beta.atcoder.jp/contests/abc090/submissions/2193514
    for b in range(1, number + 1):
        p, r = divmod(number, b)
        count += p * max(0, b - k) + max(0, r - k + 1)

    if k == 0:
        count -= number

    print(count)


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-


def calc_dist(s, start_i, start_j, h, w):
    from collections import deque

    result = 0
    d = deque()
    d.append((start_i, start_j))
    dist = [[0 for _ in range(w)] for _ in range(h)]
    visited = [[False for _ in range(w)] for _ in range(h)]
    visited[start_i][start_j] = True
    dxy = [(1, 0), (-1, 0), (0, -1), (0, 1)]

    while d:
        hd, wd = d.popleft()

        for dx, dy in dxy:
            nx = wd + dx
            ny = hd + dy

            if nx < 0 or nx >= w or ny < 0 or ny >= h:
                continue

            if s[ny][nx] == '#':
                continue

            if visited[ny][nx]:
                continue

            visited[ny][nx] = True
            dist[ny][nx] = dist[hd][wd] + 1
            d.append((ny, nx))
            result = max(result, dist[ny][nx])

    return result


def main():
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    ans = 0

    # KeyInsight
    # 始点のみを全探索(終点は全探索する必要はない)
    # 距離はBFSで計算
    for start_i in range(h):
        for start_j in range(w):
            if s[start_i][start_j] == '#':
                continue

            ans = max(ans, calc_dist(s, start_i, start_j, h, w))

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
	int n, a;
	cin >> n >> a;
	int x[n];
	rep(i,n) cin >> x[i];
  vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(2501,0)));
	dp[0][0][0] = 1;
	rep(i,n) {
		rep(j,n+1) 
		  rep(k,2501) {
				dp[i+1][j][k] += dp[i][j][k];
			  if(k+x[i] <= 2500 & j+1 <= n) dp[i+1][j+1][k+x[i]] += dp[i][j][k];
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans += dp[n][i][a*i];
	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 52224
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    vvll dp(4001, vll(4001, 0));
    while (cin >> s >> t) {
        ll ans = 0;
        REP(i, s.size()+1) REP(j, t.size()+1) dp[i][j] = 0;
        REP(i, s.size()) {
            REP(j, t.size()) {
                if (s[i] == t[j]) {
                    dp[i+1][j+1] = dp[i][j]+1;
                    chmax(ans, dp[i+1][j+1]);
                } else dp[i+1][j+1] = 0;
            }
        }
        cout << ans << '\n';
    }
}



Measured memory_bytes: 127796