I have an array like this - 

```
string[] input = new string[] {"bRad", "Charles", "sam", "lukE", "vIctor"}

```

Now I wanted to sort this according to position of capital letter occurring in each string. The first occurrence is the only occurrence to consider while sorting. If two strings have CAPs at same position then sort them alphabetically, the same applies to strings which does not have any CAPs, sort them alphabetically.

What I have done so far is not performing well enough. I have tried countless times to improve it but with no luck. There's going to be huge amount data on which this is tested. So performance is of foremost importance. I'm using .NET 2.0 and I'm not allowed to use any higher versions.

```
public static int q, p, i, s;
public static Dictionary<string, int> a = new Dictionary<string, int>();

Array.Sort(input, delegate (string x, string y) {

    if (x == y)
        return 0;

    if (a.TryGetValue(x + "|" + y, out s))
        return s;

    if (a.TryGetValue(y + "|" + x, out s))
        return -s;

    q = x.Length;
    p = y.Length;

    for (i = 0; i < x.Length; i++)
    {
        if (x[i] < 91)
        {
            q = i;
            break;
        }
    }

    for (i = 0; i < y.Length; i++)
    {
        if (y[i] < 91)
        {
            p = i;
            break;
        }
    }

    if (q == x.Length && p == y.Length)
        s = x.CompareTo(y);
    else if (q > p)
        s = 1;
    else if (q < p)
        s = -1;
    else
        s = x.CompareTo(y);

    a.Add(x + "|" + y, s);

    return s;

});

```