akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[100031];
int l[200055];
int j[100101];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[1];
queue<int> q;

//stack<int> s;
set<int> s;
map<int,int> p;
vector<P> v[100101];
vector<int> v1[100101];

bool as(P a,P b)
{
  return a.y<b.y;
}

void f(int n)
{
  for(int h=0;h<v1[n].size();h++)
  if(j[v1[n][h]]<0)
  {
    j[v1[n][h]]=1-j[n];
    f(v1[n][h]);
  }
}

int main()
{
  scanf("%d %d",&a,&b);
  c=mod;
  for(int t=1;t<=a;t++)
  {
    scanf("%d",&o[t]);
    c=min(o[t],c);
    if(c==o[t]) e=t;
  }
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d",&n,&m);
    l[t]=max(o[n],o[m]);
    v[n].push_back({m,t});
    v[m].push_back({n,t});
  }
  for(int t=1;t<=a;t++)
  {
    for(int h=0;h<v[t].size();h++)
    if(l[v[t][h].y]<=o[t])
    {
      v1[t].push_back(v[t][h].x);
      v1[v[t][h].x].push_back(t);
      goto qwe;
    }
    puts("-1");
    return 0;
    qwe:;
  }
  memset(j,-1,sizeof(j));
  
  for(int t=1;t<=a;t++)
  if(j[t]<0)
  {
    j[t]=1;
    f(t);
  }
  for(int t=1;t<=a;t++)
    if(!j[t]) printf("B");
    else printf("W");
  puts("");
  for(int t=1;t<=b;t++)
    if(l[t])
    printf("%d\n",l[t]);
    else printf("1000000000\n");
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());

  ll sum = 0;
  for (int i = 1; i < n; i++) {
    sum += (ll)a[i / 2];
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4004
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

template <class T>
T clampMax(const T& a, const T& b) { return min(a, b); }

template <class T>
T clampMin(const T& a, const T& b) { return max(a, b); }


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

const int MAX_N = 100010;
const int INF_COST = 2000000000;
int N, K;
int h[MAX_N];
int dp[MAX_N];

int main()
{
    cin >> N >> K;
    REP(i, N) cin >> h[i];
    REP(i, MAX_N) dp[i] = INF_COST;
    dp[N - 1] = 0;
    for (int i = N - 2; i >= 0; --i)
    {
        REP(j, K)
        {
            int pos = i + (j + 1);
            int cost = dp[pos] + abs(h[i] - h[pos]);
            dp[i] = min(dp[i], cost);
        }
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
pair<int, int> a[10];
long long N;
long long cost = 0;
int minn = 0;
int main()
{
	for (int i = 1; i <= 4; i++) {
		scanf("%d", &a[i].first);
		a[i].second = i;
	}
	scanf("%lld", &N);
	a[1].first *= 8; a[2].first *= 4; a[3].first *= 2;
	sort(a + 1, a + 5);
	if (a[1].second <= 3)cost += N * a[1].first / 2;
	else {
		cost += N / 2 * a[1].first;
		N = N % 2;
		cost += N*a[2].first / 2;
	}
	printf("%lld", cost);
}

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    int a_ = a;
    int b_ = b;

    if (a+k-1 >= b-k+1) {
        for (int i = a; i < b+1; i++) {
            cout << a_ << endl;
            a_++;
        } 
    }
    else {
        for (int i = a; i < a+k; i++) {
            cout << a_ << endl;
            a_++;
        }
        for (int i = b-k+1; i < b+1; i++) {
            cout << b_-k+1 << endl;
            b_++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, Ma, Mb;
	int ans = INF32;
	vector<int> data(400401, INF32);
	cin >> N >> Ma >> Mb;

	data[0] = 0;
	for (int i = 0; i < N; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;

		for (int j = 400400; a + 1000 * b <= j; j--)
		{
			if (data[j - a - 1000 * b] != INF32)
			{
				data[j] = min(data[j], data[j - a - 1000 * b] + c);
			}
		}
	}

	for (int i = Ma + Mb * 1000; i <= 400400; i += Ma + Mb * 1000)
	{
		//cout << i << " " << data[i] << endl;
		ans = min(ans, data[i]);
	}

	if (ans == INF32)
	{
		cout << -1 << endl;
	}
	else
		cout << ans << endl;
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a)
    cin >> x;

  map<int, int> even;
  map<int, int> odd;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      even[a[i]]++;
    } else {
      odd[a[i]]++;
    }
  }

  vector<pair<int, int>> e;
  vector<pair<int, int>> o;
  for (auto [k, v] : even) {
    e.emplace_back(k, v);
  }
  for (auto [k, v] : odd) {
    o.emplace_back(k, v);
  }
  sort(e.begin(), e.end(),
       [](auto &p1, auto &p2) { return p1.second > p2.second; });
  sort(o.begin(), o.end(),
       [](auto &p1, auto &p2) { return p1.second > p2.second; });

  auto f = [&](int x, int y) { return (n + 1) / 2 - x + n / 2 - y; };

  if (e[0].first != o[0].first) {
    cout << f(e[0].second, o[0].second) << endl;
    return 0;
  }
  if (e.size() == 1 && o.size() == 1) {
    cout << min(f(e[0].second, 0), f(0, o[0].second)) << endl;
    return 0;
  }
  if (e.size() == 1) {
    cout << f(e[0].second, o[1].second) << endl;
    return 0;
  }
  if (o.size() == 1) {
    cout << f(e[1].second, o[0].second) << endl;
    return 0;
  }
  cout << min(f(e[0].second, o[1].second), f(e[1].second, o[0].second)) << endl;

  return 0;
}


Measured memory_bytes: 9212
H,W,M=map(int,input().split())
R=[set([]) for _ in range(H+1)]
C=[set([]) for _ in range(W+1)]
R_n=[0]*(H+1)
C_n=[0]*(W+1)
b=[]

for i in range(M):
    y,x=map(int,input().split())
    b.append((x,y))
    R[y].add(x)
    C[x].add(y)
    R_n[y]+=1
    C_n[x]+=1

R_m=max(R_n)
R_i=[i for i, x in enumerate(R_n) if x == R_m]
C_m=max(C_n)
C_i=[i for i, x in enumerate(C_n) if x == C_m]

flag=0
for i in C_i:
    for j in R_i:
        if not i in R[j]:
            flag=1
            ans=R_m+C_m
            break
    if flag==1:
        break

if flag==0:
    ans=R_m+C_m-1

print(ans)


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

int main()
{
	int N, M;
	cin >> N >> M;

	int Ndash = 2 * M + 1;

	for (int i = 1, j = 2*(Ndash / 4) + 1; i < j; i++, j--)
	{
		cout << i << " " << j << endl;
	}

	for (int i = 2*(Ndash / 4) + 2, j = Ndash; i < j; i++, j--)
	{
		cout << i << " " << j << endl;
	}




	return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    map<string, ll> ma;
    ll q; cin >> q;

    ll a, b;
    string str;

    rep(i, q) {
        cin >> a >> str;
        if (a == 0) {
            cin >> b;
            ma[str] = b;
        }
        else if (a == 1) {
            cout << ma[str] << endl;
        }
    }

}


Measured memory_bytes: 25860
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

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

	//int t; cin >> t;

	//rep(test, t) {
	int h,w, k;
	cin >> h >> w >> k;

	vector<vector<ll>> s(h, vector<ll>(w));
	rep(i,h) { 
	  string _s;
		cin >> _s;
	  rep(j,w) s[i][j] =(ll) _s[j]-'0';
	}

	ll ans = INF;
	rep(_col, 1 << h - 1) {
		bool ok = true;
		vector<int> colline;
		colline.push_back(-1);
		rep(j,h) if (_col >> j & 1) colline.push_back(j);
		colline.push_back(h-1);

		vector<vector<int>> col(colline.size()-1, vector<int>(w,0));
		rep(l, colline.size() - 1) rep(j, w) for (int i = colline[l] + 1; i <= colline[l + 1]; ++i) {
			col[l][j] += s[i][j];
		}

		ll ans0 = colline.size()-2;
		vector<vector<ll>> sum(col.size(), vector<ll>(w, 0));
		rep(j, w) { 
		  bool overk = false;
		  rep(l, col.size()) {
				sum[l][j] += col[l][j];
			  if (j-1 >= 0) sum[l][j] += sum[l][j-1];
				overk = overk || sum[l][j] > k;
			}

			if (overk) { 
			  ans0++;
			  rep(l,col.size()) {
					if (col[l][j] > k) { ok = false; break; }
					sum[l][j] = col[l][j];
				}
				if (!ok) break;
			}
		}

		//debug2D(sum); 

		if (ok) { chmin(ans, ans0); }
		
	}

	cout << ans << endl;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

typedef unsigned long long ull;
 
mt19937_64 r(std::chrono::high_resolution_clock::now().time_since_epoch().count());

ull constexpr MASK30 = (1<<30)-1;
ull constexpr MASK31 = INT_MAX;
ull constexpr MOD = (1LL<<61)-1;
ull const base = r()%MOD;
 
struct RollingHash {
private:
    vector<ull> power,hash;
public:
    ull mul(ull a,ull b) {
        ull au = a>>31;
        ull ad = (a&MASK31);
        ull bu = b>>31;
        ull bd = (b&MASK31);
        ull mid = au*bd+ad*bu;
        return calcmod(((au*bu)<<1)+ad*bd+(mid>>30)+((mid&MASK30)<<31));
    }

    ull calcmod(ull a) {
        a = (a&MOD)+(a>>61);
        if (a > MOD) a -= MOD;
        return a;
    }

    RollingHash(string& s) {
        int n = s.size();
        power.resize(n+1);
        hash.resize(n+1);
        power[0] = 1;
        hash[0] = 0;
        for (int i = 0;i < n;++i) power[i+1] = mul(power[i],base);
        for (int i = 0;i < n;++i) hash[i+1] = calcmod(mul(hash[i],base)+s[i]);
    }

    ull get(int l, int r)  {
        if (l) {
            ull ret = hash[r]+MOD-mul(hash[l],power[r-l]);
            if (ret > MOD) ret -= MOD;
            return ret;
        }
        return hash[r];
    }
 
 
    ull connect(ull h1,int l,int r) {
        ull h2 = get(l,r);
        return calcmod(mul(h1,power[r-l])+h2);
    }
 
    int LCP(int l1,int r1,RollingHash& rh,int l2,int r2) {
        int ok = 0,ng = min(r1-l1,r2-l2)+1;
        while (ng-ok > 1) {
            int mid = (ok+ng)/2;
            if (get(l1,l1+mid) == rh.get(l2,l2+mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
};

int main() {
    string s,t,u;
    cin >> s >> t;
    int n = s.size(),m = t.size(),x,ans = 0;
    u = "";
    for (int i = 0;i < m/n+2;++i) u += s;
    x = u.size();
    RollingHash rht(t),rhu(u);
    vector<int> a(x);
    for (int i = 0;i < n;++i) a[i] = rht.LCP(0,m,rhu,i,x);
    vector<bool> b(n,false),used(n,false);

    for (int i = 0;i < n;++i) {
        if (a[i] < m) continue;
        b[i] = true;
    }
    for (int i = 0;i < n;++i) {
        if (!b[i]) used[i] = true;
        if (b[((i-m)%n+n)%n]) continue;
        int ret = 0,f = i;
        while (b[f]) {
            used[f] = true;
            (f += m) %= n;
            ret++;
        }
        ans = max(ans,ret);
    }
    for (int i = 0;i < n;++i) if (!used[i]) {
        cout << "-1" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 39880
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int a[100]={0};
	for(i=1;i<=n;i++)
	{
		int x=i%10;
		int digits=(int)log10(i);
		int y=(int)(i / pow(10, digits));
		int num=y*10+x;
		a[num]++;
	}
	int c=0;
	for(i=1;i<=n;i++)
	{
		int en=i%10;
		int dig=(int)log10(i);
		int st=(int)(i / pow(10, dig));
		int num1=en*10+st;
		c+=a[num1];
	}
	cout<<c;
	return 0;
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define gc getchar()
using namespace std;
typedef long long ll;
const int N=300009;
int n;
ll T[N],sum[N],f[N],g[N],F[N],top,sta[N],Ans[N],ans[N],Ans1[N],Ans2[N];
int read()
{
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
ll Read()
{
	ll x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	ll s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
ll get(int x)
{
	return (ll)x*x-x+2ll*g[x];
}
bool pd(int x,int y,int z)
{
	return get(y)-get(z)>2ll*x*(y-z);
}
ll work()
{
	for (int i=0;i<=n;i++) f[i]=g[i]=0;
	top=0;
	sta[++top]=0;
	for (int i=1;i<=n;i++)
	{
		f[i]=f[i-1];
		while (top>1&&!pd(i,sta[top],sta[top-1])) top--;
		f[i]=max(f[i],g[sta[top]]+(ll)(i-sta[top])*(i-sta[top]+1)/2-sum[i]);
		g[i]=f[i]+sum[i];
		while (top>1&&(get(i)-get(sta[top]))*((ll)sta[top]-sta[top-1])>=(get(sta[top])-get(sta[top-1]))*((ll)i-sta[top])) top--;
		sta[++top]=i;
	}
	return f[n];
}
ll Get(int x)
{
	return (ll)x*x-x+2*f[x]+2*sum[x];
}
bool Pd(int x,int y,int z)
{
	return Get(y)-Get(z)>2ll*x*(y-z);
}
void solve(int l,int r)
{
	if (l==r)
	{
		Ans[l]=max(Ans[l],F[l-1]+f[n-l]+1-T[l]);
		return;
	}
	int mid=(l+r>>1);
	for (int i=l-1;i<mid;i++)
	{
		while (top>1&&(Get(sta[top])-Get(sta[top-1]))*(i-sta[top-1])<=(Get(i)-Get(sta[top-1]))*(sta[top]-sta[top-1])) top--;
		sta[++top]=i;
	}
	for (int i=mid;i<=r;i++)
	{
		while (top>1&&!Pd(i,sta[top],sta[top-1])) top--;
		ans[i]=f[n-i]+F[sta[top]]+sum[sta[top]]+(ll)(i-sta[top])*(i-sta[top]+1)/2-sum[i];
	}
	for (int i=r-1;i>=mid;i--)
		ans[i]=max(ans[i],ans[i+1]);
	for (int i=mid;i<=r;i++) Ans[i]=max(Ans[i],ans[i]);
	top=0;
	solve(l,mid),solve(mid+1,r);
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++)
		T[i]=Read(),sum[i]=sum[i-1]+T[i];
	work();
	top=0;
	for (int i=1;i<=n;i++) F[i]=f[i];
	reverse(T+1,T+n+1);
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+T[i];
	work();
	top=0;
	reverse(T+1,T+n+1);
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+T[i];
	for (int i=1;i<=n;i++) Ans[i]=1-T[i];
	solve(1,n);
	for (int i=1;i<=n;i++) Ans1[i]=Ans[i];
	reverse(T+1,T+n+1);
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+T[i];
	for (int i=1;i<=n;i++) Ans[i]=1-T[i];
	swap(f,F);
	solve(1,n);
	for (int i=1;i<=n;i++) Ans2[i]=Ans[i];
	reverse(T+1,T+n+1);
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+T[i];
	swap(f,F);
	int m=read();
	while (m--)
	{
		int x=read();
		ll y=Read();
		printf("%lld\n",max(max(Ans1[x],Ans2[n-x+1])-y+T[x],F[x-1]+f[n-x]));
	}
	return 0;
}


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


int *D;
int n = 1;


void initTree(int n_) {
    while (n < n_) {
        n *= 2;
    }
    D = new int[2 * n - 1];
    for (int i = 0; i <= 2 * n - 1; ++i) {
        D[i] = 0;
    }
}

void add(int k, int a) {
    k += n - 1;
    D[k] += a;
    while (k > 0) {
        k = (k - 1) / 2;
        D[k] = D[k*2+1] + D[k*2+2];
    }
}

int query(int a, int b, int k, int l, int r) {

    if (r <= a || b <= l) {
        return 0;
    }
    if (a <= l && r <= b) {
        return D[k];
    }
    return query(a, b, 2 * k + 1, l, (l + r) / 2) + query(a, b, 2 * k + 2, (l + r) / 2, r);
}

int findRSQ(int a, int b) {
    return query(a, b, 0, 0, n);
}

int main() {
    int size;
    int q;
    int x, y;
    int operation;
    cin >> size >> q;
    initTree(size);
    for (int i = 0; i < q; ++i) {
        cin >> operation >> x >> y;
        x--;
        if (operation == 0) {
            add(x, y);
        } else {
            cout << findRSQ(x, y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4104
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#define ll long long
using namespace std;
//int main()
//{
//	ll n;
//	scanf("%lld",&n);
//	n=n^(n-1);
//	int k=0;
//	while(n>0)
//	{
//		if(n&1)
//		k++;
//		n>>=1;
//	 } 
//	 printf("%d\n",k);
//	 return 0;
// } 
int main()
{
	int a[3];
	while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF)
	{ 
	sort(a,a+3);
	int n=a[2]-a[1];
	a[0]=n+a[0];int flag=0;
	while(a[0]<a[2])
	{
		
		a[0]=a[0]+2;
		n++;
	}
	if(a[0]==a[2])
	printf("%d\n",n);
	else
	printf("%d\n",n+1);
	}
	return 0;
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int BinarySearch( ll A[], int n, int key ){
    int left = 0;
    int right = n;
    while ( left < right ){
        ll mid = (left + right) / 2;
        if ( A[mid] == key ) return 1;
        else if ( key < A[mid] ) right = mid;
        else left = mid + 1;
    }
    return 0;
}

int main (void) {
    ll N, M, ans;
    ans = 0LL;
    scanf("%lld", &N);
    ll S[N];
    REP(int, i, 0, N) scanf("%lld", &S[i]);
    scanf("%lld", &M);
    ll T[M];
    REP(int, i, 0, M) scanf("%lld", &T[i]);

    REP(int, i, 0, M){
        ans += BinarySearch( S, N, T[i] );
    }

    printf("%lld\n", ans);
    return 0;
}


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

int main(){
    string a;
    vector <string> days = {"SUN","MON","TUE", "WED", "THU", "FRI", "SAT"};
    cin >> a;
    for (int i = 0; i < 7; i++){
        if(a == days[i]){
            int ans = 7 - i;
            cout << ans << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
INPn = [input() for i in range(N)]
M = int(input())
INPm = [input() for i in range(M)]

ans = [0] * N

for i in range(N):
    for k in range(N):
        if INPn[i] == INPn[k]:
            ans[i] += 1
for i in range(N):
    for j in range(M):

        if INPn[i] == INPm[j]:
            ans[i] -= 1

for i in range(N):
    if ans[i] < 0:
        ans[i] = 0
        
mx = max(ans)
print(mx)

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

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll INF = 2e18;
const ld eps = 1e-9;

int main() {
#ifndef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
    int a, b;
    cin >> a >> b;
    cout << a * b << "\n";
}

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

int h, w;
int c_y, c_x, d_y, d_x;
vector<string> v;
int color[1005][1005];
bool check[1005][1005];
bool visit_col[500005];
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};

bool in_range(int y, int x) {
	return 0 <= y && y < h && 0 <= x && x < w;
}

void dfs(int y, int x, int col) {
	color[y][x] = col;
	for (int i = 0; i < 4; i++) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (in_range(ny, nx) && !color[ny][nx] && v[ny][nx] == '.') {
			dfs(ny, nx, col);
		}
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> h >> w;
	cin >> c_y >> c_x >> d_y >> d_x;
	c_y--, c_x--, d_y--, d_x--;
	v.resize(h);
	for (auto &i : v) cin >> i;

	int cnt = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (!color[i][j] && v[i][j] == '.') {
				dfs(i, j, ++cnt);
			}
		}
	}

	priority_queue<tuple<int, int, int>> pq;  // count, y, x
	pq.emplace(0, c_y, c_x);
	// check[c_y][c_x] = true;
	// visit_col[color[c_y][c_x]] = true;

	while (!pq.empty()) {
		int cnt, y, x;
		tie(cnt, y, x) = pq.top();
		cnt = -cnt;
		pq.pop();

		if (color[y][x] == color[d_y][d_x]) {
			cout << cnt << endl;
			return 0;
		}

		if (check[y][x]) continue;
		visit_col[color[y][x]] = true;
		check[y][x] = true;
		// cout << y << ", " << x << " (" << cnt << ")" << endl;

		for (int i = 0; i < 4; i++) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (in_range(ny, nx) && v[ny][nx] == '.' && !check[ny][nx]) {
				// check[ny][nx] = true;
				// cout << "TEST" << endl;
				// cout << y << ", " << x << " (" << cnt << ")" << endl;
				pq.emplace(-cnt, ny, nx);
			}
		}

		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				if (i == 0 && j == 0) continue;
				int ny = y + i;
				int nx = x + j;
				if (in_range(ny, nx) && v[ny][nx] == '.' && !visit_col[color[ny][nx]]) {
					// check[ny][nx] = true;
					// visit_col[color[ny][nx]] = true;
					pq.emplace(-cnt - 1, ny, nx);
				}
			}
		}
	}

	cout << -1 << endl;
}

Measured memory_bytes: 9744
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(Math.abs(a-c)<=d){
      System.out.print("Yes");
      return;
    }
    if(Math.abs(a-b)<=d&&Math.abs(b-c)<=d){
      System.out.print("Yes");
      return;
    }else{
      System.out.print("No");
      return;
    }
    
    
    
  }
  

  
}

Measured memory_bytes: 21716
#include <stdio.h>

int main(void)
{
	int a, b;

		scanf("%d%d", &a, &b);

		if (a >= 13) {
			printf("%d", b);
		}
		else if (a >= 6 && a <= 12) {
			printf("%d", b / 2);
		}
		else if (a <= 5) {
			printf("%d", 0);
		}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int)v.size(); i++)
        os << (i ? " " : "") << v[i];
    return os;
}
/*-------------------------------------------*/

int D;
int c[26];
ll s[365][26];

int last[26];

set<int> st[26];
vector<int> ret;
vector<int> ans;

ll sum = 0, MAX;

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

    srand((unsigned)time(NULL));

    rep(i, 26) st[i].insert(-1);

    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];

    rep(d, D) {
        ll a = -1, mx = -1;
        rep(i, 26) if(chmax(mx, (d - *st[i].rbegin()) * c[i] + s[d][i])) a = i;
        ans.push_back(a);
        st[a].insert(d);
        sum += s[d][a];
        rep(i, 26) sum -= c[i] * (d - *st[i].rbegin());
    }

    MAX = sum;
    ret = ans;

    rep(i, 26) st[i].insert(D);

    while(clock() < CLOCKS_PER_SEC * 1.9) {
        int x = rand() % D;
        ll a = -1, mx = -inf;
        rep(i, 26) if(i != ans[x]) {
            auto it1 = st[i].upper_bound(x);
            auto it2 = st[i].lower_bound(x);
            it2--;
            ll y = s[x][i] + (*it1 - *it2) * (*it1 - *it2 - 1) / 2 * c[i];
            y -= (*it1 - x) * (*it1 - x - 1) / 2 * c[i];
            y -= (x - *it2) * (x - *it2 - 1) / 2 * c[i];
            if(chmax(mx, y)) a = i;
        }
        auto it1 = st[ans[x]].upper_bound(x);
        auto it2 = st[ans[x]].lower_bound(x);
        it2--;
        ll y = s[x][ans[x]] + (*it1 - *it2) * (*it1 - *it2 - 1) / 2 * c[ans[x]];
        y -= (*it1 - x) * (*it1 - x - 1) / 2 * c[ans[x]];
        y -= (x - *it2) * (x - *it2 - 1) / 2 * c[ans[x]];
        if(mx >= y) {
            st[a].insert(x);
            st[ans[x]].erase(x);
            ans[x] = a;
            sum += mx - y;
            if(chmax(MAX, sum)) ret = ans;
        } else if((sum + mx - y) * 81 >= MAX * 80) {
            sum += mx - y;
            st[a].insert(x);
            st[ans[x]].erase(x);
            ans[x] = a;
        }
    }

    rep(i, D) cout << ret[i] + 1 << endl;

    return 0;

    cout << endl;

    sum = 0;
    rep(d, D) {
        int x = ret[d];
        last[x] = d + 1;
        sum += s[d][x];
        rep(i, 26) sum -= (d + 1 - last[i]) * (c[i]);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3772
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

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


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define each(itr,v) for(auto (itr):(v))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int K;
	cin >> K;
	vector<int> D(K);
	REP(i, K) {
		cin >> D[i];
	}
	int i = N;
	while (true) {
		bool flg = true;
        int j=i;
		while (j > 0) {
			int bit = j % 10;
			j /= 10;
			auto result = find(D.begin(), D.end(), bit);
			if (result!=D.end()) flg = false;
		}
		if (flg) {
			cout << i << endl;
			break;
		}
		i++;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll N,M;

typedef struct st{
	ll t,n,m,s;
	st(ll _t,ll _n,ll _m,ll _s):t(_t),n(_n),m(_m),s(_s){}
}ST;

ll cnt[10001][800];

int main(){
	while(cin >> N >> M && N+M){
		rep(i,10001)rep(j,800)cnt[i][j] = 0;
		ll r;
		cin >> r;
		rep(i,r){
			ll t,n,m,s;
			cin >> t >> n >> m >> s;
			m--;
			if(s)cnt[m][t-540]++;
			else cnt[m][t-540]--;
		}
		rep(i,M)rep(j,800-1)cnt[i][j+1] += cnt[i][j];
		// FOR(j,775-540,880- 540)cout << cnt[0][j] << " ";
		// cout << endl;
		ll q;
		cin >> q;
		rep(i,q){
			ll ts,te,m;
			ll ans = 0;
			cin >> ts >> te >> m;
			ts -= 540;
			te -= 540;
			m--;
			FOR(j,ts,te){
				if(cnt[m][j] != 0)ans++;
			}
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 65584
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double R;

// Combination Table
ll C[51][51]; // C[n][k] -> nCk

void comb_table(int N){
  for(int i=0;i<=N;++i){
    for(int j=0;j<=i;++j){
      if(j==0 or j==i){
	C[i][j]=1LL;
      }else{
	C[i][j]=(C[i-1][j-1]+C[i-1][j]);
      }
    }
  }
}

int main(void){
  int N,A,B;
  cin >> N >> A >> B;
  
  
  const int NMAX=50;
  ll v[NMAX];
  
  for(int i=0;i<N;++i){
    cin >> v[i];
  }
  
  comb_table(N);
  sort(v,v+N);
  reverse(v,v+N);
  
  R max_average=0.0;
  for(int i=0;i<A;++i){
    max_average+=v[i];
  }
  max_average/=A;
  
  int a_th_val_num=0,a_th_val_pos=0;
  for(int i=0;i<N;++i){
    if(v[i]==v[A-1]){
      a_th_val_num++;
      if(i<A){
	a_th_val_pos++;
      }
    }
  }
  
  ll cnt=0LL;
  if(a_th_val_pos==A){
    for(a_th_val_pos=A;a_th_val_pos<=B;++a_th_val_pos){
      cnt+=C[a_th_val_num][a_th_val_pos];
    }
  }else{
    cnt+=C[a_th_val_num][a_th_val_pos];
  }
  
  cout.precision(20);
  cout << fixed << max_average << endl;
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
 using namespace std;  
ll t,n,c,c3,sum,m,mn,k,r,avg;
std::vector<int >v,v2;
std::map<int, int> mp;
bool isPrime(int x)
{
for (int i=2;i*i<=x;i++)
if (x%i==0)
return false;
return true;
}
 
int main(void)
 
{
string s;
int a=0,b=0;
cin>>s;
for (int i =0;i<s.length();i++)
{
    if (s[i]=='A')a++;
    else b++;
}
if (a==3 || b==3)cout<<"No";
else cout<<"Yes";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}


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

    Int n, m, a, b;
    vector<Int> v[100002];
    priority_queue<Int> pq;
    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        v[a].push_back(b);
    }
    Int sum = 0;
    for(Int i=1; i<=m; i++){
        for(Int j=0; j<v[i].size(); j++){
            pq.push(v[i][j]);
        }
        if(!pq.empty()){
            sum += pq.top();
            pq.pop();
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5632
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

l = [0] * N

for i in range(K):
    for j in range(d[i]):
        l[A[i][j]-1] += 1

print(l.count(0))

Measured memory_bytes: 67840
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 3e5;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int INF = 0;
const int LG = 21;

void solve()
{
	int n;
	cin >> n;
	map<int, int> mp;
	while(n % 2 == 0)
	{
		mp[2]++;
		n /= 2;
	}
	for(int i = 3; i * i <= n; i++)
	{
		while(n % i == 0)
		{
			mp[i]++;
			n /= i;
		}
	}
	if(n > 1)
	{
		mp[n]++;
	}
	int ret = 0;
	for(auto x : mp)
	{
		int s = 1;
		int e = x.second;
		int ans = 0;
		while(s <= e)
		{
			int mid = s + e >> 1;
			int temp = ((1 + mid) * mid) / 2;
			if(temp <= x.second)
			{
				ans = mid;
				s = mid + 1;
			}
			else
			{
				e = mid - 1;
			}
		}
		ret += ans;
	}
	cout << ret << endl;
}
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
//整数ｎに対して、ｎを何回２で割り切れるかを返す
int howManyTimes (int n) {
  int result = 0;
  int i = 0;
  while (n % 2 == 0) {
    n /= 2;
    result++;
  }
  
  return result;
}

int main () {
  int n; cin >> n;
  
  int ans = 1;
  int maxTime = 0;
  for (int i = 1; i < n +1; i++) {
    if (howManyTimes (i) > maxTime) {
      maxTime = howManyTimes (i);
      ans = i;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))

Bs = [0] * (N+1)
for i in reversed(range(1, N+1)):
    parity = sum(Bs[i::i]) % 2
    if parity != As[i-1]:
        Bs[i] = 1

anss = [i for i in range(1, N+1) if Bs[i]]

print(len(anss))
if anss:
    print(' '.join(map(str, anss)))


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

int main(){
    int a,b,c;

    cin>>a>>b>>c;
    if(min(a,b)<c && c<max(a,b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

int main()
{
    int N,K;
    long mean =0;
    long long cost1 = 0;
    long long cost2 = 0;
    
    cin >> N;
    vector<int> x(N,0);
    for(int i = 0;i < N;i++){
        cin >> x[i];
        mean += x[i];
    }
    mean/=N;
    
    for(int i = 0;i < N;i++){
        cost1 += (long long)((x[i]-mean)*(x[i]-mean));
        cost2 += (long long)((x[i]-mean-1)*(x[i]-mean-1));
    }
    
    cout << min(cost1,cost2) << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int v, e;

int main() {
    cin >> v >> e;

    // Adjacency matrix
    vector<vector<ll>> g(v);
    rep(i, v) g[i].resize(v);
    // initialization
    rep(i, v) {
        rep(j, v) {
            if (i == j) g[i][j] = 0;
            else g[i][j] = INF;
        }
    }

    rep(i, e) {
        int s, t; ll d;
        cin >> s >> t >> d;
        g[s][t] = d;
    }

    // Warshall-Floyd
    rep(k, v) {
        rep(i, v) {
            rep(j, v) {
                if (g[i][k] != INF && g[k][j] != INF) {
                    g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
                }
            }
        }
    }

    // Check if negative cycle exists
    rep(i, v) {
        if (g[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    rep(i, v) {
        rep(j, v) {
            ll c = g[i][j];
            if (c == INF) cout << "INF";
            else cout << c;
            if (j < v-1) cout << ' ';
        }
        cout << endl;
    }
}



Measured memory_bytes: 3188
N, M = map(int, input().split())

H = list(map(int, input().split()))

good = [True] * N

for _ in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  if H[A] >= H[B]:
    good[B] = False
  if H[A] <= H[B]:
    good[A] = False
print(sum(good))

Measured memory_bytes: 20084
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int func(int i,int j){
	return (int)(i*(100+j)/100.0);
}
int main(){
	int a,b,c;
	while(cin>>a>>b>>c,a+b+c){
		int ma=-1;
		loop(i,1,c+1)loop(j,1,c+1)if(func(i,a)+func(j,a)==c)ma=max(ma,func(i,b)+func(j,b));
		cout<<ma<<endl;
	}
}

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

int main() {
  string s, c[4];
  int a[4], n1, n2, c1, c2;
  cin >> s;
  for(int i = 0; i < 4; i++) {
    c[i] = s[i];
    a[i] = stoi(c[i]);
  }
  n1 = a[0]*10 + a[1];
  n2 = a[2]*10 + a[3];
  if(n1 != 0 && n1 < 13) c1 = 0;
  else c1 = 1;
  if(n2 != 0 && n2 < 13) c2 = 0;
  else c2 = 1;
  if(c1 == 1 && c2 == 1) cout << "NA";
  else if(c1 == 1) cout << "YYMM";
  else if(c2 == 1) cout << "MMYY";
  else cout << "AMBIGUOUS";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,a,b;
  cin >> n >> b >> a;
  if(a+b<=n+1&&a*b>=n) {
    for(ll i=a;i;i--) {
      if(i!=a) cout << " ";
      cout << i;
    }
    if(b!=1) {
      ll s=(n-a)/(b-1);
      ll m=(n-a)%(b-1);
      ll pre=a;
      while(--b) {
        ll cur=pre+s;
        if(m-->0) cur++;
        for(ll i=cur;i>pre;i--) {
          cout << " " << i;
        }
        pre=cur;
      }
    }
    cout << endl;
  }
  else cout << -1 << endl;
}

Measured memory_bytes: 2176
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    s = input()
    ans = 0

    left, right = 0, len(s) - 1
    while left < right:
        l, r = s[left], s[right]
        if l == r:
            left += 1
            right -= 1
        elif l != "x" and r != "x":
            ans = -1
            break
        elif l == "x" and r != "x":
            ans += 1
            left += 1
        elif l != "x" and r == "x":
            ans += 1
            right -= 1

    print(ans)


if __name__ == '__main__':
    main()


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

#define NIL -1

struct node {
	int p, l, r;
};
node T[25];

void preparse(int u) {
	if (u == NIL)
		return;
	cout << " " << u;
	preparse(T[u].l);
	preparse(T[u].r);
}

void inparse(int u) {
	if (u == NIL)
		return;
	inparse(T[u].l);
	cout << " " << u;
	inparse(T[u].r);
}

void postparse(int u) {
	if (u == NIL)
		return;
	postparse(T[u].l);
	postparse(T[u].r);
	cout << " " << u;
}

void initnode(int n) {
	for (int i = 0; i < n; i++)
		T[i] = { NIL, NIL, NIL };
}

void regnode(int id, int l, int r) {
	T[id].l = l;
	T[l].p = id;
	T[id].r = r;
	T[r].p = id;
}

int main() {
	int n;
	cin >> n;
	initnode(n);
	for (int i = 0; i < n; i++) {
		int id, l, r;
		cin >> id >> l >> r;
		regnode(id, l, r);
	}
	int r;
	for (int i = 0;; i++)
		if (T[i].p == NIL) {
			r = i;
			break;
		}
	cout << "Preorder" << endl;
	preparse(r);
	cout << endl << "Inorder" << endl;
	inparse(r);
	cout << endl << "Postorder" << endl;
	postparse(r);
	cout << endl;
	return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
	ll n, m;
	cin >> n >> m;
	vvll graph(n);
	rep(i, 0, m){
		ll a, b;
		cin >> a >> b;
		a--; b--;
		graph.at(a).push_back(b);
		graph.at(b).push_back(a);
	}

	vll ans(n, -1);
	queue<ll> que;
	ans.at(0) = 0;
	que.push(0);
	while(que.size()){
		ll v = que.front();
		que.pop();
		vrep(nv, graph.at(v)){
			if(ans.at(nv) == -1){
				ans.at(nv) = v;
				que.push(nv);
			}
		}
	}

	bl check = true;
	vrep(i, ans) if(i == -1) check = false;
	if(check){
		cout << "Yes" << endl;
		rep(i, 1, n) cout << ans.at(i) + 1 << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 13032
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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 double PI = acos(-1.0);
// cout << fixed << setprecision(14);

bool dp[5005][5005];
bool dp1[5005][5005];

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;
	int A[N];
	int sum = 0;
	rep(i,N){
		cin >> A[i];
		sum += A[i];
	}
	if(sum < K){
		cout << N << endl;
		return 0;
	}
	sort(A, A+N);
	dp[0][0] = 1;
	dp1[N][0] = 1;
	rep(i,N){
		rep(j,K+1){
			dp[i+1][j] = (dp[i+1][j] || dp[i][j]);
			if(A[i] >= K) continue;
			else{
				if(j-A[i] >= 0){
					dp[i+1][j] = (dp[i+1][j] || dp[i][j-A[i]]);
				}
			}
		}
	}
	for(int i=N-1;i>=0;i--){
		rep(j,K+1){
			dp1[i][j] = (dp1[i][j] || dp1[i+1][j]);
			if(A[i] >= K) continue;
			else{
				if(j-A[i]>=0)
				dp1[i][j] = (dp1[i][j] || dp1[i+1][j-A[i]]);
			}
		}
	}
	int left = -1, right = N-1;
	int mid = (left+right)/2; 
	while(right-left>1){
		mid = (left+right)/2;
		bool ok = false;
		if(A[mid] >= K) ok = true;
		if(!ok){
			for(int j=K-1;j>=K-A[mid];j--){
				for(int k=0;k<=j;k++){
					if(dp[mid][k] && dp1[mid+1][j-k]){
						ok = true;
						break;
					}
				}
				if(ok) break;
			}
		}
		if(ok) right = mid;
		else left = mid;
	}
	cout << right << endl;
}

Measured memory_bytes: 49280