1. 程式人生 > >第二場訓練賽

第二場訓練賽

Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.

To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a

1, a2, ..., ak.

Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.

Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).

Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

Input

The first line of the input contains three integers nm and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.

Then m lines follow. Each of them contains three integers uv and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers .

If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak(1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

Output

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.

If the bakery can not be opened (while satisfying conditions) in any of the ncities, print  - 1 in the only line.

Examples

Input

5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5

Output

3

Input

3 1 1
1 2 3
3

Output

-1

Note

Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.

題意:是否存在一條連線特殊和不特殊的邊,存在最小值是多少;

城市1和城市5有倉庫,那我們只需要考慮城市2和城市4,之所
以不考慮城市3是因為倉庫1到城市3必須要經過城市2,顯然城
市2比城市3離倉庫1更近

於是,我們只要把有倉庫的城市標記,
如果某條雙向路一端連著有倉庫的城市,另一端連著沒有倉庫
的城市,那就把這條路的長度取來作比較,留下距離最短的路即可

---------------------



#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long LL;
int u[100010],v[100010],l[100010];
int vis[100010];
int main()
{
    int n,m,k;
    int a,i,ans=INF;
    cin>>n>>m>>k;
    for(i=0;i<m;i++)
    {
        cin>>u[i]>>v[i]>>l[i];
    }
    for(i=0;i<k;i++)
    {
        cin>>a;
        vis[a]=1;
    }
    for(i=0;i<m;i++)
    {
        if(vis[u[i]]&&!vis[v[i]]||!vis[u[i]]&&vis[v[i]])
        {
            ans=min(ans,l[i]);
        }
    }
    if(ans!=INF)
        cout<<ans<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}

B

Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.

For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.

Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

Katya had no problems with completing this task. Will you do the same?

Input

The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

Output

Print two integers m and k (1 ≤ m, k ≤ 1018), such that nm and k form a Pythagorean triple, in the only line.

In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

Examples

Input

3

Output

4 5

Input

6

Output

8 10

Input

1

Output

-1

Input

17

Output

144 145

Input

67

Output

2244 2245

Note

Illustration for the first sample.

思路:

規律為:

①n*n為奇數:聯立方程組a+b=n*n;a-b=1;

②n*n為偶數:聯立方程組a+b=n*n/2;a-b=2;

③n為1||n為2:無法構成直角三角形

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
int main()
{
    LL a,b,c;
    while(cin>>a)
    {
        if(a<=2)
            cout<<"-1"<<endl;
        else if(a%2==1)
        {
            cout<<(a*a-1)/2<<" "<<(a*a+1)/2<<endl;
        }
        else if(a%2==0)
        {
            cout<<(a*a-4)/4<<" "<<(a*a+4)/4<<endl;
        }
    }

    return 0;
}

You are given two strings ss and tt, both consisting only of lowercase Latin letters.

The substring s[l..r]s[l..r] is the string which is obtained by taking characters sl,sl+1,…,srsl,sl+1,…,sr without changing the order.

Each of the occurrences of string aa in a string bb is a position ii (1≤i≤|b|−|a|+11≤i≤|b|−|a|+1) such that b[i..i+|a|−1]=ab[i..i+|a|−1]=a (|a||a| is the length of string aa).

You are asked qq queries: for the ii-th query you are required to calculate the number of occurrences of string tt in a substring s[li..ri]s[li..ri].

Input

The first line contains three integer numbers nn, mm and qq (1≤n,m≤1031≤n,m≤103, 1≤q≤1051≤q≤105) — the length of string ss, the length of string tt and the number of queries, respectively.

The second line is a string ss (|s|=n|s|=n), consisting only of lowercase Latin letters.

The third line is a string tt (|t|=m|t|=m), consisting only of lowercase Latin letters.

Each of the next qq lines contains two integer numbers lili and riri (1≤li≤ri≤n1≤li≤ri≤n) — the arguments for the ii-th query.

Output

Print qq lines — the ii-th line should contain the answer to the ii-th query, that is the number of occurrences of string tt in a substring s[li..ri]s[li..ri].

Examples

Input

10 3 4
codeforces
for
1 3
3 10
5 6
5 7

Output

0
1
0
1

Input

15 2 3
abacabadabacaba
ba
1 15
3 4
2 14

Output

4
0
3

Input

3 5 2
aaa
baaab
1 3
1 1

Output

0
0

Note

In the first example the queries are substrings: "cod", "deforces", "fo" and "for", respectively.

思路:找子串

#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
set<int> st;
map<int,int> mp;
int vis[100010],a[100010];
int main()
{
    int n,m,q,x,y;
    string a,b;
    cin>>n>>m>>q;
    cin>>a;
    cin>>b;
    while(1)
    {
        int t=a.find(b);
        if(t!=-1)
        {
            mp[t]++;
            a[t]='3';
        }
        else
            break;
    }
    while(q--)
    {
        int ans;
        cin>>x>>y;
        x--;
        y--;
        ans=0;
        map<int,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++)
        {
            if(it->first>=x&&it->first+m-1<=y)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

-------------------------------------------------------
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
int n,m,q,x,y;
string s,t;
int ans[1010];
int main()
{
    cin>>n>>m>>q;
    cin>>s;
    cin>>t;
    for(int i=0;i<=n;i++)
    {
        if(s.substr(i,m)==t)
            ans[i]=1;
    }
    while(q--)
    {
        int sum=0;
        cin>>x>>y;
        for(int i=x-1;i<=y-m;i++)
        {
            sum+=ans[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}

Allen wants to enter a fan zone that occupies a round square and has nn entrances.

There already is a queue of aiai people in front of the ii-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.

Allen uses the following strategy to enter the fan zone:

  • Initially he stands in the end of the queue in front of the first entrance.
  • Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance).

Determine the entrance through which Allen will finally enter the fan zone.

Input

The first line contains a single integer nn (2≤n≤1052≤n≤105) — the number of entrances.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the number of people in queues. These numbers do not include Allen.

Output

Print a single integer — the number of entrance that Allen will use.

Examples

Input

4
2 3 2 0

Output

3

Input

2
10 10

Output

1

Input

6
5 2 6 5 7 4

Output

6

Note

In the first example the number of people (not including Allen) changes as follows: [2,3,2,0]→[1,2,1,0]→[0,1,0,0][2,3,2,0]→[1,2,1,0]→[0,1,0,0]. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.

In the second example the number of people (not including Allen) changes as follows: [10,10]→[9,9]→[8,8]→[7,7]→[6,6]→[5,5]→[4,4]→[3,3]→[2,2]→[1,1]→[0,0][10,10]→[9,9]→[8,8]→[7,7]→[6,6]→[5,5]→[4,4]→[3,3]→[2,2]→[1,1]→[0,0].

In the third example the number of people (not including Allen) changes as follows: [5,2,6,5,7,4]→[4,1,5,4,6,3]→[3,0,4,3,5,2]→[2,0,3,2,4,1]→[1,0,2,1,3,0]→[0,0,1,0,2,0][5,2,6,5,7,4]→[4,1,5,4,6,3]→[3,0,4,3,5,2]→[2,0,3,2,4,1]→[1,0,2,1,3,0]→[0,0,1,0,2,0].

思路:給你n個數,每個數單位時間內減1,求到達位置上為0的位置,有一個規律,假設迴圈k次找到這個值,那麼k*n+i==a[i],找出其中最先出現的最小a[i]值,其i即為所求。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
using namespace std;
const int minn=0x3f3f3f3f;
typedef long long LL;
int n;
LL a;
int main()
{
    int ans=0,min=minn;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(min>(a-i+n)/n)
        {
            min=(a-i+n)/n;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.

There are nn flowers in a row in the exhibition. Sonya can put either a rose or a lily in the ii-th position. Thus each of nn positions should contain exactly one flower: a rose or a lily.

She knows that exactly mm people will visit this exhibition. The ii-th visitor will visit all flowers from lili to riri inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.

Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

Input

The first line contains two integers nn and mm (1≤n,m≤1031≤n,m≤103) — the number of flowers and visitors respectively.

Each of the next mm lines contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n), meaning that ii-th visitor will visit all flowers from lili to riri inclusive.

Output

Print the string of nn characters. The ii-th symbol should be «0» if you want to put a rose in the ii-th position, otherwise «1» if you want to put a lily.

If there are multiple answers, print any.

Examples

Input

5 3
1 3
2 4
2 5

Output

01100

Input

6 3
5 6
1 4
4 6

Output

110010

Note

In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;

  • in the segment [1…3][1…3], there are one rose and two lilies, so the beauty is equal to 1⋅2=21⋅2=2;
  • in the segment [2…4][2…4], there are one rose and two lilies, so the beauty is equal to 1⋅2=21⋅2=2;
  • in the segment [2…5][2…5], there are two roses and two lilies, so the beauty is equal to 2⋅2=42⋅2=4.

The total beauty is equal to 2+2+4=82+2+4=8.

In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;

  • in the segment [5…6][5…6], there are one rose and one lily, so the beauty is equal to 1⋅1=11⋅1=1;
  • in the segment [1…4][1…4], there are two roses and two lilies, so the beauty is equal to 2⋅2=42⋅2=4;
  • in the segment [4…6][4…6], there are two roses and one lily, so the beauty is equal to 2⋅1=22⋅1=2.

The total beauty is equal to 1+4+2=71+4+2=7

題意:

有一排n個格子,每個格子裡能放一種花,一共有兩種花,一種用 0 代表,另一種用 1 代表,然後給你m各區間,每個區間的價值就是這個區間內的兩種花的數量之積。問你應該怎麼放花,使得這些區間的價值和最大。

思路:

題目的意思轉化一下,就是說讓0 1 的個數在各個區間內都是接近的(和相等,越接近,積越大),也就是說0 1 分佈均勻,那麼,我們直接0 1 交替輸出,就可以保證0 1 在各個區間都是最接近的。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
using namespace std;
typedef long long LL;
int main()
{
    int n,m,a[1100],b[1100];
    while(cin>>n>>m)
    {
        for(int i=1;i<=m;i++)
        {
            cin>>a[i]>>b[i];
        }
        for(int i=1;i<=n;i++)
        {
            if(i%2==0)
                cout<<"1";
            else
                cout<<"0";
        }
        cout<<endl;
    }
    return 0;
}

Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.

Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.

If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the cell n - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.

Help Slava to destroy all tanks using as few bombs as possible.

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

Output

In the first line print m — the minimum number of bombs Slava needs to destroy all tanks.

In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki.

If there are multiple answers, you can print any of them.

Examples

Input

2

Output

3
2 1 2 

Input

3

Output

4
2 1 3 2 

 思路:因為每個坦克有兩條命,所以說炸的次數應該是每個方塊炸一遍,然後在扎總數的一半那麼總次數為:n+n/2;

           題目給了1~n的格子,格子的偶數一定小於等於奇數,例如5,奇數1,3,5,偶數2,4;例如4,奇數2,4,偶數1,3,那麼我們可以以5個格子進行分析,我們為什麼不炸奇偶奇,而選擇偶奇偶,炸奇偶奇有3+2+3次,炸偶奇偶有2+3+2次,題中要求最小的轟炸數,所以我們選擇偶奇偶

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main()
{
    int n;
    cin>>n;
    cout<<n+n/2<<endl;
    for(int i=2;i<=n;i=i+2)
    {
        cout<<i<<" ";
    }
    for(int i=1;i<=n;i=i+2)
    {
        cout<<i<<" ";
    }
    for(int i=2;i<=n;i=i+2)
    {
        cout<<i<<" ";
    }
    return 0;
}

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.

題意:轉變矩形的寬和高,觀察高是否是遞減的,如果是就yes,否則no

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
using namespace std;
typedef long long LL;
LL n,w[100010],h[100010];
int main()
{
    LL i,k=0;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++)
        {
            cin>>w[i]>>h[i];
        }
        h[1]=max(h[1],w[1]);
        for(i=1; i<n; i++)
        {
            if(h[i]>=h[i+1])
            {
                if(w[i+1]>=h[i+1]&&h[i]>=w[i+1])
                {
                    swap(w[i+1],h[i+1]);
                }
                k++;
            }
            else
            {
                swap(w[i+1],h[i+1]);
                if(h[i]>=h[i+1])
                    k++;
                else
                    break;
            }
        }
        if(i<n)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }

    return 0;
}

Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.

Sonya has drawn nn numbers in a row, aiai is located in the ii-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.

Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.

For example, if the numbers [1,5,4,1,3][1,5,4,1,3] are written, and Sonya gives the number 11 to the first robot and the number 44 to the second one, the first robot will stop in the 11-st position while the second one in the 33-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 44 to the first robot and the number 55 to the second one, they will meet since the first robot will stop in the 33-rd position while the second one is in the 22-nd position.

Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.

Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (pp, qq), where she will give pp to the first robot and qq to the second one. Pairs (pipi, qiqi) and (pjpj, qjqj) are different if pi≠pjpi≠pj or qi≠qjqi≠qj.

Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.

Input

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

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105) — the numbers in a row.

Output

Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.

Examples

Input

5
1 5 4 1 3

Output

9

Input

7
1 2 1 1 1 3 2

Output

7

Note

In the first example, Sonya can give pairs (11, 11), (11, 33), (11, 44), (11, 55), (44, 11), (44, 33), (55, 11), (55, 33), and (55, 44).

In the second example, Sonya can give pairs (11, 11), (11, 22), (11, 33), (22, 11), (22, 22), (22, 33), and (33, 22).

題意:

給你n個數字,讓你求出他們有多少組合對,不能重複

思路:

set求出在每個數字之前有多少不重複的數字,就能組成多少數對,採用逆序的思路

首先我們把每個數存入陣列a裡面,然後vis陣列儲存這個資料之前有多少不重複的資料,然後把a資料插入st裡面,我們使用set的好處就是可以把這個重複資料給去掉,然後我們只需要在vis數組裡面a的值之前最多的數,最後vis陣列遍歷相加。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
typedef long long LL;
set<int> st;
int vis[100010],a[100010];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        vis[a[i]]=st.size();
        st.insert(a[i]);
    }
    LL ans=0;
    for(int i=0;i<=100000;i++)
    {
        ans+=vis[i];
    }
    cout<<ans<<endl;
    return 0;
}