//package CodeForces;

/*In the name of Allah the Most Merciful.
 * Author
 * Md. Toufiqul Islam
 * Dept. Of CSE
 * Ahsanullah University Of Science And Technology
*/
import java.util.*;
import java.math.*;
import java.io.*;
public class R469B {
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Long> block1 = new ArrayList<>();
        List<Long> block2 = new ArrayList<>();

        for(int i=0;i<n;i++){
            block1.add(sc.nextLong());
        }

        for(int i=0;i<m;i++){
            block2.add(sc.nextLong());
        }

        out.println(getCOunt(block1,block2,n,m));

        out.close();
    }

    public static int getCOunt(List<Long> list1,List<Long> list2,int n,int m){

        int pointer1 =1;
        int pointer2 = 1;

        long sum1 = list1.get(0);

        long sum2 = list2.get(0);
        int counter =0;

        while (true){
            //System.out.println(pointer1+" "+pointer2);
           // System.out.println(sum1+" "+sum2);

            if(sum1==sum2){
                counter++;
                if(pointer1<list1.size()) {
                    sum1 = list1.get(pointer1);
                }
                if(pointer2<list2.size()) {
                    sum2 = list2.get(pointer2);
                }
                if(pointer1<list1.size()) {
                    pointer1++;
                }

                if(pointer2<list2.size()) {
                    pointer2++;
                }
            }

            if(pointer1==n && pointer2==m){
                break;
            }

            else if(sum1<sum2){

                    while (sum1<sum2){
                        sum1+= list1.get(pointer1);
                        pointer1++;
                    }
                   // System.out.println("sum1 "+sum1);

            }

            else if(sum2<sum1){

                    while (sum2<sum1){
                        sum2+= list2.get(pointer2);
                        pointer2++;
                    }

            }

        }

        return counter;
    }
     public static class InputReader {
             private boolean finished = false;

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

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

             public int read() {
                 if (numChars == -1) {
                     throw new InputMismatchException();
                 }
                 if (curChar >= numChars) {
                     curChar = 0;
                     try {
                         numChars = stream.read(buf);
                     } catch (IOException e) {
                         throw new InputMismatchException();
                     }
                     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 int nextInt() {
                 int c = read();
                 while (isSpaceChar(c)) {
                     c = read();
                 }
                 int sgn = 1;
                 if (c == '-') {
                     sgn = -1;
                     c = read();
                 }
                 int res = 0;
                 do {
                     if (c < '0' || c > '9') {
                         throw new InputMismatchException();
                     }
                     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 {
                     if (c < '0' || c > '9') {
                         throw new InputMismatchException();
                     }
                     res *= 10;
                     res += c - '0';
                     c = read();
                 } while (!isSpaceChar(c));
                 return res * sgn;
             }

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

             public boolean isSpaceChar(int c) {
                 if (filter != null) {
                     return filter.isSpaceChar(c);
                 }
                 return isWhitespace(c);
             }

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

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

             public String readLine() {
                 String s = readLine0();
                 while (s.trim().length() == 0) {
                     s = readLine0();
                 }
                 return s;
             }

             public String readLine(boolean ignoreEmptyLines) {
                 if (ignoreEmptyLines) {
                     return readLine();
                 } else {
                     return readLine0();
                 }
             }

             public BigInteger readBigInteger() {
                 try {
                     return new BigInteger(nextString());
                 } catch (NumberFormatException e) {
                     throw new InputMismatchException();
                 }
             }

             public char nextCharacter() {
                 int c = read();
                 while (isSpaceChar(c)) {
                     c = read();
                 }
                 return (char) c;
             }

             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 isExhausted() {
                 int value;
                 while (isSpaceChar(value = peek()) && value != -1) {
                     read();
                 }
                 return value == -1;
             }

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

             public SpaceCharFilter getFilter() {
                 return filter;
             }

             public void setFilter(SpaceCharFilter filter) {
                 this.filter = filter;
             }

             public interface SpaceCharFilter {
                 public boolean isSpaceChar(int ch);
             }
             public int[] nextIntArray(int n){
                 int[] array=new int[n];
                 for(int i=0;i<n;++i)array[i]=nextInt();
                 return array;
             }
             public int[] nextSortedIntArray(int n){
                 int array[]=nextIntArray(n);
                 Arrays.sort(array);
                 return array;
             }
             public int[] nextSumIntArray(int n){
                 int[] array=new int[n];
                 array[0]=nextInt();
                 for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
                 return array;
             }
             public long[] nextLongArray(int n){
                 long[] array=new long[n];
                 for(int i=0;i<n;++i)array[i]=nextLong();
                 return array;
             }
             public long[] nextSumLongArray(int n){
                 long[] array=new long[n];
                 array[0]=nextInt();
                 for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
                 return array;
             }
             public long[] nextSortedLongArray(int n){
                 long array[]=nextLongArray(n);
                 Arrays.sort(array);
                 return array;
             }
         }
      public static 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(char[] array) {
                  writer.print(array);
              }

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

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

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

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

              public void println(int[] array) {
                  print(array);
                  writer.println();
              }

              public void println(double[] array) {
                  print(array);
                  writer.println();
              }

              public void println(long[] array) {
                  print(array);
                  writer.println();
              }

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

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

              public void print(char i) {
                  writer.print(i);
              }

              public void println(char i) {
                  writer.println(i);
              }

              public void println(char[] array) {
                  writer.println(array);
              }

              public void printf(String format, Object... objects) {
                  writer.printf(format, objects);
              }

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

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

              public void print(long i) {
                  writer.print(i);
              }

              public void println(long i) {
                  writer.println(i);
              }

              public void print(int i) {
                  writer.print(i);
              }

              public void println(int i) {
                  writer.println(i);
              }

              public void separateLines(int[] array) {
                  for (int i : array) {
                      println(i);
                  }
              }
          }

}


//package CodeForces;

/*In the name of Allah the Most Merciful.
 * Author
 * Md. Toufiqul Islam
 * Dept. Of CSE
 * Ahsanullah University Of Science And Technology
*/
import java.util.*;
import java.math.*;
import java.io.*;
public class R469B {
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Long> block1 = new ArrayList<>();
        List<Long> block2 = new ArrayList<>();

        for(int i=0;i<n;i++){
            block1.add(sc.nextLong());
        }

        for(int i=0;i<m;i++){
            block2.add(sc.nextLong());
        }

        int pointer1 = 0;
        int pointer2 = 0;
        int count =0;
        long sum1 = block1.get(0);
        long sum2 = block2.get(0);
        while (pointer1<=n-1 && pointer2<=m-1){

          //  System.out.println("pointer1 "+pointer1+" "+"pointer2"+" "+pointer2);

            if(sum1==sum2){
                count++;
            }
            if(sum1<sum2){
                while (sum1<sum2){
                    if(pointer1<=n-2) {
                        pointer1++;
                    }
                    sum1 += block1.get(pointer1);

                }
                if(sum1==sum2){
                    count++;

                }
               // System.out.println("after Incremnent ponter1 "+sum1+" "+sum2);
            }

             if(sum2<sum1){
                while (sum2<sum1){
                    if(pointer2<=m-2){
                        pointer2++;
                    }

                    sum2 += block2.get(pointer2);
                }
                if(sum1==sum2){

                    count++;

                }
             //   System.out.println("after Incremnent ponter2 "+sum1+" "+sum2);

            }

            pointer1++;
            pointer2++;
            if(pointer1>=n || pointer2>=m){
                break;
            }

            if(sum1==sum2){
                sum1 = block1.get(pointer1);
                sum2 = block2.get(pointer2);
            }
            else{
                sum1 += block1.get(pointer1);
                sum2 += block2.get(pointer2);
            }

            //out.println(count);

        }

        out.println(count);

        out.close();
    }
     public static class InputReader {
             private boolean finished = false;

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

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

             public int read() {
                 if (numChars == -1) {
                     throw new InputMismatchException();
                 }
                 if (curChar >= numChars) {
                     curChar = 0;
                     try {
                         numChars = stream.read(buf);
                     } catch (IOException e) {
                         throw new InputMismatchException();
                     }
                     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 int nextInt() {
                 int c = read();
                 while (isSpaceChar(c)) {
                     c = read();
                 }
                 int sgn = 1;
                 if (c == '-') {
                     sgn = -1;
                     c = read();
                 }
                 int res = 0;
                 do {
                     if (c < '0' || c > '9') {
                         throw new InputMismatchException();
                     }
                     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 {
                     if (c < '0' || c > '9') {
                         throw new InputMismatchException();
                     }
                     res *= 10;
                     res += c - '0';
                     c = read();
                 } while (!isSpaceChar(c));
                 return res * sgn;
             }

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

             public boolean isSpaceChar(int c) {
                 if (filter != null) {
                     return filter.isSpaceChar(c);
                 }
                 return isWhitespace(c);
             }

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

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

             public String readLine() {
                 String s = readLine0();
                 while (s.trim().length() == 0) {
                     s = readLine0();
                 }
                 return s;
             }

             public String readLine(boolean ignoreEmptyLines) {
                 if (ignoreEmptyLines) {
                     return readLine();
                 } else {
                     return readLine0();
                 }
             }

             public BigInteger readBigInteger() {
                 try {
                     return new BigInteger(nextString());
                 } catch (NumberFormatException e) {
                     throw new InputMismatchException();
                 }
             }

             public char nextCharacter() {
                 int c = read();
                 while (isSpaceChar(c)) {
                     c = read();
                 }
                 return (char) c;
             }

             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 isExhausted() {
                 int value;
                 while (isSpaceChar(value = peek()) && value != -1) {
                     read();
                 }
                 return value == -1;
             }

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

             public SpaceCharFilter getFilter() {
                 return filter;
             }

             public void setFilter(SpaceCharFilter filter) {
                 this.filter = filter;
             }

             public interface SpaceCharFilter {
                 public boolean isSpaceChar(int ch);
             }
             public int[] nextIntArray(int n){
                 int[] array=new int[n];
                 for(int i=0;i<n;++i)array[i]=nextInt();
                 return array;
             }
             public int[] nextSortedIntArray(int n){
                 int array[]=nextIntArray(n);
                 Arrays.sort(array);
                 return array;
             }
             public int[] nextSumIntArray(int n){
                 int[] array=new int[n];
                 array[0]=nextInt();
                 for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
                 return array;
             }
             public long[] nextLongArray(int n){
                 long[] array=new long[n];
                 for(int i=0;i<n;++i)array[i]=nextLong();
                 return array;
             }
             public long[] nextSumLongArray(int n){
                 long[] array=new long[n];
                 array[0]=nextInt();
                 for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
                 return array;
             }
             public long[] nextSortedLongArray(int n){
                 long array[]=nextLongArray(n);
                 Arrays.sort(array);
                 return array;
             }
         }
      public static 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(char[] array) {
                  writer.print(array);
              }

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

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

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

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

              public void println(int[] array) {
                  print(array);
                  writer.println();
              }

              public void println(double[] array) {
                  print(array);
                  writer.println();
              }

              public void println(long[] array) {
                  print(array);
                  writer.println();
              }

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

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

              public void print(char i) {
                  writer.print(i);
              }

              public void println(char i) {
                  writer.println(i);
              }

              public void println(char[] array) {
                  writer.println(array);
              }

              public void printf(String format, Object... objects) {
                  writer.printf(format, objects);
              }

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

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

              public void print(long i) {
                  writer.print(i);
              }

              public void println(long i) {
                  writer.println(i);
              }

              public void print(int i) {
                  writer.print(i);
              }

              public void println(int i) {
                  writer.println(i);
              }

              public void separateLines(int[] array) {
                  for (int i : array) {
                      println(i);
                  }
              }
          }

}


//package CodeForces;

/*In the name of Allah the Most Merciful.
 * Author
 * Md. Toufiqul Islam
 * Dept. Of CSE
 * Ahsanullah University Of Science And Technology
*/
import java.util.*;
import java.math.*;
import java.io.*;
public class R469B {
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Long> block1 = new ArrayList<>();
        List<Long> block2 = new ArrayList<>();

        for(int i=0;i<n;i++){
            block1.add(sc.nextLong());
        }

        for(int i=0;i<m;i++){
            block2.add(sc.nextLong());
        }

        int pointer1 = 0;
        int pointer2 = 0;
        int count =0;
        while (pointer1<=n-1 && pointer2<=m-1){

          //  System.out.println("pointer1 "+pointer1+" "+"pointer2"+" "+pointer2);
            long sum1 = block1.get(pointer1);
            long sum2 = block2.get(pointer2);

            if(sum1==sum2){
                count++;
            }
            if(sum1<sum2){
                while (sum1<sum2){
                    if(pointer1<=n-2) {
                        pointer1++;
                    }
                    sum1 += block1.get(pointer1);

                }
                if(sum1==sum2){
                    count++;

                }
               // System.out.println("after Incremnent ponter1 "+sum1+" "+sum2);
            }

             if(sum2<sum1){
                while (sum2<sum1){
                    if(pointer2<=m-2){
                        pointer2++;
                    }

                    sum2 += block2.get(pointer2);
                }
                if(sum1==sum2){
                   // System.out.println("Nabila");
                    count++;

                }
               // System.out.println("after Incremnent ponter2 "+sum1+" "+sum2);
            }

            pointer1++;
            pointer2++;

            //out.println(count);

        }

        out.println(count);

        out.close();
    }
     public static class InputReader {
             private boolean finished = false;

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

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

             public int read() {
                 if (numChars == -1) {
                     throw new InputMismatchException();
                 }
                 if (curChar >= numChars) {
                     curChar = 0;
                     try {
                         numChars = stream.read(buf);
                     } catch (IOException e) {
                         throw new InputMismatchException();
                     }
                     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 int nextInt() {
                 int c = read();
                 while (isSpaceChar(c)) {
                     c = read();
                 }
                 int sgn = 1;
                 if (c == '-') {
                     sgn = -1;
                     c = read();
                 }
                 int res = 0;
                 do {
                     if (c < '0' || c > '9') {
                         throw new InputMismatchException();
                     }
                     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 {
                     if (c < '0' || c > '9') {
                         throw new InputMismatchException();
                     }
                     res *= 10;
                     res += c - '0';
                     c = read();
                 } while (!isSpaceChar(c));
                 return res * sgn;
             }

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

             public boolean isSpaceChar(int c) {
                 if (filter != null) {
                     return filter.isSpaceChar(c);
                 }
                 return isWhitespace(c);
             }

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

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

             public String readLine() {
                 String s = readLine0();
                 while (s.trim().length() == 0) {
                     s = readLine0();
                 }
                 return s;
             }

             public String readLine(boolean ignoreEmptyLines) {
                 if (ignoreEmptyLines) {
                     return readLine();
                 } else {
                     return readLine0();
                 }
             }

             public BigInteger readBigInteger() {
                 try {
                     return new BigInteger(nextString());
                 } catch (NumberFormatException e) {
                     throw new InputMismatchException();
                 }
             }

             public char nextCharacter() {
                 int c = read();
                 while (isSpaceChar(c)) {
                     c = read();
                 }
                 return (char) c;
             }

             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 isExhausted() {
                 int value;
                 while (isSpaceChar(value = peek()) && value != -1) {
                     read();
                 }
                 return value == -1;
             }

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

             public SpaceCharFilter getFilter() {
                 return filter;
             }

             public void setFilter(SpaceCharFilter filter) {
                 this.filter = filter;
             }

             public interface SpaceCharFilter {
                 public boolean isSpaceChar(int ch);
             }
             public int[] nextIntArray(int n){
                 int[] array=new int[n];
                 for(int i=0;i<n;++i)array[i]=nextInt();
                 return array;
             }
             public int[] nextSortedIntArray(int n){
                 int array[]=nextIntArray(n);
                 Arrays.sort(array);
                 return array;
             }
             public int[] nextSumIntArray(int n){
                 int[] array=new int[n];
                 array[0]=nextInt();
                 for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
                 return array;
             }
             public long[] nextLongArray(int n){
                 long[] array=new long[n];
                 for(int i=0;i<n;++i)array[i]=nextLong();
                 return array;
             }
             public long[] nextSumLongArray(int n){
                 long[] array=new long[n];
                 array[0]=nextInt();
                 for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
                 return array;
             }
             public long[] nextSortedLongArray(int n){
                 long array[]=nextLongArray(n);
                 Arrays.sort(array);
                 return array;
             }
         }
      public static 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(char[] array) {
                  writer.print(array);
              }

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

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

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

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

              public void println(int[] array) {
                  print(array);
                  writer.println();
              }

              public void println(double[] array) {
                  print(array);
                  writer.println();
              }

              public void println(long[] array) {
                  print(array);
                  writer.println();
              }

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

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

              public void print(char i) {
                  writer.print(i);
              }

              public void println(char i) {
                  writer.println(i);
              }

              public void println(char[] array) {
                  writer.println(array);
              }

              public void printf(String format, Object... objects) {
                  writer.printf(format, objects);
              }

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

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

              public void print(long i) {
                  writer.print(i);
              }

              public void println(long i) {
                  writer.println(i);
              }

              public void print(int i) {
                  writer.print(i);
              }

              public void println(int i) {
                  writer.println(i);
              }

              public void separateLines(int[] array) {
                  for (int i : array) {
                      println(i);
                  }
              }
          }

}


/*package whatever //do not write package name here */

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

public class GFG {
    public static void main (String[] args) {
        Scanner in = new Scanner(System.in);
        int i,j,cnt=0;
        int n=in.nextInt();
        int m=in.nextInt();
        int a[]=new int[n];
        int b[]=new int[m];
        for(i=0;i<n;++i)
        {
            a[i]=in.nextInt();
        }
         for(i=0;i<m;++i)
        {
            b[i]=in.nextInt();
        }
        int s1=0;
        int s2=0;

        for(i=0,j=0;i<n&&j<m;)
        {
            if(s1==s2)
            {
                s1=a[i];
                s2=b[j];
                ++i;
                ++j;
                ++cnt;
            }
            else if(s1<s2)
            {
                s1=s1+a[i];
                ++i;
            }
            else
            {
              s2=s2+b[j];
                ++j;
            }
        }
        System.out.println(cnt);

    }
}


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

public class codes_1
	{

		public static void main(String[] args)
		{
			InputReader in = new InputReader(System.in);
			PrintWriter pw = new PrintWriter(System.out);

			//Code starts..

			int n = in.nextInt();
			int m = in.nextInt();

			int[] a = in.nextIntArray(n);
			int[] b = in.nextIntArray(m);

			int i=1, j=1;
			long sum1 = a[0];
			long sum2 = b[0];
			int ans = 0;
			while(i<n || j<m)
			{
				if(sum1<sum2)
					sum1 += a[i++];
				if(sum1>sum2)
					sum2 += b[j++];

				if(sum1==sum2){
					//pw.println(i+" "+j+" ");
					ans++;
					if(i<n)
						sum1=a[i++];
					if(j<m)
						sum2=b[j++];

				}

			}
			if(ans==0)
				ans++;
			pw.println(ans);
			//Code ends....

			pw.flush();
			pw.close();
		}

		static class InputReader
		{

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

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

			public int snext()
			{
				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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
			    {
					sgn = -1;
					c = snext();
				}
				int res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

			public long nextLong()
		    {
				int c = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
				{
					sgn = -1;
					c = snext();
				}
				long res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} 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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				StringBuilder res = new StringBuilder();
				do
				{
					res.appendCodePoint(c);
					c = snext();
				} while (!isSpaceChar(c));
				return res.toString();
			}

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

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

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

			public interface SpaceCharFilter
		    {
				public boolean isSpaceChar(int ch);
			}
		}
		public static long c = 0;

		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static  int gcd(int p2, int p22)
		{
		    if (p2 == 0)
		        return (int) p22;
		    return gcd(p22%p2, p2);
		}

		public static int findGCD(int arr[], int n)
		{
		    int result = arr[0];
		    for (int i=1; i<n; i++)
		        result = gcd(arr[i], result);

		    return result;
		}

	    public static long lcm(int[] numbers) {
	        long lcm = 1;
	        int divisor = 2;
	        while (true) {
	            int cnt = 0;
	            boolean divisible = false;
	            for (int i = 0; i < numbers.length; i++) {
	                if (numbers[i] == 0) {
	                    return 0;
	                } else if (numbers[i] < 0) {
	                    numbers[i] = numbers[i] * (-1);
	                }
	                if (numbers[i] == 1) {
	                    cnt++;
	                }
	                if (numbers[i] % divisor == 0) {
	                    divisible = true;
	                    numbers[i] = numbers[i] / divisor;
	                }
	            }
	            if (divisible) {
	                lcm = lcm * divisor;
	            } else {
	                divisor++;
	            }
	            if (cnt == numbers.length) {
	                return lcm;
	            }
	        }
	    }
		public static long fact(long n) {

			long factorial = 1;
			 for(int i = 1; i <= n; i++)
		        {
		            factorial *= i;
		        }
			 return factorial;
		}

		public static int lowerLimit(int[] a, int n) {
			int ans = 0;

			int ll = 0;
			int rl = a.length-1;
		//	System.out.println(a[rl]+" "+n);
			if(a[0]>n)
				return 0;
			if(a[0]==n)
				return 1;
			else if(a[rl]<=n)
				return rl+1;

			while(ll<=rl)
			{

				int mid = (ll+rl)/2;
				if(a[mid]==n)
				{
					ans = mid + 1;
					break;
				}

				else if(a[mid]>n)
				{
					rl = mid-1;

				}
				else
				{
					ans = mid+1;
					ll = mid+1;
				}
			}

			return ans;
		}

		public static long choose(long total, long choose){
		    if(total < choose)
		        return 0;
		    if(choose == 0 || choose == total)
		        return 1;
		    return (choose(total-1,choose-1)+choose(total-1,choose))%mod;
		}

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static int floorSearch(int arr[], int low, int high, int x)
		{
		    if (low > high)
		        return -1;

		    if (x > arr[high])
		        return high;
		    int mid = (low+high)/2;

		    if (mid > 0 && arr[mid-1] < x && x < arr[mid])
		        return mid-1;

		    if (x < arr[mid])
		        return floorSearch(arr, low, mid-1, x);

		    return floorSearch(arr, mid+1, high, x);
		}

	/*	public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}
		*/
		public static ArrayList<Integer> primeFactorization(int n)
		{
			ArrayList<Integer> a =new ArrayList<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static int lowerbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+2);
			return i;

		}
		public static int uperbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+1);
			return i;

		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int[] countDer(int n)
	    {
	        int der[] = new int[n + 1];

	        der[0] = 1;
	        der[1] = 0;
	        der[2] = 1;

	        for (int i = 3; i <= n; ++i)
	            der[i] = (i - 1) * (der[i - 1] + der[i - 2]);

	        // Return result for n
	        return der;
	    }

		 static long binomialCoeff(int n, int k)
		    {
		    long C[][] = new long[n+1][k+1];
		    int i, j;

		        // Calculate  value of Binomial Coefficient in bottom up manner
		    for (i = 0; i <= n; i++)
		    {
		        for (j = 0; j <= Math.min(i, k); j++)
		        {
		            // Base Cases
		            if (j == 0 || j == i)
		                C[i][j] = 1;

		            // Calculate value using previosly stored values
		            else
		                C[i][j] = C[i-1][j-1] + C[i-1][j];
		          }
		     }

		    return C[n][k];
		    }

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=(x%mod * x%mod)%mod;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static int modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		static class pair implements Comparable<pair>

		{
			Integer x, y;
			pair(int x,int y)
			{
				this.x=x;
				this.y=y;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

				return result;
			}

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

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

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

		static class triplet implements Comparable<triplet>
		{
			Integer x,y,z;
			triplet(int x,int y,int z)
			{
				this.x = x;
				this.y = y;
				this.z = z;
			}

			public  int compareTo(triplet o)
			{
				int result = x.compareTo(o.x);
				if(result==0)
					result =  y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(o.z);

				return result;
			}

			public boolean equlas(Object o)
			{
				if(o instanceof triplet)
				{
					triplet p = (triplet)o;
					return x==p.x && y==p.y && z==p.z;
				}
				return false;
			}

			public String toString()
			{
				return x+" "+y+" "+z;
			}
			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode() + new Long(z).hashCode();
			}
		}

		static class node implements Comparable<node>

		{
			Integer x, y, z;
			node(int x,int y, int z)
			{
				this.x=x;
				this.y=y;
				this.z=z;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(z);
				return result;
			}

			@Override
			public int compareTo(node o) {
				// TODO Auto-generated method stub
				return 0;
			}
		}
	}


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

public class codes_1
	{

		public static void main(String[] args)
		{
			InputReader in = new InputReader(System.in);
			PrintWriter pw = new PrintWriter(System.out);

			//Code starts..

			int n = in.nextInt();
			int m = in.nextInt();

			int[] a = in.nextIntArray(n);
			int[] b = in.nextIntArray(m);

			int i=1, j=1;
			long sum1 = a[0];
			long sum2 = b[0];
			int ans = 0;
			boolean flag = true;
			while(i<n || j<m)
			{
				flag = false;
				if(sum1<sum2)
					sum1 += a[i++];
				if(sum1>sum2)
					sum2 += b[j++];
				if(sum1==sum2){
					//pw.println(i+" "+j+" ");
					ans++;
					if(i<n)
					{
						flag = true;
						sum1=a[i++];
					}
						if(j<m)
						{
							flag = true;
							sum2=b[j++];
						}

				}

			}
			if(i==n && j==n && sum1==sum2 && flag)
				ans++;

			pw.println(ans);
			//Code ends....

			pw.flush();
			pw.close();
		}

		static class InputReader
		{

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

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

			public int snext()
			{
				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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
			    {
					sgn = -1;
					c = snext();
				}
				int res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

			public long nextLong()
		    {
				int c = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
				{
					sgn = -1;
					c = snext();
				}
				long res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} 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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				StringBuilder res = new StringBuilder();
				do
				{
					res.appendCodePoint(c);
					c = snext();
				} while (!isSpaceChar(c));
				return res.toString();
			}

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

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

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

			public interface SpaceCharFilter
		    {
				public boolean isSpaceChar(int ch);
			}
		}
		public static long c = 0;

		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static  int gcd(int p2, int p22)
		{
		    if (p2 == 0)
		        return (int) p22;
		    return gcd(p22%p2, p2);
		}

		public static int findGCD(int arr[], int n)
		{
		    int result = arr[0];
		    for (int i=1; i<n; i++)
		        result = gcd(arr[i], result);

		    return result;
		}

	    public static long lcm(int[] numbers) {
	        long lcm = 1;
	        int divisor = 2;
	        while (true) {
	            int cnt = 0;
	            boolean divisible = false;
	            for (int i = 0; i < numbers.length; i++) {
	                if (numbers[i] == 0) {
	                    return 0;
	                } else if (numbers[i] < 0) {
	                    numbers[i] = numbers[i] * (-1);
	                }
	                if (numbers[i] == 1) {
	                    cnt++;
	                }
	                if (numbers[i] % divisor == 0) {
	                    divisible = true;
	                    numbers[i] = numbers[i] / divisor;
	                }
	            }
	            if (divisible) {
	                lcm = lcm * divisor;
	            } else {
	                divisor++;
	            }
	            if (cnt == numbers.length) {
	                return lcm;
	            }
	        }
	    }
		public static long fact(long n) {

			long factorial = 1;
			 for(int i = 1; i <= n; i++)
		        {
		            factorial *= i;
		        }
			 return factorial;
		}

		public static int lowerLimit(int[] a, int n) {
			int ans = 0;

			int ll = 0;
			int rl = a.length-1;
		//	System.out.println(a[rl]+" "+n);
			if(a[0]>n)
				return 0;
			if(a[0]==n)
				return 1;
			else if(a[rl]<=n)
				return rl+1;

			while(ll<=rl)
			{

				int mid = (ll+rl)/2;
				if(a[mid]==n)
				{
					ans = mid + 1;
					break;
				}

				else if(a[mid]>n)
				{
					rl = mid-1;

				}
				else
				{
					ans = mid+1;
					ll = mid+1;
				}
			}

			return ans;
		}

		public static long choose(long total, long choose){
		    if(total < choose)
		        return 0;
		    if(choose == 0 || choose == total)
		        return 1;
		    return (choose(total-1,choose-1)+choose(total-1,choose))%mod;
		}

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static int floorSearch(int arr[], int low, int high, int x)
		{
		    if (low > high)
		        return -1;

		    if (x > arr[high])
		        return high;
		    int mid = (low+high)/2;

		    if (mid > 0 && arr[mid-1] < x && x < arr[mid])
		        return mid-1;

		    if (x < arr[mid])
		        return floorSearch(arr, low, mid-1, x);

		    return floorSearch(arr, mid+1, high, x);
		}

	/*	public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}
		*/
		public static ArrayList<Integer> primeFactorization(int n)
		{
			ArrayList<Integer> a =new ArrayList<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static int lowerbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+2);
			return i;

		}
		public static int uperbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+1);
			return i;

		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int[] countDer(int n)
	    {
	        int der[] = new int[n + 1];

	        der[0] = 1;
	        der[1] = 0;
	        der[2] = 1;

	        for (int i = 3; i <= n; ++i)
	            der[i] = (i - 1) * (der[i - 1] + der[i - 2]);

	        // Return result for n
	        return der;
	    }

		 static long binomialCoeff(int n, int k)
		    {
		    long C[][] = new long[n+1][k+1];
		    int i, j;

		        // Calculate  value of Binomial Coefficient in bottom up manner
		    for (i = 0; i <= n; i++)
		    {
		        for (j = 0; j <= Math.min(i, k); j++)
		        {
		            // Base Cases
		            if (j == 0 || j == i)
		                C[i][j] = 1;

		            // Calculate value using previosly stored values
		            else
		                C[i][j] = C[i-1][j-1] + C[i-1][j];
		          }
		     }

		    return C[n][k];
		    }

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=(x%mod * x%mod)%mod;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static int modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		static class pair implements Comparable<pair>

		{
			Integer x, y;
			pair(int x,int y)
			{
				this.x=x;
				this.y=y;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

				return result;
			}

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

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

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

		static class triplet implements Comparable<triplet>
		{
			Integer x,y,z;
			triplet(int x,int y,int z)
			{
				this.x = x;
				this.y = y;
				this.z = z;
			}

			public  int compareTo(triplet o)
			{
				int result = x.compareTo(o.x);
				if(result==0)
					result =  y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(o.z);

				return result;
			}

			public boolean equlas(Object o)
			{
				if(o instanceof triplet)
				{
					triplet p = (triplet)o;
					return x==p.x && y==p.y && z==p.z;
				}
				return false;
			}

			public String toString()
			{
				return x+" "+y+" "+z;
			}
			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode() + new Long(z).hashCode();
			}
		}

		static class node implements Comparable<node>

		{
			Integer x, y, z;
			node(int x,int y, int z)
			{
				this.x=x;
				this.y=y;
				this.z=z;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(z);
				return result;
			}

			@Override
			public int compareTo(node o) {
				// TODO Auto-generated method stub
				return 0;
			}
		}
	}


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

public class codes_1
	{

		public static void main(String[] args)
		{
			InputReader in = new InputReader(System.in);
			PrintWriter pw = new PrintWriter(System.out);

			//Code starts..

			int n = in.nextInt();
			int m = in.nextInt();

			int[] a = in.nextIntArray(n);
			int[] b = in.nextIntArray(m);

			int i=1, j=1;
			long sum1 = a[0];
			long sum2 = b[0];
			int ans = 0;
			while(i<n || j<m)
			{
				if(sum1<sum2)
					sum1 += a[i++];
				if(sum1>sum2)
					sum2 += b[j++];

				if(sum1==sum2){
					//pw.println(i+" "+j+" ");
					ans++;
					if(i<n)
						sum1=a[i++];
					if(j<m)
						sum2=b[j++];

				}

			}

			pw.println(ans);
			//Code ends....

			pw.flush();
			pw.close();
		}

		static class InputReader
		{

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

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

			public int snext()
			{
				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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
			    {
					sgn = -1;
					c = snext();
				}
				int res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

			public long nextLong()
		    {
				int c = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
				{
					sgn = -1;
					c = snext();
				}
				long res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} 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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				StringBuilder res = new StringBuilder();
				do
				{
					res.appendCodePoint(c);
					c = snext();
				} while (!isSpaceChar(c));
				return res.toString();
			}

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

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

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

			public interface SpaceCharFilter
		    {
				public boolean isSpaceChar(int ch);
			}
		}
		public static long c = 0;

		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static  int gcd(int p2, int p22)
		{
		    if (p2 == 0)
		        return (int) p22;
		    return gcd(p22%p2, p2);
		}

		public static int findGCD(int arr[], int n)
		{
		    int result = arr[0];
		    for (int i=1; i<n; i++)
		        result = gcd(arr[i], result);

		    return result;
		}

	    public static long lcm(int[] numbers) {
	        long lcm = 1;
	        int divisor = 2;
	        while (true) {
	            int cnt = 0;
	            boolean divisible = false;
	            for (int i = 0; i < numbers.length; i++) {
	                if (numbers[i] == 0) {
	                    return 0;
	                } else if (numbers[i] < 0) {
	                    numbers[i] = numbers[i] * (-1);
	                }
	                if (numbers[i] == 1) {
	                    cnt++;
	                }
	                if (numbers[i] % divisor == 0) {
	                    divisible = true;
	                    numbers[i] = numbers[i] / divisor;
	                }
	            }
	            if (divisible) {
	                lcm = lcm * divisor;
	            } else {
	                divisor++;
	            }
	            if (cnt == numbers.length) {
	                return lcm;
	            }
	        }
	    }
		public static long fact(long n) {

			long factorial = 1;
			 for(int i = 1; i <= n; i++)
		        {
		            factorial *= i;
		        }
			 return factorial;
		}

		public static int lowerLimit(int[] a, int n) {
			int ans = 0;

			int ll = 0;
			int rl = a.length-1;
		//	System.out.println(a[rl]+" "+n);
			if(a[0]>n)
				return 0;
			if(a[0]==n)
				return 1;
			else if(a[rl]<=n)
				return rl+1;

			while(ll<=rl)
			{

				int mid = (ll+rl)/2;
				if(a[mid]==n)
				{
					ans = mid + 1;
					break;
				}

				else if(a[mid]>n)
				{
					rl = mid-1;

				}
				else
				{
					ans = mid+1;
					ll = mid+1;
				}
			}

			return ans;
		}

		public static long choose(long total, long choose){
		    if(total < choose)
		        return 0;
		    if(choose == 0 || choose == total)
		        return 1;
		    return (choose(total-1,choose-1)+choose(total-1,choose))%mod;
		}

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static int floorSearch(int arr[], int low, int high, int x)
		{
		    if (low > high)
		        return -1;

		    if (x > arr[high])
		        return high;
		    int mid = (low+high)/2;

		    if (mid > 0 && arr[mid-1] < x && x < arr[mid])
		        return mid-1;

		    if (x < arr[mid])
		        return floorSearch(arr, low, mid-1, x);

		    return floorSearch(arr, mid+1, high, x);
		}

	/*	public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}
		*/
		public static ArrayList<Integer> primeFactorization(int n)
		{
			ArrayList<Integer> a =new ArrayList<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static int lowerbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+2);
			return i;

		}
		public static int uperbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+1);
			return i;

		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int[] countDer(int n)
	    {
	        int der[] = new int[n + 1];

	        der[0] = 1;
	        der[1] = 0;
	        der[2] = 1;

	        for (int i = 3; i <= n; ++i)
	            der[i] = (i - 1) * (der[i - 1] + der[i - 2]);

	        // Return result for n
	        return der;
	    }

		 static long binomialCoeff(int n, int k)
		    {
		    long C[][] = new long[n+1][k+1];
		    int i, j;

		        // Calculate  value of Binomial Coefficient in bottom up manner
		    for (i = 0; i <= n; i++)
		    {
		        for (j = 0; j <= Math.min(i, k); j++)
		        {
		            // Base Cases
		            if (j == 0 || j == i)
		                C[i][j] = 1;

		            // Calculate value using previosly stored values
		            else
		                C[i][j] = C[i-1][j-1] + C[i-1][j];
		          }
		     }

		    return C[n][k];
		    }

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=(x%mod * x%mod)%mod;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static int modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		static class pair implements Comparable<pair>

		{
			Integer x, y;
			pair(int x,int y)
			{
				this.x=x;
				this.y=y;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

				return result;
			}

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

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

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

		static class triplet implements Comparable<triplet>
		{
			Integer x,y,z;
			triplet(int x,int y,int z)
			{
				this.x = x;
				this.y = y;
				this.z = z;
			}

			public  int compareTo(triplet o)
			{
				int result = x.compareTo(o.x);
				if(result==0)
					result =  y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(o.z);

				return result;
			}

			public boolean equlas(Object o)
			{
				if(o instanceof triplet)
				{
					triplet p = (triplet)o;
					return x==p.x && y==p.y && z==p.z;
				}
				return false;
			}

			public String toString()
			{
				return x+" "+y+" "+z;
			}
			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode() + new Long(z).hashCode();
			}
		}

		static class node implements Comparable<node>

		{
			Integer x, y, z;
			node(int x,int y, int z)
			{
				this.x=x;
				this.y=y;
				this.z=z;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(z);
				return result;
			}

			@Override
			public int compareTo(node o) {
				// TODO Auto-generated method stub
				return 0;
			}
		}
	}


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

public class codes_1
	{

		public static void main(String[] args)
		{
			InputReader in = new InputReader(System.in);
			PrintWriter pw = new PrintWriter(System.out);

			//Code starts..

			int n = in.nextInt();
			int m = in.nextInt();

			int[] a = in.nextIntArray(n);
			int[] b = in.nextIntArray(m);
			int end=0;

			for(int i=0,j=0;i<n&&j<m;) {
				for(int a0=a[i++],b0=b[j++];a0!=b0;) {
					if(a0<b0) a0+=a[i++];
					else b0+=b[j++];
				}
				end++;
			}
			pw.println(end);
			//Code ends....

			pw.flush();
			pw.close();
		}

		static class InputReader
		{

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

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

			public int snext()
			{
				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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
			    {
					sgn = -1;
					c = snext();
				}
				int res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

			public long nextLong()
		    {
				int c = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				int sgn = 1;
				if (c == '-')
				{
					sgn = -1;
					c = snext();
				}
				long res = 0;
				do
				{
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = snext();
				} 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 = snext();
				while (isSpaceChar(c))
				{
					c = snext();
				}
				StringBuilder res = new StringBuilder();
				do
				{
					res.appendCodePoint(c);
					c = snext();
				} while (!isSpaceChar(c));
				return res.toString();
			}

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

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

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

			public interface SpaceCharFilter
		    {
				public boolean isSpaceChar(int ch);
			}
		}
		public static long c = 0;

		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static  int gcd(int p2, int p22)
		{
		    if (p2 == 0)
		        return (int) p22;
		    return gcd(p22%p2, p2);
		}

		public static int findGCD(int arr[], int n)
		{
		    int result = arr[0];
		    for (int i=1; i<n; i++)
		        result = gcd(arr[i], result);

		    return result;
		}

	    public static long lcm(int[] numbers) {
	        long lcm = 1;
	        int divisor = 2;
	        while (true) {
	            int cnt = 0;
	            boolean divisible = false;
	            for (int i = 0; i < numbers.length; i++) {
	                if (numbers[i] == 0) {
	                    return 0;
	                } else if (numbers[i] < 0) {
	                    numbers[i] = numbers[i] * (-1);
	                }
	                if (numbers[i] == 1) {
	                    cnt++;
	                }
	                if (numbers[i] % divisor == 0) {
	                    divisible = true;
	                    numbers[i] = numbers[i] / divisor;
	                }
	            }
	            if (divisible) {
	                lcm = lcm * divisor;
	            } else {
	                divisor++;
	            }
	            if (cnt == numbers.length) {
	                return lcm;
	            }
	        }
	    }
		public static long fact(long n) {

			long factorial = 1;
			 for(int i = 1; i <= n; i++)
		        {
		            factorial *= i;
		        }
			 return factorial;
		}

		public static int lowerLimit(int[] a, int n) {
			int ans = 0;

			int ll = 0;
			int rl = a.length-1;
		//	System.out.println(a[rl]+" "+n);
			if(a[0]>n)
				return 0;
			if(a[0]==n)
				return 1;
			else if(a[rl]<=n)
				return rl+1;

			while(ll<=rl)
			{

				int mid = (ll+rl)/2;
				if(a[mid]==n)
				{
					ans = mid + 1;
					break;
				}

				else if(a[mid]>n)
				{
					rl = mid-1;

				}
				else
				{
					ans = mid+1;
					ll = mid+1;
				}
			}

			return ans;
		}

		public static long choose(long total, long choose){
		    if(total < choose)
		        return 0;
		    if(choose == 0 || choose == total)
		        return 1;
		    return (choose(total-1,choose-1)+choose(total-1,choose))%mod;
		}

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static int floorSearch(int arr[], int low, int high, int x)
		{
		    if (low > high)
		        return -1;

		    if (x > arr[high])
		        return high;
		    int mid = (low+high)/2;

		    if (mid > 0 && arr[mid-1] < x && x < arr[mid])
		        return mid-1;

		    if (x < arr[mid])
		        return floorSearch(arr, low, mid-1, x);

		    return floorSearch(arr, mid+1, high, x);
		}

	/*	public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}
		*/
		public static ArrayList<Integer> primeFactorization(int n)
		{
			ArrayList<Integer> a =new ArrayList<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static int lowerbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+2);
			return i;

		}
		public static int uperbound(ArrayList<Long> list, long n) {
			int i=Collections.binarySearch(list, n);
			if(i<0)
				i = -(i+1);
			return i;

		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int[] countDer(int n)
	    {
	        int der[] = new int[n + 1];

	        der[0] = 1;
	        der[1] = 0;
	        der[2] = 1;

	        for (int i = 3; i <= n; ++i)
	            der[i] = (i - 1) * (der[i - 1] + der[i - 2]);

	        // Return result for n
	        return der;
	    }

		 static long binomialCoeff(int n, int k)
		    {
		    long C[][] = new long[n+1][k+1];
		    int i, j;

		        // Calculate  value of Binomial Coefficient in bottom up manner
		    for (i = 0; i <= n; i++)
		    {
		        for (j = 0; j <= Math.min(i, k); j++)
		        {
		            // Base Cases
		            if (j == 0 || j == i)
		                C[i][j] = 1;

		            // Calculate value using previosly stored values
		            else
		                C[i][j] = C[i-1][j-1] + C[i-1][j];
		          }
		     }

		    return C[n][k];
		    }

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=(x%mod * x%mod)%mod;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static int modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		static class pair implements Comparable<pair>

		{
			Integer x, y;
			pair(int x,int y)
			{
				this.x=x;
				this.y=y;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

				return result;
			}

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

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

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

		static class triplet implements Comparable<triplet>
		{
			Integer x,y,z;
			triplet(int x,int y,int z)
			{
				this.x = x;
				this.y = y;
				this.z = z;
			}

			public  int compareTo(triplet o)
			{
				int result = x.compareTo(o.x);
				if(result==0)
					result =  y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(o.z);

				return result;
			}

			public boolean equlas(Object o)
			{
				if(o instanceof triplet)
				{
					triplet p = (triplet)o;
					return x==p.x && y==p.y && z==p.z;
				}
				return false;
			}

			public String toString()
			{
				return x+" "+y+" "+z;
			}
			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode() + new Long(z).hashCode();
			}
		}

		static class node implements Comparable<node>

		{
			Integer x, y, z;
			node(int x,int y, int z)
			{
				this.x=x;
				this.y=y;
				this.z=z;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);
				if(result==0)
					result = z.compareTo(z);
				return result;
			}

			@Override
			public int compareTo(node o) {
				// TODO Auto-generated method stub
				return 0;
			}
		}
	}