Kitani is writing a song in the genre of “breakcore”. The drum parts and the piano part are already written. Let us assume that the song consists of 2 · n notes: n for each instrument. The notes for the piano are the pitch values, and the notes for the drum parts are the numbers of drum samples. We will represent them as integers from 1 to 109.
Kitani is interested in how varied the song is. We will measure variety by how many times a chosen segment of notes occurs in the song. An occurrence means an exact match for the drum part, and for the piano part — a match up to shifting all notes in the segment by some pitch.
Formally: let the array of integers a1, a2, …, an be the piano notes, and b1, b2, …, bn be the drum notes. Then the segment [l, r] occurs at position p (1 ≤ p ≤ n − (r − l)) if:
- bl + i = bp + i for all 0 ≤ i ≤ r − l,
- al + i − ap + i = al − ap for all 0 ≤ i ≤ r − l.
Kitani asks you to count how many times the segment [l, r] occurs.
Input
The first line contains an integer n (2 ≤ n ≤ 2· 105) — the length of arrays a and b.
The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109) — the piano notes.
The third line contains n integers b1, b2, …, bn (1 ≤ bi ≤ 109) — the drum notes.
The last, fourth line contains two integers l and r (1 ≤ l < r ≤ n) — the ends of the segment.
Output
Print a single integer — the number of occurrences of the given segment in the song.
Samples
| input | output |
|---|
7
1 2 3 2 3 4 3
1 2 2 1 2 2 1
1 3
| 2
|
9
1 2 3 4 5 7 8 9 10
1 1 2 2 1 1 1 1 2
1 2
| 3
|
Notes
In the first example, besides the segment [1, 3] itself, [4, 6] is also an occurrence.
In the second example, besides the segment [1, 2] itself, [6, 7] and [7, 8] are also occurrences.
Problem Author: Nikita Sobolev
Problem Source: The 2026 ICPC UrFU Qualification