2xF is enough to store all elements of both A and B, but not enough to explicitly store all the pairings. That said, if you are just going to add a linear layer in order to produce one scalar of output, then 2xF should be fine, and this will do the job
C = torch.stack([A,B], dim=2)
C_2F = C.view(N, -1)