Determine a string's Scrabble score and validity Your task is to determine if a given string is of proper length and can be represented with Scrabble tiles and, if so, output the sum of each letter's score.

If you don't know how to play Scrabble:, you have 100 tiles with various letters A–Z printed on them, as well as two wildcards that can represent any letter. Each letter has a certain number of points, and each tile (but not necessarily word) can only be used once. When a word is played, the point value of each tile used is added up, which becomes the score. As there are a limited number of letters available, a word can only have a certain letter as many times as that letter has tiles + any unused wildcards. The Scrabble board is 15&times;15 cells, so the word must be between 2 and 15 characters long.

For a list of the quantity and score of each letter in the English version, see below or http://boardgames.about.com/od/scrabble/a/tile_distribute.htm (archive).


Letter  Qty  Points        Letter  Qty  Points
-------------------        -------------------
A       9    1             O       8    1
B       2    3             P       2    3
C       2    3             Q       1    10
D       4    2             R       6    1
E       12   1             S       4    1
F       2    4             T       6    1
G       3    2             U       4    1
H       2    4             V       2    4
I       9    1             W       2    4
J       1    8             X       1    8
K       1    5             Y       2    4
L       4    1             Z       1    10
M       2    3             [wild]  2    0
N       6    1


Further rules


The program shall take a single string of input from STDIN or the like.
The input will always contain only uppercase letters.
If the string contains more copies of a letter than there are unused wildcards or tiles for that letter OR the string's length is not between 2 and 15 inclusive, the program should output Invalid.
Otherwise, the score should be added up with using data from the chart above and output.
Do not use wildcards unless necessary.
Do not worry about bonuses such as double word scores or whether the string is a real word.
The program shall output the result through STDOUT or the like.
Loopholes that are forbidden by default are not allowed.
Using an external source such as a website, as well as any libraries, APIs, functions, or the like that calculate Scrabble scores or proper quantities are not alllowed.
This is code-golf, so fewest bytes wins.


Walkthrough

Input: CODEGOLF
C -&gt; 3, O -&gt; 1, D -&gt; 2, E -&gt; 1, G -&gt; 2, O -&gt; 1, L -&gt; 1, F -&gt; 4
3 + 1 + 2 + 1 + 2 + 1 + 1 + 4 = 15
Output: 15


Testcases


Input             Output
------------------------
SCRABBLE          14
JAZZ              19
STACKEXCHANGE     32
XYWFHQYVZVJKHFW   81
PIZZAZZ           Invalid
KIXOKEJAJAX       Invalid
MISUNDERSTANDING  Invalid
Perl 5 228 205 186 184 178 177 153 150 149 142 137 135

Run with perl -E.

Golfed:


$_=&lt;&gt;;@a=@b=map-ord,'            0 0@0 H        ``'=~/./g;say s!.!($a[$q=64-ord$&amp;]+=8)&lt;8?$-+=1-29/$b[$q]:++$j!ge~~[2..15]&amp;&amp;$j&lt;3?$-:Invalid


This solution uses some non-printable characters, so a hexdump is provided below:

00000000: 245f 3d3c 3e3b 4061 3d40 623d 6d61 702d  $_=&lt;&gt;;@a=@b=map-
00000010: 6f72 642c 2703 0904 0909 2030 2030 030e  ord,'..... 0 0..
00000020: 4030 0e20 0704 4809 1809 601d 0e0e 6027  @0. ..H...`...`'
00000030: 3d7e 2f2e 2f67 3b73 6179 2073 212e 2128  =~/./g;say s!.!(
00000040: 2461 5b24 713d 3634 2d6f 7264 2426 5d2b  $a[$q=64-ord$&amp;]+
00000050: 3d38 293c 383f 242d 2b3d 312d 3239 2f24  =8)&lt;8?$-+=1-29/$
00000060: 625b 2471 5d3a 2b2b 246a 2167 657e 7e5b  b[$q]:++$j!ge~~[
00000070: 322e 2e31 355d 2626 246a 3c33 3f24 2d3a  2..15]&amp;&amp;$j&lt;3?$-:
00000080: 496e 7661 6c69 64                        Invalid


Alternatively, using Ctrl+Key:

$_=&lt;&gt;;@a=@b=map-ord,'^C^I^D^I^I 0 0^C^N@0^N ^G^DH^I^X^I`^]^N^N`'=~/./g;print s!.!($a[$q=64-ord$&amp;]+=8)&lt;8?$-+=1-29/$b[$q]:++$j!ge~~[2..15]&amp;&amp;$j&lt;3?$-:Invalid


Ungolfed+commented:

# Read in input
$_=&lt;&gt;;
# @a and @b: represents approximately 8x the number of tiles (when rounded up). The 
#   non-multiple-of-8 values distinguish tiles that are given equally, but are worth
#  different values
@b=@a=map-ord,"...."~=/./g;
# above is equivalent to
# @a=@b=(-03,-09,-04,-09,-09,-32,-48,-32,-48,-03,-14,-64,-48,-14,-32,-07,-04,-72,-09,-24,-09,-96,-29,-14,-14,-96);
say
    # for each character
    s!.!
        # $q: A-&gt;-1, B-&gt;-2, etc.
        # decrement number of $q tiles, add points if needed, otherwise
        #    increment j, which counts number of wilds used
        # truncate(1-29/b[q]): decimal values were chosen specifically
        #    for this to return the point value. b[q] is the number of tiles
        #    of the qth letter after a originally given.
        #  $- contains the score, is initially zero (if in a one line program, 
        #   as the golfed version is), and is always an integer
        ($a[$q=64-ord$&amp;]+=8)&lt;8 ? $- += 1 - 29/$b[$q] : ++$j
    # s returns length, check if between 2 and 15
    !ge ~~ [2..15]
    # make sure less than 3 negative tiles (aka wilds) 
    &amp;&amp; $j &lt; 3 ?
        # print score
        $-
    # or invalid
    : Invalid