题目

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实现 蓝桥杯 算法训练 多阶乘计算

    试题 算法训练 多阶乘计算 问题描述 我们知道,阶乘n!表示n*(n-1)(n-2)-21, 类似的,可以定义多阶乘计算,例如:5!!=531,依次可以有n!..!(k个'!',可以简单表示为n(k) ...

  2. Java实现 蓝桥杯VIP 基础练习 高精度加法

    java算法 蓝桥杯 高精度加法 问题描述 在C/C++语言中,整型所能表示的范围一般为-231到231(大约21亿),即使long long型,一般也只能表示到-263到263.要想计算更加规模的数 ...

  3. Java实现 LeetCode 232 用栈实现队列

    232. 用栈实现队列 使用栈实现队列的下列操作: push(x) – 将一个元素放入队列的尾部. pop() – 从队列首部移除元素. peek() – 返回队列首部的元素. empty() – 返 ...

  4. java中ThreadLocal类的详细介绍(详解)

    ThreadLocal简介 变量值的共享可以使用public static的形式,所有线程都使用同一个变量,如果想实现每一个线程都有自己的共享变量该如何实现呢?JDK中的ThreadLocal类正是为 ...

  5. java实现第六届蓝桥杯加法变乘法

    加法变乘法 题目描述 我们都知道:1+2+3+ - + 49 = 1225 现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015 比如: 1+2+3+-+1011+12+-+2728+29+- ...

  6. FTP服务器上传工具,FTP服务器上传工具下载!

    IIS7服务器管理工具能够作为FTP的客户端,进行FTP的命令操作,可在客户端,下载,安装FTP软件! 同时,它也可以作为VNC的客户端,进行VNC的命令操作!它能够批量连接Windows和Linux ...

  7. Android中数据缓存的处理

    为了避免重复操作数据库带来的性能问题,可以将数据库中的数据一次性读入到内存中,这样使得对数据查询的操作变得更加高效,但是这样会带来数据同步的问题,所以需要在每次操作完内存中的数据,同步去操作数据库中的 ...

  8. springMVC 异常

    springMVC  异常 0.依赖(不只是本次案例所需) <?xml version="1.0" encoding="UTF-8"?> <p ...

  9. 0.大话Spring Cloud

    天天说Spring cloud ,那到底它是什么? 定义 它不是云计算解决方案 它是一种微服务开发框架 它是(快速构建分布式系统的通用模式的)工具集 它基于Spring boot 构建开发 它是云原生 ...

  10. JavaScript常用项目(更新至19.11.17)

    目录 项目一:鼠标拖动方块 项目二:网页显示键入字母 项目三:实现滚播图 项目四:   本地数据记事本 项目一:鼠标拖动方块 代码: <!DOCTYPE html> <html> ...