#P7333. [JRKSJ R1] JFCA
[JRKSJ R1] JFCA
Description
A cycle is given with points on it, where the distance between every pair of adjacent points is .
Each point has two attributes and . For point , define as the shortest distance along the cycle between and a point such that and . In particular, if there is no such , then .
Input Format
The input has lines.
Line contains one integer .
Line contains integers, where the -th integer denotes , with the same meaning as above.
Line contains integers, where the -th integer denotes , with the same meaning as above.
Output Format
Output one line with integers, where the -th integer denotes , with the same meaning as above.
3
1 2 3
3 2 1
1 1 1
5
5 4 3 5 6
7 6 5 4 3
-1 2 1 1 1
5
1 1 2 1 1
2 2 2 2 2
2 1 -1 1 2
Hint
Constraints
For of the testdata, .
For of the testdata, , .
For test points to , we use bundled evaluation.
Explanation of Sample 1
For , . The distance between and is , so .
For , . The distance between and is , so .
For , . The distance between and is , so .
: Added a set of hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号