Insert semi-sorted into unsorted array Welcome to your first day at PPCG Inc. As our newest junior assistant document sorter, you are responsible for making sure all documents we sent down to you are archived in alphabetical order. It's so easy a monkey can do it. Well, metaphorically speaking, as we did hire a monkey to do it. Guess what? Turns out monkeys lack an understanding of our alphabet. Anyway, there's no time to fix the mess there is right now, so just try to not make the situation any worse, ok? Then get to it! If you get hungry, there's bananas over by the water cooler. Good luck!

Job Description

Input


You will receive a list of strings (the archive) and a string that needs to be added to that list (the document)
All strings will contain only uppercase letters, lowercase letters and spaces
Strings will always start and end with a letter


Task

Determine the target position of the document: the position it should receive in the archive. The target position can be determined as follows:


For each position:


Count the amount of strings in the archive before that position that are alphabetically before the document
Count the amount of strings in the archive after that position that are alphabetically after the document
Define the score of the position as the sum of the above two counts

The target position of the document is the position with the highest score
In case of a tie, all positions with the highest score are equally valid as target position. Only one needs to be selected.


When sorting:


Uppercase and lowercase letters are equivalent
Spaces come before letters


Output


The archive with the document added to it in any form


OR


The target position of the document, in either a 0-based or 1-based index


Job evaluation

Fewest bytes wins!

Example I/O

Archive:
    Applebuck Season
    Friendship is Magic
    The Ticket Master
    Griffon the BrushOff
    Boast Busters
    Bridle Gossip

Document: Dragonshy

Position scores (0-based index):
0: 0 + 3 = 3
1: 1 + 3 = 4
2: 1 + 2 = 3
3: 1 + 1 = 2
4: 1 + 0 = 1
5: 2 + 0 = 2
6: 3 + 0 = 3

Target position: 1
JavaScript (ES6), 81 bytes

(a,d)=&gt;a.map((e,i)=&gt;d[l="toLowerCase"]()&lt;e[l]()?s--:++s&gt;m&amp;&amp;(++m,p=++i),m=s=p=0)|p


Ungolfed:

function position(archive, document) {
    var score = 0;
    var max = 0;
    var pos = 0;
    var i = 0;
    while (i &lt; archive.length) {
        if (archive[i++].toLowerCase() &gt; document.toLowerCase()) {
            score--;
        } else {
            score++;
            if (score &gt; max) {
                max++;
                pos = i;
            }
        }
    }
    return pos;
}


Edit: Saved a lot of bytes thanks to @user81655.