题目

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

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赢。

分析

分情况讨论:假设所有的数左半部分和为sum1,右边为sum2 左边有n个?,右边有m个

①sum1==sum2:
当m不等于n时,先手一定赢。反之则后者赢。
②假如sum1>sum2
(1)n>=m时,先手可以在一边一直放9,后手弥补不了差距。先手必胜。 (2)n<m时,前2n次同上,剩下的次数中,先手放sum1时,后手只能是放sum2来使得sum1+sum2=9;所以当9|sum1-sum2时后手胜。不然的话后手是必输的。

代码

 #include <bits/stdc++.h>
using namespace std; const int maxn=2e5+;
int n;
char s[maxn];
int ls, rs, x, y; int main(){
scanf("%d",&n);
scanf("%s",s+);
for(int i=;i<=n/;i++){
if(s[i]=='?')x++;
else ls+=s[i]-'';
}
for(int i=n/+;i<=n;i++){
if(s[i]=='?')y++;
else rs+=s[i]-'';
}
if(ls<rs){
swap(ls, rs); swap(x, y);
}
if(ls==rs){
printf("%s\n", x==y? "Bicarp":"Monocarp");
}
else{
if(x>=y) printf("Monocarp\n");
else printf("%s\n", (y-x)%== && ls-rs==(y-x)/*? "Bicarp":"Monocarp");
}
return ;
}

Ticket Game【博弈】的更多相关文章

  1. Codeforces Round #585 (Div. 2)

    https://www.cnblogs.com/31415926535x/p/11553164.html 感觉很硬核啊这场,,越往后越做不动,,,emmmm,,,(这场是奔着最后一题 2sat 来的, ...

  2. CF1215D Ticket Game(思维,博弈)

    题目 传送门:https://www.luogu.com.cn/problem/CF1215D Idea 一列数,保证能分成左右两部分,其中有若干个数字被抹掉,两个人轮流填数,如果在把这些空缺的数字填 ...

  3. Ticket Game CodeForces - 1215D 博弈题

    题目描述 Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even ...

  4. hdu----(1849)Rabbit and Grass(简单的尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  6. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  7. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  8. [Kerberos] User Ticket Management

    Kerberos客户端常用命令包括 kinit, klist, kdestroy, and kpasswd,用户使用这些命令管理自己的 ticket. 此外,每台运行Kerberos的机器应该都配置/ ...

  9. 51nod1072(wythoff 博弈)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1072 题意: 中文题诶~ 思路: 博弈套路是有的, 找np局 ...

随机推荐

  1. Java实现 蓝桥杯VIP 算法训练 明明的随机数

    问题描述 明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应 ...

  2. Java实现 蓝桥杯VIP 算法提高 项链

    算法提高 项链 时间限制:1.0s 内存限制:512.0MB 问题描述 由 n(1≤n≤100) 个珠子组成的一个项链,珠子有红.蓝.白三种颜色,各种颜色的珠子的安排顺序由键盘输入的字符串任意给定.蓝 ...

  3. java实现土地测量

    ** 土地测量** 造成高房价的原因有许多,比如土地出让价格.既然地价高,土地的面积必须仔细计算.遗憾的是,有些地块的形状不规则,比如是如图[1.jpg]中所示的五边形. 一般需要把它划分为多个三角形 ...

  4. js数据劫持 Object.defineProperty() 作用

    原生js Object.defineProperty() 作用 假设我们有一个obj对象,我们要给他设置一个name属性会这么做 Object.defineProperty()也可以设置对象属性 这个 ...

  5. Tomcat线程模型分析及源码解读

    1 四种线程模型  配置方法:在tomcat conf 下找到server.xml,在<Connector port="8080" protocol="HTTP/1 ...

  6. 一篇关于Android M以后权限介绍的不错的文章

    文章地址:http://www.jianshu.com/p/e1ab1a179fbb/

  7. 区分http请求状态码来理解缓存(协商缓存和强制缓存)

    什么是http缓存呢,当我们使用chrome浏览器,按F12打开控制台,在网络请求中有时候看到状态码是200,有时候状态码是304,当我们去看这种请求的时候,我们会发现状态码为304的状态结果是:St ...

  8. kernel list 实践

    list.h /******* 链表实现,来自内核 **************************************************/ /** * container_of - c ...

  9. 如何设置body内容不能复制?

    通过在body标签上设置相关的属性: <body oncontextmenu="return false" ondragstart="return false&qu ...

  10. @atcoder - AGC003F@ Fraction of Fractal

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 H*W 黑白格图,保证黑格四连通. 定义分形如下:0 ...