#include <iostream>
using namespace std;
int main( ) {
int n; // Количество ячеек
cin >> n;
char tape[ n] ;
for ( int i = 0 ; i < n; i++ )
tape[ i] = 0 ;
int pointer = 0 ;
string program = "" , tmp;
while ( cin >> tmp)
program + = tmp;
cin >> program;
//cout << program << endl;
for ( unsigned int i = 0 ; i < program.length ( ) ; i++ ) {
//cout << i << " " << program[i] << " " << pointer << " " << (int)tape[pointer] << endl;
if ( program[ i] == '>' )
pointer++ ;
if ( program[ i] == '<' )
pointer-- ;
if ( program[ i] == '+' )
tape[ pointer] ++ ;
if ( program[ i] == '-' )
tape[ pointer] -- ;
if ( program[ i] == '.' )
cout << tape[ pointer] ;
if ( program[ i] == ',' )
cin >> tape[ pointer] ;
if ( program[ i] == '[' ) {
if ( tape[ pointer] == 0 ) {
int counter = 1 ;
while ( counter > 0 ) {
i++ ;
if ( program[ i] == '[' )
counter++ ;
if ( program[ i] == ']' )
counter-- ;
}
}
}
else if ( program[ i] == ']' ) {
if ( tape[ pointer] ! = 0 ) {
int counter = 1 ;
while ( counter > 0 ) {
i-- ;
if ( program[ i] == '[' )
counter-- ;
if ( program[ i] == ']' )
counter++ ;
}
}
}
}
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbjsgLy8g0JrQvtC70LjRh9C10YHRgtCy0L4g0Y/Rh9C10LXQugoJY2luID4+IG47CgljaGFyIHRhcGVbbl07Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKCQl0YXBlW2ldID0gMDsKCWludCBwb2ludGVyID0gMDsKCXN0cmluZyBwcm9ncmFtID0gIiIsIHRtcDsKCXdoaWxlIChjaW4gPj4gdG1wKQoJCXByb2dyYW0gKz0gdG1wOwoJY2luID4+IHByb2dyYW07CgkvL2NvdXQgPDwgcHJvZ3JhbSA8PCBlbmRsOwoJZm9yICh1bnNpZ25lZCBpbnQgaSA9IDA7IGkgPCBwcm9ncmF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MgogIG91dHB1dCAjMTIgZXZlbiBpZiBpdCdzIHplcm8KICArKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysuWy1dCiAgJmx0OyZsdDsmbHQ7Jmx0OyZsdDsmbHQ7Jmx0OyZsdDsmbHQ7Jmx0OyZsdDsgIzEKCiAgY2hlY2sgZm9yIGZpbmFsIG51bWJlcgogIGNvcHkgIzAgdG8gIzMKICAmbHQ7WyZndDsmZ3Q7Jmd0OysmZ3Q7KyZsdDsmbHQ7Jmx0OyZsdDstXSZndDsmZ3Q7Jmd0OyZndDtbJmx0OyZsdDsmbHQ7Jmx0OysmZ3Q7Jmd0OyZndDsmZ3Q7LV0KICAmbHQ7LSAjMwogIGlmICMzIG91dHB1dCAoY29tbWEpIGFuZCAoc3BhY2UpCiAgWyZndDsmZ3Q7LiZndDsuJmx0OyZsdDsmbHQ7Wy1dXQogICZsdDsmbHQ7ICMxCgogIFsmZ3Q7Jmd0OysmZ3Q7KyZsdDsmbHQ7Jmx0Oy1dJmd0OyZndDsmZ3Q7WyZsdDsmbHQ7Jmx0OysmZ3Q7Jmd0OyZndDstXSZsdDsmbHQ7WyZsdDsrJmd0Oy1dJmd0O1smbHQ7KyZndDstXSZsdDsmbHQ7Jmx0Oy0KXQ==
30000
+++++++++++ number of digits to output
> #1
+ initial number
>>>> #5
++++++++++++++++++++++++++++++++++++++++++++ (comma)
> #6
++++++++++++++++++++++++++++++++ (space)
<<<<<< #0
[
> #1
copy #1 to #7
[>>>>>>+>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]
<
divide #7 by 10 (begins in #7)
[
>
++++++++++ set the divisor #8
[
subtract from the dividend and divisor
-<-
if dividend reaches zero break out
copy dividend to #9
[>>+>+<<<-]>>>[<<<+>>>-]
set #10
+
if #9 clear #10
<[>[-]<[-]]
if #10 move remaining divisor to #11
>[<<[>>>+<<<-]>>[-]]
jump back to #8 (divisor possition)
<<
]
if #11 is empty (no remainder) increment the quotient #12
>>> #11
copy to #13
[>>+>+<<<-]>>>[<<<+>>>-]
set #14
+
if #13 clear #14
<[>[-]<[-]]
if #14 increment quotient
>[<<+>>[-]]
<<<<<<< #7
]
quotient is in #12 and remainder is in #11
>>>>> #12
if #12 output value plus offset to ascii 0
[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]
subtract #11 from 10
++++++++++ #12 is now 10
< #11
[->-<]
> #12
output #12 even if it's zero
++++++++++++++++++++++++++++++++++++++++++++++++.[-]
<<<<<<<<<<< #1
check for final number
copy #0 to #3
<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]
<- #3
if #3 output (comma) and (space)
[>>.>.<<<[-]]
<< #1
[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-
]
stdout
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89