Problem:


Score : 200 points

Problem Statement

You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.

You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.

You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.

You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.

Find the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.

We can prove that this value is uniquely determined.

Constraints

2 \leq N \leq 200

-100 \leq L \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L

Output

Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.

Sample Input 1

5 2

Sample Output 1

18

The flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.

Sample Input 2

3 -1

Sample Output 2

0

The flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.

Sample Input 3

30 -50

Sample Output 3

-1044



Sample input:
5 2


Sample output:
18

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, L = nl()

min_aji = 1000
min_aji_real = 1000
total = 0
for i in range(N):
    total += L + i
    if abs(L + i) < min_aji:
        min_aji = abs(L + i)
        min_aji_real = L + i

print(total - min_aji_real)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,L = inpl()
ans = 0
MIN = INF
for i in range(N):
    x = L + i
    ans += x

if L >= 0:
    print(ans-L)
else:
    if abs(L) < N:
        print(ans)
    else:
        print(ans-x)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc131/tasks/abc131_b

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N, L = map(int, input().split())
    apples = [L + i for i in range(N)]
    total = sum(apples)

    rm = 0
    if apples[0] >= 0:
        rm = apples[0]
    else:
        for i in range(N):
            rm = apples[i]
            if rm == 0:
                break
    total -= rm
    print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,L = (int(x) for x in input().split())

if L > 0:
    eat = L
elif N+L-1 < 0:
    eat = N+L-1
else:
    eat = 0

print(sum(range(L, L+N))-eat)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())

diff = 10**9
min_idx = -1
for i in range(N):
    _diff = abs(L + i)
    if _diff < diff:
        diff = _diff
        min_idx = i

ans = sum([L+i for i in range(N)]) - (L+min_idx)
print(ans)

Submission status: Accepted

Solution code:
N,L = list(map(int, input().split()))
S = L*N + N*(N-1)//2

if L+N-1 < 0:
  print(S - (L+N-1))
elif 0 < L:
  print(S-L)
else:
  print(S)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()

apple = [L+i for i in range(N)]
# print(apple)

for i in apple:
	if i == 0:
		print(sum(apple))
		break
else:  # 0なし
	if max(apple) > 0:
		print(sum(apple)-min(apple))
	else:
		print(sum(apple)-max(apple))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = sum(l + i for i in range(n))
res = min((abs(l + i), i) for i in range(n))
print(s - l - res[1])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
rng = []
for i in range(N):
    rng.append(L + i)
minimini = 1000000000000
mini = 100000000000
for i in rng:
    if minimini > abs(i):
        mini = i
        minimini = abs(i)

print(sum(rng) - mini)

Submission status: Accepted

Solution code:



(N,M) = (int(i) for i in input().split(" "))

K = N*(N-1)/2
K += M*N
K = int(K)
if M <=0 and N+M-1>=0:
	print(K)
elif M > 0:
	print(K-M)
else:
	print(K-N-M+1)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,l = get_nums_l()

if (l <= 0 and (l+n-1) >= 0):
    print(sum(range(l, l+n)))
elif (l+n-1) < 0:
    print(sum(range(l, l+n-1)))
else:
    print(sum(range(l+1, l+n)))

Submission status: Accepted

Solution code:
import numpy as np
N, L =  list(map(int, input().split()))
r = np.arange(L, N + L)
print(np.sum(r) - r[np.argmin(np.abs(r))])

Submission status: Accepted

Solution code:
import numpy as np

def main():
    N, L = map(int, input().split())
    aji = [L+i-1 for i in range(1, N+1)]
    absaji = list(map(abs, aji))

    i = np.argmin(absaji)

    print(sum(aji) - aji[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))

tastes = [L + i -1 for i in range(1, N+1, 1)]

if tastes[0] * tastes[-1] <= 0:
    print(sum(tastes))
else:
    if min(tastes) < 0:
        print(sum(tastes) - tastes[-1])
    else:
        print(sum(tastes) - tastes[0])

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    T = list(range(L, L+N))
    m = float("inf")
    x = float("inf")
    for t in T:
        if abs(t) < m:
            m = abs(t)
            x = t
    print(sum(T) - x)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,L=map(int,input().split())
l=[]
l2=[]
for i in range(n):
  l.append(L+i)
  l2.append(abs(L+i))
x=l2.index(min(l2))
print(sum(l)-l[x])

Submission status: Accepted

Solution code:
N,L = map(int, input().split())

if L <= 0 and L+N > 0:
    d = 0
else:
    d = min((abs(L),L), (abs(L+N-1),L+N-1))[1]

print(sum(range(L,L+N)) - d)

Submission status: Accepted

Solution code:
#B問題
N,L = map(int,input().split())
if L+N-1 < 0:
    ans = 0
    for i in range(N-1):
        ans+=L+i
elif L > 0:
    ans = 0
    for i in range(N-1):
        ans+=L+i+1
else:
    ans = 0
    for i in range(N):
        ans+=L+i
print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
A = [L+i for i in range(N)]
A.sort(key = lambda x: abs(x))

answer = sum(A[1:])
print(answer)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = []
s = 0
for i in range(N):
    A.append(L + i)
    s += L + i

mi = float('inf')
t = 0
for i in range(N):
    tmp = 0
    for j in range(N):
        if i != j:
            tmp += A[j]

    if abs(tmp - s) < mi:
        mi = abs(tmp - s)
        t = tmp


print(t)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import random
import collections
import math
import itertools
import bisect

def real_main():
    n, l = read_int_array()
    min_i = min(range(n), key=lambda x: abs(x + l))
    print(sum(x + l for x in range(n)) - (min_i + l))


def solve():
    pass


def main():
    if False and 'PYCHARM_HOSTED' in os.environ:
        main_pycharm()
    else:
        real_main()


from copy import deepcopy
def main_pycharm():
    solution = solve

    test_inputs = None
    test_outputs = None
    judge = None
    slow_solution = None
    if solution is not None:
        if test_outputs is not None:
            test_with_answers(solution, test_inputs, test_outputs)
        if judge is not None:
            test_with_judge(solution, test_inputs, judge)
        if slow_solution is not None:
            test_with_slow_solution(solution, test_inputs, slow_solution)


def test_with_answers(solution, inputs, answers):
    total, wrong = 0, 0
    for args, test_ans in zip(inputs, answers):
        ans = solution(*deepcopy(args))
        if ans != test_ans:
            print('WRONG! ans=%s, test_ans=%s, args=%s' % (ans, test_ans, args))
            wrong += 1
        else:
            print('GOOD')
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_judge(solution, inputs_gen, judge):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        if not judge(deepcopy(ans), *deepcopy(args)):
            print('WRONG! ans=%s, args=%s' % (ans, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_slow_solution(solution, inputs_gen, solution_slow):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        slow = solution_slow(*deepcopy(args))
        if ans != slow:
            print('WRONG! ans=%s, slow=%s, args=%s' % (ans, slow, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


# This mergesort can be like 7 times faster than build in sort
# (for stupid reasons)
def mergesort(A, key=lambda x: x, reverse=False):
    C = A
    A = list(range(len(A)))
    B = list(A)

    n = len(A)
    for i in range(0, n - 1, 2):
        if key(C[A[i]]) > key(C[A[i ^ 1]]):
            A[i], A[i ^ 1] = A[i ^ 1], A[i]

    width = 2
    while width < n:
        for i in range(0, n, 2 * width):
            R1, R2 = min(i + width, n), min(i + 2 * width, n)
            j, k = R1, i
            while i < R1 and j < R2:
                if key(C[A[i]]) > key(C[A[j]]):
                    B[k] = A[j]
                    j += 1
                else:
                    B[k] = A[i]
                    i += 1
                k += 1
            while i < R1:
                B[k] = A[i]
                k += 1
                i += 1
            while k < R2:
                B[k] = A[k]
                k += 1
        A, B = B, A
        width *= 2

    if reverse:
        A.reverse()
    return A


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

def read():
    return input()

def read_int():
    return int(input())

def read_array(sep=None, maxsplit=-1):
    return input().split(sep, maxsplit)

def read_int_array():
    return [int(a) for a in read_array()]

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)
mo=10**9+7

#n=int(input())  
n,l=map(int,input().split())
#a=[int(i) for i in input().split()]
a=[l+i-1 for i in range(1,n+1)]
if 0 in a:
    ans=sum(a)
elif l>0:
    ans=sum(a)-l
else:
    ans=sum(a)-(l+n-1)
    
print(ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())

ll = []
p = []
for i in range(n):
    ll.append(l + i)
    p.append(abs(l + i))

res = -1
tmp = 10 ** 100
sm = sum(ll)

for i in ll:
    dif = abs(sm - (sm - i))
    if dif < tmp:
        tmp = dif
        res = sm - i
    # print(dif, sm)

print(res)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n, l = get_li()
    tastes = list(range(l, l+n))
    print(sum(tastes) - min(tastes, key=lambda x: abs(x)))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = [l + i for i in range(n)]
a.sort(key=lambda x:abs(x))
print(sum(a) - a[0])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())

S = 0
r_abs = 1000
r = 1000

for i in range(N):
    S += i + L
    if abs(i + L) < r_abs:
        r_abs = abs(i + L)
        r = i + L

print(S - r)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
A = [L+i for i in range(N)]
ans = sum(A)
mini = 10**10
ap = None
for a in A:
    if abs(a) < mini:
        ap = a
        mini = abs(a)
print(ans - ap)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

#n = int(input())
n,l = [int(i) for i in input().split()]

ans = sum([l+i for i in range(n)])

if l>=0:
    print(ans - l)
elif l+n-1 <= 0:
    print(ans-(l+n-1))
else:
    print(ans)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, L = MI()
    A = [L + i for i in range(N)]
    if A[0] * A[-1] < 0:
        print(sum(A))
    else:
        if A[0] >= 0:
            print(sum(A) - A[0])
        else:
            print(sum(A)-A[-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
arr=[0]*n
for i in range(n):
  arr[i]=l+i+1-1
s=sum(arr)
ans=0
diff=10**10
for i in range(n):
  tmp=arr[:i]+arr[i+1:]
  tmps=sum(tmp)
  if diff>abs(s-tmps):
    ans=tmps
    diff=abs(s-tmps)
print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = float("inf")
b = 0
s = 0
for i in range(n):
    s += l+i
    if a > abs(l+i):
        b = i
        a = abs(l+i)
print(s - (l+b))

Submission status: Accepted

Solution code:
n,l=list(map(int,input().split()))
arr=[]
for i in range(1,n+1):
	arr.append(l+i-1)
sumx=sum(arr)
diff=10000000000000
ans=0
for i in range(n):
	temp=sumx-arr[i]
	if(abs(sumx-temp)<=diff):
		diff=abs(sumx-temp)
		ans=temp

print(ans)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())

a = float('inf')
b = 0

for i in range(n):
    b+=l+i
    if abs(l+i)<abs(a):
        a = l+i

print(b-a)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
A = [L+i for i in range(N)]
x = 10**9
y = -1
for a in A:
    if abs(a) < x:
        x = abs(a)
        y = a
print(sum(A) - y)

Submission status: Accepted

Solution code:
n, like = map(int, input().split())

arr = [like + i for i in range(n)]

arr.sort(key=lambda x:abs(x))

print(sum(arr[1:]))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
taste = [L+i for i in range(N)]
abstaste = sorted(taste,key = abs)
print(sum(taste)-abstaste[0])

Submission status: Accepted

Solution code:

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    L = int(buflist[1])
    apple = []
    for i in range(N):
        apple.append(L+i)
    nearest = int(1e9)+7
    for i in range(N):
        if abs(apple[i]) < abs(nearest):
            nearest = apple[i]
    print(sum(apple) - nearest)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [L+i for i in range(N)]
mi = 99999
for i in range(N):
    if abs(mi) > abs(A[i]):
        mi = A[i]
print(sum(A)-mi)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
s = sum(L + i - 1 for i in range(1, N + 1))
ans = sum(L + i - 1 for i in range(2, N + 1))
for i in range(1, N + 1):
    s1 = s - (L + i - 1)
    if abs(s - ans) > abs(s - s1):
        ans = s1
print(ans)

Submission status: Accepted

Solution code:
N,L = list(map(int,input().split()))

A = [[abs(L+i),i] for i in range(N)]

A.sort(lambda x:x[0])

j=A[0][1]
s=0
for i in range(N):
    if i!=j:
        s+=L+i

print(s)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())

apple = [L + i for i in range(N)]
eat = 10 ** 10
for a in apple:
    if abs(a) < abs(eat):
        eat = a
print(sum(apple) - eat)

Submission status: Accepted

Solution code:
n, l = [int(i) for i in input().split()]

S = 0
mi = int(1e19)

for i in range(n):
    a = l + i
    if abs(a) < abs(mi):
        mi = a
    S += a

print(S - mi)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())

ans = 0
t = 1000000
for i in range(1, n + 1):
    p = l + i - 1
    ans += p;
    if abs(p) < abs(t):
        t = p
print(ans - t)

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))

m = 300
s = 0
for i in range(N):
    if abs(L + i) < abs(m):
        m = L + i
    s += L + i

print(s - m)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from fractions import gcd
from functools import lru_cache, reduce

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

# S = sys.stdin.readline().rstrip()
# c = list(S)
# if c[0] == c[1] or c[1] == c[2] or c[2] == c[3]:
#     print('Bad')
# else:
#     print('Good')

N, L = list(map(int, sys.stdin.readline().split()))

a = np.arange(L, L + N)
d = abs(a).argmin()
print(a.sum() - a[d])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, L = LI()
    li = list(range(L, N + L))
    if 0 in li:
        ans = sum(li)
    elif li[-1] < 0:
        ans = sum(li[:-1])
    else:
        ans = sum(li[1:])
    return ans

print(main())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N,L=rl()
azi = [L+i-1 for i in range(1,N+1)]
S = sum(azi)
ind = 0
M = INF
for i in range(N):
    a = azi[i]
    if abs(a) < M:
        M = abs(a)
        ind = i

print(S-azi[ind])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = []
mi = float("inf")
for i in range(N):
    A.append(L+i)
    if abs(mi) > abs(L+i):
        mi = L+i
ans = sum(A) - mi
print(ans)

Submission status: Accepted

Solution code:

n, l = map(int,input().split())
A = []
for i in range(n):
    A.append(l+i)

ind = -1
minr = 10**10
for i in range(n):
    if abs(A[i])<minr:
        minr = abs(A[i])
        ind = i
print(sum(A)-A[ind])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())

apples= []
for i in range(1,N + 1):
    apples.append(L + i - 1)

As =sorted(apples,key=lambda x: abs(x))

print(sum(As) - As[0])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [L+i-1 for i in range(1, N+1)]
S = sum(A)
diff = float('inf')
ans = 0
for i in range(N):
    x = S - A[i]
    d = abs(S - x)
    if d < diff:
        diff = d
        ans = x
print(ans)

Submission status: Accepted

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Bad")
    elif q == 0:print("Good")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
n,l= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
a = [l+i for i in range(n)]
if min(a)>=0:
    a.pop(0)
elif max(a) < 0:
    a.pop(-1)
print(sum(a))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N,L=map(int,input().split())
A=[L+i for i in range(N)]
A.sort(key=lambda x:abs(x))

print(sum(A[1:]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, L = map(int, raw_input().split())
if L <= 0 < L + N:
    print sum(i for i in range(L, L + N))
elif 0 < L:
    print sum(i for i in range(L + 1, L + N))
else:
    print sum(i for i in range(L, L + N - 1))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            print("Bad")
            quit()
    print("Good")
    return

#B
def B():
    n,l = LI()
    a = [i+l for i in range(n)]
    ans = sum(a)
    m = n+l-1
    for i in a[::-1]:
        if i < 0:break
        m = min(m,i)
    ans -= m
    print(ans)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, l = na()

r = l+n-1

if l >= 0:
    s = 0
    for i in range(l+1, r+1):
        s += i
    print(s)
elif r <= 0:
    s = 0
    for i in range(l, r):
        s += i
    print(s)
else:
    s = 0
    for i in range(l, r+1):
        s += i
    print(s)

Submission status: Runtime Error

Solution code:
N, L = map(int, input().split())
A = []
for i in range(N):
  A.append(L+i)
i = 0
for k in A:
  if i == 0:
    x = 0
  else:
    x, y = abs(i), -abs(i)
  i += 1
  for

Submission status: Runtime Error

Solution code:
N,L = map(int,input().split())
a = []
for i in range(1,N+1):
  a.append(L+i-1)
b = []
for i in a:
  b.append(abs(i))
for i in range(1,N+!):
  if abs(L+i-1) == min(b):
    print(sum(a)-L-i+1)

Submission status: Runtime Error

Solution code:
N,L = map(int,input().split())
a = []
for i in range(N):
  a.append(L+i-1)
b = []
for i in a:
  b.append(abs(i))
for i in range(N):
  if abs(L+i-1) = min(b):
    print(sum(a)-L-i+1)

Submission status: Runtime Error

Solution code:
N,L = map(int,input().split())
a = []
for i in range(N):
  a.append(L+i-1)
b = []
for i in a:
  b.append(abs(i))
for i in range(N)
  if abs(L+i-1) = min(b):
    print(sum(a)-L-i+1)

Submission status: Runtime Error

Solution code:
N, L = map(int, input().split())

# 元々の味
s = (N-1)*(2*L+N-1) // 2
l = [abs(s - (L+i)) for i in range(N)]
m = min(l)
print(s - (L + [l.index(m)]))

Submission status: Runtime Error

Solution code:
N,L=map(int,input().split())
s = N*L+sum(1,N+1)-N
K=[]
for i in range(1,N+1):  
    K.append(L+i-1)
if 0 <= K[0]:
    s -= K[0]
elif K[0]<0 and K[N-1]>0:
    s = s
else:
    s -= K[N-1]
print(s)

Submission status: Runtime Error

Solution code:
N,L=map(int,input().split())
s = N*L+sum(1,N+1)-N
K=''
for i in range(1,N+1):  
    K.append(L+i-1)
if 0 <= K[0]:
    s -= K[0]
elif K[0]<0 and K[N-1]>0:
    s = s
else:
    s -= K[N-1]
print(s)

Submission status: Runtime Error

Solution code:
n,l=map(int,input().split())
l1=list(int(l)+i-1 for i in range(1,n+1))
l2=100
n1=sum(l1)

for i in range(1,n+1):
    if l2>abs(int(l)+i-1):
        l2=abs(int(l)+i-1)
        x=i

print(n1-l1[x-1])

Submission status: Runtime Error

Solution code:
n, l = map(int, input().split())
a = sorted([l + i for i in range(n)], key=abs)
print(sum(s[1:]))

Submission status: Runtime Error

Solution code:
n, l = map(int, input().split())
a = sorted([l + i - 1 for i in range(1, n-1)])
print(sum(a) - a[0] if abs(a[0]) > abs(a[-1]) else sum(a) - a[-1])

Submission status: Runtime Error

Solution code:
n,l=map(int,input().split())
c=0
m=100000
for i in range(1,n+1):
  c+=l+i-1
  m=min(m,abs(l+i-1))
if l<0 and a-n<=0:
  print(c+d)
else:
  print(c-d)

Submission status: Runtime Error

Solution code:
N,L = map(int,input().split())

apples = [i+L-1 for i in range(1,N+1)]

ans = float("inf")

for apple in apples:
  ans = min(ans,abs(apples))
  
print(ans)

Submission status: Runtime Error

Solution code:
N,L = map(int,input().split())

apples = [i+L-1 for i in range(1,N+1)]

ans = float("inf")

for j in range(N):
  ans = min(ans,abs(apples))
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = int(input())
 
if l >= 0:
  s = (2*l + n)*(n-1)/2
elif l < 0 and l + n-1 >= 0:
  s = (2*l + n - 1)*n/2
else:
  s = (2*l + n - 2)*(n-1)/2
 
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
l = int(input())

s = (2*l + n - 1)*n/2

if l >= 0:
  s = (2*l + n)*(n-1)/2
elif l < 0 and l + n-1 >= 0:
  s = (2*l + n - 1)*n/2
else:
  s = (2*l + n - 2)*(n-1)/2

print(s)

Submission status: Runtime Error

Solution code:
n,k=list(map(int,input().split()))
l=[]
for i in range(n):
  l.append(k+i)
l.sort()
if max(l)=>0 and min(l)<=0:
  print(sum(l))
elif max(l)<0:
  print(sum(l)-l[n-1])
else:
  print(sum(l)-l[0])