Let's use these equations to assign values to each of the 17 (French) letters below:

A = any F = 13-3N O = 0 S = 2N-4 Z = 16-4N
C = A-5N-4 H = 4N-11 P = 2 T = 14-5N  
D = 2N I = 2N+4 Q = 2N+5-A U = 1-N  
E = 3N-5 N = any R = N-11 X = 6-4N  

Anywhere the word any appears, a random number can be entered. As a result, infinitely many solutions are possible, for example (for A=20 and N=7):

A C D E F H I N O P Q R S T U X Z
20 -19 14 16 -8 17 18 7 0 2 -1 -4 10 -21 -6 -22 -12

For all values assigned to the 17-letter alphabet in this way, the following applies:

Z+E+R+O = (16-4N) + (3N-5) + (N-11) + 0 = 0
U+N = (1-N) + N = 1
D+E+U+X = (2N) + (3N-5) + (1-N) + (6-4N) = 2
T+R+O+I+S = (14-5N) + (N-11) + 0 + (2N+4) + (2N-4) = 3
Q+U+A+T+R+E = (2N+5-A) + (1-N) + A + (14-5N) + (N-11) + (3N-5)
= 4
C+I+N+Q = (A-5N-4) + (2N+4) + N + (2N+5-A) = 5
S+I+X = (2N-4) + (2N+4) + (6-4N) = 6
S+E+P+T = (2N-4) + (3N-5) + 2 + (14-5N) = 7
H+U+I+T = (4-11N) + (1-N) + (2N+4) + (14-5N) = 8
N+E+U+F = N + (3N-5) + (1-N) + (13-3N) = 9
D+I+X = (2N) + (2N+4) + (6-4N) = 10
O+N+Z+E = 0 + N + (16-4N) + (3N-5) = 11
D+O+U+Z+E = (2N) + 0 + (1-N) + (16-4N) + (3N-5)
= 12
T+R+E+I+Z+E = (14-5N) + (N-11) + (3N-5) + (2N+4) + (16-4N) + (3N-5)
= 13

It can be shown that the above equations are the only ones that result in Z+E+R+O=0, U+N=1, …. Any extension of the French numbers beyond TREIZE is impossible without distinct letters receiving repeated values.

Assignment

We represent an alphabet as a sequence of uppercase letters (str) in which each letter appears at most once.

We represent the values assigned to the letters of an alphabet as a sequence (list or tuple) of integers (int). Each value corresponds to the letter at the corresponding position in the alphabet, so the number of values in the sequence must be equal to the number of letters in the alphabet.

A word is a sequence of uppercase letters (str) in which the same letter may appear more than once. We represent a sequence of words as a string (str) in which the words are separated from each other by commas (,).

Your task:

All of the above functions may assume that the given words only exist of uppercase letters from the given alphabet, without the need to check this explicitly.

Example

>>> french_alphabet = 'ACDEFHINOPQRSTUXZ'
>>> french_values = [20, -19, 14, 16, -8, 17, 18, 7, 0, 2, -1, -4, 10, -21, -6, -22, -12]
>>> french_numbers = 'ZERO,UN,DEUX,TROIS,QUATRE,CINQ,SIX,SEPT,HUIT,NEUF,DIX,ONZE,DOUZE,TREIZE'

>>> english_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> english_values = [-10, -14, 17, -6, -14, 17, 17, 5, -12, 6, 7, 18, 3, -6, -3, 15, -16, -15, -10, 11, -12, -13, -7, 20, -16, 17]
>>> english_numbers = 'ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN'

>>> word_value('ZERO', french_alphabet, french_values)
0
>>> word_value('UN', french_alphabet, french_values)
1
>>> word_value('DEUX', french_alphabet, french_values)
2
>>> word_value('TROIS', french_alphabet, french_values)
3
>>> word_value('QUATRE', french_alphabet, french_values)
4

>>> word_values(english_numbers, english_alphabet, english_values)
(-15, -23, 1, -27, -13, -22, -2, -57, 7, -38, -9)
>>> word_values(french_numbers, french_alphabet, french_values)
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
>>> word_values(french_numbers, english_alphabet, english_values)
(-15, -18, -12, -29, -56, -17, -2, 2, -8, -15, 2, -6, -18, -27)

>>> issorted((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13))
True
>>> issorted((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), strict=True)
True
>>> issorted((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), decreasing=True)
False
>>> issorted((0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), decreasing=True, strict=True)
False
>>> issorted((13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0), decreasing=True, strict=True)
True

>>> sort(english_numbers, english_alphabet, english_values)
['SEVEN', 'NINE', 'THREE', 'ONE', 'FIVE', 'ZERO', 'FOUR', 'TEN', 'SIX', 'TWO', 'EIGHT']
>>> sort(french_numbers, french_alphabet, french_values, True)
['TREIZE', 'DOUZE', 'ONZE', 'DIX', 'NEUF', 'HUIT', 'SEPT', 'SIX', 'CINQ', 'QUATRE', 'TROIS', 'DEUX', 'UN', 'ZERO']
>>> sort(french_numbers, english_alphabet, english_values, decreasing=True)
['SEPT', 'DIX', 'SIX', 'ONZE', 'HUIT', 'DEUX', 'ZERO', 'NEUF', 'CINQ', 'UN', 'DOUZE', 'TREIZE', 'TROIS', 'QUATRE']