CF1215D Ticket Game 博弈论

题目

Monocarp and Bicarp live in Berland, where every bus ticket consists of nn digits (nn is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.

Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n2n2 digits of this ticket is equal to the sum of the last n2n2 digits.

Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 00 to 99. The game ends when there are no erased digits in the ticket.

If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.

输入

The first line contains one even integer nn (2≤n≤2⋅105)(2≤n≤2⋅105) — the number of digits in the ticket.

The second line contains a string of nn digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the ii-th character is "?", then the ii-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.

输出

If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).

Examples

Input

4
0523

Output

Bicarp

Input

2
??

Output

Bicarp

Input

8
?054??0?

Output

Bicarp

Input

6
???00?

Output

Monocarp

Note

Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.

In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.

大意

一张票有n位数,如果这张票的前一半数字的和等于后一半数字的和(n一定是偶数),就称这张票为快乐票。有些数被擦除了,标记为’?’(’?‘的个数也是偶数),现在Monocarp 和 Bicarp 进行一个游戏,两人轮流将’?'变换成0到9的任意一个数,Monocarp先手,如果最后票为快乐票则Bicarp赢,否则Monocarp赢。

分析

这是一道博弈论的题,需要分情况。

假设左半部分有a个?,数的和为x,右半部分有b个?,数的和为y

(一)如果x==y

​ ①a $=$b,每次M填一个数,B都能填一个一样的,B赢。

​ ②a>b,当两边都填了b个数的时候,只能在一边填(a-b)个数,显然两边不等,M赢

​ ③a<b, 交换一下ab和xy就和②一样了

(二)如果x>y (x<y的时候也交换一下)

​ ①a$\geq$b, M每次在左边放9,N每次在右边放9,但是右边先填满,两边不等,M赢

​ ②a$<$b,在前2a个回合,会将左边的数填满,右边还剩b-a个数。剩下的回合,M放一个数p,B放一个数q,使p+q=9,如果$\frac{b-a}{2}*9=x-y$ 并且b-a是2的倍数,恰好使两边相等,B赢,否则M赢

猜你喜欢

转载自www.cnblogs.com/ghosh/p/12765064.html