RNA to Protein Translation RNA, like DNA, is a molecule found in cells encoding genetic information. It consists of nucleotides, which are represented by the bases adenine (A), cytosine (C), guanine (G) and uracil (U).* A codon is a sequence of three nucleotides.

Proteins are large molecules which perform a vast array of functions, such as keratin which is found in hair and nails and hemoglobin which carries oxygen in blood cells.  They are made up of amino acids, which are encoded as codons in RNA molecules. Sometimes different codons may encode for the same amino acid. Each amino acid is commonly represented by a single letter, for example H stands for histidine.

Given a sequence of ACGU, can you translate it into the corresponding protein string?

* DNA consists of ACGT, where the T is thymine. During DNA to RNA transcription, thymine is replaced by uracil.



Input

Input will be a single string consisting of only the characters ACGU in upper case. You may write either a function or a full program for this challenge.

Output

You may choose to output via either printing or returning a string (the latter choice is only available in the case of a function).

Translation should begin at a start codon (AUG, represented as M) and end at a stop codon (one of UAA, UAG or UGA, represented as *). There are four cases where input may be invalid:


The input does not begin with a start codon
The input does not end with a stop codon
The input's length isn't a multiple of 3
The input contains a stop codon somewhere other than at the end


In all of these cases, Error should be outputted. Note that, unlike stop codons, start codons may appear after the start of the string.

Otherwise, you should convert each codon into its respective amino acid via the following RNA codon table:

* UAA UAG UGA
A GCU GCC GCA GCG
C UGU UGC
D GAU GAC
E GAA GAG
F UUU UUC
G GGU GGC GGA GGG
H CAU CAC
I AUU AUC AUA
K AAA AAG
L UUA UUG CUU CUC CUA CUG
M AUG
N AAU AAC
P CCU CCC CCA CCG
Q CAA CAG
R CGU CGC CGA CGG AGA AGG
S UCU UCC UCA UCG AGU AGC
T ACU ACC ACA ACG
V GUU GUC GUA GUG
W UGG
Y UAU UAC


...and output the translated string.

Examples

Invalid cases:

&lt;empty string&gt; -&gt; Error
AUG -&gt; Error
UAA -&gt; Error
AUGCUAG -&gt; Error
AAAAAAA -&gt; Error
GGGCACUAG -&gt; Error
AUGAACGGA -&gt; Error
AUGUAGUGA -&gt; Error
AUGUUUGUUCCGUCGAAAUACCUAUGAACACGCUAA -&gt; Error


Valid cases:

AUGUGA -&gt; M*
AUGAGGUGUAGCUGA -&gt; MRCS*
AUGGGUGAGAAUGAAACGAUUUGCAGUUAA -&gt; MGENETICS*
AUGCCAGUCGCACGAUUAGUUCACACGCUCUUGUAA -&gt; MPVARLVHTLL*
AUGCUGCGGUCCUCGCAUCUAGCGUUGUGGUUAGGGUGUGUAACUUCGAGAACAGUGAGUCCCGUACCAGGUAGCAUAAUGCGAGCAAUGUCGUACGAUUCAUAG -&gt; MLRSSHLALWLGCVTSRTVSPVPGSIMRAMSYDS*
AUGAAAAACAAGAAUACAACCACGACUAGAAGCAGGAGUAUAAUCAUGAUUCAACACCAGCAUCCACCCCCGCCUCGACGCCGGCGUCUACUCCUGCUUGAAGACGAGGAUGCAGCCGCGGCUGGAGGCGGGGGUGUAGUCGUGGUUUACUAUUCAUCCUCGUCUUGCUGGUGUUUAUUCUUGUUUUAA -&gt; MKNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVVYYSSSSCWCLFLF*


Edit: Added more test cases

Scoring

This is code golf, so the code in the fewest bytes wins.

Note: I'm no expert in molecular biology, so feel free to correct me if I've misstated anything :)
JavaScript (ES6) 167 177 chars encoded in UTF8 as 167 177 bytes

... so I hope everyone is happy.

Edit In fact, no need for a special case for last block too short. If the last 2 (or 1) chars are not mapped, the result string does not end with '*' and that gives error anyway. 

F=s=&gt;/^M[^*]*\*$/.test(s=s.replace(/.../g,x=&gt;
"KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF"
[[for(c of(r=0,x))r=r*4+"ACGU".search(c)]|r]))?s:'Error'


Explained

Each char in a triplet can have 4 values, so there are exactly 4^3 == 64 triplets. The C function map each triplet to a number between 0 and 63. No error check needed as input chars are only ACGU.

C=s=&gt;[for(c of(r=0,s))r=r*4+"ACGU".search(c)]|r


Each triplet maps to an aminoacid identified by a single char. We can encode this in a 64 character string. To obtain the string, start with the Codon Map:

zz=["* UAA UAG UGA","A GCU GCC GCA GCG","C UGU UGC","D GAU GAC","E GAA GAG"
,"F UUU UUC","G GGU GGC GGA GGG","H CAU CAC","I AUU AUC AUA","K AAA AAG"
,"L UUA UUG CUU CUC CUA CUG","M AUG","N AAU AAC","P CCU CCC CCA CCG","Q CAA CAG"
,"R CGU CGC CGA CGG AGA AGG","S UCU UCC UCA UCG AGU AGC","T ACU ACC ACA ACG"
,"V GUU GUC GUA GUG","W UGG","Y UAU UAC"]
a=[],zz.map(v=&gt;v.slice(2).split(' ').map(x=&gt;a[C(x)]=v[0])),a.join('')


...obtaining "KNKNTTTTRSRSIIMIQHQHPPPPRRRRLLLLEDEDAAAAGGGGVVVV*Y*YSSSS*CWCLFLF"

So we can scan the input string and use the same logic of the C function to obtain the code 0..63, and from the code the aminoacid char. The replace function wil split the input string in 3 chars blocks, eventually leaving 1 or 2 chars not managed (that will give an  invalid result string, not ending in '*').

At last, check if the encoded string is valid using a regexp: it must start with 'M', must not contain '*' and must end with '*'

Test In FireBug/FireFox console

;['AUGCUAG','GGGCACUAG','AUGAACGGA','AUGUAGUGA','AAAAAAA',
'AUGUUUGUUCCGUCGAAAUACCUAUGAACACGCUAA',
'AUGAGGUGUAGCUGA','AUGCCAGUCGCACGAUUAGUUCACACGCUCUUGUAA',
'AUGCUGCGGUCCUCGCAUCUAGCGUUGUGGUUAGGGUGUGUAACUUCGAGAACAGUGAGUCCCGUACCAGGUAGCAUAAUGCGAGCAAUGUCGUACGAUUCAUAG']
.forEach(c=&gt;console.log(c,'-&gt;',F(c)))


Output

AUGCUAG -&gt; Error
GGGCACUAG -&gt; Error
AUGAACGGA -&gt; Error
AUGUAGUGA -&gt; Error
AAAAAAA -&gt; Error
AUGUUUGUUCCGUCGAAAUACCUAUGAACACGCUAA -&gt; Error
AUGAGGUGUAGCUGA -&gt; MRCS*
AUGCCAGUCGCACGAUUAGUUCACACGCUCUUGUAA -&gt; MPVARLVHTLL*
AUGCUGCGGUCCUCGCAUCUAGCGUUGUGGUUAGGGUGUGUAACUUCGAGAACAGUGAGUCCCGUACCAGGUAGCAUAAUGCGAGCAAUGUCGUACGAUUCAUAG -&gt; MLRSSHLALWLGCVTSRTVSPVPGSIMRAMSYDS*