akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int a,n;
    cin>>a>>n;
    ll aa[n],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>aa[i];
        sum+=aa[i];
    }if(sum>a)cout<<"-1"<<endl;
    else cout<<a-sum<<endl;
}


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

using namespace std;

const int infty = 1<<28;
static int dp[1001][1<<12];

int main()
{
  while(true){

    int initHP;
    int maxHP;
    cin >> initHP >> maxHP;
    if(initHP==0&&maxHP==0)break;

    int R,C;
    cin >> R >> C;
    char M[R][C];
    int damage[256];
    for(int i = 0; i < R; ++i){
      for(int j = 0; j < C; ++j){
	cin >> M[i][j];
      }
    }
    
    int T;
    cin >> T;
    for(int i = 0; i < T; ++i){
      char c;
      int dam;
      cin >> c >> dam;
      damage[(int)c]=dam;
    }
    
    int S;
    cin >> S;
    string inst;
    for(int i = 0; i < S; ++i){
      char c;
      int step;
      cin >> c >> step;
      for(int j = 0; j < step; ++j){
	inst += c;
      }
    }

    int P;
    vector<int> potion;
    cin >> P;
    for(int i = 0; i < P; ++i){
      int p;
      cin >> p;
      potion.push_back(p);
    }

    S = inst.length();
    
    int Pmax=1<<potion.size();
    for(int i = 0; i < 1+S; ++i){
      for(int j = 0; j < Pmax; ++j){
	dp[i][j] = -infty;
      }
    }
    dp[0][0]=initHP;
    
    int ni=0;
    int nj=0;
    for(int i = 0; i < S; ++i){
      switch(inst[i]){
      case 'D':++ni;break;
      case 'U':--ni;break;
      case 'R':++nj;break;
      case 'L':--nj;break;
      }
      for(int j = 0; j < Pmax; ++j){
	if(dp[i][j]<=0)continue;
	for(int k = 0; k < (int)potion.size(); ++k){
	  if( (j&(1<<k)) == 0 ){
	    dp[i][j|(1<<k)] = max( dp[i][j|(1<<k)], min(maxHP, dp[i][j] + potion[k]) );
	  }
	}
      }
      for(int j = 0; j < Pmax; ++j){
	dp[i+1][j] = max( dp[i+1][j], dp[i][j]-damage[(int)M[ni][nj]] );
      }
    }

    int res = -infty;
    for(int i = 0; i < Pmax; ++i){
      res = max( res, dp[S][i] );
    }
    
    if(res>0)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;

  }
  return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
const long long INF = 100100100100;
int main(){
    long long m, n; cin >> m >> n;
    vector<vector<long long> > dp(n + 1, vector<long long> (m + 1, INF));
    vector<long long> p(m);
    for(int i = 0; i < m; i++) cin >> p[i];
    vector<long long> c(n);
    vector<long long> e(n);
    for(long long i = 0; i < n; i++) cin >> c[i] >> e[i];
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());

    dp[0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= m; j++){
            if(dp[i][j] != INF){

                //選ぶ
                dp[i + 1][min(m, j + c[i])] = min(dp[i + 1][min(m, j + c[i])], dp[i][j] + e[i]);

                //選ばない
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            }
        }
    }

    for(int i = 1; i < m; i++) p[i] += p[i - 1];

    long long ans = 0;

    for(long long j = 1; j <= m; j++){
        
        ans = max(ans, p[j - 1] - dp[n][j]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 42212
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();
    	if(a>8 || b>8){
    		System.out.println(":(");
    	}else{
    		System.out.println("Yay!");
    	}
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    string s;cin>>s;
    ll l=0,ans=0,now=0;
    REP(i,s.size()-1){
        if(s[i]=='>'&&s[i+1]=='<'){
            ans+=max(now,i+1-l);
            ans+=(i-l)*(i+1-l)/2;
            l=i+1;
            now=0;
        }
        else if(s[i]=='<'&&s[i+1]=='>'){
            ans+=(i-l)*(i+1-l)/2;
            now=i+1-l;
            l=i+1;
        }
    }
    ll n=s.size();
    if(s.back()=='>'){
        ans+=max(now,n-l);
        ans+=(n-1-l)*(n-l)/2;
    }
    else{
        ans+=(n-l)*(n+1-l)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 900
import collection.mutable.Queue
import java.util._
 
object Main {
  val sc = new Scanner(System.in)
  val map = new HashMap[String,Int]
  val q = Queue[String]()
  val n = sc.nextInt
  val proces = sc.nextInt
  
  
  
  
  def main(args: Array[String]): Unit = {
    for( i <- 0 until n){
      var temp = sc.next
      q.enqueue(temp)
      map.put(temp, sc.nextInt)
    }
    new Solve().main
  }
  
  
  
  
  class Solve{
      def main{
        var count = 0
        while(!q.isEmpty){
          var temp = q.dequeue() 
          
          if(map.get(temp) - proces > 0){
            map.put(temp ,map.get(temp) - proces)
            q.enqueue(temp)
            count += proces
          }else {
            count += map.get(temp)
            println(temp + " " +  count)
          }
              
        }
    }
  }
}

Measured memory_bytes: 142844
//written by Aman Mishra(aspro)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,s,e) for(ll i=s;i<=e;i++)
#define aspro ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pii pair<int,int>
#define INF 10000000000000
#define MOD 1000000007
#define N 2050
#define test int t;cin>>t;while(t--)
/*int histogram(int arr[],int n)
{
    f(j,1,n) cout<<arr[j]<<" ";cout<<endl;
    while(!s.empty()) s.pop();
    int i=1;int ans=0,area,top,ptop;
    while(i<=n)
    {
        if(s.empty() or arr[i]>=arr[s.top()])
        {
            s.push(i++);
            //i++;
        }
        else if(arr[i]<arr[s.top()])
        {
            top=s.top();
            s.pop();
            if(s.empty())    area=arr[top]*(i-1);
            else
            {
                ptop=s.top();
                area=arr[top]*(i-ptop-1);
            }
            ans=max(ans,area);
        }
    }
    while(!s.empty())
    {
        top=s.top();
        s.pop();
        if(s.empty())   area=arr[top]*(i-1);
        else
        {
            ptop=s.top();
            area=arr[top]*(i-ptop-1);
        }
         ans=max(ans,area);
    }
    //cout<<"returning  "<<ans<<endl;
    return ans;//cout<<ans<<endl;
}*/
string mat[N];
int s[N],parent[N],sz[N],ans,cnt,in[N];
vector<pii> vec;
int n,m;
int findset(int x)
{
    //cout<<"aman\n";
	//return x==parent[x]?x:parent[x]=findset(parent[x]);
	while(x!=parent[x])
        x=parent[x];
    return parent[x];
}
void union1(int x,int y)
{
	int p1=findset(x);
	int p2=findset(y);
	if(p1==p2) return ;
	parent[p1]=p2;
	sz[p2]+=sz[p1];
}
void findans()
{
	vec.clear();
	f(i,1,m-1) vec.pb({s[i],i});
	sort(vec.begin(),vec.end(),greater<pii>() );
    /*int si=vec.size();
    cout<<"sorted :\n";
    f(i,0,si-1)
    {
        cout<<i<<" "<<v[i].first<<" "<<v[i].second<<endl;
    }*/
    f(i,0,m-1) parent[i]=i;
    f(i,0,m-1) sz[i]=1;
	++cnt;
	for(auto it:vec)
	{
		int x=it.second;
		in[x]=cnt;
		if(in[x-1]==cnt) union1(x-1,x);
		if(in[x+1]==cnt) union1(x+1,x);
		ans=max(ans,  it.first*(sz[findset(x)]+1 ));
	}
}
int main()
{
    aspro
    cin>>n>>m;
    f(i,0,n-1) cin>>mat[i];
    ans=max(n,m);
    f(i,1,m-1) s[i]=1;
    f(i,1,n-1)
    {
    	f(j,1,m-1)
    	{
    		int x=(mat[i][j]==mat[i][j-1])?1:0 ;
    		int y=(mat[i-1][j]==mat[i-1][j-1])?1:0 ;
    		if(x==y) s[j]++;
    		else s[j]=1;
    	}
    	//f(j,0,m) cout<<s[j]<<" ";cout<<endl;
    	findans();
        //cout<<i<<" --- "<<ans<<endl;
    	//ans=max(ans,histo(s,m));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6664
#include <iostream>

using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  long long sum=0;
  int min=1000000001;
  int neg=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]<0)
    {
      neg++;
      a[i]*=-1;
    }
    sum+=a[i];
    if(a[i]<min)
      min=a[i];
  }
  if(neg%2!=0)
    sum-=(2*min);
  cout<<sum;
}
  

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

int k, s;
int main(void){
    cin >> k >> s;
    int cnt = 0;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (0 <= s-i-j && s-i-j <= k) ++cnt;
            
        }
        
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
//n以下の素数列挙(O(nloglogn))
vector<long> primes(long n){
    map<long,bool> mp;
    for(int i = 0;i<=n;i++){
        mp[i] = true;
    }
    mp[1] = false;
    vector<long> prime;
    for(int i = 2;i<=n;i++){
        if(mp[i]){
            for(int j = 2*i;j<=n;j+=i){
                mp[j] = false;
            }
            if(mp[(i+1)/2]) prime.push_back(i);//ここで入れる素数を変えられる
        }
    } 
    return prime;
}
int main(){
    vector<long> prime = primes(long(1e5));
    long rsum[long(1e5)];
    rsum[0] = 0;
    int k = 0;
    for(int i = 1;i<long(1e5);i++){
        rsum[i] = rsum[i-1];
        if(prime[k]==i){
            rsum[i]++;
            k++;
        }
    }
    int m;
    cin >> m;
    int ans[m];
    long l,r;
    for(int i = 0;i<m;i++){
        cin >> l >> r;
        ans[i] = rsum[r]-rsum[l-1];
    }
    for(int i = 0;i<m;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {
  
int n; cin>>n;
  string s[n];
  int ac=0,wa=0,tle=0,re=0;
  
 rep(i,n){cin>>s[i];
         if(s[i]=="AC"){ac++;}
         else if(s[i]=="WA"){wa++;}
         else if(s[i]=="TLE"){tle++;}
         else if(s[i]=="RE"){re++;}
         }
  
cout<<"AC x "<<ac<<endl;
cout<<"WA x "<<wa<<endl;
cout<<"TLE x "<<tle<<endl;
cout<<"RE x "<<re<<endl;

  
  
  
}

Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
using namespace std;
int main() {
	// your code goes here
	int start_a, end_a, start_b, end_b, common;
	cin>>start_a>>end_a>>start_b>>end_b;
	if(start_a > end_b or start_b > end_a){
		printf("0\n"); return 0;
	}
	common = min(end_a, end_b) - max(start_a, start_b);
	printf("%d\n",max(0,common));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 10000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n_=1<<18;
int n;
int p[200001];
int now[200001];
int q[200001];
P minist[3][1<<19];

void update(int type,int k,P a){
	k+=n_-1;
	minist[type][k]=a;
	while(k>0){
		k=(k-1)/2;
		minist[type][k]=min(minist[type][k*2+1],minist[type][k*2+2]);
	}
}

P query(int type,int a,int b,int k=0,int l=0,int r=n_){
	if(b<=l || r<=a)return P(INF,0);
	if(a<=l && r<=b)return minist[type][k];
	int mid=(l+r)/2;
	P vl=query(type,a,b,k*2+1,l,mid);
	P vr=query(type,a,b,k*2+2,mid,r);
	return min(vl,vr); 
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<(1<<19);i++){
		minist[0][i]=P(n+1,0);
		minist[1][i]=P(n+1,0);
		minist[2][i]=P(n+1,0);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(int i=0;i<n;i++){
		if(i%2==0){
			update(0,i/2,P(p[i],i));
		}else{
			update(1,i/2,P(p[i],i));
		}
		update(2,i,P(p[i],i));
	}
	priority_queue<PP,vector<PP>,greater<PP> > que;
	que.push(PP(0,P(0,n)));
	for(int i=0;i<n/2;i++){
		PP p=que.top();
		que.pop();
		int l=p.second.first;
		int r=p.second.second;
		P v,v2;
		if(l%2==0){
			v=query(0,l/2,r/2);
		}else{
			v=query(1,l/2,r/2);
		}
		if(v.second%2==0){
			v2=query(1,v.second/2,r/2);
			update(0,v.second/2,P(INF,0));
			update(1,v2.second/2,P(INF,0));
		}else{
			v2=query(0,(v.second+1)/2,(r+1)/2);
			update(1,v.second/2,P(INF,0));
			update(0,v2.second/2,P(INF,0));
		}
		update(2,v.second,P(INF,0));
		update(2,v2.second,P(INF,0));
		q[i*2]=v.first;
		q[i*2+1]=v2.first;
		int nl=l;
		int nr=v.second;
		int val=query(0,nl/2,nr/2).first;
		if(nl%2==1){
			val=query(1,nl/2,nr/2).first;
		}
		que.push(PP(val,P(nl,nr)));
		
		nl=v.second+1;
		nr=v2.second;
		val=query(0,nl/2,nr/2).first;
		if(nl%2==1){
			val=query(1,nl/2,nr/2).first;
		}
		que.push(PP(val,P(nl,nr)));

		nl=v2.second+1;
		nr=r;
		val=query(0,nl/2,nr/2).first;
		if(nl%2==1){
			val=query(1,nl/2,nr/2).first;
		}
		que.push(PP(val,P(nl,nr)));
	}
	for(int i=0;i<n;i++){
		printf("%d%c",q[i],i+1==n?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 19572
using System;

class program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    
    if(a > b) Console.WriteLine(a - 1);
    else Console.WriteLine(a);
  }
}

Measured memory_bytes: 11092
#include <cstdio>
#include <queue>
#include <cstring>

using namespace std;

int w, h;
char a[555][555];

int main(void) {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf(" %c", a[i]+j);
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      printf("%c", i == 0 || a[i][j] == '#' || (i!=h-1&&j%2 == 0) ? '#' : '.');
    }
    puts("");
  }

  puts("");
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      printf("%c", i == h-1 || a[i][j] == '#' || (i!=0&&j%2 == 1) ? '#' : '.');
    }
    puts("");
  }
  
  return 0;
}


Measured memory_bytes: 896
N = int(input())
A = list(map(int,input().split()))

import numpy as np
A = np.array(A)

ans = 0
while 1:
    if(sum(A%2) == 0):
        ans += 1
        A = A/2
    elif(sum(A%2) != 0):
        break;
print(ans)

Measured memory_bytes: 21528
import math
N = int(input())
if N == 1:
    print(0)
    exit()
div = {}
i = 2
while i*i <= N:
    while N % i == 0:
        N = N // i
        if i in div:
            div[i] += 1
        else:
            div[i] = 1
    if N == 1:
        break
    i += 1
if N != 1:
    div[N] = 1
ans = 0
for v in div.values():
    i = 1
    while v >= i:
        v -= i
        i += 1
        ans += 1
print(ans)


Measured memory_bytes: 9116
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int cntCity = sc.nextInt();
    int cntRoad = sc.nextInt();
    int[] city = new int[cntCity];

    for (int i = 0; i < cntRoad; i++) {
      city[sc.nextInt() - 1] += 1;
      city[sc.nextInt() - 1] += 1;
    }

    for (int i : city) {
      System.out.println(i);
    }
  }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define INF (1e9)

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

typedef long long ll;

ll cal(ll a, ll b){
    return ((a % (ll)(1e9+7)) * (b % (ll)(1e9+7))) % (ll)(1e9+7);
}

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

    ll nums[2];
    cin >> nums[0] >> nums[1];

    if(abs(nums[1] - nums[0]) > 1){
        cout << 0 << endl;
        return 0;
    }

    vector<ll> results(2);
    rep(i, 2){
        results[i] = nums[i];
        for(ll j = nums[i]-1; j >= 1; j--){
            results[i] = cal(results[i], j);
        }
    }

    // cout << results[0] << " ; " << results[1] << endl;
    cout << cal((int)(nums[0] == nums[1]) + 1, cal(results[0], results[1])) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
ll gcd(ll a, ll b){ return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b){ return a/gcd(a,b)*b; }

int main(void){
  ll n;
  cin >> n;
  ll ans = 1;
  REP(i, n){
    ll t;
    cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int s,i,j;
    i=0;
    int test[1000000];
    int check=0;
    scanf("%d",&s);
    while(check==0){
    if(s%2==0){
        test[i]=s;
        s=s/2;
    }else{
        test[i]=s;
        s=3*s+1;
    }
    for(j=0;j<i;j++){
        if(test[j]==s){
            check+=1;
        }
    }
    i++;
    }
    printf("%d\n",i+1);
    return 0;
}

Measured memory_bytes: 128
N, X, M = [int(_) for _ in input().split()]
seen = {}
i = 0
A = []
while True:
    if X in seen:
        i2 = seen[X]
        i3 = i
        break
    seen[X] = i
    A += [X]
    i += 1
    X = X**2 % M
if N < i3:
    ans = sum(A[:N])
elif i2 == i3:
    ans = sum(A[:i2]) + A[i2] * (N - i2)
else:
    q, r = divmod(N - i2, i3 - i2)
    ans = sum(A[:i2]) + sum(A[i2:]) * q + sum(A[i2:i2 + r])
print(ans)


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

using namespace std;

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



int main(){

  int n,cnt=0;
  cin >> n;
  vector<int> p(n);
  rep(i,n){cin >> p[i];p[i]--;}
  rep(i,n){
    if (p[i]==i){
      swap(p[i],p[i+1]);
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
using namespace std;

long long n,m;

int main()
{
	scanf("%lld%lld",&n,&m);
	if(n==1ll && m==1ll) printf("1\n");
	else if(n==1ll) printf("%lld\n",m-2ll);
	else if(m==1ll) printf("%lld\n",n-2ll);
	else printf("%lld\n",(n-2ll)*(m-2ll));
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
G=[list(map(int,input().split())) for i in range(M)]

MIN=0
MAX=10**9

for a,b in G:
    MIN=max(MIN,a)
    MAX=min(MAX,b)

print(max(0,MAX-MIN+1))


Measured memory_bytes: 27340
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a, b, c, d[10000];
vector<pair<int, int> >P;
int main() {
    while (true) {
        cin >> a >> b >> c; P.clear();
        if (a == 0)break;
        for (int i = 1; i <= a; i++)cin >> d[i];
        for (int i = b; i <= c; i++) {
            P.push_back(make_pair(d[i] - d[i + 1], i));
        }
        sort(P.begin(), P.end());
        cout << P[P.size() - 1].second << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define next DCXISSOHANDSOME
#define ll long long

ll num[100010][26],next[100010],n,l,r,hh;
char s[200010];

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll fib(ll len,ll x)
{
	if (len<=n) return num[len][x];
	if (len<=n+hh) return num[n][x]+num[len-n][x];
	ll f1=num[n][x],f2=num[n][x]+num[hh][x],l1=n,l2=n+hh;
	while (len>=l1+l2)
	{
		ll hhh=f2;f2+=f1;f1=hhh;
		hhh=l2;l2+=l1;l1=hhh;
	}
	return f2+fib(len-l2,x);
}

inline ll calc(ll len,ll x)
{
	if (len<=n) return num[len][x];
	return fib(len,x);
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1)>>1;
	l=rd();r=rd();
	next[1]=0;
	for (ll i=2;i<=n;i++)
	{
		ll j=next[i-1];
		for (;j&&s[j+1]!=s[i];j=next[j]);
		if (s[j+1]==s[i]) j++;
		next[i]=j;
	}
	for (ll i=1;i<=n;i++)
	{
		for (ll j=0;j<26;j++) num[i][j]=num[i-1][j];
		num[i][s[i]-'a']++;
	}
	hh=n-next[n];
	for (ll i=0;i<26;i++) printf("%lld ",calc(r,i)-calc(l-1,i));
	puts("");
	return 0;
}

Measured memory_bytes: 21504
N,M,X = map(int,input().split(" "))
A = []
lis = []
rikai = [[0 for _ in range(M)]for _ in range(2 ** N)]
flag = True
kane = 0
ans = 10 ** 10
for i in range(N):
    A.append(list(map(int,input().split(" "))))
    
for i in range(2 ** N):
    lis.clear()
    kane = 0
    flag = True
    for i2 in range(N):
        if ((i >> i2) & 1):
            lis.append(i2)
    for i2 in lis:
        kane += A[i2][0]
        for i3 in range(M):
            rikai[i][i3] += A[i2][i3 + 1]
    for i2 in rikai[i]:
        if i2 < X:
            flag = False
    if flag:
        if ans > kane:
            ans = kane
            
if ans != 10 ** 10:
    print(ans)
else:
    print(-1)



Measured memory_bytes: 11232
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

template<typename T>
vector <T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

class CPrison {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        vector<int> L(M), R(M);
        REP(i, M) cin >> L[i] >> R[i];
        sort(L.begin(), L.end());
        sort(R.begin(), R.end());

        int res = R.front() - L.back() + 1;
        cout << max(res, 0LL) << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CPrison solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N, flg = 0;
  long long ans = 1, t = 1000000007;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }

  sort(A, A+N);

  if (N%2 == 0){
    for (int i = 0; i < N; i+=2){
      if(A[i]!=i+1 || A[i+1]!=i+1){
        flg = 1;
        break;
      }
    }
  }else{
    if (A[0] != 0){
      flg = 1;
    }else{
      for (int i = 1; i < N; i+=2){
        if(A[i]!=i+1 || A[i+1]!=i+1){
          flg = 1;
          break;
        }
      }
    }
  }

  if (flg==1){
    printf("0\n");
  }else{
    for (int i=0; i < N/2; i++){
      ans *= 2;
      ans %= t;
    }
    printf("%llu\n",ans);
  }

}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  int n, k;
  cin >> n >> k;
  int a[n + 5];
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a +n);
  lol sum = 0;
  rep(i, k){
    sum += a[i];
  }
  cout << sum << '\n';
    
  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],n;
map<int,int>m;
inline int check(int mid)
{
	if(mid==1)
	{
		for(int i=1;i<n;i++)
			if(a[i]>=a[i+1])
				return 0;
		return 1;
	}
	m.clear();
	for(int i=2;i<=n;i++)
	{
		if(a[i]<=a[i-1])
		{
			m.erase(m.upper_bound(a[i]),m.end());
			int k=a[i];
			m[k]++;
			for(;k&&m[k]==mid;)
			{
				m.erase(k);
				k--;
				m[k]++;
			}
			if(!k)
				return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	int l=1,r=n,mid;
	while(l<r)
	{
		mid=l+r>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<vector>
#include<string.h>
#define N 100005
using namespace std;
vector<int> g[N];
int f[N];
int n, m;
int maxn(int x, int y)
{
	return x > y ? x : y;
}
void dp(int x)
{
	for (int i = 0; i < g[x].size(); i++)
	{
		int y;
		y = g[x][i];
		if (f[y])
			f[x] = maxn(f[x], f[y] + 1);
		else
		{
			dp(y);
			f[x] = maxn(f[x], f[y] + 1);
		}
	}
}
int main()
{
	scanf("%d %d", &n, &m);
	memset(f, 0, sizeof(f)); 
	for (int i = 1; i <= n; i++)
		g[0].push_back(i);
	int tmp1, tmp2;
	for (int i = 1; i <= m; i++)
	{
		scanf("%d %d", &tmp1, &tmp2);
		g[tmp2].push_back(tmp1);
	}
	dp(0);
	printf("%d\n", f[0] - 1);
	return 0;
}

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

int main(){
    int n; cin>>n;
    vector<ll> l(0);
    vector<ll> r(0);
    for (int i=0; i<n; i++){
        ll a; cin>>a;
        if(i%2==0) r.push_back(a);
        else l.push_back(a);
    }
    if(n%2==0){
        reverse(l.begin(), l.end());
        for(int i=0; i<n/2; i++) cout << l[i] << ' ';
        for(int i=0; i<n/2; i++){
            if(i==n/2-1) cout << r[i];
            else cout << r[i] << ' ';
        }
    }
    else{
        reverse(r.begin(), r.end());
        for(int i=0; i<n/2+1; i++) cout << r[i] << ' ';
        for(int i=0; i<n/2; i++){
            if(i==n/2-1) cout << l[i];
            else cout << l[i] << ' ';
        }
    }
    cout << endl;
}

Measured memory_bytes: 5092
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        boolean [] b = new boolean [1001];
        ArrayList<Integer> prime = new ArrayList<Integer>();
        prime.add(2);
        for(int i=3; i<=1000; i+=2){
            if(b[i]==false){
                prime.add(i);
                int k=3;
                while(i*k<=1000){
                    b[i*k]=true;
                    k+=2;
                }
            }
        }
        int s = prime.size();
        long [] PNum = new long [s];
        for(int i=0; i<s; i++){
            int P = prime.get(i);
            for(int j=1; j<=N; j++){
                int tmp=j;
                while(tmp%P==0){
                    PNum[i]++;
                    tmp/=P;
                }
            }
        }
        long ans=1;
        long mod=1000000007;
        for(int i=0; i<s; i++){
            ans*=(PNum[i]+1);
            ans%=mod;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 10068
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
 
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

void solve(){
    int x,k,d,ans = inf;
    cin >> x >> k >> d;
    x = abs(x);
    int alfa = min(k,x/d);
    k -= alfa;
    int cur = x-alfa*d;
    if(k%2 == 0){
        ans = abs(cur);
        if(k > 1)ans = min(ans,abs(cur-2*d));
    }
    else {
        ans = abs(cur-d);
    }
    cout << ans << "\n";
}
 
signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=700;
    for(int i=0;i<s.length();i++){
        if(s[i]=='o')
            n=n+100;
        else
            n=n;
    }
    cout<<n<<endl;
    return 0;
}


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

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point{
    public:
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}
    Point operator+(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator-(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator*(const double &a){
        return Point(a*x,a*y);
    }
    Point operator/(const double &a){
        return Point(x/a,y/a);
    }
    double abs(){
        return sqrt(norm());
    }
    double norm(){
        return x*x+y*y;
    }
    bool operator<(const Point &p){
        return x!=p.x?x<p.x:y<p.y;
    }
    bool operator==(const Point &p){
        return fabs(x-p.x)<EPS&&fabs(y-p.y)<EPS;
    }
};
typedef Point Vector;
struct Segment{
    Point p1,p2;
    Segment(){}
    Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

bool isOrthogonal(Segment s1,Segment s2){
    return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

bool isParallel(Segment s1,Segment s2){
    return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/base.norm();
    return s.p1+base*r;   
}

Point reflect(Segment s,Point p){
    return p+(project(s,p)-p)*2;
}

double getDistanceLP(Line l,Point p){
    return abs(cross(l.p2-l.p1,p-l.p1))/(l.p2-l.p1).abs();
}

double getDistanceSP(Segment s,Point p){
    if(dot(s.p2-s.p1,p-s.p1)<0){
        return (p-s.p1).abs();
    }
    if(dot(s.p1-s.p2,p-s.p2)<0){
        return (p-s.p2).abs();
    }
    return getDistanceLP(s,p);
}

int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return 1;
    if(cross(a,b)<-EPS) return -1;
    if(dot(a,b)<-EPS) return 2;
    if(a.norm()<b.norm()) return -2;
    return 0;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
        ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

double getDistance(Segment s1,Segment s2){
    if(intersect(s1,s2)) return 0;
    return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
        min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}

Point getCrossPoint(Segment s1,Segment s2){
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}

int main(){
    int q;
    cin>>q;
    int a,b,c,d,e,f,g,h;
    Point p1,p2,p3,p4;
    for(int i=0;i<q;i++){
        cin>>a>>b>>c>>d>>e>>f>>g>>h;
        p1=Point(a,b);
        p2=Point(c,d);
        p3=Point(e,f);
        p4=Point(g,h);
        Segment s1(p1,p2),s2(p3,p4);
        printf("%.10lf\n",getDistance(s1,s2));
    }
}


Measured memory_bytes: 3224
#define LOCAL
#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 rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int a, b; cin >> a >> b;
	if(a + b >= 10){
		cout << "error" << endl;
		return 0;
	}
	cout << a + b << endl;

	return 0;
}


Measured memory_bytes: 3500
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    int N, x;
    cin >> N >> x;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    sort(a, a + N);
    int ans = 0;

    // 少ない子から順に飴を配る
    for (int i = 0; i < N; ++i) {
        if (x >= a[i]) {
            ++ans;
            x -= a[i];
        }
    }

    // 飴が余っていたら1人を犠牲にする
    if (ans == N && x > 0) --ans;

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


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

int main()
{
    string s;
    static bool a,b,c;
    cin >> s;
    for (int i = 0 ; i < 3 ; i++)
        if (s[i] == 'a')
            a = true;
        else if (s[i] == 'b')
            b = true;
        else if (s[i] == 'c')
            c = true;
    cout << (a&&b&&c ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  Int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}
  
  void init(Int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(const vector<T> &v){
    Int n_=v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i]=v[i];
    for(Int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  inline T reflect(Int k){
    return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
  }
  inline void eval(Int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  inline void thrust(Int k){
    for(Int i=height;i;i--) eval(k>>i);
  }
  inline void recalc(Int k){    
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
  }
  void update(Int a,Int b,E x){
    thrust(a+=n);
    thrust(b+=n-1);
    for(Int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(Int a,T x){
    thrust(a+=n);
    dat[a]=x;laz[a]=ei;
    recalc(a);
  }
  T query(Int a,Int b){
    thrust(a+=n);
    thrust(b+=n-1);
    T vl=ti,vr=ti;
    for(Int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  vector<Int> ss(n),ts(n),xs(n);
  for(Int i=0;i<n;i++) cin>>ss[i]>>ts[i]>>xs[i];
  {
    using T = tuple<Int, Int, Int>;
    vector<T> vt;
    for(Int i=0;i<n;i++) vt.emplace_back(xs[i],ss[i],ts[i]);
    sort(vt.rbegin(),vt.rend());
    for(Int i=0;i<n;i++) tie(xs[i],ss[i],ts[i])=vt[i];
  }
  
  vector<Int> ds(q);
  for(Int i=0;i<q;i++) cin>>ds[i];
  
  auto f=[](Int a,Int b){return max(a,b);};  
  SegmentTree<Int, Int> seg(f,f,f,-1,-1);
  seg.build(vector<Int>(q,-1));

  for(Int i=0;i<n;i++){
    Int lb=ss[i]-xs[i],ub=ts[i]-xs[i];   
    Int ll=0,rr=0;
    {
      Int l=-1,r=q;
      while(l+1<r){
        Int m=(l+r)>>1;
        if(lb<=ds[m]) r=m;
        else l=m;
      }            
      ll=r;
    }    
    {
      Int l=-1,r=q;      
      while(l+1<r){
        Int m=(l+r)>>1;
        if(ds[m]<ub) l=m;
        else r=m;
      }      
      rr=r;
    }
    //cout<<lb<<" "<<ub<<":"<<ll<<" "<<rr<<endl;
    if(ll<=rr) seg.update(ll,rr,i);
  }

  for(Int i=0;i<q;i++){
    Int k=seg.query(i,i+1);
    cout<<(k<0?k:xs[k])<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 17872
N = int(input())
len_N = len(str(N))
cnt = 0
for i in range(1,len_N,2):
    cnt += 10**(i)-10**(i-1)
if len_N%2 == 1:
    cnt += N - 10**(len_N-1)+1
if N<10:
    cnt = N
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <utility>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 100000
#define MAXL 100
typedef long long int lli;

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

    string s;
    bool includeY = false;
    for(int i = 0; i < n; i++){
        char c_input;
        cin >> c_input;
        if(!includeY && c_input == 'Y'){
            includeY = true;
        }
        s += c_input;
    }

    string ans = (includeY)? "Four" : "Three";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int one = 0;
		int two = 0;
		int three = 0;
		for(int i = 0; i < n; i++) {
			if(p[i] <= a) {
				one ++;
			}else if(a < p[i] && p[i] <= b) {
				two ++;
			}else {
				three ++;
			}
		}
		int min = Math.min(one, two);
		int ans = Math.min(min, three);
		System.out.println(ans);
		sc.close();
	}
}



Measured memory_bytes: 25300
a, b, ab, x, y = (int(i) for i in input().split())
costcut = a + b - 2*ab
if costcut<=0:
    total = a*x + b*y
else:
    base = min(x,y)*2*ab
    nokori = abs(x-y)
    if x>y:
        if a>2*ab:
            total = base + nokori*2*ab
        else:
            total = base + nokori*a
    else:
        if b>2*ab:
            total = base + nokori*2*ab
        else:
            total = base + nokori*b
print(total)

Measured memory_bytes: 3064
import math
N = int(input())
XY = [list(map(int,input().split())) for _ in  range(N)]
for i in range(N):
    XY[i].append(math.atan2(XY[i][1],XY[i][0]))

XY.sort(key = lambda x:x[2])
ans = 0
tmp = [0,0]
ruisekiwa_x = [0] * N
ruisekiwa_y = [0] * N
ruisekiwa_x[0] = XY[0][0]
ruisekiwa_y[0] = XY[0][1]

for i in range(1,N):
    ruisekiwa_x[i] = ruisekiwa_x[i-1] + XY[i][0]
    ruisekiwa_y[i] = ruisekiwa_y[i-1] + XY[i][1]
    
ans = 0
for i in range(N):
    for j in range(i,N):
        if i>0: 
            tmp[0] = ruisekiwa_x[j] - ruisekiwa_x[i-1]
            tmp[1] = ruisekiwa_y[j] - ruisekiwa_y[i-1]
        else:
            tmp[0] = ruisekiwa_x[j] 
            tmp[1] = ruisekiwa_y[j] 
            
            
        ans = max(ans,math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1]))
for i in range(N):
    if XY[i][2] < 0:
        XY[i][2] = -math.pi-XY[i][2]
    else:
        XY[i][2] = math.pi - XY[i][2]
        

XY.sort(key = lambda x:x[2])
ruisekiwa_x = [0] * N
ruisekiwa_y = [0] * N
ruisekiwa_x[0] = XY[0][0]
ruisekiwa_y[0] = XY[0][1]

for i in range(1,N):
    ruisekiwa_x[i] = ruisekiwa_x[i-1] + XY[i][0]
    ruisekiwa_y[i] = ruisekiwa_y[i-1] + XY[i][1]
    
for i in range(N):
    for j in range(i,N):
        if i>0: 
            tmp[0] = ruisekiwa_x[j] - ruisekiwa_x[i-1]
            tmp[1] = ruisekiwa_y[j] - ruisekiwa_y[i-1]
        else:
            tmp[0] = ruisekiwa_x[j] 
            tmp[1] = ruisekiwa_y[j] 
            
            
        ans = max(ans,math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1]))
        
print(ans)



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

fn main() {
    let input = scan!();
    let t = input.split_whitespace().collect::<Vec<_>>();
    for (&t0, &t1) in t.iter().zip(t[1..].iter()) {
        if t0.to_string().pop().unwrap() != t1.chars().next().unwrap() {
            println!("NO");
            return;
        }
    }
    println!("YES");
}


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

int main() {
  int N;
  cin >> N;
  long long res = 0;
  for (int i = 0; i < N; ++i) {
    int a, b; cin >> a >> b; res += b-a+1;
  }
  cout << res << endl;
}

Measured memory_bytes: 3528
n = int(input())
R = []
for i in range(n):
    a,b = map(int,input().split())
    R.append((a,b))
B = []
for i in range(n):
    c,d = map(int,input().split())
    B.append((c,d))

R.sort(reverse=True)#aをx座標でソート
B.sort(key = lambda x:x[1])#bをｙ座標でソート
ans = 0
for i in R:
    for j in range(len(B)):
        if i[0] < B[j][0] and i[1] < B[j][1]:
            ans += 1
            B.pop(j)
            break

print(ans)


Measured memory_bytes: 9244
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

long long n, k, a[500000];

int main()
{
    cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    long long p = 0, s = 0, ss = 0;
    for (int i = k; i < n; i++) s += max(0LL, a[i]);
    for (int i = 0; i < k; i++) ss += a[i];
    ans = max(ans, p + max(0LL, ss) + s);
    for (int i = k; i < n; i++)
    {
        s -= max(0LL, a[i]);
        ss += a[i];
        p += max(0LL, a[i - k]);
        ss -= a[i - k];
        ans = max(ans, p + max(0LL, ss) + s);
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL M;
  cin>>M;
  LL cnt_carry = 0;
  ULL carry=0;
  ULL sum_c = 0;
  ULL s= 0;
  REP(i,0,M){
    ULL d,c;
    cin>>d>>c;
    sum_c+=c;
    s+=d*c;

    ULL sum = d*c+carry;
    cnt_carry+=sum/9;
    carry=sum%10;
  }
  cout<<sum_c -1 + (s-1)/9<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define pii pair<int,int>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=55;

vector <pii> q,g[maxn];
vector <int> v[maxn];
int n,m;
bool vis[maxn];

bool get_path(int x,int ed,int id){
	vis[x]=1;
	if(x==ed) return true;	
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i].fst;
		if(!vis[to]) if(get_path(to,ed,id)){
			v[id].pb(g[x][i].snd);
			return true;
		}
	}
	return false;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v); 
		u--; v--;
		g[u].pb(mp(v,i));
		g[v].pb(mp(u,i));
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		q.pb(mp(u,v));
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<maxn;j++) vis[j]=0;
		get_path(q[i].fst,q[i].snd,i);
	}
//	for(int i=0;i<v[0].size();i++) printf("%d ",v[0][i]);
//	printf("\n");
	ll ans=0ll;
	for(int mask=0;mask<(1<<m);mask++){
		for(int i=0;i<n;i++) vis[i]=0;
		vector <int> t;
		for(int i=0;i<m;i++)
			if(mask&(1<<i)) t.pb(i); 
		int sum=0;
		for(int i=0;i<t.size();i++) for(int j=0;j<v[t[i]].size();j++)
			if(!vis[v[t[i]][j]]) vis[v[t[i]][j]]=1;
		for(int i=0;i<n-1;i++) if(vis[i]) sum++;
		ll sum2=1ll;
		for(int i=0;i<n-1-sum;i++) sum2=sum2*2ll;
//		printf("%d %d\n",t.size(),sum2);
		if(t.size()%2==0) ans+=sum2;
		else ans-=sum2;		
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256