using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
var histogram = new Dictionary<string, int>{{"ABC", 0}, {"ACB", 0}, {"BAC", 0}, {"BCA", 0}, {"CAB", 0}, {"CBA", 0}};
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k =0; k < 3; k++)
{
var sc = new SwappableChars("ABC");
sc.Swap(0, i); sc.Swap(1, j); sc.Swap(2, k);
histogram[sc.ToString()] += 1;
}
foreach (var x in histogram) Console.WriteLine("{0}: {1}", x.Key, x.Value);
}
}
public class SwappableChars
{
private char[] mChars;
public SwappableChars(string text)
{
mChars = text.ToCharArray();
}
public void Swap(int i, int j)
{
var hoge = mChars[i];
mChars[i] = mChars[j];
mChars[j] = hoge;
}
public override string ToString()
{
return new string(mChars);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKCmNsYXNzIFByb2dyYW0KewogICAgc3RhdGljIHZvaWQgTWFpbihzdHJpbmdbXSBhcmdzKQogICAgewogICAgICAgIHZhciBoaXN0b2dyYW0gPSBuZXcgRGljdGlvbmFyeTxzdHJpbmcsIGludD57eyJBQkMiLCAwfSwgeyJBQ0IiLCAwfSwgeyJCQUMiLCAwfSwgeyJCQ0EiLCAwfSwgeyJDQUIiLCAwfSwgeyJDQkEiLCAwfX07CiAgICAgICAgICAgIAogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCAzOyBpKyspCiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCAzOyBqKyspCiAgICAgICAgICAgICAgICBmb3IoaW50IGsgPTA7IGsgPCAzOyBrKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdmFyIHNjID0gbmV3IFN3YXBwYWJsZUNoYXJzKCJBQkMiKTsKICAgICAgICAgICAgICAgICAgICBzYy5Td2FwKDAsIGkpOyBzYy5Td2FwKDEsIGopOyBzYy5Td2FwKDIsIGspOwogICAgICAgICAgICAgICAgICAgIGhpc3RvZ3JhbVtzYy5Ub1N0cmluZygpXSArPSAxOwogICAgICAgICAgICAgICAgfQoKICAgICAgICBmb3JlYWNoICh2YXIgeCBpbiBoaXN0b2dyYW0pIENvbnNvbGUuV3JpdGVMaW5lKCJ7MH06IHsxfSIsIHguS2V5LCB4LlZhbHVlKTsKICAgIH0KfQoKcHVibGljIGNsYXNzIFN3YXBwYWJsZUNoYXJzCnsKICAgIHByaXZhdGUgY2hhcltdIG1DaGFyczsKCiAgICBwdWJsaWMgU3dhcHBhYmxlQ2hhcnMoc3RyaW5nIHRleHQpCiAgICB7CiAgICAgICAgbUNoYXJzID0gdGV4dC5Ub0NoYXJBcnJheSgpOwogICAgfQoKICAgIHB1YmxpYyB2b2lkIFN3YXAoaW50IGksIGludCBqKQogICAgewogICAgICAgIHZhciBob2dlID0gbUNoYXJzW2ldOwogICAgICAgIG1DaGFyc1tpXSA9IG1DaGFyc1tqXTsKICAgICAgICBtQ2hhcnNbal0gPSBob2dlOwogICAgfQoKICAgIHB1YmxpYyBvdmVycmlkZSBzdHJpbmcgVG9TdHJpbmcoKQogICAgewogICAgICAgIHJldHVybiBuZXcgc3RyaW5nKG1DaGFycyk7CiAgICB9Cn0=