akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, R;
    cin >> N >> R;

    ll ans = R;

    if (N < 10) {
        ans = R + (100 * (10 - N));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N,M,Q;
int ans = 0;
vint A(101),B(101),C(101),D(101);

void dfs(vector<int> v,int cnt,int las){
  if(cnt == N){
    int tmp = 0;
    rep(i,0,Q){
      if(v[B[i]] - v[A[i]] == C[i]) tmp += D[i];
    }
    ans = max(ans,tmp);
  }
  else{
    rep(i,las,M+1){
      vint nw = v;
      nw.push_back(i);
      dfs(nw,cnt+1,i);
    }
  }
}

signed main(){
  cin >> N >> M >> Q;
  rep(i,0,Q){
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    A[i]--;B[i]--;
  }
  vint v;
  dfs(v,0,1);
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void) {
	int n,max,min,i;
	long sum;
	max = -1000000;
	min = (-1)*max;
	scanf("%d",&n);
	for(i=n,sum=0;i;i--){
		scanf("%d",&n);
		sum+=n;
		if(n<min){min=n;}
		if(n>max){max=n;}
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int m,n,x;

int main(){
	while(cin>>m>>n&&m){
		int a=0;
		rep(i,m){
			int s=0;
			rep(j,n)cin>>x,s+=x;
			a=max(a,s);
		}
		cout<<a<<endl;
	}
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if (h >= k) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
import itertools
 
white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))
 
white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.product(white_num_list, repeat = len(str(N))))
 
num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
    
num_list = sorted(num_list)
 
def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    placeholder = str(min(white_num_list)) * (len(str(N)) + 1)
    if placeholder[0] == '0':
        white_num_list.remove(0)
        placeholder = str(min(white_num_list)) + placeholder[1:]
    return int(placeholder)
      
print(price(N, num_list, white_num_list))

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = int;
using namespace std;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n, m;
	cin >> n >> m;
	Int a[112], as = 0;
	RC(i, n){
		cin >> a[i];
		as += a[i];
	}
	Int threshold = (as - 1) / (m * 4);
	Int count = 0;
	RC(i, n){
		if(a[i] > threshold) ++count;
	}
	cout << (count >= m ? "Yes" : "No") << endl;
}


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

int a[2222];
int main() {
	long n, k, t = 0, b = 0, p = 1e9 + 7;
	cin >> n >> k;
	set<int> s;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
		for (int j = 0; j < i; j++)
			if (a[i] < a[j]) t++;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] < a[j]) b++;
	cout << (t * k + (k - 1)*k / 2 % p*b) % p << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, num;
int f[1000];

int main(){
	while (cin >> n&&n){
		fill(f, f + 1000, 0);
		REP(i, n){
			cin >> num;
			f[num] = 1;
		}
		int co[2];
		co[0] = n; co[1] = n;
		int x = 1;
		while (co[0] != 0 && co[1] != 0){
			int max = 0;
			bool g = 0;
			FOR(j, 1, 2 * n + 1){
				if (f[j] == x&&max < j){
					f[j] = -1;
					x = !x;
					co[x]--;
					max = j;
					g = 1;
				}
				if (co[0] == 0 || co[1] == 0)break;
			}
			x = !x;
		}
		cout << co[1] << endl;
		cout << co[0] << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin >>n;
	for(int i=0; i<n; i++){
		double a[3],b[3],dis;
		cin >>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2];
		dis = sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]));
		if(dis>a[2]+b[2]){cout <<"0"<<endl;}
		else if(dis<abs(a[2]-b[2]) && a[2]>b[2]){cout <<"2"<<endl;}
		else if(dis<abs(a[2]-b[2]) && a[2]<b[2]){cout <<"-2"<<endl;}
		else{cout <<"1"<<endl;}
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()

def func(x, y):
    i = 0
    j = 0
    cnt = 0
    s = [0 for i in range(n)]
    while j < n and i < n:
        if y[j] > x[i]:
            cnt += 1
            i += 1
        else:
            s[j] = cnt
            j += 1
    if i == n:
        for k in range(j,n):
            s[k] = cnt
    return s

s1 = func(a, b)
for i in range(1, n):
    s1[i] += s1[i-1]
s2 = func(b, c)
cnt = 0
for i in range(n):
    if s2[i] != 0:
        cnt += s1[s2[i]-1]

print(cnt)

Measured memory_bytes: 23420
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define pb push_back
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fs(s) for(ll i=0;s[i]!='\0';i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define gcd(a,b) __gcd(a,b)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define c1(x) __builtin_popcountll(x)
#define setprs(x) cout << fixed << setprecision(x);
#define endl '\n'
const ll mod=1e9 + 7;
const ll sz=1e6 + 100;
const double PI =3.14159265;
ll power(ll a, ll b, ll m = mod){if(b==0)return 1;else if(b==1)return a%m;else{ll t=power(a,b>>1,m);t=((t%m)*(t%m))%m;if(b&1)return ((t%m)*(a%m))%m;else return t%m;}}
 
//--------------------------------------------------------

#define int ll

void solve()
{
    int n, k;
    int h[sz];
    cin >> n >> k;
    f(i,0,n)cin >> h[i];
    int cost[sz]={0};
    // fr(i,n-1, n-k){
    //     cost[i] = abs(h[n-1] - h[i]);
    // }
    f(i,0,n)cost[i] = mod;
    cost[0] = 0;
    f(i, 0, n){
        f(j,1,k+1){
            if(i+j < n){
                cost[i+j] = min(cost[i+j], abs(h[i+j] - h[i]) + cost[i]);
            }
        }
    }
    cout << cost[n-1];
} 
 
int32_t main()
{
    fastio
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}

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

int main(){
    string X;
    cin>>X;
    stack<char> S;
    for(int i=0;i<X.size();i++){
        if(X[i]=='S') S.push('S');
        else{
            if(S.empty()==1||S.top()=='T') S.push('T');
            else S.pop();
        }
    }
    cout<<S.size()<<endl;
    
}

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

#define LL long long

int K;
LL answer = 0;

int gcd(int a, int b, int c) {
  int gcd_value = 0;
  int max_value = max(a, max(b, c));

  for(int i = 1; i <= sqrt(max_value); i++) {
    if(a % i == 0 && b % i == 0 && c % i == 0) gcd_value = max(gcd_value, i);
    if(a % (max_value / i) == 0 && b % (max_value / i) == 0 && c % (max_value / i) == 0) gcd_value = max(gcd_value, max_value / i);
  }

  return gcd_value;
}

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

  cin >> K;

  for(int i = 1; i <= K; i++) {
    for(int j = 1; j <= K; j++) {
      for(int k = 1; k <= K; k++) {
        answer += gcd(i, j, k);
      }
    }
  }

  cout << answer << "\n";

  return 0;
}

Measured memory_bytes: 3696
N = int(raw_input())
a = map(int,raw_input().split(" "))
b = [0,0,0]

for aa in a:
	if aa % 4 == 0:
		b[2] += 1
	elif aa % 2 == 0:
		b[1] += 1
	else:
		b[0] += 1

if (b[1] == 0 and b[2] + 1 >= b[0]) or (b[1] != 0 and b[2] >= b[0]):
	print "Yes"
else:
	print "No"


Measured memory_bytes: 11296
def find_sum_of_digits(n):
    sum = 0
    while (n > 0):
        sum += n % 10
        n //= 10
    return sum

N, A, B = map(int, input().split())
u = 0
for i in range(N+1):
    # num = sum(map(int, list(str(i))))
    num = find_sum_of_digits(i)
    if num >= A and num <= B:
        u += i
print(u)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first 
#define se second
#define pi pair<ll,ll> 
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int n;
int main(){ 
  #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int s,w;
  cin>>s>>w;
  if(s<=w)
  	cout<<"unsafe"<<endl;
  else
  	cout<<"safe"<<endl;
}

Measured memory_bytes: 3652
// problem: "https://atcoder.jp/contests/abc148/tasks/abc148_b"

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string s,t;
    int N;
    cin>>N;
    cin>>s>>t;

    int i,k;
    i = k = 0;
    string n;
    while(i < N)
    {
        n.append(s.substr(i,1));
        k++;

        n.append(t.substr(i,1));
        k++;

        i++;
    }

    cout<<n;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main(){
  int n,k;cin>>n>>k;
  if(n==1&&k==0){
    cout<<"0 0 1 1"<<endl;exit(0);
  }
  else if(n==1&&k==1){
    cout<<-1<<endl;exit(0);
  }
  if(k>=(1<<n)){
    cout<<-1<<endl;exit(0);
  }
    cout<<k<<" ";
  for(int i=(1<<n)-1;i>=0;--i){
    if(i==k)continue;
    cout<<i<<" ";
  }
  cout<<k<<" ";
  rep(i,(1<<n)){
    if(i==k)continue;
    cout<<i<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 1792
N,M = list(map(int,input().split()))
#隣接リスト
ad = {}
for n in range(N):
    ad[n+1]=[]

for m in range(M):
    a,b = list(map(int,input().split()))
    ad[a].append(b)
    ad[b].append(a)
    
from collections import deque
    
color = {}
for n in range(N):
    color[n+1] = -1

depth = {}
for n in range(N):
    depth[n+1] = -1
    
group = {}
# for n in range(N):
#     group[n+1] = -1
    
group_= 0
for p in range(1,N+1):
    if color[p] != -1: 
        continue
    elif color[p] == -1: 
        start = p
        color[start] = 0
        que = deque([start])
        visit = deque([])
        group_+=1
        group[group_] = [start]

    depth[start] = 0
    while len(que) > 0:
        start = que[0]
#         print(start,que)
        for v in ad[start]:
#             print(v,color[v])
            if color[v] == -1:
                que.append(v)
                color[v] = 0
                depth[v] = depth[start]+1
                group[group_].append(v)
                
        color[start] = 1
        visit.append(que.popleft())

ans=0
for g in group.keys():
    if len(group[g]) > ans:
        ans=len(group[g])
print(ans)

Measured memory_bytes: 168644
#include <stdio.h>
typedef struct pair{
	double x,y;
}pair;
double abs(double a){
	if(a<0) return -a;
	return a;
}

double naiseki(pair A,pair B,pair C,pair D){
	pair a,b;
	a.x=B.x-A.x;
	a.y=B.y-A.y;
	b.x=D.x-C.x;
	b.y=D.y-C.y;
	return a.x*b.x+a.y*b.y;
}
int main(){
	pair A,B,C,D;
	while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y)){
		if(naiseki(A,B,C,D)==0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<double> v;
    for(int i = 0; i < n; i++){
        double p;   cin >> p;
        v.push_back((p+1)/2.0);
    }
    double tmp = 0;
    for(int i = 0; i < k; i++){
        tmp += v[i];
    }
    double ret = tmp;
    for(int i = k; i < n; i++){
        tmp -= v[i-k];
        tmp += v[i];
        ret = max(ret, tmp);
    }
    cout << fixed << setprecision(12) << ret << endl;
    return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<deque>
using namespace std;

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

int main(){
  deque<char> dq;
  string S;cin >> S;
  rep(i, S.size())dq.push_back(S[i]);
  int Q;cin >> Q;
  int count = 0;
  for(int i = 0;i < Q;++i){
    int t;cin >> t;
    if(t == 1){
      count++;
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(f == ((count) % 2) + 1)
        dq.push_front(c);
      else
        dq.push_back(c);
    }
  }
  if(count % 2)
    for(int i = dq.size() - 1;i >= 0;--i)
      cout << dq[i];
  else
    for(int i = 0;i < dq.size();++i)
      cout << dq[i];
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll a(ll L) {  // a(i) : レベルiバーガーの厚さ
    if(L == 0) {
        return 1;
    }
    return 2*a(L-1) + 3;
}

ll f(ll L, ll x) {  // レベルLバーガーの下からx層に含まれるパティの枚数
    if(L == 0) {
        return 1;
    }
    else if(x == 1) {
        return 0;
    }
    else if(x <= 1 + a(L-1)) {
        return f(L-1, x-1);
    }
    else if(x == 2 + a(L-1)) {
        return f(L-1, a(L-1)) + 1;
    }
    else if(x <= 2 + 2*a(L-1)) {
        return f(L-1, x - (2 + a(L-1))) + f(L-1, a(L-1)) + 1;
    }
    else if(x == 3 + 2*a(L-1)) {
        return 2*f(L-1, a(L-1)) + 1;
    }
}
 
int main() {
    ll n, x;
    cin >> n >> x;
    
    out(f(n, x));
    re0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N,W;
long long w[110],v[110];
long long dp[110][100100];
const long long INF=1LL << 60;
int main(){
  cin >> N >> W;
  for(int i=0;i<N;i++) cin >> w[i] >> v[i];
  for(int i=0;i<110;i++) for(int j=0;j<100100;j++) dp[i][j]=0;
  for(int i=v[0];i>0;i--) dp[0][i]=w[0];

  for(int i=1;i<N;i++){
    for(int j=1;j<100100;j++){
      dp[i][j]=dp[i-1][j];
      if(j<=v[i]) dp[i][j]=min(dp[i][j]==0?INF:dp[i][j],w[i]);
      if(j-v[i]>=0 && dp[i-1][j-v[i]]!=0) dp[i][j]=min(dp[i][j]==0?INF:dp[i][j],dp[i-1][j-v[i]]+w[i]);
    }
  }

  long long res=0;
  for(int i=0;i<=N;i++){
    for(long long j=0;j<100100;j++){
      if(dp[i][j]>W || dp[i][j]==0) continue;
      res=max(res,j);
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 86272
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define MAXN ()
#define INF (0x7fffffff)
#define LL long long
#define pii pair<int, int>
using namespace std;
inline int ws(int x)
{
	int re = 0;
	while (x)
	{
		re += x % 10;
		x /= 10;
	}
	return re;
}
int main()
{
	int ans = INF, n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		ans = min(ans, ws(i) + ws(n - i));
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    map<int, int> cnt;
    forn(i, n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    int mx = *max_element(all(a));
    int mn = 1000;
    forn(i, mx + 1){
        int d = max(i, mx - i);
        cnt[d]--;
        mn = min(mn, d + 1);
    }
    forn(i, mx + 1){
        if (cnt[i] < 0){
            cout << "Impossible\n";
            return;
        }
    }
    forn(i, mn){
        if (cnt[i] > 0){
            cout << "Impossible\n";
            return;
        }
    }
    cout << "Possible\n";
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>str>>b;
	if(str=="+"){cout<<a+b;}
	else{cout<<a-b;}




	cout<<endl;
} 


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

using namespace std;

int main()
{
    int cols;
    cin >> cols;

    vector<vector<int>> mat(2, vector<int>(cols));
    for (auto &row : mat) {
        for (auto &num : row) {
            cin >> num;
        }
    }

    for (size_t i = 0; i < mat.size(); i += 1) {
        for (size_t j = 0; j < mat[i].size(); j += 1) {
            auto to_add = 0;
            if (i > 0) {
                to_add = max(to_add, mat[i - 1][j]);
            }
            if (j > 0) {
                to_add = max(to_add, mat[i][j - 1]);
            }
            mat[i][j] += to_add;
        }
    }

    cout << mat.back().back() << "\n";
    return 0;
}


Measured memory_bytes: 256
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

int n, k;
double ans = 0;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        if (i >= k) ans += 1.0 / n;
        else
        {
            int tmp = i, cnt = 0;
            while (tmp < k) tmp *= 2, cnt++;
            ans += 1.0 / n * pow(0.5, (double)cnt);
        }
    }
    printf("%.9f\n", ans);
    return 0;
}

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

int main(void){
  int a, b;
  cin >> a >> b;
  if(a > 9 || b > 9){
    cout << "-1" << endl;
    return 0;
  }
  cout << a*b << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<ll> A(n);
    for(i=0;i<n;i++){
        cin >> A[i];
    }
    ll ret = 0;
    for(i=0;i<=62;i++){
        ll cnt1=0,cnt0=0;
        for(j=0;j<n;j++){
            if((A[j]>>i)%2==0)cnt0++;
            else cnt1++;
        }
        ret += (((cnt1*cnt0)%MOD)*((1ll<<i)%MOD))%MOD;
        ret%=MOD;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    string S = in<string>();
    int maximum = 0;
    int value = 0;
    REP(i,N){
        value += S[i] == 'D' ? -1 : 1;
        maximum = max (maximum , value);
    }
    cout << maximum << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
double pi = 3.141592653589793;
ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    string order;
    string word;
    set<string> s;
    for (int i = 0; i < N; i++) {
        cin >> order >> word;
        if (order == "insert") {
            s.insert(word);
        } else {
            int c = s.count(word);
            if (c == 1) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
}


Measured memory_bytes: 32580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    cin >> n >> w;
    ll wt[n],val[n];
    for(ll i = 0;i < n;i++){
    	cin >> wt[i] >> val[i];
    }
    ll dp[100001][n];
    for(ll i = 0;i < n;i++){
    	dp[0][i] = 0;
    }
    for(ll i = 1;i < 100001;i++){
    	if(i == val[0]){
    		dp[val[0]][0] = wt[0];
    	}
    	else{
    		dp[i][0] = LONG_MAX;
    	}
    }
    for(ll i = 1;i < 100001;i++){
    	for(ll j = 1;j < n;j++){
    		dp[i][j] = dp[i][j-1];
    		if(i >= val[j]){
    			if(dp[i-val[j]][j-1] != LONG_MAX){
    				dp[i][j] = min(dp[i][j],dp[i-val[j]][j-1]+wt[j]);
    			}
    		}
    	}
    }
    ll ans = 0;
    for(ll i = 0;i < 100001;i++){
    	if(dp[i][n-1] <= w){
    		ans = i;
    	}
    }
    cout << ans << endl;
}


Measured memory_bytes: 78336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;

int main(){
    int a,b; cin >> a>>b;
    int sasiguti = 1;
    int ans = 0;

    while (sasiguti < b) {
        sasiguti+=(a-1);
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final int principal = 100000;
		final float interest = 0.05f;
		int debtBal = principal;
		
		Scanner scan = new Scanner(System.in);
		int week = scan.nextInt();
		
		for(int i = 1; i <= week; i++) {
			debtBal += debtBal * interest;
			debtBal = (int)Math.ceil((double)debtBal / 1000);
			debtBal *= 1000;
		}
		
		System.out.println(debtBal);
	}
}

Measured memory_bytes: 26128
from collections import deque

di = [-1,0,1,0]
dj = [0,-1,0,1]

H,W = map(int, input().split())
si,sj = map(int, input().split())
ti,tj = map(int, input().split())
si -= 1
sj -= 1
ti -= 1
tj -=1
s = list()
for i in range(H):
  s.append(input())

inf = 10**9
dist = [[inf] * W for i in range(H)]
q = deque()
q.appendleft([si,sj])
dist[si][sj] = 0
while(len(q) > 0):
  tmp = q.popleft()
  i = tmp[0]
  j = tmp[1]
  d = dist[i][j]
  for v in range(4):
    ni = i + di[v]
    nj = j + dj[v]
    if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
      continue
    if s[ni][nj] == "#":
      continue
    if dist[ni][nj] <= d:
      continue
    dist[ni][nj] = d
    q.appendleft([ni,nj])
  for ei in range(-2, 3, 1):
    for ej in range(-2, 3, 1):
      ni = i + ei
      nj = j + ej
      if (ni < 0) or (ni >= H) or (nj < 0) or (nj >= W):
        continue
      if dist[ni][nj] <= d+1:
        continue
      if s[ni][nj] == "#":
        continue
      dist[ni][nj] = d+1
      q.append([ni,nj])

ans = dist[ti][tj]
if ans == inf:
  ans = -1
print(ans)

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll Calc(ll a, ll b){
  if(a%b == 0)return 2*a-b;
  return Calc(b,a%b) + (a/b)*2*b;
}

int main(){
  ll n, x; cin >> n >> x;
  cout << n + Calc(x,n-x) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int H;
	int W = 301;
	do {
		if (W <= 300) {
			for (int h = 1; h <= H; h++) {
				for (int w = 1; w <= W; w++) {
					if (!((h+w)%2)) {
						printf("#");
					} else {
						printf(".");
					}
					
				}
				printf("\n");
			}
			printf("\n");
		}
		scanf("%d %d", &H, &W);
	} while (H > 0 && W > 0);
	
	return 0;
}

Measured memory_bytes: 2592
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<int, int> P;


ll gcd(ll a, ll b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

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

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

int main()
{
	
	ll A, B;
	cin >> A >> B;

	cout << lcm(A, B) << endl;

	return 0;
}

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

int main()
{
    int i;
    int alphabet[26] = {0};
    char sentence[1201];
    char * onechar;
    
    while(fgets(sentence, sizeof(sentence), stdin) != NULL){
        onechar = &sentence[0];
        for(i = 0; ; i++){
            if(onechar[i] == '\0') break;
            else if(isupper(onechar[i])) {
                //tolower(onechar[i]);
                onechar[i] += 32;
                //printf("%c\n", onechar[i]);    
            }
        }

        for(i = 0; ; i++){
            if(onechar[i] == '\0') break;
            else if(isalpha(onechar[i])){
                alphabet[onechar[i] - 97]++;
            }
            //printf("%c", onechar[i]);
        }
        fflush(stdin);
    }
    for(i = 0; i < 26; i++){
       printf("%c : %d\n", i + 97, alphabet[i]);
    }
    
    return 0;
}


Measured memory_bytes: 2096
#include <cstdio>

using namespace std;

int main()
{
	double xs[4],ys[4],a,t;
	int p,np,ans;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xs[0],&ys[0],&xs[1],&ys[1],&xs[2],&ys[2],&xs[3],&ys[3])!=EOF){
		ans=a=t=0;
		for(int i=0;i<4;i++){
			p=(i+3)%4;
			np=(i+1)%4;
			t=(xs[i]-xs[p])*(ys[np]-ys[i])-(ys[i]-ys[p])*(xs[np]-xs[i]);
			if(a*t<0){
				ans=1;
				break;
			}
			else{
				a=t;
			}
		}
		if(ans==0){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n; cin >> n;
    VI A(n), B;

    REP(i, n) cin >> A.at(i);
    
    int c = 1;
    for (auto a:A)
    {
        if (c>0) B.push_back(a);
        else B.insert(B.begin(), a);
        c *= -1;
    }

    if (n%2==1) reverse(ALL(B));
    PRINT(B);cout <<endl;
  
    return 0;
}



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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;
        ll sum = 0, pre = 0, ans = LLONG_MAX;
        for (auto x: a) sum += x;
        a.pop_back();
        for (auto x: a) {
                pre += x;
                ll suf = sum - pre;
                ans = min(ans, abs(pre - suf));
        }

        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int inf = 1e9;
using vi = vector<int>;

int main() {
  int n; cin >> n;

  vi hh{-inf, -inf, 0};
  vi dp{ inf,  inf, 0};

  cin >> hh.at(2); n--;
  rep(i, n) {
    hh.at(0) = hh.at(1);
    hh.at(1) = hh.at(2);
    dp.at(0) = dp.at(1);
    dp.at(1) = dp.at(2);
    cin >> hh.at(2);
    
    dp.at(2) = min(
      dp.at(1) + abs(hh.at(1) - hh.at(2)),
      dp.at(0) + abs(hh.at(0) - hh.at(2))
    );
  }

  cout << dp.at(2) << endl;
}


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

int main() {
    int n, k;
    int maxi = 1000000000;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    for (int i = 0; i < n - k + 1; i++) {
        maxi = min(maxi, h.at(i + k - 1) - h.at(i));
    }
    cout << maxi << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
int A[100010];
string s;
vector<int>a,b;
int main(){
    cin>>s;
    int i,x;
    for(i=0;i<s.size();i++){
        if(s[i]=='L') a.push_back(i);
        else b.push_back(i);
    }
    for(i=0;i<s.size();i++){
        if(s[i]=='R'){
             x=lower_bound(a.begin(),a.end(),i)-a.begin();
             x=a[x];
             if((x-i)%2) A[x-1]++;
             else A[x]++;
        }
        else{
             x=lower_bound(b.begin(),b.end(),i)-b.begin()-1;
             x=b[x];
             if((x-i)%2) A[x+1]++;
             else A[x]++;
        }

    }
    cout<<A[0];
    for(i=1;i<s.size();i++) cout<<" "<<A[i];
    cout<<endl;
}


Measured memory_bytes: 1532
N, Q = map(int, input().split())
S = input()
queries = [tuple(map(int, input().split())) for _ in range(Q)]
counters = [0 for _ in range(N + 1)]
for idx, s in enumerate(S):
    counters[idx + 1] = counters[idx] + (1 if S[idx:idx + 2] == "AC" else 0)
for q in queries:
    l, r = q
    print(counters[r - 1] - counters[l - 1])


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<LL,LL>> p(n);
  for(int i=0;i<n;i++){
    cin >> p[i].first >> p[i].second;
  }
  sort(all(p));
  LL ans=0;
  for(int i=0;i<n;i++){
    if(p[i].second<m){
      ans+=p[i].first*p[i].second;
      m-=p[i].second;
    }else{
      ans+=m*p[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
line = [int(i) for i in input().split()]


#sum
#count : 組み合わせの個数
#tmp : L番目の要素で始まる組み合わせの個数

count = 0
sum = line[0]
r = 1
count_tmp = 1

for L in range(N-1):
  #ビットが被るまで右端を伸ばす。かぶったら終了
  for r in range(r,N):
    sum_tmp = sum+line[r]
    if sum_tmp == sum ^ line[r]:
      sum = sum_tmp
      count_tmp += 1
      if r == N-1:
        r += 1
    else:
      break
  count += count_tmp
  count_tmp -= 1
  sum -= line[L]

#L=N, r=Nの分を１つ追加する
print(count+1)

Measured memory_bytes: 23560
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

int main(){
	ll a,b,c;
	sfl(a),sfl(b),sfl(c);
	cout<<min(b/a,c)<<endl;
}



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

int main()
{
    int n,q;
    cin>>n>>q;
    
    map<int,vector<int>>m;
    
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        
        m[x].push_back(y);
        m[y].push_back(x);
    }
    
    int count[n+1];
    memset(count,0,sizeof(count));
    
    while(q--)
    {
        int a,b;
        cin>>a>>b;
        
        count[a]+=b;
    }
    
    queue<int>q1;
    
    bool visited[n+1];
    memset(visited,false,sizeof(visited));
    
    q1.push(1);
    visited[1]=true;
    
    while(!q1.empty())
    {
        int x=q1.front();
        q1.pop();
        
        visited[x]=true;
        
        for(int i=0;i<m[x].size();i++)
        {
            if(!visited[m[x][i]])
            {
                count[m[x][i]]+=count[x];
                q1.push(m[x][i]);
            }
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        cout<<count[i]<<" "; 
    }

    cout<<endl;
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll n;
  cin>>n;
  vector<ll> a(5);
  cin>>a;

  ll mn = *min_element(a.begin(),a.end());

  constexpr auto ceil = [](auto a,auto b){return (a-1)/b+1;};
  cout<< 4ll+ceil(n,mn) <<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
int v,r;
double x[100];
double y[100];
int p[100];

int FindP(int s1){
	if(s1!=p[s1])p[s1]=FindP(p[s1]);
	return p[s1];
}

bool Unite(int a,int b){
	int pa=FindP(a);
	int pb=FindP(b);
	if(pa==pb){
		return true;
	}else{
		if(pa>pb){
			p[pb]=pa;
		}else{
			p[pa]=pb;
		}
		return false;
	}
}

int main() {
	cin>>v>>r;
	rep(i,v)p[i]=i;
	rep(i,v)cin>>x[i]>>y[i];
	double total=0;
	rep(i,v){
		for(int j=i+1;j<v;++j){
			int s1=0,s2=0;
			rep(k,v){
				int s3=(y[k]-y[j])*(x[i]-x[j])-(y[i]-y[j])*(x[k]-x[j]);
				if(x[i]==x[j])s3=x[k]-x[i];
				if(y[i]==y[j])s3=y[k]-y[i];
				if(s3>0)s1++;
				if(s3<0)s2++;
			}
			if(!(s1>0&&s2>0)){
				total+=pow(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2),0.5);
				Unite(i,j);
			}
		}
	}
	Pdi road[1000];
	rep(i,r){
		int a1,a2;
		cin>>a1>>a2;
		a1--;
		a2--;
		road[i]=Pdi(pow(pow((x[a1]-x[a2]),2)+pow((y[a1]-y[a2]),2),0.5),Pi(a1,a2));
	}
	sort(road,road+r);
	rep(i,r){
		if(!Unite(road[i].second.first,road[i].second.second))total+=road[i].first;
	}
	printf("%0.4f\n",total);
	return 0;
}



Measured memory_bytes: 3432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;


signed _main(){
  string S; cin >> S;
  int Q; cin >> Q;
  deque<char> d;
  rep(i,S.size()){
    d.push_back(S[i]);
  }
  int revflag=0;
  rep(i,Q){
    int T; cin >> T;
    if(T==1){
      revflag=1-revflag;
    }
    else{
      int F;
      char C;
      cin >> F >> C;
      if(!revflag){
        if(F==1) d.push_front(C);
        else d.push_back(C);
      }
      else{
        if(F==1) d.push_back(C);
        else d.push_front(C);
      }
    }
  }
  if(!revflag){
    fore(i,d) cout << i;
    cout << "\n";
  }
  else{
    reverse(d.begin(),d.end());
    fore(i,d) cout << i;
    cout << "\n";
  }
  return  0;
}


Measured memory_bytes: 976