Orig Description
Complete Equality Bilateral Trade
The country of Aizu in cyberspace is engaged in information trade with the country of Wakamatsu. The two countries are achieving economic development by exchanging useful data with each other. Both countries, which have a national policy of philanthropy, equality, and above all, the old Aizu phrase "What cannot be done should not be done," conduct regular surveys of trade conditions.
In the survey, a table is given that calculates the value obtained by subtracting the outflow from the inflow of data from Aizu country in byte units every 1 nanosecond. From this table, find the longest interval whose total sum is zero. The longer this interval, the more equality is maintained.
Given a table that records the trade conditions, write a program to find the length of the longest interval whose sum is zero.
Input
The input is given in the following format.
N
d1
d2
:
dN
The number of values in the table N (1 ≤ N ≤ 200000) is given on the first line. The following N lines give the integer values di (-109 ≤ di ≤ 109) written in the i-th line of the table.
Output
Output the length of the longest interval whose sum is zero obtained from the table on a single line. If there is no such interval, output "0" on a single line.
Sample Input 1
5
18
102
-155
53
32
Sample Output 1
3
In the first example, the sum of the values from the second to the fourth rows becomes zero, so the longest interval becomes three.
Sample Input 2
4
1
1
-1
-1
Sample Output 2
4
In the second example, the sum of the second and third rows becomes zero, but the sum of the first to fourth rows also becomes zero, so the longest interval becomes four.
Extracted Specification
Canonicalized Input Description:
An integer N (1 ≤ N ≤ 200000), representing some quantity or size.
A list of N integers, each integer is between -10^9 and 10^9.
### Example Input:
```
5
18
102
-155
53
32
```
### Function Signature:
Write a function f(N, A) that takes in the input.
```python
def f(N: int, A: List[int]):
'''
N: an integer
A: a list of integers
'''
```
Test Case Generator
Certainly! Here is a Python test case generator for the "Complete Equality Bilateral Trade" problem. This generator will create random test cases within the given constraints.
```python
import random
def tcgen():
N = random.randint(1, 200000)
# Random integers between -10^9 and 10^9 for the table
d = [random.randint(-10**9, 10**9) for _ in range(N)]
return N, d
# Function to print the generated test case in the required format
def print_test_case():
N, d = tcgen()
print(N)
for value in d:
print(value)
# Example usage
if __name__ == "__main__":
print_test_case()
```
This function `tcgen()` generates a random value for \(N\) within the range [1, 200000] and a list of \(N\) integers, each between \(-10^9\) and \(10^9\). The `print_test_case` function prints the generated test case in the required format.
You can run this script to generate and print random test cases for the problem. This way, you can test the robustness and performance of your solution with various input sizes and values.
Extract Arguments
def extract_arguments(fh):
N = int(fh.readline().strip())
D = [int(fh.readline().strip()) for _ in range(N)]
return N, D