#C14969. Count Common Items in Shopping Lists
Count Common Items in Shopping Lists
Count Common Items in Shopping Lists
You are given four shopping lists from different stores. Each list is a comma-separated string of items. Your task is to count how many lists (stores) each item appears in. In other words, if an item appears in multiple lists, its count increases by one for each unique list in which it appears.
You should assume that each list may contain duplicate items, but duplicates in the same list should be counted only once. The formula used is: \( count(item) = \sum_{i=1}^{4} I(item \in list_i) \) where \( I(\cdot) \) is the indicator function.
inputFormat
The input consists of four lines. Each line contains a comma-separated list of items. There will be a space after every comma. Read the four lines from standard input.
outputFormat
Output a JSON object representing the dictionary, where the keys are the item names and the values are the counts of lists in which the item appears. The keys in the JSON object should be sorted lexicographically. Write the output to standard output.
## sampleapples, bananas, carrots, dates
bananas, dates, eggs, figs
grapes, apples, bananas, eggs
carrots, dates, figs, apples
{"apples": 3, "bananas": 3, "carrots": 2, "dates": 3, "eggs": 2, "figs": 2, "grapes": 1}