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
// @jagrit_07
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int a[] = sc.nextIntArray(n);
        int m = sc.nextInt();
        int b[] = sc.nextIntArray(m);
        
        long sum1 = 0;
        long sum2 = 0;
        for(int i: a) sum1+=i;
        for(int i: b) sum2+=i;
        if(sum1!=sum2)
        {
            //It will never be possible;
            System.out.println(-1);
            return;
        }
        else
        {
            int i=0;
            int j=0;
            List<Long> list = new ArrayList<>();
            sum1=0;
            sum2=0;
            while(i<n && j<m)
            {
                if(sum1==0 && sum2==0)
                {
                    sum1 = sum1 + a[i];
                    sum2 = sum2 + b[j];
                    i++;
                    j++;
                }
                else
                {
                    //System.out.println(sum1+" "+sum2);
                    if(sum1==sum2)
                    {
                        list.add(sum1);
                        sum1=0;
                        sum2=0;
                       // i++;
                       // j++;
                    }
                    else if(sum1<sum2)
                    {
                        sum1=sum1+a[i];
                        i++;
                    }
                    else
                    {
                        sum2=sum2+b[j];
                        j++;
                    }
                }
                
            }
            //System.out.println(Arrays.toString(list.toArray()));
            if(sum1!=0) list.add(sum1);
            i=n-1;
            j=m-1;
            List<Long> list2 = new ArrayList<>();
            sum1=0;
            sum2=0;
            while(i>=0 && j>=0)
            {
                if(sum1==0 && sum2==0)
                {
                    sum1 = sum1 + a[i];
                    sum2 = sum2 + b[j];
                }
                else
                {
                    if(sum1==sum2)
                    {
                        list2.add(sum1);
                        sum1=0;
                        sum2=0;
                        i--;
                        j--;
                    }
                    else if(sum1<sum2)
                    {
                        sum1=sum1+a[i];
                        i--;
                    }
                    else
                    {
                        sum2=sum2+b[j];
                        j--;
                    }
                }
                
            }
            if(sum1!=0) list2.add(sum1);
            //System.out.println(Arrays.toString(list2.toArray()));
            System.out.println(Math.max(list.size(),list2.size()));
        }
        
        
        
    }
    public static void findDivisors(HashSet<Integer> hs, int num)
    {
        for(int i=2;i<=Math.sqrt(num);i++)
        {
            if(num%i==0)
            {
                if(num/i!=i)
                {
                    hs.add(i);
                    hs.add(num/i);
                }
                else
                {
                    hs.add(i);
                }
            }
        }
    }
    static class Pair
    {
        long x;
        long y;

        //int i;
        public Pair(long x, long  y)
        {
            this.x=x;
            this.y=y;
        }
    }
    static class Comp implements Comparator<Pair>
    {
        public int compare(Pair p1, Pair p2)
        {
            if(p1.x>p2.x)
            {
                return 1;
            }
            if(p1.x<p2.x)
            {
                return -1;
            }
            if(p1.y>p2.y)
            {
                return -1; 
            }
            if(p1.y<p2.y)
            {
                return 1;
            }
            return 0;
        }
    }


    public static int bs(int num[], long x)
    {
        int low=0;
        int high=num.length-1;
        int ans=-1;
        while(low<=high)
        {
            int mid = low + (high-low)/2;
            if(num[mid]==x)
            {
                ans = mid;
                //break;
                low = mid+1;
            }
            else if(num[mid]<x)
            {
               // ans=mid;
                ans = mid;
                low=mid+1;
            }
            else
            {
                //ans=mid;
                high=mid-1;
            }
        }
        return ans;
    }
    
    
    
    
    
    
    
    
    
    
    //Comparing two list;
    public static List<Integer> comp(List<Integer> l1, List<Integer> l2)
    {
        if(l1.size()<l2.size()) return l1;
        if(l2.size()<l1.size()) return l2;
        
        for(int i=0;i<l1.size();i++)
        {
            if(l1.get(i)<l2.get(i))
            {
                return l1;
            }
            else if(l2.get(i)<l1.get(i))
            {
                return l2;
            }
        }
        return l2;
    }
   
    
   
    
 
    /* to find (x^y)%p in O(log y) */
    static long power(long x, long y, int p) 
    { 
        // Initialize result 
        long ans = 1;      
         
        // Update x if it is more   
        // than or equal to p 
        x = x % p;  
  
       if (x == 0) return 0; // In case x is divisible by p;    
  
        while (y > 0) 
        { 
            if((y & 1)==1) 
            {
                 ans = ((long)(ans * x))% p;    
            }
            y = y >> 1;  //y/2; 
            x = ((long)(x * x) )% p;  
        } 
        return ans; 
    } 
    
    
    
    
    
    public static void printList(List<Integer> list)
    {
        StringBuffer bf = new StringBuffer("");
        for(int i: list) bf.append(i+" ");
        System.out.println(bf.toString());
    }
    
    
    
    
    
    public static int sum(int a[])
    {
        int sum=0;
        for(int i: a) sum=sum+i;
        return sum;
    }
    
  
    public static int getMax(int a[])
    {
        int m=Integer.MIN_VALUE;
        for(int i: a) m=Math.max(i,m);
        return m;
    }
 
    
    
    
    public static int partition(int arr[], int low, int high) 
    { 
        int pivot = arr[high];  
        int i = (low-1);
        for (int j=low; j<high; j++) 
        { 
            if (arr[j] < pivot) 
            { 
                i++; 
                int temp = arr[i]; 
                arr[i] = arr[j]; 
                arr[j] = temp; 
            } 
        } 
        int temp = arr[i+1]; 
        arr[i+1] = arr[high]; 
        arr[high] = temp; 
  
        return i+1; 
    } 
    public static void sort(int arr[], int low, int high) 
    { 
        if (low < high) 
        { 
            int pi = partition(arr, low, high); 
            sort(arr, low, pi-1); 
            sort(arr, pi+1, high); 
        } 
    } 
    
    
    
    
    
    
    static long gcd(long a,long b)
    {
        if(b==0) return a;
        return gcd(b,a%b);
    }
    
    
    static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
    static void sort(long[] a) {
		ArrayList<Long> l=new ArrayList<>();
		for (long i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
    
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (final IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (final IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] nextIntArray(final int n) {
			final int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(next());
			}
			return a;
		}

	}	
}
//private ArrayList<String[]> action = new ArrayList<String[]>();


//Templates for Comparator and Classes - @jagrit_07
/*
Arrays.sort(newEmployees, new Comparator<Employee>() {
    @Override
    public int compare(Employee emp1, Employee emp2) {
        return emp1.getName().compareTo(emp2.getName());
    }
});
class Pair
	{
		
		long i; //index;
		long l; //left;
		long c; //cost;
		public Pair(long x,long y,long z)
		{
			this.i=x;
			this.l=y;
			this.c=z;
		}
		public String toString()
		{
			return this.i+" "+this.l+" "+this.c;
		}
	}
class Comp implements Comparator<Pair>
	{
		public int compare(Pair p1, Pair p2)
		{
			if(p1.c!=p2.c)
			{
				return (int)(p1.c-p2.c); //sort acc to cost;
			}
			else{
				return (int)(p1.i-p2.i); //sort acc to index;
			}
			
		}
	}
*/

/*
System.out.println( 
      String.format("%.5f", b)); 
  HashMap - Put template - d.put(a1,d.getOrDefault(a1,0)+1);
  for (Map.Entry<String, Integer> entry : map.entrySet()) {
        System.out.println(entry.getKey() + ":" + entry.getValue());
    }
  Deque<String> deque 
            = new LinkedList<String>();  
            
  List<Integer> c[] = new ArrayList[3];          
*/