There are people in a market. Person :
A transaction consists of person buying the item owned by person . The transaction is allowed if and .
Each person may buy at most one item, and each person's item may be sold at most once. A person is allowed to sell their item and buy another person's item.
Find the maximum possible number of transactions.
Person can buy person 's item, and person can buy person 's item.
Two transactions are possible: person buys person 's item, and person buys person 's item. Person cannot buy another person's item.
Three transactions can be made by letting persons , , and buy the items of persons , , and , respectively. Four transactions are impossible because persons and would both need the only item they can buy from someone else, which is person 's item.
All five people can buy an item. In order, they may buy the items of persons , , , , and .