第二场训练赛

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

猜你喜欢

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