1. 程式人生 > >國慶第一場訓練賽

國慶第一場訓練賽

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;
}

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;
}

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;
}


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;
}


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;
}