Multiple purchase dates for sale of K-1 units

I sold units of a publicly-traded partnership. I purchased the units on multiple dates with outright purchases and with reinvestment of distributions. Some of the gains/losses will be short-term, some long-term. How do I enter the different purchase dates with different costs?