Advertisement
Guest User

H.py

a guest
Jun 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. def main():
  2.     n = int(input())
  3.  
  4.     product_min = {}
  5.     product_current = {}
  6.  
  7.     for _ in range(n):
  8.         visit = input().split()
  9.         num_of_products = visit[0]
  10.         products = visit[1:]
  11.  
  12.         for p in product_current:
  13.             if p in products:
  14.                 product_min[p] = min(
  15.                     product_min.get(p, product_current[p]), product_current[p]
  16.                 )
  17.             else:
  18.                 product_current[p] += 1
  19.  
  20.         for p in products:
  21.             if p not in product_current:
  22.                 product_current[p] = 0
  23.  
  24.     print(len(product_min))
  25.     for p, v in sorted(product_min.items()):
  26.         print(p, v + 1)
  27.  
  28.  
  29. if __name__ == "__main__":
  30.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement