Competition - 20181031

题目A:

You are given a string ss, consisting of nn lowercase Latin letters.

A substring of string ss is a continuous segment of letters from ss. For example, "defor" is a substring of "codeforces" and "fors" is not.

The length of the substring is the number of letters in it.

Let's call some string of length nn diverse if and only if there is no letter to appear strictly more than n2n2 times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.

Your task is to find any diverse substring of string ss or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000) — the length of string ss.

The second line is the string ss, consisting of exactly nn lowercase Latin letters.

Output

Print "NO" if there is no diverse substring in the string ss.

Otherwise the first line should contain "YES". The second line should contain anydiverse substring of string ss.

Examples

Input

10
codeforces

Output

YES
code

Input

5
aaaaa

Output

NO

Note

The first example has lots of correct answers.

Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.

大意:

给定一个字符串,找出一个子串,该子串内的任意一个字符的数目不超过n/2,n为该子串的长度。输出任意一个这样的子串。

思路:

恩,,这个题一开始没看懂,以为是求一个没有重复字母的子串,样例过了,然后提交一直WA,,。看懂题之后,直接找到一个长度为2且两字符不相同的子串即可,若有别的子串,也必须是建立在两个不同的字符的基础之上的。

代码:

#include<bits/stdc++.h>
using namespace std;
char s[1001];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    int flag=0;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
        {
            puts("YES");
            printf("%c%c\n",s[i-1],s[i]);
            return 0;
        }
    }
    puts("NO");
    return 0;
}

题目B:

Vasya has got nn books, numbered from 11 to nn, arranged in a stack. The topmost book has number a1a1, the next one — a2a2, and so on. The book at the bottom of the stack has number anan. All numbers are distinct.

Vasya wants to move all the books to his backpack in nn steps. During ii-th step he wants to move the book number bibi into his backpack. If the book with number bibi is in the stack, he takes this book and all the books above the book bibi, and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order [1,2,3][1,2,3] (book 11 is the topmost), and Vasya moves the books in the order [2,1,3][2,1,3], then during the first step he will move two books (11 and 22), during the second step he will do nothing (since book 11 is already in the backpack), and during the third step — one book (the book number 33). Note that b1,b2,…,bnb1,b2,…,bn are distinct.

Help Vasya! Tell him the number of books he will put into his backpack during each step.

Input

The first line contains one integer n (1≤n≤2⋅105)n (1≤n≤2⋅105) — the number of books in the stack.

The second line contains nn integers a1,a2,…,an (1≤ai≤n)a1,a2,…,an (1≤ai≤n) denoting the stack of books.

The third line contains nn integers b1,b2,…,bn (1≤bi≤n)b1,b2,…,bn (1≤bi≤n) denoting the steps Vasya is going to perform.

All numbers a1…ana1…an are distinct, the same goes for b1…bnb1…bn.

Output

Print nn integers. The ii-th of them should be equal to the number of books Vasya moves to his backpack during the ii-th step.

Examples

Input

3
1 2 3
2 1 3

Output

2 0 1 

Input

5
3 1 4 2 5
4 5 1 3 2

Output

3 2 0 0 0 

Input

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

Output

1 1 2 0 1 1 

Note

The first example is described in the statement.

In the second example, during the first step Vasya will move the books [3,1,4][3,1,4]. After that only books 22 and 55 remain in the stack (22is above 55). During the second step Vasya will take the books 22 and 55. After that the stack becomes empty, so during next steps Vasya won't move any books.

大意:

将n本书放入栈,每一本书都有独自的书号,给定一个书号的顺序,求解按该顺序拿书,每次需要拿几本书。

思路:

思路很清晰啊,一个书号对应一个栈中的位置,用multimap 直接查找每一个书号对应的栈中位置,若对应的位置已经被拿过了【之前的书已经在当前书之下,当前书已经被拿走了】,输出零,否则要拿从当前到栈顶本书。

一开始害怕超时,用了multimap查找,结果还是超时了,百思不得姐,哪里有复杂度啊,都是一重数组??然后拼命开大数组,当然没用。默默把我的vector换成数组,没用TL,默默把我的multimap换成用数组下标表示的索引,TL,我说不上来那是一种什么样的感受,,沉默了好久,我默默把cin换成了scanf,然后就过了。当然很想骂人,事实上我也这么做了,然后大佬给我敲了一行代码,我的cin也顺利的AC了。学到了。

//19:56
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n;
    int a[200001];
    multimap<int,int> mapA;
    multimap<int,int>::iterator p1,p2;

    cin>>n;
    int x;
    for(int i=1;i<=n;i++){
        cin>>x;
        a[i]=x;
        mapA.insert(make_pair(x,i));
    }
    int need;
    int last=0;
    for(int i=1;i<=n;i++){
        cin>>need;
        p1=mapA.find(need);
        int poi=p1->second;
        if(poi>last){
            cout<<poi-last<<" ";
            last=poi;
        }else{
            cout<<"0 ";
        }
    }
    return 0;
}


/*

#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    int n;
    int a[200001];
    int b[200001];

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[a[i]]=i;//下标为索引,内容为下标所在地址;
    }

    int need;
    int p1,last=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&need);
        p1=b[need];
        int poi=p1;
        if(poi>last){
            printf("%d ",(poi-last));
            last=poi;
        }else{
             printf("0 ");
        }
    }
    return 0;
}

*/
//20:37

题目D:

XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nnbooths, arranged in a circle. The booths are numbered 11 through nn clockwise with nnbeing adjacent to 11. The ii-th booths sells some candies for the price of aiai burles per item. Each booth has an unlimited supply of candies.

Polycarp has decided to spend at most TT burles at the fair. However, he has some plan in mind for his path across the booths:

  • at first, he visits booth number 11;
  • if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately;
  • then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).

Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.

Calculate the number of candies Polycarp will buy.

Input

The first line contains two integers nn and TT (1≤n≤2⋅1051≤n≤2⋅105, 1≤T≤10181≤T≤1018) — the number of booths at the fair and the initial amount of burles Polycarp has.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the price of the single candy at booth number ii.

Output

Print a single integer — the total number of candies Polycarp will buy.

Examples

Input

3 38
5 2 5

Output

10

Input

5 21
2 4 100 2 6

Output

6

Note

Let's consider the first example. Here are Polycarp's moves until he runs out of money:

  1. Booth 11, buys candy for 55, T=33T=33;
  2. Booth 22, buys candy for 22, T=31T=31;
  3. Booth 33, buys candy for 55, T=26T=26;
  4. Booth 11, buys candy for 55, T=21T=21;
  5. Booth 22, buys candy for 22, T=19T=19;
  6. Booth 33, buys candy for 55, T=14T=14;
  7. Booth 11, buys candy for 55, T=9T=9;
  8. Booth 22, buys candy for 22, T=7T=7;
  9. Booth 33, buys candy for 55, T=2T=2;
  10. Booth 11, buys no candy, not enough money;
  11. Booth 22, buys candy for 22, T=0T=0.

No candy can be bought later. The total number of candies bought is 1010.

In the second example he has 11 burle left at the end of his path, no candy can be bought with this amount.

大意:

一个首尾相连的数组,每一个位置有一个花费值,给一定的钱,问可以经过多少个位置【从1->n走】,可以一直走下去。

思路:

数据很大,真的一步步走时不可能的,想到先计算一圈走下来的花费,然后直接去余,用剩余的钱再走最后一圈;后面就发现了问题,剩余的前还是可能会转几个相同的圈,结果显然得有多个循环,不断更新当前钱数走一圈的最大花费,直到剩余钱小于最小的数组值。

代码:

//20:49
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
#include<list>
using namespace std;
typedef long long ll;

ll n,num,money,minx,
    a[200001];

int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>money;
    cin>>a[1];
    minx=a[1];
    for(ll i=2;i<=n;i++){
        cin>>a[i];
        minx=min(a[i],minx);
    }
/* cout<<" minx="<<minx<<endl;*/
    while(money>=minx){
        ll oneM=0,oneN=0;

        for(ll i=1;i<=n;i++){
            if(money>=a[i]){
                money-=a[i];
                num++;
                oneM+=a[i];
                oneN++;
            }
        }
        num+=oneN*(money/oneM);
        money=money%oneM;
        /*cout<<"  num="<<num<<endl;
        cout<<"  money="<<money<<endl;
        cout<<"  oneM="<<oneM<<endl;
        cout<<"  oneN="<<oneN<<endl<<endl;*/
    }

    cout<<num<<endl;
}

猜你喜欢

转载自blog.csdn.net/sodacoco/article/details/83591732