Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to find out someone has changed the volume to aa. Of course, Bob has a remote control that can change the volume.

There are six buttons (−5,−2,−1,+1,+2,+5−5,−2,−1,+1,+2,+5) on the control, which in one press can either increase or decrease the current volume by 11, 22, or 55. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than 00.

As Bob is so angry, he wants to change the volume to bb using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given aa and bb, finds the minimum number of presses to change the TV volume from aa to bb.

Input

Each test contains multiple test cases. The first line contains the number of test cases TT (1≤T≤10001≤T≤1000). Then the descriptions of the test cases follow.

Each test case consists of one line containing two integers aa and bb (0≤a,b≤1090≤a,b≤109) — the current volume and Bob's desired volume, respectively.

Output

For each test case, output a single integer — the minimum number of presses to change the TV volume from aa to bb. If Bob does not need to change the volume (i.e. a=ba=b), then print 00.

Example

Input

3
4 0
5 14
3 9

Output

2
3
2

Note

In the first example, Bob can press the −2−2 button twice to reach 00. Note that Bob can not press −5−5 when the volume is 44 since it will make the volume negative.

In the second example, one of the optimal ways for Bob is to press the +5+5 twice, then press −1−1 once.

In the last example, Bob can press the +5+5 once, then press +1+1.

能选5的时候选5,不能选5的时候选2,不能选2的时候选1。

验证可行性,如果有个大于等于5的数,不选5那么至少要选两个2一个1,甚至更多,所以直接贪心,完事。

#include<bits/stdc++.h>
#define MAXM 100000000
#define MAXN 1000005
using namespace std;
int main()
{
int a,b,t;
cin>>t;
while(t--)
{ cin>>a>>b;
int ans=abs(a-b);
int c=ans%5;
int sum=(ans-c)/5;
ans=c%2;
sum+=(c-ans)/2+ans;
cout<<sum<<endl;
}
}

Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)的更多相关文章

  1. Codeforce 1255 Round #601 (Div. 2)D. Feeding Chicken (模拟)

    Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he deci ...

  2. Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)

    Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the L ...

  3. Codeforce 1255 Round #601 (Div. 2)B. Fridge Lockers(思维)

    Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a priv ...

  4. Codeforces Round #601 (Div. 2) A Changing Volume

    好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include&l ...

  5. 【cf比赛记录】Codeforces Round #601 (Div. 2)

    Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...

  6. Codeforces Round #601 (Div. 2)

    传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include ...

  7. codeforce Codeforces Round #201 (Div. 2)

    cf 上的一道好题:  首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是  所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...

  8. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version)

    Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的 ...

随机推荐

  1. 初识docker与理解

    因最近公司的一个新项目,有一个业务场景是需要给多个甲方的服务器配置运行环境与部署,所以考虑使用docker来实现环境配置的统一 1.docker是什么 docker是一种容器虚拟化技术的实现,相当于在 ...

  2. (js描述的)数据结构[树结构之红黑树](13)

    1.二叉送搜索树的缺点: 2.红黑树难度: 3.红黑树五大规则: 4.红黑树五大规则的作用: 5.红黑树二大变换: 1)变色 2)旋转 6.红黑树的插入五种变换情况: 先声明--------插入的数据 ...

  3. Java第四天,随机数如何生成?ArrayList如何使用?

    虽然很多时候我们查阅Java API文档,但是对于一些必要的类,我们还是需要去了解的.因为这样的情况下,我们就可以尽量的去缩短开发的周期.接下来我们认识一下哪些API类是必须熟记的. Random 这 ...

  4. Python线程和协程CPU资源利用率测试

    前言介绍 协程 ,又称为微线程,它是实现多任务的另一种方式,只不过是比线程更小的执行单元.因为它自带CPU的上下文,这样只要在合适的时机,我们可以把一个协程切换到另一个协程.通俗的理解: 在一个线程中 ...

  5. xshell使用记录

    1.rz---上传文件 2.ls----列出文件 3.chmod +x webbench_pro  -----赋予执行权限 4../webbench_pro----当前目录执行程序

  6. The Super Powers UVA - 11752

    题目大意:将范围从1~pow(2,64)-1内的super power输出.super power的定义:一个数x至少存在两种x=pow(i,k),(k!=1). 题解: 注意数据范围2的64次方-1 ...

  7. 落谷 P1734 最大约数和

    题目描述 选取和不超过S的若干个不同的正整数,使得所有数的约数(不含它本身)之和最大. 输入格式 输入一个正整数S. 输出格式 输出最大的约数之和. 输入输出样例 输入 #1复制 11 输出 #1复制 ...

  8. OkHttp 优雅封装 HttpUtils 之 上传下载解密

    曾经在代码里放荡不羁,如今在博文中日夜兼行,只为今天与你分享成果.如果觉得本文有用,记得关注我,我将带给你更多. 还没看过第一篇文章的欢迎移步:OkHttp 优雅封装 HttpUtils 之气海雪山初 ...

  9. Flutter环境安装,ios真机调试

    MAC: 下载Flutter,官网的可能很慢.可以去我的网盘下载, 提取码: 3t6y. 下载完的包会在~/Downloads目录下,我们移到~/opt/flutter目录下. mkdir ./opt ...

  10. Say goodbye

    Since September 28th 2015 Scriptogram officially closed. We considered every option before making th ...