5-3-周练博客

来源:互联网 发布:淘宝盖楼需要等级吗 编辑:程序博客网 时间:2024/05/16 15:45

A - Lucky Year

                   

Apart from having lots of holidays throughout theyear, residents of Berland also have whole lucky years. Year is consideredlucky if it has no more than 1 non-zero digit in its number. So years 100,40000, 5 are lucky and 12, 3001 and 12345 are not.

You are given current year in Berland. Your task is tofind how long will residents of Berland wait till the next lucky year.

Input

The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.

Output

Output amount of years from the current year to thenext lucky one.

Example

Input

4

Output

1

Input

201

Output

99

Input

4000

Output

1000

Note

In the first example next lucky year is 5. In thesecond one — 300. In the third — 5000.

大意:找出数n距比它大的只有1位不为0的数的距离

 

水题,从1位到n位打表,然后根据表扫描即可。

code

#include<iostream>
using namespace std;
int t=0;
long long a[100000];
int z(int n){
long long p=1;
for (long long i=2;i<=n;i++)
p*=10;
for (long long i=1;i<=9;i++)
{
a[t++]=i*p;
}
return 0;
}
int deal(){
int i;
for (i=1;i<=10;i++)
z(i);
int r;
cin>>r;
for (i=0;i<t;)
{
if (r>=a[i]) {
i++;
continue;}
break;
}
cout<<a[i]-r<<endl;
}
int main(){
deal();
}

 

B - Isit rated?

Is it rated?

Here it is. The UltimateQuestion of Competitive Programming, Codeforces, and Everything. And you arehere to answer it.

Another Codeforces round hasbeen conducted. No two participants have the same number of points. For eachparticipant, from the top to the bottom of the standings, their rating beforeand after the round is known.

It's known that if at leastone participant's rating has changed, then the round was rated for sure.

It's also known that if theround was rated and a participant with lower rating took a better place in thestandings than a participant with higher rating, then at least one roundparticipant's rating has changed.

In this problem, you shouldnot make any other assumptions about the rating system.

Determine if the current roundis rated, unrated, or it's impossible to determine whether it is rated of not.

Input

The first line contains asingle integer n (2 ≤ n ≤ 1000) — the number of roundparticipants.

Each of the next nlines contains two integers ai andbi (1 ≤ ai, bi ≤ 4126) —the rating of thei-th participant before and after the round,respectively. The participants are listed in order from the top to the bottomof the standings.

Output

If the round is rated forsure, print "rated". If the round is unrated for sure, print"unrated". If it's impossible to determine whether the round is ratedor not, print "maybe".

Example

Input

6
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884

Output

rated

Input

4
1500 1500
1300 1300
1200 1200
1400 1400

Output

unrated

Input

5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699

Output

maybe

Note

In the first example, theratings of the participants in the third and fifth places have changed,therefore, the round was rated.

In the second example, noone's rating has changed, but the participant in the second place has lowerrating than the participant in the fourth place. Therefore, if the round wasrated, someone's rating would've changed for sure.

In the third example, no one'srating has changed, and the participants took places in non-increasing order oftheir rating. Therefore, it's impossible to determine whether the round israted or not.

方法:

若两次不相等必定rated

否则,

若排名不是降序则必定unreatd

然后就是maybe

Code:

#include<iostream>

using namespace std;

#include<cstdio>

//#include<algorithm>

int a[10000],b[10000];

int n;

int t;

int deal()

{

       scanf("%d",&n);

       inti;

       intr;

       r=0;t=0;

       for(i=0;i<n;i++)

       {

              scanf("%d%d",&a[i],&b[i]);

              if(a[i]!=b[i])

              {

                     r=1;

              }

              if(i==0) continue;

              if(a[i]>a[i-1]) t=1;

       }

       if(r==1)

       {

              cout<<"rated"<<endl;

              return0;

       }

       if(t==1)

       {

              cout<<"unrated"<<endl;

              return0;

       }

       cout<<"maybe"<<endl;

}

int main()

{

       deal();

}

C - FakeNP

Tavak and Seyyed are goodfriends. Seyyed is very funny and he told Tavak to solve the following probleminstead of longest-path.

You are given l and r.For all integers from l to r, inclusive, we wrote down all oftheir integer divisors except 1. Find the integer that we wrote down themaximum number of times.

Solve the problem to show thatit's not a NP problem.

Input

The first line contains twointegers l and r (2 ≤ l ≤ r ≤ 109).

Output

Print single integer, theinteger that appears maximum number of times in the divisors.

If there are multiple answers,print any of them.

Example

Input

19 29

Output

2

Input

3 6

Output

3

Note

Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html

The first example: from 19 to29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.

The second example: from 3 to6 these numbers are divisible by 3: {3, 6}.

方法:

就是在考智商,然而我智商并不行,qwq

l==r则必定是l

否则一定是2

其余数的次数一定小于等于2

Code:

#include<iostream>

usingnamespace std;

intdeal()

{

        int n;

        int m;

        cin>>n>>m;

        if(n==m) cout<<n<<endl;

        else

        cout<<2<<endl;

}

intmain()

{

        deal();

}

 

 

 

D -3-palindrome

In the beginning of the newyear Keivan decided to reverse his name. He doesn't like palindromes, so hechanged Naviek to Navick.

He is too selfish, so for agiven n he wants to obtain a string ofn characters, each ofwhich is either 'a', 'b' or 'c', with no palindromes of length 3 appearing inthe string as a substring. For example, the strings "abc" and"abca" suit him, while the string "aba" doesn't. He alsowant the number of letters 'c' in his string to be as little as possible.

Input

The first line contains singleinteger n (1 ≤ n ≤ 2·105) — the length of thestring.

Output

Print the string thatsatisfies all the constraints.

If there are multiple answers,print any of them.

Example

Input

2

Output

aa

Input

3

Output

bba

Note

A palindrome is a sequence ofcharacters which reads the same backward and forward.

方法:

本来百思不得其解,但是发现是只是不存在长度为3的回文字串,也就是不会有ABA这种形式,那么aabb依次输出即可

Code

#include<iostream>

usingnamespace std;

char s[7]="aabb";

intmain()

{

        int n;

        cin>>n;

        int i;

        for (i=0;i<n;i++)

        cout<<s[i%4];

}

E -T-Shirt Hunt

Not so long ago theCodecraft-17 contest was held on Codeforces. The top 25 participants, andadditionally random 25 participants out of those who got into top 500, willreceive a Codeforces T-shirt.

Unfortunately, you didn'tmanage to get into top 25, but you got into top 500, taking placep.

Now the elimination round of8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17T-shirt winners will be chosen as follows. Lets be the number of pointsof the winner of the elimination round of 8VC Venture Cup 2017. Then thefollowing pseudocode will be executed:


i := (s div 50) mod 475
repeat 25 times:
    i := (i * 96 + 42) mod 475
    print (26 + i)

Here "div" is theinteger division operator, "mod" is the modulo (the remainder ofdivision) operator.

As the result of pseudocodeexecution, 25 integers between 26 and 500, inclusive, will be printed. Thesewill be the numbers of places of the participants who get the Codecraft-17 T-shirts.It is guaranteed that the 25 printed integers will be pairwise distinct for anyvalue of s.

You're in the lead of theelimination round of 8VC Venture Cup 2017, havingx points. You believethat having at least y points in the current round will be enough forvictory.

To change your final score,you can make any number of successful and unsuccessful hacks. A successful hackbrings you 100 points, an unsuccessful one takes 50 points from you. It'sdifficult to do successful hacks, though.

You want to win the currentround and, at the same time, ensure getting a Codecraft-17 T-shirt. What is thesmallest number of successful hacks you have to do to achieve that?

Input

The only line contains threeintegers p, x and y (26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) —your place in Codecraft-17, your current score in the elimination round of 8VCVenture Cup 2017, and the smallest number of points you consider sufficient forwinning the current round.

Output

Output a single integer —the smallest number of successful hacks you have to do in order to both win theelimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17T-shirt.

It's guaranteed that your goalis achievable for any valid input data.

Example

Input

239 10880 9889

Output

0

Input

26 7258 6123

Output

2

Input

493 8000 8000

Output

24

Input

101 6800 6500

Output

0

Input

329 19913 19900

Output

8

Note

In the first example, there isno need to do any hacks since 10880 points already bring the T-shirt to the239-th place of Codecraft-17 (that is, you). In this case, according to thepseudocode, the T-shirts will be given to the participants at the followingplaces:


475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133365 312 449 301 343

In the second example, youhave to do two successful and one unsuccessful hack to make your score equal to7408.

In the third example, you needto do as many as 24 successful hacks to make your score equal to 10400.

In the fourth example, it'ssufficient to do 6 unsuccessful hacks (and no successful ones) to make yourscore equal to 6500, which is just enough for winning the current round andalso getting the T-shirt

Code:

#include<iostream>

using namespacestd;

#include<cstdio>

int judge(int x,intn)

{

    int p=x/50;

    p=p%475;

    int i;

//  cout<<x<<":"<<endl;

    for (i=1;i<=25;i++)

    {

        p=(p*96+42)%475;

        //cout<<26+p<<" ";

        if (26+p==n) return 1;

    }

//  cout<<endl;

    return 0;

}

int deal()

{

    int p,x,y;

    scanf("%d%d%d",&p,&x,&y);

    //{

    int cs=0;

    while (x-50<y)

    {

        cs++;

        x+=100;

    }

    int t=x;

    while (x>=y)

    {

        if (judge(x,p)) {

        //  cout<<x<<"";

            cout<<cs<<endl;return 0;

        }

        x-=50; 

    }

    x=t-50;

    if (x<y) x=t+50;

    int xx=t;

    int c1=cs,c2=cs;

    while(1)

    {

        if (judge(x,p))

        {

            cs=c2;

            break;

        }

        x+=100;

        c2++;

        if (judge(xx,p))

        {

            cs=c1;

            break;

        }

        xx+=100;

        c1++;

    }

//  cout<<x<<" ";

    cout<<cs<<endl;

}

int main()

{

    deal();

}

方法:

网上题解多的是,注意x-50<y的情况

蛤蛤

原创粉丝点击