import java.util.*; import java.util.Map.Entry; class B{ static Scanner s = new Scanner(System.in); public static void main(String[] args) { int size = Integer.parseInt(s.next()); boolean[] buy = new boolean[size]; Product[] p = new Product[size]; for(int i=0;i0;--i) { int from=Integer.parseInt(s.next())-1, x =Integer.parseInt(s.next()), to =Integer.parseInt(s.next())-1; buy[to]=false; p[from].needs.put(p[to], x); } for(int i=0;i needs = new HashMap<>(); long memo=0; boolean explored=false; long getNeeds() { if(!explored) { explored=true; for(Entry e:needs.entrySet()) { memo+=e.getKey().getNeeds()*e.getValue(); } } return memo; } } class PerfectP extends Product{ @Override long getNeeds() { return 1; } }