Wasting the Class Fund

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 MB

Problem

Wookje 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 nn colors and Kkokkkoki comes in mm models. Wookje asked each of his kk 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?

Input

The first line contains the number of Ppokppoki colors nn, the number of Kkokkkoki models mm, and the number of friends kk. (1n,m1281 \le n, m \le 128, 1k5121 \le k \le 512)

Each of the next kk lines contains nin_i, mim_i, and cic_i. nin_i is a Ppokppoki color number (1nin1 \le n_i \le n) and mim_i is a Kkokkkoki model number (1mim1 \le m_i \le m). If cic_i is 0, the friend wants Ppokppoki nin_i bought and Kkokkkoki mim_i not bought. If cic_i is 1, the friend wants Kkokkkoki mim_i bought and Ppokppoki nin_i not bought.

Output

Print the minimum number of candies Wookje must prepare.