Researchers at Meta have been working on a self-supervised learning model for images called DINO. However, not all researchers seem to be equally working on the model. In particular, Johnny, one of the researchers, has been getting easily distracted at the team meetings.
For example, during the presentation this morning, a slide with a neural network containing a fully-connected layer appeared, and Johnny decided to start counting the number of unique intersection points that exist between the edges in the layer. However, Johnny realizes that doing this manually will take forever, and now he wants you to help him count the intersection points for him!
A fully-connected linear layer can be represented as a set of $$$n$$$ input nodes and $$$m$$$ output nodes with straight-line edges connecting every pair of input and output nodes. The input nodes are equally spaced on a vertical line, and the output nodes are equally spaced on another vertical line.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 1000$$$) – the number of input nodes and the number of output nodes of the fully-connected linear layer, respectively.
Output a single integer, the number of unique intersection points between the edges in the fully-connected linear layer. Nodes do not count as intersection points of edges.
4 3
14
In the example test case, there are $$$4$$$ input nodes and $$$3$$$ output nodes. From the diagram above, observe that there are $$$14$$$ unique intersection points by manual inspection.