use std::io;

fn main()
{
    let mut n = String::new();
    let mut line1 = String::new();
    let mut line2 = String::new();

    io::stdin().read_line(&mut n).unwrap();
    io::stdin().read_line(&mut line1).unwrap();
    io::stdin().read_line(&mut line2).unwrap();
    let displays: Vec<&str> = line1.trim().split_whitespace().collect();
    let sizes: Vec<&str> = line2.trim().split_whitespace().collect();
    let mut pairs = Vec::new();
    for i in 0..n.trim().parse().unwrap()
    {
        pairs.push((displays[i].parse::<i32>().unwrap(), sizes[i].parse::<i32>().unwrap(), i as i32));
    }
    pairs.sort_by_key(|k| k.0);

    println!("{}", dfs(pairs.as_slice(), 0, 0));
}

fn dfs(pairs: &[(i32, i32, i32)], cnt: i32, sum: i32) -> i32
{
    if cnt == 3
    {
        sum
    }
    else if pairs.is_empty()
    {
        -1
    }
    else
    {
        let mut out = -1i32;
        for i in 0..pairs.len()
        {
            let mut part = pairs.split_at(i + 1).1;

            while let Some(&value) = part.first()
            {
                if value.0 > pairs[i].0 && value.2 > pairs[i].2
                {
                    let num = dfs(part, cnt + 1, sum + pairs[i].1);
                    if num != -1
                    {
                        if out == -1
                        {
                            out = num;
                        }
                        else
                        {
                            out = if num < out {num} else {out};
                        }
                    }
                }
                part = part.split_at(1).1;
            }
        }
        out
    }
}


use std::io;

fn main()
{
    let mut n = String::new();
    let mut line1 = String::new();
    let mut line2 = String::new();

    io::stdin().read_line(&mut n).unwrap();
    io::stdin().read_line(&mut line1).unwrap();
    io::stdin().read_line(&mut line2).unwrap();
    let displays: Vec<&str> = line1.trim().split_whitespace().collect();
    let sizes: Vec<&str> = line2.trim().split_whitespace().collect();
    let mut pairs = Vec::new();
    let n = n.trim().parse().unwrap();
    for i in 0..n
    {
        pairs.push((displays[i].parse::<i64>().unwrap(), sizes[i].parse::<i64>().unwrap(), i as i32));
    }
    pairs.sort_by_key(|k| k.1);
    let mut out = -1i64;
    let pirce = pairs.as_slice();
    for i in 0..pirce.len()
    {
        if out == -1
        {
            out = dfs(pirce.split_at(i).1, 0, 0, &pirce[i]);
        }
        else
        {
            break;
        }
    }

    println!("{}", out);
}

fn cmp(a: &(i64, i64, i32), b: &(i64, i64, i32), turn: &(i64, i64, i32)) -> bool
{
    if ((a.0 > b.0 && a.2 > b.2) || (a.0 < b.0 && a.2 < b.2)) && ((a.0 > turn.0 && a.2 > turn.2) || (a.0 < turn.0 && a.2 < turn.2))
    {
        true
    }
    else
    {
        false
    }
}

fn dfs(pairs: &[(i64, i64, i32)], cnt: i32, sum: i64, turn: &(i64, i64, i32)) -> i64
{
    if cnt == 2
    {
        sum + pairs[0].1
    }
    else
    {
        let mut out = -1i64;
        let mut part = pairs.split_at(1).1;
        while !part.is_empty()
        {
            if cmp(&part[0], &pairs[0], turn)
            {
                out = dfs(part, cnt + 1, sum + pairs[0].1, turn);
                if out != -1
                {
                    break;
                }
            }
            part = part.split_at(1).1;
        }
        out
    }
}


use std::io;
use std::io::Stdin;
use std::str::FromStr;

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_t<T : FromStr>(stdin : &Stdin) -> T {
    let mut line = String::new();
    read_line(stdin, &mut line);
    parse_t(&line)
}

fn read_ts<T : FromStr>(stdin : &Stdin, ts : &mut Vec<T>) {
    let mut line = String::new();
    read_line(stdin, &mut line);
    let word_iter = line.split_whitespace();
    for word in word_iter {
        let x = parse_t(word);
        ts.push(x);
    }
}

const INFINITY : u64 = u64::max_value();

fn min_cost_for_3_displays(n : usize,
                           ss : &Vec<u64>,
                           cs : &Vec<u64>) -> Option<u64> {
    let mut min_cost_3_displays = INFINITY;
    let mut min_cost_2_displays = vec![];
    // For each display ...
    for i in 0 .. n {
        // Find the min cost 3 display.
        for &(font_size, cost) in min_cost_2_displays.iter() {
            if ss[i] > font_size {
                let cost_3_displays = cost + cs[i];
                if cost_3_displays < min_cost_3_displays {
                    min_cost_3_displays = cost_3_displays;
                }
            }
        }
        // Find the min cost 2 display.
        let mut min_cost_2_display = INFINITY;
        for j in 0 .. i {
            if ss[j] < ss[i] {
                if cs[j] < min_cost_2_display {
                    min_cost_2_display = cs[j];
                }
            }
        }
        if min_cost_2_display == INFINITY {
            // Do nothing ...
        } else {
            min_cost_2_display = min_cost_2_display + cs[i];
            min_cost_2_displays.push((ss[i], min_cost_2_display));
        }
    }
    if min_cost_3_displays == INFINITY {
        None
    } else {
        Some(min_cost_3_displays)
    }
}

fn main() {
    let stdin = io::stdin();
    let n : usize = read_t(&stdin);
    let mut ss : Vec<u64> = vec![];
    read_ts(&stdin, &mut ss);
    let mut cs : Vec<u64> = vec![];
    read_ts(&stdin, &mut cs);
    // println!("{}", n);
    // println!("{:?}", ss);
    // println!("{:?}", cs);
    match min_cost_for_3_displays(n, &ss, &cs) {
        None => {
            println!("-1");
        },
        Some(c) => {
            println!("{}", c);
        },
    }
}


use std::io;

#[allow(dead_code)]
fn solve() -> Vec<String> {
    let mut input = "".split_ascii_whitespace();
    let mut read = || loop {
        if let Some(word) = input.next() {
            break word;
        }
        input = {
            let mut input = "".to_owned();
            io::stdin().read_line(&mut input).unwrap();
            if input.is_empty() {
                panic!("reached EOF");
            }
            Box::leak(input.into_boxed_str()).split_ascii_whitespace()
        };
    };
    macro_rules! read(($ty:ty) => (read().parse::<$ty>().unwrap()));

    let mut rr = vec!["".to_string(); 0];

    let t = 1;
    for _ in 0..t {
        let n = read!(usize);
        let mut a = vec![0; n];
        for i in 0..n {
            a[i] = read!(usize);
        }
        let mut b = vec![0; n];
        for i in 0..n {
            b[i] = read!(usize);
        }

        let mut r = 0;
        for j in 1..(n - 1) {
            let u = a[j];
            let mut t = b[j];
            let mut tl = 0;
            let mut tr = 0;
            for i in 0..j {
                if a[i] < u && (tl == 0 || tl > b[i]) {
                    tl = b[i];
                }
            }
            for k in (j + 1)..n {
                if a[k] > u && (tr == 0 || tr > b[k]) {
                    tr = b[k];
                }
            }
            if tl == 0 || tr == 0 {
                continue;
            }
            t += tl + tr;
            if r == 0 || r > t {
                r = t;
            }
        }

        rr.push(format!("{}", if r == 0 { -1 } else { r as i64 }));
    }

    rr
}

#[allow(dead_code)]
fn main() {
    let output = solve();
    println!("{}", output.join("\n"));
}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	s := make([]int, n)
	c := make([]int, n)
	fmt.Scanf("\n")
	for i := 0; i < n; i++ {
		var value int
		fmt.Scanf("%d", &value)
		s[i] = value
	}
	fmt.Scanf("\n")
	for i := 0; i < n; i++ {
		var value int
		fmt.Scanf("%d", &value)
		c[i] = value
	}

	mincost1 := make([]int, n)
	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost1[i] = c[i]
		mincost2[i] = 2147483647
		if i > 0 && mincost1[i] > mincost1[i-1] {
			mincost1[i] = mincost1[i-1]
		}
	}

	min := 2147483647
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+mincost1[j] < mincost2[i] {
						mincost2[i] = c[i] + mincost1[j]
					}
					x[i] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		x[i] = 1
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == 2147483647 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}

	mincost1 := make([]int, n)
	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost1[i] = c[i]
		mincost2[i] = math.MaxInt32
		if i > 0 && mincost1[i] > mincost1[i-1] {
			mincost1[i] = mincost1[i-1]
		}
	}

	min := math.MaxInt32
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+c[j] < mincost2[i] {
						mincost2[i] = c[i] + c[j]
					}
					x[i] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		x[i] = 1
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == math.MaxInt32 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}

	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost2[i] = math.MaxInt32
	}

	min := math.MaxInt32
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] {
				if c[i]+c[j] < mincost2[i] {
					mincost2[i] = c[i] + c[j]
				}
			}
		}
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == math.MaxInt32 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}

	mincost1 := make([]int, n)
	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost1[i] = c[i]
		mincost2[i] = 2147483647
		if i > 0 && mincost1[i] > mincost1[i-1] {
			mincost1[i] = mincost1[i-1]
		}
	}

	min := 2147483647
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+mincost1[j] < mincost2[i] {
						mincost2[i] = c[i] + mincost1[j]
					}
					x[i] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		x[i] = 1
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == 2147483647 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}

	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost2[i] = math.MaxInt32
	}

	min := math.MaxInt32
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+c[j] < mincost2[i] {
						mincost2[i] = c[i] + c[j]
					}
				}
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == math.MaxInt32 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}

	mincost1 := make([]int, n)
	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost1[i] = c[i]
		mincost2[i] = math.MaxInt64
		if i > 0 && mincost1[i] > mincost1[i-1] {
			mincost1[i] = mincost1[i-1]
		}
	}

	min := math.MaxInt64
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+c[j] < mincost2[i] {
						mincost2[i] = c[i] + c[j]
					}
					x[i] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		x[i] = 1
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == math.MaxInt64 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		var value int
		fmt.Scanf("%d", &value)
		s[i] = value
	}
	for i := 0; i < n; i++ {
		var value int
		fmt.Scanf("%d", &value)
		c[i] = value
	}

	var min int
	min = 2147483647
	for i := 2; i < n; i++ {
		for j := 1; j < i; j++ {
			for k := 0; k < j; k++ {
				if s[i] > s[j] && s[j] > s[k] {
					if min > c[i]+c[j]+c[k] {
						min = c[i] + c[j] + c[k]
					}
				}
			}
		}
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		var value int
		fmt.Scanf("%d", &value)
		s[i] = value
	}
	for i := 0; i < n; i++ {
		var value int
		fmt.Scanf("%d", &value)
		c[i] = value
	}

	mincost1 := make([]int, n)
	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost1[i] = c[i]
		mincost2[i] = 2147483647
		if i > 0 && mincost1[i] > mincost1[i-1] {
			mincost1[i] = mincost1[i-1]
		}
	}

	min := 2147483647
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+mincost1[j] < mincost2[i] {
						mincost2[i] = c[i] + mincost1[j]
					}
					x[i] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		x[i] = 1
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == 2147483647 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}

	mincost2 := make([]int, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = 1
		mincost2[i] = math.MaxInt32
	}

	min := math.MaxInt32
	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 2 {
					if c[i]+c[j] < mincost2[i] {
						mincost2[i] = c[i] + c[j]
					}
					x[i] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		x[i] = 1
	}

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if s[i] > s[j] && x[i] < x[j]+1 {
				x[i] = x[j] + 1
				if x[i] == 3 {
					if c[i]+mincost2[j] < min {
						min = c[i] + mincost2[j]
					}
					x[i] = 2
				}
			}
		}
	}
	if min == math.MaxInt32 {
		fmt.Println(-1)
		return
	}
	fmt.Println(min)
}


package main

import (
	"fmt"
)

func Min (x int , y int) int {
	if x < y {
		return x
	}
	return y
}

func main () {
	var n int
	fmt.Scanf("%d\n",&n)

	len := []int{}
	cost := []int{}
	for i := 0 ;i< n ;i++ {
		var l int
		if i == n - 1 {
			fmt.Scanf("%d\n",&l)
		} else {
			fmt.Scanf("%d",&l)
		}

		len = append(len , l)
	}

	for i := 0 ;i< n ;i++ {
		var c int
		if i == n - 1 {
			fmt.Scanf("%d\n",&c)
		} else {
			fmt.Scanf("%d",&c)
		}

		cost = append(cost , c)
	}

	dp2 := make([]int,4000)
	dp3 := make([]int,4000)

	for i := 0 ;i< n ;i++ {
		dp2[i] = 0xffffffff
		for j := 0 ; j < i ; j ++ {
			if len[j] < len[i] {
				dp2[i] = Min(dp2[i],cost[j] + cost[i])
			}
		}
	}

	var ans int = 0xffffffff
	for i := 0 ;i< n ;i++ {
		dp3[i] = 0xffffffff
		for j := 1 ; j < i ; j ++ {
			if len[j] < len[i] {
				dp3[i] = Min(dp3[i],dp2[j] + cost[i])
			}
		}
		ans = Min(ans,dp3[i])
	}

	if ans == 0xffffffff{
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}


package main

import (
	"fmt"
)

func Min (x int64 , y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func main () {
	var n int
	fmt.Scanf("%d\n",&n)

	len := []int64{}
	cost := []int64{}
	for i := 0 ;i< n ;i++ {
		var l int64
		if i == n - 1 {
			fmt.Scanf("%d\n",&l)
		} else {
			fmt.Scanf("%d",&l)
		}

		len = append(len , l)
	}

	for i := 0 ;i< n ;i++ {
		var c int64
		if i == n - 1 {
			fmt.Scanf("%d\n",&c)
		} else {
			fmt.Scanf("%d",&c)
		}

		cost = append(cost , c)
	}

	dp2 := make([]int64,4000)
	dp3 := make([]int64,4000)

	for i := 0 ;i< n ;i++ {
		dp2[i] = 0xffffffff
		for j := 0 ; j < i ; j ++ {
			if len[j] < len[i] {
				dp2[i] = Min(dp2[i],cost[j] + cost[i])
			}
		}
	}

	var ans int64 = 0xffffffff
	for i := 0 ;i< n ;i++ {
		dp3[i] = 0xffffffff
		for j := 1 ; j < i ; j ++ {
			if len[j] < len[i] {
				dp3[i] = Min(dp3[i],dp2[j] + cost[i])
			}
		}
		ans = Min(ans,dp3[i])
	}

	if ans == 0xffffffff{
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}


package main

import (
	"fmt"
)

func main () {
	var n int
	fmt.Scanf("%d\n",&n)

	len := []int{}
	cost := []int{}
	for i := 0 ;i< n ;i++ {
		var l int
		if i == n - 1 {
			fmt.Scanf("%d\n",&l)
		} else {
			fmt.Scanf("%d",&l)
		}

		len = append(len , l)
	}

	for i := 0 ;i< n ;i++ {
		var c int
		if i == n - 1 {
			fmt.Scanf("%d\n",&c)
		} else {
			fmt.Scanf("%d",&c)
		}

		cost = append(cost , c)
	}

	dp2 := make([]int,4000)
	dp3 := make([]int,4000)

	for i := 0 ;i< n ;i++ {
		dp2[i] = 0xffffffff
		for j := 0 ; j < i ; j ++ {
			if len[j] < len[i] {
				dp2[i] = Min(dp2[i],cost[j] + cost[i])
			}
		}
	}

	var ans int = 0xffffffff
	for i := 0 ;i< n ;i++ {
		dp3[i] = 0xffffffff
		for j := 1 ; j < i ; j ++ {
			if len[j] < len[i] {
				dp3[i] = Min(dp3[i],dp2[j] + cost[i])
			}
		}
		ans = Min(ans,dp3[i])
	}

	if ans == 0xffffffff{
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}

}

func Min (x int , y int) int {
	if x < y {
		return x
	}
	return y
}


package main

/*
	The idea to solve this problem is by fix to screen j, after that we search
	for screen i, then we search for screen k. For details:
	https://codeforces.com/blog/entry/59758
*/

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	var n, x int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	fonts := make([]int, 0, n)
	costs := make([]int, 0, n)
	// load fonts
	for i := 0; i < n; i++ {
		format := "%d"
		if i == n-1 {
			format += "\n"
		}
		fmt.Fscanf(stdin, format, &x)
		fonts = append(fonts, x)
	}
	// load costs
	for i := 0; i < n; i++ {
		format := "%d"
		if i == n-1 {
			format += "\n"
		}
		fmt.Fscanf(stdin, format, &x)
		costs = append(costs, x)
	}
	// search process, we start by fixing in j screen
	minCost := math.MaxInt32
	for j := 0; j < n; j++ {
		// search for i screen
		screenIdx := -1
		cost := costs[j]
		for i := 0; i < j; i++ {
			// the font size must be smaller than j screen
			if fonts[i] >= fonts[j] {
				continue
			}
			// take first screen or which has lower price than first screen
			if screenIdx == -1 || costs[i] < costs[screenIdx] {
				screenIdx = i
			}
		}
		// if screen not found skip
		if screenIdx == -1 {
			continue
		}
		// add cost of renting screen
		cost += costs[screenIdx]

		// search for k screen
		screenIdx = -1
		for k := j + 1; k < n; k++ {
			// the font size must larger than j screen
			if fonts[k] <= fonts[j] {
				continue
			}
			// take first screen or which has lower price than first screen
			if screenIdx == -1 || costs[k] < costs[screenIdx] {
				screenIdx = k
			}
		}
		// if screen not found skip
		if screenIdx == -1 {
			continue
		}
		// add cost of renting screen
		cost += costs[screenIdx]

		// search for overall min cost
		if cost < minCost {
			minCost = cost
		}
	}
	if minCost == math.MaxInt32 {
		fmt.Println("-1")
	} else {
		fmt.Printf("%d\n", minCost)
	}
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	var n, x int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	fonts := make([]int, 0, n)
	costs := make([]int, 0, n)
	// load fonts
	for i := 0; i < n; i++ {
		format := "%d"
		if i == n-1 {
			format += "\n"
		}
		fmt.Fscanf(stdin, format, &x)
		fonts = append(fonts, x)
	}
	// load costs
	for i := 0; i < n; i++ {
		format := "%d"
		if i == n-1 {
			format += "\n"
		}
		fmt.Fscanf(stdin, format, &x)
		costs = append(costs, x)
	}
	// search process, we start by fixing in j screen
	minCost := math.MaxInt32
	for j := 0; j < n; j++ {
		// search for i screen
		screenIdx := -1
		cost := costs[j]
		for i := 0; i < j; i++ {
			// the font size must be smaller than j screen
			if fonts[i] >= fonts[j] {
				continue
			}
			// take first screen or which has lower price than first screen
			if screenIdx == -1 || costs[i] < costs[screenIdx] {
				screenIdx = i
			}
		}
		// if screen not found skip
		if screenIdx == -1 {
			continue
		}
		// add cost of renting screen
		cost += costs[screenIdx]

		// search for k screen
		screenIdx = -1
		for k := j + 1; k < n; k++ {
			// the font size must larger than j screen
			if fonts[k] <= fonts[j] {
				continue
			}
			// take first screen or which has lower price than first screen
			if screenIdx == -1 || costs[k] < costs[screenIdx] {
				screenIdx = k
			}
		}
		// if screen not found skip
		if screenIdx == -1 {
			continue
		}
		// add cost of renting screen
		cost += costs[screenIdx]

		// search for overall min cost
		if cost < minCost {
			minCost = cost
		}
	}
	if minCost == math.MaxInt32 {
		fmt.Println("-1")
	} else {
		fmt.Printf("%d\n", minCost)
	}
}


package main

import "fmt"

const (
    maxn int = 3005
    inf int = 300000005
)

var (
    n int
    s, c [maxn]int
    dp [4][maxn]int
)

func min(x, y int) int {
    if x < y { return x } else { return y }
}

func read() {
    fmt.Scan(&n)
    for i := 1; i <= n; i++ {
        fmt.Scan(&s[i])
    }
    for i := 1; i <= n; i++ {
        fmt.Scan(&c[i])
    }
}

func solve() {
    var ans int = inf
    for i := 1; i <= n; i++ { dp[1][i] = c[i] }
    for i := 2; i <= 3; i++ {
        for j := 1; j <= n; j++ {
            dp[i][j] = inf
            for k := 1; k < j; k++ {
                if s[k] < s[j] {
                    dp[i][j] = min(dp[i][j], dp[i - 1][k] + c[j])
                }
            }
            if i == 3 && dp[i][j] < ans { ans = dp[i][j] }
        }
    }
    if ans == inf { fmt.Println("-1") } else { fmt.Println(ans) }
}

func main() {
    read()
    solve()
}


import java.io.InputStream;
import java.util.*;

public class B662 {
    static int n;
    static int q;
    //    static List<Integer> lenghts;
    static Map<Integer, Integer> len;

    public static void main(String[] args) {
        readInput(System.in);
    }

    private static void readInput(InputStream s) {
        Scanner in = new Scanner(s);
        n = in.nextInt();
        len = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int newValue = in.nextInt();

            if (len.keySet().contains(newValue)) {
                len.replace(newValue, len.get(newValue) + 1);
            } else {
                len.put(newValue, 1);
            }
        }
        q = in.nextInt();

        for (int i = 0; i < q; i++) {
            String znak = in.next();
            int number = in.nextInt();
            if ("+".equals(znak)) {
                if (len.keySet().contains(number)) {
                    len.put(number, len.get(number) + 1);
                } else {
                    len.put(number, 1);
                }
            } else {
                len.put(number, len.get(number) - 1);
            }

            boolean b = true;

            int[] four_and_two = new int[5];
            for (Map.Entry<Integer, Integer> v : len.entrySet()) {
                four_and_two[4] += v.getValue() / 4;
                four_and_two[2] += v.getValue() / 2;
            }

            if (four_and_two[4] >= 1 && four_and_two[2] >= 4 || four_and_two[4] >= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }

        }

    }
}


import java.io.*;
import java.util.*;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,i,temp;
	n=scan.nextInt();
	int[] a=new int[n];
	int two=0,four=0,six=0,eight=0;
	int[] hash = new int[100001];
	for(i=0;i<n;++i)
		{
		a[i]=scan.nextInt();
		temp = a[i];
		hash[temp]++;
		if(hash[temp]==2)
			{
			++two;
			}
		else if(hash[temp]==4)
			{
			++four;
			--two;
			}
		else if(hash[temp]==6)
			{
			++six;
			--four;
			}
		else if(hash[temp]==8)
			{
			++eight;
			--six;
			}
		}
	int q=scan.nextInt();
	while(q-->0)
	{
	char ch = scan.next().charAt(0);
	temp = scan.nextInt();
	if(ch=='+')
		{

		hash[temp]++;
		if(hash[temp]==2)
			{
			++two;
			}
		else if(hash[temp]==4)
			{
			++four;
			--two;
			}
		else if(hash[temp]==6)
			{
			++six;
			--four;
			}
		else if(hash[temp]==8)
			{
			++eight;
			--six;
			}
	//	System.out.println(four);
		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1||six>=2)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	else
		{
		if(hash[temp]==2)
			{
			--two;
			//--four;
			}
		else if(hash[temp]==4)
			{
			++two;
			--four;
			}
		else if(hash[temp]==6)
			{
			--six;
			++four;
			}
		else if(hash[temp]==8)
			{
			--eight;
			++six;
			}
		hash[temp]--;

		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1||six>=2)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	}
	}
}


import java.io.*;
import java.util.*;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,i,temp;
	n=scan.nextInt();
	int[] a=new int[n];
	int two=0,four=0,six=0,eight=0;
	int[] hash = new int[100001];
	for(i=0;i<n;++i)
		{
		a[i]=scan.nextInt();
		temp = a[i];
		hash[temp]++;
		if(hash[temp]==2)
			{
			++two;
			}
		else if(hash[temp]==4)
			{
			++four;
			--two;
			}
		else if(hash[temp]==6)
			{
			++six;
			--four;
			}
		else if(hash[temp]==8)
			{
			++eight;
			--six;
			}
		}
	int q=scan.nextInt();
	while(q-->0)
	{
	char ch = scan.next().charAt(0);
	temp = scan.nextInt();
	if(ch=='+')
		{

		hash[temp]++;
		if(hash[temp]==2)
			{
			++two;
			}
		else if(hash[temp]==4)
			{
			++four;
			--two;
			}
		else if(hash[temp]==6)
			{
			++six;
			--four;
			}
		else if(hash[temp]==8)
			{
			++eight;
			--six;
			}
		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	else
		{
		if(hash[temp]==2)
			{
			--two;
			//--four;
			}
		else if(hash[temp]==4)
			{
			++two;
			--four;
			}
		else if(hash[temp]==6)
			{
			--six;
			++four;
			}
		else if(hash[temp]==8)
			{
			--eight;
			++six;
			}
		hash[temp]--;

		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	}
	}
}


import java.io.*;
import java.util.*;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,i;
	n=scan.nextInt();
	int[] a=new int[n];
	int two=0,four=0,six=0,eight=0;
	int[] hash = new int[100001];
	for(i=0;i<n;++i)
		{
		a[i]=scan.nextInt();
		hash[a[i]]++;
		if(hash[a[i]]==2)
			++two;
		else if(hash[a[i]]==4)
			{
			--two;
			++four;
			}
		else if(hash[a[i]]==6)
			{
			--four;
			++six;
			}
		else if(hash[a[i]]==8)
			{
			--six;
			++eight;
			}
		}
	int q=scan.nextInt();
	while(q-->0)
	{
	char ch = scan.next().charAt(0);
	int temp = scan.nextInt();
	if(ch=='+')
		{
		hash[temp]++;
		if(hash[temp]==2)
			++two;
		else if(hash[temp]==4)
			{
			--two;
			++four;
			}
		else if(hash[temp]==6)
			{
			--four;
			++six;
			}
		else if(hash[temp]==8)
			{
			--six;
			++eight;
			}
		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	else
		{
		if(hash[temp]==2)
			--two;
		else if(hash[temp]==4)
			--four;
		else if(hash[temp]==6)
			--six;
		else if(hash[temp]==8)
			--eight;
		hash[temp]--;
		if(hash[temp]==2)
			++two;
		else if(hash[temp]==4)
			++four;
		else if(hash[temp]==6)
			++six;
		else if(hash[temp]==8)
			++eight;
		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	}
	}
}


import java.io.*;
import java.util.*;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int n,i;
	n=scan.nextInt();
	int[] a=new int[n];
	int two=0,four=0,six=0,eight=0;
	int[] hash = new int[100001];
	for(i=0;i<n;++i)
		{
		a[i]=scan.nextInt();
		if(hash[a[i]]==2)
			--two;
		else if(hash[a[i]]==4)
			--four;
		else if(hash[a[i]]==6)
			--six;
		else if(hash[a[i]]==8)
			--eight;
		hash[a[i]]++;
		if(hash[a[i]]==2)
			++two;
		else if(hash[a[i]]==4)
			++four;
		else if(hash[a[i]]==6)
			++six;
		else if(hash[a[i]]==8)
			++eight;
		}
	int q=scan.nextInt();
	while(q-->0)
	{
	char ch = scan.next().charAt(0);
	int temp = scan.nextInt();
	if(ch=='+')
		{
		if(hash[temp]==2)
			--two;
		else if(hash[temp]==4)
			--four;
		else if(hash[temp]==6)
			--six;
		else if(hash[temp]==8)
			--eight;
		hash[temp]++;
		if(hash[temp]==2)
			++two;
		else if(hash[temp]==4)
			++four;
		else if(hash[temp]==6)
			++six;
		else if(hash[temp]==8)
			++eight;

		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	else
		{
		if(hash[temp]==2)
			--two;
		else if(hash[temp]==4)
			--four;
		else if(hash[temp]==6)
			--six;
		else if(hash[temp]==8)
			--eight;
		hash[temp]--;
		if(hash[temp]==2)
			++two;
		else if(hash[temp]==4)
			++four;
		else if(hash[temp]==6)
			++six;
		else if(hash[temp]==8)
			++eight;
		if(four>1 || (four==1&&(six>=1||two>=2||eight>=1)) || (six>=1&&(two>=1||eight>=1)) || (two>=1&&eight>=1) || eight>=1)
			System.out.println("YES");
		else
			System.out.println("NO");
		}
	}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeMap;
import java.text.*;

public class Main {
	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt(), q, square = 0, pair = 0, ch, inp;
		char x;
		int cnt[] = new int[(int) (1e5 + 1)];
		boolean flag[] = new boolean[(int) (1e5 + 1)];
		for (int i = 0; i < n; i++)
		{
			ch = in.nextInt();
			cnt[ch]++;
			if (cnt[ch] % 4 == 0) {
				pair--;
				square++;
				flag[ch] = false;
			} else if ((cnt[ch] + 2) % 4 == 0) {
				pair++;
				flag[ch] = true;
			}
		}
		q = in.nextInt();
		while (q-- > 0) {
			x = in.next().charAt(0);
			inp = in.nextInt();
			if (x == '+') {
				cnt[inp]++;

				if (cnt[inp] % 4 == 0) {
					if (flag[inp]) {
						pair--;
						flag[inp] = false;
					}
					square++;
				} else if ((cnt[inp] + 2) % 4 == 0) {
					pair++;
					flag[inp] = true;
				}

			} else {
				cnt[inp]--;
				if (cnt[inp] != 0) {
					if ((cnt[inp] + 1) % 4 == 0)
						square--;
					else if ((cnt[inp] + 3) % 4 == 0) {
						pair--;
						flag[inp] = false;
					}
				}
			}

			if (square > 1)
				out.println("YES");
			else if (square == 1 && pair >= 2)
				out.println("YES");
			else
				out.println("NO");

		}
		out.close();
	}

}

class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new InputStreamReader(System.in));

	}

	public FastReader(File f) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(f));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());

			} catch (IOException e) {
				e.printStackTrace();
			}

		}

		return st.nextToken();

	}

	int nextInt() {

		return Integer.parseInt(next());
	}

	double nextDouble() {

		return Double.parseDouble(next());
	}

	long nextLong() {

		return Long.parseLong(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();

		} catch (IOException e) {

			e.printStackTrace();
		}
		return str;

	}

	boolean ready() throws IOException {
		return br.ready();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeMap;
import java.text.*;

public class Main {
	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt(), q, square = 0, pair = 0, ch, inp;
		char x;
		int cnt[] = new int[(int) (1e5 + 1)];
		boolean flag[] = new boolean[(int) (1e5 + 1)];
		for (int i = 0; i < n; i++)
		{
			ch = in.nextInt();
			cnt[ch]++;
			if (cnt[ch] % 4 == 0) {
				pair--;
				square++;
				flag[ch] = false;
			} else if ((cnt[ch] + 2) % 4 == 0) {
				pair++;
				flag[ch] = true;
			}
		}
		q = in.nextInt();
		while (q-- > 0) {
			x = in.next().charAt(0);
			inp = in.nextInt();
			if (x == '+') {
				cnt[inp]++;

				if (cnt[inp] % 4 == 0) {
					if (flag[inp]) {
						pair--;
						flag[inp] = false;
					}
					square++;
				} else if ((cnt[inp] + 2) % 4 == 0) {
					pair++;
					flag[inp] = true;
				}

			} else {
				cnt[inp]--;
				if (cnt[inp] != 0) {
					if ((cnt[inp] + 1) % 4 == 0)
					{
						square--;
						if(!flag[inp])
						{
							pair++;
							flag[inp]=true;
						}
					}
						else if ((cnt[inp] + 3) % 4 == 0) {
						pair--;
						flag[inp] = false;
					}
				}
			}

			if (square > 1)
				out.println("YES");
			else if (square == 1 && pair >= 2)
				out.println("YES");
			else
				out.println("NO");

		}
		out.close();
	}

}

class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new InputStreamReader(System.in));

	}

	public FastReader(File f) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(f));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());

			} catch (IOException e) {
				e.printStackTrace();
			}

		}

		return st.nextToken();

	}

	int nextInt() {

		return Integer.parseInt(next());
	}

	double nextDouble() {

		return Double.parseDouble(next());
	}

	long nextLong() {

		return Long.parseLong(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();

		} catch (IOException e) {

			e.printStackTrace();
		}
		return str;

	}

	boolean ready() throws IOException {
		return br.ready();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeMap;
import java.text.*;

public class Main {
	static final int MAX = (int) (1e5 + 10);
	static int pair = 0, square = 0;
	static boolean flag[] = new boolean[MAX];

	public static void change(int ch, boolean flag1) {
		if (flag1) {
			pair++;
			flag[ch] = flag1;
			return;
		}
		pair--;
		flag[ch] = flag1;

	}

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt(), ch;
		int cnt[] = new int[MAX];

		while (n-- > 0)
		{
			ch = in.nextInt();
			cnt[ch]++;

			if (cnt[ch] % 4 == 0)
			{
				change(ch, false);
				square++;
			}
			else if ((cnt[ch] + 2) % 4 == 0)
				change(ch, true);

		}

		n = in.nextInt();

		while (n-- > 0) {

			if (in.next().charAt(0) == '+') {
				ch = in.nextInt();

				cnt[ch]++;

				if (cnt[ch] % 4 == 0)
				{
					if (flag[ch])
						change(ch, false);
					square++;
				}
				else if ((cnt[ch] + 2) % 4 == 0)
					change(ch, true);

			}
			else {
				ch = in.nextInt();
				cnt[ch]--;
				if ((cnt[ch] + 1) % 4 == 0) {
					square--;
					if (!flag[ch])
						change(ch, true);

				} else if ((cnt[ch] + 3) % 4 == 0)
					change(ch, false);
			}

			if (square > 1 || square == 1 && pair >= 2)
				out.println("YES");
			else
				out.println("NO");

		}
		out.close();
	}

}

class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new InputStreamReader(System.in));

	}

	public FastReader(File f) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(f));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());

			} catch (IOException e) {
				e.printStackTrace();
			}

		}

		return st.nextToken();

	}

	int nextInt() {

		return Integer.parseInt(next());
	}

	double nextDouble() {

		return Double.parseDouble(next());
	}

	long nextLong() {

		return Long.parseLong(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();

		} catch (IOException e) {

			e.printStackTrace();
		}
		return str;

	}

	boolean ready() throws IOException {
		return br.ready();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeMap;
import java.text.*;

public class Main {
	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt(), q, square = 0, pair = 0, ch, inp;
		char x;
		int cnt[] = new int[(int) (1e5 + 1)];
		for (int i = 0; i < n; i++) {
			ch = in.nextInt();
			cnt[ch]++;
			if (cnt[ch] % 4 == 0) {
				pair--;
				square++;
			} else if ((cnt[ch] + 2) % 4 == 0)
				pair++;
		}
		q = in.nextInt();
		while (q-- > 0) {
			x = in.next().charAt(0);
			inp = in.nextInt();
			if (x == '+') {
				cnt[inp]++;

				if (cnt[inp] % 4 == 0) {
					pair--;
					square++;
				} else if ((cnt[inp] + 2) % 4 == 0)
					pair++;

			} else {
				cnt[inp]--;
				if (cnt[inp] != 0) {
					if ((cnt[inp] + 1) % 4 == 0)
						square--;
					else if ((cnt[inp] + 3) % 4 == 0)
						pair--;
				}
			}

			if (square > 1)
				out.println("YES");
			else if (square == 1 && pair >= 2)
				out.println("YES");
			else
				out.println("NO");

		}
		out.close();
	}

}

class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new InputStreamReader(System.in));

	}

	public FastReader(File f) throws FileNotFoundException {
		br = new BufferedReader(new FileReader(f));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());

			} catch (IOException e) {
				e.printStackTrace();
			}

		}

		return st.nextToken();

	}

	int nextInt() {

		return Integer.parseInt(next());
	}

	double nextDouble() {

		return Double.parseDouble(next());
	}

	long nextLong() {

		return Long.parseLong(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();

		} catch (IOException e) {

			e.printStackTrace();
		}
		return str;

	}

	boolean ready() throws IOException {
		return br.ready();
	}
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        int[]ar=split();
        int q=cin();
        int[] c=new int[100001];
        int[]cnt=new int[100001];
        for(int i=0;i<n;i++)
        {
        	c[ar[i]]++;
        	cnt[c[ar[i]]]++;
        }
        for(int i=0;i<q;i++)
        {
        	String[] cmd=br.readLine().split(" ");
        	String s=cmd[0];
        	int x=Integer.valueOf(cmd[1]);
        	if(s.equals("+"))
        	{
        		c[x]++;
        		cnt[c[x]]++;
        	}
        	else
        	{
        		cnt[c[x]]--;
        		c[x]--;
        	}
        	if(cnt[8]>0 || (cnt[4]>=2)||(cnt[6]>0 && cnt[2]>=2)||(cnt[4]>0 && cnt[2]>=3))
        		System.out.println("YES");
        	else
        		System.out.println("NO");
        }
    }
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        int[]ar=split();
        int q=cin();
        int[] c=new int[10001];
        for(int i=0;i<n;i++)
        {
        	c[ar[i]]++;
        }
        PriorityQueue<Pair> pq=new PriorityQueue<>();
        HashMap<Integer,Pair> map=new HashMap<>();
        for(int i=1;i<=10000;i++)
        {
        	if(c[i]!=0)
        	{
        		Pair p=new Pair(i,c[i]);
        		pq.add(p);
        		map.put(i,p);
        	}
        }
        for(int i=0;i<q;i++)
        {
        	String[] cmd=br.readLine().split(" ");
        	String s=cmd[0];
        	int x=Integer.valueOf(cmd[1]);
        	Pair p=map.get(x);
        	if(s.equals("+"))
        	{
        		if(p==null)
        		{
        			map.put(x, new Pair(x,1));
        			pq.add(new Pair(x,1));
        		}
        		else
        		{
        			Pair temp=new Pair(p.num,p.count+1);
//        			System.out.println(p.num+" "+p.count);
        			pq.remove(p);
        			pq.add(temp);
        			map.put(x, temp);
        		}
        	}
        	else
        	{
        		Pair temp=new Pair(p.num,p.count-1);
        		pq.remove(p);
    			pq.add(temp);
    			map.put(x, temp);
        	}
        	Pair k=pq.poll();
//        	System.out.println(k.num+" "+k.count);
        	if(k.count<4)
        		System.out.println("NO");
        	else
        	{
        		int rem=k.count-4;
        		if(rem>=4)
        			System.out.println("YES");
        		else
        		{
        			if(rem>=2)
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.peek();
        					if(f.count<2)
        						System.out.println("NO");
        					else
        						System.out.println("YES");
        				}
        			}
        			else
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.poll();
        					if(f.count>=4)
        						System.out.println("YES");
        					else
        					{
        						if(f.count<2)
        							System.out.println("NO");
        						else
        						{
        							if(pq.isEmpty())
        								System.out.println("NO");
        							else
        							{
        								Pair g=pq.peek();
        								if(g.count<2)
        									System.out.println("NO");
        								else
        									System.out.println("YES");
        							}
        						}
        					}
        					pq.add(f);
        				}
        			}
        		}
        	}
        	pq.add(k);
        }
    }
}
class Pair implements Comparable<Pair>
{
	int num;
	int count;
	public Pair(int n,int c)
	{
		this.num=n;
		this.count=c;
	}
	@Override
	public int compareTo(Pair o) {
		return o.count-this.count;
	}
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        int[]ar=split();
        int q=cin();
        int[] c=new int[10001];
        for(int i=0;i<n;i++)
        {
        	c[ar[i]]++;
        }
        PriorityQueue<Pair> pq=new PriorityQueue<>();
        HashMap<Integer,Pair> map=new HashMap<>();
        for(int i=1;i<=10000;i++)
        {
        	if(c[i]!=0)
        	{
        		Pair p=new Pair(i,c[i]);
        		pq.add(p);
        		map.put(i,p);
        	}
        }
        for(int i=0;i<q;i++)
        {
        	String[] cmd=br.readLine().split(" ");
        	String s=cmd[0];
        	int x=Integer.valueOf(cmd[1]);
        	Pair p=map.get(x);
        	if(s.equals("+"))
        	{
        		if(p==null)
        		{
        			Pair h=new Pair(x,1);
        			map.put(x,h);
        			pq.add(h);
        		}
        		else
        		{
        			Pair temp=new Pair(p.num,p.count+1);
//        			System.out.println(p.num+" "+p.count);
        			pq.remove(p);
        			pq.add(temp);
        			map.put(x, temp);
        		}
        	}
        	else
        	{
        		Pair temp=new Pair(p.num,p.count-1);
        		pq.remove(p);
        		if(p.count!=1) {
    			pq.add(temp);
    			map.put(x, temp);}
        		else
        			map.remove(x);
        	}
        	if(pq.isEmpty())
        	{
        		System.out.println("NO");
        		continue;
        	}
        	Pair k=pq.poll();
//        	System.out.println(k.num+" "+k.count);
        	if(k.count<4)
        		System.out.println("NO");
        	else
        	{
        		int rem=k.count-4;
        		if(rem>=4)
        			System.out.println("YES");
        		else
        		{
        			if(rem>=2)
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.peek();
        					if(f.count<2)
        						System.out.println("NO");
        					else
        						System.out.println("YES");
        				}
        			}
        			else
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.poll();
        					if(f.count>=4)
        						System.out.println("YES");
        					else
        					{
        						if(f.count<2)
        							System.out.println("NO");
        						else
        						{
        							if(pq.isEmpty())
        								System.out.println("NO");
        							else
        							{
        								Pair g=pq.peek();
        								if(g.count<2)
        									System.out.println("NO");
        								else
        									System.out.println("YES");
        							}
        						}
        					}
        					pq.add(f);
        				}
        			}
        		}
        	}
        	pq.add(k);
        }
    }
}
class Pair implements Comparable<Pair>
{
	int num;
	int count;
	public Pair(int n,int c)
	{
		this.num=n;
		this.count=c;
	}
	@Override
	public int compareTo(Pair o) {
		return o.count-this.count;
	}
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        int[]ar=split();
        int q=cin();
        int[] c=new int[100001];
        for(int i=0;i<n;i++)
        {
        	c[ar[i]]++;
        }
        PriorityQueue<Pair> pq=new PriorityQueue<>();
        HashMap<Integer,Pair> map=new HashMap<>();
        for(int i=1;i<=100000;i++)
        {
        	if(c[i]!=0)
        	{
        		Pair p=new Pair(i,c[i]);
        		pq.add(p);
        		map.put(i,p);
        	}
        }
        for(int i=0;i<q;i++)
        {
        	String[] cmd=br.readLine().split(" ");
        	String s=cmd[0];
        	int x=Integer.valueOf(cmd[1]);
        	Pair p=map.get(x);
        	if(s.equals("+"))
        	{
        		if(p==null)
        		{
        			Pair h=new Pair(x,1);
        			map.put(x,h);
        			pq.add(h);
        		}
        		else
        		{
        			Pair temp=new Pair(p.num,p.count+1);
//        			System.out.println(p.num+" "+p.count);
        			pq.remove(p);
        			pq.add(temp);
        			map.put(x, temp);
        		}
        	}
        	else
        	{
        		Pair temp=new Pair(p.num,p.count-1);
        		pq.remove(p);
        		if(p.count!=1) {
    			pq.add(temp);
    			map.put(x, temp);}
        		else
        			map.remove(x);
        	}
        	if(pq.isEmpty())
        	{
        		System.out.println("NO");
        		continue;
        	}
        	Pair k=pq.poll();
//        	System.out.println(k.num+" "+k.count);
        	if(k.count<4)
        		System.out.println("NO");
        	else
        	{
        		int rem=k.count-4;
        		if(rem>=4)
        			System.out.println("YES");
        		else
        		{
        			if(rem>=2)
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.peek();
        					if(f.count<2)
        						System.out.println("NO");
        					else
        						System.out.println("YES");
        				}
        			}
        			else
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.poll();
        					if(f.count>=4)
        						System.out.println("YES");
        					else
        					{
        						if(f.count<2)
        							System.out.println("NO");
        						else
        						{
        							if(pq.isEmpty())
        								System.out.println("NO");
        							else
        							{
        								Pair g=pq.peek();
        								if(g.count<2)
        									System.out.println("NO");
        								else
        									System.out.println("YES");
        							}
        						}
        					}
        					pq.add(f);
        				}
        			}
        		}
        	}
        	pq.add(k);
        }
    }
}
class Pair implements Comparable<Pair>
{
	int num;
	int count;
	public Pair(int n,int c)
	{
		this.num=n;
		this.count=c;
	}
	@Override
	public int compareTo(Pair o) {
		return o.count-this.count;
	}
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        int[]ar=split();
        int q=cin();
        int[] c=new int[10001];
        for(int i=0;i<n;i++)
        {
        	c[ar[i]]++;
        }
        PriorityQueue<Pair> pq=new PriorityQueue<>();
        HashMap<Integer,Pair> map=new HashMap<>();
        for(int i=1;i<=10000;i++)
        {
        	if(c[i]!=0)
        	{
        		Pair p=new Pair(i,c[i]);
        		pq.add(p);
        		map.put(i,p);
        	}
        }
        for(int i=0;i<q;i++)
        {
        	String[] cmd=br.readLine().split(" ");
        	String s=cmd[0];
        	int x=Integer.valueOf(cmd[1]);
        	Pair p=map.get(x);
        	if(s.equals("+"))
        	{
        		if(p==null)
        		{
        			Pair h=new Pair(x,1);
        			map.put(x,h);
        			pq.add(h);
        		}
        		else
        		{
        			Pair temp=new Pair(p.num,p.count+1);
//        			System.out.println(p.num+" "+p.count);
        			pq.remove(p);
        			pq.add(temp);
        			map.put(x, temp);
        		}
        	}
        	else
        	{
        		Pair temp=new Pair(p.num,p.count-1);
        		pq.remove(p);
        		if(p.count!=1) {
    			pq.add(temp);
    			map.put(x, temp);}
        		else
        			map.remove(x);
        	}
        	Pair k=pq.poll();
//        	System.out.println(k.num+" "+k.count);
        	if(k.count<4)
        		System.out.println("NO");
        	else
        	{
        		int rem=k.count-4;
        		if(rem>=4)
        			System.out.println("YES");
        		else
        		{
        			if(rem>=2)
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.peek();
        					if(f.count<2)
        						System.out.println("NO");
        					else
        						System.out.println("YES");
        				}
        			}
        			else
        			{
        				if(pq.isEmpty())
        					System.out.println("NO");
        				else
        				{
        					Pair f=pq.poll();
        					if(f.count>=4)
        						System.out.println("YES");
        					else
        					{
        						if(f.count<2)
        							System.out.println("NO");
        						else
        						{
        							if(pq.isEmpty())
        								System.out.println("NO");
        							else
        							{
        								Pair g=pq.peek();
        								if(g.count<2)
        									System.out.println("NO");
        								else
        									System.out.println("YES");
        							}
        						}
        					}
        					pq.add(f);
        				}
        			}
        		}
        	}
        	pq.add(k);
        }
    }
}
class Pair implements Comparable<Pair>
{
	int num;
	int count;
	public Pair(int n,int c)
	{
		this.num=n;
		this.count=c;
	}
	@Override
	public int compareTo(Pair o) {
		return o.count-this.count;
	}
}


import java.util.*;
public class CodeforceseDIV2662 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}

		HashMap<Integer,Integer> m=new HashMap<>();
		for(int i=0;i<n;i++) {
			m.put(a[i],m.getOrDefault(a[i], 0)+1);
		}
		int q=sc.nextInt();

		for(int i=0;i<q;i++) {
			char s=sc.next().charAt(0);
			int g=sc.nextInt();
			int flag=0;
			if(s=='+') {
				m.put(g,m.get(g)+1);
			}else {

				m.put(g,m.get(g)-1);
			}

			for(Map.Entry<Integer,Integer> e:m.entrySet()) {
				int j=e.getValue();
				int l=e.getKey();
				if(j>=8) {
					flag=1;
					System.out.println("yes");
					break;
				}else {
					if(j%2==0) {

					s:for(int k=1;k<=100000;k++) {
						for(Map.Entry<Integer,Integer> t:m.entrySet()) {
							int y=t.getKey();
							int x=t.getValue();
					if(y!=l&&x==8*k-j) {
					flag=1;
						System.out.println("Yes");
						break s;

					}

					}

				}
					}

				}
				if(flag==1) {
					break;
				}
			}
			if(flag==0) {
				System.out.println("NO");
			}

		}
	}

}


import java.util.*;
public class CodeforceseDIV2662 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}

		HashMap<Integer,Integer> m=new HashMap<>();
		for(int i=0;i<n;i++) {
			m.put(a[i],m.getOrDefault(a[i], 0)+1);
		}
		int q=sc.nextInt();

		for(int i=0;i<q;i++) {
			char s=sc.next().charAt(0);
			int g=sc.nextInt();
			int flag=0;
			if(s=='+') {
				m.put(g,m.getOrDefault(g,0)+1);
			}else {

				m.put(g,m.getOrDefault(g,0)-1);
			}

			for(Map.Entry<Integer,Integer> e:m.entrySet()) {
				int j=e.getValue();
				int l=e.getKey();
				if(j>=8) {
					flag=1;
					System.out.println("yes");
					break;
				}else {
					if(j%2==0) {

					s:for(int k=1;k<=100000;k++) {
						for(Map.Entry<Integer,Integer> t:m.entrySet()) {
							int y=t.getKey();
							int x=t.getValue();
					if(y!=l&&x==8*k-j) {
					flag=1;
						System.out.println("Yes");
						break s;

					}

					}

				}
					}

				}
				if(flag==1) {
					break;
				}
			}
			if(flag==0) {
				System.out.println("NO");
			}

		}
	}

}


import java.util.*;
public class CodeforceseDIV2662 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		int four=0,two=0;
		int ele[]=new int[100001];

		for(int i=0;i<n;i++) {
			ele[a[i]]++;
			if(ele[a[i]]%4==0) {
				four++;
				two--;
			}else if(ele[a[i]]%2==0){
				two++;
			}

		}
		int q=sc.nextInt();

		for(int i=0;i<q;i++) {
			char s=sc.next().charAt(0);

			if(s=='+') {
				int g=sc.nextInt();
			ele[g]++;
			if(ele[g]%4==0) {
				four++;
				two--;
			}else if(ele[g]%2==0) {
				two++;
			}
			}else {
				int g=sc.nextInt();

				if(ele[g]%4==0) {
					four--;
					two++;
				}else if(ele[g]%2==0) {
					two--;
				}
				ele[g]--;
			}
			if(four>=2) {
				System.out.println("yes");

			}else if(four==1&&two>=2) {
				System.out.println("yes");
			}else {
				System.out.println("no");
			}

	}

}

}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int d[] = new int[10000000];
        for (int i = 0; i < n; ++i) {
            d[FS.nextInt()]++;
        }
        int q = FS.nextInt();
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                d[am]--;
            }
            if (c == '+') {
                d[am]++;
            }

            int kv = 0, pr = 0;
            boolean f = false;

            for (int v = 0; v < d.length; ++v) {

                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    f = true;
                    break;
                }

                if (d[v] >= 8) {
                    kv += 2;
                    continue;
                }
                if (d[v] >= 6) {
                    kv++;
                    pr++;
                    continue;
                }
                if (d[v] >= 4) {
                    kv++;
                    continue;
                }
                if (d[v] >= 2) {
                    pr++;
                }
            }

            if (!f) {
                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                } else {
                    FS.pt.println("NO");
                }
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
        solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static Integer nextIntBox() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int arr[] = FS.readArray(n);
        int q = FS.nextInt();
        Map<Integer, Integer> d = new HashMap<>(1000000);
        for (int i : arr) {
            Integer am = d.get(i);
            if (am == null) am = 1;
            else am++;
            d.put(i, am);
        }
        boolean prev = false;
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
                if (prev) {
                    FS.pt.println("YES");
                }
            }

            int kv = 0, pr = 0;
            boolean f = false;

            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();

                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    f = true;
                    prev = true;
                    break;
                }

                if (v >= 8) {
                    kv+=2;
                    continue;
                }
                if (v >= 6) {
                    kv++;
                    pr++;
                    continue;
                }
                if (v >= 4) {
                    kv++;
                    continue;
                }
                if (v >= 2) {
                    pr++;
                }
            }

            if (!f) {
                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    prev = true;
                } else {
                    FS.pt.println("NO");
                    prev = false;
                }
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
            solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int arr[] = FS.readArray(n);
        int q = FS.nextInt();
        Map<Integer, Integer> d = new HashMap<>();
        for (int i : arr) {
            Integer am = d.get(i);
            if (am == null) am = 1;
            else am++;
            d.put(i, am);
        }
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
            }
            int stor = 0;
            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();
                stor += v / 2;
            }
            if (stor >= 4) {
                FS.pt.println("YES");
            } else {
                FS.pt.println("NO");
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
            solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int arr[] = FS.readArray(n);
        int q = FS.nextInt();
        Map<Integer, Integer> d = new HashMap<>(10000);
        for (int i : arr) {
            Integer am = d.get(i);
            if (am == null) am = 1;
            else am++;
            d.put(i, am);
        }
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
            }

            int kv = 0, pr = 0;
            boolean f = false;

            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();

                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    f = true;
                    break;
                }

                if (v >= 8) {
                    kv+=2;
                    continue;
                }
                if (v >= 6) {
                    kv++;
                    pr++;
                    continue;
                }
                if (v >= 4) {
                    kv++;
                    continue;
                }
                if (v >= 2) {
                    pr++;
                }
            }

            if (!f) {
                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                } else {
                    FS.pt.println("NO");
                }
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
            solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int arr[] = FS.readArray(n);
        int q = FS.nextInt();
        Map<Integer, Integer> d = new HashMap<>(1000000);
        for (int i : arr) {
            Integer am = d.get(i);
            if (am == null) am = 1;
            else am++;
            d.put(i, am);
        }
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
            }

            int kv = 0, pr = 0;
            boolean f = false;

            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();

                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    f = true;
                    break;
                }

                if (v >= 8) {
                    kv+=2;
                    continue;
                }
                if (v >= 6) {
                    kv++;
                    pr++;
                    continue;
                }
                if (v >= 4) {
                    kv++;
                    continue;
                }
                if (v >= 2) {
                    pr++;
                }
            }

            if (!f) {
                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                } else {
                    FS.pt.println("NO");
                }
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
            solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        Map<Integer, Integer> d = new HashMap<>(100000);
        for (int i = 0; i < n; ++i) {
            Integer u = FS.nextIntBox();
            Integer am = d.get(u);
            if (am == null) am = 1;
            else am++;
            d.put(u, am);
        }
        int q = FS.nextInt();
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
            }

            int kv = 0, pr = 0;
            boolean f = false;

            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();

                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    f = true;
                    break;
                }

                if (v >= 8) {
                    kv += 2;
                    continue;
                }
                if (v >= 6) {
                    kv++;
                    pr++;
                    continue;
                }
                if (v >= 4) {
                    kv++;
                    continue;
                }
                if (v >= 2) {
                    pr++;
                }
            }

            if (!f) {
                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                } else {
                    FS.pt.println("NO");
                }
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
        solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static Integer nextIntBox() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int arr[] = FS.readArray(n);
        int q = FS.nextInt();
        Map<Integer, Integer> d = new HashMap<>(10000);
        for (int i : arr) {
            Integer am = d.get(i);
            if (am == null) am = 1;
            else am++;
            d.put(i, am);
        }
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
            }

            int stor = 0;
            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();
                stor += v / 2;
                if (stor >= 4) break;
            }

            if (stor >= 4) {
                FS.pt.println("YES");
            } else {
                FS.pt.println("NO");
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
            solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int d[] = new int[10000000];
        int kv = 0, pr = 0;
        for (int i = 0; i < n; ++i) {
            int x = FS.nextInt();
            kv -= d[x] / 4;
            pr -= d[x] / 2;
            d[x]++;
            kv += d[x] / 4;
            pr += d[x] / 2;
        }
        int q = FS.nextInt();
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int x = FS.nextInt();
            kv -= d[x] / 4;
            pr -= d[x] / 2;

            if (c == '+') {
                d[x]++;
            }
            if (c == '-') {
                d[x]--;
            }

            kv += d[x] / 4;
            pr += d[x] / 2;

            if (kv >= 1 && pr >= 4) {
                FS.pt.println("YES");
            } else {
                FS.pt.println("NO");
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
        solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static Integer nextIntBox() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}


//package codeforces.contest.c1393;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/*
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
 */
public class B {

    static void solve() {
        int n = FS.nextInt();
        int arr[] = FS.readArray(n);
        int q = FS.nextInt();
        Map<Integer, Integer> d = new TreeMap<>(Comparator.comparing(it -> it));
        for (int i : arr) {
            Integer am = d.get(i);
            if (am == null) am = 1;
            else am++;
            d.put(i, am);
        }
        for (int i = 0; i < q; i++) {
            char c = FS.next().charAt(0);
            int am = FS.nextInt();
            if (c == '-') {
                Integer r = d.get(am);
                if (r == 1) {
                    d.remove(am);
                } else {
                    r -= 1;
                    d.put(am, r);
                }
            }
            if (c == '+') {
                Integer r = d.get(am);
                if (r == null) {
                    r = 1;
                } else {
                    r++;
                }
                d.put(am, r);
            }

            int kv = 0, pr = 0;
            boolean f = false;

            for (Map.Entry<Integer, Integer> entry : d.entrySet()) {
                Integer k = entry.getKey();
                Integer v = entry.getValue();

                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                    f = true;
                    break;
                }

                if (v >= 8) {
                    kv+=2;
                    continue;
                }
                if (v >= 6) {
                    kv++;
                    pr++;
                    continue;
                }
                if (v >= 4) {
                    kv++;
                    continue;
                }
                if (v >= 2) {
                    pr++;
                }
            }

            if (!f) {
                if (kv >= 1 && pr >= 2 || kv >= 2) {
                    FS.pt.println("YES");
                } else {
                    FS.pt.println("NO");
                }
            }
        }
    }

    public static void main(String[] args) {
//        int T = FS.nextInt();
//        for (int tt = 0; tt < T; tt++) {
            solve();
//        }
        FS.pt.close();
    }

    static class FS {
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private static StringTokenizer st = new StringTokenizer("");
        static PrintWriter pt = new PrintWriter(System.out);

        static String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        static int nextInt() {
            return Integer.parseInt(next());
        }

        static int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        static int[][] read2Array(int m, int n) {
            int[][] a = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

        static void printArr(int[] arr) {
            for (int value : arr) {
                pt.print(value);
                pt.print(" ");
            }
            pt.println();
        }

        static void print2Arr(int[][] arr, int m, int n) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    pt.print(arr[i][j]);
                    pt.print(" ");
                }
                pt.println();
            }
            pt.println();
        }

        static void close() {
            pt.close();
        }

        static long nextLong() {
            return Long.parseLong(next());
        }
    }
}