714A.md (1319B)
1 Source: https://codeforces.com/problemset/problem/714/A 2 3 A. Meeting of Old Friends 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! 22 23 Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. 24 25 Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. 26 27 Calculate the number of minutes they will be able to spend together. 28 29 Input 30 31 The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1 ≤ *l*1, *r*1, *l*2, *r*2, *k* ≤ 1018, *l*1 ≤ *r*1, *l*2 ≤ *r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. 32 33 Output 34 35 Print one integer — the number of minutes Sonya and Filya will be able to spend together. 36 37 Examples 38 39 Input 40 41 ``` 42 1 10 9 20 1 43 ``` 44 45 Output 46 47 ``` 48 2 49 ``` 50 51 Input 52 53 ``` 54 1 100 50 200 75 55 ``` 56 57 Output 58 59 ``` 60 50 61 ``` 62 63 Note 64 65 In the first sample, they will be together during minutes 9 and 10. 66 67 In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.