Vasya has two arrays A and B of lengths n and m, respectively.

He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array [1, 10, 100, 1000, 10000] Vasya can obtain array [1, 1110, 10000], and from array [1, 2, 3] Vasya can obtain array [6].

Two arrays A and B are considered equal if and only if they have the same length and for each valid i A_i = B_i.

Vasya wants to perform some of these operations on array A, some on array B, in such a way that arrays A and B become equal. Moreover, the lengths of the resulting arrays should be maximal possible.

Help Vasya to determine the maximum length of the arrays that he can achieve or output that it is impossible to make arrays A and B equal.

Input

The first line contains a single integer n~(1 ≤ n ≤ 3 ⋅ 10^5) — the length of the first array.

The second line contains n integers a_1, a_2, ⋅⋅⋅, a_n~(1 ≤ a_i ≤ 10^9) — elements of the array A.

The third line contains a single integer m~(1 ≤ m ≤ 3 ⋅ 10^5) — the length of the second array.

The fourth line contains m integers b_1, b_2, ⋅⋅⋅, b_m~(1 ≤ b_i ≤ 10^9) - elements of the array B.

Output

Print a single integer — the maximum length of the resulting arrays after some operations were performed on arrays A and B in such a way that they became equal.

If there is no way to make array equal, print "-1".

Examples

Input

5
11 2 3 5 7
4
11 7 3 7


Output

3


Input

2
1 2
1
100


Output

-1


Input

3
1 2 3
3
1 2 3


Output

3
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.stream.Collectors;

public class solution {
	static final String fileName = "E:\\DownLoad\\Temp\\input15.txt";
	static final StdIn in = new StdIn();
	static final PrintWriter out = new PrintWriter(System.out);

	static int dx[] = { 1, 0, 0, -1 };
	static int dy[] = { 0, -1, 1, 0 };
	
	public static void main(String[] args) throws Exception {
		int n = in.nextInt();
		long a[] = new long[n];
		long sum = 0;
		for(int i = 0; i < n; ++i) {
			long x = in.nextLong();
			sum += x;
			a[i] = sum;
		}
		int m = in.nextInt();
		long b[] = new long[m];
		sum = 0;
		for(int i = 0; i < m; ++i) {
			long x = in.nextLong();
			sum += x;
			b[i] = sum;
		}
		if(a[n - 1] != b[m - 1]) out.println(-1);
		else {
			int cnt = 0;
			for(int i = 0; i < n; ++i) {
				int x = Arrays.binarySearch(b, a[i]);
				if(x >= 0) ++cnt;
			}
			out.println(cnt);
		}
		out.close();
	}
	
	static public boolean nextPermutation(int[] nums) {
		if (nums.length < 2)
			return false;
		int firstSmaller = nums.length - 2;
		while (firstSmaller >= 0) {
			if (nums[firstSmaller] < nums[firstSmaller + 1])
				break;
			firstSmaller--;
		}
		if (firstSmaller == -1) {
			reverse(nums, 0, nums.length - 1);
			return false;
		}
		int firstLarger = nums.length - 1;
		while (firstLarger > firstSmaller) {
			if (nums[firstLarger] > nums[firstSmaller])
				break;
			firstLarger--;
		}
		swap(nums, firstSmaller, firstLarger);
		reverse(nums, firstSmaller + 1, nums.length - 1);
		return true;
	}

	static void swap(int[] nums, int i, int j) {
		int tmp = nums[i];
		nums[i] = nums[j];
		nums[j] = tmp;
	}

	static void reverse(int[] nums, int start, int end) {
		for (int i = start; i <= (start + end) / 2; i++)
			swap(nums, i, start + end - i);
	}

	static long mul_mod(long a, long b, long m) {
		if (a >= m)
			a %= m;
		if (b >= m)
			b %= m;
		double x = a;
		long c = (long) (x * b / m);
		long r = (long) (a * b - c * m) % m;
		return r < 0 ? r + m : r;
	}

	static long pow_mod(long a, long b, long m) {
		long res = 1;
		a %= m;
		while (b > 0) {
			if (b % 2 != 0)
				res = mul_mod(res, a, m);
			b >>= 1;
			a = mul_mod(a, a, m);
		}
		return res;
	}

	static class Pair implements Comparable<Pair> {
		public int x;
		public int y;

		public Pair() {
		}

		public Pair(int a, int b) {
			x = a;
			y = b;
		}

		@Override
		public boolean equals(Object obj) {
			Pair tmp = (Pair) obj;
			return tmp.x == x && tmp.y == y;
		}

		@Override
		public int hashCode() {
			return Long.hashCode(x) * 31 + Long.hashCode(y) * 10000007;
		}

		@Override
		public int compareTo(Pair o) {
			long d = x - o.x;
			if (d == 0)
				return Long.compare(y, o.y);
			return Long.compare(x, o.x);
		}

		@Override
		public String toString() {
			return x + " " + y;
		}
	}

	static class StdIn {
		final private int BUFFER_SIZE = 1 << 17;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public StdIn() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public StdIn(InputStream in) {
			try {
				din = new DataInputStream(in);
			} catch (Exception e) {
				throw new RuntimeException();
			}
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public StdIn(String fileName) {
			InputStream in;
			try {
				in = new FileInputStream(new File(fileName));
				din = new DataInputStream(in);
			} catch (Exception e) {
				throw new RuntimeException();
			}
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String next() {
			int c;
			while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
				;
			StringBuilder s = new StringBuilder();
			while (c != -1) {
				if (c == ' ' || c == '\n' || c == '\r')
					break;
				s.append((char) c);
				c = read();
			}
			return s.toString();
		}

		public String nextLine() {
			int c;
			while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
				;
			StringBuilder s = new StringBuilder();
			while (c != -1) {
				if (c == '\n' || c == '\r')
					break;
				s.append((char) c);
				c = read();
			}
			return s.toString();
		}

		public int nextInt() {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public int[] readIntArray(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; ++i)
				ar[i] = nextInt();
			return ar;
		}

		public long nextLong() {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public long[] readLongArray(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; ++i)
				ar[i] = nextLong();
			return ar;
		}

		public double nextDouble() {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() {
			try {
				if (bufferPointer == bytesRead)
					fillBuffer();
				return buffer[bufferPointer++];
			} catch (IOException e) {
				throw new RuntimeException();
			}
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}