CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
dp = [[a[i] if i==j else max(a[i],a[(i+1)%n]) if (i+1)%n==j else 0 for j in range(n)] for i in range(n)]

for i in range(3 if n%2==0 else 2,n,2):
    for l in range(n):
        r = (l+i)%n

        pat = []
        for x,nextl,nextr in [(l,(l+1)%n,r),(r,l,(r+n-1)%n)]:
            if a[nextl] > a[nextr]:
                nextl = (nextl+1)%n
            else:
                nextr = (nextr+n-1)%n
            pat.append(a[x] + dp[nextl][nextr])

        dp[l][r] = max(pat)

print((max(dp[(i+1)%n][i] for i in range(n))))

# Optimized solution
n  = int(eval(input()))
a  = [int(eval(input())) for _ in range(n)]
dp = [0 for _ in range(n)]

for i in range(n):
    if i%2 == n%2:
        dp = [ dp[(l+1)%n] if a[l]>a[(l+i)%n] else dp[l] for l in range(n)]
    else:
        dp = [ max( a[l]+dp[(l+1)%n], a[(l+i)%n]+dp[l] ) for l in range(n)]

print((max(dp)))
# Original solution
n, q, s, t = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(n + 1)]
for _ in range(q):
    l, r, x = list(map(int, input().split()))
    for i in range(l, r + 1):
        a[i] += x
    temp = 0
    for i in range(1, n + 1):
        temp += (a[i - 1] - a[i]) * s if a[i] > a[i - 1] else (a[i - 1] - a[i]) * t
    print(temp)


# Optimized solution
n, q, s, t = list(map(int, input().split()))
a = [int(eval(input())) for _ in range(n + 1)]
for i in range(1, n + 1)[::-1]:
    a[i] -= a[i - 1]
count = 0
for i in range(n + 1):
    count -= a[i] * s if a[i] > 0 else a[i] * t
for _ in range(q):
    l, r, x = list(map(int, input().split()))
    count += a[l] * s if a[l] > 0 else a[l] * t
    a[l] += x
    count -= a[l] * s if a[l] > 0 else a[l] * t
    if r < n:
        count += a[r + 1] * s if a[r + 1] > 0 else a[r + 1] * t
        a[r + 1] -= x
        count -= a[r + 1] * s if a[r + 1] > 0 else a[r + 1] * t
    print(count)
# Original solution
# -*- coding: utf-8 -*-
n=int(eval(input()))
m=int(eval(input()))
ans=c=m
for i in range(n):
    a,b=[int(a) for a in input().split()]
    if c<0:
        continue
    c+=a-b
    if ans<c:
        ans=c
    if c<0:
        ans=0
print(ans)

# Optimized solution
n=int(eval(input()))
ans=c=m=int(eval(input()))
for i in[0]*n:
    a,b=list(map(int,input().split()))
    if c<0:ans=0;break
    c+=a-b
    ans=max(ans,c)
print(ans)
# Original solution
from collections import deque
n, m = int(eval(input())), int(eval(input()))
B, S = 0, m
d = deque([0]*m)
for _ in range(n):
    cars = list(map(int, input().split()))
    for _ in range(cars[0]): d.append(0)
    try:
        for _ in range(cars[1]): d.pop()
    except IndexError:
        B = 1
    S = max(S, len(d))
print((0 if B else S))

# Optimized solution
n, m = int(eval(input())), int(eval(input()))
B, S = 0, m
d = [0]*m
for _ in range(n):
    cars = list(map(int, input().split()))
    for _ in range(cars[0]): d.append(0)
    try:
        for _ in range(cars[1]): d.pop()
    except IndexError:
        B = 1
    S = max(S, len(d))
print((0 if B else S))
# Original solution
n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
    a, b = list(map(int, input().split()))
    m += a - b
    if m < 0:
        print((0))
        break
    S_max = max(S_max, m)
else:
    print(S_max)


# Optimized solution
n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
    a, b = list(map(int, input().split()))
    m += a - b
    if m < 0:
        S_max = 0
        break
    S_max = max(S_max, m)
print(S_max)
# Original solution
n = eval(input())
lis = []
for i in range(n):
    com = input()
    try:
        com, x = com.split()
        if   com == 'insert':
            lis.append(x)
        elif com == 'delete':
            l = len(lis) - 1
            while (lis[l] != x) and l >= 0:
                l -= 1
            if lis[l] == x:
                lis.pop(l)
    except:
        if com == 'deleteFirst':
            lis.pop()
        if com == 'deleteLast':
            lis.pop(0)

print(" ".join( map(str, reversed(lis)) ))

# Optimized solution
n = eval(input())
lis = []
bot = 0
for i in range(n):
    com = input()
    if   com[0] == 'i':
        lis.append(com[7:])
    elif com[6] == ' ':
        try:
            lis.pop(~lis[::-1].index(com[7:]))
        except:
            pass
    elif com[6] == 'F':
        lis.pop()
    else:
        bot += 1

print(' '.join( map(str, reversed(lis[bot:])) ))
# Original solution
#coding:utf-8
from collections import deque

n = int(eval(input()))
day = deque()
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        day.appendleft(order[1])
    if order[0] == "delete":
        try:
            day.remove(order[1])
        except:
            continue
    if order[0] == "deleteFirst":
        day.popleft()
    if order[0] == "deleteLast":
        day.pop()

day = " ".join(day)              
print(day)



# Optimized solution
#coding:utf-8
from collections import deque

n = int(eval(input()))
day = deque()
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        day.appendleft(order[1])
    elif order[0] == "delete":
        try:
            day.remove(order[1])
        except:
            continue
    elif order[0] == "deleteFirst":
        day.popleft()
    elif order[0] == "deleteLast":
        day.pop()

day = " ".join(day)              
print(day)
# Original solution
class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next


class LinkedList:
    def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil

    def insert(self, key):
        node = Node(key, self.nil, self.nil.next)
        self.nil.next.prev = node
        self.nil.next = node

    def search(self, key):
        cur = self.nil.next

        while cur != self.nil and cur.key != key:
            cur = cur.next

        return cur

    def delete_node(self, node):
        if node == self.nil:
            return

        node.prev.next = node.next
        node.next.prev = node.prev

    def delete_first(self):
        self.delete_node(self.nil.next)

    def delete_last(self):
        self.delete_node(self.nil.prev)

    def delete_key(self, key):
        node = self.search(key)
        self.delete_node(node)


def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = input().split()

        if order[0] == "insert":
            ll.insert(int(order[1]))
        elif order[0] == "delete":
            ll.delete_key(int(order[1]))
        elif order[0] == "deleteFirst":
            ll.delete_first()
        else:
            ll.delete_last()

    cur = ll.nil
    while cur.next != ll.nil:
        if cur != ll.nil:
            print(" ", end="")
        cur = cur.next
        print(cur.key, end="")

    print()


if __name__ == '__main__':
    main()



# Optimized solution
import sys


class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next


class LinkedList:
    def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil

    def insert(self, key):
        node = Node(key, self.nil, self.nil.next)
        self.nil.next.prev = node
        self.nil.next = node

    def search(self, key):
        cur = self.nil.next

        while cur != self.nil and cur.key != key:
            cur = cur.next

        return cur

    def delete_node(self, node):
        if node == self.nil:
            return

        node.prev.next = node.next
        node.next.prev = node.prev

    def delete_first(self):
        self.delete_node(self.nil.next)

    def delete_last(self):
        self.delete_node(self.nil.prev)

    def delete_key(self, key):
        node = self.search(key)
        self.delete_node(node)


def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            ll.insert(int(order[1]))
        elif order[0] == "delete":
            ll.delete_key(int(order[1]))
        elif order[0] == "deleteFirst":
            ll.delete_first()
        else:
            ll.delete_last()

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ")


if __name__ == '__main__':
    main()
# Original solution
from collections import deque

arr = []

for i in range(int(eval(input()))):
  command_line = input().split(" ")
  command = command_line[0]
  arg = ""
  if len(command_line) > 1: arg = command_line[1]

  if command == "insert":
    arr.insert(0, arg)
  if command == "delete":
    try:
      arr.remove(arg)
    except ValueError:
      pass
  if command == "deleteFirst":
    arr.pop(0)
  if command == "deleteLast":
    arr.pop()

print((" ".join(arr)))

# Optimized solution
from collections import deque

q = deque()

for i in range(int(eval(input()))):
  command_line = input().split(" ")
  command = command_line[0]
  arg = ""
  if len(command_line) > 1: arg = command_line[1]

  if command == "insert":
    q.appendleft(arg)
  elif command == "delete":
    try:
      q.remove(arg)
    except ValueError:
      pass
  elif command == "deleteFirst":
    q.popleft()
  else:
    q.pop()

print((" ".join(q)))
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 08:50:28 2017

@author: syaga
"""

COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"]

if __name__ == "__main__":
    n = int(eval(input()))
    com = []
    for i in range(n):
        com.append(input().split())
    ans = []
    for i in com:
        if i[0] == COMMAND[0]:
            ans.insert(0, i[1])
        elif i[0] == COMMAND[1]:
            if i[1] in ans:
                ans.remove(i[1])
        elif i[0] == COMMAND[2]:
            ans.pop(0)
        elif i[0] == COMMAND[3]:
            ans.pop()
    print((" ".join(ans)))

# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 09:13:28 2017

@author: syaga
"""

COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"]

if __name__ == "__main__":
    n = int(eval(input()))
    com = []
    for i in range(n):
        com.append(input().split())
    ans = []
    for i in com:
        if i[0] == COMMAND[0]:
            ans.append(i[1])
        elif i[0] == COMMAND[1]:
            if i[1] in ans:
                ind = len(ans)-1-ans[::-1].index(i[1])
                del ans[ind]
        elif i[0] == COMMAND[2]:
            ans.pop()
        elif i[0] == COMMAND[3]:
            ans.pop(0)
    ans.reverse()
    print((" ".join(ans)))
# Original solution
# -*- coding: utf-8 -*-

from collections import deque

COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")

if __name__ == "__main__":
    n = int(eval(input()))
    ans = deque()
    for i in range(n):
        com = input().split()
        if com[0] == COMMAND[0]:
            ans.appendleft(com[1])
        elif com[0] == COMMAND[1]:
            if com[1] in ans:
                ans.remove(com[1])
        elif com[0] == COMMAND[2]:
            ans.popleft()
        elif com[0] == COMMAND[3]:
            ans.pop()
    print((" ".join(ans)))

# Optimized solution
# -*- coding: utf-8 -*-

from collections import deque
import sys

COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    ans = deque()
    inp = sys.stdin.readlines()
    for i in range(n):
        com = inp[i].split()
        if com[0] == COMMAND[0]:
            ans.appendleft(com[1])
        elif com[0] == COMMAND[1]:
            if com[1] in ans:
                ans.remove(com[1])
        elif com[0] == COMMAND[2]:
            ans.popleft()
        elif com[0] == COMMAND[3]:
            ans.pop()
    print((" ".join(ans)))
# Original solution
n = int(eval(input()))

dlist = []

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = int(arr[1])
    if cmd == 'insert':
        dlist.insert(0, key)
    elif cmd == 'delete':
        if dlist.count(key) > 0:
            idx = dlist.index(key)
            if idx != -1:
                dlist.pop(idx)
    elif cmd == 'deleteFirst':
        dlist.pop(0)
    elif cmd == 'deleteLast':
        dlist.pop(-1)

print((' '.join(map(str, dlist))))



# Optimized solution
n = int(eval(input()))

dlist = []

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.insert(0, key)
    elif cmd == 'delete':
        if dlist.count(key) > 0:
            idx = dlist.index(key)
            if idx != -1:
                dlist.pop(idx)
    elif cmd == 'deleteFirst':
        dlist.pop(0)
    elif cmd == 'deleteLast':
        dlist.pop(-1)

print((' '.join(dlist)))
# Original solution
from collections import deque

queue = deque([])

n = int(input())

for i in range(n):
    commands = input().split(" ")
    command = commands[0]
    if command == "insert":
        queue.appendleft(commands[1])
    elif command == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif command == "deleteFirst":
        queue.popleft()
    elif command == "deleteLast":
        queue.pop()

last = queue.pop()
for i in queue:
    print(i, end=" ")

print(last)


# Optimized solution
from collections import deque

queue = deque([])

for _ in range(int(eval(input()))):
    commands = input().split(" ")
    command = commands[0]
    if command == "insert":
        queue.appendleft(commands[1])
    elif command == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif command == "deleteFirst":
        queue.popleft()
    elif command == "deleteLast":
        queue.pop()

print((" ".join(queue)))
# Original solution
from collections import deque

queue = deque([])

for _ in range(int(eval(input()))):
    commands = input().split(" ")
    command = commands[0]
    if command == "insert":
        queue.appendleft(commands[1])
    elif command == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif command == "deleteFirst":
        queue.popleft()
    elif command == "deleteLast":
        queue.pop()

print((" ".join(queue)))

# Optimized solution
from collections import deque

queue = deque()

for _ in range(int(eval(input()))):
    commands = input().split(" ")
    if commands[0] == "insert":
        queue.appendleft(commands[1])
    elif commands[0] == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif commands[0] == "deleteFirst":
        queue.popleft()
    elif commands[0] == "deleteLast":
        queue.pop()

print((" ".join(queue)))
# Original solution
from collections import deque

def main():

    queue = deque()

    for _ in range(int(eval(input()))):
        commands = input().split(" ")
        if commands[0] == "insert":
            queue.appendleft(commands[1])
        elif commands[0] == "delete":
            try:
                queue.remove(commands[1])
            except ValueError:
                pass
        elif commands[0] == "deleteFirst":
            queue.popleft()
        elif commands[0] == "deleteLast":
            queue.pop()

    print((" ".join(queue)))

main()

# Optimized solution
import sys
from collections import deque

queue = deque()

for _ in range(int(sys.stdin.readline())):
    commands = sys.stdin.readline()[:-1].split(" ")
    if commands[0] == "insert":
        queue.appendleft(commands[1])
    elif commands[0] == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif commands[0] == "deleteFirst":
        queue.popleft()
    elif commands[0] == "deleteLast":
        queue.pop()

print((" ".join(queue)))
# Original solution
# coding: utf-8
import sys
from collections import deque

output_str = deque()
data_cnt =  int(eval(input()))  

for i in range(data_cnt):
    line = input().rstrip()
    if line.find(" ") > 0:
        in_command, in_str = line.split(" ")
    else:
        in_command = line
    
    if in_command == "insert":
        output_str.appendleft(in_str)
    elif in_command == "delete":
        if output_str.count(in_str) > 0:
            output_str.remove(in_str)
    elif in_command == "deleteFirst":
        output_str.popleft()
    elif in_command == "deleteLast": 
        output_str.pop()

print((" ".join(output_str)))

# Optimized solution
# coding: utf-8
import sys
from collections import deque

output_str = deque()
data_cnt =  int(eval(input()))  

for i in range(data_cnt):
    in_command = input().rstrip().split(" ")
    
    if in_command[0] == "insert":
        output_str.appendleft(in_command[1])
    elif in_command[0] == "delete":
        if output_str.count(in_command[1]) > 0:
            output_str.remove(in_command[1])
    elif in_command[0] == "deleteFirst":
        output_str.popleft()
    elif in_command[0] == "deleteLast": 
        output_str.pop()

print((" ".join(output_str)))
# Original solution
n = int(input())
xlist = []
for i in range(n):
    command = list(map(str,input().split()))
    if (command[0] == 'insert'):
        x = command[1]
        if (len(xlist) == 0):
            xlist.append(int(x))
        else:
            xlist.append(int(x))
            for i in range(1,len(xlist)):
                k = len(xlist) - i 
                j = k-1
                xlist[j], xlist[k] = xlist[k], xlist[j]
        #print(xlist)
    elif (command[0] == 'delete'):
        x = command[1]
        if (int(x) in xlist) :
            xlist.remove(int(x))
        #print(xlist)
    elif (command[0] == 'deleteFirst'):
        if (len(xlist) > 0):
            del xlist[0]
        #print(xlist)
    elif (command[0] == 'deleteLast'):
        if (len(xlist) > 0):
            del xlist[-1]
        #print(xlist)
n = len(xlist)
for i in range(n):
    if (i == n-1):
        print('{}'.format(xlist[i]), end = '')
    else:
        print('{} '.format(xlist[i]), end = '')
print()


# Optimized solution
n = int(input())
xlist = []
for i in range(n):
    command = list(map(str,input().split()))
    if (command[0] == 'insert'):
        x = command[1]
        if (len(xlist) == 0):
            xlist.append(int(x))
        else:
            xlist = [int(x)] + xlist
        #print(xlist)
    elif (command[0] == 'delete'):
        x = command[1]
        if (int(x) in xlist) :
            xlist.remove(int(x))
        #print(xlist)
    elif (command[0] == 'deleteFirst'):
        if (len(xlist) > 0):
            del xlist[0]
        #print(xlist)
    elif (command[0] == 'deleteLast'):
        if (len(xlist) > 0):
            del xlist[-1]
        #print(xlist)
n = len(xlist)
for i in range(n):
    if (i == n-1):
        print('{}'.format(xlist[i]), end = '')
    else:
        print('{} '.format(xlist[i]), end = '')
print()
# Original solution
from sys import stdin

class DList:
    class Cell:
        def __init__(self, k):
            self.key  = k
            self.prev = None
            self.next = None

    def __init__(self):
        self.head = DList.Cell(None)
        self.last = DList.Cell(None)
        self.head.next = self.last
        self.last.prev = self.head

    def insert(self, x):
        c = DList.Cell(x)
        c.prev = self.head
        c.next = self.head.next
        c.next.prev = c
        self.head.next = c

    def delete(self, x):
        c = self.__find(x)
        if c != None:
            self.__delete(c)

    def __delete(self, c):
        c.prev.next = c.next
        c.next.prev = c.prev

    def __find(self, x):
        c = self.head.next
        while c != None and c.key != x:
            c = c.next
        return c

    def deleteFirst(self):
        self.__delete(self.head.next)
    def deleteLast(self):
        self.__delete(self.last.prev)

    def print(self):
        c = self.head.next
        sep = ''
        while c != self.last:
            print(sep + str(c.key), end='')
            c = c.next
            sep = ' '
        print()

dlist = DList()

n = int(stdin.readline())
for i in range(n):
    cmd = tuple(stdin.readline().split())
    if   cmd[0] == 'insert':
        dlist.insert(int(cmd[1]))
    elif cmd[0] == 'delete':
        dlist.delete(int(cmd[1]))
    elif cmd[0] == 'deleteFirst':
        dlist.deleteFirst()
    elif cmd[0] == 'deleteLast':
        dlist.deleteLast()

dlist.print()



# Optimized solution
from sys import stdin

class DList:
    class Cell:
        def __init__(self, k):
            self.key  = k
            self.prev = None
            self.next = None

    def __init__(self):
        self.head = DList.Cell(None)
        self.last = DList.Cell(None)
        self.head.next = self.last
        self.last.prev = self.head

    def insert(self, x):
        c = DList.Cell(x)
        c.prev = self.head
        c.next = self.head.next
        c.next.prev = c
        self.head.next = c

    def delete(self, x):
        c = self.__find(x)
        if c != None:
            self.__delete(c)

    def __delete(self, c):
        c.prev.next = c.next
        c.next.prev = c.prev

    def __find(self, x):
        c = self.head.next
        while c != None and c.key != x:
            c = c.next
        return c

    def deleteFirst(self):
        self.__delete(self.head.next)
    def deleteLast(self):
        self.__delete(self.last.prev)

    def print(self):
        c = self.head.next
        ls = []
        while c != self.last:
            ls.append(c.key)
            c = c.next
        print(' '.join(map(str, ls)))

dlist = DList()

n = int(stdin.readline())
for i in range(n):
    cmd = tuple(stdin.readline().split())
    if   cmd[0] == 'insert':
        dlist.insert(int(cmd[1]))
    elif cmd[0] == 'delete':
        dlist.delete(int(cmd[1]))
    elif cmd[0] == 'deleteFirst':
        dlist.deleteFirst()
    elif cmd[0] == 'deleteLast':
        dlist.deleteLast()

dlist.print()
# Original solution
from collections import deque

n = int(eval(input()))

q = deque()
for i in range(n):
    cmd = input().strip().split()
    try:
        if cmd[0][0] == 'i':
            q.appendleft(cmd[1])
        elif cmd[0][-1] == 'e':
            q.remove(cmd[1])
        elif cmd[0][6] == 'F':
            q.popleft()
        else:
            q.pop()
    except:
        pass

print((' '.join(q)))

# Optimized solution
from collections import deque

n = int(eval(input()))

q = deque()
for i in range(n):
    cmd = input().strip().split()
    if cmd[0] == 'insert':
        q.appendleft(cmd[1])
        continue
    if cmd[0] == 'delete':
        try:
            q.remove(cmd[1])
        except:
            pass
        continue
    if cmd[0] == 'deleteFirst':
        q.popleft()
        continue
    if cmd[0] == 'deleteLast':
        q.pop()
        continue

print((' '.join(q)))
# Original solution
n = int(eval(input()))
L = []
i = 0
while i < n:
    s = list(map(str, input().split(' ')))
    if s[0] == 'insert':
        L.insert(0, int(s[1]))
    elif s[0] == 'delete':
        if int(s[1]) in L:
            L.remove(int(s[1]))
    elif s[0] == 'deleteFirst':
        del L[0]
    elif s[0] == 'deleteLast':
        del L[-1]
    i += 1
print((' '.join(map(str, L))))


# Optimized solution
n = int(eval(input()))
L = []
i = 0
while i < n:
    s = list(map(str, input().split(' ')))
    if s[0] == 'insert':
        L.insert(0, int(s[1]))
    elif s[0] == 'delete':
        try:
            L.remove(int(s[1]))
        except:
            pass
    elif s[0] == 'deleteFirst':
        del L[0]
    elif s[0] == 'deleteLast':
        del L[-1]
    i += 1
print((' '.join(map(str, L))))