using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chokudai
{
    class Program
    {
        static void Main(string[] args)
        {
            string command =
                @"ちょくちょくちょく　ちょくだいちょくだい　ちょく　だい
　ちょくだいちょく　ｎ
　ちょくちょく　答え　ちょく　だいちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょくちょく

　だいだいちょくちょく　だいだいだいだいだい　ｎ　ちょく　だいだい
　　ちょくだいちょく　あ
　　ちょくちょく　い　ちょく　だいだい

　　だいだいちょくちょく　ちょくちょくちょくだい　ちょくちょくだいだいだい　あ　ちょく　だいちょくだい　ちょく　だいちょく
　　　ちょくちょく　あ　ちょくちょくだいだい　あ　ちょく　だいちょくだい
　　　ちょくちょく　い　ちょくちょくちょくちょく　い　ちょく　だいちょく
　　だいちょくだいちょく

　　ちょくちょく　答え　最小値　答え　い
　　ちょくちょく　ｎ　ちょくちょくちょくだい　ｎ　ちょく　だいちょく
　だいちょくだいちょく

　だいちょく　答え
　だいちょく　だいだい　ちょく　だいちょくだい　だい　ちょくちょくだいちょく　だい　ちょくだいちょくだい
ちょくちょくだい

ちょくちょくちょく　最小値　ちょく　だいちょくだい　あ　い
　だいだいだいだい　だいだいだいだいだい　あ　い
　　ちょくだいだい　い
　だいだいちょくだい
　ちょくだいだい　あ
ちょくちょくだい";
            var commands = new List<string>();

            var tmp = command.Split(new char[] { '　', '\n' , '\r'});
            foreach (var s in tmp)
            {
                if (s != "") commands.Add(s);
            }

            Interpreter interpreter = new Interpreter(commands);
            interpreter.Run();
        }
    }
    partial class Interpreter
    {
        List<string> commands; // 読み込んだ命令
        Dictionary<string, dynamic> vars; // 変数名->値
        Dictionary<string, Function> funcs; // 関数名->(index(関数名を指す), 引数の数)
        Queue<string> input_que; // 受け取った入力を格納

        public Interpreter(List<string> _commands)
        {
            commands = _commands;
            vars = new Dictionary<string, dynamic>();
            funcs = new Dictionary<string, Function>();
            input_que = new Queue<string>();

            funcs.Add("ちょくちょくちょくちょく", new PrimitiveFunction(2, a => a[0] + a[1])); // 加算
            funcs.Add("ちょくちょくちょくだい", new PrimitiveFunction(2, a => a[0] - a[1])); // 減算
            funcs.Add("ちょくちょくだいちょく", new PrimitiveFunction(2, a => a[0] * a[1])); // 乗算
            funcs.Add("ちょくちょくだいだい", new PrimitiveFunction(2, a => a[0] / a[1])); // 除算
            funcs.Add("ちょくちょくだいだいだい", new PrimitiveFunction(2, a => a[0] % a[1])); // 余剰演算
            funcs.Add("だいだいだいだいだい", new PrimitiveFunction(2, a => BoolToInt(a[0] > a[1]))); // 大なり
            funcs.Add("だいだいだいだいちょく", new PrimitiveFunction(2, a => BoolToInt(a[0] == a[1]))); // イコール
        }

        // 関数を定義する
        void DefFunc(string name, List<string> commands)
        {
            var udf = new UserDefinedFunction(this, commands);
            funcs.Add(name, udf);
        }


        // 空白で区切られた文字の読み込み
        string ReadStr()
        {
            if (input_que.Count == 0)
            {
                var inputs = Console.ReadLine().Split();
                foreach (string s in inputs)
                {
                    input_que.Enqueue(s);
                }
            }
            return input_que.Dequeue();
        }

        // bool型をint型に変換
        static public int BoolToInt(bool a)
        {
            return a ? 1 : 0;
        }

        public void Run()
        {
            int now_index = 0;
            while (now_index < commands.Count)
            {
                string command = commands[now_index];
                now_index++;

                if (command == "ちょくちょくちょく")
                {
                    int func_begin = now_index;
                    string func_name = commands[now_index];
                    while (now_index < commands.Count && !(commands[now_index] == "ちょくちょくだい" && !(commands[now_index - 1] == "ちょく" || commands[now_index - 1] == "だい"))) now_index++;
                    int func_end = now_index;
                    var func_commands = commands.GetRange(func_begin, func_end - func_begin + 1);
                    DefFunc(func_name, func_commands);

                }
            }
            funcs["ちょくだいちょくだい"].Run(null);
        }
    }
    partial class Interpreter
    {
        // ユーザー定義関数とプリミティブな関数を同等に扱うためのもの
        abstract class Function
        {
            public int arg_num { get; protected set; }
            public abstract dynamic Run(dynamic[] args);
        }

        // ユーザー定義関数
        class UserDefinedFunction : Function
        {
            Interpreter interpreter; // 親er
            List<string> commands; // 命令
            Dictionary<string, dynamic> vars; // 変数名->値
            Dictionary<int, Tuple<int, int>> ifs; // ifのindex->(else ifのindex, 終了場所のindex)
            Dictionary<int, int> whiles; // whileのindex->終了場所のindex

            public UserDefinedFunction(Interpreter _interpreter, List<string> _commands)
            {
                interpreter = _interpreter;
                commands = _commands;
                ifs = new Dictionary<int, Tuple<int, int>>();
                whiles = new Dictionary<int, int>();

                int now_index = 1;
                arg_num = (int)GetInt(ref now_index);

                now_index += arg_num;

                var if_stack = new Stack<Queue<int>>();
                var while_stack = new Stack<int>();

                while (now_index < commands.Count)
                {
                    string command = commands[now_index];
                    if (command == "だいだいだいだい" && commands[now_index - 1] != "ちょく" && commands[now_index - 1] != "だい") // if
                    {
                        if_stack.Push(new Queue<int>());
                        if_stack.Peek().Enqueue(now_index);
                    }
                    else if (command == "だいだいだいちょく" && commands[now_index - 1] != "ちょく" && commands[now_index - 1] != "だい") // else if
                    {
                        if_stack.Peek().Enqueue(now_index);
                    }
                    else if (command == "だいだいちょくだい" && commands[now_index - 1] != "ちょく" && commands[now_index - 1] != "だい") // end if
                    {
                        int end = now_index;
                        var que = if_stack.Peek();
                        int fst = que.Dequeue();
                        while (que.Count != 0)
                        {
                            int snd = que.Dequeue();
                            ifs.Add(fst, new Tuple<int, int>(snd, end));
                            fst = snd;
                        }
                        ifs.Add(fst, new Tuple<int, int>(end, end));
                    }
                    else if (command == "だいだいちょくちょく" && commands[now_index - 1] != "ちょく" && commands[now_index - 1] != "だい") // while
                    {
                        while_stack.Push(now_index);
                    }
                    else if (command == "だいちょくだいちょく" && commands[now_index - 1] != "ちょく" && commands[now_index - 1] != "だい") // end while
                    {
                        int begin = while_stack.Pop();
                        int end = now_index;
                        whiles.Add(begin, end);
                    }
                    now_index++;
                }
            }

            // Getxxのnow_indexは終了時、xxを表すコマンドの直後のindexに変更される
            long GetInt(ref int now_index)
            {
                long ret = 0;
                now_index++;
                string s = commands[now_index];
                int i = (s[0] == 'ち' ? 3 : 2);
                while (i < s.Length)
                {
                    ret *= 2;
                    if (s[i] == 'ち')
                    {
                        ret++;
                        i += 3;
                    }
                    else
                    {
                        i += 2;
                    }
                }
                if (s[0] == 'ち') ret *= -1;
                now_index++;
                return ret;
            }
            char GetChar(ref int now_index)
            {
                int ret = 0;
                int i = 0;
                now_index++;
                string s = commands[now_index];
                while (i < s.Length)
                {
                    ret *= 2;
                    if (s[i] == 'ち')
                    {
                        ret++;
                        i += 3;
                    }
                    else
                    {
                        i += 2;
                    }
                }
                now_index++;
                return (char)ret;
            }
            string GetStr(ref int now_index)
            {
                now_index++;

                // 文字数読み込み
                int len = (int)GetVal(ref now_index); // 文字列の長さ

                // 文字読み込み
                string s = "";
                for (int i = 0; i < len; ++i)
                {
                    char ch = GetVal(ref now_index);
                    s += ch;
                }
                return s;
            }
            List<dynamic> GetList(ref int now_index)
            {
                now_index++;

                int len = GetVal(ref now_index);

                var list = new List<dynamic>();
                for (int i = 0; i < len; ++i)
                {
                    list.Add(GetVal(ref now_index));
                }
                return list;
            }

            // 任意の値を取得する　通常はこれを使う
            dynamic GetVal(ref int now_index)
            {
                string command = commands[now_index];
                if (command == "ちょく")
                {
                    return GetInt(ref now_index);
                }
                else if (command == "ちょくだい")
                {
                    return GetList(ref now_index);
                }
                else if (command == "だい")
                {
                    return GetChar(ref now_index);
                }
                else if (command == "だいだい")
                {
                    return GetStr(ref now_index);
                }
                else if (command == "だいだいちょくだいだい") // deque構築
                {
                    now_index++;
                    return new Deque<dynamic>();
                }
                else if (command == "だいちょくだいちょくだい") // priority_queue構築
                {
                    now_index++;
                    return new PriorityQueue<long>();
                }
                else if (command == "だいちょくちょく") // リストの要素数を求める
                {
                    ++now_index;
                    var list = GetVal(ref now_index);
                    int rank = GetVal(ref now_index);
                    for (int i = 0; i < rank; ++i)
                    {
                        list = list[GetVal(ref now_index)];
                    }
                    if (list is string) return list.Length;
                    return list.Count;
                }
                else if (command == "だいちょくだい") // ランダムアクセス
                {
                    ++now_index;
                    var list = GetVal(ref now_index);
                    int rank = (int)GetVal(ref now_index);
                    for (int i = 0; i < rank; ++i)
                    {
                        list = list[(int)GetVal(ref now_index)];
                    }
                    return list;
                }
                else if (command == "ちょくだいだいちょく") // 論理演算
                {
                    ++now_index;
                    string s = commands[now_index++];
                    int[] res = new int[4];
                    int t = 0;
                    for (int i = 0; i < 4; ++i)
                    {
                        if (s[t] == 'ち')
                        {
                            res[i] = 1;
                            t += 3;
                        }
                        else if (s[t] == 'だ')
                        {
                            res[i] = 0;
                            t += 2;
                        }
                    }
                    int a = Interpreter.BoolToInt(!EqualToZero(GetVal(ref now_index)));
                    int b = Interpreter.BoolToInt(!EqualToZero(GetVal(ref now_index)));
                    return res[a * 2 + b];
                }
                else if (command == "だいだいちょくだいちょく") // deq pop_front
                {
                    var deq = vars[commands[++now_index]];
                    now_index++;
                    return deq.PopFront();
                }
                else if (command == "だいだいちょくちょくだい") // deq pop_back
                {
                    var deq = vars[commands[++now_index]];
                    now_index++;
                    return deq.PopBack();
                }
                else if (command == "だいちょくだいちょくちょく") // pq pop
                {
                    var pq = vars[commands[++now_index]];
                    now_index++;
                    return pq.Pop();
                }
                else if (command == "だいちょくちょくだいちょく") // pq count
                {
                    var pq = vars[commands[++now_index]];
                    now_index++;
                    return pq.count;
                }
                else if (command == "だいちょくだいだいちょく") // deq count
                {
                    var deq = vars[commands[++now_index]];
                    now_index++;
                    return deq.count;
                }
                else if (interpreter.funcs.ContainsKey(command)) // 関数呼び出し
                {
                    now_index++;
                    return CallFunc(command, ref now_index);
                }
                else return vars[commands[now_index++]];
            }

            // 0と空文字列、空リストを0と見なす
            bool EqualToZero(dynamic val)
            {
                if (val is int || val is long || val is char) return val == 0;
                if (val is string) return val == "";
                return val.Count == 0;
            }

            // 関数呼び出し
            dynamic CallFunc(string name, ref int now_index)
            {
                var function = interpreter.funcs[name];
                int arg_num2 = function.arg_num;
                dynamic[] args2 = new dynamic[arg_num2];
                for (int i = 0; i < arg_num2; ++i)
                {
                    args2[i] = GetVal(ref now_index);
                }
                return function.Run(args2);
            }

            // 変数の定義or代入
            void SetVar(string name, dynamic val)
            {
                // すでに宣言されていたら代入
                if (vars.ContainsKey(name))
                {
                    vars[name] = val;
                }
                // 未定義なら変数を定義
                else
                {
                    vars.Add(name, val);
                }
            }

            // リストに要素を追加
            // index: 要素を追加する場所(デフォルトで末尾)
            void ListInsert(string name, int[] index, dynamic val)
            {
                var list = vars[name];
                int rank = index.Length;
                for (int i = 0; i < rank - 1; ++i)
                {
                    list = list[index[i]];
                }
                int id = index[rank - 1];
                if (id == -1) id = list.Count;
                list.Insert(id, val);
            }

            // リストの要素に値を代入
            void SetListElement(string name, int[] index, dynamic val)
            {
                var list = vars[name];
                int rank = index.Length;
                for (int i = 0; i < rank; ++i)
                {
                    list = list[index[i]];
                }
                list = val;
            }

            // リストから要素を削除
            // indexはListInsertに同じ
            void ListDelete(string name, int[] index)
            {
                var list = vars[name];
                int rank = index.Length;
                for (int i = 0; i < rank - 1; ++i)
                {
                    list = list[index[i]];
                }
                int id = index[rank - 1];
                list.RemoveAt((id < 0 ? list.Count - 1 : id));
            }

            public override dynamic Run(dynamic[] args)
            {
                vars = new Dictionary<string, dynamic>();
                var while_stack = new Stack<int>();
                var if_stack = new Stack<int>();
                int now_index = 3;

                // 引数を変数リストに格納
                for (int i = 0; i < arg_num; ++i)
                {
                    vars.Add(commands[now_index], args[i]);
                    now_index++;
                }

                while (true)
                {
                    string command = commands[now_index];
                    if (command == "ちょくちょくだい" && !(commands[now_index - 1] == "ちょく" || commands[now_index - 1] == "だい")) break;
                    now_index++;
                    if (command == "ちょくちょく") // 変数の定義or代入
                    {
                        string name = commands[now_index];
                        now_index++;
                        SetVar(name, GetVal(ref now_index));
                    }
                    else if (command == "だいだいだいだい") // if始まり
                    {
                        int begin = now_index - 1;
                        if (EqualToZero(GetVal(ref now_index))) now_index = (ifs[begin].Item1 == ifs[begin].Item2 ? ifs[begin].Item1 + 1 : ifs[begin].Item1);
                        else if_stack.Push(begin);
                    }
                    else if (command == "だいだいだいちょく") // else if
                    {
                        int begin = now_index - 1;
                        if (if_stack.Count == 0 || ifs[if_stack.Peek()].Item1 != begin)
                        {
                            if (EqualToZero(GetVal(ref now_index))) now_index = ifs[begin].Item1;
                            else if_stack.Push(begin);
                        }
                        else
                        {
                            now_index = ifs[if_stack.Pop()].Item2 + 1;
                        }
                    }
                    else if (command == "だいだいちょくだい") // if文終わり
                    {
                        if_stack.Pop();
                    }
                    else if (command == "だいだいちょくちょく") // while文始まり
                    {
                        int begin = now_index - 1;
                        if (EqualToZero(GetVal(ref now_index))) now_index = whiles[begin] + 1;
                        else while_stack.Push(begin);
                    }
                    else if (command == "だいちょくだいだい") // break
                    {
                        now_index = whiles[while_stack.Pop()];
                    }
                    else if (command == "だいちょくだいちょく") // while文終わり
                    {
                        now_index = while_stack.Pop();
                    }
                    else if (command == "ちょくだいちょく") // 数字の入力の受け取り
                    {
                        string name = commands[now_index];
                        SetVar(name, int.Parse(interpreter.ReadStr()));
                        now_index++;
                    }
                    else if (command == "ちょくだいだいだい") // 文字列の入力の受け取り
                    {
                        string name = commands[now_index];
                        SetVar(name, interpreter.ReadStr());
                        now_index++;
                    }
                    else if (command == "ちょくだいだいだいだい") // 一行丸々受け取り
                    {
                        string name = commands[now_index];
                        SetVar(name, Console.ReadLine());
                        now_index++;
                    }
                    else if (command == "だいちょく") // 標準出力
                    {
                        Console.Write(GetVal(ref now_index));
                    }
                    else if (command == "だいだいだい")
                    {
                        string name = commands[now_index++];
                        int rank = GetVal(ref now_index);
                        var list = vars[name];
                        for (int i = 0; i < rank - 1; ++i)
                        {
                            list = list[GetVal(ref now_index)];
                        }
                        int id = GetVal(ref now_index);
                        var val = GetVal(ref now_index);
                        list[id] = val;
                    }
                    else if (command == "だいちょくちょくちょく") // リストへの要素の追加
                    {
                        string name = commands[now_index++];
                        int rank = GetVal(ref now_index);
                        int[] index = new int[rank];
                        for (int i = 0; i < rank; ++i)
                        {
                            index[i] = GetVal(ref now_index);
                        }
                        dynamic element = GetVal(ref now_index);
                        ListInsert(name, index, element);
                    }
                    else if (command == "だいちょくちょくだい") // リストの要素の削除
                    {
                        string name = commands[now_index++];
                        int rank = GetVal(ref now_index);
                        int[] index = new int[rank];
                        for (int i = 0; i < rank; ++i)
                        {
                            index[i] = GetVal(ref now_index);
                        }
                        ListDelete(name, index);
                    }
                    else if (command == "だいだいだいちょくだい") // 昇順ソート
                    {
                        string name = commands[now_index++];
                        var list = vars[name];
                        list.Sort();
                    }
                    else if (command == "だいだいだいちょくちょく") //降順ソート
                    {
                        string name = commands[now_index++];
                        var list = vars[name];

                        list.Sort();
                        list.Reverse();
                    }
                    else if (command == "だいだいちょくだいちょく") // deq pop_front
                    {
                        var deq = vars[commands[now_index++]];
                        deq.PopFront();
                    }
                    else if (command == "だいだいちょくちょくだい") // deq pop_back
                    {
                        var deq = vars[commands[now_index++]];
                        deq.PopBack();
                    }
                    else if (command == "だいだいちょくちょくちょく") // deq push_front
                    {
                        var deq = vars[commands[now_index++]];
                        deq.PushFront(GetVal(ref now_index));
                    }
                    else if (command == "だいちょくだいだいだい") // deq push_back
                    {
                        var deq = vars[commands[now_index++]];
                        deq.PushBack(GetVal(ref now_index));
                    }
                    else if (command == "だいちょくだいちょくちょく") // pq pop
                    {
                        var pq = vars[commands[now_index++]];
                        pq.Pop();
                    }
                    else if (command == "だいちょくちょくだいだい") // pq push
                    {
                        var pq = vars[commands[now_index++]];
                        pq.Push(GetVal(ref now_index));
                    }
                    else if (command == "ちょくだいだい") // return
                    {
                        return GetVal(ref now_index);
                    }
                    else if (command == "ちょくちょくだい") // 関数の終了
                    {
                        return null;
                    }
                    else if (interpreter.funcs.ContainsKey(command)) // 関数呼び出し
                    {
                        CallFunc(command, ref now_index);
                    }
                    else if (vars.ContainsKey(command)) // 変数参照
                    {
                        GetVal(ref now_index);
                    }
                    else
                    {
                        throw new Exception($"no function or variable named {command} found.\n current index is {now_index - 1}.");
                    }
                }
                return null;
            }
        }

        // プリミティブな関数
        class PrimitiveFunction : Function
        {
            Func<dynamic[], dynamic> func;

            public PrimitiveFunction(int _arg_num, Func<dynamic[], dynamic> _func)
            {
                arg_num = _arg_num;
                func = _func;
            }

            public override dynamic Run(dynamic[] args)
            {
                return func(args);
            }
        }
    }
    class DequeElement<T>
    {
        public T val;
        public DequeElement<T> front, back;
        public DequeElement() { }
        public DequeElement(T _val, DequeElement<T> _front, DequeElement<T> _back)
        {
            val = _val;
            front = _front;
            back = _back;
        }
    }
    class Deque<T>
    {
        DequeElement<T> front, back;
        public int count { get; private set; }
        public Deque()
        {
            front = new DequeElement<T>();
            back = new DequeElement<T>();
            front.front = front;
            front.back = back;
            back.front = front;
            back.back = back;
            count = 0;
        }
        public T Front()
        {
            return front.back.val;
        }
        public T Back()
        {
            return back.front.val;
        }
        public T PopFront()
        {
            var deletion = front.back;
            front.back = deletion.back;
            deletion.back.front = front;
            count--;
            return deletion.val;
        }
        public T PopBack()
        {
            var deletion = back.front;
            back.front = deletion.front;
            deletion.front.back = back;
            count--;
            return deletion.val;
        }
        public void PushFront(T val)
        {
            var addition = new DequeElement<T>(val, front, front.back);
            front.back.front = addition;
            front.back = addition;
            count++;
        }
        public void PushBack(T val)
        {
            var addition = new DequeElement<T>(val, back.front, back);
            back.front.back = addition;
            back.front = addition;
            count++;
        }
    }
    class PriorityQueue<T> where T : IComparable
    {
        List<T> elements;
        public int count { get; private set; }
        public PriorityQueue()
        {
            elements = new List<T>();
            count = 0;
        }
        public T Front()
        {
            return elements[0];
        }
        public T Pop()
        {
            T ret = elements[0];
            count--;
            if (count != 0)
            {
                elements[0] = elements[count - 1];
                elements.RemoveAt(count - 1);
            }
            UpdateToLeaf(0);
            return ret;
        }
        public void Push(T val)
        {
            if (count >= elements.Count) elements.Add(val);
            else elements[count] = val;
            count++;
            UpdateToRoot(count - 1);
        }
        // 根から葉へ更新
        void UpdateToLeaf(int index)
        {
            int child = index * 2 + 1;
            if (child >= count) return;
            if ((child + 1 < count) && elements[child + 1].CompareTo(elements[child]) > 0) child += 1;
            if (elements[index].CompareTo(elements[child]) < 0)
            {
                T tmp = elements[index];
                elements[index] = elements[child];
                elements[child] = tmp;
                UpdateToLeaf(child);
            }
        }
        // 葉から根へ更新
        void UpdateToRoot(int index)
        {
            if (index == 0) return;
            int parent = (index - 1) / 2;
            if (elements[index].CompareTo(elements[parent]) > 0)
            {
                T tmp = elements[index];
                elements[index] = elements[parent];
                elements[parent] = tmp;
                UpdateToRoot(parent);
            }
        }
    }
}


Measured memory_bytes: 30408