国庆第一场训练赛

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.

题意:旋转矩形,使他们的高是递减的

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
using namespace std;
typedef long long LL;
const int maxn=0x3f3f3f3f;
int main()
{
    LL n;
    LL w[100010],h[100010];
    LL flag=0;
    while(cin>>n)
    {
        flag=0;
        memset(w,0,sizeof(w));
        memset(h,0,sizeof(h));
        for(LL i=0; i<n; i++)
        {
            cin>>w[i]>>h[i];
        }
        LL k=0;
        h[0]=max(h[0],w[0]);
        for(LL i=0; i<n-1; i++)
        {
            if(h[i]<h[i+1])
            {
                swap(w[i+1],h[i+1]);
                if(h[i]<h[i+1])
                {
                    flag=1;
                    break;
                }
                else
                    k++;

            }
            if(h[i]>=h[i+1])
            {
                if(h[i+1]<=w[i+1]&&h[i]>=w[i+1])
                    h[i+1]=max(h[i+1],w[i+1]);
            }
        }
        if(flag==1)
        {
            cout<<"NO"<<endl;
        }
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

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 ciciis 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.

思路:钱包的钱能买上面的物品,如果钱足够买上面的物品才能够使用下一个钱,否则不能进行。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
using namespace std;
typedef long long LL;
const int maxn=0x3f3f3f3f;
int main()
{
    int n,m,k=1,x;
    int c[1010],a[1010];
    memset(c,0,sizeof(c));
    memset(a,0,sizeof(a));
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>c[i];
    for(int i=1; i<=m; i++)
        cin>>a[i];

    for(int i=1; i<=n; i++)
    {
        if(c[i]<=a[k])
        {
           a[k++];
        }
    }
    cout<<k-1<<endl;
    return 0;
}

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.

题意:每个辅音后面紧跟着一个元音("a", "o", "u", "i" , "e"),然后字母‘n’不算.

思路:首次我们查找如果查找第一个字母,然后查找下一个字母,如果第一个字母不是元音或者‘n’,那么检查下一个,如果下一个为还是为辅音或者长度超过了字母的长度,则返回NO,否则返回YES。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
typedef long long LL;
using namespace std;
string s;
int main()
{
    char a[5]= {'a','e','i','o','u'};
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if ((s[i]!=a[0]&&s[i]!=a[1]&&s[i]!=a[2]&&s[i]!=a[3]&&s[i]!=a[4])&& s[i] != 'n')//辅音
        {
            if (i+1 >= s.size() || (s[i+1]!=a[0]&&s[i+1]!=a[1]&&s[i+1]!=a[2]&&s[i+1]!=a[3]&&s[i+1]!=a[4]))
            {
                printf("NO\n");
                return 0;
            }
        }
    }
    printf("YES\n");
    return 0;
}


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。

思路:首先对原序列排序,然后开始循环每个元素,在里面我们设置一个循环,使得pos的位置小于n,然后在a[pos]<=a[n]的情况下,pos++;如果不满足这个情况我们就跳出这个循环,ans++,pos++;

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
typedef long long LL;
using namespace std;
int a[100010],n,ans,pos=0;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        while(pos<=n-1&&a[pos]<=a[i])
        {
            pos++;
        }
        if(pos<=n-1)
        {
            ans++;
            pos++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


E - Minimum Ternary String

You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').

You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).

For example, for string "010210" we can perform the following moves:

  • "010210" →→ "100210";
  • "010210" →→ "001210";
  • "010210" →→ "010120";
  • "010210" →→ "010201".

Note than you cannot swap "02" →→ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.

You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).

String aa is lexicographically less than string bb (if strings aa and bb have the same length) if there exists some position ii (1≤i≤|a|1≤i≤|a|, where |s||s| is the length of the string ss) such that for every j<ij<i holds aj=bjaj=bj, and ai<biai<bi.

Input

The first line of the input contains the string ss consisting only of characters '0', '1' and '2', its length is between 11 and 105105 (inclusive).

Output

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

Examples

Input

100210

Output

001120

Input

11222121

Output

11112222

Input

20

Output

20

题意:给你一个由0 1 2 构成的字符串,其中0可以和1、1可以和2交换位置,求交换后字典序最小的的串

题解:1可以和0换,可以和1换,可以和2换,那么1在这个字符串当中就可以任意滑动,要想字符串的字典序最小

那么所有的1肯定会在第一个出现2前面,要是没有2,那么最后的字符串一定会是000111的形式,如果有2的话,第一个2后面1一定全部在第一个2的前面

第一个二后面的0和2实际上就不会变化.

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
typedef long long LL;
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.size();
    int pos;
    int flag=0;
    int num1=0,num2=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='2'&&flag==0)
        {
            flag=1;
            pos=i;
        }
        if(s[i]=='1')
            num2++;
        if(s[i]=='0'&&flag==0)
            num1++;
    }
    for(int i=0;i<num1;i++)
        cout<<"0";
    for(int i=0;i<num2;i++)
        cout<<"1";
    if(flag==1)
    {
        for(int i=pos;i<len;i++)
        {
            if(s[i]=='1')
                continue;
            cout<<s[i];
        }
    }
    cout<<endl;
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_38984851/article/details/82942171