Each friend gives one of two opposite demands on a Ppokppoki color and a Kkokkkoki model; choose buys to maximize satisfied friends and report the rest.
Medium7GraphMinimum spanning treeGreedyUnion-findNo attempts yetTime limit2sMemory limit512 MBWookje has a mission! He has to decide what to buy with the class fund (taxes paid by the citizens of Seoul). Wookje is excited about wasting (?) the class fund, because it is not tax that he (a resident of Gyeonggi Province) paid. He picked two items well suited for wasting (?) money and decided to gather his friends' opinions on them. The two items are Ppokppoki (bubble wrap) and Kkokkkoki.


(Ppokppoki and Kkokkkoki)
Wookje's market research shows that Ppokppoki comes in n colors and Kkokkkoki comes in m models. Wookje asked each of his k friends: "Pick one Ppokppoki color you want to buy and one Kkokkkoki model you do not want to buy, or pick one Ppokppoki color you do not want to buy and one Kkokkkoki model you want to buy."
For each Ppokppoki color and each Kkokkkoki model, Wookje decides whether to buy it. A friend is satisfied only if both of their requests are respected. Wookje wants to satisfy as many friends as possible, but satisfying everyone is hard. So he will buy one candy for each friend who is not satisfied, as an apology. (The candy is also paid for with the class fund.)
What is the minimum number of candies Wookje must prepare?
The first line contains the number of Ppokppoki colors n, the number of Kkokkkoki models m, and the number of friends k. (1≤n,m≤128, 1≤k≤512)
Each of the next k lines contains ni, mi, and ci. ni is a Ppokppoki color number (1≤ni≤n) and mi is a Kkokkkoki model number (1≤mi≤m). If ci is 0, the friend wants Ppokppoki ni bought and Kkokkkoki mi not bought. If ci is 1, the friend wants Kkokkkoki mi bought and Ppokppoki ni not bought.
Print the minimum number of candies Wookje must prepare.