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 com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.omg.CORBA.INTERNAL;

import javax.swing.plaf.basic.BasicTreeUI;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;


public class Main {
    private static Scanner sc;
    private static Printer pr;
    static boolean []visited;
    static int []color;
    static int []pow=new int[(int)3e5+1];
    static int []count;
    static boolean check=true;
    static boolean checkBip=true;
    static TreeSet<Integer>[]list;
    private static long aLong=(long)(Math.pow(10,9)+7);
    static final long div=998244353;
    static  int answer=0;
    static int[]countSubTree;
    static int[]colorNode;
    static boolean con=true;
    static ArrayList<Integer>dfsPath=new ArrayList<>();
    static ArrayList<Integer>ans=new ArrayList<>();
    static boolean[]rec;
    static int min=Integer.MAX_VALUE;
    static ArrayList<Task>tasks=new ArrayList<>();
    static  boolean []checkpath;
    private static void solve() throws IOException {
        int n=sc.nextInt();
        long  []inA=new long[n];
        for (int i=0;i<n;++i){
            inA[i]=sc.nextLong();
        }
        int m=sc.nextInt();
        long []inB=new long[m];
        for (int i=0;i<m;++i){
            inB[i]=sc.nextLong();
        }
        int outLen=0;
        long dif=0;
        int i=0,j=0;
        while (i!=n&&j!=m){
            //System.out.println("i:"+i+" j:"+j);
            dif=inA[i]-inB[j];
            //System.out.println("diff:"+dif);
            //System.out.println("**********");
            if (dif==0){
                ++i;
                ++j;
                ++outLen;
            }else if (dif>0){
                inA[i]-=inB[j];
                ++j;
            }
            else {
                inB[j]-=inA[i];
                ++i;
            }
        }
        //System.out.println(i+" "+j);
        if (dif==0&&i==n&&j==m)pr.println(outLen);
        else pr.println(-1);
    }
    public static class dsu{
        int []rank;
        int[]parent;
        long []sum;
        int n;
        public dsu(int n) {
            this.n = n;
            parent=new int[n];
            rank=new int[n];
            sum=new long[n];
            for (int i=0;i<n;++i){
                rank[i]=1;
                parent[i]=i;
                sum[i]=0;
            }
        }
        public int dad(int child){
            if (parent[child]==child)return child;
            else return dad(parent[child]);
        }
        public void merge(int u,int v){
            int dadU=dad(u);
            int dadV=dad(v);
            if (dadU==dadV)return ;
            if (u!=v){
                if (rank[u]<rank[v]){
                    parent[u]=v;
                    sum[v]+=sum[u];
                }
                else if (rank[u]==rank[v]){
                    parent[u]=v;
                    sum[v]+=sum[u];
                }
                else{
                    parent[v]=u;
                    sum[u]+=sum[v];
                }
            }
        }
    }
    public static long power(long x,long y,long mods){
        if (y==0) return 1%mods;
        long u=power(x,y/2,mods);
        u=((u)*(u))%mods;
        if (y%2==1) u=(u*(x%mods))%mods;
        return u;
    }
    public static class Task implements Comparable<Task>{
        long l,r;
        public Task(long w,long v) {
            this.l=w;
            this.r=v;
        }

        @Override
        public int compareTo(Task o) {
            if (o.l<this.l)return 1;
            else if (o.l>this.l)return -1;
            else {
                if (o.r>this.r)return 1;
                else if (o.r<this.r)return -1;
            }
            return 0;
        }
    }
    public static void printSolve(StringBuilder str, int[] colors, int n,int color){
        for(int i = 1;i<=n;++i)
            if(colors[i] == color)
                str.append(i + " ");
        str.append('\n');
    }
    public static class pairTask{
        int  val;
        int size;
        public pairTask(int   x, int  y) {
            this.val = x;
            this.size = y;
        }
    }
    public static void subTree(int src,int parent,int x){
        countSubTree[src]=1;
        if (src==x) {
            checkpath[src]=true;
            //System.out.println("src:"+src);
        }
        else checkpath[src]=false;
        for (int v:list[src]){
            if (v==parent)
                continue;
            subTree(v,src,x);
            countSubTree[src]+=countSubTree[v];
            checkpath[src]|=checkpath[v];
        }
    }
    public static boolean prime(long src){
        for (int i=2;i*i<=src;i++){
            if (src%i==0)
                return false;
        }
        return true;
    }
    public static void bfsColor(int src){
        Queue<Integer>queue = new ArrayDeque<>();
        queue.add(src);
        while (!queue.isEmpty()){
            boolean b=false;
            int vertex=-1,p=-1;
            int poll=queue.remove();
            for (int v:list[poll]){
                if (color [v]==0){
                    vertex=v;
                    break;
                }
            }
            for (int v:list[poll]){
                if (color [v]!=0&&v!=vertex){
                    p=v;
                    break;
                }
            }
            for (int v:list[p]){
                if (color [v]!=0){
                    color[vertex]=color[v];
                    b=true;
                    break;
                }
            }
            if (!b){
                color[vertex]=color[poll]+1;
            }
        }
    }
    static int add(int a,int b ){
        if (a+b>=div)
            return (int)(a+b-div);
        return (int)a+b;
    }
    public static int isBipartite(ArrayList<Integer>[]list,int src){
        color[src]=0;
        Queue<Integer>queue=new LinkedList<>();
        int []ans={0,0};
        queue.add(src);
        while (!queue.isEmpty()){
            ans[color[src=queue.poll()]]++;
            for (int v:list[src]){
                if (color[v]==-1){
                    queue.add(v);
                    color[v]=color[src]^1;
                }else if (color[v]==color[src])
                    check=false;
            }
        }
        return add(pow[ans[0]],pow[ans[1]]);
    }
    public static int powerMod(long b, long e){
        long ans=1;
        while (e-->0){
            ans=ans*b%div;
        }
        return (int)ans;
    }
    public static int dfs(int s){
        int ans=1;
        visited[s]=true;
        for (int k:list[s]){
            if (!visited[k]){
                ans+=dfs(k);
            }
        }
        return ans;
    }
    public static int[] radixSort(int[] f) {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
    public static long []primeFactor(int n){
        long []prime=new long[n+1];
        prime[1]=1;
        for (int i=2;i<=n;i++)
            prime[i]=((i&1)==0)?2:i;
        for (int i=3;i*i<=n;i++){
            if (prime[i]==i){
                for (int j=i*i;j<=n;j+=i){
                    if (prime[j]==j)
                        prime[j]=i;
                }
            }
        }
        return prime;
    }
    public static StringBuilder binaryradix(long number){
        StringBuilder builder=new StringBuilder();
        long remainder;
        while (number!=0) {
            remainder = number % 2;
            number >>= 1;
            builder.append(remainder);
        }
        builder.reverse();
        return builder;
    }
    public static int binarySearch(long[] a, int index,long target) {
            int l = index;
            int h = a.length - 1;
            while (l<=h) {
                int med = l + (h-l)/2;
                if(a[med] - target <= target) {
                    l = med + 1;
                }
                else h = med  - 1;
            }
            return h;
    }
    public static int val(char c){
        return c-'0';
    }
    public static long gcd(long a,long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
        private static class Pair implements Comparable<Pair> {
            long x;
            long y;

            Pair() {
                this.x = 0;
                this.y = 0;
            }

            Pair(long x, long y) {
                this.x = x;
                this.y = y;
            }

            @Override
            public boolean equals(Object obj) {
                if (this == obj) {
                    return true;
                }
                if (obj == null) return false;
                Pair other = (Pair) obj;
                if (this.x == other.x && this.y == other.y) {
                    return true;
                }
                return false;
            }

            @Override
            public int compareTo(Pair other) {
                if (this.x != other.x) return Long.compare(this.x, other.x);
                return Long.compare(this.y*other.x, this.x*other.y);
            }
    }

    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pr = new Printer(System.out);
        solve();

        pr.close();
       // sc.close();
    }
    private static class Scanner {
        BufferedReader br;

        Scanner (InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        private boolean isPrintable(int ch) {
            return ch >= '!' && ch <= '~';
        }

        private boolean isCRLF(int ch) {
            return ch == '\n' || ch == '\r' || ch == -1;
        }

        private int nextPrintable() {
            try {
                int ch;
                while (!isPrintable(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }

                return ch;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        String next() {
            try {
                int ch = nextPrintable();
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (isPrintable(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        int nextInt() {
            try {
                // parseInt from Integer.parseInt()
                boolean negative = false;
                int res = 0;
                int limit = -Integer.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Integer.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                int multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        long nextLong() {
            try {
                // parseLong from Long.parseLong()
                boolean negative = false;
                long res = 0;
                long limit = -Long.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Long.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                long multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

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

        String nextLine() {
            try {
                int ch;
                while (isCRLF(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (!isCRLF(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
//				throw new NoSuchElementException();
            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

    static class List {
        String Word;
        int length;

        List(String Word, int length) {
            this.Word = Word;
            this.length = length;
        }
    }
    private static class Printer extends PrintWriter {
        Printer(PrintStream out) {
            super(out);
        }
    }
}