A. Splits
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n.

For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1].

The following sequences aren't splits of 8: [1, 7], [5, 4], [11,  - 3], [1, 1, 4, 1, 1].

The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split [1, 1, 1, 1, 1] is 5, the weight of the split [5, 5, 3, 3, 3] is 2 and the weight of the split [9] equals 1.

For a given n, find out the number of different weights of its splits.

Input

The first line contains one integer n (1 ≤ n ≤ 109).

Output

Output one integer — the answer to the problem.

Examples
input

Copy
7
output

Copy
4
input

Copy
8
output

Copy
5
input

Copy
9
output

Copy
5
Note

In the first sample, there are following possible weights of splits of 7:

Weight 1: []

Weight 2: [, 1]

Weight 3: [, 1]

Weight 7: []

把一个数分为不同的集合(元素可以重复),和为n

n是奇数,长度为n的,n/2+1,。。。1(长度为2不存在)

n是偶数,长度为n,长度为n/2。。。1(均可以存在)

所以结论就是n/2+1

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin>>n;
cout<<n/+;
return ;
}
B. Messages
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.

Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.

Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.

Determine the maximum amount of money Vasya's bank account can hold after T minutes.

Input

The first line contains five integers nABC and T (1 ≤ n, A, B, C, T ≤ 1000).

The second string contains n integers ti (1 ≤ ti ≤ T).

Output

Output one integer  — the answer to the problem.

Examples
input

Copy
4 5 5 3 5
1 5 5 4
output

Copy
20
input

Copy
5 3 1 1 3
2 2 2 1 1
output

Copy
15
input

Copy
5 5 3 4 5
1 2 3 4 5
output

Copy
35
Note

In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.

In the second sample the messages can be read at any integer moment.

In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.

昨天晚上没有这个Note啊,毒瘤

所以就是看下(T-t[i])*(c-b)的正负啊,%%%聚聚

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long ans;
int t[];
int main()
{
int n,a,b,c,T;
cin>>n>>a>>b>>c>>T;
for(int i=;i<=n;i++)
cin>>t[i];
for(int i=;i<=n;i++)
if((T-t[i])*(c-b)<=)
ans+=a;
else
ans+=a+(T-t[i])*(c-b);
cout<<ans;
return ;
}
C. Alternating Sum
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two integers aa and bb. Moreover, you are given a sequence s0,s1,…,sns0,s1,…,sn. All values in ss are integers 11 or −1−1. It's known that sequence is kk-periodic and kk divides n+1n+1. In other words, for each k≤i≤nk≤i≤n it's satisfied that si=si−ksi=si−k.

Find out the non-negative remainder of division of n∑i=0sian−ibi∑i=0nsian−ibi by 109+9109+9.

Note that the modulo is unusual!

Input

The first line contains four integers n,a,bn,a,b and kk (1≤n≤109,1≤a,b≤109,1≤k≤105)(1≤n≤109,1≤a,b≤109,1≤k≤105).

The second line contains a sequence of length kk consisting of characters '+' and '-'.

If the ii-th character (0-indexed) is '+', then si=1si=1, otherwise si=−1si=−1.

Note that only the first kk members of the sequence are given, the rest can be obtained using the periodicity property.

Output

Output a single integer — value of given expression modulo 109+9109+9.

Examples
input

Copy
2 2 3 3
+-+
output

Copy
7
input

Copy
4 1 5 1
-
output

Copy
999999228
Note

In the first example:

(n∑i=0sian−ibi)(∑i=0nsian−ibi) = 2230−2131+20322230−2131+2032 = 7

In the second example:

(n∑i=0sian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)(∑i=0nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9).

等比数列啊,但是等比数列的比可以是1,记得判断

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MD=1e9+;
ll po(ll a,ll b)
{
ll ans=;
while(b)
{
if(b&)ans=ans*a%MD;
b>>=,a=a*a%MD;
}
return ans;
}
int main()
{
ll n,a,b,k;
cin>>n>>a>>b>>k;
string s;
cin>>s;
ll cur=;
for(int i=;i<k;i++)
{
if(s[i]=='+')cur=(cur+po(a,n-i)*po(b,i)%MD)%MD;
else cur=(cur-po(a,n-i)*po(b,i)%MD+MD)%MD;
}
ll t=po(a,k*(MD-)%(MD-))*po(b,k)%MD;
if(t==)
cout<<cur*((n+)/k)%MD;
else
cout<<cur*po(t-,MD-)%MD*(po(t,(n+)/k)-)%MD;
return ;
}

Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2)的更多相关文章

  1. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1) 963B 964D B Destruction of a Tree

    题 OvO http://codeforces.com/contest/963/problem/B CF 963B 964D 解 对于题目要求,显然一开始的树,要求度数为偶数的节点个数为奇数个,通过奇 ...

  2. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)D. Frequency of String

    题意:有一个串s,n个串模式串t,问s的子串中长度最小的包含t k次的长度是多少 题解:把所有t建ac自动机,把s在ac自动机上匹配.保存每个模式串在s中出现的位置.这里由于t两两不同最多只有xsqr ...

  3. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)

    A. Alternating Sum 就是个等比数列,特判公比为 $1$ 的情况即可. #include <bits/stdc++.h> using namespace std; ; ; ...

  4. CodeForces 837D - Round Subset | Educational Codeforces Round 26

    /* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...

  5. Codeforces 932 A.Palindromic Supersequence (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分 ...

  6. ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) A

    2018-02-19 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 mega ...

  7. Divide by Zero 2018 and Codeforces Round #474 (Div. 1 + Div. 2, combined)

    思路:把边看成点,然后每条边只能从下面的边转移过来,我们将边按照u为第一关键字,w为第二关键字排序,这样就能用线段树维护啦. #include<bits/stdc++.h> #define ...

  8. ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined)

    靠这把上了蓝 A. Palindromic Supersequence time limit per test 2 seconds memory limit per test 256 megabyte ...

  9. Codeforces 932 C.Permutation Cycle-数学 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    C. Permutation Cycle   time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. react中constructor和super()以及super(props)的区别。

    react中这两个API出镜率超级高,但是一直不太懂这到底是干嘛的,有什么用:今天整理一下,方便自己查看同时方便大家. 1.constructor( )-----super( )的基本含义 const ...

  2. Centos 7 搭建git服务器及使用gitolite控制权限

    一.安装git yum install git git --version #查看git版本 二.升级git(可选,如果之前已经安装git,需要升级git到最新版本) git clone https: ...

  3. Outlook 0x800CCC1A 错误

    使用POP3帐户时,您可能在Outlook 2013/2016中看到以下错误.我在Exchange Server 2013环境中遇到此问题,在Windows 8.1上运行的Microsoft Outl ...

  4. ABAP,Java和JavaScript的序列化,反序列化

    ABAP 1. ABAP提供了一个工具类cl_proxy_xml_transform,通过它的两个方法abap_to_xml_xstring和xml_xstring_to_abap实现两种格式的互换. ...

  5. 使用nodejs消费SAP Cloud for Customer上的Web service

    Jerry在公众号文章C4C和微信集成系列教程里曾经使用nodejs去消费C4C提供的标准webservice. 看一个具体例子:C4C里Individual Customers可以维护Social ...

  6. 从PEP-8学习Python编码风格

    (搬运自我在SegmentFault的博客) 关于空行 类与顶级函数(top-level function)的定义之间应当空两行. 类中的方法之间应当空一行. 方法中的逻辑部分之间可以空一行. 关于原 ...

  7. halt, reboot, poweroff - 中止系统运行

    SYNOPSIS /sbin/halt [-n] [-w] [-d] [-f] [-i] [-p] /sbin/reboot [-n] [-w] [-d] [-f] [-i] /sbin/powero ...

  8. lca(最近公共祖先(在线)) 倍增法详解

    转自大佬博客 : https://blog.csdn.net/lw277232240/article/details/72870644 描述:倍增法用于很多算法当中,通过字面意思来理解 LCA是啥呢 ...

  9. js中异步方案比较完整版(callback,promise,generator,async)

    JS 异步已经告一段落了,这里来一波小总结 1. 回调函数(callback) setTimeout(() => { // callback 函数体 }, 1000) 缺点:回调地狱,不能用 t ...

  10. superset docker 部署

    公众号原文有更多效果图哦 一.使用自己的数据库 1. 拉取项目 // 创建目录用于存放项目 mkdir -p /mnt/superset cd /mnt/superset git clone http ...