import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;

public class Solu {
    static StringBuffer str = new StringBuffer();
    static InputReader in = new InputReader(System.in);
    static int mm=1000000007;
    public static void main(String[] args) {
        int i,j,it,t;
        int n=in.nextInt();
        long a[]=new long[n];
        long hk=0;
        long kj=0;
        for(i=0;i<n;i++){
            a[i]=in.nextLong();
            hk+=a[i];
        }
        int k=in.nextInt();
        long b[]=new long[k];

        for(i=0;i<k;i++){
            b[i]=in.nextLong();
            kj+=b[i];
        }
        long ss1=a[0];
        long ss2=b[0];
        int x=1;
        int y=1;
        ArrayList<Long> z=new ArrayList<>();
        ArrayList<Long> w=new ArrayList<>();
        while(x<n && y<k){
            if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
            else{
                if(ss1>ss2){
                    ss2+=b[y];
                    y+=1;
                }else{
                    ss1+=a[x];
		x+=1;
                }
            }
            if(x>=n || y>=k)
                break;
        }
        if(x<n){
            long kl=0;
            for(i=x;i<n;i++){
                kl+=a[i];
            }
            ss1+=kl;
        }
        if(y<k){
            long kl=0;
            for(i=y;i<k;i++){
                kl+=b[i];
            }
            ss2+=kl;
        }
        if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
        long gg=0;
        long hh=0;
        for(i=0;i<z.size();i++){
            gg+=z.get(i);
        }
        for(i=0;i<w.size();i++){
            hh+=w.get(i);
        }
        if(gg!=hh|| z.size()!=w.size()  || gg!=hk || hh!=kj){
            System.out.println(-1);
        }else{
            System.out.println(z.size());
        }
    }
    static long gcd(long a, long b){
        return (b==0)?a:gcd(b,a%b);
    }
    static int gcdi(int a, int b){
        return (b==0)?a:gcdi(b,a%b);
    }
    public static void ap(String st){
        str.append(st);
    }
    public static void pn() {
        System.out.println(str);
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0) {
                read();
            }
        }

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

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

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;

public class Solu {
    static StringBuffer str = new StringBuffer();
    static InputReader in = new InputReader(System.in);
    static int mm=1000000007;
    public static void main(String[] args) {
        int i,j,it,t;
        int n=in.nextInt();
        long a[]=new long[n];
        long hk=0;
        long kj=0;
        for(i=0;i<n;i++){
            a[i]=in.nextLong();
            hk+=a[i];
        }
        int k=in.nextInt();
        long b[]=new long[k];

        for(i=0;i<k;i++){
            b[i]=in.nextLong();
            kj+=b[i];
        }
        long ss1=a[0];
        long ss2=b[0];
        int x=1;
        int y=1;
        ArrayList<Long> z=new ArrayList<>();
        ArrayList<Long> w=new ArrayList<>();
        while(true){
            if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
            else{
                if(ss1>ss2){
                    ss2+=b[y];
                    y+=1;
                }else{
                    ss1+=a[x];
		x+=1;
                }
            }
            if(x>=n || y>=k)
                break;
        }
        if(x<n){
            long kl=0;
            for(i=x;i<n;i++){
                kl+=a[i];
            }
            ss1+=kl;
        }
        if(y<k){
            long kl=0;
            for(i=y;i<k;i++){
                kl+=b[i];
            }
            ss2+=kl;
        }
        if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
        long gg=0;
        long hh=0;
        for(i=0;i<z.size();i++){
            gg+=z.get(i);
        }
        for(i=0;i<w.size();i++){
            hh+=w.get(i);
        }
        if(gg!=hh|| z.size()!=w.size() || gg==0 || gg!=hk || hh!=kj){
            System.out.println(-1);
        }else{
            boolean fl=true;
            for(i=0;i<z.size();i++){
                if(z.get(i)!=w.get(i)){
                    fl=false;
                    break;
                }
            }
            if(fl)
            System.out.println(z.size());
            else
                System.out.println(-1);
        }
    }
    static long gcd(long a, long b){
        return (b==0)?a:gcd(b,a%b);
    }
    static int gcdi(int a, int b){
        return (b==0)?a:gcdi(b,a%b);
    }
    public static void ap(String st){
        str.append(st);
    }
    public static void pn() {
        System.out.println(str);
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0) {
                read();
            }
        }

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

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

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;

public class Solu {
    static StringBuffer str = new StringBuffer();
    static InputReader in = new InputReader(System.in);
    static int mm=1000000007;
    public static void main(String[] args) {
        int i,j,it,t;
        int n=in.nextInt();
        long a[]=new long[n];
        long hk=0;
        long kj=0;
        for(i=0;i<n;i++){
            a[i]=in.nextLong();
            hk+=a[i];
        }
        int k=in.nextInt();
        long b[]=new long[k];

        for(i=0;i<k;i++){
            b[i]=in.nextLong();
            kj+=b[i];
        }
        long ss1=a[0];
        long ss2=b[0];
        int x=1;
        int y=1;
        ArrayList<Long> z=new ArrayList<>();
        ArrayList<Long> w=new ArrayList<>();
        while(true){
            if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
            else{
                if(ss1>ss2){
                    ss2+=b[y];
                    y+=1;
                }else{
                    ss1+=a[x];
		x+=1;
                }
            }
            if(x>=n || y>=k)
                break;
        }
        if(x<n){
            long kl=0;
            for(i=x;i<n;i++){
                kl+=a[i];
            }
            ss1+=kl;
        }
        if(y<k){
            long kl=0;
            for(i=y;i<k;i++){
                kl+=b[i];
            }
            ss2+=kl;
        }
        if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
        long gg=0;
        long hh=0;
        for(i=0;i<z.size();i++){
            gg+=z.get(i);
        }
        for(i=0;i<w.size();i++){
            hh+=w.get(i);
        }
        if(gg!=hh|| z.size()!=w.size()  || gg!=hk || hh!=kj){
            System.out.println(-1);
        }else{
            System.out.println(z.size());
        }
    }
    static long gcd(long a, long b){
        return (b==0)?a:gcd(b,a%b);
    }
    static int gcdi(int a, int b){
        return (b==0)?a:gcdi(b,a%b);
    }
    public static void ap(String st){
        str.append(st);
    }
    public static void pn() {
        System.out.println(str);
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0) {
                read();
            }
        }

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

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

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;

public class Solu {
    static StringBuffer str = new StringBuffer();
    static InputReader in = new InputReader(System.in);
    static int mm=1000000007;
    public static void main(String[] args) {
        int i,j,it,t;
        int n=in.nextInt();
        long a[]=new long[n];
        for(i=0;i<n;i++){
            a[i]=in.nextLong();
        }
        int k=in.nextInt();
        long b[]=new long[k];
        for(i=0;i<k;i++){
            b[i]=in.nextLong();
        }
        long ss1=a[0];
        long ss2=b[0];
        int x=1;
        int y=1;
        ArrayList<Long> z=new ArrayList<>();
        ArrayList<Long> w=new ArrayList<>();
        while(true){
            if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
            else{
                if(ss1>ss2){
                    ss2+=b[y];
                    y+=1;
                }else{
                    ss1+=a[x];
		x+=1;
                }
            }
            if(x>=n || y>=k)
                break;
        }
        if(x<n){
            long kl=0;
            for(i=x;i<n;i++){
                kl+=a[i];
            }
            ss1+=kl;
        }
        if(y<k){
            long kl=0;
            for(i=y;i<k;i++){
                kl+=b[i];
            }
            ss2+=kl;
        }
        if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
        long gg=0;
        long hh=0;
        for(i=0;i<z.size();i++){
            gg+=z.get(i);
        }
        for(i=0;i<w.size();i++){
            hh+=w.get(i);
        }
        if(gg!=hh|| z.size()!=w.size() || gg==0){
            System.out.println(-1);
        }else{
            System.out.println(z.size());
        }
    }
    static long gcd(long a, long b){
        return (b==0)?a:gcd(b,a%b);
    }
    static int gcdi(int a, int b){
        return (b==0)?a:gcdi(b,a%b);
    }
    public static void ap(String st){
        str.append(st);
    }
    public static void pn() {
        System.out.println(str);
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0) {
                read();
            }
        }

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

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

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;

public class Solu {
    static StringBuffer str = new StringBuffer();
    static InputReader in = new InputReader(System.in);
    static int mm=1000000007;
    public static void main(String[] args) {
        int i,j,it,t;
        int n=in.nextInt();
        long a[]=new long[n];
        for(i=0;i<n;i++){
            a[i]=in.nextLong();
        }
        int k=in.nextInt();
        long b[]=new long[k];
        for(i=0;i<k;i++){
            b[i]=in.nextLong();
        }
        long ss1=a[0];
        long ss2=b[0];
        int x=1;
        int y=1;
        ArrayList<Long> z=new ArrayList<>();
        ArrayList<Long> w=new ArrayList<>();
        while(true){
            if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
            else{
                if(ss1>ss2){
                    ss2+=b[y];
                    y+=1;
                }else{
                    ss1+=a[x];
		x+=1;
                }
            }
            if(x>=n || y>=k)
                break;
        }
        if(x<n){
            long kl=0;
            for(i=x;i<n;i++){
                kl+=a[i];
            }
            ss1+=kl;
        }
        if(y<k){
            long kl=0;
            for(i=y;i<k;i++){
                kl+=b[i];
            }
            ss2+=kl;
        }
        if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
        long gg=0;
        long hh=0;
        for(i=0;i<z.size();i++){
            gg+=z.get(i);
        }
        for(i=0;i<w.size();i++){
            hh+=w.get(i);
        }
        if(gg!=hh|| z.size()!=w.size()){
            System.out.println(-1);
        }else{
            System.out.println(z.size());
        }
    }
    static long gcd(long a, long b){
        return (b==0)?a:gcd(b,a%b);
    }
    static int gcdi(int a, int b){
        return (b==0)?a:gcdi(b,a%b);
    }
    public static void ap(String st){
        str.append(st);
    }
    public static void pn() {
        System.out.println(str);
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0) {
                read();
            }
        }

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

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

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}


import java.util.Scanner;
public class D_50{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n];
		for (int i = 0 ; i < n ; i++) A[i] = sc.nextLong();
		int m = sc.nextInt();
		long[] B = new long[m];
		for (int i = 0 ; i< m ; i++) B[i] = sc.nextInt();
		int A_idx = 0; int B_idx = 0;
	int counter= 0;
	long first = A[A_idx]; long second = B[B_idx];
		while(A_idx<n && B_idx<m){
			if (first == second){
				if (A_idx==n-1 || B_idx == m-1){
					counter++;
					A_idx++;
					B_idx++;
					break;
				}
				else{
					counter++;
					A_idx++; first = A[A_idx];
					B_idx++; second = B[B_idx];
				}
			}
			else if(first < second){
				A_idx++;
				if (A_idx<n)
					first += A[A_idx];
				else
					break;
			}
			else if(second < first)
			{
				B_idx++;
				if (B_idx < m)
				second += B[B_idx];
				else
					break;
			}
		}
		if (A_idx==n && B_idx==m)
			System.out.println(counter);
		else
			System.out.println(-1);
	}
}


import java.util.Scanner;
public class D_50{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n];
		for (int i = 0 ; i < n ; i++) A[i] = sc.nextLong();
		int m = sc.nextInt();
		long[] B = new long[m];
		for (int i = 0 ; i< m ; i++) B[i] = sc.nextInt();
		int A_idx = 0; int B_idx = 0;
	int counter= 0;
	long first = A[A_idx]; long second = B[B_idx];
		while(A_idx<n && B_idx<m){
			if (first == second){
				if (A_idx==n-1 || B_idx == m-1){
					counter++;
					A_idx++;
					B_idx++;
					break;
				}
				else{
					counter++;
					A_idx++; first = A[A_idx];
					B_idx++; second = B[B_idx];
				}
			}
			else if(first < second){
				A_idx++;
				first += A[A_idx];
			}
			else if(second < first)
			{
				B_idx++;
				second += B[B_idx];
			}
		}
		if (A_idx==n && B_idx==m)
			System.out.println(counter);
		else
			System.out.println(-1);
	}
}


import java.util.Scanner;
public class D_50{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n];
		for (int i = 0 ; i < n ; i++) A[i] = sc.nextLong();
		int m = sc.nextInt();
		long[] B = new long[m];
		for (int i = 0 ; i< m ; i++) B[i] = sc.nextInt();
		int A_idx = 0; int B_idx = 0;
	int counter= 0;
	long first = A[A_idx]; long second = B[B_idx];
		while(A_idx<n-1 && B_idx<m-1){
			if (first == second){
				counter++;
				A_idx++; first = A[A_idx];
				B_idx++; second = B[B_idx];
			}
			else if(first < second){
				A_idx++;
				first += A[A_idx];
			}
			else if(second < first)
			{
				B_idx++;
				second += B[B_idx];
			}
		}
		if (A_idx==n-1 && B_idx==m-1 && A[A_idx]==B[B_idx])
			System.out.println(counter+1);
		else
			System.out.println(-1);
	}
}


/*
javac d.java && java d
*/

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

public class d {
	public static void main(String[] args) { new d(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n, m;
	int[] a, b;
	long[] sa, sb;

	d() {
		n = in.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = in.nextInt();

		m = in.nextInt();
		b = new int[m];
		for (int i = 0; i < m; i++)
			b[i] = in.nextInt();

		boolean imp = false;
		int p = 0, q = 0, l = 0;
		long s = 0, t = 0;
		while (p < n && q < m) {
			s = a[p];
			t = b[q];

			if (s == t) {
				l++;
				p++;
				q++;
			}
			else {
				int np = p + 1;
				int nq = q + 1;
				while (np <= n && nq <= m && s != t) {
					if (s < t && np < n) s += a[np++];
					else if (nq < m) t += b[nq++];
					else break;
				}
				imp |= s != t;
				p = np;
				q = nq;
				l++;
			}
		}
		imp |= ((p == n) ^ (q == m));

		if (imp) out.println(-1);
		else out.println(l);
		out.close();
	}

	int abs(int x) { return x < 0 ? -x : x; }
	long abs(long x) { return x < 0 ? -x : x; }
	double abs(double x) { return x < 0 ? -x : x; }
	int min(int x, int y) { return x < y ? x : y; }
	int max(int x, int y) { return x > y ? x : y; }
	long min(long x, long y) { return x < y ? x : y; }
	long max(long x, long y) { return x > y ? x : y; }
	double min(double x, double y) { return x < y ? x : y; }
	double max(double x, double y) { return x > y ? x : y; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x / gcd(x, y)) * y; }
	long lcm(long x, long y) { return (x / gcd(x, y)) * y; }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


/*
javac d.java && java d
*/

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

public class d {
	public static void main(String[] args) { new d(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n, m;
	int[] a, b;
	long[] sa, sb;

	d() {
		n = in.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = in.nextInt();

		m = in.nextInt();
		b = new int[m];
		for (int i = 0; i < m; i++)
			b[i] = in.nextInt();

		boolean imp = false;
		int p = 0, q = 0, l = 0;
		long s = 0, t = 0;
		while (p < n && q < m) {
			s = a[p];
			t = b[q];

			if (s == t) {
				l++;
				p++;
				q++;
			}
			else {
				int np = p + 1;
				int nq = q + 1;
				while (np < n && nq < m && s != t) {
					if (s < t) s += a[np++];
					else t += b[nq++];
				}
				imp |= s != t;
				p = np;
				q = nq;
				l++;
			}
		}

		if (imp) out.println(-1);
		else out.println(l);
		out.close();
	}

	int abs(int x) { return x < 0 ? -x : x; }
	long abs(long x) { return x < 0 ? -x : x; }
	double abs(double x) { return x < 0 ? -x : x; }
	int min(int x, int y) { return x < y ? x : y; }
	int max(int x, int y) { return x > y ? x : y; }
	long min(long x, long y) { return x < y ? x : y; }
	long max(long x, long y) { return x > y ? x : y; }
	double min(double x, double y) { return x < y ? x : y; }
	double max(double x, double y) { return x > y ? x : y; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x / gcd(x, y)) * y; }
	long lcm(long x, long y) { return (x / gcd(x, y)) * y; }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


/*
javac d.java && java d
*/

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

public class d {
	public static void main(String[] args) { new d(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n, m;
	int[] a, b;
	long[] sa, sb;

	d() {
		n = in.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = in.nextInt();

		m = in.nextInt();
		b = new int[m];
		for (int i = 0; i < m; i++)
			b[i] = in.nextInt();

		boolean imp = false;
		int p = 0, q = 0, l = 0;
		long s = 0, t = 0;
		while (p < n && q < m) {
			s = a[p];
			t = b[q];

			if (s == t) {
				l++;
				p++;
				q++;
			}
			else {
				int np = p + 1;
				int nq = q + 1;
				while (np < n && nq < m && s != t) {
					if (s < t) s += a[np++];
					else t += b[nq++];
				}
				imp |= s != t;
				p = np;
				q = nq;
				l++;
			}
		}
		imp |= ((p == n) ^ (q == m));

		if (imp) out.println(-1);
		else out.println(l);
		out.close();
	}

	int abs(int x) { return x < 0 ? -x : x; }
	long abs(long x) { return x < 0 ? -x : x; }
	double abs(double x) { return x < 0 ? -x : x; }
	int min(int x, int y) { return x < y ? x : y; }
	int max(int x, int y) { return x > y ? x : y; }
	long min(long x, long y) { return x < y ? x : y; }
	long max(long x, long y) { return x > y ? x : y; }
	double min(double x, double y) { return x < y ? x : y; }
	double max(double x, double y) { return x > y ? x : y; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x / gcd(x, y)) * y; }
	long lcm(long x, long y) { return (x / gcd(x, y)) * y; }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n1 = scan.nextInt();
        int[] a = new int[n1];
        for (int i=0;i<n1;i++) a[i] = scan.nextInt();
        int n2 = scan.nextInt();
        int[] b = new int[n2];
        for (int i=0;i<n2;i++) b[i] = scan.nextInt();
        Task tsk = new Task();
        System.out.println(tsk.solve(a, b));
    }

    static class Task{
        public int solve(int[] a, int[] b){
            long suma = 0, sumb = 0;
            for (int i: a) suma += i;
            for (int i: b) sumb += i;
            if (suma != sumb) return -1;
            int cnt = 0;
            int p1 = 0, p2 = 0;
            long s1 = 0, s2 = 0;
            while (p1 < a.length || p2 < b.length) {
                if (s1 < s2) {
                    if (p1 == a.length) break;
                    s1 += a[p1++];
                }
                else if (s1 > s2) {
                    if (p2 == b.length) break;
                    s2 += b[p2++];
                }
                else {
                    if (s1 != 0) cnt++;
                    if (p1 < a.length && p2 < b.length) {
                        s1 = a[p1++];
                        s2 = b[p2++];
                    } else break;
                }
            }
            return p1 == a.length && p2 == b.length && s1 == s2? cnt + (s1 > 0?1:0): -1;
        }
    }
}


import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        InputReader in = new InputReader(inputStream);
        int n1 = in.nextInt();
        int[] a = new int[n1];
        for (int i=0;i<n1;i++) a[i] = in.nextInt();
        int n2 = in.nextInt();
        int[] b = new int[n2];
        for (int i=0;i<n2;i++) b[i] = in.nextInt();
        Task tsk = new Task();
        System.out.println(tsk.solve(a, b));
    }

    static class Task{
        public int solve(int[] a, int[] b){
            int cnt = 0;
            int p1 = 1, p2 = 1;
            long s1 = a[0], s2 = b[0];
            while (p1 < a.length || p2 < b.length) {
                if (s1 < s2) {
                    if (p1 == a.length) break;
                    s1 += a[p1++];
                }
                else if (s1 > s2) {
                    if (p2 == b.length) break;
                    s2 += b[p2++];
                }
                else {
                    if (s1 != 0) cnt++;
                    if (p1 < a.length) s1 += a[p1++];
                    if (p2 < b.length) s2 += b[p2++];
                }
            }
            return p1 == a.length && p2 == b.length && s1 == s2? cnt + (s1 > 0?1:0): -1;
        }
    }

    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());
        }

    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n1 = scan.nextInt();
        int[] a = new int[n1];
        for (int i=0;i<n1;i++) a[i] = scan.nextInt();
        int n2 = scan.nextInt();
        int[] b = new int[n2];
        for (int i=0;i<n2;i++) b[i] = scan.nextInt();
        Task tsk = new Task();
        System.out.println(tsk.solve(a, b));
    }

    static class Task{
        public int solve(int[] a, int[] b){
            int cnt = 0;
            int p1 = 0, p2 = 0, s1 = 0, s2 = 0;
            while (p1 < a.length || p2 < b.length) {
                if (s1 < s2) {
                    if (p1 == a.length) break;
                    s1 += a[p1++];
                }
                else if (s1 > s2) {
                    if (p2 == b.length) break;
                    s2 += b[p2++];
                }
                else {
                    if (s1 != 0) cnt++;
                    if (p1 < a.length && p2 < b.length) {
                        s1 = a[p1++];
                        s2 = b[p2++];
                    } else break;
                }
            }
            return p1 == a.length && p2 == b.length && s1 == s2? cnt + (s1 > 0?1:0): -1;
        }
    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n1 = scan.nextInt();
        int[] a = new int[n1];
        for (int i=0;i<n1;i++) a[i] = scan.nextInt();
        int n2 = scan.nextInt();
        int[] b = new int[n2];
        for (int i=0;i<n2;i++) b[i] = scan.nextInt();
        Task tsk = new Task();
        System.out.println(tsk.solve(a, b));
    }

    static class Task{
        public int solve(int[] a, int[] b){
            int cnt = 0;
            int p1 = 0, p2 = 0;
            long s1 = 0, s2 = 0;
            while (p1 < a.length || p2 < b.length) {
                if (s1 < s2) {
                    if (p1 == a.length) break;
                    s1 += a[p1++];
                }
                else if (s1 > s2) {
                    if (p2 == b.length) break;
                    s2 += b[p2++];
                }
                else {
                    if (s1 != 0) cnt++;
                    if (p1 < a.length && p2 < b.length) {
                        s1 = a[p1++];
                        s2 = b[p2++];
                    } else break;
                }
            }
            return p1 == a.length && p2 == b.length && s1 == s2? cnt + (s1 > 0?1:0): -1;
        }
    }
}


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

public class Main {

    public static void main(String[] args)
    {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        int[]a = new int[n];
        for (int i =0;i<n;i++)
            a[i]=in.nextInt();
        int m = in.nextInt();
        int[]b = new int[m];
        for (int i =0;i<m;i++)
            b[i]=in.nextInt();
        boolean check= true;
        int p0=0;
        int p1=0;
        long sum1=0;
        long sum2=0;
        long length1=n;
        long length2=m;
        while (p0<n||p1<m)
        {
            if (p0>=n&&p1<m)
            {
                check=false;
                break;
            }
            if (p0<n&&p1>=m)
            {
                check=false;
                break;
            }
            if (sum1==0)
            {
                sum1+=(long)a[p0];
                sum2+=(long)b[p1];
                p0++;
                p1++;
                continue;
            }
            if (sum1>sum2)
            {
                sum2+=(long)b[p1];
                p1++;
                length2--;
            }
            else if (sum1<sum2)
            {
                sum1+=(long)a[p0];
                p0++;
                length1--;
            }
           else if (sum1==sum2)
            {
                sum1+=(long)a[p0];
                sum2+=(long)b[p1];
                p0++;
                p1++;

            }
        }
        out.printLine(length1!=length2?-1:length1);
        out.flush();
    }

}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public String readString() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}


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

public class Main {

    public static void main(String[] args)
    {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        long[]a = new long[n];
        for (int i =0;i<n;i++)
            a[i]=in.nextLong();
        int m = in.nextInt();
        long[]b = new long[m];
        for (int i =0;i<m;i++)
            b[i]=in.nextLong();
        boolean check= true;
        int p0=0;
        int p1=0;
        long sum1=0;
        long sum2=0;
        long length1=n;
        long length2=m;
        while (p0<n||p1<m)
        {

            if (sum1==0)
            {
                sum1+=(long)a[p0];
                sum2+=(long)b[p1];
                p0++;
                p1++;
                continue;
            }
            if (sum1>sum2)
            {
                if (p1>=m)
                {
                    check=false;
                    break;
                }
                sum2+=(long)b[p1];
                p1++;
                length2--;
            }
            else if (sum1<sum2)
            {
                if (p0>=n)
                {
                    check=false;
                    break;
                }
                sum1+=(long)a[p0];
                p0++;
                length1--;
            }
           else if (sum1==sum2)
            {
                if ((p0>=n&&p1<m)||(p0<n&&p1>=m))
                {
                    check=false;
                    break;
                }
                sum1=(long)a[p0];
                sum2=(long)b[p1];
                p0++;
                p1++;

            }
        }
        out.printLine(length1!=length2||!check||sum1!=sum2?-1:length1);
        out.flush();
    }

}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public String readString() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}


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

public class Main {

    public static void main(String[] args)
    {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        int[]a = new int[n];
        for (int i =0;i<n;i++)
            a[i]=in.nextInt();
        int m = in.nextInt();
        int[]b = new int[m];
        for (int i =0;i<m;i++)
            b[i]=in.nextInt();
        boolean check= true;
        int p0=0;
        int p1=0;
        long sum1=0;
        long sum2=0;
        long length1=n;
        long length2=m;
        while (p0<n||p1<m)
        {
            if (p0>=n&&p1<m)
            {
                check=false;
                break;
            }
            if (p0<n&&p1>=m)
            {
                check=false;
                break;
            }
            if (sum1==0)
            {
                sum1+=(long)a[p0];
                sum2+=(long)b[p1];
                p0++;
                p1++;
                continue;
            }
            if (sum1>sum2)
            {
                sum2+=b[p1];
                p1++;
                length2--;
            }
            else if (sum1<sum2)
            {
                sum1+=a[p0];
                p0++;
                length1--;
            }
           else if (sum1==sum2)
            {
                sum1+=a[p0];
                sum2+=b[p1];
                p0++;
                p1++;

            }
        }
        out.printLine(length1!=length2?-1:length1);
        out.flush();
    }

}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public String readString() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}


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

public class d {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }

    public static void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }

        int m = in.nextInt();
        int[] b = new int[m];

        for (int i = 0; i < m; ++i) {
            b[i] = in.nextInt();
        }

        int ai = 0, bi = 0;
        long aSum = a[0], bSum = b[0];
        int result = 0;

        while (ai < n - 1 || bi < m - 1) {
            if (aSum > bSum && bi < m - 1) {
                bSum += b[++bi];
            } else if (aSum < bSum && ai < n - 1) {
                aSum += a[++ai];
            } else if (aSum == bSum) {
                aSum = 0;
                bSum = 0;
                ++result;

                if (ai < n - 1) {
                    aSum = a[++ai];
                }

                if (bi < m - 1) {
                    bSum = b[++bi];
                }
            }
        }

        if (aSum == bSum) {
            ++result;
        } else {
            result = -1;
        }

        out.println(result);
        out.flush();
    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

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

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


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

public class d {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }

    public static void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }

        int m = in.nextInt();
        int[] b = new int[m];

        for (int i = 0; i < m; ++i) {
            b[i] = in.nextInt();
        }

        int ai = 0, bi = 0;
        int result = 0;
        long aSum = 0, bSum = 0;

        while (ai < n && bi < m) {
            ++result;

            aSum = a[ai++];
            bSum = b[bi++];

            while (aSum != bSum) {
                if (aSum < bSum && ai < n) {
                    aSum += a[ai++];
                } else if (aSum > bSum && bi < m) {
                    bSum += b[bi++];
                } else {
                    break;
                }
            }
        }

        if (ai < n) {
            for (int i = ai; i < n; ++i) {
                aSum += a[ai];
            }
        }

        if (bi < m) {
            for (int i = bi; i < m; ++i) {
                bSum += b[bi];
            }
        }

        if (aSum != bSum) {
            result = -1;
        }

        out.println(result);
        out.flush();
    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

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

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


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

public class d {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }

    public static void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }

        int m = in.nextInt();
        int[] b = new int[m];

        for (int i = 0; i < m; ++i) {
            b[i] = in.nextInt();
        }

        int ai = 0, bi = 0;
        int result = 0;
        long aSum = 0, bSum = 0;

        while (ai < n && bi < m) {
            ++result;

            aSum = a[ai++];
            bSum = b[bi++];

            while (aSum != bSum) {
                if (aSum < bSum) {
                    aSum += a[ai++];
                } else {
                    bSum += b[bi++];
                }
            }
        }

        if (aSum != bSum) {
            result = -1;
        }

        out.println(result);
        out.flush();
    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

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

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


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

public class d {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }

    public static void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }

        int m = in.nextInt();
        int[] b = new int[m];

        for (int i = 0; i < m; ++i) {
            b[i] = in.nextInt();
        }

        int ai = 0, bi = 0;
        int result = 0;
        long aSum = 0, bSum = 0;

        while (ai < n && bi < m) {
            ++result;

            aSum = a[ai++];
            bSum = b[bi++];

            while (aSum != bSum) {
                if (aSum < bSum && ai < n) {
                    aSum += a[ai++];
                } else if (aSum > bSum && bi < m) {
                    bSum += b[bi++];
                } else {
                    break;
                }
            }
        }

        if (aSum != bSum) {
            result = -1;
        }

        out.println(result);
        out.flush();
    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

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

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


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

public class Codeforces1036D {
	public static void main(String[] args) {
		MyScanner scanner = new MyScanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		int m = scanner.nextInt();
		int[] b = new int[m];
		for(int i = 0; i < m; i++) {
			b[i] = scanner.nextInt();
		}
		int i = 0;
		int j = 0;
		long sumA = a[0];
		long sumB = b[0];
		int ans = 0;
		while(i < n && j < m) {
			if(sumA == sumB) {
				ans++;
				i++;
				j++;
				if(i < n) {
					sumA = a[i];
				}
				if(j < m) {
					sumB = b[j];
				}
			}
			else if(sumA < sumB) {
				i++;
				if(i < n) {
					sumA += a[i];
				}
			}
			else {
				j++;
				if(j < m) {
					sumB += b[j];
				}
			}
		}
		if(i < n || j < m) {
			ans = -1;
		}
		System.out.println(ans);
	}
}

class MyScanner {
	private BufferedReader reader;
	private StringTokenizer tokens;

	public MyScanner(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
	}

	public String next() {
		while(tokens == null || !tokens.hasMoreElements()) {
			try {
				tokens = new StringTokenizer(reader.readLine());
			} catch(IOException error) {
				error.printStackTrace();
			}
		}
		return tokens.nextToken();
	}

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


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

public class Codeforces1036D {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		int m = scanner.nextInt();
		int[] b = new int[m];
		for(int i = 0; i < m; i++) {
			b[i] = scanner.nextInt();
		}
		int i = 0;
		int j = 0;
		long sumA = a[0];
		long sumB = b[0];
		int ans = 0;
		while(i < n && j < m) {
			if(sumA == sumB) {
				ans++;
				i++;
				j++;
				if(i < n) {
					sumA = a[i];
				}
				if(j < m) {
					sumB = b[j];
				}
			}
			else if(sumA < sumB) {
				i++;
				if(i < n) {
					sumA += a[i];
				}
			}
			else {
				j++;
				if(j < m) {
					sumB += b[j];
				}
			}
		}
		if(i < n || j < m) {
			ans = -1;
		}
		System.out.println(ans);
	}
}


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

public class Codeforces1036D {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		int m = scanner.nextInt();
		int[] b = new int[m];
		for(int i = 0; i < m; i++) {
			b[i] = scanner.nextInt();
		}
		int i = 0;
		int j = 0;
		int sumA = a[0];
		int sumB = b[0];
		int ans = 0;
		while(i < n && j < m) {
			if(sumA == sumB) {
				ans++;
				i++;
				j++;
				if(i < n) {
					sumA = a[i];
				}
				if(j < m) {
					sumB = b[j];
				}
			}
			else if(sumA < sumB) {
				i++;
				if(i < n) {
					sumA += a[i];
				}
			}
			else {
				j++;
				if(j < m) {
					sumB += b[j];
				}
			}
		}
		if(i < n || j < m) {
			ans = -1;
		}
		System.out.println(ans);
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    int A[] = new int[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Integer.parseInt(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    int B[] = new int[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Integer.parseInt(st.nextToken());

	    int sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        int tA=0,tB=0,c=0;
	        int i=0,j=0;

	        while(i<n && j<m)
	        {
	            tA+=A[i];
	            tB+=B[j];

	            if(tA==tB)
	            {
	                c++;
	                tA=tB=0;
	            }
	            else
	            {
	                while(tA!=tB)
	                {
	                    if(tA<tB)
	                    {
	                        i++;
	                        tA+=A[i];
	                    }
	                    else
	                    {
	                        j++;
	                        tB+=B[j];
	                    }
	                }
	                c++;
	                tA=tB=0;
	            }
	            i++;
	            j++;
	        }
	        System.out.println(c);

	    }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    int A[] = new int[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Integer.parseInt(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    int B[] = new int[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Integer.parseInt(st.nextToken());

	    int sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        long tA=0,tB=0,c=0;
	        int i=0,j=0;

	        while(i<n && j<m)
	        {
	            tA+=A[i];
	            tB+=B[j];

	            if(tA==tB)
	            {
	                c++;
	                tA=tB=0;
	            }
	            else
	            {
	                while(tA!=tB)
	                {
	                    if(tA<tB)
	                    {
	                        if(i<n)
	                        {
	                            i++;
	                            tA+=A[i];
	                        }
	                    }
	                    else
	                    {
	                        if(j<m)
	                        {
	                            j++;
	                            tB+=B[j];
	                        }
	                    }
	                }
	                c++;
	                tA=tB=0;
	            }
	            i++;
	            j++;
	        }
	        System.out.println(c);

	    }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    long A[] = new long[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Long.parseLong(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    long B[] = new long[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Long.parseLong(st.nextToken());

	    long sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        long tA=0,tB=0,c=0;
	        int i=0,j=0;
	        while(i<n && j<m)
	        {
	            tA+=A[i++];
	            tB+=B[j++];

	            if(tA==tB)
	            {
	                c++;
	                tA=tB=0;
	            }
	            else
	            {
	                while(tA!=tB)
	                {
	                    if(tA<tB)
	                    {
	                        tA+=A[i++];
	                    }
	                    else
	                    {
	                        tB+=B[j++];
	                    }
	                }
	                c++;
	                tA=tB=0;
	            }
	        }
	        System.out.println(c);

	    }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    int A[] = new int[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Integer.parseInt(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    int B[] = new int[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Integer.parseInt(st.nextToken());

	    int sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        long tA=0,tB=0,c=0;
	        int i=0,j=0;

	        while(i<n)
	        {
	            tA+=A[i++];
	            tB+=B[j++];
	            c++;

	            while(tA!=tB)
	            {
	                if(tA<tB)   tA+=A[i++];
	                else    tB+=B[j++];
	            }
	        }
	        System.out.println(c);

	    }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    int A[] = new int[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Integer.parseInt(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    int B[] = new int[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Integer.parseInt(st.nextToken());

	    int sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        int tA=0,tB=0,c=0;
	        int i=0,j=0;

	        while(i<n && j<m)
	        {
	            tA+=A[i];
	            tB+=B[j];

	            if(tA==tB)
	            {
	                c++;
	                tA=tB=0;
	            }
	            else
	            {
	                while(tA!=tB)
	                {
	                    if(tA<tB)
	                    {
	                        if(i<n)
	                        {
	                            i++;
	                            tA+=A[i];
	                        }
	                    }
	                    else
	                    {
	                        if(j<m)
	                        {
	                            j++;
	                            tB+=B[j];
	                        }
	                    }
	                }
	                c++;
	                tA=tB=0;
	            }
	            i++;
	            j++;
	        }
	        System.out.println(c);

	    }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    int A[] = new int[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Integer.parseInt(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    int B[] = new int[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Integer.parseInt(st.nextToken());

	    int sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        int tA=0,tB=0,c=0;
	        int i=-1,j=-1;

	        while(i<n-1 && j<m-1)
	        {
	            i++;
	            j++;

	            tA+=A[i];
	            tB+=B[j];

	            if(tA==tB)
	            {
	                c++;
	                tA=tB=0;
	            }
	            else
	            {
	                while(tA!=tB)
	                {
	                    if(tA<tB)
	                    {
	                        i++;
	                        tA+=A[i];
	                    }
	                    else
	                    {
	                        j++;
	                        tB+=B[j];
	                    }
	                }
	                c++;
	                tA=tB=0;
	            }
	        }
	        System.out.println(c);

	    }
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static ArrayList<ArrayList<Integer>> list;
    static HashSet<Integer> hs;
    static ArrayList<Integer> tmp;
    //int n=Integer.parseInt(br.readLine());
    //int n=Integer.parseInt(st.nextToken());
    //StringTokenizer st = new StringTokenizer(br.readLine());
	public static void main (String[] args) throws java.lang.Exception
	{
	    int n=Integer.parseInt(br.readLine());
	    long A[] = new long[n];
	    StringTokenizer st = new StringTokenizer(br.readLine());
	    for(int i=0;i<n;i++)
	    A[i] = Long.parseLong(st.nextToken());

	    int m=Integer.parseInt(br.readLine());
	    long B[] = new long[m];
	    st = new StringTokenizer(br.readLine());
	    for(int i=0;i<m;i++)
	    B[i] = Long.parseLong(st.nextToken());

	    int sA=0,sB=0;

	    for(int i=0;i<n;i++)
	    sA+=A[i];

	    for(int i=0;i<m;i++)
	    sB+=B[i];

	    if(sA!=sB)
	    System.out.println("-1");

	    else
	    {
	        long tA=0,tB=0,c=0;
	        int i=0,j=0;
	        while(i<n && j<m)
	        {
	            tA+=A[i++];
	            tB+=B[j++];

	            if(tA==tB)
	            {
	                c++;
	                tA=tB=0;
	            }
	            else
	            {
	                while(tA!=tB)
	                {
	                    if(tA<tB)
	                    {
	                        tA+=A[i++];
	                    }
	                    else
	                    {
	                        tB+=B[j++];
	                    }
	                }
	                c++;
	                tA=tB=0;
	            }
	        }
	        System.out.println(c);

	    }
	}
}