Brainf*** to tinyBF converter You don't need to know these languages to participate. All necessary information has been provided in this question.

You should write a program or function which given a brainfuck (BF) code as input outputs its tinyBF equivalent.

BF has 8 instructions characters: +-&gt;&lt;[],. and tinyBF has 4: =+&gt;|. Converting works the following way: starting from the beginning of the BF code each symbol is replaced by on of its two tinyBF counterparts based on the number of = signs in the tinyBF code until that point (i.e. = behaves like a toggle switch).

The converter table (with columns: Brainfuck symbol;  tinyBF symbol(s) when ther are even ='s before; tinyBF symbol(s) when ther are odd ='s before):

BF   even    odd

+      +      =+
-     =+       +
&gt;      &gt;      =&gt;
&lt;     =&gt;       &gt;
[      |      =|
]     =|       |
.     ==      ==
,    |=|    =|=|


(This creates an almost unique tinyBF code. The only conflict occurs if the BF code contains a [] which is generally unused as it creates an infinite void loop.)

Input


An at least 1 byte long valid brainfuck program containing only the characters +-&gt;&lt;[],.
Guaranteed not to contain the string []
Trailing newline is optional.


Output


A tinyBF program.
Trailing newline is optional.


Examples

You can convert any BF program to tinyBF with this (1440 byte long) converter (see the Edit section for a small deviation).

Format is Input into Output

++-  into  ++=+
,[.,]  into  |=||==|=|=| or |=|=|==|=|| (both is acceptable check the Edit section)
&gt;++.--.[&lt;]+-,  into  &gt;++===++===|=&gt;|=+=+=|=|
&gt;++-+++++++[&lt;+++++++++&gt;-]&lt;.  into  &gt;++=+=+++++++|=&gt;=+++++++++&gt;=+|&gt;==


Edit

As @Jakube pointed out in the official tinyBF converter in the equivalents of the , BF instruction (|=| and =|=|) the last = signs aren't counted towards the toggle state. Both the official and mine interpretations are acceptable but you have to choose one.

This is code-golf so the shortest entry wins.
Extended BrainFuck 276 bytes

(not counting uneccesary linefeeds)

{a&lt;&lt;]&gt;&amp;c}{b&lt;&lt;-]&lt;[-&gt;}{c]&lt;]&gt;[&gt;[}{d 4+[-&lt;}3&gt;4-&gt;3-&gt;5-&gt;--&gt;&gt;&amp;d 4+&gt;]&lt;[-&lt;
4+&lt;3+&lt;4+&lt;8+4&gt;]&lt;[&lt;]&lt;&lt;,[&gt;3+&amp;d 6-&gt;]+&lt;-[-[-[-[14-[--[&gt;&amp;d 6-&gt;]+&lt;+[--[[
-]&gt;[-&amp;c&gt;.&amp;b&gt;&gt;.&lt;.&lt;+&amp;a-&gt;&gt;.&lt;.&amp;b&gt;.&lt;&amp;a-&gt;&gt;.&gt;&gt;.3&lt;&amp;b 4&gt;.4&lt;&amp;a 4&gt;.3&lt;&amp;b+&gt;&gt;.&gt;
&gt;.6&lt;]&gt;]&lt;]&gt;[-3&gt;..3&lt;&amp;c 3&gt;.&lt;&lt;&amp;b+&gt;&gt;.&gt;.3&lt;&amp;a&gt;&gt;.&lt;.&gt;.&lt;.&amp;b+&gt;.&gt;.&lt;.&lt;&amp;a-&gt;&gt;.&gt;.
&lt;&lt;&amp;b 3&gt;.5&lt;]&gt;]&lt;,]


How to compile and run:

beef ebf.bf &lt; tinybf.ebf &gt; tinybf.bf
beef tinybf.bf &lt; source.bf &gt; source.tbf


It will work with any wrapping BF interpreter that uses/support 0 as EOF.
Actual EBF source before golfing:

:i:f:o:p:e:a:g
$p ~"|=+&gt;"&lt;[&lt;]@o
$i,( $f+++++++(-$i------)+$i-; +
     ($i-; ,
       ($i-; -
         ($i-; .
           ($i--------------; &lt;
             ($i--; &gt;
               ($f++++(-$i------)+$i+; [
                 ($i--; ]
                   ((-) $f(-) )
                      $f ( $o[$p.$f-]&lt;[@f-$e.$p.$o+$i] ) ; ]
                  ) $f ( $o[-$e.$p.$f-]&lt;[@f-$p.$i] ) ; [
                ) $f ( $o[-$e.$g.$f-]&lt;[@f-$g.$i] ) ; &gt;
              ) $f ( $o[$g.$f-]&lt;[@f-$o+$e.$g.$i] ) ; &lt;
            ) $f (- $e.. ) ; .
          ) $f ( $o[$a.$f-]&lt;[@f-$o+$e.$a.$i] ) ; -
        ) $f ( $o[$e.$p.$e.$p.$f-]&lt;[@f-$o+$p.$e.$p.$i] ) ; ,
     ) $f ( $o[-$e.$a.$f-]&lt;[@f-$a.$i] ) ; +
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