Language: C++

{-# LANGUAGE OverloadedStrings #-} 

import Control.Applicative
import Data.Array.IO
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s1 <- BS.getLine
  n <- return (case (C.readInt s1) of
               Just x -> fst x
               Nothing -> 0)
  key  <- newArray(0, 2100000) 0 :: IO(IOUArray Int Int)
  next <- newArray(0, 2100000) 0 :: IO(IOUArray Int Int)
  prev <- newArray(0, 2100000) 0 :: IO(IOUArray Int Int)
  solve n key next prev
 
solve :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
solve n key next prev = do
  if n == 0 then
    do {
      printanswer key next prev;
      return ();
      }
    else do {
    ss <- C.words <$> BS.getLine;
    process n ss key next prev;
    solve (n - 1) key next prev;
    }
  
process :: Int -> [BS.ByteString] -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO()
process n ss key next prev
  | command == "insert" = insertx n x key next prev
  | command == "delete" = deletex n x key next prev
  | command == "deleteFirst" = deleteFirst n key next prev
  | command == "deleteLast" = deleteLast n key next prev
  where command = ss !! 0
        x = case (C.readInt (ss !! 1)) of
             Just s -> fst s
             Nothing -> 0

printanswer :: IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
printanswer key next prev = do
  t <- readArray next 0;
  if t == 0 then do {
    return ();
    }
    else do {
    nextindex <- (readArray next 0);
    x <- readArray key nextindex;
    nextnextindex <- readArray next nextindex;
    putStr (show x);
    printanswer2 nextnextindex key next prev;
    }

printanswer2 :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
printanswer2 index key next prev = do
    if index == 0 then
      do {
        putStrLn "";
        return ();
        }
      else do {
      x <- readArray key index;
      putStr (" " ++ (show x));
      nextindex <- (readArray next index);
      printanswer2 nextindex key next prev;
      }

insertx :: Int -> Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
insertx n x key next prev = do
  nextnext <- (readArray next 0);
  writeArray key (n + 1) x;
  writeArray next (n + 1) nextnext;
  writeArray prev (n + 1) 0;
  writeArray prev nextnext (n + 1);
  writeArray next 0 (n + 1);
  return ();

deletex :: Int -> Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
deletex n x key next prev = do
  nextnext <- readArray next 0;
  deletex2 n nextnext x key next prev;
  return ();

deletex2 :: Int -> Int -> Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
deletex2 n index x key next prev = do
  t <- readArray key index;
  if index == 0 then
    do {
      return ();
      }
    else do {
    if t == x then
      do {
        pn <- readArray prev index;
        nn <- readArray next index;
        writeArray next pn nn;
        writeArray prev nn pn;
        return ();
        }
    else do {
      nextindex <- readArray next index;
      deletex2 n nextindex x key next prev;
      }
    }
  
deleteFirst :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
deleteFirst n key next prev = do
  nextindex <- readArray next 0;
  nextnextindex <- readArray next nextindex;
  writeArray next 0 nextnextindex;
  writeArray prev nextnextindex 0;
  
deleteLast :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
deleteLast n key next prev = do
  previndex <- readArray prev 0;
  prevprevindex <- readArray prev previndex;
  writeArray prev 0 prevprevindex;
  writeArray next prevprevindex 0;

Compiler output:
a.cc:1:3: error: stray '#' in program
    1 | {-# LANGUAGE OverloadedStrings #-}
      |   ^
a.cc:1:32: error: stray '#' in program
    1 | {-# LANGUAGE OverloadedStrings #-}
      |                                ^
a.cc:1:1: error: expected unqualified-id before '{' token
    1 | {-# LANGUAGE OverloadedStrings #-}
      | ^
a.cc:3:1: error: 'import' does not name a type
    3 | import Control.Applicative
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:26:5: error: expected unqualified-id before 'else'
   26 |     else do {
      |     ^~~~
a.cc:32:1: error: 'process' does not name a type
   32 | process :: Int -> [BS.ByteString] -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO()
      | ^~~~~~~
a.cc:46:3: error: expected unqualified-id before 'if'
   46 |   if t == 0 then do {
      |   ^~
a.cc:49:5: error: expected unqualified-id before 'else'
   49 |     else do {
      |     ^~~~
a.cc:57:1: error: 'printanswer2' does not name a type
   57 | printanswer2 :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
      | ^~~~~~~~~~~~
a.cc:64:7: error: expected unqualified-id before 'else'
   64 |       else do {
      |       ^~~~
a.cc:71:1: error: 'insertx' does not name a type
   71 | insertx :: Int -> Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
      | ^~~~~~~
a.cc:74:3: error: 'writeArray' does not name a type
   74 |   writeArray key (n + 1) x;
      |   ^~~~~~~~~~
a.cc:75:3: error: 'writeArray' does not name a type
   75 |   writeArray next (n + 1) nextnext;
      |   ^~~~~~~~~~
a.cc:76:3: error: 'writeArray' does not name a type
   76 |   writeArray prev (n + 1) 0;
      |   ^~~~~~~~~~
a.cc:77:3: error: 'writeArray' does not name a type
   77 |   writeArray prev nextnext (n + 1);
      |   ^~~~~~~~~~
a.cc:78:3: error: 'writeArray' does not name a type
   78 |   writeArray next 0 (n + 1);
      |   ^~~~~~~~~~
a.cc:79:3: error: expected unqualified-id before 'return'
   79 |   return ();
      |   ^~~~~~
a.cc:81:1: error: 'deletex' does not name a type
   81 | deletex :: Int -> Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
      | ^~~~~~~
a.cc:84:3: error: 'deletex2' does not name a type
   84 |   deletex2 n nextnext x key next prev;
      |   ^~~~~~~~
a.cc:85:3: error: expected unqualified-id before 'return'
   85 |   return ();
      |   ^~~~~~
a.cc:87:1: error: 'deletex2' does not name a type
   87 | deletex2 :: Int -> Int -> Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
      | ^~~~~~~~
a.cc:90:3: error: expected unqualified-id before 'if'
   90 |   if index == 0 then
      |   ^~
a.cc:94:5: error: expected unqualified-id before 'else'
   94 |     else do {
      |     ^~~~
a.cc:109:1: error: 'deleteFirst' does not name a type
  109 | deleteFirst :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
      | ^~~~~~~~~~~
a.cc:112:3: error: 'nextnextindex' does not name a type
  112 |   nextnextindex <- readArray next nextindex;
      |   ^~~~~~~~~~~~~
a.cc:113:3: error: 'writeArray' does not name a type
  113 |   writeArray next 0 nextnextindex;
      |   ^~~~~~~~~~
a.cc:114:3: error: 'writeArray' does not name a type
  114 |   writeArray prev nextnextindex 0;
      |   ^~~~~~~~~~
a.cc:116:1: error: 'deleteLast' does not name a type
  116 | deleteLast :: Int -> IOUArray Int Int -> IOUArray Int Int -> IOUArray Int Int -> IO ()
      | ^~~~~~~~~~
a.cc:119:3: error: 'prevprevindex' does not name a type
  119 |   prevprevindex <- readArray prev previndex;
      |   ^~~~~~~~~~~~~
a.cc:120:3: error: 'writeArray' does not name a type
  120 |   writeArray prev 0 prevprevindex;
      |   ^~~~~~~~~~
a.cc:121:3: error: 'writeArray' does not name a type
  121 |   writeArray next prevprevindex 0;
      |   ^~~~~~~~~~