1. 程式人生 > >【題解】codeforces549C[AHSOFNU codeforces訓練賽1 by hzwer]A.The Game Of Parity 博弈論

【題解】codeforces549C[AHSOFNU codeforces訓練賽1 by hzwer]A.The Game Of Parity 博弈論

Description

There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly k cities left.

The prophecy says that if the total number of surviving residents is even, then Daenerys wins: Stannis gets beheaded, and Daenerys rises on the Iron Throne. If the total number of surviving residents is odd, Stannis wins and everything goes in the completely opposite way.

Lord Petyr Baelish wants to know which candidates to the throne he should support, and therefore he wonders, which one of them has a winning strategy. Answer to this question of Lord Baelish and maybe you will become the next Lord of Harrenholl.

Input

The first line contains two positive space-separated integers, n and k (1 ≤ k ≤ n ≤ 2·105) — the initial number of cities in Westeros and the number of cities at which the game ends.

The second line contains n space-separated positive integers ai (1 ≤ ai ≤ 106), which represent the population of each city in Westeros.

Output

Print string “Daenerys” (without the quotes), if Daenerys wins and “Stannis” (without the quotes), if Stannis wins.

Examples

Input

3 1 1 2 1

Output

Stannis

Input

3 1 2 2 1

Output

Daenerys

Input

6 3 5 20 12 7 14 101

Output

Stannis

Note

In the first sample Stannis will use his move to burn a city with two people and Daenerys will be forced to burn a city with one resident. The only survivor city will have one resident left, that is, the total sum is odd, and thus Stannis wins.

In the second sample, if Stannis burns a city with two people, Daenerys burns the city with one resident, or vice versa. In any case, the last remaining city will be inhabited by two people, that is, the total sum is even, and hence Daenerys wins.

博弈論。分幾類討論: 1.如果一方可以把奇數拿光,那麼Daenerys贏了; 2.如果一方可以把偶數拿光,如果k是奇數則Stannis贏了,否則Daenerys贏了; 3.雙方都不能拿空奇或偶,那麼最後行動的人就可以選擇奇或偶,一定贏。

#include<cstdio>
int n,k,a,odd,even;
int main()
{
	//freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a);
    	if(a&1)odd++;
    	else even++;
	}
	if(n==k)
	{
		if(odd&1)puts("Stannis");
		else puts("Daenerys");
		return 0;
	}
	int step=n-k;
	if(step/2>=odd)return puts("Daenerys"),0;//最後只剩偶數 
	if(step/2>=even)//最後只剩奇數 
	{
		if(k&1)puts("Stannis");
		else puts("Daenerys");
		return 0;
	}
	//奇偶都有,誰最後走誰贏 
	if(step&1)return puts("Stannis"),0;
	return puts("Daenerys"),0;
}

總結

分類討論