← Home
For problem statement at 1000-1999/1400-1499/1400-1409/1402/problemA.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1400-1409/1402/verifierA.go ends with build oracle failed: exit status 1
# command-line-arguments
./1402A.go:83:21: cannot use inv2 (variable of type int) as int64 value in argument to mul
./1402A.go:120:18: cannot use inv2 (variable of type int) as int64 value in argument to mul

exit status 1 can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const MOD = 1000000007
const INV2 = 500000004

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	// Increase buffer size to handle long lines (up to ~2MB for 10^5 integers)
	const maxCapacity = 2048 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	if !scanner.Scan() {
		return
	}
	n, _ := strconv.Atoi(scanner.Text())

	h := make([]int, n)
	w := make([]int, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())
		h[i] = val
	}

	for i := 0; i < n; i++ {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())
		w[i] = val
	}

	// Prefix sums of widths modulo MOD
	p := make([]int, n+1)
	p[0] = 0
	for i := 0; i < n; i++ {
		p[i+1] = (p[i] + w[i]) % MOD
	}

	left := make([]int, n)
	right := make([]int, n)
	stack := make([]int, 0, n)

	// Calculate Nearest Smaller Element to the Left
	for i := 0; i < n; i++ {
		for len(stack) > 0 && h[stack[len(stack)-1]] >= h[i] {
			stack = stack[:len(stack)-1]
		}
		if len(stack) == 0 {
			left[i] = -1
		} else {
			left[i] = stack[len(stack)-1]
		}
		stack = append(stack, i)
	}

	stack = stack[:0]
	// Calculate Nearest Smaller or Equal Element to the Right
	for i := n - 1; i >= 0; i-- {
		for len(stack) > 0 && h[stack[len(stack)-1]] > h[i] {
			stack = stack[:len(stack)-1]
		}
		if len(stack) == 0 {
			right[i] = n
		} else {
			right[i] = stack[len(stack)-1]
		}
		stack = append(stack, i)
	}

	totalFancy := 0
	for i := 0; i < n; i++ {
		// Calculate total width of the valid range for h[i]
		wTotal := (p[right[i]] - p[left[i]+1] + MOD) % MOD
		
		// Calculate width of the part strictly to the left of section i
		wLeft := (p[i] - p[left[i]+1] + MOD) % MOD
		
		// Calculate width of the part strictly to the right of section i
		wRight := (p[right[i]] - p[i+1] + MOD) % MOD

		// Number of valid horizontal intervals crossing section i
		// Total intervals - intervals strictly left - intervals strictly right
		cnt := (calc(wTotal) - calc(wLeft) - calc(wRight) + 2*MOD) % MOD
		
		// Multiply by valid vertical intervals (1..h[i])
		term := (int64(cnt) * int64(calc(h[i]))) % MOD
		totalFancy = (totalFancy + int(term)) % MOD
	}

	fmt.Println(totalFancy)
}

// Calculates n*(n+1)/2 % MOD
func calc(n int) int {
	v := int64(n)
	return int(v * (v + 1) % MOD * INV2 % MOD)
}
```