
    Given historical ride-sharing demand patterns across n time intervals, where each value represents net passenger flow (pickups minus drop-offs), find the time window with maximum cumulative passenger demand when this pattern is projected over k consecutive periods. The demand pattern is assumed to repeat cyclically k times, and the selected time window can span across period boundaries.
    

    
def max_sub_array_sum_repeated(a, n, k):
    """
    Given historical ride-sharing demand patterns across n time intervals, where each value represents net passenger flow (pickups minus drop-offs), find the time window with maximum cumulative passenger demand when this pattern is projected over k consecutive periods. The demand pattern is assumed to repeat cyclically k times, and the selected time window can span across period boundaries.
    

    """
def max_sub_array_sum_repeated(a, n, k):
    """
    Given historical ride-sharing demand patterns across n time intervals, where each value represents net passenger flow (pickups minus drop-offs), find the time window with maximum cumulative passenger demand when this pattern is projected over k consecutive periods. The demand pattern is assumed to repeat cyclically k times, and the selected time window can span across period boundaries.
    

    """
    max_so_far = -2147483648
    max_ending_here = 0
    for i in range(n * k):
        max_ending_here = max_ending_here + a[i % n]
        if max_so_far < max_ending_here:
            max_so_far = max_ending_here
        if max_ending_here < 0:
            max_ending_here = 0
    return max_so_far