package main import ( "bufio" "fmt" "os" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var out = bufio.NewWriter(os.Stdout) func solveHonestly(n int, a, b []int) int { var ans int for i := 0; i < n-1; i++ { for j := i + 1; j < n; j++ { if a[i]+Max(b[i], b[j]) < a[j]+Min(b[i], b[j]) { fmt.Println(i, j) ans++ } else { break } } } return ans } func solve(n int, a, b []int) int { canWin := make([]bool, n) for i := 1; i < n; i++ { if b[i-1] < b[i] { canWin[i] = a[i-1]+b[i] < a[i]+b[i-1] } else { canWin[i] = a[i-1]+b[i-1] < a[i]+b[i] } } //fmt.Println(canWin) //番兵 canWin = append(canWin, false) var ans int var cnt int for i := 1; i < n; i++ { if canWin[i] { cnt++ } if !canWin[i+1] { ans += cnt * (cnt + 1) / 2 cnt = 0 } } return ans } func main() { buf := make([]byte, 1024*1024) sc.Buffer(buf, bufio.MaxScanTokenSize) sc.Split(bufio.ScanWords) n := nextInt() a := nextIntSlice(n) b := nextIntSlice(n) //ans := solveHonestly(n, a, b) ans := solve(n, a, b) PrintInt(ans) } func nextInt() int { sc.Scan() i, _ := strconv.Atoi(sc.Text()) return i } func nextIntSlice(n int) []int { s := make([]int, n) for i := range s { s[i] = nextInt() } return s } func PrintInt(x int) { defer out.Flush() fmt.Fprintln(out, x) } func Abs(x int) int { if x < 0 { return -x } return x } func Min(x, y int) int { if x < y { return x } return y } func Max(x, y int) int { if x < y { return y } return x }