<?php
$lista = new SplDoublyLinkedList();

while (($linha = fgets(STDIN)) !== false) {
    $linha = trim($linha);
    if ($linha == "") continue;
    
    $partes = explode(" ", $linha);
    $op = intval($partes[0]);
    
    if ($op == 0) {
        break;
    } elseif ($op == 1) {
        $x = intval($partes[1]);
        $lista->push($x);
    } elseif ($op == 5) {
        $x = intval($partes[1]);
        $k = intval($partes[2]);
        $pos = $k - 1;
        
        if ($pos >= 0 && $pos <= $lista->count()) {
            $lista->add($pos, $x);
        }
    } elseif ($op == 3) {
        $i = 0;
        foreach ($lista as $val) {
            if ($i > 0) {
                echo " ";
            }
            echo $val;
            $i++;
        }
        echo PHP_EOL;
    }
}
?>

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: