After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.

Rules of this game are simple: each player bring his favourite n-digit credit card. Then both players name the digits written on their cards one by one. If two digits are not equal, then the player, whose digit is smaller gets a flick (knock in the forehead usually made with a forefinger) from the other player. For example, if n = 3, Sherlock's card is 123 and Moriarty's card has number 321, first Sherlock names 1and Moriarty names 3 so Sherlock gets a flick. Then they both digit 2 so no one gets a flick. Finally, Sherlock names 3, while Moriarty names 1 and gets a flick.

Of course, Sherlock will play honestly naming digits one by one in the order they are given, while Moriary, as a true villain, plans to cheat. He is going to name his digits in some other order (however, he is not going to change the overall number of occurences of each digit). For example, in case above Moriarty could name 1, 2, 3and get no flicks at all, or he can name 2, 3 and 1 to give Sherlock two flicks.

Your goal is to find out the minimum possible number of flicks Moriarty will get (no one likes flicks) and the maximum possible number of flicks Sherlock can get from Moriarty. Note, that these two goals are different and the optimal result may be obtained by using different strategies.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of digits in the cards Sherlock and Moriarty are going to use.

The second line contains n digits — Sherlock's credit card number.

The third line contains n digits — Moriarty's credit card number.

Output

First print the minimum possible number of flicks Moriarty will get. Then print the maximum possible number of flicks that Sherlock can get from Moriarty.

Examples

Input

3
123
321

Output

0
2

Input

2
88
00

Output

2
0

Note

First sample is elaborated in the problem statement. In the second sample, there is no way Moriarty can avoid getting two flicks.

思路:两个进行排序,然后看自己的去比别人的大,如果M不挨打,那他一定要大于等于另一个,都要从小的遍历 ,然后标记,不然下次还会比,另一个打的最多也差不多的思路

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<cmath> typedef long long ll;
using namespace std; char a[1005]; char b[1005]; int s1[1005];
int s2[1005]; int vis[1005];
int main() {
int n;
cin>>n;
scanf("%s",a);
scanf("%s",b); for(int t=0; t<n; t++) {
s1[t]=a[t]-'0';
s2[t]=b[t]-'0';
}
sort(s1,s1+n);
sort(s2,s2+n);
int s=n;
for(int t=0; t<n; t++) {
for(int j=0; j<n; j++) {
if(s2[t]>=s1[j]&&vis[j]==0) {
s--;
vis[j]=1;
break;
}
} }
memset(vis,0,sizeof(vis));
int ss=0;
int k=0;
for(int t=0; t<n; t++) {
for(int j=0; j<n; j++) { if(s2[t]>s1[j]&&vis[j]==0) {
ss++;
vis[j]=1;
break;
}
}
} cout<<s<<endl;
cout<<ss<<endl; return 0;
}

Game of Credit Cards(贪心+思维)的更多相关文章

  1. codeforces 893D Credit Card 贪心 思维

    codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...

  2. CodeForces - 777B Game of Credit Cards 贪心

    题目链接: http://codeforces.com/problemset/problem/777/B 题目大意: A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并 ...

  3. Codeforces 777B:Game of Credit Cards(贪心)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  4. code force 401B. Game of Credit Cards

    B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. Codeforces 777B Game of Credit Cards

    B. Game of Credit Cards time limit per test:2 seconds memory limit per test:256 megabytes input:stan ...

  6. Codeforces777B Game of Credit Cards 2017-05-04 17:19 29人阅读 评论(0) 收藏

    B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

  8. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  9. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

随机推荐

  1. SqlServer—大话函数依赖与范式

    说明:数据库中的某些概念真的很让人头疼,概念的东西本来就是很枯燥的,再加上枯燥的学习,那就更加枯燥了.概念这东西,你不理解也能生产东西,经验多了就行,但是为了更深入的学习,你还必须理解.这里,我抛开书 ...

  2. IDEA+DevTools实现热部署功能

      开发IDE: Intellij IDEA 2018.1 SpringBoot:1.5.9.RELEASE 热部署 大家都知道在项目开发过程中,常常会改动页面数据或者修改数据结构,为了显示改动效果, ...

  3. PHP解决跨域访问的问题

    在控制器的第一行放如下代码即可解决 header('Access-Control-Allow-Origin: http://ding.taozugong.com'); header('Access-C ...

  4. LightOJ 1079 Just another Robbery (01背包)

    题意:给定一个人抢劫每个银行的被抓的概率和该银行的钱数,问你在他在不被抓的情况下,能抢劫的最多数量. 析:01背包,用钱数作背包容量,dp[j] = max(dp[j], dp[j-a[i] * (1 ...

  5. MongoDB整理笔记の安全访问

    MongoDB安全访问将从以下三个方面得到控制!   1.绑定IP内网地址访问MongoDB服务     2.设置监听端口     3.使用用户名和密码 绑定IP内网地址访问MongoDB服务 Mon ...

  6. maven的pom文件解析及配置

    1.IDEA中的Maven的pom.xml文件,其实比较通俗点介绍功能主要项目引入的jar包,管理配置项目以及一些插件的配置等项目 2.对于pom配置详细介绍,整理如下2篇文档介绍的比较系统全面: h ...

  7. SignalR 跨域解决方案全面

    SignalR 分:PersistentConnection和Hub 2种模式. 跨域又分:UseCors和JsonP  2种方法 所以例子写了4种. 核心代码: UseCors //Persiste ...

  8. js工具库简单介绍

    javascript mvc的解决方案: angularjs, backbone,underscore, 有空的时候了解一下. 移动端的几个需要了解一下,jq mobile, zepto.knocko ...

  9. android studio中使用recyclerview制作个显示考勤打卡的日历来

    1. 用户在app端选择个日期就能查询这个月的考勤打卡信息,并以日历上标注不同的颜色来显示给用户,当然这个日历是recyclerview做出来的,只是每行显示7个,表示一周的七天. 2. 员工考勤打卡 ...

  10. C#Thread学习

    一.Thread的使用方式 1.不带参数 (1)使用lambda public static void fun1() { Console.WriteLine($"Main ThreadId: ...