#P12732. 外人
外人
Description
Yuta and Saki sometimes run into each other at school. Since they are in different classes, they are usually in different places during lessons and only see each other when changing classrooms at the breaks.
At Suisei High School, there are a total of breaks in a day. During the -th break, Yuta moves from the -th floor to the -th floor, while Saki moves from the -th floor to the -th floor. Assuming the break starts at time and ends at time , their movements can be represented as line segments on a Cartesian coordinate system with time on the horizontal axis and height on the vertical axis. Specifically, Yuta's path is the line segment from point to , and Saki's path is the line segment from point to .
If they are at the same height at the same time, meaning if the aforementioned two line segments intersect, then the two will see each other. They may see each other on the stairs between floors, or at the start or end of their journey. In other words, the coordinates of the intersection point does not have to be an integer, and the intersection point can be at the endpoints of the segments, that is, if Yuta and Saki are in the same floor for class, i.e., , then it is considered that they will meet each other during both the -th break (if ) and the -th break (if ).
They want to know during how many breaks they will see each other in total today.
Input Format
The first line contains an integer representing the number of class periods, with the number of breaks being .
The second line is consisted of integers representing .
The third line is consisted of integers representing .
Output Format
Output a single integer indicating the number of encounters.
3
1 2 3
3 1 2
1
Hint
Sample Explanation
During the first break, Yuta and Saki meet on the stairs between the st and nd floors.
During the second break, the two do not meet.
Constraints
For of the testdata, .
For an additional of the testdata, all -s are the same.
For an additional of the testdata, all -s are the same.
For all of the testdata, , .
京公网安备 11011102002149号