#P9914. 「RiOI-03」匀速相遇
「RiOI-03」匀速相遇
Background
When everyone is accelerating, you and I met at a crossroads in life at a constant speed.
It was a glance that stirred my heart, yet also a regret that we could not stay. Once again, we run at a constant speed toward our own directions. When will we meet again next time...
Problem Description
There are points on the Cartesian plane, where:
- There are type points. Initially, they are located at in order.
- There are type points. Initially, they are located at in order.
At some moment, type and type points start moving at the same time. Specifically:
- For the -th type point, it moves upward (i.e. in the positive direction of the axis) at a constant speed of units per second. In particular, if , then the point stays still forever.
- For the -th type point, it moves rightward (i.e. in the positive direction of the axis) at a constant speed of units per second. In particular, if , then the point stays still forever.
Meeting and parting are nothing special. As a passer-by in rushing time, at this station where you stay briefly, can you help Little T solve this simple problem: find how many pairs of points will meet at some moment, i.e. they are at the same position at some time.
Since you cannot stop time, all points will keep moving endlessly, whether they meet or not. May you, running on this road, one day meet your ideals at a constant speed, never stopping.
Input Format
The first line contains two positive integers .
The second line contains integers , representing the moving speeds of the -th type points in order.
The third line contains integers , representing the moving speeds of the -th type points in order.
Output Format
One line with one integer, representing how many pairs of points will meet at some moment.
3 3
1 2 3
3 2 1
1
3 3
2 5 1
83 101 98
0
Hint
Sample Explanation 1
When , the -nd type point and the -nd type point reach the point at the same time. This is also the only meeting in this sample, so the output is .
Data Scale and Constraints
This problem uses bundled testdata.
- Subtask 0 (10 pts): , .
- Subtask 1 (20 pts): , .
- Subtask 2 (30 pts): guaranteed , .
- Subtask 3 (40 pts): no special restrictions.
For all testdata, , .
Translated by ChatGPT 5