A. The Artful Expedient

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Rock... Paper!

After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.

A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1, x2, ..., xnand y1, y2, ..., yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.

Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value xi xor yj equals to one of the 2n integers. Here xormeans the bitwise exclusive or operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.

Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.

The second line contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.

The third line contains n space-separated integers y1, y2, ..., yn (1 ≤ yi ≤ 2·106) — the integers finally chosen by Karen.

Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: xi = yji ≠ j and xi = xji ≠ j and yi = yj.

Output

Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.

Examples
input
3
1 2 3
4 5 6
output
Karen
input
5
2 4 6 8 10
9 7 5 3 1
output
Karen
Note

In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.

In the second example, there are 16 such pairs, and Karen wins again.

简单的模拟题;

AC代码:

 #include<cstdio>
#include<map>
using namespace std;
int n,num[][];
map<int,int> vis;
int main()
{
scanf("%d",&n);
for(int r=;r<;r++) for(int i=;i<=n;i++) {scanf("%d",&num[r][i]);vis[num[r][i]]=;}
int pair=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(vis.count(num[][i]^num[][j])) pair++;
}
}
if(pair%) printf("Koyomi\n");
else printf("Karen\n");
}

B. The Eternal Immortality

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Even if the world is full of counterfeits, I still regard it as wonderful.

Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.

The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.

Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Examples
input
2 4
output
2
input
0 10
output
0
input
107 109
output
2
Note

In the first example, the last digit of  is 2;

In the second example, the last digit of  is 0;

In the third example, the last digit of  is 2.

简单模拟题,稍微做一些特别的处理即可;

AC代码:

 #include<iostream>
using namespace std;
typedef unsigned long long LLU;
LLU n,m;
int main()
{
cin>>n>>m;
int ans=;
for(LLU i=m;i>n;i--)
{
ans*=i%;
ans%=;
if(ans==) break;
}
cout<<ans;
}

C. The Intriguing Obsession

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

— This is not playing but duty as allies of justice, Nii-chan!

— Not allies but justice itself, Onii-chan!

With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!

There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of ab and c distinct islands respectively.

Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.

The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.

Input

The first and only line of input contains three space-separated integers ab and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.

Output

Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.

Examples
input
1 1 1
output
8
input
1 2 2
output
63
input
1 3 5
output
3264
input
6 2 9
output
813023575
Note

In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.

In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.

题意:

有三堆群岛,分别用不同颜色标记,现在在岛间建桥,桥长度均为1,限制条件:同颜色的岛间距离不小于3或者没有连接,求有多少种建桥方案(结果对998244353取模)。

题解:

对于两堆岛,假设岛堆1有m个岛,岛堆2有n个岛,且满足m<=n,则不难得到两个两堆岛间建立桥的方案数:

$f(m,n)=\sum_{i=0}^{m}C_{m}^{i}A_{n}^{i}=\sum_{i=0}^{m}C_{m}^{i}C_{n}^{i}i!$

关于如何求组合数C(n,m):http://www.cnblogs.com/xienaoban/p/6798058.html

因为我们看到,a,b,c最大不超过5000,所以可以用迭代的方式求组合数和阶乘;

最后根据公式计算出答案即可;

 #include<cstdio>
#include<algorithm>
#define MAX 5003
#define MOD 998244353
using namespace std;
typedef long long ll;
ll C[MAX][MAX],fac[MAX];
void calc_Cmn()//求组合数
{
for(int i=;i<MAX;i++)
{
C[i][]=C[i][i]=;
for(int j=;j<i;j++) C[i][j]=(C[i-][j-]+C[i-][j])%MOD;
}
}
void calc_factorial()//求阶乘
{
fac[]=fac[]=;
for(int i=;i<MAX;i++) fac[i]=(fac[i-]*i)%MOD;
}
ll f(int m,int n)
{
ll ret=;
for(int i=;i<=m;i++)
{
ret+=(((C[m][i]*C[n][i])%MOD)*fac[i])%MOD;
ret=ret%MOD;
}
return ret;
}
int main()
{
calc_Cmn();
calc_factorial();
int x,y,z,m,n;
scanf("%d%d%d",&x,&y,&z); m=min(x,y), n=max(x,y);
ll ans1=f(m,n);
m=min(x,z), n=max(x,z);
ll ans2=f(m,n);
m=min(y,z), n=max(y,z);
ll ans3=f(m,n); printf("%I64d\n",(((ans1*ans2)%MOD)*ans3)%MOD);
}

PS.里面包含了求组合数和阶乘的算法模板

codeforces 869A/B/C的更多相关文章

  1. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  2. codeforces 869A The Artful Expedient【暴力枚举/亦或性质】

    A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...

  3. CodeForces - 869A The Artful Expedient

    题意:有两个序列X和Y,各含n个数,这2n个数互不相同,若满足xi^yj的结果在序列X内或序列Y内的(xi,yj)对数为偶数,则输出"Karen",否则输出"Koyomi ...

  4. codeforces 869A

    A. The Artful Expedient time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. layui文件上传进度条(模拟)

    1.修改上传组件js(没测) https://blog.csdn.net/weixin_42457316/article/details/81017471 https://www.cnblogs.co ...

  2. Java适配器模式的简单应用

    对于刚从工厂生产出来的商品,有些功能并不能完全满足用户的需要.因此,用户通常会对其进行一定的改装工作.编写程序为普通的汽车增加GPS定位功能,借此演示适配器模式的用法. 思路分析: 这个问题的需求是, ...

  3. python关键字与标识符

    编程语言众多,但每种语言都有相应的关键字,Python 也不例外,它自带了一个 keyword 模块,用于检测关键字. 关键字列表 进入 Python 交互模式,获取关键字列表: >>&g ...

  4. AESDK开发之UI消息响应

    UI创建: 在该入口下 case PF_Cmd_PARAMS_SETUP: //.... break; 必须在末尾指定UI数目,UI数目一般是枚举,如果和枚举长度不一致也会报错.所以最好是直接修改枚举 ...

  5. 转:ANDROID音频系统散记之四:4.0音频系统HAL初探

    昨天(2011-11-15)发布了Android4.0的源码,今天download下来,开始挺进4.0时代.简单看了一下,发现音频系统方面与2.3的有较多地方不同,下面逐一描述. 一.代码模块位置 1 ...

  6. PowerDesigner 同步Name到Comment 及 同步 Comment 到Name

    PowerDesigner中使用方法为:     PowerDesigner->Tools->Execute Commands->Edit/Run Scripts 代码一:将Name ...

  7. C++ 输入输出流 文本文件 二进制文件读写

    文本文件/ASCII文件(能直接显示内容,费存储空间):文件中每一个字节中均以ASCII代码形式存放数据,即一个字节存放一个字符,这个文件就是ASCII文件或称字符文件. 二进制文件(不能显示内容,节 ...

  8. 使用 webpack 优化资源

    在前端应用的优化中,对加载资源的大小控制极其的重要,大多数时候我们能做的是在打包编译的过程对资源进行大小控制.拆分与复用.本片文章中主要是基于 webpack 打包,以 React.vue 等生态开发 ...

  9. [原]Linux下清空文件内容的三种方法

    ========问题======== 有些文件需要清空内容而不改变属性 =======解决方案====== 1.直接删除,创建同名文件.(这种方法的弊端是有可能这个文件带着权限或者是属性,那么你新建这 ...

  10. 记录一次OOM排查经历(一)

    一.经历概要 程序里有个跑数据的job,这个job的主要功能是往数据库写假数据. 既需要跑历史数据(传给job的日期是过去的时间),也需要能够上线后,实时跑(十秒钟触发一次,传入触发时的当前时间). ...