import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val s = nextLine() val t = s + s val dp = Array(2 * n) { Array(2) { Array(2) { false } } } val x0 = if (s[0] == '0') arrayOf(0) else if (s[0] == '1') arrayOf(1) else arrayOf(0, 1) val x1 = if (s[1] == '0') arrayOf(0) else if (s[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