Codeforces Round #439

来源:互联网 发布:网络信息工作领导小组 编辑:程序博客网 时间:2024/06/05 06:04
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 choosen distinct positive integers, denoted byx1, x2, ..., xn andy1, y2, ..., yn respectively. They reveal their sequences, and repeat untilall of2n 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 valuexixoryj equals to one of the2n integers. Herexor means 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 integern (1 ≤ n ≤ 2 000) — the length of both sequences.

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

The third line contains n space-separated integersy1, 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 = yj;i ≠ j andxi = xj;i ≠ j andyi = 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
31 2 34 5 6
Output
Karen
Input
52 4 6 8 109 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 since6 is an even number.

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


题目大意:给出两个长度为 n 的数组 a、b,从 a、b 中各选一个元素 ai,bj,问使得 ai xor bj 的结果属于 a、b 中的 2n 个数的 ( i , j ) 的对数。

直接暴力。。。数据范围不大,用数组哈希就行,一开始用的 map 结果T了。。。

代码:

#include<cstdio>#include<algorithm>#include<map>#include<cstring>using namespace std;map<int,bool> m;const int maxn1 = 2e3 + 5;const int maxn2 = 3 * 1e6 + 5;int a[maxn1],b[maxn1];bool c[maxn2];int main(){    memset(c,false,sizeof(c));    int n;    scanf("%d",&n);    for(int i = 0;i < n; ++i) scanf("%d",&a[i]),c[a[i]] = true;    for(int i = 0;i < n; ++i) scanf("%d",&b[i]),c[b[i]] = true;    int ans = 0;    for(int i = 0;i < n; ++i)    {        for(int j = 0;j < n; ++j)        {            if(c[a[i] ^ b[j]]) ++ans;        }    }    printf("%s\n",ans & 1 ? "Koyomi" : "Karen");    return 0;}

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 everya! years. Here a! denotes the factorial of integera, 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 ofb! years, that is, . Note that whenb ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to knowthe 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 integersa 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 is2;

In the second example, the last digit of is0;

In the third example, the last digit of is2.


题目大意:求 b! / a! 的个位数字。由于 b 可以很大,所以直接暴力是行不通的。这里我们可以观察一下,发现只要  b-a >= 10,最后计算的时候所有参与乘法的数的个位数字都在 0 ~ 9 中循环,而且只要个位数字中有 0,或者2、5,4、5 这样相乘后结果中有 0 的,结果的个位数字就恒为 0 了。所以我们最多只需要算十个数甚至更少(懒得推了按十次算的),就可以得到正确答案。
代码:
#include<cstdio>#define ll long longusing namespace std;int main(){    ll a,b,c,temp = 1;    scanf("%I64d %I64d",&a,&b);    for(ll i = b,j = 0;j < 10 && i > a; --i,++j)    {        c = i % 10;        temp = temp * c % 10;    }    printf("%I64d\n",temp);    return 0;}

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 ofa,b andc 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 length1. 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 isat least3, 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 modulo998 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 integersa, b andc (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, modulo998 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 is23 = 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.


题目大意:有三种颜色的岛屿,需要在他们之间修一些桥,修的时候需要满足同一颜色的不能直接连接,任意两个岛屿的最短距离不得小于 3 (每个桥的长度为 1 )。
其实条件转化一下很简单,只要同一颜色的不互连,同一颜色的任意两个不连接到同一个其他岛屿即可。结果就是任意两种颜色(总共 C(3,2) = 3 种组合)连接方法数的乘积。
假设 a,b 为两种颜色的岛屿数,b 为个数较少的一个,则 a,b 之间连接的方法数为:
C(b,1)*a + C(b,2)*a*(a-1) + C(b,3)*a*(a-1)*(a-2)…+C(b,b)*a*(a-1)*...*(a-b+1)
由于组合数的结果很大而且算的次数很多,这里用Lucas定理计算组合数。
代码:
#include<cstdio>#include<cstring>#include<algorithm>#define ll long longusing namespace std;const ll mod = 998244353;ll a[3];ll Fastpow(ll a,ll b){    ll ans = 1;    while(b > 0)    {        if(b & 1) ans = (ans * a) % mod;        b >>= 1;        a = (a * a) % mod;    }    return ans;}ll Getc(ll a,ll b){    if(a < b) return 0;    if(b > a - b) b = a - b;    ll s1 = 1,s2 = 1;    for(ll i = 0;i < b; ++i)    {        s1 = s1 * (a - i) % mod;        s2 = s2 * (i + 1) % mod;    }    return s1 * Fastpow(s2,mod - 2) % mod;}ll Lucas(ll n,ll k){    if(k == 0) return 1;    return Getc(n % mod,k % mod) * Lucas(n / mod,k / mod) % mod;}ll cal(ll y,ll x){    ll ans = 0,t1 = 1,t2 = 1;    for(ll i = x,j = 1;i > x - y; --i,++j)    {        t2 = t2 * i % mod;        t1 = t2 * Lucas(y,j);        ans = (ans + t1) % mod;    }    return ans + 1;}int main(){    for(int i = 0;i < 3; ++i) scanf("%I64d",&a[i]);    sort(a,a + 3);    ll ans = 1;    ans = (ans * cal(a[0],a[1])) % mod;    ans = (ans * cal(a[0],a[2])) % mod;    ans = (ans * cal(a[1],a[2])) % mod;    printf("%I64d\n",ans);    return 0;}

原创粉丝点击