Figuring that they cannot do worse than the humans have, Farmer John's cows have decided to start an airline. Being cows, they decide to cater to the heretofore-untapped market of cows as passengers. They plan to serve the cows who live along the western coast of Lake Michigan. Each morning, they will fly from the northern-most point of the coast southward towards Chicowgo, making many stops along the way. Each evening, they will fly back north to the northernmost point. They need your help to decide which passengers to carry each day. Each of farms numbered along the coast contains an airport (Farm is northern-most;farm is southern-most). On this day, groups of cows wish to travel. Each group of cows wants to fly from a particular farm to another particular farm. The airline, if it wishes, is allowed to stop and pick up only part of a group. Cows that start a flight, however, must stay on the plane until they reach their destination. Given the capacity of the airplane and the groups of cows that want to travel, determine the maximum number of cows that the airline can fly to their destination.
Lines : Each line contains three space-separated integers , and that specify a group of cows that wishes to travel. The cows are currently at farm and want to travel to farm .
第一行: 个用空格隔开的整数 , 和 。
第二到 行:每一行有 个用空格隔开的整数 ,,。 表示有 只奶牛想从农场 乘飞机到农场 。
输出格式
Line : The maximum number of cows that can be flown to their destination. This is the sum of the number of cows flown to their destination on the flight southward in the morning plus the number of cows flown to their destination on the flight northward in the evening.
可以完成旅行的奶牛人数的最大值。
样例
样例输入 #1
4 8 3
1 3 2
2 8 3
4 7 1
8 3 2
样例输出 #1
6
样例说明
INPUT DETAILS:
Four groups of cows, eight farms, and three seats on the plane.