国庆个人赛——NO.1

 1、

A - Turn the Rectangles

There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of rectangles.

Each of the next nn lines contains two integers wiwi and hihi (1≤wi,hi≤1091≤wi,hi≤109) — the width and the height of the ii-th rectangle.

Output

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

Input

3
3 4
4 6
3 5

Output

YES

Input

2
3 4
5 5

Output

NO

Note

In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

In the second test, there is no way the second rectangle will be not higher than the first one.

详解这篇博客

2、

B- Reorder the Array

You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array [10,20,30,40][10,20,30,40], we can permute it so that it becomes [20,40,10,30][20,40,10,30]. Then on the first and the second positions the integers became larger (20>1020>10, 40>2040>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 22. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the length of the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

Examples

Input

7
10 1 1 1 5 5 3

Output

4

Input

5
1 1 1 1 1

Output

0

Note

In the first sample, one of the best permutations is [1,5,5,3,10,1,1][1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.


思路:

交换两个数的位置,交换后大于原位置数 加和,求和最大

直接暴力

首先按从大到小排序,判断是不是有比该数小的,如果有就加 1,同时要注意不能同时交换,所以用 vis 数组标记


CODE :

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))

int a[100000+10];
int vis[100000+10];

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    int n;
    memset(vis,0);

    scanf("%d",&n);

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }

    sort(a,a+n,cmp);

    if(a[0]==a[n])
        printf("0\n");

    else
    {
        int ans=0;
        int sum=0;

        for(int i=0; i<n; i++)
        {
            sum=0;
            for(int j=i+1; j<n; j++)
            {
                if(vis[j])
                    continue;
                if(a[i]>a[j]&&!vis[j])
                {
                    ans++;
                    sum++;
                    vis[j]=1;
                    break;
                }
            }
            if(sum==0)
                break;
        }
        printf("%d\n",ans);
    }
}

3、

C-Romaji

Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.

In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.

Help Vitya find out if a word ss is Berlanese.

Input

The first line of the input contains the string ss consisting of |s||s| (1≤|s|≤1001≤|s|≤100) lowercase Latin letters.

Output

Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".

You can print each letter in any case (upper or lower).

Examples

Input

sumimasen

Output

YES

Input

ninja

Output

YES

Input

codeforces

Output

NO

Note

In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.

In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.


题意:判断一个字符串是不是符合题意的

符合题意需要满足以下条件:

1、除了 n 之外,辅音字母之后必须有元音出现,所以 末尾字母一定不能是除了 n 之外的辅音字母

2、元音之后可以出现任何字母

3、在 n 之后,可以出现任意字母,可以出现福音,可以出现多个元音

首先先特判末尾字母

然后就跑一遍循环,判断辅音字母的下一位是不是元音即可


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))

int main()
{
    char s[200];
    int len;

    scanf("%s",s);
    int flag=0;
    int sum=0;
    len=strlen(s);
    // cout<<len<<' '<<s[len-1]<<endl;
    if(s[len-1]!='a'&&s[len-1]!='e'&&s[len-1]!='i'&&s[len-1]!='o'&&s[len-1]!='u'&&s[len-1]!='n')
        cout<<"NO"<<endl;

    else
    {
        for(int i=0; i<len-1; i++)
        {
            if(s[i]!='a'&&s[i]!='e'&&s[i]!='i'&&s[i]!='o'&&s[i]!='u')
            {
                if(s[i]=='n')
                    continue;
                else
                {
                    if(s[i+1]=='a'||s[i+1]=='e'||s[i+1]=='i'||s[i+1]=='o'||s[i+1]=='u')
                        continue;
                    else
                    {
                        flag=1;
                        break;
                    }
                }
                if(flag==1)
                    break;

            }
        }
        if(flag==1)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
}

 

4、

D - Game Shopping

Maxim wants to buy some games at the local game shop. There are nn games in the shop, the ii-th game costs cici.

Maxim has a wallet which can be represented as an array of integers. His wallet contains mm bills, the jj-th bill has value ajaj.

Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.

When Maxim stands at the position ii in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the ii-th game using this bill. After Maxim tried to buy the nn-th game, he leaves the shop.

Maxim buys the ii-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the ii-th game. If he successfully buys the ii-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.

For example, for array c=[2,4,5,2,4]c=[2,4,5,2,4] and array a=[5,3,4,6]a=[5,3,4,6] the following process takes place: Maxim buys the first game using the first bill (its value is 55), the bill disappears, after that the second bill (with value 33) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because c2>a2c2>a2, the same with the third game, then he buys the fourth game using the bill of value a2a2(the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value a3a3.

Your task is to get the number of games Maxim will buy.

Input

The first line of the input contains two integers nn and mm (1≤n,m≤10001≤n,m≤1000) — the number of games and the number of bills in Maxim's wallet.

The second line of the input contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤10001≤ci≤1000), where cici is the cost of the ii-th game.

The third line of the input contains mm integers a1,a2,…,ama1,a2,…,am (1≤aj≤10001≤aj≤1000), where ajaj is the value of the jj-th bill from the Maxim's wallet.

Output

Print a single integer — the number of games Maxim will buy.

Examples

Input

5 4
2 4 5 2 4
5 3 4 6

Output

3

Input

5 2
20 40 50 20 40
19 20

Output

0

Input

6 4
4 8 15 16 23 42
1000 1000 1000 1000

Output

4

Note

The first example is described in the problem statement.

In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.

In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.


题意:

钱包里有若干张钱,如果钱包最上边的一张能够买当前商品的话,就把该钱去掉,买的商品数 加 1

如果不能购买的话,移步到下一个商品处,直至遍历完所有的商品

思路:

定义 i,j指针,移动比较


CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))

int main()
{
    int n,m;
    int a[1000+10];
    int b[1000+10];

    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);

    for(int i=0;i<m;i++)
        scanf("%d",&b[i]);

    int ans=0;
    int i=0,j=0;

    while(i<n)
    {
        if(b[j]>=a[i])
        {
            i++;
            j++;
            ans++;
        }
        else
            i++;
    }

    printf("%d\n",ans);
}

猜你喜欢

转载自blog.csdn.net/JKdd123456/article/details/82917077