Connecting Gaps with Tetris Pieces You should write a program or function which given a list of tetris blocks as input outputs or returns the biggest gap between two points in the same height level which the pieces can connect.

The 7 types of tetris pieces are the following:



We will refer to these pieces by the letters I, J, L, O, S, T and Z respectively, referring to their shapes. You can rotate the pieces but cannot mirror them just like in a Tetris game.

Our task is to create an orthogonally connected area (sides connected to sides) from the given pieces. This area should connect (also orthogonally) two unit squares which are at the same height. We should find the biggest possible gap between the two squares which we can bridge. 

Detailed examples

With the piece L we can connect a gap of 3

   L
XLLLX


With the piece S we can connect a gap of 2

  SS
XSSX


With the pieces S,S,O we can connect a gap of 7 (Note that we can't connect a gap of 8)

 S
XSSOO SSX
  SOOSS


Input


A string representing the available pieces containing only the uppercase letters I, J, L, O, S, T and Z. Every letter represents a complete tetris piece.
The letters will be in alphabetical order in the string.
The string will be at least one character long.


Output


A single positive integer, the biggest gap connectable with the given pieces.


Examples

Input => Output

OSS  =&gt;  7

LS  =&gt;  5

LZ  =&gt;  6

ZZZZ  =&gt;  10

LLSSS  =&gt;  14

IIJSSSTTZ  =&gt;  28

IISSSSSS  =&gt;  24

OOOSSSSSSSSSSSSTT  =&gt;  45

IJLOSTZ  =&gt;  21

IJLOSTZZZZZZZ  =&gt;  37

IIJLLLOSTT  =&gt;  31

IJJJOOSSSTTZ  =&gt;  35


This is code-golf so the shortest entry wins.
CJam, 53

'[,73&gt;qf{1$e=s':+\+~}:+3*I+O-SZ-JO+m0e&gt;ZS-LO+-e&gt;2+3/-


Try it online

The idea is: assign each of the I, J, ..., Z variables to be the number of occurences of that letter, and calculate string length * 3 + I - O. Then count the number of non-compensated S's or Z's: an S can be compensated by Z, J or O, and a Z can be compensated by S, L or O, and subtract ceil(that number/3), as we lose 1 unit for every 3 S's or Z's.