#C3629. Longest Subarray with Sum Divisible by k

    ID: 47077 Type: Default 1000ms 256MiB

Longest Subarray with Sum Divisible by k

Longest Subarray with Sum Divisible by k

You are given an array of integers and an integer k. Your task is to find the longest contiguous subarray whose sum is divisible by k. If there are multiple subarrays with the same maximum length, return the one with the smallest starting index.

The subarray might be empty if no valid subarray exists.

Input/Output: The input is read from standard input (stdin) and the output should be written to standard output (stdout).

Note: If the resulting subarray is empty, print nothing (or an empty line).

inputFormat

The first line contains two integers, n and k, where n is the number of elements in the array and k is the divisor.

The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output the elements of the longest contiguous subarray (space-separated) whose sum is divisible by k in one line. If no such subarray exists, output an empty line.

## sample
6 3
2 7 6 1 4 5
7 6 1 4

</p>