use std::io::{self, *};

fn main() {
    let mut stdin = io::stdin();
    let mut input = String::new();
    stdin.read_to_string(&mut input).unwrap();
    let mut tokens = input.split_whitespace();

    let mut n = tokens.next().unwrap().parse::<i32>().unwrap();
    let mut weapons = Vec::new();
    for _ in 0..n {
        let weapon = tokens.next().unwrap().parse::<i32>().unwrap();
        weapons.push(weapon);
    }

    let mut count = 0;

    let mut g = tokens.next().unwrap().parse::<i32>().unwrap();
    for _ in 0..g {
        let left = tokens.next().unwrap().parse::<usize>().unwrap();
        let right = tokens.next().unwrap().parse::<usize>().unwrap();
        if right - left >= 50 {
            count += 1;
        } else {
            let mut temp = weapons[(left - 1)..right].to_vec();
            temp.sort_unstable();
            let found = temp
                .windows(3)
                .any(|win| win[0] + win[1] > win[2]);
            if found { count += 1; }
        }
    }
    print!("{}", count);
}