I.O.U.

题意翻译

题目描述 试着想象一下这里有一个三个好朋友组成的小团体:A,B和C。A欠B 20 卢布,B欠C 20 卢布。债务总额是 40 卢布。你可以发现债务并不是以最优的方式被管理起来的。让我们像这样排列债务:A欠C 20 卢布而B不负担任何债务。债务仍然是一样的,但是现在的债务总额只有 20 卢布。 这就是对示例的解释。现在想象你有一个小团体,这其中有n个人。我们用1-n给每个人编号。你知道每个人与人之间的债务。你需要在不改变债务含义的情况下优化它。换句话说,对于最后每个人,他应该收到的总资金和他应该付出的总资金之间的差必须相等。按照最优解输出所有债务的总和。请参照样例的注释来更好地理解问题。 翻译提供者:素锦年华

题目描述

Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The debts still mean the same but the total sum of the debts now equals 20 rubles. This task is a generalisation of a described example. Imagine that your group of friends has $ n $ people and you know the debts between the people. Optimize the given debts without changing their meaning. In other words, finally for each friend the difference between the total money he should give and the total money he should take must be the same. Print the minimum sum of all debts in the optimal rearrangement of the debts. See the notes to the test samples to better understand the problem.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ $ (1<=n<=100; 0<=m<=10^{4}) $ . The next $ m $ lines contain the debts. The $ i $ -th line contains three integers $ a_{i},b_{i},c_{i} $ $ (1<=a_{i},b_{i}<=n; a_{i}≠b_{i}; 1<=c_{i}<=100) $ , which mean that person $ a_{i} $ owes person $ b_{i} $ $ c_{i} $ rubles. Assume that the people are numbered by integers from 1 to $ n $ . It is guaranteed that the same pair of people occurs at most once in the input. The input doesn't simultaneously contain pair of people $ (x,y) $ and pair of people $ (y,x) $ .

输出格式


Print a single integer — the minimum sum of debts in the optimal rearrangement.

输入输出样例

输入样例 #1

5 3
1 2 10
2 3 1
2 4 1

输出样例 #1

10

输入样例 #2

3 0

输出样例 #2

0

输入样例 #3

4 3
1 2 1
2 3 1
3 1 1

输出样例 #3

0

说明

In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.