Bob found a vending machine that is broken, and he wants to make money from it. The machine has n positions, numbered 1 to n. Position i holds si snacks, one press of its button costs pi, and one snack from that position sells on the market for mi.
The machine is broken in a consistent way. When Bob presses the button at position i, the machine charges him pi and then dispenses one snack from position f(i) instead of position i. If position f(i) is already empty, Bob pays and receives nothing. A press at position i never reduces the number of snacks at position i; only the position the snack came out of loses one. Bob may press any button as many times as he likes, in any order, and he pays for every press.
Bob sells every snack he receives at its market price, and a snack that came out of position j sells for mj. He has enough money to pay for any number of presses. Find the largest net gain Bob can reach, that is, the total market price of the snacks he receives minus the total amount he pays. Pressing nothing at all is allowed.
The first line contains the number of positions n (1≤n≤105). Each of the next n lines describes one position, from position 1 to position n, with four integers f, p, m, s.
Print the largest net gain Bob can reach as a single integer on one line.