CF1609G A Stroll Around the Matrix

Description

![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1609G/ceef08d1b03037a22565155ac40e7e9a427625a1.png)William has two arrays of numbers $ a_1, a_2, \dots, a_n $ and $ b_1, b_2, \dots, b_m $ . The arrays satisfy the conditions of being convex. Formally an array $ c $ of length $ k $ is considered convex if $ c_i - c_{i - 1} < c_{i + 1} - c_i $ for all $ i $ from $ 2 $ to $ k - 1 $ and $ c_1 < c_2 $ . Throughout William's life he observed $ q $ changes of two types happening to the arrays: 1. Add the arithmetic progression $ d, d \cdot 2, d \cdot 3, \dots, d \cdot k $ to the suffix of the array $ a $ of length $ k $ . The array after the change looks like this: $ [a_1, a_2, \dots, a_{n - k}, a_{n - k + 1} + d, a_{n - k + 2} + d \cdot 2, \dots, a_n + d \cdot k] $ . 2. The same operation, but for array $ b $ . After each change a matrix $ d $ is created from arrays $ a $ and $ b $ , of size $ n \times m $ , where $ d_{i, j}=a_i + b_j $ . William wants to get from cell ( $ 1, 1 $ ) to cell ( $ n, m $ ) of this matrix. From cell ( $ x, y $ ) he can only move to cells ( $ x + 1, y $ ) and ( $ x, y + 1 $ ). The length of a path is calculated as the sum of numbers in cells visited by William, including the first and the last cells. After each change William wants you to help find out the minimal length of the path he could take.

Input Format

N/A

Output Format

N/A