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 n/2 digits of this ticket is equal to the sum of the last n/2 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).
4
0523
Bicarp
2
??
Bicarp
8
?054??0?
Bicarp
6
???00?
Monocarp
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int main()
{
int n,x1=0,y1=0,x2=0,y2=0,x,y;
char s[200005];
scanf("%d",&n);
scanf("%s",s);
for(int i=0;i<n/2;i++)
{
// printf("%c",s[i]);
if(s[i]=='?') x1++;
else y1+=(s[i]-'0');
}
for(int i=n/2;i<n;i++)
{
// printf("%c",s[i]);
if(s[i]=='?') x2++;
else y2+=(s[i]-'0');
}
// printf("%d %d %d %d\n",x1,x2,y1,y2);
if(x1==x2&&y1==y2) printf("Bicarp\n");
else if(y1==y2) printf("Monocarp\n");
else if((x1>x2&&y1>=y2)||(x1<x2&&y1<=y2)) printf("Monocarp\n");
else
{
x=abs(x2-x1);
y=abs(y2-y1);
if(y%9==0&&y/9==(x+1)/2) printf("Bicarp\n");
else printf("Monocarp\n");
}
return 0;
}