2727.Symmetric and Transitive

Time Limit: 1s Memory Limit: 256MB

Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.A set ρ of pairs (a,b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation ρ, if pair 2727_1.png, in this case we use a notation 2727_2.png.Binary relation is equivalence relation, if: It is reflexive (for any a it is true that 2727_3.png); It is symmetric (for any a, b it is true that if 2727_2.png, then 2727_4.png); It is transitive (if 2727_2.png and 2727_5.png, than 2727_6.png). Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":Take any two elements, a and b. If 2727_2.png, then 2727_4.png (according to property (2)), which means 2727_3.png (according to property (3)).It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109+7.

Input Format(From the terminal/stdin)

Input A single line contains a single integer n (1 \le n \le 4000).

Output Format(To the terminal/stdout)

Output In a single line print the answer to the problem modulo 109+7.

Sample Input 1

Copy
1
 \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
2
 \n

Sample Output 2

Copy
3
 \n

Sample Input 3

Copy
3
 \n

Sample Output 3

Copy
10
  \n

Hints

If n=1 there is only one such relation- an empty one, i.e. 2727_7.png. In other words, for a single element x of set A the following is hold: 2727_8.png.If n=2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are 2727_7.png, ρ={(x,x)}, ρ={(y,y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.

Submit

请先 登录

© 2025 FAQs