Language: C++

package main

import "fmt"
var N, M int
var u, w, v int
var dp, arr []int64
var DP, mat [][]int
var vis, dist []int
var indeg, outdeg []int
var a, h []int
var bit []int64
const (
	MaxInt = 1<<31 - 1
	MinInt = -MaxInt - 1
	MOD = int(1e9) + 7
)

func maxArr(a []int64) int64 {
	res := a[0]
	for _,e := range a {
		if e > res { res = e }
	}
	return res
}

func buildMatrix(mat *[][]int, size int) {
	for i := range *mat {
		(*mat)[i] = make([]int, size)
	}
}

func addSelf(a *int, b int) {
	*a += b
}

func subSelf(a *int, b int) {
	*a -= b
}

func mul (a, b int) int {
	return a*b
}

func mulMOD(a, b int) int {
	return (a%MOD)*(b%MOD)%MOD
}

func addSelfMOD(a *int, b int) {
	addSelf(a, b)
	if *a > MOD {
		*a -= MOD
	}
}

func subSelfMOD(a *int, b int) {
	subSelf(a, b)
	if *a < 0 {
		*a += MOD
	}
}

func max(a, b int64) int64 {
	if a > b { return a }
	return b
}

func min(a, b int) int {
	if a < b { return a }
	return b
}

func abs(a int) int {
	if a < 0 { return -a }
	return a
}

// color: 0->w, 1->b
func dfs(u, parent int) (int, int) {
	w,b := 1,0 // -> children are white or it is black
	for _, e := range mat[u] {
		if e != parent {
			wc, bc := dfs(e, u)
			tmp := w
			w = mulMOD(bc,w)
			b = (mulMOD(tmp, wc) + mulMOD(b, bc+wc))%MOD
		}
	}
	return w, (w+b)%MOD
}

func count(i int) int64 {
	i++
	s := int64(0)
	for i > 0 {
		if bit[i] > s {
			s = bit[i]
		}
		i -= i&(-i)
	}
	return s
}
func update(i int , v int64) {
	i++
	for i <= N+1 {
		if bit[i] < v {
			bit[i] = v
		}
		i += i&(-i)
	}
}

func main() {
	_, e := fmt.Scanf("%d", &N)
	if e != nil {
		return
	}
	a = make([]int, N)
	h = make([]int, N)
	base := 1
	for base <= N {
		base *= 2
	}
	bit = make([]int64, 2*base)
	for i := 0; i < N; i++ {
		_, e := fmt.Scanf("%d", &h[i])
		if e != nil {
			return
		}
	}
	for i := 0; i < N; i++ {
		_, e := fmt.Scanf("%d", &a[i])
		if e != nil {
			return
		}
	}
	dp = make([]int64, N+1)
	for i:=0; i<N; i++ {
		dp[h[i]] = max(dp[h[i]], count(h[i])+int64(a[i]))
		update(h[i], dp[h[i]])
	}
	fmt.Println(maxArr(dp))
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:26:1: error: 'func' does not name a type
   26 | func buildMatrix(mat *[][]int, size int) {
      | ^~~~
a.cc:32:1: error: 'func' does not name a type
   32 | func addSelf(a *int, b int) {
      | ^~~~
a.cc:36:1: error: 'func' does not name a type
   36 | func subSelf(a *int, b int) {
      | ^~~~
a.cc:40:1: error: 'func' does not name a type
   40 | func mul (a, b int) int {
      | ^~~~
a.cc:44:1: error: 'func' does not name a type
   44 | func mulMOD(a, b int) int {
      | ^~~~
a.cc:48:1: error: 'func' does not name a type
   48 | func addSelfMOD(a *int, b int) {
      | ^~~~
a.cc:55:1: error: 'func' does not name a type
   55 | func subSelfMOD(a *int, b int) {
      | ^~~~
a.cc:62:1: error: 'func' does not name a type
   62 | func max(a, b int64) int64 {
      | ^~~~
a.cc:67:1: error: 'func' does not name a type
   67 | func min(a, b int) int {
      | ^~~~
a.cc:72:1: error: 'func' does not name a type
   72 | func abs(a int) int {
      | ^~~~
a.cc:78:1: error: 'func' does not name a type
   78 | func dfs(u, parent int) (int, int) {
      | ^~~~
a.cc:91:1: error: 'func' does not name a type
   91 | func count(i int) int64 {
      | ^~~~
a.cc:102:1: error: 'func' does not name a type
  102 | func update(i int , v int64) {
      | ^~~~
a.cc:112:1: error: 'func' does not name a type
  112 | func main() {
      | ^~~~