Codeforces Round #439

本文解析了三项算法挑战赛题目,包括艺术策略、永恒不朽与迷人的执着,涵盖位运算、数学技巧及组合计数等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 by x1, x2, ..., xn andy1, y2, ..., yn respectively. They reveal their sequences, and repeat untilall 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 valuexixor yj equals to one of the2n integers. Here xor 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 and xi = xj;i ≠ 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 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 every a! 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 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 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 long
using 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 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 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 integers a, b 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, 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 long
using 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值