In the disaster-recovery wing, machines are numbered in a line, and from machine i you can only "failover" to i+A[i] or i-A[i] — Rakib needs to know if a backup machine is reachable from the primary one. You are given N positions in a line and an array A of size N. From position i (1-indexed) you may jump to position i+A[i] or i-A[i], as long as the target is between 1 and N. Given a query (start, end), print "YES" if end is reachable from start, else "NO". Answer Q independent queries. Use BFS/DFS per query, or precompute smartly if Q is large.
Input
Line1: N. Line2: N integers (array A). Line3: Q. Next Q lines: start end.
Output
Q lines: "YES" or "NO".
Constraints
1 ≤ N ≤ 10^5, 1 ≤ Q ≤ 100
Sample Input
5 2 3 1 1 1 1 1 5
Sample Output
YES
Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.