for (int i = 0; i < n; i++)
{
    if (valCount.ContainsKey(x))
        valCount[x]++;
    else
        valCount[x] = 1;
}