<?php
$lista = new SplDoublyLinkedList();
while (($linha = fgets(STDIN)) !== false) {
    $linha = trim($linha);
    if ($linha === "") continue;
    $partes = explode(" ", $linha);
    $operacao = intval($partes[0]);
    if ($operacao == 0) break;
    if ($operacao == 1) {
        $valor = intval($partes[1]);
        $lista->push($valor);
    } elseif ($operacao == 4) {
        $indice = intval($partes[1]) - 1;
        if ($indice >= 0 && $indice < $lista->count()) {
            echo $lista[$indice] . PHP_EOL;
        }
    }
}
?>

Embed on website

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