8 1 个人赛 to me

E

Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.

A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.

In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

Input

The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers.

The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

Output

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print each letter in arbitrary case (small or large).

Examples

Input

4
31 31 30 31

Output

Yes

Input

2
30 30

Output

No

Input

5
29 31 30 31 30

Output

Yes

Input

3
31 28 30

Output

No

Input

3
31 31 28

Output

Yes

Note

In the first example the integers can denote months July, August, September and October.

In the second example the answer is no, because there are no two consecutive months each having 30 days.

In the third example the months are: February (leap year) — March — April – May — June.

In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.

In the fifth example the months are: December — January — February (non-leap year).

 一个很笨的方法

//注意判断不能出现两个29的情况  即两个闰年
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const ll M=1e6;
deque <ll> dq;
queue <ll> q;
//map <ll,ll> m;
ll a[51000];
ll yue1[24]= {31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31};
ll yue2[24]= {31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31};
ll yue3[24]= {31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
    ll n,i,j,e=0,ans;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<23;i++)
    {
        ans=0;e=i;
        for(j=0;j<5100;j++)
        {
            if(ans>=n)
            {
                printf("Yes\n");
                return 0;
            }
            if(yue1[i]==a[j])
            {
                ans++;
                i++;
            }
            else
            {
                ans=0;
                i=e;
                break;
            }

        }
    }
    for(i=0;i<23;i++)
    {
        ans=0;e=i;
        for(j=0;j<5100;j++)
        {
            if(ans>=n)
            {
                printf("Yes\n");
                return 0;
            }
            if(yue2[i]==a[j])
            {
                ans++;
                i++;
            }
            else
            {
                ans=0;
                i=e;
                break;
            }

        }
    }
    for(i=0;i<23;i++)
    {
        ans=0;e=i;
        for(j=0;j<5100;j++)
        {
            if(ans>=n)
            {
                printf("Yes\n");
                return 0;
            }
            if(yue3[i]==a[j])
            {
                ans++;
                i++;
            }
            else
            {
                ans=0;
                i=e;
                break;
            }

        }
    }
    printf("No\n");
    return 0;
}

 

 

 B

Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.

Mishka can put a box i into another box j if the following conditions are met:

  • i-th box is not put into another box;
  • j-th box doesn't contain any other boxes;
  • box i is smaller than box j (ai < aj).

Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

Help Mishka to determine the minimum possible number of visible boxes!

Input

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Output

Print the minimum possible number of visible boxes.

Examples

Input

3
1 2 3

Output

1

Input

4
4 2 4 3

Output

2

Note

In the first example it is possible to put box 1 into box 2, and 2 into 3.

In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

题意:大盒子装小盒子 问最少装几个

队列的做法:

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const ll M=1e6;
deque <ll> dq;
queue <ll> q;
ll a[51000],yue[12]= {31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
    ll n,ans,i;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    sort(a,a+n);
    while(!q.empty())
        q.pop();
    for(i=0;i<n;i++)
        q.push(a[i]);
    ll e=0;
    while(!q.empty())
    {
        ll size1=q.size();
        e=0;
        for(i=0;i<size1;i++)
        {
            if(e<q.front())
            {
                e=q.front();
                q.pop();
            }
            else
            {
                ll t=q.front();
                q.pop();
                q.push(t);
            }
        }
        ans++;
    }
    printf("%lld\n",ans);
    return 0;
}

还有一种简单做法

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const ll M=1e6;
deque <ll> dq;
queue <ll> q;
//map <ll> m;
ll a[51000],yue[12]= {31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
    ll n,i;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    sort(a,a+n);
    ll ans=1,maxx=1;

    for(i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
        {
            ans++;
            if(ans>=maxx)
              maxx=ans;
        }
        else
            ans=1;
    }
    printf("%lld\n",maxx);
    return 0;
}

map做法

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
const int MAX=1e4+10;
typedef long long ll;
vector <ll> v[MAX+10];
map <ll,ll> m;
int main()
{
    ll i,n,x,maxx=0;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&x);
        m[x]++;
    }
    map<ll,ll>::iterator iter;
    for(iter=m.begin();iter!=m.end();++iter)
    {
        if(iter->second>maxx)
            maxx=iter->second;
    }
    printf("%lld\n",maxx);
    return 0;
}

A

The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.

You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).

As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".

Input

The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.

Output

Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.

Examples

Input

harry potter

Output

hap

Input

tom riddle

Output

tomr

题意  找出一个按字典序排序 最小的  两个字符串的头是新字符串的头跟尾  往中间插

英语是硬伤啊~~~~~~~~~~~

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const ll M=1e6;
deque <ll> dq;
queue <ll> q;
map <ll,ll> m;
ll a[51000];
char s1[1000010],s2[1000010],s3[1000010],c;
int main()
{
    memset(s1,0,sizeof(s1));
    memset(s2,0,sizeof(s2));
    memset(s3,0,sizeof(s3));
    scanf("%s%s",s1,s2);
    c=s2[0];
    s3[0]=s1[0];
    ll e=1,i;
    for(i=1;s1[i];i++)
    {
        if(s1[i]<c)
            s3[e++]=s1[i];
        else
            break;
    }
    s3[e]=c;
    puts(s3);
    return 0;
}

D - D   CodeForces - 903B

 

Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.

After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.

Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.

The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.

Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.

Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

Input

The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion.

The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.

Output

In the first line print one integer n denoting the minimum number of phases required to win the battle.

Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab.

The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action.

If there are multiple optimal solutions, print any of them.

Examples

Input

10 6 100
17 5

Output

4
STRIKE
HEAL
STRIKE
STRIKE

Input

11 6 100
12 5

Output

2
STRIKE
STRIKE

Note

In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.

In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

题意:vova打怪物  vova拥有h1的能量 a1的攻击力 喝一次~补充c1的能量  怪物有h2的能量 a2的攻击力   每次回合vova可以选择攻击或者补充能量 问最少几次操作vova可以取得胜利  每次操作是什么

注意:当怪物能量<=0时vova取得胜利   注意每次判断补充能量的条件

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
ll ans[1000100];
int main()
{
    ll i,a1,h1,c1,h2,a2,e=0;
    while(~scanf("%lld%lld%lld%lld%lld",&h1,&a1,&c1,&h2,&a2))
    {
        ll anss=0;
        e=0;
        while(h2>0)
        {
            if(h1<=a2&&a1<h2)//补充能量
            {
                h1=h1+c1;
                ans[e++]=1;
                h1=h1-a2;
            }
            else
            {
                h2=h2-a1;
                h1=h1-a2;
                ans[e++]=2;
            }
            anss++;
        }
        printf("%lld\n",anss);
        for(i=0;i<anss;i++)
        {
            if(ans[i]==1)
                printf("HEAL\n");
            else
                printf("STRIKE\n");
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/zcy19990813/p/9702722.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值