f b l=if null l then 0 else
      if(head l)==(last b)then f(b++[head l])(tail l)else
      2+if null ((tail l)++(init b)) then 0 else f[head b](tail ((init b)++(tail l)))
main=do
 l<-getLine
 print$f [head l](tail l)