Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.

Input

The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s.

Output

If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.

Examples

Input

8
00111000


Output

YES


Input

7
1001011


Output

NO


Input

7
1010100


Output

YES
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class ExtraTerrestrialIntelligence {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// This will store inputs
		long startTime = System.currentTimeMillis();
		ArrayList<String> inputs = new ArrayList<String>();
		boolean isResultWritten = false;

		// To write test result
		PrintWriter resultWriter = null;
		try {
			resultWriter = new PrintWriter(new File("output.txt"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// To read input data
		try {
			readInputData(inputs);
		} catch (Exception e) {
			resultWriter.write("NO");
		}
		// readThroughScanner(inputs);

		if (inputs.size() == 2) {
			// if all the intervals between successive signals are equal
			try {
				int noOfDays = Integer.parseInt(inputs.get(0));
				String signal = inputs.get(1);
				if (signal.length() != noOfDays) {
					resultWriter.write("NO");
				} else {
					int count = 0;
					
					int prevPosition = 0;
					int distance = 0;
					for (int i = 0; i < signal.length(); i++) {
						if (signal.charAt(i) == '1') {
							count++;
							
							if (count > 1) {
								if (count == 2) {
									distance = i - prevPosition;
								} else {
								
									if (distance != (i - prevPosition)) {
										System.out.println(" previous distance " + distance + " now " + (i - prevPosition));
										resultWriter.write("NO");
										isResultWritten = true;
										break;
									} 
								}
							}
							prevPosition = i;
						} 
					}
					if (!isResultWritten) {
						resultWriter.write("YES");
					} 
					else if (count < 3 && !isResultWritten) {
						// if there less than 3 1
						resultWriter.write("NO");
					}
				}
			} catch (NumberFormatException nfe) {
				resultWriter.write("NO");
			}
		} else {
			resultWriter.write("NO");
		}
		resultWriter.flush();
		resultWriter.close();
		// System.out.println("Time taken :" + (System.currentTimeMillis() -
		// startTime) + " ms");
	}

	private static void readInputData(ArrayList<String> inputs)
			throws Exception {
		LineNumberReader fis = null;
		try {
			fis = new LineNumberReader(new FileReader("input.txt"));
			String eachLine = null;
			while ((eachLine = fis.readLine()) != null) {
				inputs.add(eachLine);
			}

		} catch (FileNotFoundException e) {
			throw e;
		} finally {
			if (fis != null) {
				fis.close();
			}
		}

	}

	private static void readThroughScanner(ArrayList<String> inputs) {
		// To read input from the console
		Scanner scanner = new Scanner(System.in);

		String eachInput = null;
		while ((eachInput = scanner.nextLine()) != null) {
			if (eachInput.trim().length() != 0) {
				inputs.add(eachInput);
				if (inputs.size() == 2) {
					break;
				}
			} else {
				break;
			}
		}
		scanner.close();
	}

	private static void readThroughBuffer(ArrayList<String> inputs) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String s = null;
		try {
			while ((s = br.readLine()) != null) {
				if (s.trim().length() > 0) {
					inputs.add(s);
				} else {
					break;
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
