When loading, press .addBtn or .calculateBtn in functions that has such button:
```
<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BC961 Zero-Code Engine</title>
    <style>
        body {
            font-family: monospace;
            background-color: #f0f0f0;
            text-align: center;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 100vh;
        }

        h1 {
            margin-bottom: 20px;
        }

        #container {
            display: flex;
            width: 100%;
            border: 2px solid black;
        }

        #blocks {
            overflow-y: auto;
            padding: 10px;
            flex-grow: 1;
            background-color: #fff;
            border-right: 2px solid black;
        }

        #buttons {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            padding: 10px;
            background-color: #fff;
            width: 200px;
        }

        button {
            margin-bottom: 10px;
            padding: 10px 20px;
            font-size: 16px;
        }

        .block {
            margin: 10px 0;
            padding: 10px;
            border: 1px solid #ccc;
            background-color: #fafafa;
        }

        textarea {
            width: calc(100% - 20px);
            max-width: 100%;
            resize: none;
        }

        hr {
            margin: 20px 0;
            padding: 0;
            height: 0;
            border: none;
            color: black;
            width: 100%;
            border-top: 1px solid #333;
        }
    </style>
</head>

<body>
    <h1>BC961 Zero-Code Engine</h1>
    <div id="container">
        <div id="blocks"></div>

        <div id="buttons">
            <button id="addImageBlock">Add Image</button>
            <button id="addTextBlock">Add Text</button>
            <hr>
            <button id="addIntervalBlock">Add Interval</button>
            <hr>
            <button id="addInputBlock">Add Input</button>
            <button id="addIfStartBlock">Add IfStart</button>
            <button id="addIfEndBlock">Add IfEnd</button>
            <hr>
            <button id="addProgramStopBlock">Add Program Stop</button>
            <button id="addBreakBlock">Add Break</button>
            <hr>
            <button id="writeInCookieBlock">Write In Cookie</button>
            <button id="clearCookieBlock">Clear Cookie</button>
            <button id="addToCookieBlock">Add to Cookie</button>
            <button id="moveToCookieBlock">Move to Cookie</button>
            <button id="substractFromCookieBlock">Substract From Cookie</button>
            <button id="outputCharFromCookie">Output Char From Cookie</button>
            <button id="debugOutputFromCookie">Debug Output From Cookie</button>
            <button id="startCycle">Start Cycle</button>
            <button id="endCycle">End Cycle</button>
            <button id="returnToInitCookie">Return to Init Cookie</button>
            <button id="printCookieValue">Print Cookie Value</button>
            <button id="randomValue">Random Value</button>
            <button id="arythmeticExpression">Arythmetic Expression</button>
            <button id="moveValueToAnotherCookie">Move Value To Other Cookie</button>
            <button id="inWhichCookieAreWe">In Which Cookie Are We</button>
            <button id="copyValueToAnotherCookie">Copy Value To Other Cookie</button>
            <button id="moveToTheCookieAddressFromCurrentCookieAndTransferTheNumberOfTheCurrentCookie">Move To Cookie Address From Current Cookie</button>
            <button id="moveToTheCookieAddressFromCurrentCookie">Move To The Cookie Address From Current Cookie</button>
            <button id="writeAddressInCookie">Write Address In Cookie</button>
            <button id="addX">Add X[+/-0/1]</button>
            <button id="addM">Add M[+/-0/1]</button>
            <hr>
            <button id="saveBtn">Save Configuration</button>
            <button id="loadBtn">Load Configuration</button>
            <input type="file" id="loadInput" accept="application/json" style="display: none;">
            <hr>
            <button id="finishBtn">Finish</button>
            <hr>
            <p>BC961 Zero-Code Engine v1.2<br>Made by GDCocos @2024</p>
            <button id="downloadBtn" style="display: none;">Download Result</button>
            <button id="copyBtn" style="display: none;">Copy Result</button>
        </div>
    </div>

    <script>
        let result = `/* Made With BC961 Zero-Code Engine by GDCocos! */\n`;

        function convert(str) {
            let res = "";
            for (let i = 0; i < str.length; i++) {
                if (str[i] === "\n") {
                    res += ">";
                } else {
                    let tmp2 = str.charCodeAt(i);
                    while (tmp2 !== 0) {
                        if (tmp2 >= 10) {
                            res += "C";
                            tmp2 -= 10;
                        } else {
                            res += "c";
                            tmp2 -= 1;
                        }
                    }
                    res += "9L";
                }
            }
            return res;
        }

        function generateASCII(data, width, height) {
            const asciiChars = '@%#*+=-:. ';
            let asciiImage = '';
            for (let y = 0; y < height; y += 20) {
                for (let x = 0; x < width; x += 10) {
                    const index = (y * width + x) * 4;
                    const r = data[index];
                    const g = data[index + 1];
                    const b = data[index + 2];
                    const avg = (r + g + b) / 3;
                    const charIndex = Math.floor((avg / 255) * (asciiChars.length - 1));
                    asciiImage += asciiChars[charIndex];
                }
                asciiImage += '\n';
            }
            return asciiImage;
        }

        function addImageBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'ImageBlock');
            block.innerHTML = `
                <input type="file" accept="image/*">
                <button class="addBtn">Add Image</button>
                <hr>
            `;
            const fileInput = block.querySelector('input[type="file"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const file = fileInput.files[0];
                if (!file) return;
                const reader = new FileReader();
                reader.onload = (e) => {
                    const img = new Image();
                    img.onload = () => {
                        const canvas = document.createElement('canvas');
                        canvas.width = img.width;
                        canvas.height = img.height;
                        const ctx = canvas.getContext('2d');
                        ctx.drawImage(img, 0, 0);
                        const imageData = ctx.getImageData(0, 0, img.width, img.height).data;
                        const asciiImage = generateASCII(imageData, img.width, img.height);
                        result += "\n\n" + convert(asciiImage);
                        addButton.style.display = 'none';
                    };
                    img.src = e.target.result;
                    block.insertBefore(img, addButton);
                };
                reader.readAsDataURL(file);
            });
            document.getElementById('blocks').appendChild(block);
        }

        function addTextBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'TextBlock');
            block.innerHTML = `
                <textarea rows="4"></textarea>
                <button class="addBtn">Add Text</button>
                <hr>
            `;
            const textArea = block.querySelector('textarea');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const textValue = textArea.value.trim();
                if (textValue) {
                    result += "\n\n" + convert(textValue);
                }
                addButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function addIntervalBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'IntervalBlock');
            block.innerHTML = `
                <input type="number" placeholder="Enter interval in ms">
                <button class="addBtn">Add Interval</button>
                <hr>
            `;
            const intervalInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const intervalValue = intervalInput.value.trim();
                if (intervalValue) {
                    result += `\n\nS[${intervalValue}]`;
                }
                addButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function addIfStartBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'IfStartBlock');
            block.innerHTML = `
                <h2>Operation:</h2>
                <label><input type="radio" name="operation-${Date.now()}" value="Sum"> ></label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Difference"> <</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Multiply"> =</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Division"> ~</label><br>
                <h2>Values</h2>
                <label><input type="radio" name="pair-${Date.now()}" value="current_next"> Current and Next</label><br>
                <label><input type="radio" name="pair-${Date.now()}" value="current_previous"> Current and Previous</label><br>
                <label><input type="radio" name="pair-${Date.now()}" value="previous_next"> Previous and Next</label><br>
                <button class="addBtn">Add IfStart</button>
                <hr>
            `;
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const operation = block.querySelector('input[name^="operation"]:checked')?.value;
                const pair = block.querySelector('input[name^="pair"]:checked')?.value;
                if (!operation || !pair) {
                    alert('Please, choose.');
                    return;
                }
                switch (pair) {
                    case 'current_next':
                        if (operation === 'Sum') result += `\n\n(t > k ! `;
                        else if (operation === 'Difference') result += `\n\n(t < k ! `;
                        else if (operation === 'Multiply') result += `\n\n(t = k ! `;
                        else if (operation === 'Division') result += `\n\n(t ~ k ! `;
                        break;
                    case 'current_previous':
                        if (operation === 'Sum') result += `\n\n(t > i ! `;
                        else if (operation === 'Difference') result += `\n\n(t < i ! `;
                        else if (operation === 'Multiply') result += `\n\n(t = i ! `;
                        else if (operation === 'Division') result += `\n\n(t ~ i ! `;
                        break;
                    case 'previous_next':
                        if (operation === 'Sum') result += `\n\n(i > k ! `;
                        else if (operation === 'Difference') result += `\n\n(i < k ! `;
                        else if (operation === 'Multiply') result += `\n\n(i = k ! `;
                        else if (operation === 'Division') result += `\n\n(i ~ k ! `;
                        break;
                }
                addButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function addIfEndBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'IfEndBlock');
            block.innerHTML = `<strong>If Line Ended.</strong><hr>`;
            result += `\n)`;
            document.getElementById('blocks').appendChild(block);
        }

        function addInputBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'InputBlock');
            block.innerHTML = `<strong>Action Input</strong><hr>`;
            result += `\n\ne`;
            document.getElementById('blocks').appendChild(block);
        }

        function addProgramStopBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'ProgramStopBlock');
            block.innerHTML = `<strong>Stop Point</strong><hr>`;
            result += `-`;
            document.getElementById('blocks').appendChild(block);
        }

        function addBreakBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'BreakBlock');
            block.innerHTML = `<strong>Break Point</strong><hr>`;
            result += `_`;
            document.getElementById('blocks').appendChild(block);
        }

        function writeInCookieBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'WriteInCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <input type="number" placeholder="Value">
                <button class="addBtn">Write In Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]:nth-child(1)');
            const valueInput = block.querySelector('input[type="number"]:nth-child(2)');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                const value = valueInput.value.trim();
                if (cookieNumber && value) {
                    result += `\n\nN${"k".repeat(Number(cookieNumber))}L${"c".repeat(Number(value))}N`;
                    cookieNumberInput.value = '';
                    valueInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function clearCookieBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'ClearCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <button class="addBtn">Clear Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\nN${"k".repeat(Number(cookieNumber))}LN`;
                    cookieNumberInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function addToCookieBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'AddToCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <input type="number" placeholder="Value">
                <button class="addBtn">Add to Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]:nth-child(1)');
            const valueInput = block.querySelector('input[type="number"]:nth-child(2)');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                const value = valueInput.value.trim();
                if (cookieNumber && value) {
                    result += `\n\nN${"k".repeat(Number(cookieNumber))}${"c".repeat(Number(value))}N`;
                    cookieNumberInput.value = '';
                    valueInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function moveToCookieBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'MoveToCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <button class="addBtn">Move to Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\nN${"k".repeat(Number(cookieNumber))}`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function SubstractFromCookieBlock() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'SubtractFromCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <input type="number" placeholder="Value">
                <button class="addBtn">Substract From Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]:nth-child(1)');
            const valueInput = block.querySelector('input[type="number"]:nth-child(2)');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                const value = valueInput.value.trim();
                if (cookieNumber && value) {
                    result += `\n\nN${"k".repeat(Number(cookieNumber))}${"o".repeat(Number(value))}N`;
                    cookieNumberInput.value = '';
                    valueInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function outputCharFromCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'OutputCharFromCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <button class="addBtn">Output Char From Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\n9`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function debugOutputFromCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'DebugOutputFromCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Cookie Number">
                <button class="addBtn">Debug Output From Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\na`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function startCycle() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'StartCycleBlock');
            block.innerHTML = `<strong>Cycle Started.</strong><hr>`;
            result += `\n6`;
            document.getElementById('blocks').appendChild(block);
        }

        function endCycle() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'EndCycleBlock');
            block.innerHTML = `<strong>Cycle Ended.</strong><hr>`;
            result += `\n1`;
            document.getElementById('blocks').appendChild(block);
        }

        function returnToInitCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'ReturnToInitCookieBlock');
            block.innerHTML = `<strong>Returned to the Stack Start.</strong><hr>`;
            result += `\nN`;
            document.getElementById('blocks').appendChild(block);
        }

        function printCookieValue() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'PrintCookieValueBlock');
            block.innerHTML = `<strong>Cookie Value Printed.</strong><hr>`;
            result += `\nn`;
            document.getElementById('blocks').appendChild(block);
        }

        function randomValue() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'RandomValueBlock');
            block.innerHTML = `<strong>Random Value has been written into cookie.</strong><hr>`;
            result += `\nR`;
            document.getElementById('blocks').appendChild(block);
        }

        function arythmeticExpression() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'ArithmeticExpressionBlock');
            block.innerHTML = `
                <h2>Operation:</h2>
                <label><input type="radio" name="operation-${Date.now()}" value="Sum"> Sum</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Difference"> Difference</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Multiply"> Multiply</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Division"> Division</label><br>
                <h2>Values</h2>
                <label><input type="radio" name="pair-${Date.now()}" value="current_next"> Current and Next</label><br>
                <label><input type="radio" name="pair-${Date.now()}" value="current_previous"> Current and Previous</label><br>
                <label><input type="radio" name="pair-${Date.now()}" value="previous_next"> Previous and Next</label><br>
                <button class="calculateBtn">Add Arithmetic Expression</button>
                <hr>
            `;
            const calculateButton = block.querySelector('.calculateBtn');
            calculateButton.addEventListener('click', () => {
                const operation = block.querySelector('input[name^="operation"]:checked')?.value;
                const pair = block.querySelector('input[name^="pair"]:checked')?.value;
                if (!operation || !pair) {
                    alert('Please, choose.');
                    return;
                }
                switch (pair) {
                    case 'current_next':
                        if (operation === 'Sum') result += `\n\n{t + k}`;
                        else if (operation === 'Difference') result += `\n\n{t - k}`;
                        else if (operation === 'Multiply') result += `\n\n{t * k}`;
                        else if (operation === 'Division') result += `\n\n{t / k}`;
                        break;
                    case 'current_previous':
                        if (operation === 'Sum') result += `\n\n{t + i}`;
                        else if (operation === 'Difference') result += `\n\n{t - i}`;
                        else if (operation === 'Multiply') result += `\n\n{t * i}`;
                        else if (operation === 'Division') result += `\n\n{t / i}`;
                        break;
                    case 'previous_next':
                        if (operation === 'Sum') result += `\n\n{i + k}`;
                        else if (operation === 'Difference') result += `\n\n{i - k}`;
                        else if (operation === 'Multiply') result += `\n\n{i * k}`;
                        else if (operation === 'Division') result += `\n\n{i / k}`;
                        break;
                }
                calculateButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function moveValueToAnotherCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'MoveValueToAnotherCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Offset">
                <button class="addBtn">Move Value To Other Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const offset = cookieNumberInput.value.trim();
                if (offset) {
                    result += `\n\nM[${offset}]`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function inWhichCookieAreWe() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'InWhichCookieAreWeBlock');
            block.innerHTML = `<strong>Position output added.</strong><hr>`;
            result += `\ng`;
            document.getElementById('blocks').appendChild(block);
        }

        function copyValueToAnotherCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'CopyValueToAnotherCookieBlock');
            block.innerHTML = `
                <input type="number" placeholder="Offset">
                <button class="addBtn">Copy Value To Other Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const offset = cookieNumberInput.value.trim();
                if (offset) {
                    result += `\n\nX[${offset}]`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function moveToTheCookieAddressFromCurrentCookieAndTransferTheNumberOfTheCurrentCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'MoveToCookieAddressAndTransferNumberBlock');
            block.innerHTML = `<strong>Cookie Value Transferred.</strong><hr>`;
            result += `\nP`;
            document.getElementById('blocks').appendChild(block);
        }

        function moveToTheCookieAddressFromCurrentCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'MoveToCookieAddressBlock');
            block.innerHTML = `<strong>Moved to Cookie from Cookie Value.</strong><hr>`;
            result += `\nJ`;
            document.getElementById('blocks').appendChild(block);
        }

        function writeAddressInCookie() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'WriteAddressInCookieBlock');
            block.innerHTML = `<strong>Cookie Address has been written.</strong><hr>`;
            result += `\nG`;
            document.getElementById('blocks').appendChild(block);
        }

        function addX() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'AddXBlock');
            block.innerHTML = `
                <h2>Left Or Right:</h2>
                <label><input type="radio" name="operation-${Date.now()}" value="Sum"> -</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Difference"> +</label><br>
                <h2>Move Cursor or Not</h2>
                <label><input type="radio" name="pair-${Date.now()}" value="1"> 1</label><br>
                <label><input type="radio" name="pair-${Date.now()}" value="0"> 0</label><br>
                <button class="calculateBtn">Add x[+/-0/1]</button>
                <hr>
            `;
            const calculateButton = block.querySelector('.calculateBtn');
            calculateButton.addEventListener('click', () => {
                const direction = block.querySelector('input[name^="operation"]:checked')?.value;
                const moveCursor = block.querySelector('input[name^="pair"]:checked')?.value;
                if (!direction || !moveCursor) {
                    alert('Please, choose.');
                    return;
                }
                switch (moveCursor) {
                    case '1':
                        if (direction === 'Sum') result += `\n\nx[-1]`;
                        else if (direction === 'Difference') result += `\n\nx[+1]`;
                        break;
                    case '0':
                        if (direction === 'Sum') result += `\n\nx[-0]`;
                        else if (direction === 'Difference') result += `\n\nx[+0]`;
                        break;
                }
                calculateButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function addM() {
            const block = document.createElement('div');
            block.className = 'block';
            block.setAttribute('data-type', 'AddMBlock');
            block.innerHTML = `
                <h2>Left Or Right:</h2>
                <label><input type="radio" name="operation-${Date.now()}" value="Sum"> -</label><br>
                <label><input type="radio" name="operation-${Date.now()}" value="Difference"> +</label><br>
                <h2>Move Cursor or Not</h2>
                <label><input type="radio" name="pair-${Date.now()}" value="1"> 1</label><br>
                <label><input type="radio" name="pair-${Date.now()}" value="0"> 0</label><br>
                <button class="calculateBtn">Add m[+/-0/1]</button>
                <hr>
            `;
            const calculateButton = block.querySelector('.calculateBtn');
            calculateButton.addEventListener('click', () => {
                const direction = block.querySelector('input[name^="operation"]:checked')?.value;
                const moveCursor = block.querySelector('input[name^="pair"]:checked')?.value;
                if (!direction || !moveCursor) {
                    alert('Please, choose.');
                    return;
                }
                switch (moveCursor) {
                    case '1':
                        if (direction === 'Sum') result += `\n\nm[-1]`;
                        else if (direction === 'Difference') result += `\n\nm[+1]`;
                        break;
                    case '0':
                        if (direction === 'Sum') result += `\n\nm[-0]`;
                        else if (direction === 'Difference') result += `\n\nm[+0]`;
                        break;
                }
                calculateButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        document.getElementById('addImageBlock').addEventListener('click', addImageBlock);
        document.getElementById('addTextBlock').addEventListener('click', addTextBlock);
        document.getElementById('addIntervalBlock').addEventListener('click', addIntervalBlock);
        document.getElementById('addIfStartBlock').addEventListener('click', addIfStartBlock);
        document.getElementById('addIfEndBlock').addEventListener('click', addIfEndBlock);
        document.getElementById('addInputBlock').addEventListener('click', addInputBlock);
        document.getElementById('addProgramStopBlock').addEventListener('click', addProgramStopBlock);
        document.getElementById('addBreakBlock').addEventListener('click', addBreakBlock);
        document.getElementById('writeInCookieBlock').addEventListener('click', writeInCookieBlock);
        document.getElementById('clearCookieBlock').addEventListener('click', clearCookieBlock);
        document.getElementById('addToCookieBlock').addEventListener('click', addToCookieBlock);
        document.getElementById('moveToCookieBlock').addEventListener('click', moveToCookieBlock);
        document.getElementById('substractFromCookieBlock').addEventListener('click', SubstractFromCookieBlock);
        document.getElementById('outputCharFromCookie').addEventListener('click', outputCharFromCookie);
        document.getElementById('debugOutputFromCookie').addEventListener('click', debugOutputFromCookie);
        document.getElementById('startCycle').addEventListener('click', startCycle);
        document.getElementById('endCycle').addEventListener('click', endCycle);
        document.getElementById('returnToInitCookie').addEventListener('click', returnToInitCookie);
        document.getElementById('printCookieValue').addEventListener('click', printCookieValue);
        document.getElementById('randomValue').addEventListener('click', randomValue);
        document.getElementById('arythmeticExpression').addEventListener('click', arythmeticExpression);
        document.getElementById('moveValueToAnotherCookie').addEventListener('click', moveValueToAnotherCookie);
        document.getElementById('inWhichCookieAreWe').addEventListener('click', inWhichCookieAreWe);
        document.getElementById('copyValueToAnotherCookie').addEventListener('click', copyValueToAnotherCookie);
        document.getElementById('moveToTheCookieAddressFromCurrentCookieAndTransferTheNumberOfTheCurrentCookie').addEventListener('click', moveToTheCookieAddressFromCurrentCookieAndTransferTheNumberOfTheCurrentCookie);
        document.getElementById('moveToTheCookieAddressFromCurrentCookie').addEventListener('click', moveToTheCookieAddressFromCurrentCookie);
        document.getElementById('writeAddressInCookie').addEventListener('click', writeAddressInCookie);
        document.getElementById('addX').addEventListener('click', addX);
        document.getElementById('addM').addEventListener('click', addM);

        function saveState() {
            const blocks = [];
            document.querySelectorAll('#blocks .block').forEach((blockElement, index) => {
                const type = blockElement.getAttribute('data-type');
                const id = blockElement.id || `block-${index + 1}`;
                let data = {};
                switch (type) {
                    case 'ImageBlock':
                        const img = blockElement.querySelector('img');
                        data.imageUrl = img ? img.src : "";
                        data.description = "";
                        break;
                    case 'TextBlock':
                        const textarea = blockElement.querySelector('textarea');
                        data.content = textarea ? textarea.value : "";
                        break;
                    case 'IntervalBlock':
                        const intervalInput = blockElement.querySelector('input[type="number"]');
                        data.intervalMs = intervalInput ? parseInt(intervalInput.value, 10) : 0;
                        break;
                    case 'IfStartBlock':
                        const operation = blockElement.querySelector('input[name^="operation"]:checked')?.value;
                        const pair = blockElement.querySelector('input[name^="pair"]:checked')?.value;
                        data.operation = operation || "";
                        data.pair = pair || "";
                        break;
                    case 'IfEndBlock':
                        break;
                    case 'InputBlock':
                        break;
                    case 'ProgramStopBlock':
                        break;
                    case 'WriteInCookieBlock':
                        const writeCookieNumber = blockElement.querySelector('input[type="number"]:nth-child(1)')?.value || 0;
                        const writeValue = blockElement.querySelector('input[type="number"]:nth-child(2)')?.value || 0;
                        data.cookieNumber = parseInt(writeCookieNumber, 10);
                        data.value = parseInt(writeValue, 10);
                        break;
                    case 'ClearCookieBlock':
                        const clearCookieNumber = blockElement.querySelector('input[type="number"]')?.value || 0;
                        data.cookieNumber = parseInt(clearCookieNumber, 10);
                        break;
                    case 'AddToCookieBlock':
                        const addCookieNumber = blockElement.querySelector('input[type="number"]:nth-child(1)')?.value || 0;
                        const addValue = blockElement.querySelector('input[type="number"]:nth-child(2)')?.value || 0;
                        data.cookieNumber = parseInt(addCookieNumber, 10);
                        data.value = parseInt(addValue, 10);
                        break;
                    case 'MoveToCookieBlock':
                        const moveCookieNumber = blockElement.querySelector('input[type="number"]')?.value || 0;
                        data.cookieNumber = parseInt(moveCookieNumber, 10);
                        break;
                    case 'SubtractFromCookieBlock':
                        const subtractCookieNumber = blockElement.querySelector('input[type="number"]:nth-child(1)')?.value || 0;
                        const subtractValue = blockElement.querySelector('input[type="number"]:nth-child(2)')?.value || 0;
                        data.cookieNumber = parseInt(subtractCookieNumber, 10);
                        data.value = parseInt(subtractValue, 10);
                        break;
                    case 'OutputCharFromCookieBlock':
                        const outputCookieNumber = blockElement.querySelector('input[type="number"]')?.value || 0;
                        data.cookieNumber = parseInt(outputCookieNumber, 10);
                        break;
                    case 'DebugOutputFromCookieBlock':
                        const debugCookieNumber = blockElement.querySelector('input[type="number"]')?.value || 0;
                        data.cookieNumber = parseInt(debugCookieNumber, 10);
                        break;
                    case 'StartCycleBlock':
                        break;
                    case 'EndCycleBlock':
                        break;
                    case 'ReturnToInitCookieBlock':
                        break;
                    case 'PrintCookieValueBlock':
                        break;
                    case 'RandomValueBlock':
                        break;
                    case 'ArithmeticExpressionBlock':
                        const arithOperation = blockElement.querySelector('input[name^="operation"]:checked')?.value || "";
                        const arithPair = blockElement.querySelector('input[name^="pair"]:checked')?.value || "";
                        data.operation = arithOperation;
                        data.pair = arithPair;
                        break;
                    case 'MoveValueToAnotherCookieBlock':
                        const offsetMove = blockElement.querySelector('input[type="number"]')?.value || 0;
                        data.offset = parseInt(offsetMove, 10);
                        break;
                    case 'InWhichCookieAreWeBlock':
                        break;
                    case 'CopyValueToAnotherCookieBlock':
                        const offsetCopy = blockElement.querySelector('input[type="number"]')?.value || 0;
                        data.offset = parseInt(offsetCopy, 10);
                        break;
                    case 'MoveToCookieAddressAndTransferNumberBlock':
                        break;
                    case 'MoveToCookieAddressBlock':
                        break;
                    case 'WriteAddressInCookieBlock':
                        break;
                    case 'AddXBlock':
                        const xDirection = blockElement.querySelector('input[name^="operation"]:checked')?.value || "";
                        const xMoveCursor = blockElement.querySelector('input[name^="pair"]:checked')?.value || "";
                        data.direction = xDirection;
                        data.moveCursor = xMoveCursor;
                        break;
                    case 'AddMBlock':
                        const mDirection = blockElement.querySelector('input[name^="operation"]:checked')?.value || "";
                        const mMoveCursor = blockElement.querySelector('input[name^="pair"]:checked')?.value || "";
                        data.direction = mDirection;
                        data.moveCursor = mMoveCursor;
                        break;
                }
                blocks.push({ id, type, data });
            });
            const saveObject = { blocks };
            const json = JSON.stringify(saveObject, null, 2);
            const saveContainer = document.createElement('div');
            saveContainer.style.position = 'fixed';
            saveContainer.style.top = '50%';
            saveContainer.style.left = '50%';
            saveContainer.style.transform = 'translate(-50%, -50%)';
            saveContainer.style.backgroundColor = '#fff';
            saveContainer.style.padding = '20px';
            saveContainer.style.border = '2px solid #000';
            saveContainer.style.zIndex = '1000';
            saveContainer.innerHTML = `
                <h2>Save Configuration</h2>
                <textarea id="saveTextArea" rows="15" cols="50">${json}</textarea><br><br>
                <button id="downloadSaveBtn">Download JSON</button>
                <button id="copySaveBtn">Copy to Clipboard</button>
                <button id="closeSaveBtn">Close</button>
            `;
            document.body.appendChild(saveContainer);
            document.getElementById('downloadSaveBtn').addEventListener('click', () => {
                const blob = new Blob([json], { type: 'application/json' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'bc961_save.json';
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                URL.revokeObjectURL(url);
            });
            document.getElementById('copySaveBtn').addEventListener('click', () => {
                const textArea = document.getElementById('saveTextArea');
                textArea.select();
                textArea.setSelectionRange(0, 99999);
                navigator.clipboard.writeText(textArea.value).then(() => {
                    alert("Configuration copied to clipboard!");
                }).catch(err => {});
            });
            document.getElementById('closeSaveBtn').addEventListener('click', () => {
                document.body.removeChild(saveContainer);
            });
        }

        function createImageBlock(id, imageUrl, description) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'ImageBlock');
            block.innerHTML = `
                <input type="file" accept="image/*">
                ${imageUrl ? `<img src="${imageUrl}" alt="Loaded Image" style="max-width: 100px; display: block; margin-top: 10px;">` : ''}
                <button class="addBtn">Add Image</button>
                <hr>
            `;
            if (imageUrl) {
                const addButton = block.querySelector('.addBtn');
                addButton.style.display = 'none';
            }
            const fileInput = block.querySelector('input[type="file"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const file = fileInput.files[0];
                if (!file) return;
                const reader = new FileReader();
                reader.onload = (e) => {
                    const img = new Image();
                    img.onload = () => {
                        const canvas = document.createElement('canvas');
                        canvas.width = img.width;
                        canvas.height = img.height;
                        const ctx = canvas.getContext('2d');
                        ctx.drawImage(img, 0, 0);
                        const imageData = ctx.getImageData(0, 0, img.width, img.height).data;
                        const asciiImage = generateASCII(imageData, img.width, img.height);
                        result += "\n\n" + convert(asciiImage);
                        addButton.style.display = 'none';
                    };
                    img.src = e.target.result;
                    block.insertBefore(img, addButton);
                };
                reader.readAsDataURL(file);
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createTextBlock(id, content) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'TextBlock');
            block.innerHTML = `
                <textarea rows="4">${content}</textarea>
                <button class="addBtn">Add Text</button>
                <hr>
            `;
            const textArea = block.querySelector('textarea');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const textValue = textArea.value.trim();
                if (textValue) {
                    result += "\n\n" + convert(textValue);
                }
                addButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createIntervalBlock(id, intervalMs) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'IntervalBlock');
            block.innerHTML = `
                <input type="number" value="${intervalMs}" placeholder="Enter interval in ms">
                <button class="addBtn">Add Interval</button>
                <hr>
            `;
            const intervalInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const intervalValue = intervalInput.value.trim();
                if (intervalValue) {
                    result += `\n\nS[${intervalValue}]`;
                }
                addButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createIfStartBlock(id, operation, pair) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'IfStartBlock');
            block.innerHTML = `
                <h2>Operation:</h2>
                <label><input type="radio" name="operation-${id}" value="Sum" ${operation === 'Sum' ? 'checked' : ''}> ></label><br>
                <label><input type="radio" name="operation-${id}" value="Difference" ${operation === 'Difference' ? 'checked' : ''}> <</label><br>
                <label><input type="radio" name="operation-${id}" value="Multiply" ${operation === 'Multiply' ? 'checked' : ''}> =</label><br>
                <label><input type="radio" name="operation-${id}" value="Division" ${operation === 'Division' ? 'checked' : ''}> ~</label><br>
                <h2>Values</h2>
                <label><input type="radio" name="pair-${id}" value="current_next" ${pair === 'current_next' ? 'checked' : ''}> Current and Next</label><br>
                <label><input type="radio" name="pair-${id}" value="current_previous" ${pair === 'current_previous' ? 'checked' : ''}> Current and Previous</label><br>
                <label><input type="radio" name="pair-${id}" value="previous_next" ${pair === 'previous_next' ? 'checked' : ''}> Previous and Next</label><br>
                <button class="addBtn">Add IfStart</button>
                <hr>
            `;
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                if (!operation || !pair) {
                    alert('Please, choose.');
                    return;
                }
                switch (pair) {
                    case 'current_next':
                        if (operation === 'Sum') result += `\n\n(t > k ! `;
                        else if (operation === 'Difference') result += `\n\n(t < k ! `;
                        else if (operation === 'Multiply') result += `\n\n(t = k ! `;
                        else if (operation === 'Division') result += `\n\n(t ~ k ! `;
                        break;
                    case 'current_previous':
                        if (operation === 'Sum') result += `\n\n(t > i ! `;
                        else if (operation === 'Difference') result += `\n\n(t < i ! `;
                        else if (operation === 'Multiply') result += `\n\n(t = i ! `;
                        else if (operation === 'Division') result += `\n\n(t ~ i ! `;
                        break;
                    case 'previous_next':
                        if (operation === 'Sum') result += `\n\n(i > k ! `;
                        else if (operation === 'Difference') result += `\n\n(i < k ! `;
                        else if (operation === 'Multiply') result += `\n\n(i = k ! `;
                        else if (operation === 'Division') result += `\n\n(i ~ k ! `;
                        break;
                }
                addButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createIfEndBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'IfEndBlock');
            block.innerHTML = `<strong>If Line Ended.</strong><hr>`;
            result += `\n)`;
            document.getElementById('blocks').appendChild(block);
        }

        function createInputBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'InputBlock');
            block.innerHTML = `<strong>Action Input</strong><hr>`;
            result += `\n\ne`;
            document.getElementById('blocks').appendChild(block);
        }

        function createProgramStopBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'ProgramStopBlock');
            block.innerHTML = `<strong>Stop Point</strong><hr>`;
            result += `-`;
            document.getElementById('blocks').appendChild(block);
        }

        function createBreakBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'BreakBlock');
            block.innerHTML = `<strong>Break Point</strong><hr>`;
            result += `_`;
            document.getElementById('blocks').appendChild(block);
        }

        function createWriteInCookieBlock(id, cookieNumber, value) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'WriteInCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <input type="number" value="${value}" placeholder="Value">
                <button class="addBtn">Write In Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]:nth-child(1)');
            const valueInput = block.querySelector('input[type="number"]:nth-child(2)');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                const value = valueInput.value.trim();
                if (cookieNumber && value) {
                    result += `\n\n${"k".repeat(Number(cookieNumber))}L${"c".repeat(Number(value))}N`;
                    cookieNumberInput.value = '';
                    valueInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createClearCookieBlock(id, cookieNumber) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'ClearCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <button class="addBtn">Clear Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\n${"k".repeat(Number(cookieNumber))}LN`;
                    cookieNumberInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createAddToCookieBlock(id, cookieNumber, value) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'AddToCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <input type="number" value="${value}" placeholder="Value">
                <button class="addBtn">Add to Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]:nth-child(1)');
            const valueInput = block.querySelector('input[type="number"]:nth-child(2)');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                const value = valueInput.value.trim();
                if (cookieNumber && value) {
                    result += `\n\n${"k".repeat(Number(cookieNumber))}${"c".repeat(Number(value))}N`;
                    cookieNumberInput.value = '';
                    valueInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createMoveToCookieBlock(id, cookieNumber) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'MoveToCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <button class="addBtn">Move to Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\n${"k".repeat(Number(cookieNumber))}`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createSubtractFromCookieBlock(id, cookieNumber, value) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'SubtractFromCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <input type="number" value="${value}" placeholder="Value">
                <button class="addBtn">Substract From Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]:nth-child(1)');
            const valueInput = block.querySelector('input[type="number"]:nth-child(2)');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                const value = valueInput.value.trim();
                if (cookieNumber && value) {
                    result += `\n\n${"k".repeat(Number(cookieNumber))}${"o".repeat(Number(value))}N`;
                    cookieNumberInput.value = '';
                    valueInput.value = '';
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createOutputCharFromCookieBlock(id, cookieNumber) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'OutputCharFromCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <button class="addBtn">Output Char From Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\n9`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createDebugOutputFromCookieBlock(id, cookieNumber) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'DebugOutputFromCookieBlock');
            block.innerHTML = `
                <input type="number" value="${cookieNumber}" placeholder="Cookie Number">
                <button class="addBtn">Debug Output From Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const cookieNumber = cookieNumberInput.value.trim();
                if (cookieNumber) {
                    result += `\n\na`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createStartCycleBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'StartCycleBlock');
            block.innerHTML = `<strong>Cycle Started.</strong><hr>`;
            result += `\n6`;
            document.getElementById('blocks').appendChild(block);
        }

        function createEndCycleBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'EndCycleBlock');
            block.innerHTML = `<strong>Cycle Ended.</strong><hr>`;
            result += `\n1`;
            document.getElementById('blocks').appendChild(block);
        }

        function createReturnToInitCookieBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'ReturnToInitCookieBlock');
            block.innerHTML = `<strong>Returned to the Stack Start.</strong><hr>`;
            result += `\nN`;
            document.getElementById('blocks').appendChild(block);
        }

        function createPrintCookieValueBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'PrintCookieValueBlock');
            block.innerHTML = `<strong>Cookie Value Printed.</strong><hr>`;
            result += `\nn`;
            document.getElementById('blocks').appendChild(block);
        }

        function createRandomValueBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'RandomValueBlock');
            block.innerHTML = `<strong>Random Value has been written into cookie.</strong><hr>`;
            result += `\nR`;
            document.getElementById('blocks').appendChild(block);
        }

        function createArithmeticExpressionBlock(id, operation, pair) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'ArithmeticExpressionBlock');
            block.innerHTML = `
                <h2>Operation:</h2>
                <label><input type="radio" name="operation-${id}" value="Sum" ${operation === 'Sum' ? 'checked' : ''}> Sum</label><br>
                <label><input type="radio" name="operation-${id}" value="Difference" ${operation === 'Difference' ? 'checked' : ''}> Difference</label><br>
                <label><input type="radio" name="operation-${id}" value="Multiply" ${operation === 'Multiply' ? 'checked' : ''}> Multiply</label><br>
                <label><input type="radio" name="operation-${id}" value="Division" ${operation === 'Division' ? 'checked' : ''}> Division</label><br>
                <h2>Values</h2>
                <label><input type="radio" name="pair-${id}" value="current_next" ${pair === 'current_next' ? 'checked' : ''}> Current and Next</label><br>
                <label><input type="radio" name="pair-${id}" value="current_previous" ${pair === 'current_previous' ? 'checked' : ''}> Current and Previous</label><br>
                <label><input type="radio" name="pair-${id}" value="previous_next" ${pair === 'previous_next' ? 'checked' : ''}> Previous and Next</label><br>
                <button class="calculateBtn">Add Arithmetic Expression</button>
                <hr>
            `;
            const calculateButton = block.querySelector('.calculateBtn');
            calculateButton.addEventListener('click', () => {
                if (!operation || !pair) {
                    alert('Please, choose.');
                    return;
                }
                switch (pair) {
                    case 'current_next':
                        if (operation === 'Sum') result += `\n\n{t + k}`;
                        else if (operation === 'Difference') result += `\n\n{t - k}`;
                        else if (operation === 'Multiply') result += `\n\n{t * k}`;
                        else if (operation === 'Division') result += `\n\n{t / k}`;
                        break;
                    case 'current_previous':
                        if (operation === 'Sum') result += `\n\n{t + i}`;
                        else if (operation === 'Difference') result += `\n\n{t - i}`;
                        else if (operation === 'Multiply') result += `\n\n{t * i}`;
                        else if (operation === 'Division') result += `\n\n{t / i}`;
                        break;
                    case 'previous_next':
                        if (operation === 'Sum') result += `\n\n{i + k}`;
                        else if (operation === 'Difference') result += `\n\n{i - k}`;
                        else if (operation === 'Multiply') result += `\n\n{i * k}`;
                        else if (operation === 'Division') result += `\n\n{i / k}`;
                        break;
                }
                calculateButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createMoveValueToAnotherCookieBlock(id, offset) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'MoveValueToAnotherCookieBlock');
            block.innerHTML = `
                <input type="number" value="${offset}" placeholder="Offset">
                <button class="addBtn">Move Value To Other Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const offset = cookieNumberInput.value.trim();
                if (offset) {
                    result += `\n\nM[${offset}]`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createInWhichCookieAreWeBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'InWhichCookieAreWeBlock');
            block.innerHTML = `<strong>Position output added.</strong><hr>`;
            result += `\ng`;
            document.getElementById('blocks').appendChild(block);
        }

        function createCopyValueToAnotherCookieBlock(id, offset) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'CopyValueToAnotherCookieBlock');
            block.innerHTML = `
                <input type="number" value="${offset}" placeholder="Offset">
                <button class="addBtn">Copy Value To Other Cookie</button>
                <hr>
            `;
            const cookieNumberInput = block.querySelector('input[type="number"]');
            const addButton = block.querySelector('.addBtn');
            addButton.addEventListener('click', () => {
                const offset = cookieNumberInput.value.trim();
                if (offset) {
                    result += `\n\nX[${offset}]`;
                    addButton.style.display = 'none';
                }
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createMoveToCookieAddressAndTransferNumberBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'MoveToCookieAddressAndTransferNumberBlock');
            block.innerHTML = `<strong>Cookie Value Transferred.</strong><hr>`;
            result += `\nP`;
            document.getElementById('blocks').appendChild(block);
        }

        function createMoveToCookieAddressBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'MoveToCookieAddressBlock');
            block.innerHTML = `<strong>Moved to Cookie from Cookie Value.</strong><hr>`;
            result += `\nJ`;
            document.getElementById('blocks').appendChild(block);
        }

        function createWriteAddressInCookieBlock(id) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'WriteAddressInCookieBlock');
            block.innerHTML = `<strong>Cookie Address has been written.</strong><hr>`;
            result += `\nG`;
            document.getElementById('blocks').appendChild(block);
        }

        function createAddXBlock(id, direction, moveCursor) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'AddXBlock');
            block.innerHTML = `
                <h2>Left Or Right:</h2>
                <label><input type="radio" name="operation-${id}" value="Sum" ${direction === '-' ? 'checked' : ''}> -</label><br>
                <label><input type="radio" name="operation-${id}" value="Difference" ${direction === '+' ? 'checked' : ''}> +</label><br>
                <h2>Move Cursor or Not</h2>
                <label><input type="radio" name="pair-${id}" value="1" ${moveCursor === '1' ? 'checked' : ''}> 1</label><br>
                <label><input type="radio" name="pair-${id}" value="0" ${moveCursor === '0' ? 'checked' : ''}> 0</label><br>
                <button class="calculateBtn">Add x[+/-0/1]</button>
                <hr>
            `;
            const calculateButton = block.querySelector('.calculateBtn');
            calculateButton.addEventListener('click', () => {
                const direction = block.querySelector('input[name^="operation"]:checked')?.value;
                const moveCursor = block.querySelector('input[name^="pair"]:checked')?.value;
                if (!direction || !moveCursor) {
                    alert('Please, choose.');
                    return;
                }
                switch (moveCursor) {
                    case '1':
                        if (direction === 'Sum') result += `\n\nx[-1]`;
                        else if (direction === 'Difference') result += `\n\nx[+1]`;
                        break;
                    case '0':
                        if (direction === 'Sum') result += `\n\nx[-0]`;
                        else if (direction === 'Difference') result += `\n\nx[+0]`;
                        break;
                }
                calculateButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        function createAddMBlock(id, direction, moveCursor) {
            const block = document.createElement('div');
            block.className = 'block';
            block.id = id;
            block.setAttribute('data-type', 'AddMBlock');
            block.innerHTML = `
                <h2>Left Or Right:</h2>
                <label><input type="radio" name="operation-${id}" value="Sum" ${direction === '-' ? 'checked' : ''}> -</label><br>
                <label><input type="radio" name="operation-${id}" value="Difference" ${direction === '+' ? 'checked' : ''}> +</label><br>
                <h2>Move Cursor or Not</h2>
                <label><input type="radio" name="pair-${id}" value="1" ${moveCursor === '1' ? 'checked' : ''}> 1</label><br>
                <label><input type="radio" name="pair-${id}" value="0" ${moveCursor === '0' ? 'checked' : ''}> 0</label><br>
                <button class="calculateBtn">Add m[+/-0/1]</button>
                <hr>
            `;
            const calculateButton = block.querySelector('.calculateBtn');
            calculateButton.addEventListener('click', () => {
                const direction = block.querySelector('input[name^="operation"]:checked')?.value;
                const moveCursor = block.querySelector('input[name^="pair"]:checked')?.value;
                if (!direction || !moveCursor) {
                    alert('Please, choose.');
                    return;
                }
                switch (moveCursor) {
                    case '1':
                        if (direction === 'Sum') result += `\n\nm[-1]`;
                        else if (direction === 'Difference') result += `\n\nm[+1]`;
                        break;
                    case '0':
                        if (direction === 'Sum') result += `\n\nm[-0]`;
                        else if (direction === 'Difference') result += `\n\nm[+0]`;
                        break;
                }
                calculateButton.style.display = 'none';
            });
            document.getElementById('blocks').appendChild(block);
        }

        document.getElementById('saveBtn').addEventListener('click', saveState);

        function loadState() {
            document.getElementById('loadInput').click();
        }

        function handleLoad(event) {
            const file = event.target.files[0];
            if (!file) {
                alert("No file selected.");
                return;
            }
            const reader = new FileReader();
            reader.onload = function(e) {
                try {
                    const json = e.target.result;
                    const saveObject = JSON.parse(json);
                    restoreState(saveObject);
                } catch (error) {}
            };
            reader.readAsText(file);
        }

        function restoreState(saveObject) {
            if (!saveObject.blocks || !Array.isArray(saveObject.blocks)) {
                return;
            }
            const blocksContainer = document.getElementById('blocks');
            blocksContainer.innerHTML = "";
            saveObject.blocks.forEach(block => {
                const { id, type, data } = block;
                switch (type) {
                    case 'ImageBlock':
                        createImageBlock(id, data.imageUrl, data.description);
                        break;
                    case 'TextBlock':
                        createTextBlock(id, data.content);
                        break;
                    case 'IntervalBlock':
                        createIntervalBlock(id, data.intervalMs);
                        break;
                    case 'IfStartBlock':
                        createIfStartBlock(id, data.operation, data.pair);
                        break;
                    case 'IfEndBlock':
                        createIfEndBlock(id);
                        break;
                    case 'InputBlock':
                        createInputBlock(id);
                        break;
                    case 'ProgramStopBlock':
                        createProgramStopBlock(id);
                        break;
                    case 'BreakBlock':
                        createBreakBlock(id);
                        break;
                    case 'WriteInCookieBlock':
                        createWriteInCookieBlock(id, data.cookieNumber, data.value);
                        break;
                    case 'ClearCookieBlock':
                        createClearCookieBlock(id, data.cookieNumber);
                        break;
                    case 'AddToCookieBlock':
                        createAddToCookieBlock(id, data.cookieNumber, data.value);
                        break;
                    case 'MoveToCookieBlock':
                        createMoveToCookieBlock(id, data.cookieNumber);
                        break;
                    case 'SubtractFromCookieBlock':
                        createSubtractFromCookieBlock(id, data.cookieNumber, data.value);
                        break;
                    case 'OutputCharFromCookieBlock':
                        createOutputCharFromCookieBlock(id, data.cookieNumber);
                        break;
                    case 'DebugOutputFromCookieBlock':
                        createDebugOutputFromCookieBlock(id, data.cookieNumber);
                        break;
                    case 'StartCycleBlock':
                        createStartCycleBlock(id);
                        break;
                    case 'EndCycleBlock':
                        createEndCycleBlock(id);
                        break;
                    case 'ReturnToInitCookieBlock':
                        createReturnToInitCookieBlock(id);
                        break;
                    case 'PrintCookieValueBlock':
                        createPrintCookieValueBlock(id);
                        break;
                    case 'RandomValueBlock':
                        createRandomValueBlock(id);
                        break;
                    case 'ArithmeticExpressionBlock':
                        createArithmeticExpressionBlock(id, data.operation, data.pair);
                        break;
                    case 'MoveValueToAnotherCookieBlock':
                        createMoveValueToAnotherCookieBlock(id, data.offset);
                        break;
                    case 'InWhichCookieAreWeBlock':
                        createInWhichCookieAreWeBlock(id);
                        break;
                    case 'CopyValueToAnotherCookieBlock':
                        createCopyValueToAnotherCookieBlock(id, data.offset);
                        break;
                    case 'MoveToCookieAddressAndTransferNumberBlock':
                        createMoveToCookieAddressAndTransferNumberBlock(id);
                        break;
                    case 'MoveToCookieAddressBlock':
                        createMoveToCookieAddressBlock(id);
                        break;
                    case 'WriteAddressInCookieBlock':
                        createWriteAddressInCookieBlock(id);
                        break;
                    case 'AddXBlock':
                        createAddXBlock(id, data.direction, data.moveCursor);
                        break;
                    case 'AddMBlock':
                        createAddMBlock(id, data.direction, data.moveCursor);
                        break;
                }
            });
        }

        document.getElementById('loadBtn').addEventListener('click', loadState);
        document.getElementById('loadInput').addEventListener('change', handleLoad);

        document.getElementById('finishBtn').addEventListener('click', () => {
            document.getElementById('addImageBlock').style.display = 'none';
            document.getElementById('addTextBlock').style.display = 'none';
            document.getElementById('addIntervalBlock').style.display = 'none';
            document.getElementById('addIfStartBlock').style.display = 'none';
            document.getElementById('addIfEndBlock').style.display = 'none';
            document.getElementById('addInputBlock').style.display = 'none';
            document.getElementById('addProgramStopBlock').style.display = 'none';
            document.getElementById('addBreakBlock').style.display = 'none';
            document.getElementById('writeInCookieBlock').style.display = 'none';
            document.getElementById('clearCookieBlock').style.display = 'none';
            document.getElementById('addToCookieBlock').style.display = 'none';
            document.getElementById('moveToCookieBlock').style.display = 'none';
            document.getElementById('substractFromCookieBlock').style.display = 'none';
            document.getElementById('outputCharFromCookie').style.display = 'none';
            document.getElementById('debugOutputFromCookie').style.display = 'none';
            document.getElementById('startCycle').style.display = 'none';
            document.getElementById('endCycle').style.display = 'none';
            document.getElementById('returnToInitCookie').style.display = 'none';
            document.getElementById('printCookieValue').style.display = 'none';
            document.getElementById('randomValue').style.display = 'none';
            document.getElementById('arythmeticExpression').style.display = 'none';
            document.getElementById('moveValueToAnotherCookie').style.display = 'none';
            document.getElementById('inWhichCookieAreWe').style.display = 'none';
            document.getElementById('copyValueToAnotherCookie').style.display = 'none';
            document.getElementById('moveToTheCookieAddressFromCurrentCookieAndTransferTheNumberOfTheCurrentCookie').style.display = 'none';
            document.getElementById('moveToTheCookieAddressFromCurrentCookie').style.display = 'none';
            document.getElementById('writeAddressInCookie').style.display = 'none';
            document.getElementById('addX').style.display = 'none';
            document.getElementById('addM').style.display = 'none';
            document.getElementById('finishBtn').style.display = 'none';
            document.querySelectorAll('#buttons hr').forEach(line => line.style.display = 'none');
            checkDownloadVisibility();
        });

        function checkDownloadVisibility() {
            document.getElementById('downloadBtn').style.display = result ? 'block' : 'none';
            document.getElementById('copyBtn').style.display = result ? 'block' : 'none';
        }

        document.getElementById('downloadBtn').addEventListener('click', () => {
            const blob = new Blob([result], { type: 'text/plain' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'result.bc961';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        });

        document.getElementById('copyBtn').addEventListener('click', () => {
            navigator.clipboard.writeText(result).then(() => {
                alert("Result copied to clipboard!");
            }).catch(err => {});
        });

        window.onload = function() {
            const buttons = document.querySelectorAll('#buttons button');
            buttons.forEach(button => {
                button.click();
            });
        };
    </script>

</body>

</html>
```