Buggy python submission (verdict: Time Limit Exceeded):
class DoublyLinkedList:
    def __init__(self, num):
        self.elements = [None for _ in range(300001)]
        self.elements[0] = [None, num, None]
        self.top = 0
        self.bottom = 0
        self.cnt = 0

    def push_top(self, val):
        self.cnt += 1
        self.elements[self.top][0] = self.cnt
        self.elements[self.cnt] = [None, val, self.top]
        self.top = self.cnt

    def push_bottom(self, val):
        self.cnt += 1
        self.elements[self.bottom][2] = self.cnt
        self.elements[self.cnt] = [self.bottom, val, None]
        self.bottom = self.cnt

    @staticmethod
    def from_str(s):
        ret = DoublyLinkedList(s[0])
        for v in s[1:]:
            ret.push_bottom(v)
        return ret

    def to_str(self):
        cur = self.top
        val = self.elements[self.top][1]
        while self.elements[cur][2] is not None:
            val += self.elements[self.elements[cur][2]][1]
            cur = self.elements[cur][2]
        return val


def main():
    s = input()
    d = DoublyLinkedList.from_str(s)
    q = int(input())
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                d.push_bottom(c)
            else:
                d.push_top(c)
        else:
            if f == '1':
                d.push_top(c)
            else:
                d.push_bottom(c)

    if swapped:
        print(d.to_str()[::-1])
    else:
        print(d.to_str())


if __name__ == '__main__':
    main()



Fixed submission:

def main():
    s = input()
    q = int(input())
    bottom = ''
    top = ''
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                bottom += c
            else:
                top += c
        else:
            if f == '1':
                top += c
            else:
                bottom += c

    if swapped:
        print(bottom[::-1] + s[::-1] + top)
    else:
        print(top[::-1]+s+bottom)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
class DoblyLinkedList:
    class node:
        def __init__(self, pre, val, nex):
            self.val = val
            self.pre = pre
            self.nex = nex

    def __init__(self, num):
        self.elements = [None for _ in range(300001)]
        self.elements[0] = self.node(None, num, None)
        self.top = 0
        self.bottom = 0
        self.cnt = 0

    def push_top(self, val):
        self.cnt += 1
        self.elements[self.top].pre = self.cnt
        node = self.node(None, val, self.top)
        self.elements[self.cnt] = node
        self.top = self.cnt

    def push_bottom(self, val):
        self.cnt += 1
        self.elements[self.bottom].nex = self.cnt
        node = self.node(self.bottom, val, None)
        self.elements[self.cnt] = node
        self.bottom = self.cnt

    @staticmethod
    def from_str(s):
        ret = DoblyLinkedList(s[0])
        for v in s[1:]:
            ret.push_bottom(v)
        return ret

    def to_str(self):
        cur = self.top
        val = self.elements[self.top].val
        while self.elements[cur].nex is not None:
            val += self.elements[self.elements[cur].nex].val
            cur = self.elements[cur].nex
        return val


def main():
    s = input()
    d = DoblyLinkedList.from_str(s)
    q = int(input())
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                d.push_bottom(c)
            else:
                d.push_top(c)
        else:
            if f == '1':
                d.push_top(c)
            else:
                d.push_bottom(c)

    if swapped:
        print(d.to_str()[::-1])
    else:
        print(d.to_str())


if __name__ == '__main__':
    main()



Fixed submission:

def main():
    s = input()
    q = int(input())
    bottom = ''
    top = ''
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                bottom += c
            else:
                top += c
        else:
            if f == '1':
                top += c
            else:
                bottom += c

    if swapped:
        print(bottom[::-1] + s[::-1] + top)
    else:
        print(top[::-1]+s+bottom)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
class DoblyLinkedList:
    class node:
        def __init__(self, pre, val, nex):
            self.val = val
            self.pre = pre
            self.nex = nex

    def __init__(self, num):
        self.elements = [None for _ in range(100001)]
        self.elements[0] = self.node(None, num, None)
        self.top = 0
        self.bottom = 0
        self.cnt = 0

    def push_top(self, val):
        self.cnt += 1
        self.elements[self.top].pre = self.cnt
        node = self.node(None, val, self.top)
        self.elements[self.cnt] = node
        self.top = self.cnt

    def push_bottom(self, val):
        self.cnt += 1
        self.elements[self.bottom].nex = self.cnt
        node = self.node(self.bottom, val, None)
        self.elements[self.cnt] = node
        self.bottom = self.cnt

    @staticmethod
    def from_str(s):
        ret = DoblyLinkedList(s[0])
        for v in s[1:]:
            ret.push_bottom(v)
        return ret

    def to_str(self):
        cur = self.top
        val = self.elements[self.top].val
        while self.elements[cur].nex is not None:
            val += self.elements[self.elements[cur].nex].val
            cur = self.elements[cur].nex
        return val


def main():
    s = input()
    d = DoblyLinkedList.from_str(s)
    q = int(input())
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                d.push_bottom(c)
            else:
                d.push_top(c)
        else:
            if f == '1':
                d.push_top(c)
            else:
                d.push_bottom(c)

    if swapped:
        print(d.to_str()[::-1])
    else:
        print(d.to_str())


if __name__ == '__main__':
    main()



Fixed submission:

def main():
    s = input()
    q = int(input())
    bottom = ''
    top = ''
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                bottom += c
            else:
                top += c
        else:
            if f == '1':
                top += c
            else:
                bottom += c

    if swapped:
        print(bottom[::-1] + s[::-1] + top)
    else:
        print(top[::-1]+s+bottom)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
class DoblyLinkedList:
    class node:
        def __init__(self, pre, val, nex):
            self.val = val
            self.pre = pre
            self.nex = nex

    def __init__(self, num):
        self.elements = {0: self.node(None, num, None)}
        self.top = 0
        self.bottom = 0
        self.cnt = 0

    def push_top(self, val):
        self.cnt += 1
        self.elements[self.top].pre = self.cnt
        node = self.node(None, val, self.top)
        self.elements[self.cnt] = node
        self.top = self.cnt

    def push_bottom(self, val):
        self.cnt += 1
        self.elements[self.bottom].nex = self.cnt
        node = self.node(self.bottom, val, None)
        self.elements[self.cnt] = node
        self.bottom = self.cnt

    @staticmethod
    def from_str(s):
        ret = DoblyLinkedList(s[0])
        for v in s[1:]:
            ret.push_bottom(v)
        return ret

    def to_str(self):
        cur = self.top
        val = self.elements[self.top].val
        while self.elements[cur].nex is not None:
            val += self.elements[self.elements[cur].nex].val
            cur = self.elements[cur].nex
        return val


def main():
    s = input()
    d = DoblyLinkedList.from_str(s)
    q = int(input())
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                d.push_bottom(c)
            else:
                d.push_top(c)
        else:
            if f == '1':
                d.push_top(c)
            else:
                d.push_bottom(c)



    if swapped:
        print(d.to_str()[::-1])
    else:
        print(d.to_str())


if __name__ == '__main__':
    main()



Fixed submission:

def main():
    s = input()
    q = int(input())
    bottom = ''
    top = ''
    swapped = 0
    for _ in range(q):
        query = input()
        if len(query) == 1:
            swapped = 1 - swapped
            continue
        _, f, c = query.split()
        if swapped:
            if f == '1':
                bottom += c
            else:
                top += c
        else:
            if f == '1':
                top += c
            else:
                bottom += c

    if swapped:
        print(bottom[::-1] + s[::-1] + top)
    else:
        print(top[::-1]+s+bottom)


if __name__ == '__main__':
    main()