import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    if (N % 3 != 0) {
        if (A.map!(a => a == 0).all) {
            writeln("Yes");
        } else {
            writeln("No");
        }
        return;
    }

    long[] count = new long[](3);
    count[] = -1;

    foreach (i, a; A) {
        if (count[i%3] == -1) count[i%3] = a;
        else if (count[i%3] != a) {
            writeln("No");
            return;
        }
    }

    writeln("Yes");
    return;
}