import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val s = nextLine() var t = s + s for (i in 0 until n - 1) { if (s[i] != '?' && s[i + 1] != '?') { val s0 = s.slice(i until n) + s.slice(0 until i) t = s0 + s0 break } } if (s[0] != '?' && s[n - 1] != '?') { val s0 = s[n - 1] + s.slice(0 until n - 1) t = s0 + s0 } val dp = Array(2 * n) { Array(2) { Array(2) { false } } } val x0 = if (t[0] == '0') arrayOf(0) else if (t[0] == '1') arrayOf(1) else arrayOf(0, 1) val x1 = if (t[1] == '0') arrayOf(0) else if (t[1] == '1') arrayOf(1) else arrayOf(0, 1) for (c0 in x0) { for (c1 in x1) { dp[1][c1][c0] = true } } for (i in 2 until 2 * n) { val x = if (t[i] == '0') arrayOf(0) else if (t[i] == '1') arrayOf(1) else arrayOf(0, 1) for (c0 in arrayOf(0, 1)) { for (c1 in arrayOf(0, 1)) { if (dp[i - 1][c1][c0]) { for (c in x) { if (c0 == c1 && c1 == c) { continue } dp[i][c][c1] = true } } } } } val b = dp[2 * n - 1][0][0] || dp[2 * n - 1][0][1] || dp[2 * n - 1][1][0] || dp[2 * n - 1][1][1] println(if (b) "Yes" else "No") } fun main() { Thread(null, { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() }, "solve", abs(1L.shl(26))) .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } } .apply { start() }.join() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion