criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits/stdc++.h>
using namespace std;

typedef long long int in;

in tree[800005],ans=-1e18;

void update(in node,in s,in e,in ind,in val)
{
    if(s==e)
    {
        tree[node]=val;
    }
    else
    {
        in m=(s+e)/2;
        
        if(s<=ind&&ind<=m)
        update(2*node,s,m,ind,val);
        else
        update(2*node+1,m+1,e,ind,val);
        
        tree[node]=max(tree[2*node],tree[2*node+1]);
    }
}

in query(in node,in s,in e,in l,in r)
{
    if(r<s||e<l)
    return 0;
    
    if(l<=s&&e<=r) 
    return tree[node];
    
    in m=(s+e)/2;
    
    in max1=query(2*node,s,m,l,r);
    in max2=query(2*node+1,m+1,e,l,r);
    
    in maxi=max(max1,max2);
    
    return maxi;
}

int main()
{
    in n,i,j;
    cin>>n;
    
    in h[n+2],v[n+2];
    
    for(i=1;i<=n;++i)
    cin>>h[i];
    
    for(i=1;i<=n;++i)
    cin>>v[i];
    
    for(i=1;i<=n;++i)
    {
        ans=max(ans,query(1,1,n,0,h[i]-1)+v[i]);
        
        update(1,1,n,h[i],dp[i]);
    }
    
    cout<<ans;
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:62:27: error: 'dp' was not declared in this scope; did you mean 'dup'?
   62 |         update(1,1,n,h[i],dp[i]);
      |                           ^~
      |                           dup
Language: C++

#include <bits/stdc++.h>

using namespace std;
int n,i,a[200005];
long long tree[400020],x,sol;
const int mod=1e9+7;
long long querry(int nod,int st,int dr)
{
    if(nod>400005)return;
    if(dr<=a[i])
        return tree[nod];
    else {
        long long mij=(st+dr)>>1,x=0,y=0;
        x=querry(2*nod,st,mij);
        if(mij<a[i])
            y=querry(2*nod+1,mij+1,dr);
        return max(x,y);
    }
}
void update(int nod,int st,int dr)
{
    if(nod>400005)return;
    if(st==dr)tree[nod]=x;
    else {
     int mij=(st+dr)>>1;
     if(mij>=a[i])
     update(2*nod,st,mij);
     if(mij<a[i])
        update(2*nod+1,mij+1,dr);
     if(2*nod<=400005)
        tree[nod]=max(tree[2*nod],tree[2*nod+1]);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    {
        cin>>x;
        x+=querry(1,1,n);
        sol=max(sol,x);
        update(1,1,n);
    }
    cout<<sol;
    return 0;
}


Compiler output:
a.cc: In function 'long long int querry(int, int, int)':
a.cc:9:19: error: return-statement with no value, in function returning 'long long int' [-fpermissive]
    9 |     if(nod>400005)return;
      |                   ^~~~~~
Language: C++


#include<bits/stdc++.h>
#define ll long long int

using namespace std ;

ll sea(ll x , vector<pair<ll, ll>>  arr )
{    ll i = 0 , j = arr.size()-1 ;
if(arr[j].first < x)
return  j ;
    while(i < j )
    {
        ll r = j-  + (j-i)/2 ;
        if( arr[r].first>=x)
        {
            j= r-1 ;

        }else
        {
            i=r ;
            }
   }
    return j-(j-i)/2 ;
}
vector<pair<ll ,ll> > del (vector< pair<ll, ll >> arr , ll b )
{
    ll m = arr[b].second ;
    while(b+arr.begin() !=  arr.end() -1 )
    {
        if(arr[b].second > arr[b+1].second )
        {
            arr.erase(arr.begin() + b+1 ) ;

        }else
        break ;
    }

    return arr ;
}

int main()
{
    ll t ;
    scanf("%lld", &t) ;
    vector<int> visi(t+1 , 0) ;
    visi[0] =1 ;

    vector<pair<ll,ll>> arr ;
    vector<ll> brr(t) , crr(t) ;
    arr.push_back(make_pair(0 ,0 ) );
    for(ll i =0 ;i < t ; i++)
    {
        scanf("%lld",&brr[i]) ;
    }
    for(ll i =0 ;i < t ; i++)
    {
        scanf("%lld",&crr[i] ) ;
    }

    for(ll i =0 ;i < t ; i++)
    {
        ll a = brr[i]  , b = crr[i] ;


        ll c = sea(a , arr ) + 1 ;
        arr.insert(c +arr.begin() , make_pair(a , b + arr[c-1].second ) ) ;
        visi[arr[c].first ] =1 ;


        arr = del(arr , c ) ;








if(i>=n/2){


        ll j = arr[c].first , k = arr[c].first  , puta = 0 , putb= 0 ;





        while(j>1 && visi[j-1]==1 )
        {
            j-- ;
        }

        while(k<t && visi[k+1] == 1 )
        k++ ;

        ll left = c , right = c  ;
        while(left!=0  )
        {
            if( arr[left-1].first<j || arr[left].first<j)
            break ;
            left-- ;


        }
        while(right!=arr.size()-1 )
        {
            if( arr[right+1].first >k || arr[right].first>k)
            break ;
            right++ ;


        }



        for(ll g = left ; g <= right ; g++ )
        {
            if(putb < arr[g].second)
            {
                putb = arr[g].second ;
                puta = arr[g].first ;
            }
        }


        arr.erase(arr.begin() + left , arr.begin()+ right ) ;
        arr.insert(arr.begin() + left , make_pair(puta , putb)) ;





            }
    }




    ll m = 0 ;
    for(ll i=0 ;i <arr.size()  ;i++)
    m = max(m , arr[i].second ) ;
printf("%lld\n" , m) ;

return   0 ;


}


Compiler output:
a.cc: In function 'int main()':
a.cc:79:7: error: 'n' was not declared in this scope
   79 | if(i>=n/2){
      |       ^
Language: C++

#include "utils.cpp"

// DP + セグメントツリー（RMQ）の問題
// DPテーブルは、「左からi本目までの花を考慮したときに、i番目の花を必ず残す場合の価値の最大値」
// 自分より左にあって、かつ高さが自分より低いものの中から最大値を選ぶ必要がある。それと自分自身の価値を足し合わせたものがDPテーブルの値になる。
// 高さhが低い順にDPテーブルを埋めていけば良い。DPテーブルの初期値を0にすることで、高さが注目している要素より大きいものは無視できるようになる。
ll dp[400004];

void update(ll i, ll x) {
    dp[i] = x;
    while (i > 0) {
        i = (i - 1) / 2;
        dp[i] = max(dp[i*2+1], dp[i*2+2]);
    }
}

// [a, b) の区間に対するクエリについて
// ノード k （区間 [l, r) 担当）が答える
ll query(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a || b <= l) return 0; // 区間がかぶらない場合単位元を返す
    if (a <= l && r <= b) return dp[k]; // 区間が完全に被っている場合
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(c1, c2);
    }
}

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n), a(n);
    vector<ll> idx(n);
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];

    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&h](ll i1, ll i2) {
        return h[i1] < h[i2];
    });

    ll N = 1;
    while (N < n) N *= 2;

    for (auto i : idx) {
        ll left_max = query(0, i, 0, 0, N);
        update(i + N - 1, a[i] + left_max);
    }

    cout << dp[0] << endl;

    return 0;
}

Compiler output:
a.cc:1:10: fatal error: utils.cpp: No such file or directory
    1 | #include "utils.cpp"
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int M=2e5+5;
int h[M],a[M];

LL bit[M];
inline lowbit(int x)
{
	return x&(-x);
}
void upd(int p,LL v)
{
	for(;p<M;p+=lowbit(p))
		bit[p]=max(bit[p],v);
}
LL getmx(int p)
{
	LL mx=0;
	for(;p;p-=lowbit(p))
		mx=max(mx,bit[p]);
	return mx;
}

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		int id=h[i];
		LL dp=getmx(id-1)+a[i];
		ans=max(ans,dp);
		upd(id,dp);
	}
	printf("%lld\n",ans);
	return 0;
}

Compiler output:
a.cc:9:8: error: ISO C++ forbids declaration of 'lowbit' with no type [-fpermissive]
    9 | inline lowbit(int x)
      |        ^~~~~~
Language: C++


n=int(input())
h=list(map(int,input().split()))
b=list(map(int,input().split()))
new_arr=[]
for i in range(n):
    new_arr.append([h[i],b[i],i])
new_arr.sort(key=lambda x: x[0])
new_arr=new_arr[::-1]

ans=[0 for i in range(n+1)]


for seq in new_arr:
    idx=seq[2]
    ans[idx]=max(ans[idx::])+seq[1]
print(max(ans))


Compiler output:
a.cc:2:1: error: 'n' does not name a type
    2 | n=int(input())
      | ^
Language: C++

#include<iostream>
#define  ll long long  int 
#define pb push_back
using namespace std ;
#include<bits/stdc++.h>
ll visi[10000][200001] , arr[10000][200001]  ;
ll high[100000] , val[100000] ;
ll n ;
ll doi(ll  minval , ll i)
{
    if(visi[minval][i]==1)
    return arr[minval][i] ;
    
    
    if(i==n-1)
    {
        visi[minval][i] =1 ;
        if(high[i]>=minval)
        {
            arr[minval][i] = val[i] ;
            
        }else
        {
            arr[minval][i] = 0 ;
        }
        return arr[minval][i] ;
    }
    
    if(high[i] >= minval)
    {
        arr[minval][i] = max(val[i] +doi(high[i] , i+1) , doi(minval , i+1)) ;
    }else
    {
        arr[minval][i] = doi(minval , i+1) ;
    }
        visi[minval][i] =1 ;
        return arr[minval][i] ;
    
}




int main()
{
    cin >> n ;
    for (ll i=0 ; i < n ;i++)
    {
        cin >> high[i] ;
    }
    
    for (ll i=0 ; i < n ;i++)
    {
        cin >> val[i] ;
    }
    
    
    cout<< doi(0 , 0) ;
    return  0 ;
}

Compiler output:
/tmp/ccUsw68m.o: in function `doi(long long, long long)':
a.cc:(.text+0x59): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0xd0): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0xf5): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x11c): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x145): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x161): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x19d): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x1bc): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccUsw68m.o
a.cc:(.text+0x209): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#define  ll long long  int 
#define pb push_back
using namespace std ;
#include<bits/stdc++.h>
ll visi[1000000000][200001] , arr[10000000][200001]  ;
ll high[100000] , val[100000] ;
ll n ;
ll doi(ll  minval , ll i)
{
    if(visi[minval][i]==1)
    return arr[minval][i] ;
    
    
    if(i==n-1)
    {
        visi[minval][i] =1 ;
        if(high[i]>=minval)
        {
            arr[minval][i] = val[i] ;
            
        }else
        {
            arr[minval][i] = 0 ;
        }
        return arr[minval][i] ;
    }
    
    if(high[i] >= minval)
    {
        arr[minval][i] = max(val[i] +doi(high[i] , i+1) , doi(minval , i+1)) ;
    }else
    {
        arr[minval][i] = doi(minval , i+1) ;
    }
        visi[minval][i] =1 ;
        return arr[minval][i] ;
    
}




int main()
{
    cin >> n ;
    for (ll i=0 ; i < n ;i++)
    {
        cin >> high[i] ;
    }
    
    for (ll i=0 ; i < n ;i++)
    {
        cin >> val[i] ;
    }
    
    
    cout<< doi(0 , 0) ;
    return  0 ;
}

Compiler output:
/tmp/ccrN9wIp.o: in function `doi(long long, long long)':
a.cc:(.text+0x59): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0xd0): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0xf5): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x11c): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x145): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x161): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x19d): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x1bc): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccrN9wIp.o
a.cc:(.text+0x209): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#define  ll long long  int 
#define pb push_back
using namespace std ;
#include<bits/stdc++.h>
ll visi[100000][100000] , arr[100000][100000]  ;
ll high[100000] , val[100000] ;
ll n ;
ll doi(ll  minval , ll i)
{
    if(visi[minval][i]==1)
    return arr[minval][i] ;
    
    
    if(i==n-1)
    {
        visi[minval][i] =1 ;
        if(high[i]>=minval)
        {
            arr[minval][i] = val[i] ;
            
        }else
        {
            arr[minval][i] = 0 ;
        }
        return arr[minval][i] ;
    }
    
    if(high[i] >= minval)
    {
        arr[minval][i] = max(val[i] +doi(high[i] , i+1) , doi(minval , i+1)) ;
    }else
    {
        arr[minval][i] = doi(minval , i+1) ;
    }
        visi[minval][i] =1 ;
        return arr[minval][i] ;
    
}




int main()
{
    cin >> n ;
    for (ll i=0 ; i < n ;i++)
    {
        cin >> high[i] ;
    }
    
    for (ll i=0 ; i < n ;i++)
    {
        cin >> val[i] ;
    }
    
    
    cout<< doi(0 , 0) ;
    return  0 ;
}

Compiler output:
/tmp/ccMxNmTW.o: in function `doi(long long, long long)':
a.cc:(.text+0x59): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0xd0): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0xf5): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x11c): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x145): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x161): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x19d): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x1bc): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/ccMxNmTW.o
a.cc:(.text+0x209): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include<iostream>
#define  ll long long  int 
#define pb push_back
using namespace std ;
#include<bits/stdc++.h>
ll visi[1000000001][100001] , arr[1000000001][100001]  ;
ll high[100000] , val[100000] ;
ll n ;
ll doi(ll  minval , ll i)
{
    if(visi[minval][i]==1)
    return arr[minval][i] ;
    
    
    if(i==n-1)
    {
        visi[minval][i] =1 ;
        if(high[i]>=minval)
        {
            arr[minval][i] = val[i] ;
            
        }else
        {
            arr[minval][i] = 0 ;
        }
        return arr[minval][i] ;
    }
    
    if(high[i] >= minval)
    {
        arr[minval][i] = max(val[i] +doi(high[i] , i+1) , doi(minval , i+1)) ;
    }else
    {
        arr[minval][i] = doi(minval , i+1) ;
    }
        visi[minval][i] =1 ;
        return arr[minval][i] ;
    
}




int main()
{
    cin >> n ;
    for (ll i=0 ; i < n ;i++)
    {
        cin >> high[i] ;
    }
    
    for (ll i=0 ; i < n ;i++)
    {
        cin >> val[i] ;
    }
    
    
    cout<< doi(0 , 0) ;
    return  0 ;
}

Compiler output:
/tmp/cceACWJG.o: in function `doi(long long, long long)':
a.cc:(.text+0x59): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0xd0): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0xf5): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x11c): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x145): relocation truncated to fit: R_X86_64_PC32 against symbol `arr' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x161): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x19d): relocation truncated to fit: R_X86_64_PC32 against symbol `val' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x1bc): relocation truncated to fit: R_X86_64_PC32 against symbol `high' defined in .bss section in /tmp/cceACWJG.o
a.cc:(.text+0x209): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include <bits/stdc++.h>
#include "../lib/segmenttree/segtree_update_max.hpp"

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<P> v(n);
  vll a(n);

  for(int i=0;i<n;++i) {
    cin >> v[i].first;
    v[i].second = i;
  }
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  sort(v.begin(), v.end());


  vll init(n, 0);

  SegmentTreeUpdMax<ll> st(init);
  for(int i=0;i<n;++i) {
    int now = v[i].second;
    ll val = st.query(0, now+1);
    st.update(now, val + a[now]);
  }

  cout << st.query(0, n) << endl;
  

}


Compiler output:
a.cc:2:10: fatal error: ../lib/segmenttree/segtree_update_max.hpp: No such file or directory
    2 | #include "../lib/segmenttree/segtree_update_max.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: Java

class Main{
  public static long solve2(int[] h, int[] b){
        long ans = Integer.MIN_VALUE;
        int[] dp = new int[h.length];
        for(int i = 0; i < b.length; i++){
            dp[i] = b[i];
        }
        for(int i = 1; i < h.length; i++){
            for(int j = 0; j < i; j++){
                if(h[i] > h[j] && dp[i] < dp[j]+b[i]){
                    dp[i] = b[i] + dp[j];
                }
            }
        }
        //System.out.println(Arrays.toString(dp));
        for(int i = 0; i < b.length; i++){
            if(ans < dp[i]){
                ans = dp[i];
            }
        }
        return ans;
    }
  public static void main(String args[]) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer str;
      int n = Integer.parseInt(br.readLine());
      int[] h = new int[n];
      int[] b = new int[n];
      str = new StringTokenizer(br.readLine()," ");
      int i = 0;
      while(str.hasMoreTokens()){
          h[i] = Integer.parseInt(str.nextToken());
          i++;
      }
      str = new StringTokenizer(br.readLine()," ");
      i = 0;
      while(str.hasMoreTokens()){
          b[i] = Integer.parseInt(str.nextToken());
          i++;
      }
    
      System.out.println(solve2(h, b));
      
    }
}

Compiler output:
Main.java:24: error: cannot find symbol
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      ^
  symbol:   class BufferedReader
  location: class Main
Main.java:24: error: cannot find symbol
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                              ^
  symbol:   class BufferedReader
  location: class Main
Main.java:24: error: cannot find symbol
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                                                 ^
  symbol:   class InputStreamReader
  location: class Main
Main.java:25: error: cannot find symbol
      StringTokenizer str;
      ^
  symbol:   class StringTokenizer
  location: class Main
Main.java:29: error: cannot find symbol
      str = new StringTokenizer(br.readLine()," ");
                ^
  symbol:   class StringTokenizer
  location: class Main
Main.java:35: error: cannot find symbol
      str = new StringTokenizer(br.readLine()," ");
                ^
  symbol:   class StringTokenizer
  location: class Main
6 errors
Language: Java

import java.util.*;
import java.io.*;
public class Main {
    public static long solve(int[] h, int[] b, int i, int prev, long[][] dp){
        if(i >= h.length){
            return 0;
        }
        if(dp[i][prev+1] > -1){
            return dp[i][prev+1];
        }
        long ans = Integer.MIN_VALUE;
        if(prev < 0 || h[i] > h[prev]){
            ans = Math.max(ans, b[i] + solve(h, b, i+1, i, dp));
        }
        ans = Math.max(ans, solve(h, b, i+1, prev, dp));
        return dp[i][prev+1] = ans;
        
    }
    public static void main(String args[]) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer str;
      int n = Integer.parseInt(br.readLine());
      int[] h = new int[n];
      int[] b = new int[n];
      str = new StringTokenizer(br.readLine()," ");
      int i = 0;
      while(str.hasMoreTokens()){
          h[i] = Integer.parseInt(str.nextToken());
          i++;
      }
      str = new StringTokenizer(br.readLine()," ");
      i = 0;
      while(str.hasMoreTokens()){
          b[i] = Integer.parseInt(str.nextToken());
          i++;
      }
      long[][] dp = new long[n+1][n+1];
      for(int i = 0; i < dp.length; i++){
          for(int j = 0; j < dp.length; j++){
              dp[i][j] = -1;
          }
      }
      System.out.println(solve(h, b, 0, -1, dp));
    }
}

Compiler output:
Main.java:38: error: variable i is already defined in method main(String[])
      for(int i = 0; i < dp.length; i++){
              ^
1 error
Language: Java

import java.io.*;
import java.util.*;

class Main {

    public static long memo(int[] flowers, int[] price, int n, int prev, long[][] memo){
        if(n < 0)
            return 0;
        if(memo[prev+1][n] > 0){
        
            return memo[prev+1][n];
        }
        long ans = Long.MIN_VALUE;
        if(prev == -1 || flowers[prev] > flowers[n])
        ans = Math.max(ans, price[n] + memo(flowers,price,n-1,n,memo));
        ans = Math.max(ans, 0 + memo(flowers,price,n-1,prev,memo));
        
        return memo[prev+1][n] = ans;
    }
    
    public static long solve(int[] flowers, int[] price){

        long[] dp = new long[flowers.length];
        for(int i = 0; i < flowers.length; i++)
            dp[i] = price[i];
            
        for(int i = 0; i < price.length; i++){
            for(int j = i-1; j >= 0; j--){
                if(flowers[j] < flowers[i]){
                    long current = dp[j] + price[i];
                    if(dp[i] < current)
                        dp[i] = current;
                }
            }
        }

        long ans = Long.MIN_VALUE;
        for(long i : dp)
            ans = Math.max(ans,i);
        return ans;
    }
    

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine().trim());
        int flowers[] = new int[n];
        int price[] = new int[n];

        StringTokenizer token = new StringTokenizer(br.readLine().trim(), " ");
        int i = 0;
        while(token.hasMoreTokens()){
            flowers[i] = Integer.parseInt(token.nextToken());
            i++;
        }
        
        i = 0;
        token = new StringTokenizer(br.readLine().trim(), " ");
        while(token.hasMoreTokens()){
            price[i] = Integer.parseInt(token.nextToken());
            i++;
        }

        
        i = 0;
        long[][] memo = new long[10000000000][10000000000];
        // for(i = 0; i < memo.length; i++)
        //     Arrays.fill(memo[i],-1l);
        
       // System.out.println(solve(flowers,price));
        System.out.println(memo(flowers,price,n-1,-1,memo));
    }
}

Compiler output:
Main.java:66: error: integer number too large
        long[][] memo = new long[10000000000][10000000000];
                                 ^
Main.java:66: error: integer number too large
        long[][] memo = new long[10000000000][10000000000];
                                              ^
2 errors
Language: C++

#include <bits/stdc++.h>
using namespace std;
int n;
int h[200005];
long long a[200005];
long long bit[200005],dp[200005];
inline void modify(int p,long long v){
	for(int i=p+1;i<=200003;i+=(i&-i){
		bit[i]=max(bit[i],v);
	}
}
inline long long query(int p){
	long long res=0;
	for(int i=p;i;i-=(i&-i){
		res=max(res,bit[i]);
	}
	return res;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>h[i];
	}
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	for(int i=1;i<=200003;++i){
		bit[i]=-2e15;
		dp[i]=-2e15;
	}
	modify(0,0);
	dp[0]=0;
	for(int i=1;i<=n;++i){
		dp[h[i]]=max(dp[h[i]],query(h[i])+a[i]);
		modify(h[i],dp[h[i]]);
	}
	cout<<query(n+1)<<'\n';
	return 0;
}

Compiler output:
a.cc: In function 'void modify(int, long long int)':
a.cc:8:42: error: expected ')' before '{' token
    8 |         for(int i=p+1;i<=200003;i+=(i&-i){
      |            ~                             ^
      |                                          )
a.cc: In function 'long long int query(int)':
a.cc:14:32: error: expected ')' before '{' token
   14 |         for(int i=p;i;i-=(i&-i){
      |            ~                   ^
      |                                )
Language: Java

public class Main
{
  public static void main(String args[])
  {int n;
      Scanner sc=new Scanner(System.in);
      n=sc.nextInt();
      int a[]=new int[n];
      int h[]=new int[n];
      for(int i=0;i<n;i++)
      {
          h[i]=sc.nextInt();
          a[i]=sc.nextInt();
      }
        int ans=0;
        int dp[]=new int[n];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {if(h[j]<h[i])
                
                dp[i]=Math.max(dp[i],dp[j]+a[i]);
            
            else
            {
                dp[i]=a[i];
            }
        }
            if(dp[i]>ans)
            { 
              
            ans=dp[i];
            
        }
        
      
    }
     System.out.println(ans);
      
}
}

Compiler output:
Main.java:5: error: cannot find symbol
      Scanner sc=new Scanner(System.in);
      ^
  symbol:   class Scanner
  location: class Main
Main.java:5: error: cannot find symbol
      Scanner sc=new Scanner(System.in);
                     ^
  symbol:   class Scanner
  location: class Main
2 errors
Language: Java


import java.io.InputStreamReader;
import java.util.Scanner;

import static java.lang.Math.max;


public class Solution {


    int MAXN = (int) (2 * 1e5 + 10);

    int N;
    long[] bit = new long[MAXN];
    int[] h = new int[MAXN];
    int[] a = new int[MAXN];
    long[] dp = new long[MAXN];

    int LSOne(int S) {
        return S & -S;
    }

    void update(int x, long val) {
        while (x <= N) {
            bit[x] = max(bit[x], val);
            x += LSOne(x);
        }
    }

    long query(int x) {
        long ans = 0;
        while (x > 0) {
            ans = max(ans, bit[x]);
            x -= LSOne(x);
        }
        return ans;
    }


    int go() {
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        N = scanner.nextInt();


        for (int i = 1; i <= N; i++) {
            h[i] = scanner.nextInt();
        }
        for (int i = 1; i <= N; i++) {
            a[i] = scanner.nextInt();
        }
        for (int flower = 1; flower <= N; flower++) {
            dp[flower] = query(h[flower] - 1) + a[flower];
            update(h[flower], dp[flower]);
        }
        long best = 0;
        for (int i = 0; i <= N; i++) {
            best = max(best, dp[i]);

        }
        System.out.printf("%d\n", best);
        return 0;
    }


    public static void main(String[] args) {

        Solution f = new Solution();
        f.go();

    /*
    4
3 1 4 2
10 20 30 40
answer : 60

     */
    }
}


Compiler output:
Main.java:8: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
1 error
Language: C++

     #include<bits/stdc++.h>
         
        using namespace std;
        typedef long long int lld;
        #define INF 1000000000000000000
        #define MOD 1000000007
        int n;
        lld FT[1000000];
        void upd(int pos, lld val){
        	for(int i=pos;i<=n;i+=(i&(-i))){
        		FT[i]=max(FT[i],val);
        	}
        }
        lld ans(int pos){
        	lld ans=0;
        	for(int i=pos;i>0;i-=(i&(-i))){
        		ans=max(FT[i],ans);
        	}return ans;
        }
        int main(){
        	cin>>n;
        	int per[n];
        	for(int i=0;i<n;i++)scanf("%d",&per[i]);
        	for(int i=0;i<=n;i++)FT[i]=0;
        	lld DP[n+1];
        	DP[0]=0;
            lld ans=0;
        	for(int i=0;i<n;i++){
        		lld x;
        		scanf("%lld",&x);
        		DP[i+1]=x+ans(per[i]);
        		upd(per[i],DP[i+1]);
                ans=max(ans,DP[i+1]);
        		//cout<<DP[i+1]<<endl;
        	}printf("%lld\n",ans);
        	
        	
        	return 0;
        }

Compiler output:
a.cc: In function 'int main()':
a.cc:31:38: error: 'ans' cannot be used as a function
   31 |                         DP[i+1]=x+ans(per[i]);
      |                                   ~~~^~~~~~~~
Language: C++

// IOI 2021
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

int H[N]
ll FEN[N];

void Add(int p, ll x) {
	for (p++; p < N; p += p & -p) FEN[p] = max(FEN[p], x);
}
ll Get(int p) {
	ll res = 0;
	for (; p > 0; p -= p & -p) res = max(res, FEN[p]);
	return res;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> H[i], H[i]--;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		x += Get(H[i]);
		Add(H[i], x);
	}
	cout << Get(n) << endl;

	return 0;
}


Compiler output:
a.cc:24:1: error: expected initializer before 'll'
   24 | ll FEN[N];
      | ^~
a.cc: In function 'void Add(int, ll)':
a.cc:27:39: error: 'FEN' was not declared in this scope
   27 |         for (p++; p < N; p += p & -p) FEN[p] = max(FEN[p], x);
      |                                       ^~~
a.cc: In function 'll Get(int)':
a.cc:31:51: error: 'FEN' was not declared in this scope
   31 |         for (; p > 0; p -= p & -p) res = max(res, FEN[p]);
      |                                                   ^~~
a.cc: In function 'int main()':
a.cc:40:44: error: 'H' was not declared in this scope
   40 |         for (int i = 0; i < n; i++) cin >> H[i], H[i]--;
      |                                            ^
a.cc:43:26: error: 'H' was not declared in this scope
   43 |                 x += Get(H[i]);
      |                          ^
Language: C++

#include <iostream>
#include <cstdio>
#include <set>
using namespace std;


long long int n, h[200010], w[200010], dp[200010],
				inde[200010], maxi;
set<int> setim;

int main(void){	
	//freopen("asd.in", "r", stdin);
	cin>>n;
	for(int i=0;i<n;i++){cin>>h[i];inde[h[i]]=i;}
	for(int i=0;i<n;i++)cin>>w[i];
	dp[inde[1]]=w[inde[1]];
	setim.insert(inde[1]);
	maxi=w[inde[1]];
	for (int i = 2; i <= n; ++i){
		set<int>::iterator konum=setim.upper_bound(inde[i]);
		if(konum!=setim.begin()){
			dp[inde[i]]=w[inde[i]]+dp[*(--konum)];
			maxi=max(maxi, dp[inde[i]]);
			for(set<int>::iterator j=++konum;j!=setim.end()&&dp[inde[i]]>dp[*(j)])
				setim.erase(j);
		}else{
			dp[inde[i]]=w[inde[i]];
			maxi=max(maxi, dp[inde[i]]);
			for(set<int>::iterator j=konum;dp[inde[i]]>dp[*(j)];j++)setim.erase(j);
		}
		setim.insert(inde[i]);
	}
	cout<<maxi;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:94: error: expected ';' before ')' token
   24 |                         for(set<int>::iterator j=++konum;j!=setim.end()&&dp[inde[i]]>dp[*(j)])
      |                                                                                              ^
      |                                                                                              ;
Language: C++

#include <iostream>
#include <cstring>
using namespace std;

long long int n, h[200010], w[200010], dp[200010], index[200010], maxi;

int main(void){	
	cin>>n;
	for(int i=0;i<n;i++){cin>>h[i];index[h[i]]=i;}
	for(int i=0;i<n;i++)cin>>w[i];
	for (int i = 1; i <= n; ++i){
		dp[i]=w[index[i]];
		for (int j = i-1; j >0; j--){
			if(index[i]<index[j])continue;
			dp[i]=max(dp[i], dp[j]+w[index[i]]);
		}
		maxi=max(maxi, dp[i]);
	}
	cout<<maxi;

	return 0;
}

Compiler output:
a.cc:5:64: error: 'long long int index [200010]' redeclared as different kind of entity
    5 | long long int n, h[200010], w[200010], dp[200010], index[200010], maxi;
      |                                                                ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:2:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:9:45: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
    9 |         for(int i=0;i<n;i++){cin>>h[i];index[h[i]]=i;}
      |                                             ^
a.cc:12:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   12 |                 dp[i]=w[index[i]];
      |                              ^
a.cc:14:33: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   14 |                         if(index[i]<index[j])continue;
      |                                 ^
a.cc:14:42: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   14 |                         if(index[i]<index[j])continue;
      |                                          ^
a.cc:15:55: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   15 |                         dp[i]=max(dp[i], dp[j]+w[index[i]]);
      |                                                       ^
Language: C++

#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

ll tree[4*200003],a[200003],h[200003],dp[200003];

void build(int node,int start,int end){
	if(start == end){
		tree[node] = 0;
	}
	else{
		int m = (start+end)/2;
		build(2*node,start,m);
		build(2*node+1,m+1,end);
		tree[node] = max(tree[node*2],tree[node*2+1]);
	}
}

void update(int node,int start,int end,int idx,ll val){
	if(start == end){
		tree[node] = max(val,tree[node]);
	}
	else{
		int m = (start+end)/2;
		if(idx>=start && idx<=m)
		{
			update(2*node,start,m,idx,val);
		}
		else{
			update(2*node+1,m+1,end,idx,val);
		}
		tree[node] = max(tree[node*2],tree[node*2+1]);
	}
}

ll query(int node,int l,int r,int start,int end){
	if(r<start || l>end){
		return 0;
	}
	if(l<=start && r>=end){
		return tree[node];
	}

	int m = (start+end)/2;
	return max(query(2*node,l,r,start,m),query(2*node+1,l,r,m+1,end));

}
int main(){
	int n,i;
	scanf("%d",&n);
	build(1,1,n);
	for(i=1;i<=n;i++){
		scanf("%lld",&h[i]);
	}
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	dp[0]=0;
	for(i=1;i<=n;i++){
		ll val = a[i] + query(1,1,h[i]-1,1,n);
		update(1,1,n,h[i],val);
		dp[i]= max(dp[i-1],val); 
	}
	ll ans=dp[n]
	printf("%lld\n",ans );
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:9: error: expected ',' or ';' before 'printf'
   69 |         printf("%lld\n",ans );
      |         ^~~~~~
Language: C++

#include <iostream>
using namespace std;

long long* h;

bool f(long long p, long long q)
{
    return h[p] < h[q];
}

int main()
{
    long long N;
    cin >> N;
    h = new long long[N+1];
    long long a[N+1];
    for(long long i = 1; i <= N; i++) cin >> h[i];
    for(long long i = 1; i <= N; i++) cin >> a[i];

    long long ind[N];
    for(long long i = 0; i < N; i++) ind[i] = i+1;
    sort(ind, ind+N, f);

    long long BIT[N+1];
    for(long long i = 1; i <= N; i++) BIT[i] = 0;

    long long r, res = 0;
    for(long long i: ind)
    {
        r = a[i];
        for(long long j = i-1; j >= 1; j -= j&-j) r = max(r, BIT[j] + a[i]);
        res = max(res, r);
        for(long long j = i; j <= N; j += j&-j) BIT[j] = max(BIT[j], r);
    }
    cout << res << '\n';
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   22 |     sort(ind, ind+N, f);
      |     ^~~~
      |     short
Language: C++

#include <bits/stdc++.h>
#define N 200010
using namespace std;
typedef long long ll;

ll a[N],h[N];
ll dp[N],bit[N];
int n;

void add(int x,ll y)
{
    for(;x<=n;x+=lowbit(x)) bit[x] = max(bit[x],y);
}

ll query(int x)
{
    ll res = 0;
    for(;x;x-=lowbit(x)) res = max(res,bit[x]);
    return res;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        dp[i] = query(h[i]+a[i]);
        add(h[i],dp[i]);
    }
    cout<<query(n)<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'void add(int, ll)':
a.cc:12:18: error: 'lowbit' was not declared in this scope
   12 |     for(;x<=n;x+=lowbit(x)) bit[x] = max(bit[x],y);
      |                  ^~~~~~
a.cc: In function 'll query(int)':
a.cc:18:15: error: 'lowbit' was not declared in this scope
   18 |     for(;x;x-=lowbit(x)) res = max(res,bit[x]);
      |               ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int n, h[200005], a[200005];
long long ans = 0, dp[200005], st[400005] = {0};
void update (int pos, ll x) {
  	pos += n - 1;	
  	st[pos] = x;
  	do {
      	pos /= 2;
    	st[pos] = max (st[pos << 1], st[pos << 1 | 1]);
    } while (pos);
}
long long query (int pos) {
  	pos += n - 1;
	long long c = 0;
  	while (pos) {
    	c = max (c, st[pos]);
      	pos = (pos ^ 1) >> 1;
    }
  	return c;
}
int main () {
	cin >> n;
  	for (int i = 1; i <= n; i++) {
    	cin >> a[i];
    }
  	for (int i = 1; i <= n; i++) {
    	cin >> h[i];
    }
  	update (h[1], a[1]);
  	ans = a[1];
  	for (int i = 2; i <= n; i++) {
      	long long c = a[i] + query (h[i]);
      	ans = max (c, ans);
      	update (h[i], c);
    }
  	cout << ans << '\n';
}

Compiler output:
a.cc:6:23: error: 'll' has not been declared
    6 | void update (int pos, ll x) {
      |                       ^~
Language: C++

#include <iostream>
#include <limits>
using namespace std;
const int N = 2e5 + 5;
int a[N], h[N];
long long seg[4 * N];
long long dp[N];

long long query(int l, int r, int start, int end, int pos) {
	
	if (start >= l && end <= r) {  // [start [l , r] end]
		return seg[pos];
	}

    if (r < start || l > end)
		return INT_MIN;
	int mid = (start + end) >> 1;
	long long Left = query(l, r, start, mid, 2 * pos);
	long long right = query(l, r, mid + 1, end, 2 * pos + 1);
	return max(Left, right);
}
void update(int updateIndex, long long value, int start, int end, int pos) {
	if (start == end) {
		seg[pos] = value;
		return;
	}
	int mid = (start + end) >> 1;
	if (mid >= updateIndex) {
		update(updateIndex, value, start, mid, 2 * pos);
	}
	else {
		update(updateIndex, value, mid + 1, end, 2 * pos + 1);
	}
    seg[pos] = max(seg[2 * pos], seg[2 * pos + 1]);
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for (int i = 0; i < n; i++) {
		long long leftmax = query(0, h[i], 0, n, 1);
        //cout << leftmax << " \n";
        dp[i] = leftmax + a[i];
		update(h[i], dp[i], 0, n, 1);
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans;
	return 0;
}


Compiler output:
a.cc: In function 'long long int query(int, int, int, int, int)':
a.cc:16:24: error: 'INT_MIN' was not declared in this scope
   16 |                 return INT_MIN;
      |                        ^~~~~~~
a.cc:3:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <limits>
  +++ |+#include <climits>
    3 | using namespace std;
Language: C++

#include "iostream"
using namespace std;
const int N = 2e5 + 5;
int a[N], h[N];
long long seg[4 * N];
long long dp[N];

long long query(int l, int r, int start, int end, int pos) {
	
	if (start >= l && end <= r) {  // [start [l , r] end]
		return seg[pos];
	}

    if (r < start || l > end)
		return INT_MIN;
	int mid = (start + end) >> 1;
	long long Left = query(l, r, start, mid, 2 * pos);
	long long right = query(l, r, mid + 1, end, 2 * pos + 1);
	return max(Left, right);
}
void update(int updateIndex, long long value, int start, int end, int pos) {
	if (start == end) {
		seg[pos] = value;
		return;
	}
	int mid = (start + end) >> 1;
	if (mid >= updateIndex) {
		update(updateIndex, value, start, mid, 2 * pos);
	}
	else {
		update(updateIndex, value, mid + 1, end, 2 * pos + 1);
	}
    seg[pos] = max(seg[2 * pos], seg[2 * pos + 1]);
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for (int i = 0; i < n; i++) {
		long long leftmax = query(0, h[i], 0, n, 1);
        //cout << leftmax << " \n";
        dp[i] = leftmax + a[i];
		update(h[i], dp[i], 0, n, 1);
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans;
	return 0;
}


Compiler output:
a.cc: In function 'long long int query(int, int, int, int, int)':
a.cc:15:24: error: 'INT_MIN' was not declared in this scope
   15 |                 return INT_MIN;
      |                        ^~~~~~~
a.cc:2:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    1 | #include "iostream"
  +++ |+#include <climits>
    2 | using namespace std;
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define ll long long

ll int dp[200005];
int next[200005];
int harr[200005];
int carr[200005];
int n;


ll int kil(int idx)
{
  if(idx == n)
    return 0;

  if(dp[idx] != -1)
    return dp[idx];

  dp[idx] = max(dp[idx], kil(next[idx]) + carr[idx]);
  dp[idx] = max(dp[idx], kil(idx+1));

  return dp[idx];
}

int main()
{
  memset(dp, -1, sizeof dp);
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>harr[i];

  for(int i=0;i<n;i++)
    cin>>carr[i];

  for(int i=0;i<n;i++)
  {
    int y = n;
    for(int j=i+1;j<n;j++)
      if(harr[j] >= harr[i])
      {
        y = j;
        break;
      }
    next[i] = y;
  }

  cout<<kil(0)<<endl;

  return 0;
}


Compiler output:
a.cc: In function 'long long int kil(int)':
a.cc:21:30: error: reference to 'next' is ambiguous
   21 |   dp[idx] = max(dp[idx], kil(next[idx]) + carr[idx]);
      |                              ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [200005]'
    7 | int next[200005];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:46:5: error: reference to 'next' is ambiguous
   46 |     next[i] = y;
      |     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [200005]'
    7 | int next[200005];
      |     ^~~~
Language: Java



import java.util.Scanner;

public class Q {

	private static Scanner in;
	
	private static int n;
	private static int[] h;
	private static int[] v;
	private static final int MOD = (int)1e9+7;
	private static long[] seg;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		h =  new int[n];
		v =  new int[n];
		for(int i=0; i<n; i++) {
			h[i] = in.nextInt();
		}

		for(int i=0; i<n; i++) {
			v[i] = in.nextInt();
		}
		
		int m = 4*(int)1e6;
		seg = new long[m];
		
		for(int i=n-1; i>=0; i--) {
			long value = query(h[i]+1, (int)1e6, 0, 4*n-1, 0);
			
			update(h[i], value+v[i], 0, 4*n-1, 0);
		}
		
		System.out.println(query(0, (int)1e6, 0, 4*n-1, 0));
		
	}
	
	private static long query(int qlow, int qhigh, int low, int high, int pos) {
		if (qlow>high || low>qhigh) {
			return -(long)1e15;
		} else if (qlow<=low && qhigh>=high) {
			return seg[pos];
		} else {
			int mid = (low+high)/2;
			return Math.max(query(qlow, qhigh, low, mid, 2*pos+1), query(qlow, qhigh, mid+1, high, 2*pos+2));
		}
	}
	
	private static void update(int index, long v, int low, int high, int pos) {
		if (low==high) {
			seg[pos] = Math.max(seg[pos], v);
			return;
		}
		
		int mid = (low+high)/2;
		if (index<=mid) {
			update(index, v, low, mid, 2*pos+1);
		} else {
			update(index, v, mid+1, high, 2*pos+2);
		}
		
		seg[pos] = Math.max(seg[2*pos+1], seg[2*pos+2]);
		
		
	}
	
	

}


Compiler output:
Main.java:5: error: class Q is public, should be declared in a file named Q.java
public class Q {
       ^
1 error