I.O.U.

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

You are developing a new app intended to simplify expense-sharing among groups of friends.  This app will allow them to keep track of who encountered an expense and how it should be shared with others through the form of I.O.U.s.  For instance, if Alice pays for a meal shared with Bob and Carol, and Bob's and Carol's share were \\5andand\1010, respectively, then Bob would issue an I.O.U. over \\5toAliceandCarolwouldissueanI.O.U.overto Alice and Carol would issue an I.O.U. over\1010 to Alice.

Your app will maintain a ledger of who owes whom. Note that cycles can occur: For instance, if Bob initially owes Alice \\10andlaterpaysaand later pays a\55 expense on behalf of Alice, Alice would issue an I.O.U. over \\5toBob. ThisI.O.U.wouldthencancelout,orreduce,theI.O.U.AliceholdsfromBobfromto Bob.  This I.O.U. would then cancel out, or reduce, the I.O.U. Alice holds from Bob from\1010 to \\5.Itsalsopossibleforcyclestoinvolvemorethan. It's also possible for cycles to involve more than 2$ people.

Your app will be given a list of I.O.U.s issued and settle them as much as possible by considering all cycles and reducing each debt in a cycle by the minimum amount of debt occurring in the cycle. After all cycles are considered and canceled, your app should output who owes whom how much.  If there are multiple ways in which cancelation can occur, you may choose any of them as long as there are no cycles left at the end. However, you may not introduce I.O.U.s between friends that never gave an I.O.U. to each other, e.g., if Alice owes Bob money, and Bob owes the same amount to Carol, you cannot remove Bob from the picture and declare that Alice now owes Carol.

입력

The input consists of a single test case. The first line contains two integers nn and mm (1n100,0m10,0001 \le n \le 100, 0 \le m \le 10\\,000), where nn denotes the number of friends and mm denotes the number of I.O.U.s issued. Friends are numbered 00 to n1n-1. This is followed by mm lines containing three integers aa, bb, cc (0a<n,0b<n,ab,0<c1,0000 \le a < n, 0 \le b < n, a \ne b, 0 < c \le 1\\,000) denoting an I.O.U. given by friend aa to friend bb over cc dollars. Any friend ii holds at most one I.O.U. from any friend jj (iji \ne j), but friend ii may hold an I.O.U. from friend jj at the same time that friend jj holds an I.O.U from ii.

출력

First, output a single number pp, denoting the number of I.O.U.s left after canceling all cycles.  Then, on the following pp lines, output the I.O.U.s that are left in the same form in which they appear in the input (e.g. using 33 integers aa, bb, cc denoting that friend aa owes friend bb cc dollars).  Do not include any I.O.U.s fully canceled, i.e., all the I.O.U.s you output must have c>0c > 0.