So to sum up, for most railways, AC electrification is the cheaper, more efficient option.
There are exceptions, such as underground railways without room for overhead line, where use of a third rail close to the ground means voltage must be low for safety reasons. For a given voltage, DC contains more power than AC, so third rail systems are always DC.