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:
N, L = map(int, input().split())
taste_list = []

for i in range(1, N+1):
    taste = L + i - 1
    taste_list.append((taste, abs(taste)))
    
sorted_taste_list = sorted(taste_list, key=lambda x: x[1])
del sorted_taste_list[0]
sum = 0
while sorted_taste_list:
    sum += sorted_taste_list.pop()[0]
print(sum)

Submission status: Accepted

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

taste =[]

for i in range(n):
    taste.append(l + i)

sum = 0

for i in range(n):
    sum += taste[i]

sa = 1000
ans = 0
for i in range(n):
    if sa > abs(sum - (sum - taste[i])):
        sa = abs(sum - (sum - taste[i]))
        ans = i

print(sum - taste[ans])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
ringo = [L+i-1 for i in range(1, N+1)]
ringo = sorted(ringo, key=lambda x: abs(x))
print(sum(ringo[1:]))

Submission status: Accepted

Solution code:
def main():

    n,l = map(int,raw_input().split())
    taste = []
    flag = True
    sum_taste = 0
    for i in range(n):
        sum_taste = sum_taste + i + l
        if (i + l) < 0:
            taste.append((abs(i + l),"nag"))
        else:
            taste.append((abs(i + l),"pog"))
    sorted_taste = sorted(taste,key = lambda x:x[0])
    if sorted_taste[0][1] == "nag":
        print(sum_taste + sorted_taste[0][0])
    else:
        print(sum_taste - sorted_taste[0][0])



if __name__ == "__main__":
    main()

Submission status: Accepted

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

azi=[]
for i in range(N):
  azi.append(L+i)
  
if azi[0]*azi[N-1]<=0:
  eat = 0
elif abs(azi[0])<=abs(azi[N-1]):
  eat = azi[0]
else:
  eat = azi[N-1]

total=sum(azi)-eat

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

if L < 0:
  if N + L <= 0:
    print(int((2 * L + N - 2) * (N - 1) / 2))
  else:
    print(int(N * (2 * L + N - 1) / 2))
else:
  print(int((2 * L + N) * (N - 1) / 2))

Submission status: Accepted

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

t1 = 100
s1 = 0
t4 = 0
for i1 in range(n1):

    t4 = n2 + i1
    
    s1 += t4
    if abs(t1) >= abs(t4):
        t1 = t4
print(s1 - t1)

Submission status: Accepted

Solution code:
#N  個のリンゴがあります。
#これらはそれぞれリンゴ 1、リンゴ 2、リンゴ 3、...、リンゴ N と呼ばれており、リンゴ i の「味」は L+i−1 です。
#「味」は負になることもありえます。
#また、1 個以上のリンゴを材料として、アップルパイをつくることができます。
#その「味」は、材料となったリンゴの「味」の総和となります。
#あなたはこれらのリンゴを全て材料として、アップルパイをつくる予定でしたが、おなかがすいたので 1 個だけ食べることにしました。
#勿論、食べてしまったリンゴはアップルパイの材料にはできません。
#つくる予定だったアップルパイとできるだけ同じものをつくりたいので、N 個のリンゴ全てを材料としてできるアップルパイの「味」と、食べていない N−1 個のリンゴを材料としてできるアップルパイの「味」の差の絶対値ができるだけ小さくなるように、食べるリンゴを選ぶことにしました。
#このようにして選ばれたリンゴを食べた時、食べていない N−1 個のリンゴを材料としてできるアップルパイの「味」を求めてください。
#なお、この値は一意に定まることが証明できます。

N, L = map(int, input().split())
A = [L+x for x in range(N)]

min_abs = abs(A[0])
ate = A[0]

for i in range(len(A)):
    if min_abs > abs(A[i]):
        min_abs = abs(A[i])
        ate = A[i]
        
print(sum(A)-ate)

Submission status: Accepted

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

total = sum(list(range(l, n+l)))
pie = []
min_abs = 9999999
for i in range(n):
    a = list(range(l, n+l))
    a.pop(i)
    if abs(total-sum(a)) < min_abs:
        min_abs = abs(total-sum(a))
        ans = sum(a)
print(ans)

Submission status: Accepted

Solution code:
def resolve():
	n,l=map(int,input().split())
	a=[i+l for i in range(n)]
	p=[i for i in a if i>0]
	m=[i for i in a if i<0]
	if 0 in a:
		print(sum(a))
	elif len(p)<len(m):
		print(sum(a)-max(m))
	else:
		print(sum(a)-min(p))
		
resolve()

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
a = [L + i - 1 for i in range(1, N+1)]
a.pop([i for i, j in enumerate(a) if min(np.abs(a)) == abs(j)][0])
print(sum(a))

Submission status: Accepted

Solution code:
import math

N,L = map(int,input().split())

sum = N*(N-1)//2 + N*L
if L >= 0:
    print(sum-L)
elif L+N-1 <= 0:
    print(sum-(L+N-1))
else:
    print(sum)

Submission status: Accepted

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

if apples[-1] < 0:
    apples[-1] = 0
elif l > 0:
    apples[0] = 0
print(sum(apples))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
aji = 0
for i in range(1,n+1):
    aji += l+i-1
sa = 1e10
ans = 0
for i in range(1,n+1):
    ajii = 0
    for j in range(1,n+1):
        if i == j:
            continue
        ajii += l+j-1
    #print(sa,ajii,i)
    if abs(ajii-aji) < sa:
        sa = abs(ajii-aji)
        ans = ajii
print(ans)

Submission status: Accepted

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

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

minaji = ringo[0]
for aji in ringo:
  if abs(minaji) > abs(aji):
    minaji = aji

print(sum(ringo) - minaji)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
left = l
right = n+l-1
eat = 0
aji = 0

if right <=0:
	eat = right
elif left >=0:
	eat = left
else:
	eat = 0

for i in range(left,right+1):
	aji += i

aji -= eat
print(aji)

Submission status: Accepted

Solution code:
import math

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

apple_tastes = [L + i - 1 for i in range(1, N + 1)]
sum_apple_tastes = sum(apple_tastes)
should_eat_apple_index = 0


def sum_up_apple_tastes_without_index(index):
    """sum up apple tastes without index"""
    copy = apple_tastes.copy()
    del copy[index]
    return sum(copy)


def abs_diff_sum_of_apple_tastes(index):
    """diff between sum of all tastes and sum of target """
    return math.fabs(
        sum_up_apple_tastes_without_index(index) -
        sum_apple_tastes
    )


for i, taste in enumerate(apple_tastes):
    current_diff = abs_diff_sum_of_apple_tastes(i)
    acc_diff = abs_diff_sum_of_apple_tastes(should_eat_apple_index)
    if (current_diff < acc_diff):
        should_eat_apple_index = i


result = int(sum_up_apple_tastes_without_index(should_eat_apple_index))
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ingredients = [l + i for i in range(n)]
bite_eating = min(ingredients, key=abs)
ans = sum(ingredients) - bite_eating
print(ans)

Submission status: Accepted

Solution code:
num, t = map(int, input().split())
taste = []
findmin = []

sum= 0
for i in range(1,num + 1):
  taste.append(t+i-1)
  sum += t+i-1
for j in range(len(taste)):
  findmin.append(taste[j]*taste[j])
m = findmin.index(min(findmin))
print(sum - taste[m])

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
table = []
for i in range(y,y+x):
    table.append(i)

if table[-1] <= 0:
    ans = sum(table) - table[-1]
elif table[0] < 0 and 0 <= table[-1]:
    ans = sum(table)
elif 0 <= table[0]:
    ans = sum(table) - table[0]
print(ans)

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
minimum = 10000000
table = [i for i in range(y,y+x)]

table1 = list(filter(lambda x: x>=0,table)) + [1000000000]
table2 = list(filter(lambda x: x<0,table))[::-1] + [-1000000]

if table1[0] > table2[0] * -1:
    print(sum(table) - table2[0])
else:
    print(sum(table) - table1[0])

Submission status: Accepted

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

n, l = map(int, input().split())
sum = 0
ans = [0]*n
apple = [0]*n
for i in range(n):
    apple[i] = l+i
    sum += apple[i]
    ans[i] = abs(apple[i])
print(sum-apple[ans.index(min(ans))])

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
minimum = 10000000
table = [i for i in range(y,y+x)]

for x in table:
    if abs(minimum) > abs(x):
        minimum = x
print(sum(table) - minimum)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [L+(x+1)-1 for x in range(N)]
min_abs = abs(A[0])
eat = A[0]
for i in range(len(A)):
  if min_abs > abs(A[i]):
    min_abs = abs(A[i])
    eat = A[i]
print(sum(A)-eat)

Submission status: Accepted

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

n = list(range(L, L+N))

if min(n) >= 0:
    n.remove(min(n))
elif min(n) < 0 < max(n):
    n.remove(0)
else:
    n.remove(max(n))

print(sum(n))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
n = 101
ret = 0
for x in range(L, L + N):
    ret += x
    if abs(x) < abs(n):
        n = x
print(ret - n)

Submission status: Accepted

Solution code:
inputs = [int(i) for i in input().split()]

min_abs_value = 1000
result = 0

for i in range(1, inputs[0]+1):
    value = inputs[1] + i - 1
    result += value
    if (abs(value) < abs(min_abs_value)):
        min_abs_value = value

result -= min_abs_value
print(result)

Submission status: Accepted

Solution code:
N,L=map(int,input().split(" "))
if N<2 or N > 200 or L<-100 or L>100:
	print ('Illegal')
else:
	s=L*N+N*(N+1)/2-N
	e=1-L

	if e<=0:
		e=1
	elif e>N:
		e=N
	s=s-(L+e-1)
	print(int(s))

Submission status: Accepted

Solution code:
NL = input().split()
N = int(NL[0])
L = int(NL[1])
apple = []
apple_abs = []
sum = 0
for i in range(1,N+1):
  apple.append(L+i-1)
  apple_abs.append(abs(L+i-1))

apple_min = min(apple_abs)

for i in apple:
  if abs(i) == apple_min:
    continue
  sum += i
print(sum)

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
azi=list(map(lambda x:L+(x+1)-1,range(N)))
sum=sum(azi)
min=float("inf")
for n in azi:
    if min > abs(n):
        min = abs(n)
        ans=sum-n 
print(ans)

Submission status: Accepted

Solution code:
check = 10000000
taste_all = 0
list1 = []
N, L = map(int, input().split()) 
for i in range(1,N+1):
    taste = L + i -1
    if (check > abs(taste)):
        check = min (check,abs(taste))
        remove_apple = taste
    list1.append(taste)
    taste_all =taste_all + taste
list1.remove(remove_apple)

print(sum(list1))

Submission status: Accepted

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

t = list(range(L, L + N))
s = sum(t)

if 0 in t:
    print(s)
else:
    if abs(t[0]) < abs(t[N - 1]):
        print(s - t[0])
    else:
        print(s - t[N - 1])

Submission status: Accepted

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

T = [L + i for i in range(N)]
T = sorted(T, key=lambda x: abs(x))

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
aji1 = [L+i-1 for i in range(1,N+1)]
aji = [abs(L+i-1) for i in range(1,N+1)]
#print(aji)
minaji = max(aji1)
no = 0
for i in range(N):
    if aji[i] < minaji:
        no = i + 1
        minaji = aji[i]
aji1[no-1] = 0
print(sum(aji1))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
for i in range(a):
    c.append([abs(b+i), b+i])
c.sort()
d = 0
for i in range(1, a):
    d += c[i][1]
print(d)

Submission status: Accepted

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

if(L>=0):
    print((N*L +N*(N-1)//2 - L))
if(L<0 and L+N-1>=0):
    print((N*L +N*(N-1)//2))
if(L<0 and L+N-1<0):
    print(N*L +N*(N-1)//2 - (L+N-1))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
list_=list(range(L,L+N))
print(sum(list_)-min(list(map(abs,list_)))*(1,-1)[max(list_)<0])

Submission status: Accepted

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

for i in range(N):
  lst.append(L + (i+1) - 1)
  
if L >= 0:
  print(sum(lst)-lst[0])
elif L+N-1 >= 0:
  print(sum(lst))
else:
  print(sum(lst) - lst[N-1])

Submission status: Accepted

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

if l >= 0:
    print(sum(taste)-taste[0])
elif l+n-1 >= 0:
    print(sum(taste))
else:
    print(sum(taste)-taste[n-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, L = map(int, str(input()).split())

# リンゴの味のリストを作成
Apple_taste = [ i + L for i in range(N)]

# Lが正の値の時、最小値を引く
# Lが負の値かつabs(L)>=Nのとき、最大値を引く
# それ以外は0を含むので、総和と一致する
if L >= 0:
    Output = sum(Apple_taste) - min(Apple_taste)
elif abs(L) >= N:
    Output = sum(Apple_taste) - max(Apple_taste)
else :
    Output = sum(Apple_taste)

print(Output)

Submission status: Accepted

Solution code:
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N, L = read_int()

apples = [L + i for i in range(N)]
tasteN = sum(apples)
INF = float('INF')
def solve():
    res = INF
    for a in apples:
        res = min(res, abs(a))
    return tasteN - res if res * tasteN > 0 else tasteN + res

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
n, l = [int(item) for item in input().split()]
apples = [item + l for item in range(n)]
if apples[0] <= 0 and apples[-1] >= 0:
    print(sum(apples))
elif apples[0] > 0:
    print(sum(apples[1:]))
else:
    print(sum(apples[:-1]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int):
    apple_taste_list = [L+i for i in range(N)]

    min_abs = 100000
    for i in apple_taste_list:
        if abs(i) < abs(min_abs):
            min_abs = i

    sum_of_taste = sum(apple_taste_list)
    
    print(sum_of_taste - min_abs)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
inf = float('inf')

N, L = map(int, input().split())

s = 0
eat = inf

for i in range(L, L + N):
    if abs(i) < abs(eat):
        eat = i
    s += i

print(s - eat)

Submission status: Accepted

Solution code:
import numpy as np

n, l = map(int, input().split())
apples = list(range(l, n + l))

if 0 in apples:
    print(sum(apples))
else:
    print(sum(apples) - sorted(apples, key=abs)[0])

Submission status: Accepted

Solution code:
intxt = input().split()
n = int(intxt[0])
l = int(intxt[1])
taste = n * (n + 2 * l - 1) // 2
if l + n - 1 <= 0:
    taste -= l + n - 1
elif l >= 0:
    taste -= l

print(taste)

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
total_taste = 0
pi = []
result = []
for i in range(1, N+1):
    taste = i + L - 1
    total_taste = taste + total_taste
for i in range(1, N+1):
    taste = i + L - 1
    pi.append(total_taste - taste)
for i in pi:
    result.append(total_taste - i)
print(pi[np.argmin(np.abs(result))])

Submission status: Accepted

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

tastes= [x for x in range(L,L+n,1)]

abs_tastes=[abs(x) for x in tastes]

eat = tastes[abs_tastes.index(min(abs_tastes))]

ans = sum(tastes) - eat

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,L=map(int,input().split())
A=[]
for i in range(N):
    A.append(L+i)
if max(A)<0:
    print(sum(A)-max(A))
elif min(A)>0:
    print(sum(A)-min(A))
else:
    print(sum(A))

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())

a = np.array(range(1,N+1))
t = a + L - 1

s = t.sum()

min = 90000000
min_ans = -90000000
for i in range(len(t)):
    x = abs(s - (s - t[i]))
    if x < min:
        min = x
        min_ans = s - t[i]

print(min_ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int):
    taste_max = L + N - 1
    taste_min = L
    if taste_min <= 0 and 0 <= taste_max:
        return (taste_min + taste_max) * N // 2
    elif taste_max < 0:
        return (taste_min + taste_max - 1) * (N - 1) // 2
    else:
        return (taste_min + 1 + taste_max) * (N - 1) // 2


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    print(solve(N, L))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
eat = L + N - 1
if eat > 0:
  eat = L
  if eat < 0:
    eat = 0

print("%d" % (1/2*N*(N+1)+(L-1)*N-eat))

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
li = []
a = 500
for i in range(n):
    li.append(i+l)
    if abs(a) > abs(i+l):
        a = i + l
print(sum(li) - a)

Submission status: Accepted

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

applePie = L*N
min = 20000

for i in range(N):
    applePie += i
    if (L+i)*(L+i) < min*min:
        min = L+i

applePie -= min

print(applePie)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
total = 0
for i in range(1,n+1):
    total += l+i-1
if l >= 0:
    print(int(total - l))
elif l < 1-n:
    print(int(total - (l+n-1)))
else:
    print(total)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = []
B = []
for i in range(N):
  A.append(L+i)
  B.append(abs(L+i))
C = sum(A[0:N])
D = max(A)
if D>0 :
  E=min(B)
else:
  E=D
print(C-E)

Submission status: Accepted

Solution code:
#abc131b

n,l=map(int,raw_input().split())

L=l
R=l+n-1
if R<=0:
 temp=R
elif L>=0:
 temp=L
else:
 temp=0
print (R+L)*(R-L+1)/2-temp

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    N, L = map(int, input().split())

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

    list2 = []
    for i in range(N):
        list2.append(abs(list[i]))

    list2.sort()
    tmp = list2.pop(0)

    if tmp in list:
        list.remove(tmp)
    elif -tmp in list:
        list.remove(-tmp)

    ans = 0
    for i in list:
        ans += i

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
total = int(N*L + (N/2)*(1+N) - N)
if L > 0:
  total -= L
elif 1 - L > N:
  total -= L + N - 1
print(total)

Submission status: Accepted

Solution code:
quantity, basis = map(int, input().split())

totalTaste = 0
# 食べる予定のリンゴの味を保持
eatApple = basis

for i in range(1, quantity + 1):
  # リンゴの味を計算
  appleTaste = basis + i - 1
  # 全部のリンゴを使った場合のアップルパイの味を計算
  totalTaste += appleTaste
  # リンゴの味の絶対値を比較し、今のリンゴのほうが小さい場合、食べるリンゴを更新する。
  if (abs(appleTaste) < abs(eatApple)):
    eatApple = appleTaste

print(totalTaste - eatApple)

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
from sys import stdin

def main():
    """
     解答をこちらに
    """
    n, l = list(map(int, input().split()))
    t = list(range(l, l+n))
    t_abs = list(map(abs,t))
    eat_ap = t_abs.index(min(t_abs))
    t.pop(eat_ap)
    print(sum(t))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

eat = apple[0]
for j in apple:
  if j < 0:
    if j > eat:
      eat = j
  elif j == 0:
  	eat = 0
  else:
    if j < eat:
      eat = j
print(sum(apple) - eat)

Submission status: Accepted

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

list=[]

num = 0

for i in range(N):
  
  num += L+i
  list.append(abs(L+i))
  
min_num = min(list)

if L+i-1 >=0:
  print(num - min_num)

else:
  print(num+min_num)

Submission status: Accepted

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

sum1 = sum(range(N)) + N * L
sum2 = [abs(L+ i) for i in range(N)]
select_num = sum2.index(min(sum2))
print(sum1 - (L + select_num))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
List = []
ans = 0
Min = float('inf') 
for i in range(1,N+1):
    List.append(L+i-1)
    Min = min(Min,abs(L+i-1))
    if L+i-1 <0:
        ans = (-1)*Min
    else:
        ans = Min
print(sum(List)-ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
R=L+N-1
s = sum(L + i for i in range(N))
if L ^ R < 0:
    print(s)
elif R < 0:
    print(s - R)
else:
    print(s - L)

Submission status: Accepted

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

taste = 0
for n in range(1, N+1):
    taste+=n+L-1
if (L > 0):
    taste-=L
elif (0 > N+L-1):
    taste-=N+L-1

print(taste)

Submission status: Accepted

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

azilist = range(L,L+N)
eatindex = -1

for i,a in enumerate(azilist):
    if i == len(azilist)-1:
        break
    else:
        b=abs(a)
        c=abs(azilist[i+1])
        if b<c:
            eatindex=i
            break
print(sum(azilist) - azilist[i])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
apple=[i+l for i in range(n)]
apple_abs=list(map(abs,apple))
tmp=apple[apple_abs.index(min(apple_abs))]
print(sum(apple)-tmp)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
ans = 101
all_sum = 0
for i in range(N):
    if ans > abs(L+i):
        ans = abs(L+i)
for i in range(N):
    if abs(L+i) == ans:
        continue
    else :
        all_sum += (L+i)
print(all_sum)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
origin=(2*L+N-1)*N/2
D=[]
A=[]
for i in range(1,N+1):
  answer=(2*L+N-1)*N/2-(L+i-1)
  difference=abs(origin-answer)
  A.append(int(answer))
  D.append(difference)
print(A[D.index(min(D))])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
temp = 10000
count = 0
for i in range(1, N+1):
    if abs(temp) > abs(L+i-1):
        temp = (L+i-1)

for i in range(1, N+1):
    count += L+i-1

count -= temp
print(count)

Submission status: Accepted

Solution code:
n, l = map(int, input().split(" "))
taste = []
for i in range(n):
  taste.append(i+l)
  
min_index = taste.index(min(taste, key=abs))

sum = 0
for i in range(n):
  if i != min_index:
    sum += taste[i]

print(sum)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sumA = 0
index = 0
while index < n:
    sumA+=index
    index+=1
if l <= 0 <= l+n-1:
    print(sumA+n*l)
else:
    if l > 0:
        print(sumA+n*l-l)
    else:
        print(sumA+n*l-l-n+1)

Submission status: Accepted

Solution code:
a, b=input().split(" ")
a=int(a)
b=int(b)

total=a*(b-1)+a*(a+1)/2

c=abs(b)
d=1
for i in range (1, a+1):
    if abs(b+i-1)<c:
        d=i
        c=abs(b+i-1)

print(int(total-(b+d-1)))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
A=[]
for i in range(N):
    A.append(L+i)
total=sum(A) #予定のアップルパイ 例1なら20

#絶対値の低いやつPU
b=10000
j=0 #絶対値の小さいリンゴの番号
for i in range(N):
    if abs(A[i]) < b:
        j=i
        b =abs(A[i])
print(total-A[j])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [] # リスト宣言(りんごの味)

for i in range(N):
    A.append(L + i) # A.append([追加するもの])

total = sum(A) # リストAの総和

# 持ってるりんごの味で一番絶対値が小さいものを選ぶ
b = 1000000
j = 0 # 絶対値が一番小さいりんごの番号
for i in range(N):
    if abs(A[i]) < b:
        j = i
        b = abs(A[i])

print(total - A[j])

Submission status: Accepted

Solution code:
N,L = list(map(int,input().split()))
sum = 0
list1 = []
list2 = []
for i in range(N):
    sum = sum+i+L

    list1.append(abs(i+L))
    list2.append(i+L)
print(sum - list2[list1.index(min(list1))])

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
c = []
d = []
e = 0
for i in range(a):
     c.append(i+b)
     d.append(abs(i+b))
     e += i+b
d = sorted(d)
if c[-1] < 0:
     print(e+d[0])
else:
     print(e-d[0])

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
sum = 0
eat = 9999
for i in range(1, N + 1):
	sum = sum + (L + i - 1)
	if abs(eat) > abs(L + i - 1):
		eat = L + i - 1

ans = sum - eat
print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
eat = 301
eatNum = 0
for i in range (0,N):
    if abs(i + L) < eat:
        eat = abs(i + L)
        eatNum = i
ans = 0
for i in range(0,N):
    if i != eatNum:
       ans += i + L
print(ans)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
before = (l-1)*n + int(n*(n+1)/2)
first = l
last = l+n-1
if first*last>0:
  if first>0:
  	print(before-first)
  else:
    print(before-last)
else:
  print(before)

Submission status: Accepted

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

# 絶対値が最小のリンゴを食べればよい
R = L + N - 1
S = N * (L + R) // 2
ans = S - max(0, L) - min(0, R)

# 出力
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
apple_sum = 0
eat_apple = float('inf')

for i in range(1,n+1):
	apple_sum += l + i - 1
	if abs(eat_apple) > abs(l+i-1):
		eat_apple = l+i-1

ans = apple_sum - eat_apple

print(ans)

Submission status: Accepted

Solution code:
inputs = input().split()
n = int(inputs[0])
l = int(inputs[1])

tastes = []
mintaste = l
for i in range(1, n+1):
  taste = l + i - 1
  tastes.append(taste)
  if abs(taste) < abs(mintaste):
    mintaste = taste

sum = sum(tastes) - mintaste

print(sum)

Submission status: Accepted

Solution code:
inputs = input().split()
n = int(inputs[0])
l = int(inputs[1])

tastes = []
minabs = abs(l)
for i in range(1, n+1):
  taste = l + i - 1
  tastes.append(taste)
  if abs(taste) < minabs:
    minabs = abs(taste)

sum = 0
for i in range(n):
  if abs(tastes[i]) != minabs:
    sum += tastes[i]

print(sum)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
  n, l = map(int, input().split(" "))
  app_list = []
  abs_min = 10000000000
  delete_member = 0
  for i in range(n):
    score = l + i
    app_list.append(score)
    if abs(score) < abs_min:
      delete_member = score
      abs_min = abs(score)
  app_list.remove(delete_member)
  print(sum(app_list))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
li = [i for i in range(l, l + n)]
min = 0
if l > 0:
  min = l
elif li[-1] < 0:
  min = li[-1]
print(sum(li) - min)

Submission status: Accepted

Solution code:
mylistA=[]
mylistB=[]
N,L=map(int,input().split())
for i in range(1,N+1):
  y=L+i-1
  mylistA.append(y)
  
mylistB=list(map(abs,mylistA))
x=min(mylistB)
z=mylistB.index(x)
print(sum(mylistA)-mylistA[z])

Submission status: Accepted

Solution code:
N, L = map( int, input().split())
now = abs(L)
for i in range(N):
    if abs(L+i) < now:
        now = abs(L+i)
ans = 0
for i in range(N):
    if abs(L+i) == now:
        continue
    ans += L+i
print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split(' '))
a = []
b = []
for i in range(0, n):
    a.append(l + i)
    b.append(abs(l + i))
a.pop(b.index(min(b)))
print(sum(a))

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
if y > 0:
    mini = y
elif x + y -1 < 0:
    mini = x + y - 1
else:
    mini = 0
print(x*y + x*(x+1)//2 - x - mini)

Submission status: Accepted

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

min_abs = 300
diff = 300

for i in range(1, N+1):
  if abs(L + i - 1) < min_abs:
  	min_abs = abs(L + i - 1)
  	diff = L + i - 1
print(total - diff)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
if l > 0:
    _min = l
elif l+n-1 < 0:
    _min = l+n-1
else:
    _min = 0
print(l*n + n*(n+1)//2 - n - _min)

Submission status: Accepted

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

sum = 0
for i in range(1,int(n+1)):
  sum += l + i - 1

if l > 0:
  sum = sum - l
else:
  #0を含むとき
  if n>abs(l):
    sum = sum 
  else:
    sum = sum - (l+n-1)
    
print(sum)

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
if N+L-1<=0:
  print(int(L*(N-1)+N*(N-1)/2-N+1))
elif L>=0:
  print(int(L*(N-1)+N*(N+1)/2-1-N+1))
else :
  print(int(L*N+N*(N+1)/2-N))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
L = list(range(L, N+L))
L_abs=list(map(lambda x: abs(x), L))
L.pop(L_abs.index(min(L_abs)))
print(sum(L))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

List = [int(x) for x in input().split()]
N = List[0]
L = List[1]

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

print(int(N*L-N+N*(N+1)/2-Choose))

Submission status: Accepted

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

taste = 0
taste_sum = 0
eat = 0
temp_eat = 0

for i in range(1,N+1):
  taste = L+i-1
  taste_sum += taste
  
  if i == 1:
    eat = taste
    temp_eat = abs(taste)
    
  elif abs(taste) < temp_eat:
    temp_eat = abs(taste)
    eat = taste

print(taste_sum - eat)

Submission status: Accepted

Solution code:
Amin = 10**9
ans = 0
N,L = (int(x) for x in input().split())
for i in range(N):
    Atmp = L + i
    ans += Atmp
    if abs(Amin) > abs(Atmp):
        Amin = Atmp
ans -= Amin
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min = 10**100
total_taste = 0
for i in range(N):
    taste = L + i
    if abs(min) > abs(taste):
        min = taste
    total_taste += taste
ans = total_taste - min
print (ans)