All problems

Snack Pack Pairs

Easy · hash map

A shop sells snack packs. The list sizes gives the number of snacks in each pack: pack i holds sizes[i] snacks.

A gift box contains exactly two different packs. A box is shareable if its total number of snacks can be split equally between k friends with none left over, that is, the total is a multiple of k.

Return how many shareable boxes can be made. Two boxes are different if they use different pairs of positions i < j, even when the packs have the same sizes. If there are none, return 0.

Examples

Example 1

Input: sizes = [3, 5, 1, 7], k = 4

Output: 4

The boxes (3, 5), (3, 1), (5, 7) and (1, 7) hold 8, 4, 12 and 8 snacks. The other two hold 10 and 6.

Example 2

Input: sizes = [2, 2, 2], k = 4

Output: 3

Every pair of packs holds 4 snacks, and there are three pairs.

Example 3

Input: sizes = [1, 2, 3], k = 10

Output: 0

No pair adds up to a multiple of 10.

Constraints