天天看點

Codeforces Round #585 (Div. 2) D. Ticket Game

Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n

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 n2

digits of this ticket is equal to the sum of the last n2

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 0

to 9

. 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.

Input

The first line contains one even integer n

(2≤n≤2⋅105)

— the number of digits in the ticket.

The second line contains a string of n

digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i

-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.

Output

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

Examples

Input

Copy

4
0523
      

Output

Copy

Bicarp
      

Input

Copy

2
??
      

Output

Copy

Bicarp
      

Input

Copy

8
?054??0?
      

Output

Copy

Bicarp
      

Input

Copy

6
???00?
      

Output

Copy

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.

題意:一個字元串由數字和?組成,兩個人輪流把問号換成0-9的數字,如果最後前一半數字和不等于後一半數字和,那麼Monocarp赢,否則Bicarp赢

思路:前面和後面的?兩兩配對,配對的都變成相同數字,剩下的?在的那邊如果數字和也大于另一邊,那麼Monocarp赢,否則

看?兩兩和變成9(如果?剩奇數個,Monocarp赢)後是否前面等于後面,是的話 Bicarp赢,否則Monocarp赢;

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define mod 1000000007
#define maxn 205000
char a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",a+1);
    int x1=0,x2=0,y1=0,y2=0;
    for(int i=1;i<=n/2;i++)
    {
        if(a[i]=='?') x2++;
        else x1+=a[i]-'0';
    }
    for(int i=n/2+1;i<=n;i++)
    {
        if(a[i]=='?') y2++;
        else y1+=a[i]-'0';
    }
    //printf("x1=%d y1=%d x2=%d y2=%d\n",x1,y1,x2,y2);
    if(x1==y1)
    {
        if(x2==y2) printf("Bicarp\n");
        else printf("Monocarp\n");
    }
    else if((x1>y1&&x2>=y2)||(x1<y1&&x2<=y2))
    {
        printf("Monocarp\n");
    }
    else if((x1>y1&&x2<y2)||(x1<y1&&x2>y2))
    {
        int x=abs(x1-y1),y=abs(x2-y2);
        if(x%9==0&&x/9==(y+1)/2)
        {
            printf("Bicarp\n");
        }
        else printf("Monocarp\n");
    }
}