import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean[] prime = new boolean[100001];
		fill(prime, true);
		for (int i = 2; i < 100001; i++)
			if (prime[i])
				for (int j = 2 * i; j < 100001; j += i)
					prime[j] = false;
		int n = nextInt();
		boolean[] mood = new boolean[n];
		for (int i = 0; i < n; i++) {
			if (nextInt() == 1)
				mood[i] = true;
			else
				mood[i] = false;
		}
		boolean yes = false;
		for (int i = 3; i <= n; i++)
			if (prime[i] && n % i == 0) {
				int up = n / i;
				for (int j = 0; j < up; j++) {
					boolean f = true;
					for (int k = j; k < n; k += up)
						if (!mood[k]) {
							f = false;
							break;
						}
					if (f) {
						yes = true;
						break;
					}
				}
			}
		if (yes)
			out.println("YES");
		else
			out.println("NO");

		in.close();
		out.close();
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean[] prime = new boolean[100001];
		fill(prime, true);
		for (int i = 3; i < 100001; i++)
			if (prime[i])
				for (int j = 2 * i; j < 100001; j += i)
					prime[j] = false;
		int n = nextInt();
		boolean[] mood = new boolean[n];
		for (int i = 0; i < n; i++) {
			if (nextInt() == 1)
				mood[i] = true;
			else
				mood[i] = false;
		}
		boolean yes = false;
		for (int i = 3; i <= n; i++)
			if (prime[i] && n % i == 0) {
				int up = n / i;
				for (int j = 0; j < up; j++) {
					boolean f = true;
					for (int k = j; k < n; k += up)
						if (!mood[k]) {
							f = false;
							break;
						}
					if (f) {
						yes = true;
						break;
					}
				}
			}
		if (yes)
			out.println("YES");
		else
			out.println("NO");

		in.close();
		out.close();
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


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

public class p71c {
    public static void main(String[] args) throws Exception{
        p71cc in = new p71cc(System.in);
        int n = in.nextLong();
        int[] all = new int[n];
        for (int i = 0; i < all.length; i++) {
            all[i] = in.nextLong();
            //System.out.println(all[i]);
        }
        for (int i = 1; i < all.length*1.0/2; i++) {
            if(all.length%i == 0) {
                for (int j = 0; j < i; j++) {
                    boolean f = true;
                    for (int k = j; k < all.length; k+=i) {
                        if(all[k] == 0) {
                            //System.out.println("why");
                            f = false;
                            break;
                        }
                    }
                    if(f) {
                        System.out.println("YES");
                        return;
                    }
                }
            }
        }
        System.out.println("NO");
    }
}
class p71cc {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public p71cc(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public int nextLong() throws Exception {
        int ret = 0;
        byte c = read();

        while (c <= ' ')
            c = read();
        boolean neg = c == '-';
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg)
            return -ret;
        return ret;
    }

    public char nextChar() throws Exception {
        char ret = ' ';
        byte c = read();

        while (c <= ' ')
            c = read();

        ret = (char)c;

        return ret;
    }
    public String nextString() throws Exception {
        StringBuffer ret = new StringBuffer();
        byte c = read();

        while (c <= ' ')
            c = read();
        do {
            ret = ret.append((char)c);
            c = read();
        } while (c > ' ');

        return ret.toString();
    }

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

    private byte read() throws Exception {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

}


import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;

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

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

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

        Vector<Integer> pr = new Vector<Integer>();
        boolean[] complex = new boolean[n + 1];
        for (int i = 3; i * i <= n; i++)
            if (!complex[i])
                for (int j = i + i; j <= n; j += i)
                    complex[j] = true;

        for (int i = 3; i <= n; i++)
            if (!complex[i])
                pr.add(i);

        pr.add(4);
        pr.add(n);

        boolean yes = false;

        outer: for (int i = 0; i < pr.size(); i++) {
            int prime = pr.elementAt(i);

            if (n % prime != 0)
                continue;

            int count = n / prime;
            for (int j = 0; j < count; j++) {
                boolean good = true;
                for (int k = j; k < n; k += count)
                    if (b[k] == 0) {
                        good = false;
                        break;
                    }
                if (good) {
                    yes = true;
                    break outer;
                }
            }
        }

        out.print(yes ? "YES" : "NO");
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	private List<Integer> getDivisors(int n) {
		List<Integer> res = new ArrayList<Integer>();
		res.add(n);
		if (n%2 == 0 && n > 4) {
			res.add(n/2);
		}
		for (int i = 3; i*i <= n; ++i) {
			if (n%i == 0) {
				res.add(i);
				res.add(n/i);
			}
		}
		return res;
	}

	private boolean can(int start, int step) {
		int memo = start;
		if (!isFunny[start]) {
			return false;
		}
		start += step;
		while (start != memo) {
			if (!isFunny[start]) {
				return false;
			}
			start += step;
			if (start >= n) {
				start -= n;
			}
		}
		return true;
	}

	private void processing() {
		List<Integer> divs = getDivisors(n);
		for (int div: divs) {
			int step = n/div;
			for (int start = 0; start < step; ++start) {
				if (can(start, step)) {
					println(YES);
					return;
				}
			}
		}
		println(NO);
	}

	private void readData() throws IOException {
		n = nextInt();
		isFunny = new boolean[n];
		for (int i = 0; i < n; ++i) {
			int m = nextInt();
			isFunny[i] = m == 1;
		}
	}

	private int n;
	private boolean[] isFunny;

	private static final String YES = "YES";
	private static final String NO = "NO";

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		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 readInt() {
			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 readLong() {
			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 readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

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

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			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 char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			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, readInt());
				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, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

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

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

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

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Author -
 * User: kansal
 * Date: 3/29/11
 * Time: 8:59 PM
 */
public class RoundTableKnights {
    public static BufferedReader reader;
    public static StringTokenizer tokenizer = null;

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

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

    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));

        int n = nextInt();
        //int n = 100000;

        boolean[] good = new boolean[n];
        //Random r = new Random();
        for(int i = 0; i < n; ++i) {
            good[i] = (nextInt() == 1);
            //good[i] = r.nextBoolean();
        }

        boolean[] possible = new boolean[n+1];
        Arrays.fill(possible, true);
        for(int pts = 3; pts <= n; ++pts) {
            if (n % pts != 0 || !possible[n/pts]) {
                continue;
            }
            int jumps = n / pts;
            boolean ok = false;
            for(int i = 0; i < jumps; ++i) {
                if (!good[i]) {
                    continue;
                }
                boolean curOk = true;
                int x = jumps;
                for(int j = 1; j < pts; ++j, x += jumps) {
                    if (!good[i + x]) {
                        curOk = false;
                        break;
                    }
                }
                if (curOk) {
                    ok = true;
                    break;
                }
            }
            if (ok) {
                System.out.println("YES");
                return;
            }
            else {
                for(int f = 1; f * f <= jumps; ++f) {
                    if (jumps % f != 0) {
                        continue;
                    }
                    possible[f] = false;
                    possible[jumps/f] = false;
                }
            }
        }

        System.out.println("NO");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

/**
 * Author -
 * User: kansal
 * Date: 3/29/11
 * Time: 8:59 PM
 */
public class RoundTableKnights {
    public static BufferedReader reader;
    public static StringTokenizer tokenizer = null;

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

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

    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));

        int n = nextInt();
        //int n = 100000;

        boolean[] good = new boolean[n];
        //Random r = new Random();
        for(int i = 0; i < n; ++i) {
            good[i] = (nextInt() == 1);
            //good[i] = r.nextBoolean();
        }

        boolean[] possible = new boolean[n+1];
        Arrays.fill(possible, true);
        for(int pts = 3; pts <= n; ++pts) {
            if (n % pts != 0 || !possible[pts]) {
                continue;
            }
            int jumps = n / pts;
            boolean ok = false;
            for(int i = 0; i < jumps; ++i) {
                if (!good[i]) {
                    continue;
                }
                boolean curOk = true;
                int x = jumps;
                for(int j = 1; j < pts; ++j, x += jumps) {
                    if (!good[i + x]) {
                        curOk = false;
                        break;
                    }
                }
                if (curOk) {
                    ok = true;
                    break;
                }
            }
            if (ok) {
                System.out.println("YES");
                return;
            }
            else {
                for(int f = 1; f * f <= jumps; ++f) {
                    if (jumps % f != 0) {
                        continue;
                    }
                    possible[f] = false;
                    possible[jumps/f] = false;
                }
            }
        }

        System.out.println("NO");
    }
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int N;
	boolean[] a;

	int[] good;
	int tick = 1;

	int pNum = 0;
	int[] primes = new int [10000];
	boolean[] erat;

	void run() throws IOException {
		int MAXN = 100000;
		int MAX = 1000;
		erat = new boolean [MAXN + 1];

		for (int i = 2; i <= MAXN; i++) {
			if (!erat[i]) {
				primes[pNum++] = i;
				if (i <= MAX)
					for (int j = i * i; j <= MAXN; j += i)
						erat[j] = true;
			}
		}

		primes[0] = 4;

		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		N = nextInt();
		a = new boolean [N];

		for (int i = 0; i < N; i++)
			a[i] = nextInt() == 1;

		good = new int [N + 1];

		for (int i = 0; i < pNum && primes[i] <= N; i++) {
			if (N % primes[i] == 0 && can(primes[i])) {
				out.println("YES");
				out.close();
				return;
			}
		}

		out.println("NO");
		out.close();
	}

	boolean can(int num) {
		int offset = N / num;
		tick++;
		for (int i = 0; i < N; i++) {
			if (!(a[i] && a[(i + offset) % N])) {
				if (good[i % offset] != tick) {
					good[i % offset] = tick;
				}
			}
		}
		for (int i = 0; i < offset; i++)
			if (good[i] != tick)
				return true;
		return false;
	}

	/***************************************************************
	 * Input
	 **************************************************************/
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int N;
	boolean[] a;

	int[] good;
	int tick = 1;

	int pNum = 0;
	int[] primes = new int [10000];
	boolean[] erat;

	void run() throws IOException {
		int MAXN = 100000;
		int MAX = 1000;
		erat = new boolean [MAXN + 1];

		for (int i = 2; i <= MAXN; i++) {
			if (!erat[i]) {
				primes[pNum++] = i;
				if (i <= MAX)
					for (int j = i * i; j <= MAXN; j += i)
						erat[j] = true;
			}
		}

		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		N = nextInt();
		a = new boolean [N];

		for (int i = 0; i < N; i++)
			a[i] = nextInt() == 1;

		good = new int [N + 1];

		for (int i = 1; i < pNum && primes[i] <= N; i++) {
			if (N % primes[i] == 0 && can(primes[i])) {
				out.println("YES");
				out.close();
				return;
			}
		}

		out.println("NO");
		out.close();
	}

	boolean can(int num) {
		int offset = N / num;
		tick++;
		for (int i = 0; i < N; i++) {
			if (!(a[i] && a[(i + offset) % N])) {
				if (good[i % offset] != tick) {
					good[i % offset] = tick;
				}
			}
		}
		for (int i = 0; i < offset; i++)
			if (good[i] != tick)
				return true;
		return false;
	}

	/***************************************************************
	 * Input
	 **************************************************************/
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int N;
	boolean[] a;

	int[] good;
	int tick = 1;

	int pNum = 0;
	int[] primes = new int [10000];
	boolean[] erat;

	void run() throws IOException {
		int MAXN = 100000;
		int MAX = 1000;
		erat = new boolean [MAXN + 1];

		for (int i = 2; i <= MAXN; i++) {
			if (!erat[i]) {
				primes[pNum++] = i;
				if (i <= MAX)
					for (int j = i * i; j <= MAXN; j += i)
						erat[j] = true;
			}
		}

		primes[0] = 4;

		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		N = nextInt();
		a = new boolean [N];

		for (int i = 0; i < N; i++)
			a[i] = nextInt() == 1;

		good = new int [N + 1];

		for (int i = 0; i < pNum && (i == 0 || primes[i] <= N); i++) {
			if (N % primes[i] == 0 && can(primes[i])) {
				out.println("YES");
				out.close();
				return;
			}
		}

		out.println("NO");
		out.close();
	}

	boolean can(int num) {
		int offset = N / num;
		tick++;
		for (int i = 0; i < N; i++) {
			if (!(a[i] && a[(i + offset) % N])) {
				if (good[i % offset] != tick) {
					good[i % offset] = tick;
				}
			}
		}
		for (int i = 0; i < offset; i++)
			if (good[i] != tick)
				return true;
		return false;
	}

	/***************************************************************
	 * Input
	 **************************************************************/
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


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

public class BetaRound65_C implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws IOException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	@Override
	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new BetaRound65_C()).start();
	}

	void solve() throws IOException {
		int n = readInt();
		boolean[] a = new boolean[2*n];
		for (int i = 0; i < n; i++) {
			a[i] = readInt() == 1;
		}
		for (int i = n; i < 2*n; i++) {
			a[i] = a[i - n];
		}
		ArrayList<Integer> b = new ArrayList<Integer>();
		for (int i = 3; i <= n; i++) {
			if (n % i == 0) {
				b.add(i);
			}
		}
		for (Integer m : b) {
			int d = n / m;
next:		for (int k = 0; k < d; k++) {
				for (int i = k; i < n + k; i += d) {
					if (!a[i]) continue next;
				}
				out.print("YES");
				return;
			}
		}
		out.print("NO");
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class C {
    private static StreamTokenizer in;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    static {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
                System.in)));
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args) throws Exception {
        int n = nextInt();

        boolean[] mas = new boolean[n];

        for (int i = 0; i < n; i++) {
            mas[i] = (nextInt() == 0) ? false : true;
        }

        int n2 = n / 2;

        boolean ans = true;
        for (int i = 3; i <= n; i++) {
            if (n % i != 0)
                continue;

            int step = n / i;

            //if(step >= n / 2)continue;

            for (int k = 0; k < step; k++) {
                boolean b = true;
                for (int j = 0; j < n; j += n / i) {
                    if (!mas[j])
                        b = false;
                }

                if (b) {
                    out.println("YES");
                    out.flush();
                    return;
                }
            }
        }

        out.println("NO");

        out.flush();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class C {
    private static StreamTokenizer in;
    private static PrintWriter out;

    private static int nextInt() throws Exception {
        in.nextToken();
        return (int) in.nval;
    }

    private static String nextString() throws Exception {
        in.nextToken();
        return in.sval;
    }

    static {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(
                System.in)));
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args) throws Exception {
        int n = nextInt();

        boolean[] mas = new boolean[n];

        for (int i = 0; i < n; i++) {
            mas[i] = (nextInt() == 0) ? false : true;
        }

        int n2 = n / 2;

        boolean ans = true;
        for (int i = 1; i <= n / 2; i++) {
            if (n % i != 0)
                continue;
            if(n % 2 == 0 && i >= n / 2)continue;

            int step = i;

            //if(step >= n / 2)continue;

            for (int k = 0; k < step; k++) {
                boolean b = true;
                for (int j = k; j < n; j += i) {
                    if (!mas[j])
                        b = false;
                }

                if (b) {
                    out.println("YES");
                    out.flush();
                    return;
                }
            }
        }

        out.println("NO");

        out.flush();
    }
}


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

public class C {

    public static void main(String[] args) {
        new Solver().run();
    }

        static class Solver implements Runnable {
            BufferedReader reader;
            StringTokenizer tokenizer = null;

            Solver() {
                reader = new BufferedReader(new InputStreamReader(System.in));
            }

            public void run() {
                try {
	                int n = nextInt();
	                int[] knights = new int[n];

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

	                boolean possible = false;
	                for (int i = 3; i <= n; i++){
	                        if (n%i==0){
	                                int step = n/i;
	                                for (int j = 0; j < step; j++){
	                                        boolean doable = true;
	                                        for (int k = j; k < n; k += step){
	                                                if (knights[k] == 0){
	                                                        doable = false;
	                                                }
	                                        }

	                                        if (doable){
	                                                possible = true;
	                                        }
	                                }
	                        }
	                }

	                if (possible){
	                        System.out.println("YES");
	                }else{
	                        System.out.println("NO");
	                }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

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

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

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

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

}


import java.io.IOException;
import java.util.Locale;
import java.util.Scanner;

public class C {

	private void processInput() throws IOException {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		boolean[] m = new boolean[n];
		for (int i = 0;i < n; i++) {
			m[i] = in.nextInt() == 0 ? false : true ;
		}

		String res = go(n, m);

		in.close();

		System.out.printf(Locale.ENGLISH, "%s\n", res);
	}

	private String go(int n, boolean[] m) {

		int br = 0;
		for (int i = 0; i < n; i++) {

			if (!m[i]) continue;
			for (int step = i+1; step <= n / 2; step++) {
				int x = 0;

				int pos = i;

				while (true) {
					pos = (pos + step ) % n;
					if (!m[pos]) break;
					x++;
					if (x > n) break;
					if (pos == i) {
						if (x >= 3) {
							return "YES";
						} else {
							break;
						}
					}
				}
			}
		}

		return "NO";
	}

	public static void main(String[] args) throws Exception {
		C c = new C();
		c.processInput();
	}
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author dody
 */
public class ProbC {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        String table = scanner.nextLine();
        table = table.replaceAll(" ", "");
        int sum = 0;
        for(int i = 0; i< table.length(); i++){
            sum += table.charAt(i)-'0';
        }
        if(sum == table.length()){
             System.out.println("YES");
                return;
        }
//        for(int i =0; i<table.length();i++)
        boolean [] sol = new boolean[n/3+1];

        Arrays.fill(sol, true);
        sol[0] = false;

        for(int i = 2; i <= n/3; i++){
            if(n % i != 0 || !sol[i]){
                sol[i] = false;
                continue;
            }
            sol[i] = check(table,i);
            if(sol[i]){
                System.out.println("YES");
                return;
            }
            for(int j = 2; j * i < sol.length; j++){
                sol[j] = false;
            }
        }
        System.out.println("NO");
    }

    private static boolean check(String table, int i) {

        for(int start = 0; start < i; start++){
            boolean ret = true;
            for(int j = start; j<table.length(); j+= i){
                if(table.charAt(j) == '0')
                    ret =  false;
            }
            if(ret)
                return true;
        }
        return false;
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _81B
{
    class Program
    {
        public static string s;

        public static string FindNext(ref int index)
        {
            for (int i = index; i < s.Length; i++)
            {
                if(s[i] == '.')
                {
                    for (int j = i + 3; j < s.Length; j++)
                    {
                        if(s[j] == ',')
                        {
                            index = j;
                            return "...,";
                        }
                        if(s[j] >= '0' && s[j] <= '9' && i < s.Length)
                        {
                            string temp = "";
                            while(s[j] >= '0' && s[j] <= '9' && j < s.Length)
                            {
                                temp += s[j++];
                                if (j == s.Length)
                                    break;
                            }
                            for (int k = j; k < s.Length; k++)
                            {
                                if (s[k] == ',')
                                {
                                    index = k;
                                    return "..." + temp + ",";
                                }
                            }
                            index = j - 1;
                            return "..." + temp;
                        }
                        if (s[j] == '.')
                        {
                            index = j - 1;
                            return "...";
                        }
                    }
                    index = i + 3;
                    return "...";
                }
                if (s[i] == ',')
                {
                    index = i;
                    return ",";
                }
                if(s[i] >= '0' && s[i] <= 'i' && i < s.Length)
                {
                    string temp = "";
                    while(s[i] >= '0' && s[i] <= '9' && i < s.Length)
                    {
                        temp += s[i++];
                        if (i == s.Length)
                            break;
                    }
                    for (int k = i; k < s.Length; k++)
                    {
                        if (s[k] == ',')
                        {
                            index = k;
                            return temp + ",";
                        }
                        if (s[k] >= '0' && s[k] <= '9')
                            break;
                    }
                    index = i - 1;
                    return temp;
                }
            }
            index = 666;
            return "";
        }

        static void Main(string[] args)
        {
            s = Console.ReadLine();
            int index = 0;
            string temp = "";
            if(s == "")
            {
                Console.WriteLine(s);
                    return;
            }
            while (index != 666 && index < s.Length)
            {
                temp += FindNext(ref index) + " ";
                index++;
            }
            temp = temp.Remove(temp.Length - 1);
            Console.WriteLine(temp);
            //string s = Console.ReadLine(), ss = "";
            //bool begin = false, end = false;
            //if (s.Length > 3)
            //{
            //    if (s[0] == s[1] && s[1] == s[2] && s[2] == '.')
            //    {
            //        begin = true;
            //    }
            //}
            //if (s[s.Length - 1] == ',')
            //    end = true;
            //int begini = 0, endi = s.Length;
            //if (begin)
            //    begini = 3;
            //if (end)
            //    endi--;
            //for (int i = begini; i < endi; i++)
            //{
            //    if (s[i] == ',')
            //    {
            //        if (s[i - 1] == ' ')
            //        {
            //            s = s.Remove(i - 1, 1);
            //            s = s.Insert(i + 1, " ");
            //        }
            //        else s = s.Insert(i + 1, " ");
            //        endi++;
            //    }
            //    if (s[i] == '.')
            //    {
            //        s = s.Insert(i, " ");
            //        endi++;
            //    }
            //}
            //Console.WriteLine(s);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _81B
{
    class Program
    {
        public static string s;

        public static string FindNext(ref int index)
        {
            for (int i = index; i < s.Length; i++)
            {
                if(s[i] == '.')
                {
                    for (int j = i + 3; j < s.Length; j++)
                    {
                        if(s[j] == ',')
                        {
                            index = j;
                            return "...,";
                        }
                        if(s[j] >= '0' && s[j] <= '9' && i < s.Length)
                        {
                            string temp = "";
                            while(s[j] >= '0' && s[j] <= '9' && j < s.Length)
                            {
                                temp += s[j++];
                                if (j == s.Length)
                                    break;
                            }
                            for (int k = j; k < s.Length; k++)
                            {
                                if (s[k] == ',')
                                {
                                    index = k;
                                    return "..." + temp + ",";
                                }
                                if (s[k] >= '0' && s[k] <= '9')
                                    break;
                                if (s[k] == '.')
                                    break;
                            }
                            index = j - 1;
                            return "..." + temp;
                        }
                        if (s[j] == '.')
                        {
                            index = j - 1;
                            return "...";
                        }
                    }
                    index = i + 3;
                    return "...";
                }
                if (s[i] == ',')
                {
                    index = i;
                    return ",";
                }
                if(s[i] >= '0' && s[i] <= 'i' && i < s.Length)
                {
                    string temp = "";
                    while(s[i] >= '0' && s[i] <= '9' && i < s.Length)
                    {
                        temp += s[i++];
                        if (i == s.Length)
                            break;
                    }
                    for (int k = i; k < s.Length; k++)
                    {
                        if (s[k] == ',')
                        {
                            index = k;
                            return temp + ",";
                        }
                        if (s[k] >= '0' && s[k] <= '9')
                            break;
                        if (s[k] == '.')
                            break;
                    }
                    index = i - 1;
                    return temp;
                }
            }
            index = 666;
            return "";
        }

        static void Main(string[] args)
        {
            s = Console.ReadLine();
            int index = 0;
            string temp = "";
            if(s == "")
            {
                Console.WriteLine(s);
                    return;
            }
            while (index != 666 && index < s.Length)
            {
                temp += FindNext(ref index) + " ";
                index++;
            }
            temp = temp.Remove(temp.Length - 1);
            Console.WriteLine(temp);
            //string s = Console.ReadLine(), ss = "";
            //bool begin = false, end = false;
            //if (s.Length > 3)
            //{
            //    if (s[0] == s[1] && s[1] == s[2] && s[2] == '.')
            //    {
            //        begin = true;
            //    }
            //}
            //if (s[s.Length - 1] == ',')
            //    end = true;
            //int begini = 0, endi = s.Length;
            //if (begin)
            //    begini = 3;
            //if (end)
            //    endi--;
            //for (int i = begini; i < endi; i++)
            //{
            //    if (s[i] == ',')
            //    {
            //        if (s[i - 1] == ' ')
            //        {
            //            s = s.Remove(i - 1, 1);
            //            s = s.Insert(i + 1, " ");
            //        }
            //        else s = s.Insert(i + 1, " ");
            //        endi++;
            //    }
            //    if (s[i] == '.')
            //    {
            //        s = s.Insert(i, " ");
            //        endi++;
            //    }
            //}
            //Console.WriteLine(s);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _81B
{
    class Program
    {
        public static string s;

        public static string FindNext(ref int index)
        {
            for (int i = index; i < s.Length; i++)
            {
                if(s[i] == '.')
                {
                    for (int j = i + 3; j < s.Length; j++)
                    {
                        if(s[j] == ',')
                        {
                            index = j;
                            return "...,";
                        }
                        if(s[j] >= '0' && s[j] <= '9' && i < s.Length)
                        {
                            string temp = "";
                            while(s[j] >= '0' && s[j] <= '9' && j < s.Length)
                            {
                                temp += s[j++];
                                if (j == s.Length)
                                    break;
                            }
                            for (int k = j; k < s.Length; k++)
                            {
                                if (s[k] == ',')
                                {
                                    index = k;
                                    return "..." + temp + ",";
                                }
                                if (s[k] >= '0' && s[k] <= '9')
                                    break;
                            }
                            index = j - 1;
                            return "..." + temp;
                        }
                        if (s[j] == '.')
                        {
                            index = j - 1;
                            return "...";
                        }
                    }
                    index = i + 3;
                    return "...";
                }
                if (s[i] == ',')
                {
                    index = i;
                    return ",";
                }
                if(s[i] >= '0' && s[i] <= 'i' && i < s.Length)
                {
                    string temp = "";
                    while(s[i] >= '0' && s[i] <= '9' && i < s.Length)
                    {
                        temp += s[i++];
                        if (i == s.Length)
                            break;
                    }
                    for (int k = i; k < s.Length; k++)
                    {
                        if (s[k] == ',')
                        {
                            index = k;
                            return temp + ",";
                        }
                        if (s[k] >= '0' && s[k] <= '9')
                            break;
                    }
                    index = i - 1;
                    return temp;
                }
            }
            index = 666;
            return "";
        }

        static void Main(string[] args)
        {
            s = Console.ReadLine();
            int index = 0;
            string temp = "";
            if(s == "")
            {
                Console.WriteLine(s);
                    return;
            }
            while (index != 666 && index < s.Length)
            {
                temp += FindNext(ref index) + " ";
                index++;
            }
            temp = temp.Remove(temp.Length - 1);
            Console.WriteLine(temp);
            //string s = Console.ReadLine(), ss = "";
            //bool begin = false, end = false;
            //if (s.Length > 3)
            //{
            //    if (s[0] == s[1] && s[1] == s[2] && s[2] == '.')
            //    {
            //        begin = true;
            //    }
            //}
            //if (s[s.Length - 1] == ',')
            //    end = true;
            //int begini = 0, endi = s.Length;
            //if (begin)
            //    begini = 3;
            //if (end)
            //    endi--;
            //for (int i = begini; i < endi; i++)
            //{
            //    if (s[i] == ',')
            //    {
            //        if (s[i - 1] == ' ')
            //        {
            //            s = s.Remove(i - 1, 1);
            //            s = s.Insert(i + 1, " ");
            //        }
            //        else s = s.Insert(i + 1, " ");
            //        endi++;
            //    }
            //    if (s[i] == '.')
            //    {
            //        s = s.Insert(i, " ");
            //        endi++;
            //    }
            //}
            //Console.WriteLine(s);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _81B
{
    class Program
    {
        public static string s;

        public static string FindNext(ref int index)
        {
            for (int i = index; i < s.Length; i++)
            {
                if(s[i] == '.')
                {
                    for (int j = i + 3; j < s.Length; j++)
                    {
                        if(s[j] == ',')
                        {
                            index = j;
                            return "...,";
                        }
                        if(s[j] >= '0' && s[j] <= '9' && i < s.Length)
                        {
                            string temp = "";
                            while(s[j] >= '0' && s[j] <= '9' && j < s.Length)
                            {
                                temp += s[j++];
                                if (j == s.Length)
                                    break;
                            }
                            j--;
                            for (int k = j; k < s.Length; k++)
                            {
                                if (s[k] == ',')
                                {
                                    index = k;
                                    return "..." + temp + ",";
                                }
                            }
                            index = j;
                            return "..." + temp;
                        }
                        if (s[j] == '.')
                        {
                            index = j - 1;
                            return "...";
                        }
                    }
                    index = i + 3;
                    return "...";
                }
                if (s[i] == ',')
                {
                    index = i;
                    return ",";
                }
                if(s[i] >= '0' && s[i] <= 'i' && i < s.Length)
                {
                    string temp = "";
                    while(s[i] >= '0' && s[i] <= '9' && i < s.Length)
                    {
                        temp += s[i++];
                        if (i == s.Length)
                            break;
                    }
                    i--;
                    for (int k = i; k < s.Length; k++)
                    {
                        if (s[k] == ',')
                        {
                            index = k;
                            return temp + ",";
                        }
                    }
                    index = i;
                    return temp;
                }
            }
            index = 666;
            return "";
        }

        static void Main(string[] args)
        {
            s = Console.ReadLine();
            int index = 0;
            string temp = "";
            if(s == "")
            {
                Console.WriteLine(s);
                    return;
            }
            while (index != 666 && index < s.Length)
            {
                temp += FindNext(ref index) + " ";
                index++;
            }
            temp = temp.Remove(temp.Length - 1);
            Console.WriteLine(temp);
            //string s = Console.ReadLine(), ss = "";
            //bool begin = false, end = false;
            //if (s.Length > 3)
            //{
            //    if (s[0] == s[1] && s[1] == s[2] && s[2] == '.')
            //    {
            //        begin = true;
            //    }
            //}
            //if (s[s.Length - 1] == ',')
            //    end = true;
            //int begini = 0, endi = s.Length;
            //if (begin)
            //    begini = 3;
            //if (end)
            //    endi--;
            //for (int i = begini; i < endi; i++)
            //{
            //    if (s[i] == ',')
            //    {
            //        if (s[i - 1] == ' ')
            //        {
            //            s = s.Remove(i - 1, 1);
            //            s = s.Insert(i + 1, " ");
            //        }
            //        else s = s.Insert(i + 1, " ");
            //        endi++;
            //    }
            //    if (s[i] == '.')
            //    {
            //        s = s.Insert(i, " ");
            //        endi++;
            //    }
            //}
            //Console.WriteLine(s);
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Sequence_Formatting
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            s = s.Replace(",", ", ");
            s = s.Replace("...", " ...");

            int t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace(" ,", ",");
            }

            s = s.Replace(",,", ", ,");

            t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace("  ", " ");
            }

            s = s.Trim(' ');
            writer.WriteLine(s);
            writer.Flush();
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Sequence_Formatting
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            s = s.Replace(",", ", ");
            s = s.Replace("...", " ...");

            int t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace(" ,", ",");
            }

            t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace("  ", " ");
            }

            s = s.Trim(' ');
            writer.WriteLine(s);
            writer.Flush();
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Sequence_Formatting
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            s = s.Replace(",", ", ");
            s = s.Replace("...", " ...");

            int t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace("  ", " ");
            }

            s = s.Trim(' ');
            writer.WriteLine(s);
            writer.Flush();
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Sequence_Formatting
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            s = s.Replace(",", ", ");

            int t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace("... ", "...");
            }

            s = s.Replace("...", " ...");

            t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace(" ,", ",");
            }

            t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace(",,", ", ,");
            }

            t = 0;
            while (t != s.Length)
            {
                t = s.Length;
                s = s.Replace("  ", " ");
            }

            s = s.Trim(' ');
            writer.WriteLine(s);
            writer.Flush();
        }
    }
}


#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
vector<int> v[101];
void init()
{
    for(int i = 0; i<101;i++)
        v[i].clear();
}
int dis[101];
void dfs(int now,int from,int len)
{
    dis[now] = len;
    for(int i = 0; i< v[now].size(); i++)
    {
        int u = v[now][i];
        if(u != from)
        {
            dfs(u,now,len + 1);
        }
    }

}
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n;
    while(scanf("%d",&n) == 1)
    {
        int ans = 0;
        for(int i = 1;i<=n;i++)
        {
            int m;
            init();
            scanf("%d",&m);
            for(int k = 0; k < m - 1; k++)
            {
                int w,u;
                scanf("%d %d",&w,&u);
                v[u].push_back(w);
                v[w].push_back(u);
            }
            memset(dis,0,sizeof(dis));
            dfs(1, -1,0);
            int nxt = max_element(dis + 1, dis + m + 1) - dis;
            memset(dis,0,sizeof(dis));
            dfs(nxt,-1,0);
            ans += *max_element(dis + 1,dis + m + 1);
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define N 111
int e[N][N],ans,len;
using namespace std;
int go (int k,int n){
	int maxn=0;
	for ( int i = 1; i <= n; i++ )
		if ( e[k][i] ){
			e[k][i] = e[i][k] = 0;
			maxn = max(maxn,go(i,n)+1);
			e[k][i] = e[i][k] = 1;
		}
	return maxn;
}
int main(void)
{
	int n,t;
	freopen("input.txt","r", stdin);
	freopen("output.txt","w", stdout);
	scanf("%d", &n);
	while ( n-- ){
		scanf("%d", &t);
		memset(e,0,sizeof(e));
		for ( int i = 1; i < t; i++ ){
			int x,y;
			scanf("%d%d", &x,&y);
			e[x][y]=e[y][x]=1;
		}
		len=0;
		for ( int i=1; i <= t; i++ )
			len = max(len,go(i,t));
		ans += len;
	}
	printf("%d\n", ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define N 111
int e[N][N],ans,len;
using namespace std;
int go (int k,int n){
	int maxn=0;
	for ( int i = 1; i <= n; i++ )
		if ( e[k][i] ){
			e[k][i] = e[i][k] = 0;
			maxn = max(maxn,go(i,n)+1);
			e[k][i] = e[i][k] = 1;
		}
	return maxn;
}
int main(void)
{
	int n,t;
	scanf("%d", &n);
	while ( n-- ){
		scanf("%d", &t);
		memset(e,0,sizeof(e));
		for ( int i = 1; i < t; i++ ){
			int x,y;
			scanf("%d%d", &x,&y);
			e[x][y]=e[y][x]=1;
		}
		len=0;
		for ( int i=1; i <= t; i++ )
			len = max(len,go(i,t));
		ans += len;
	}
	printf("%d\n", ans);
	return 0;
}


/*
PROG:   [p]
ID  :   hewifi
LANG:   C++
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
const int Inf = (int)(1e9);
const int N = 100 + 5;
int w[N][N];
int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int ans = 0, t, n, u, v;
    scanf("%d", &t);
    while (t -- > 0) {
        scanf("%d", &n);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) w[i][j] = Inf;
            w[i][i] = 0;
        }
        for (int i = 0; i < n - 1; ++i) {
            scanf("%d%d", &u, &v);
            -- u; -- v;
            w[u][v] = w[v][u] = 1;
        }
        for (int k = 0; k < n; ++k)
            for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                w[i][j] = std::min(w[i][j], w[i][k] + w[k][j]);
        int mx = 0;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j) if (w[i][j] != Inf)
                mx = std::max(mx, w[i][j]);
        //printf("%d\n", mx);
        ans += mx;
    }
    printf("%d\n", ans);
    return 0;
}


// by shik
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
using namespace std;
vector<int> e[110];
int big,t;
void go( int p, int f=-1, int lv=0 ) {
	if ( lv>big ) {
		big=lv;
		t=p;
	}
	FOR(it,e[p]) if ( *it!=f ) go(*it,p,lv+1);
}
int get() {
	int n,a,b;
	scanf("%d",&n);
	for ( int i=1; i<=n; i++ ) e[i].clear();
	for ( int i=1; i<n; i++ ) {
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	big=-1; go(1);
	big=-1; go(t);
	return big;
}
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n,ans=0;
	scanf("%d",&n);
	while ( n-- ) ans+=get();
	printf("%d\n",ans);
	return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <bitset>
#include <cassert>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std; typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const ld EPS = 1e-9; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; typedef complex<ld> cbase; inline void fft (vector<cbase> &a, bool invert) {int n = (int)a.size(); for (int i = 1, j = 0; i < n; ++i) {int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) swap(a[i], a[j]);} for (int len = 2; len <= n; len <<= 1) {ld ang = 2 * PI / len * (invert ? -1 : 1); cbase wlen(cos(ang), sin(ang)); for (int i = 0; i < n; i += len) {cbase w(1); for (int j=0; j < len / 2; ++j) {cbase u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen;}}} if (invert) for (int i = 0; i < n; ++i) a[i] /= n;} inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(ll a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;} struct lnum {vector <int> a; int base; lnum(int num = 0, int base = 1000000000):base(base) {if (!num) a.resize(1); while(num) {a.pb(num % base); num /= base;}} inline int len() const {return a.size();} lnum & operator=(const lnum &l) {if (this != &l) {a = l.a; base = l.base;} return *this;} inline friend lnum operator+(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int ln = l.len(), rn = r.len(); int n = max(ln, rn); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = o; if (i < ln) s += l.a[i]; if (i < rn) s += r.a[i]; o = s >= base; if (o) s -= base; ret.a[i] = s;} if (o) ret.a.push_back(1); return ret;} inline friend lnum operator-(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int n = l.len(); int rn = r.len(); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = l.a[i] - o; if (i < rn) s -= r.a[i]; o = s < 0; if (o) s += base; ret.a[i] = s;} if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator*(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; if (l.len() * r.len() > 1000000) {vector<cbase> fa (l.a.begin(), l.a.end()), fb (r.a.begin(), r.a.end()); int n = 1; while (n < max (l.len(), r.len())) n <<= 1; n <<= 1; fa.resize (n), fb.resize (n); fft (fa, false), fft (fb, false); for (int i = 0; i < n; ++i) fa[i] *= fb[i]; fft (fa, true); ret.a.resize(n); for (int i = 0; i < n; ++i) ret.a[i] = int (fa[i].real() + 0.5); int carry = 0; for (int i=0; i < n; ++i) {ret.a[i] += carry; carry = ret.a[i] / base; ret.a[i] %= base;}} else {ret.a.resize(l.len() + r.len()); for (int i = 0; i < l.len(); ++i) for (int j = 0, carry = 0; j < r.len() || carry; ++j) {long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry; ret.a[i + j] = cur % base; carry = cur / base;}} while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator/(const lnum &l, const int &r) {lnum ret(0, l.base); ret.a.resize(l.len()); int carry = 0; for(int i = l.len() - 1; i >= 0; --i) {long long cur = l.a[i] + (ll)carry * l.base; ret.a[i] = cur / r; carry = cur % r;} while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); return ret;}  inline friend bool operator<(const lnum &l, const lnum &r) {if (l.len() < r.len()) return true; if (l.len() > r.len()) return false; int n = l.len(); for(int i = n - 1; i >= 0; --i) {if (l.a[i] < r.a[i]) return true; if (l.a[i] > r.a[i]) return false;} return false;} inline friend bool operator>(const lnum &l, const lnum &r) {return r < l;} inline friend bool operator==(const lnum &l, const lnum &r) {if (l.len() != r.len()) return false; int n = l.len(); for(int i = n - 1; i; --i) {if (l.a[i] != r.a[i]) return false;} return true;} inline friend bool operator!=(const lnum &l, const lnum &r) {return !(l == r);} inline void print() {if (base == 1000000000) {printf("%d", a.back()); for(int i = a.size() - 2; i >=0; --i) printf("%09d", a[i]);} else {for(int i = a.size() - 1; i >= 0; --i) printf("%d", a[i]);}}};

VVI g;
int d;

int dfs(int v, int p = -1)
{
    VI t;
    int ret = 0;
    for(int to : g[v])
    {
        if (to == p)
            continue;
        t.pb(dfs(to, v) + 1);
    }
    sort(all(t), greater<int>());
    if (t.size() > 1)
        remax(d, t[0] + t[1]);
    if (t.size() > 0)
        ret = t[0];
    remax(d, ret);
    return ret;
}

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    in(t);
    int ans = 0;
    while(t--)
    {

        in(n);
        g.clear();
        g.resize(n);
        d = 0;
        forn(i, n - 1)
        {
            int a = nxt() - 1;
            int b = nxt() - 1;
            g[a].pb(b);
            g[b].pb(a);
        }
        dfs(0);
        ans += d;
    }
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>

using namespace std;

#define mp make_pair
#define pb push_back
#define LL long long
#define ULL unsigned long long
#define BASE 73
#define NMAX 10000
#define NMAX2 20001
#define MOD1 1000000007
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define get_max(val1, val2) val1 = max(val1, val2);

int PASSED_POINT = 0;

void Duxar() {
#ifndef ONLINE_JUDGE
	printf("\n . . . . . . . . . . . . . Passed point - %d\n", ++PASSED_POINT);
#endif
}

template <class T>
void read_int(T &_value) {
	T sign = 1;
	char ch;
	_value = 0;
	while(!isdigit(ch = getchar())) {
		(ch == '-') && (sign = -1);
	}
	do {
		_value = _value * 10 + (ch - '0');
	} while(isdigit(ch = getchar()));
	_value *= sign;
}

template <class T>
T add_nr(T a, T b) {
	T _res = a + b;
	return _res % MOD1;
}

int N;
int GetLength();

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.cpp", "r", stdin);
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int i, ans = 0;

	read_int(N);

	for (i = 1; i <= N; ++i) {
		ans += GetLength() - 1;
	}
	printf("%d\n", ans);

	return 0;
}

pair <int, int> Dfs(vector <vector <int> > &graph, int iam, int from) {
	pair <int, int> ans(0, iam);
	for (auto to: graph[iam]) {
		if (to != from) {
			ans = max(ans, Dfs(graph, to, iam));
		}
	}
	++ans.first;
	return ans;
}

int GetLength() {
	int i, nr_nodes, from, to;
	vector <vector <int> > graph;
	pair <int, int> first_node, second_node;

	read_int(nr_nodes);
	graph.resize(nr_nodes + 1);

	for (i = 0; i < nr_nodes - 1; ++i) {
		read_int(from); read_int(to);
		graph[from].pb(to);
		graph[to].pb(from);
	}

	first_node = Dfs(graph, 1, 0);
	second_node = Dfs(graph, first_node.second, 0);

	return second_node.first;
}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>

using namespace std;

#define int ll
const bool online_judge =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v)  (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < n; i++)
#define tag(i,v) rep(i,SZ(v))
#define _trace(x) #x << " = " << (x)
#define trace(x)  { if(!online_judge) cerr << _trace(x) << endl; }
#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << endl; }
#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << " " << _trace(z) << endl; }
#define tracev(x) { if(!online_judge) { cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl; } }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) (x/y+x%y)

const int inf = 1LL << 60;
int toInt(string s) {int res; stringstream ss; ss<<s; ss>>res; return res; }
string toString(int n) { stringstream ss; ss<<n; return ss.str(); }

void run() {

  /* entry point */

  int t;
  cin >> t;

  int ans = 0;

  rep(i,t){
    int n;
    cin >> n;
    vi count(n,0);
    rep(j,n-1){
      int a,b;
      cin >> a >> b;
      a--; b--;
      count[a]++;
      count[b]++;
    }
    int tmp = 1;
    rep(k,n){
      int c = count[k];
      if(c >= 2){
	tmp++;
      }
    }
    trace(tmp);
    ans += tmp;
  }

  cout << ans << endl;

}

#undef int

int main(int argc, char *argv[]) {

  #if 0
  if(online_judge){
    ifstream ifile("input.txt");
    if(ifile) freopen("input.txt", "rt", stdin);
    if(ifile) freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>

using namespace std;

#define int ll
const bool online_judge =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v)  (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < n; i++)
#define tag(i,v) rep(i,SZ(v))
#define _trace(x) #x << " = " << (x)
#define trace(x)  { if(!online_judge) cerr << _trace(x) << endl; }
#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << endl; }
#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << " " << _trace(z) << endl; }
#define tracev(x) { if(!online_judge) { cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl; } }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) (x/y+x%y)

const int inf = 1LL << 60;
int toInt(string s) {int res; stringstream ss; ss<<s; ss>>res; return res; }
string toString(int n) { stringstream ss; ss<<n; return ss.str(); }

void run() {

  /* entry point */

  int t;
  cin >> t;

  int ans = 0;

  rep(i,t){
    int n;
    cin >> n;
    if(n == 1)
      continue;
    vi count(n,0);
    rep(j,n-1){
      int a,b;
      cin >> a >> b;
      a--; b--;
      count[a]++;
      count[b]++;
    }
    int tmp = 1;
    rep(k,n){
      int c = count[k];
      if(c >= 2){
	tmp++;
      }
    }
    trace(tmp);
    ans += tmp;
  }

  cout << ans << endl;

}

#undef int

int main(int argc, char *argv[]) {

  #if 1
  if(online_judge){
    ifstream ifile("input.txt");
    if(ifile) freopen("input.txt", "rt", stdin);
    if(ifile) freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>

using namespace std;

#define int ll
const bool online_judge =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v)  (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < n; i++)
#define tag(i,v) rep(i,SZ(v))
#define _trace(x) #x << " = " << (x)
#define trace(x)  { if(!online_judge) cerr << _trace(x) << endl; }
#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << endl; }
#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << " " << _trace(z) << endl; }
#define tracev(x) { if(!online_judge) { cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl; } }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) (x/y+x%y)

const int inf = 1LL << 60;
int toInt(string s) {int res; stringstream ss; ss<<s; ss>>res; return res; }
string toString(int n) { stringstream ss; ss<<n; return ss.str(); }

int visited[110];

int dfs(const vvi &graph, int n){
  if(visited[n] != 0)
    return -1;
  visited[n] = 1;
  int ans = -1;
  vi v = graph[n];
  tag(i,v){
    ans = max(ans, dfs(graph, v[i]));
  }
  if(ans == -1)
    return 0;
  return ans+1;
}

int solve(const vvi &graph, int n){
  int ans = 0;
  #if 1
  rep(i,n){
    memset(visited, 0, sizeof(visited));
    int tmp2 = dfs(graph,i);
    ans = max(ans, tmp2);
  }
  #endif
  return ans;
}

void run() {

  /* entry point */

  int t;
  cin >> t;

  int ans = 0;

  vvi graph;

  rep(i,t){
    int n;
    cin >> n;
    graph = vvi(n,vi());
    rep(j,n-1){
      int a,b;
      cin>>a>>b;
      a--;b--;
      graph[a].pb(b);
      graph[b].pb(a);
    }
    int tmp = solve(graph,n);
    trace(tmp);
    ans += tmp;
  }

  cout << ans << endl;

}

#undef int

int main(int argc, char *argv[]) {

  #if 1
  if(online_judge){
    ifstream ifile("input.txt");
    if(ifile) freopen("input.txt", "rt", stdin);
    if(ifile) freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz size()
#define fst first
#define snd second
#define For(i, st, en) for(int i=int(st); i<=int(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<int(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)

template <class _T> inline _T sqr(const _T& x) { return x * x; }
template <class _T> inline string toStr(const _T& a) { ostringstream os(""); os << a; return os.str(); }

typedef long double ld;

// Constants
const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-11;

// Types
typedef signed   long long i64;
typedef unsigned long long u64;
typedef vector < int > VI;
typedef vector < string > VS;
typedef pair < int, int > PII;

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	cout << setiosflags(ios::fixed) << setprecision(10);

	int t;
	int a[128][128];
	scanf("%d", &t);
	int ans = 0;
	forn(iii, t)
	{
		int n;
		scanf("%d", &n);
		memset(a, 0x3F, sizeof(a));
		forn(i, n)
		{
			a[i][i] = 0;
		}
		forn(i, n - 1)
		{
			int u, v;
			scanf("%d %d", &u, &v);
			--u;
			--v;
			a[u][v] = a[v][u] = 1;
		}
		forn(i, n)
		{
			forn(j, n)
			{
				forn(k, n)
				{
					a[j][k] = min(a[j][k], a[j][i] + a[i][k]);
				}
			}
		}
		int ma = 0;
/*		forn(i, n)
		{
			forn(j, n)
			{
				cout << a[i][j] << " ";
			}
			cout << endl;
		}*/
		forn(i, n)
		{
			forn(j, i)
			{
				ma = max(ma, a[i][j]);
			}
		}
		ans += ma;
	}
	cout << ans;

	return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>

#define pb push_back

const char IN [ ] = "input.txt" ;
const char OUT [ ] = "output.txt" ;
const int MAX = 114 ;

using namespace std;

vector < int > gr [ MAX ] ;
int dp [ MAX ] ;
bool viz [ MAX ] ;

inline void schm ( long long &a , long long b )
{
    if ( a < b )
        a = b ;
}

void dfs ( int nod )
{
    viz [ nod ] = 1 ;
    for ( auto x : gr [ nod ] )
    {
        if ( viz [ x ]  == 0 )
        {
            dp [ x ] = dp [ nod ] + 1 ;
            dfs ( x ) ;
        }
    }
}

long long calcull ( int n )
{
    long long sol = 0 ;
    for ( int i = 1 ; i <= n ; ++ i )
    {
        dp [ i ] = 0 ;
        memset ( viz , 0 , sizeof ( viz ) ) ;
        dfs ( i ) ;
        for ( int j = 1 ; j <= n ; ++ j )
            schm ( sol , dp [ j ] ) ;
    }
    return sol ;
}

int main(              )
{
    long long sol = 0 ;
    freopen( IN , "r" , stdin ) ;
    freopen( OUT , "w" , stdout ) ;
    int t ;
    scanf ( "%d" ,&t ) ;
    for ( ; t ; -- t )
    {
        int n ;
        scanf ( "%d" ,&n ) ;
        for ( int i = 1 ; i <= n ; ++ i )
            gr [ i ].clear ( ) ;
        for ( int i = 1 ; i < n ; ++ i )
        {
            int a , b ;
            scanf ( "%d %d" ,&a ,&b ) ;
            gr [ a ].pb ( b ) ;
            gr [ b ].pb ( a ) ;
        }
        sol = sol + calcull ( n ) ;
    }
    printf ( "%I64d" , sol ) ;
    return 0;
}


#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
using namespace std;

vector<int> e[111];

int dfs(int x, int parent, int dist) {
    int t = dist;
    for (auto i : e[x]) if (i != parent) t = max(t, dfs(i, x, dist + 1));
    return t;
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int tc;
    cin >> tc;
    int ans = 0;
    while (tc--) {
        int n; cin >> n;
        for (int i = 0; i <= n; i++) e[i].clear();
        for (int i = 0; i < n - 1; i++) {
            int x, y;
            cin >> x >> y;
            e[x].push_back(y);
            e[y].push_back(x);
        }
        int cur = 0;
        for (int i = 1; i <= n; i++) cur = max(cur, dfs(i, -1, 0));
        ans += cur;
    }
    cout << ans << endl;
}


#include<stdio.h>

void f(int j,int p);

int mapa[200][200],n,k,l,i,j,a,b,t,m,s,h[200];

int main()
{
    freopen("entrada.txt","r",stdin);
    freopen("salida.txt","w",stdout);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<110;j++)
        {
            for(k=0;k<110;k++)
            {
                mapa[j][k]=0;
            }
        }
        scanf("%d",&l);
        m=0;
        for(j=1; j<l; j++)
        {
            scanf("%d%d",&a,&b);
            mapa[a][b] = mapa[b][a] = 1;
        }
        for(j=1;j<=l;j++)
            f(j,0);
        t += m;
    }
    printf("%d",t);

    return 0;
}

void f(int j,int p)
{
    int i;
    if(h[j])
        return;
    h[j]=1;
    if(p>m)
        m=p;

    for(i=1;i<=l;i++)
    {
        if(mapa[j][i])
            f(i,p+1);
    }
    h[j]=0;
}


#include<stdio.h>

int mapa[200][200],n,k,l,i,j,a,b,t,m,s,h[200];

void f(int j,int p);

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<110;j++)
        {
            for(l=0;l<110;l++)
            {
                mapa[j][l]=0;
            }
        }
        scanf("%d",&k);
        m=0;
        for(j=1;j<k;j++)
        {
            scanf("%d%d",&a,&b);
            mapa[a][b]=mapa[b][a]=1;
        }
        for(j=1;j<=k;j++)
            f(j,0);
        t+=m;
    }
    printf("%d",t);

    return 0;
}

void f(int j,int p)
{
    int i;

    if(h[j])
        return;

    h[j]=1;

    if(p>m)
        m=p;

    for(i=1;i<=k;i++)
    {
        if(mapa[j][i])
            f(i,p+1);
    }
    h[j]=0;
}


#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#define N 110

void inicializar();
void nodo_nuevo(int a,int b);
int mayor(int n1,int n2);
int bus_profundidad(int u,int g);

int raiz[N], nodo[N*2], siguiente[N*2], longitud, e;

int main(){
    int n, m, v, a, res, i;
    FILE *archIn = fopen("input.txt", "r");
    FILE *archOut = fopen("output.txt", "w");
    while(fscanf(archIn,"%d",&n) != EOF){
        res = 0;
        while(n--){
            fscanf(archIn,"%d",&m);
            inicializar();
            longitud = 0;
            for(i = 0; i < m-1; i++){
                fscanf(archIn,"%d%d",&v,&a);
                nodo_nuevo(v,a);
                nodo_nuevo(a,v);
            }
            bus_profundidad(1,-1);
            res += longitud;
        }
        fprintf(archOut,"%d",res);
    }
    return 0;
}

void inicializar(){
    e = 0;
    memset(raiz,-1,sizeof(raiz));
}

void nodo_nuevo(int a,int b){
    nodo[e] = b;
    siguiente[e] = raiz[a];
    raiz[a] = e++;
}

int mayor(int n1,int n2){
   if(n1<n2)
        return n2;
   else
        return n1;
}

int bus_profundidad(int u,int g){
    int r, max, i;
    r = 0;
    for(i = raiz[u];i != -1;i = siguiente[i]){
        if(nodo[i] == g){
            continue;
        }
        max = bus_profundidad(nodo[i],u);
        longitud = mayor(longitud,r + max + 1);
        r = mayor(r,max + 1);
    }
    return r;
}


#include <stdio.h>
#include <stdlib.h>
#define CLAVE -1

typedef struct nodoDirectorio{
    int vertice;
    struct nodoAdyacente *lista;
    struct nodoDirectorio *enlace;
    int distancia;

} NodoGrafo;

typedef NodoGrafo* TipoDato;

typedef struct nodo
{
    TipoDato elemento;
    struct nodo *siguiente;
} Nodo;

void crearPila(Nodo **pila);
void insertar(Nodo **pila,TipoDato elemento);
TipoDato quitar(Nodo **pila);
int pilaVacia(Nodo *pila);

typedef struct nodoAdyacente
{
    struct nodoDirectorio *destino;
    struct nodoAdyacente *enlace;
} NodoLista;

void nuevoVertice(NodoGrafo **grafo, int vertice);
void arista(NodoGrafo *grafo, int org, int dst);
NodoGrafo* direccion(NodoGrafo *grafo,int vert);
void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[]);

int total = 0;
int longitud = 0;

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int nro;
    scanf("%d",&nro);
    NodoGrafo *vec[nro];
    int i,x,y,mayor = 0, k,total=0;
    for( k = 0; k < nro; k++)
    {
        vec[k] = NULL;

        int n;
        scanf("%d",&n);

        for( i = 1; i <= n; i++)
        {
            nuevoVertice(&vec[k],i);
        }
        for( i = 1; i <=n-1; i++)
        {
            scanf("%d%d",&x,&y);

            arista(vec[k],x,y);
            arista(vec[k],y,x);

        }
           int m[n];
            mayor = 0;
           longitud = 0;
        for( i = 1; i <= n; i++)
        {
            recorreProfundidad(vec[k],n,i,m);
            if(longitud > mayor){mayor = longitud;}
        }
        total = total + mayor;
    }
            printf("%d",total);

    return 0;

}
void nuevoVertice(NodoGrafo **grafo, int vertice)
{
    NodoGrafo *nuevo;
    nuevo = (NodoGrafo*)malloc(sizeof(NodoGrafo));
    nuevo -> vertice = vertice;
    nuevo -> lista = NULL;
    nuevo -> enlace = *grafo;
    *grafo = nuevo;
}
void arista(NodoGrafo *grafo, int org, int dst)
{
    NodoGrafo *v1,*v2;
    NodoLista *ady;

    v1 = direccion(grafo,org);
    v2 = direccion(grafo,dst);

    if( v1 && v2 )
    {
        ady = (NodoLista*)malloc(sizeof(NodoLista));
        ady -> destino = v2;
        ady -> enlace = v1 -> lista;
        v1 -> lista = ady;
    }
}

NodoGrafo* direccion(NodoGrafo *grafo,int vert)
{
    NodoGrafo *aux;

    aux = grafo;

    while( aux -> vertice != vert && aux != NULL )
    {
        aux = aux -> enlace;
    }
    return aux;

}

void crearPila(Nodo **pila)
{
    *pila = NULL;
}

int pilaVacia(Nodo *pila)
{
    return pila == NULL;
}

void insertar(Nodo **pila,TipoDato elemento)
{
    Nodo *nuevo;

    nuevo = (Nodo*)malloc(sizeof(Nodo));
    nuevo -> elemento = elemento;
    nuevo -> siguiente = *pila;
    (*pila) = nuevo;
}

TipoDato quitar(Nodo **pila)
{
    TipoDato tem;
    Nodo *q;

    if(pilaVacia(*pila))
    {
        puts(" Se intenta sacar un elemento en pila vacia");
        exit(1);
    }

    tem = (*pila) -> elemento;
    q = *pila;
    (*pila) = (*pila) -> siguiente;
    free(q);

    return tem;
}

void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[])
{
    NodoGrafo *v1,*v2,*w;
    NodoLista *ady;
    Nodo *pila;

    crearPila(&pila);
    int i;
    int tiempos[n];
    for( i = 0; i < n; i++)
    {
        m[i] = CLAVE;
        tiempos[i] = 0;
    }
    m[v-1] = 0;

    v1 = direccion(grafo,v);
    insertar(&pila,v1);
    total = 0;
    v1 -> distancia = 0;
    while(!pilaVacia(pila))
    {

        w = quitar(&pila);
        ady = w -> lista;
        while(ady != NULL)
        {

            int k;
            k = ady -> destino -> vertice - 1;
            if(m[k] == CLAVE)
            {
                insertar(&pila,ady->destino);
                m[k] = 1;
                ady -> destino -> distancia = w -> distancia + 1;
                if(ady -> destino -> distancia > longitud)
                    longitud = ady -> destino -> distancia;

            }

            ady = ady -> enlace;
        }

    }

}


#include <stdio.h>
#include <stdlib.h>
#define CLAVE -1

typedef struct nodoDirectorio{
    int vertice;
    struct nodoAdyacente *lista;
    struct nodoDirectorio *enlace;
    int distancia;

} NodoGrafo;
typedef NodoGrafo* TipoDato;

typedef struct nodo
{
    TipoDato elemento;
    struct nodo *siguiente;
} Nodo;

void crearPila(Nodo **pila);
void insertar(Nodo **pila,TipoDato elemento);
TipoDato quitar(Nodo **pila);
int pilaVacia(Nodo *pila);

typedef struct nodoAdyacente
{
    struct nodoDirectorio *destino;
    struct nodoAdyacente *enlace;
} NodoLista;

void nuevoVertice(NodoGrafo **grafo, int vertice);
void arista(NodoGrafo *grafo, int org, int dst);
NodoGrafo* direccion(NodoGrafo *grafo,int vert);
void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[]);
int longitud=0;
int maximo=0;

int main()
{
    NodoGrafo* cabeza;
    cabeza = NULL;

    freopen("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    int k,n,mayor=0,total=0;
    int nro;
    scanf("%d",&nro);
    NodoGrafo *vec[nro];

    int m[nro];

        int i,x,y;
    for(k=0;k<nro;k++){

        vec[k]=NULL;
        scanf("%d",&n);
        for( i = 1; i <= n; i++)
        {
            nuevoVertice(&vec[k],i);
        }
        for( i = 1; i <=n-1; i++)
        {
            scanf("%d%d",&x,&y);
            arista(vec[k],x,y);
            arista(vec[k],y,x);

        }
        for( i =1; i<= n;i++)
        {
            recorreProfundidad(vec[k],n,i,m);
            if(longitud>maximo){maximo=longitud;}
        }

        total=total+maximo;
    }
    printf("%d",total);
        return 0;

}

void nuevoVertice(NodoGrafo **grafo, int vertice)
{
    NodoGrafo *nuevo;
    nuevo = (NodoGrafo*)malloc(sizeof(NodoGrafo));
    nuevo -> vertice = vertice;
    nuevo -> lista = NULL;
    nuevo -> enlace = *grafo;
    *grafo = nuevo;
}

void arista(NodoGrafo *grafo, int org, int dst)
{
    NodoGrafo *v1,*v2;
    NodoLista *ady;

    v1 = direccion(grafo,org);
    v2 = direccion(grafo,dst);

    if( v1 && v2 )
    {
        ady = (NodoLista*)malloc(sizeof(NodoLista));
        ady -> destino = v2;
        ady -> enlace = v1 -> lista;
        v1 -> lista = ady;
    }
}

NodoGrafo* direccion(NodoGrafo *grafo,int vert)
{
    NodoGrafo *aux;

    aux = grafo;

    while( aux -> vertice != vert && aux != NULL )
    {
        aux = aux -> enlace;
    }
    return aux;
}

void borrarArco(NodoGrafo *grafo, int org, int dst)
{
    NodoGrafo *v1,*v2;

    v1 = direccion(grafo,org);
    v2 = direccion(grafo,dst);

    if( v1 && v2 )
    {
        NodoLista *ady;
        NodoLista *a = NULL;
        ady = v1 -> lista;
        while(ady)
        {
            if(ady -> destino == v2)
            {
                if(a == NULL)
                    v1 -> lista = ady -> enlace;
                else
                    a -> enlace = ady -> enlace;
                free(ady);
                ady = NULL;
            }
            else
            {
                a = ady;
                ady = ady -> enlace;
            }
        }
    }
}

void crearPila(Nodo **pila)
{
    *pila = NULL;
}

int pilaVacia(Nodo *pila)
{
    return pila == NULL;
}

void insertar(Nodo **pila,TipoDato elemento)
{
    Nodo *nuevo;

    nuevo = (Nodo*)malloc(sizeof(Nodo));
    nuevo -> elemento = elemento;
    nuevo -> siguiente = *pila;
    (*pila) = nuevo;
}

TipoDato quitar(Nodo **pila)
{
    TipoDato tem;
    Nodo *q;

    if(pilaVacia(*pila))
    {
        puts(" Se intenta sacar un elemento en pila vacia");
        exit(1);
    }
     tem = (*pila) -> elemento;
    q = *pila;
    (*pila) = (*pila) -> siguiente;
    free(q);

    return tem;
}

void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[])
{
    NodoGrafo *v1,*v2,*z;
    NodoLista *ady;
    Nodo *pila;

    crearPila(&pila);
    int i;
    for( i = 0; i < n; i++)
    {
        m[i] = CLAVE;

    }
    m[v-1] = 0;
    v1 = direccion(grafo,v);
    insertar(&pila,v1);
    v1 -> distancia = 0;
    while(!pilaVacia(pila))
    {
        z = quitar(&pila);
        ady = z -> lista;
        while(ady != NULL)
        {
            int k;
            k = ady -> destino -> vertice - 1;
            if(m[k] == CLAVE)
            {
                insertar(&pila,ady->destino);
                m[k] = 1;
                ady -> destino -> distancia = z -> distancia + 1;
                if(ady -> destino -> distancia >longitud)
                   longitud=ady -> destino -> distancia ;

            }
                ady = ady -> enlace;

        }

    }
}