4679: 非理性问题

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:12 通过:11

题目描述

Petya的作业是这样的:
  给定函数f(x)=(((x \ mod \ p_1) \ mod \ p_2) \ mod \ p_3)  \ mod \ p_4(这里mod表示取余数的操作)。他的任务是计算范围为 [a,b] 的整数 x 的数量,并且f(x)=x 。
可惜Petya忘记了取余数的顺序,只写了4个数字。取余数的24种可能顺序中的每一种都有相等的被选中的概率。例如,如果Petya有数字1,2,3,4那么他可以按这个顺序取余数或者先取余数对4取模,然后对2,3,1取模。这些数字还有22种其他的排列方式,表示可以取余数的顺序。在这个问题中,Petya写下的4个数字是成对不同的。
  现在Petya不可能完成老师给的任务,但只是为了好玩,他决定找出x的数量(x \in [a,b]),并且f (x)=x 的概率不小于 31.4159265352718281828459045\% 。换句话说,如果存在至少$7个 p_{1},p_{2},p_{3},p_{4} 的数字排列,其中 f(x)=x,petya将选择x.


Little Petya was given this problem for homework:
You are given function f(x)=(((x \ mod \ p_1) \ mod \ p_2) \ mod \ p_3)  \ mod \ p_4 (here mod represents the operation of taking the remainder). His task is to count the number of integers x in range  [a,b]  with property f(x)=x  .

It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.

Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers x \in [a,b] with property that probability that  f(x)=x  is not less than 31.4159265352718281828459045\% . In other words, Petya will pick up the number  x if there exist at least 7 permutations of numbers  p_{1},p_{2},p_{3},p_{4} , for which f(x)=x  .

输入格式

First line of the input will contain 6 integers, separated by spaces: p_{1},p_{2},p_{3},p_{4},a,b (1<=p_{1},p_{2},p_{3},p_{4}<=1000,0<=a<=b<=31415 ).

It is guaranteed that numbers  p_{1},p_{2},p_{3},p_{4}  will be pairwise distinct.

第一行包含6个被空格隔开的整数  p_{1},p_{2},p_{3},p_{4},a,b  ( 1<=p_{1},p_{2},p_{3},p_{4}<=1000,0<=a<=b<=31415 )。

保证 p_{1},p_{2},p_{3},p_{4}  是成对不同的

输出格式

Output the number of integers in the given range that have the given property.

输出给定范围内具有给定属性的整数的数目。

输入样例 复制

2 7 1 8 2 8

输出样例 复制

0

数据范围与提示

样例输入 #1

2 7 1 8 2 8

样例输出 #1

0

样例输入 #2

20 30 40 50 0 100

样例输出 #2

20

样例输入 #3

31 41 59 26 17 43

样例输出 #3

9