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. 使用srvany.exe把程序安装成windows服务的方法

    http://mazhihui.iteye.com/blog/1294431 srvany.exe是什么? srvany.exe是Microsoft Windows Resource Kits工具集的 ...

  2. 第四章 TCP粘包/拆包问题的解决之道---4.1---

    4.1 TCP粘包/拆包 TCP是一个“流”协议,所谓流,就是没有界限的一串数据.TCP底层并不了解上层业务数据的具体含义,它会根据TCP缓冲区的实际情况进行包的划分,所以在业务上认为,一个完整的包可 ...

  3. windows防火墙设置端口开放技巧

    选择“打开或者关闭windows防火墙”把防火墙打开,然后选择“高级设置”,选择“创建规则”来指定端口.(这里也可以在“入站规则”里选择已经存在的端口.) 指定ip开放3389端口 某新服务器,开放8 ...

  4. Nginx(六)-- 配置文件之Gzip

    1.概念及作用 Gizp主要对内容.静态文件做压缩,用来提升网站访问速度,节省带宽. 2.使用方法 gzip既可以配置在server中,也可以配置在server外,此处配置在server中,如下:   ...

  5. Redis 操作哈希数据

    通常我们将一些结构化的信息打包成哈希映射表,结构如下,key/value 键值对模式不变,但 value 是一个键值对 name: "Tom" age: ...... > h ...

  6. WEB-DICT词库计划

    欢迎大家支持晓阳童鞋的词库计划,建立一个庞大的中文词库 地址如下:http://webdict.info/ 什么是WEB-DICT词库计划? WEB-DICT词表计划目标是通过机器学习算法以及人工标注 ...

  7. Android应用的自动升级、更新模块的实现(转)

    我们看到很多Android应用都具有自动更新功能,用户一键就可以完成软件的升级更新.得益于Android系统的软件包管理和安装机制,这一功能实现起来相当简单,下面我们就来实践一下.首先给出界面效果: ...

  8. KMP算法的实现(Java语言描述)

    标签:it KMP算法是模式匹配专用算法. 它是在已知模式串的next或nextval数组的基础上执行的.如果不知道它们二者之一,就没法使用KMP算法,因此我们需要计算它们. KMP算法由两部分组成: ...

  9. 使用gdb调试theos tweak插件

    查看设备日志tail -f /var/log/syslog或者 Mobilesubstrate injects your dylib into the target process. Debuggin ...

  10. [转]了解如何通过reverse_iterator的base得到iterator

    转自:http://blog.csdn.net/shuchao/article/details/3705252 调用reverse_iterator的base成员函数可以产生“对应的”iterator ...