训练

一、A - Round House

 

Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.

Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house bentrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.

 Illustration for n = 6, a = 2, b =  - 5.

Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.

Input

The single line of the input contains three space-separated integers na and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.

Output

Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.

Examples

Input

6 2 -5

Output

3

Input

5 1 3

Output

4

Input

3 2 7

Output

3

Note

The first example is illustrated by the picture in the statements.


题意: 输入n,a,b分别代表一共有几个房子,从第几个房子开始,走几个房子,b为正代表顺时针,b为负代表逆时针。输出最后到达哪个房子。


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#include <queue>
using namespace std;
const int maxn = 1e9+10;
const int maxx = 110;
int mapp[maxx];
int main()
{
	int n,a,b;
	int i,j;
	while(scanf("%d%d%d", &n, &a, &b)!=EOF)
	{
		if(b>0)
		{
			for(i=0; i<n; i++)
			{
				if(a>n)
					a = 1;
				mapp[i] = a;
				a++;
			}
		}
		else
		{
			for(int i=0; i<n; i++)
			{
				if(a<=0)
					a = n;
                mapp[i] = a;
				a--;
			}
		}
		int j;
		if(b>=0)
        {
            j = b%n;
        }
        else
        {
            j = (-b)%n;
        }
		printf("%d\n",mapp[j]);
	}
	return 0;
}

二、B - Lunch Rush

Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.

The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch in the i-th restaurant. If time ti exceeds the time k that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal fi - (ti - k). Otherwise, the Rabbits get exactly fi units of joy.

Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.

Input

The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the characteristics of the i-th restaurant.

Output

In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.

Examples

Input

2 5
3 3
4 5

Output

4

Input

4 6
5 8
3 6
2 3
2 2

Output

3

Input

1 5
1 7

Output

-1

题意; 第一行输入n, k 以下n行输入 fi, ti,   如果t<=k,则第i个的能量就为f,  如果t>k,则第j个的能量就为f-(t-k);  输出最大的能量值;


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#include <queue>
using namespace std;
int n, k;
int f, t;
int ans;
int maxx;
int main()
{
    while(scanf("%d%d", &n, &k)!=EOF)
    {
        maxx = -999999999;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d", &f, &t);
            if(t<k)
                ans = f;
            else
                ans = f-(t-k);
            maxx = max(maxx, ans);

        }
        printf("%d\n", maxx);
    }
    return 0;
}


三、C - Perfect Number

We consider a positive integer perfect, if and only if the sum of its digits is exactly 1010. Given a positive integer kk, your task is to find the kk-th smallest perfect positive integer.

Input

A single line with a positive integer kk (1≤k≤100001≤k≤10000).

Output

A single number, denoting the kk-th smallest perfect integer.

Examples

Input

1

Output

19

Input

2

Output

28

Note

The first perfect integer is 1919 and the second one is 2828.


题意:把每一位加起来等于10的数称为完美整数,输入n求,第n个完美数是多少。


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#include <queue>
using namespace std;
int n;
int main()
{
    while(scanf("%d", &n)!=EOF)
    {
        int x = 18;
        int sum = 0;
        int cnt, i;
        while(sum!=n)
        {
            x++;
            cnt = 0;
            i = x;
            while(i!=0)
            {
                cnt+=i%10;
                i/=10;
            }
            if(cnt==10)
            {
                sum++;
            }
        }
        printf("%d\n", x);
    }
    return 0;
}

四、D - Tricky Sum

In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.

For example, for n = 4 the sum is equal to  - 1 - 2 + 3 - 4 =  - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.

Calculate the answer for t values of n.

Input

The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.

Each of next t lines contains a single integer n (1 ≤ n ≤ 109).

Output

Print the requested sum for each of t integers n given in the input.

Examples

Input

2
4
1000000000

Output

-4
499999998352516354

Note

The answer for the first sample is explained in the statement.


题意:输入n,输出从1加到n 但是如果,这个数是2的幂,则减掉这个数。等比数列算出来所有在n中2的次方和然后前n项和减去2倍的他就好


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#include <queue>
using namespace std;
long long t, sum;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n;
        long long i = 1;
        long long k = 0;
        scanf("%lld", &n);
        while(i<=n)
        {
            i*=2;
        }
        printf("%lld\n", (n+1)*n/2-i*2+2);//前n项和减去2倍的i
    }
    return 0;
}

五、E - Caisa and Pylons

Caisa solved the problem with the sugar and now he is on the way back to home.

Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.

Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?

Input

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1  ≤  hi  ≤  105) representing the heights of the pylons.

Output

Print a single number representing the minimum number of dollars paid by Caisa.

Examples

Input

5
3 4 3 2 4

Output

4

Input

3
4 4 4

Output

4

Note

In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
 


题意:给定n个位置的高度,0的位置为0,每次移动一步时,需要消耗hi−hi+1的能量,一开始能量为0,过程中能量不能为负,一美元可以买一点能量,问说最小开销。

解题思路:水题,找最大值即可。


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#include <queue>
using namespace std;
int n;
int mapp[100010];
int main()
{
    int ans = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d", &mapp[i]);
        ans = max(ans, mapp[i]);
    }
    printf("%d\n", ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值