Implement a function that counts the number of pairs (i, j) with i < j and arr[i] * i > arr[j] * j. The function should modify the input array in place so that arr[i] = i * arr[i], and then count the number of such pairs by using a modified merge sort (i.e., count inversions in the transformed array). The resulting count corresponds to the number of pairs in the original formulation.
Function Signature
def count_pairs(arr: List[int], n: int) -> int:
Input Requirements (File I/O)
The program must read input from a file at /app/input.txt.
The input file format:
Line 1: n (1 <= n <= 100000)
Line 2: n integers representing arr[0], arr[1], ..., arr[n-1], separated by spaces
The program should write output to a file at /app/output.txt containing a single integer: the count of pairs.
Output Requirements
The output file /app/output.txt must contain exactly one integer: the number of pairs (i, j) with i < j and arr[i] * i > arr[j] * j, as computed via the transformed array and inversion counting.
Implementation Guidelines
The algorithm must handle up to n = 100000 efficiently (O(n log n)).
In-place transformation: for each i in [0, n-1], update arr[i] to i * arr[i].
Use a merge sort-based approach to count inversions in the transformed array, with a helper function to merge and count during the sort process.
The solution should be implemented in /app/solution.py.
The main entry should read from /app/input.txt, invoke count_pairs, and write the result to /app/output.txt.
Example
Input file /app/input.txt:
4
5 1 4 2
After transforming in place, arr becomes [0, 1, 8, 6].
Inversions in the transformed array: (2, 3) since 8 > 6; others do not form inversions.
Output file /app/output.txt:
1