An equilateral triangle of side $n$ is divided into equilateral triangles of side $1$.  Find the greatest possible number of unit segments with endpoints at vertices of the small triangles that can be chosen so that no three of them are sides of a single triangle.