蓝桥杯寒假训练----6

大提琴的声音就像一条河,左岸是我无法忘却的回忆,右岸是我值得紧握的璀璨年华,中间流淌的,是我年年岁岁淡淡的感伤。

                                                      Draw! 

You still have partial information about the score during the historic football match. You are given a set of pairs $$$(a_i, b_i)$$$, indicating that at some point during the match the score was "$$$a_i$$$: $$$b_i$$$". It is known that if the current score is «$$$x$$$:$$$y$$$», then after the goal it will change to "$$$x+1$$$:$$$y$$$" or "$$$x$$$:$$$y+1$$$". What is the largest number of times a draw could appear on the scoreboard?

The pairs "$$$a_i$$$:$$$b_i$$$" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

Input

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10000$$$) — the number of known moments in the match.

Each of the next $$$n$$$ lines contains integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \le a_i, b_i \le 10^9$$$), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).

All moments are given in chronological order, that is, sequences $$$x_i$$$ and $$$y_j$$$ are non-decreasing. The last score denotes the final result of the match.

Output

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

Examples

input

3
2 0
3 1
3 4

output

2

input

3
0 0
0 0
0 0

output

1

input

1
5 4

output

5

Note

In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,x,y,xx,yy,jg=1;
int main()
{
    cin>>n;
    for(int i=0; i>x>>y;
        if(min(x,y)>=max(xx,yy))
        {
            jg+=min(x,y)-max(xx,yy)+1;
            if(xx==yy)
                jg-=1;
        }
        xx=x;
        yy=y;
    }
    cout<

                                                    Birthday 

Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.

Formally, let's number children from 11 to nn in a circle order, that is, for every ii child with number ii will stand next to the child with number i+1i+1, also the child with number 11 stands next to the child with number nn. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.

Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.

Input

The first line contains a single integer nn (2≤n≤1002≤n≤100) — the number of the children who came to the cowboy Vlad's birthday.

The second line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) denoting heights of every child.

Output

Print exactly nn integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.

If there are multiple possible answers, print any of them.

Examples

input

Copy

5
2 1 1 3 2

output

Copy

1 2 3 2 1

input

Copy

3
30 10 20

output

Copy

10 20 30

Note

In the first example, the discomfort of the circle is equal to 11, since the corresponding absolute differences are 11, 11, 11 and 00. Note, that sequences [2,3,2,1,1][2,3,2,1,1] and [3,2,1,1,2][3,2,1,1,2] form the same circles and differ only by the selection of the starting point.

In the second example, the discomfort of the circle is equal to 2020, since the absolute difference of 1010 and 3030 is equal to 2020.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
dequeq;
int s[110],n;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>s[i];
    sort(s+1,s+n+1);
    for(int i=1; i<=n; i++)
    {
        if(i&1)
            q.push_front(s[i]);
        else
            q.push_back(s[i]);
    }
    for(int i=0; i

                                                Creative Snap 

Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.

Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of 22. Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:

  • if the current length is at least 22, divide the base into 22 equal halves and destroy them separately, or
  • burn the current base. If it contains no avenger in it, it takes AA amount of power, otherwise it takes his B⋅na⋅lB⋅na⋅l amount of power, where nana is the number of avengers and ll is the length of the current base.

Output the minimum power needed by Thanos to destroy the avengers' base.

Input

The first line contains four integers nn, kk, AA and BB (1≤n≤301≤n≤30, 1≤k≤1051≤k≤105, 1≤A,B≤1041≤A,B≤104), where 2n2n is the length of the base, kkis the number of avengers and AA and BB are the constants explained in the question.

The second line contains kk integers a1,a2,a3,…,aka1,a2,a3,…,ak (1≤ai≤2n1≤ai≤2n), where aiai represents the position of avenger in the base.

Output

Output one integer — the minimum power needed to destroy the avengers base.

Examples

input

Copy

2 2 1 2
1 3

output

Copy

6

input

Copy

3 2 1 2
1 7

output

Copy

8

Note

Consider the first example.

One option for Thanos is to burn the whole base 1−41−4 with power 2⋅2⋅4=162⋅2⋅4=16.

Otherwise he can divide the base into two parts 1−21−2 and 3−43−4.

For base 1−21−2, he can either burn it with power 2⋅1⋅2=42⋅1⋅2=4 or divide it into 22 parts 1−11−1 and 2−22−2.

For base 1−11−1, he can burn it with power 2⋅1⋅1=22⋅1⋅1=2. For 2−22−2, he can destroy it with power 11, as there are no avengers. So, the total power for destroying 1−21−2 is 2+1=32+1=3, which is less than 44.

Similarly, he needs 33 power to destroy 3−43−4. The total minimum power needed is 66.
 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
ll n,k,a,b;
int s[100010];
ll dfs(int l,int r)
{
    int m = l + (r - l + 1) / 2;
    ll jg;
    int ls =upper_bound(s + 1, s + 1 + k, r) - lower_bound(s + 1, s + 1 + k, l);
    if (ls == 0)
        return jg = a;
    else
        jg = b * ls * (r - l + 1);
    if (r - l >= 1)
        jg = min(jg, dfs(l, m - 1) + dfs(m, r));
    return jg;
}
int main()
{
    cin>>n>>k>>a>>b;
    for(int i=1; i<=k; i++)
        cin>>s[i];
    sort(s+1,s+k+1);
    cout<

                                          Ayoub and Lost Array 

Ayoub had an array aa of integers of size nn and this array had two interesting properties:

  • All the integers in the array were between ll and rr (inclusive).
  • The sum of all the elements was divisible by 33.

Unfortunately, Ayoub has lost his array, but he remembers the size of the array nn and the numbers ll and rr, so he asked you to find the number of ways to restore the array.

Since the answer could be very large, print it modulo 109+7109+7 (i.e. the remainder when dividing by 109+7109+7). In case there are no satisfying arrays (Ayoub has a wrong memory), print 00.

Input

The first and only line contains three integers nn, ll and rr (1≤n≤2⋅105,1≤l≤r≤1091≤n≤2⋅105,1≤l≤r≤109) — the size of the lost array and the range of numbers in the array.

Output

Print the remainder when dividing by 109+7109+7 the number of ways to restore the array.

Examples

input

Copy

2 1 3

output

Copy

3

input

Copy

3 2 2

output

Copy

1

input

Copy

9 9 99

output

Copy

711426616

Note

In the first example, the possible arrays are : [1,2],[2,1],[3,3][1,2],[2,1],[3,3].

In the second example, the only possible array is [2,2,2][2,2,2].

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int n,l,r;
ll dp[200100][3],s[3];
int main()
{
    cin>>n>>l>>r;
    s[0]=r/3-(l-1)/3;
    s[1]=s[0]-1;
    if(l%3==1)
        s[1]++;
    if(r%3==1||r%3==2)
        s[1]++;
    s[2]=s[0]-1;
    if(l%3==1||l%3==2)
        s[2]++;
    if(r%3==2)
        s[2]++;
    dp[1][0]=s[0];
    dp[1][1]=s[1];
    dp[1][2]=s[2];
    for(int i=2; i<=n; i++)
    {
        dp[i][0]=((dp[i-1][0]*s[0])%mod+(dp[i-1][1]*s[2])%mod+(dp[i-1][2]*s[1])%mod)%mod;
        dp[i][1]=((dp[i-1][0]*s[1])%mod+(dp[i-1][1]*s[0])%mod+(dp[i-1][2]*s[2])%mod)%mod;
        dp[i][2]=((dp[i-1][0]*s[2])%mod+(dp[i-1][1]*s[1])%mod+(dp[i-1][2]*s[0])%mod)%mod;
    }
    cout<

                                      Stars Drawing (Hard Edition)

A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 00 are not allowed).

Let's consider empty cells are denoted by '.', then the following figures are stars:

蓝桥杯寒假训练----6_第1张图片The leftmost figure is a star of size 11, the middle figure is a star of size 22 and the rightmost figure is a star of size 33.

You are given a rectangular grid of size n×mn×m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 11 to nn, columns are numbered from 11 to mm. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n⋅mn⋅m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.

In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n⋅mn⋅m stars.

Input

The first line of the input contains two integers nn and mm (3≤n,m≤10003≤n,m≤1000) — the sizes of the given grid.

The next nn lines contains mm characters each, the ii-th line describes the ii-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

Output

If it is impossible to draw the given grid using stars only, print "-1".

Otherwise in the first line print one integer kk (0≤k≤n⋅m0≤k≤n⋅m) — the number of stars needed to draw the given grid. The next kk lines should contain three integers each — xjxj, yjyj and sjsj, where xjxj is the row index of the central star character, yjyj is the column index of the central star character and sjsj is the size of the star. Each star should be completely inside the grid.

Examples

input

Copy

6 8
....*...
...**...
..*****.
...**...
....*...
........

output

Copy

3
3 4 1
3 5 2
3 5 1

input

Copy

5 5
.*...
****.
.****
..**.
.....

output

Copy

3
2 2 1
3 3 1
3 4 1

input

Copy

5 5
.*...
***..
.*...
.*...
.....

output

Copy

-1

input

Copy

3 3
*.*
.*.
*.*

output

Copy

-1

Note

In the first example the output

2
3 4 1
3 5 2

is also correct.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
char g[1010][1010];
int l[1010][1010], r[1010][1010], up[1010][1010], dw[1010][1010];
int n, m, xx[1010][1010], yy[1010][1010];
struct node
{
    int x;
    int y;
    int len;
};
vector p;
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%s", g[i] + 1);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (g[i][j] == '*')
            {
                l[i][j] = l[i][j - 1] + 1;
                up[i][j] = up[i - 1][j] + 1;
            }
        }
    }
    for (int i = n; i >= 1; i--)
    {
        for (int j = m; j >= 1; j--)
        {
            if (g[i][j] == '*')
            {
                r[i][j] = r[i][j + 1] + 1;
                dw[i][j] = dw[i + 1][j] + 1;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (g[i][j] == '*')
            {
                int len = inf;
                len = min(min(l[i][j], r[i][j]),min(up[i][j], dw[i][j]));
                if (len > 1)
                {
                    node tmp;
                    tmp.x = i;
                    tmp.y = j;
                    tmp.len =
                        len - 1;
                    p.push_back(tmp);
                    xx[i - len + 1][j]++;
                    xx[i + len][j]--;
                    yy[i][j - len + 1]++;
                    yy[i][j + len]--;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            xx[i][j] += xx[i - 1][j];
            yy[i][j] += yy[i][j - 1];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (g[i][j] == '*' && xx[i][j] == 0 &&yy[i][j] ==0)
            {
                printf("-1\n");
                return 0;
            }
        }
    }
    int cd = p.size();
    printf("%d\n", cd);
    for (int i = 0; i < cd; i++)
        printf("%d %d %d\n", p[i].x, p[i].y, p[i].len);
    return 0;
}

                                                   Multiplicity

You are given an integer array a1,a2,…,ana1,a2,…,an.

The array bb is called to be a subsequence of aa if it is possible to remove some elements from aa to get bb.

Array b1,b2,…,bkb1,b2,…,bk is called to be good if it is not empty and for every ii (1≤i≤k1≤i≤k) bibi is divisible by ii.

Find the number of good subsequences in aa modulo 109+7109+7.

Two subsequences are considered different if index sets of numbers included in them are different. That is, the values ​of the elements ​do not matter in the comparison of subsequences. In particular, the array aa has exactly 2n−12n−1 different subsequences (excluding an empty subsequence).

Input

The first line contains an integer nn (1≤n≤1000001≤n≤100000) — the length of the array aa.

The next line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106).

Output

Print exactly one integer — the number of good subsequences taken modulo 109+7109+7.

Examples

input

Copy

2
1 2

output

Copy

3

input

Copy

5
2 2 1 22 14

output

Copy

13

Note

In the first example, all three non-empty possible subsequences are good: {1}{1}, {1,2}{1,2}, {2}{2}

In the second example, the possible good subsequences are: {2}{2}, {2,2}{2,2}, {2,22}{2,22}, {2,14}{2,14}, {2}{2}, {2,22}{2,22}, {2,14}{2,14}, {1}{1}, {1,22}{1,22}, {1,14}{1,14}, {22}{22}, {22,14}{22,14}, {14}{14}.

Note, that some subsequences are listed more than once, since they occur in the original array multiple times.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int n,m;
ll a[200010],dp[2000010],sum;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    dp[0]=1;
    for(int i=1; i<=n; i++)
    {
        vectorv;
        for(int j=1; j*j<=a[i]; j++)
        {
            if(a[i]%j==0)
            {
                v.push_back(j);
                if(j!=a[i]/j)
                    v.push_back(a[i]/j);
            }
        }
        sort(v.begin(),v.end());
        for(int j=v.size()-1; j>=0; j--)
            dp[v[j]]=(dp[v[j]]+dp[v[j]-1])%mod;
    }
    for(int i=1; i<=n; i++)
        sum=(sum+dp[i])%mod;
    cout<

                                              Fight Against Traffic

Little town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible number of roads on a path between them.

In order to improve the transportation system, the city council asks mayor to build one new road. The problem is that the mayor has just bought a wonderful new car and he really enjoys a ride from his home, located near junction s to work located near junction t. Thus, he wants to build a new road in such a way that the distance between these two junctions won't decrease.

You are assigned a task to compute the number of pairs of junctions that are not connected by the road, such that if the new road between these two junctions is built the distance between s and t won't decrease.

Input

The firt line of the input contains integers nms and t (2 ≤ n ≤ 1000, 1 ≤ m ≤ 1000, 1 ≤ s, t ≤ ns ≠ t) — the number of junctions and the number of roads in Nsk, as well as the indices of junctions where mayors home and work are located respectively. The i-th of the following m lines contains two integers ui and vi (1 ≤ ui, vi ≤ nui ≠ vi), meaning that this road connects junctions ui and vi directly. It is guaranteed that there is a path between any two junctions and no two roads connect the same pair of junctions.

Output

Print one integer — the number of pairs of junctions not connected by a direct road, such that building a road between these two junctions won't decrease the distance between junctions s and t.

Examples

input

Copy

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

output

Copy

0

input

Copy

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

output

Copy

5

input

Copy

5 6 1 5
1 2
1 3
1 4
4 5
3 5
2 5

output

Copy

3
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define inf 1000000000
typedef long long ll;
using namespace std;
int m,n,s,t,jg,mp[1010][1010];
int main()
{
    cin>>n>>m>>s>>t;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(i!=j)
                mp[i][j]=inf;
        }
    }
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        mp[x][y]=mp[y][x]=1;
    }
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++)
            if(mp[i][j]!=1&&min(mp[i][s]+mp[t][j],mp[i][t]+mp[s][j])+1>=mp[s][t])
                jg++;
    cout<

 

你可能感兴趣的:(蓝桥杯练习)