cf--2019-08-23(题目有点多,进来看)

妙笔难书一纸愁肠,苍白的誓言,终究抵不过岁月的遗忘。

 

 

 

目录

Polycarp's New Job

Ilya and a Colorful Walk

Tape

Two distinct points

 Lunar New Year and Cross Counting

 Easy Problem


Polycarp's New Job

Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.

Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).

A bill x×yx×y fits into some wallet h×wh×w if either x≤hx≤h and y≤wy≤w or y≤hy≤h and x≤wx≤w. Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others.

Now you are asked to perform the queries of two types:

  1. + x y+ x y — Polycarp earns a bill of size x×yx×y;
  2. ? h w? h w — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size h×wh×w.

It is guaranteed that there is at least one query of type 11 before the first query of type 22 and that there is at least one query of type 22 in the input data.

For each query of type 22 print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.

Input

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

Each of the next nn lines contains a query of one of these two types:

  1. + x y+ x y (1≤x,y≤1091≤x,y≤109) — Polycarp earns a bill of size x×yx×y;
  2. ? h w? h w (1≤h,w≤1091≤h,w≤109) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size h×wh×w.

It is guaranteed that there is at least one query of type 11 before the first query of type 22 and that there is at least one query of type 22 in the input data.

Output

For each query of type 22 print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.

Example

input

Copy

9
+ 3 2
+ 2 3
? 1 20
? 3 3
? 2 3
+ 1 5
? 10 10
? 1 5
+ 1 1

output

Copy

NO
YES
YES
YES
NO

Note

The queries of type 22 of the example:

  1. Neither bill fits;
  2. Both bills fit (just checking that you got that bills can overlap);
  3. Both bills fit (both bills are actually the same);
  4. All bills fit (too much of free space in a wallet is not a problem);
  5. Only bill 1×51×5 fit (all the others don't, thus it's "NO").  

题意:操作+ x y表示有x  *   y的矩形,?  x  y 表示前面的矩形是否能装进该矩形;cin,cout,过不了。。。

#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 main()
{
    int N,x,y;
    char ch[10];
    scanf("%d",&N);
    int mxh=0,mxw=0;
    while(N--)
    {
        scanf("%s%d%d",&ch,&x,&y);
        if(x>y)
            swap(x,y);
        if(ch[0]=='+')
        {
            mxh=max(mxh,x);
            mxw=max(mxw,y);
        }
        else
        {
            if(x>=mxh&&y>=mxw)
//                cout<<"YES"<

Ilya and a Colorful Walk

Ilya lives in a beautiful city of Chordalsk.

There are nn houses on the street Ilya lives, they are numerated from 11 to nn from left to right; the distance between every two neighboring houses is equal to 11 unit. The neighboring houses are 11 and 22, 22 and 33, ..., n−1n−1 and nn. The houses nn and 11 are not neighboring.

The houses are colored in colors c1,c2,…,cnc1,c2,…,cn so that the ii-th house is colored in the color cici. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.

Ilya wants to select two houses ii and jj so that 1≤i

Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.

Help Ilya, find this maximum possible distance.

Input

The first line contains a single integer nn (3≤n≤3000003≤n≤300000) — the number of cities on the street.

The second line contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤n1≤ci≤n) — the colors of the houses.

It is guaranteed that there is at least one pair of indices ii and jj so that 1≤i

Output

Print a single integer — the maximum possible distance Ilya can walk.

Examples

input

Copy

5
1 2 3 2 3

output

Copy

4

input

Copy

3
1 2 1

output

Copy

1

input

Copy

7
1 1 3 1 1 1 1

output

Copy

4

Note

In the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of 5−1=45−1=4 units.

In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of 11 unit.

In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of 7−3=47−3=4 units.

给出N个数, 保证至少有两种不同的数, 求得两个不同的数直接的最大距离

#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,s[300010],jg;
int main(){
    cin>>N;
    for(int i=1;i<=N;i++)
        cin>>s[i];
    for(int i=2;i<=N;i++){
        if(s[i]!=s[1])
            jg=max(jg,i-1);
    }
    for(int i=N-1;i>0;i--){
        if(s[i]!=s[N])
            jg=max(jg,N-i);
    }
    cout<

Tape

You have a long stick, consisting of mm segments enumerated from 11 to mm. Each segment is 11 centimeter long. Sadly, some segments are broken and need to be repaired.

You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length tt placed at some position ss will cover segments s,s+1,…,s+t−1s,s+1,…,s+t−1.

You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.

Time is money, so you want to cut at most kk continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?

Input

The first line contains three integers nn, mm and kk (1≤n≤1051≤n≤105, n≤m≤109n≤m≤109, 1≤k≤n1≤k≤n) — the number of broken segments, the length of the stick and the maximum number of pieces you can use.

The second line contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤m1≤bi≤m) — the positions of the broken segments. These integers are given in increasing order, that is, b1

Output

Print the minimum total length of the pieces.

Examples

input

Copy

4 100 2
20 30 75 80

output

Copy

17

input

Copy

5 100 3
1 2 4 60 87

output

Copy

6

Note

In the first example, you can use a piece of length 1111 to cover the broken segments 2020 and 3030, and another piece of length 66 to cover 7575and 8080, for a total length of 1717.

In the second example, you can use a piece of length 44 to cover broken segments 11, 22 and 44, and two pieces of length 11 to cover broken segments 6060 and 8787.

题意:在一个长度为m的区间内有n处破损,我们要至多k次使用胶带将其全部填补。

#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,K,M,s[100010],x;
int main(){
    int jg=0,ls=0;
    scanf("%d%d%d",&N,&M,&K);
    for(int i=1;i<=N;i++){
        scanf("%d",&x);
        s[i]=x-ls-1;
        ls=x;
    }
    sort(s+2,s+N+1);
    for(int i=2;i<=N-K+1;i++)
        jg+=s[i];
    printf("%d\n",N+jg);
    return 0;
}

Two distinct points

You are given two segments [l1;r1][l1;r1] and [l2;r2][l2;r2] on the xx-axis. It is guaranteed that l1

cf--2019-08-23(题目有点多,进来看)_第1张图片The example of two segments on the xx-axis.

Your problem is to find two integers aa and bb such that l1≤a≤r1l1≤a≤r1, l2≤b≤r2l2≤b≤r2 and a≠ba≠b. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment [l1;r1][l1;r1] and the second one belongs to the segment [l2;r2][l2;r2].

It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.

You have to answer qq independent queries.

Input

The first line of the input contains one integer qq (1≤q≤5001≤q≤500) — the number of queries.

Each of the next qq lines contains four integers l1i,r1i,l2il1i,r1i,l2i and r2ir2i (1≤l1i,r1i,l2i,r2i≤109,l1i

Output

Print 2q2q integers. For the ii-th query print two integers aiai and bibi — such numbers that l1i≤ai≤r1il1i≤ai≤r1i, l2i≤bi≤r2il2i≤bi≤r2i and ai≠biai≠bi. Queries are numbered in order of the input.

It is guaranteed that the answer exists. If there are multiple answers, you can print any.

Example

input

Copy

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

output

Copy

2 1
3 4
3 2
1 2
3 7
#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 main(){
    int N,x1,x2,y1,y2,f,s;
    scanf("%d",&N);
    while(N--){
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        f=x1;
        for(int i=x2;i<=y2;i++){
            if(i!=f){
                s=i;
                break;
            }
        }
        printf("%d %d\n",f,s);
    }
    return 0;
}

 Lunar New Year and Cross Counting

Lunar New Year is approaching, and you bought a matrix with lots of "crosses".

This matrix MM of size n×nn×n contains only 'X' and '.' (without quotes). The element in the ii-th row and the jj-th column (i,j)(i,j) is defined as M(i,j)M(i,j), where 1≤i,j≤n1≤i,j≤n. We define a cross appearing in the ii-th row and the jj-th column (1

The following figure illustrates a cross appearing at position (2,2)(2,2) in a 3×33×3 matrix.

X.X
.X.
X.X

Your task is to find out the number of crosses in the given matrix MM. Two crosses are different if and only if they appear in different rows or columns.

Input

The first line contains only one positive integer nn (1≤n≤5001≤n≤500), denoting the size of the matrix MM.

The following nn lines illustrate the matrix MM. Each line contains exactly nn characters, each of them is 'X' or '.'. The jj-th element in the ii-th line represents M(i,j)M(i,j), where 1≤i,j≤n1≤i,j≤n.

Output

Output a single line containing only one integer number kk — the number of crosses in the given matrix MM.

Examples

input

Copy

5
.....
.XXX.
.XXX.
.XXX.
.....

output

Copy

1

input

Copy

2
XX
XX

output

Copy

0

input

Copy

6
......
X.X.X.
.X.X.X
X.X.X.
.X.X.X
......

output

Copy

4

Note

In the first sample, a cross appears at (3,3)(3,3), so the answer is 11.

In the second sample, no crosses appear since n<3n<3, so the answer is 00.

In the third sample, crosses appear at (3,2)(3,2), (3,4)(3,4), (4,3)(4,3), (4,5)(4,5), so the answer is 44.

#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 mp[510][510];
int N,ct;
int main(){
    scanf("%d",&N);
    for(int i=0;i>mp[i][j];
    for(int i=1;i

 Easy Problem

Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length nn consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard; otherwise the statement is easy. For example, hard, hzazrzd, haaaaard can be considered hard statements, while har, hart and drah are easy statements.

Vasya doesn't want the statement to be hard. He may remove some characters from the statement in order to make it easy. But, of course, some parts of the statement can be crucial to understanding. Initially the ambiguity of the statement is 00, and removing ii-th character increases the ambiguity by aiai (the index of each character is considered as it was in the original statement, so, for example, if you delete character r from hard, and then character d, the index of d is still 44 even though you delete it from the string had).

Vasya wants to calculate the minimum ambiguity of the statement, if he removes some characters (possibly zero) so that the statement is easy. Help him to do it!

Recall that subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

Input

The first line contains one integer nn (1≤n≤1051≤n≤105) — the length of the statement.

The second line contains one string ss of length nn, consisting of lowercase Latin letters — the statement written by Vasya.

The third line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤9982443531≤ai≤998244353).

Output

Print minimum possible ambiguity of the statement after Vasya deletes some (possibly zero) characters so the resulting statement is easy.

Examples

input

Copy

6
hhardh
3 2 9 11 7 1

output

Copy

5

input

Copy

8
hhzarwde
3 2 6 9 4 8 7 1

output

Copy

4

input

Copy

6
hhaarr
1 2 3 4 5 6

output

Copy

0

Note

In the first example, first two characters are removed so the result is ardh.

In the second example, 55-th character is removed so the result is hhzawde.

In the third example there's no need to remove anything.

题意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在hard这个单词,这个单词可以是不连续的。字母之间隔着几个字母也是可以的。

#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,dp[5],hf[200010];
string ss;
int main()
{
    cin>>N;
    cin>>ss;
    for(int i=0; i>hf[i];
    for(int i=0; i

 

你可能感兴趣的:(codeforces)