A. Alyona and Numbers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.

Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.

As usual, Alyona has some troubles and asks you to help.

Input

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).

Output

Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.

Examples
Input
6 12
Output
14
Input
11 14
Output
31
Input
1 5
Output
1
Input
3 8
Output
5
Input
5 7
Output
7
Input
21 21
Output
88
Note

Following pairs are suitable in the first sample case:

for x = 1 fits y equal to 4 or 9;

  • for x = 2 fits y equal to 3 or 8;
  • for x = 3 fits y equal to 2, 7 or 12;
  • for x = 4 fits y equal to 1, 6 or 11;
  • for x = 5 fits y equal to 5 or 10;
  • for x = 6 fits y equal to 4 or 9.

Only the pair (1, 4) is suitable in the third sample case.

题意:给你 n,m     1 ≤ x ≤ n, 1 ≤ y ≤ m  问有多少对x/y 使得(x+y)%5==0

题解:水

 #include <bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m;
int main()
{
scanf("%d %d",&n,&m);
ll ans=;
for(int i=;i<=n;i++)
{
int exm=i%;
int re=-exm;
if(m>=re){
ans=ans+(m-re)/;
ans++;
}
}
cout<<ans<<endl;
return ;
}
B. Alyona and Mex
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.

Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.

Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.

The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Output

Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

Examples
Input
5
1 3 3 3 6
Output
5
Input
2
2 1
Output
3
Note

In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.

To reach the answer to the second sample case one must not decrease any of the array elements.

题意:给你n个数 每次操作只能减小某个数 经过一系列操作之后 使得没有出现的数的最小值尽量大

题解:水

 #include <bits/stdc++.h>
#define ll __int64
using namespace std;
int n;
int a[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
int now=;
for(int i=;i<=n;i++)
{
if(now<=a[i])
now++;
else
continue;
}
cout<<now<<endl;
return ;
}
C. Alyona and the Tree
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.

The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > au, where au is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u.

Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root.

Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?

Input

In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree.

In the second line the sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 109) is given, where ai is the number written on vertex i.

The next n - 1 lines describe tree edges: ith of them consists of two integers pi and ci (1 ≤ pi ≤ n,  - 109 ≤ ci ≤ 109), meaning that there is an edge connecting vertices i + 1 and pi with number ci written on it.

Output

Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.

Example
Input
9
88 22 83 14 95 91 98 53 11
3 24
7 -8
1 67
1 64
9 65
5 12
6 -80
3 8
Output
5
Note

The following image represents possible process of removing leaves from the tree:

题意:给你一个树 有点权 边权 删除最少的叶子结点 使得 对于任意一个点到其子树中的点的路径边权和小于等与目标点的点权

题解:dfs处理 记录当前节点的祖先节点中到当前节点的路径边权和的最大值

 #include <bits/stdc++.h>
#define ll __int64
using namespace std;
ll n;
ll a[];
ll p[];
ll in[];
ll out[];
ll d[];
map<ll,ll> mp;
ll nedge=;
ll dfn=;
ll re=;
struct node
{
ll to;
ll pre;
ll we;
}N[];
void add(ll pre,ll to,ll we)
{
nedge++;
N[nedge].to=to;
N[nedge].we=we;
N[nedge].pre=p[pre];
p[pre]=nedge;
}
void getdfs(ll root,ll sum,ll now)
{
in[root]=++dfn;
d[root]=max(sum,now);
sum=d[root];
mp[root]=;
for(int i=p[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
getdfs(N[i].to,sum+N[i].we,N[i].we);
}
out[root]=dfn;
}
void dfs(ll root)
{
mp[root]=;
for(int i=p[root];i;i=N[i].pre){
if(mp[N[i].to])
continue;
if(d[N[i].to]>a[N[i].to])
{
re=re+out[N[i].to]-in[N[i].to]+;
continue ;
}
dfs(N[i].to);
}
}
int main()
{
ll r,w;
memset(p,,sizeof(p));
scanf("%I64d",&n);
for(ll i=;i<=n;i++)
scanf("%I64d",&a[i]);
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d",&r,&w);
add(i,r,w);
add(r,i,w);
}
getdfs(,0ll,0ll);
mp.clear();
dfs();
printf("%I64d\n",re);
return ;
}

最新文章

  1. JavaScript常用方法100种
  2. 实现台式机redhat6.4无线网卡上网RTL8188CUS
  3. Swift 设计指南之 编程规范
  4. fdtd simulation, plotting with gnuplot, writting in perl
  5. duilib -- Label控件的bug(转载)
  6. Java [leetcode 33]Search in Rotated Sorted Array
  7. 在android4.0中实现View的拖动效果
  8. IP处理函数inet_aton()和inet_ntoa(),inet_pton,inet_ntop
  9. angular嵌入注入服务实例
  10. 【Java学习笔记之二十九】Java中的&quot;equals&quot;和&quot;==&quot;的用法及区别
  11. Socket层实现系列 — getsockname()和getpeername()的实现
  12. Ubuntu文件写入内容时出现错误 E121:无法打开并写入文件解决方案
  13. Python基础之模块与包
  14. 分包收集 android 运行的 logcat 日志
  15. java 中如何声明线程安全的集合 set, map 和list【转】
  16. 深入源码分析Java线程池的实现原理
  17. Oracle 启动的时候需要的服务
  18. Git忽略提交 .gitignore配置。自动生成IDE的.gitignore。解决gitignore不生效
  19. Strusts2笔记9--防止表单重复提交和注解开发
  20. Java 运用流传输文件

热门文章

  1. JavaScript学习笔记(二)——函数和数组
  2. 多用户在线FTP程序
  3. 第一次ScrumMeeting博客:团队任务分解
  4. 第10次Scrum会议(10/22)【欢迎来怼】
  5. 第6题 ZigZag转换
  6. pyspark在windows中的安装
  7. 使用 Maven 管理项目
  8. 【.Net】从字符串数组中寻找数字的元素
  9. Android四大组件之Intent(续)
  10. Django 2.0 学习(15):Web框架