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())
lst=[]
for i in range(1,n+1):
    lst.append(l+i-1)

if min(lst)>0:
    ans=sum(lst)-min(lst)
elif max(lst)<0:
    ans=sum(lst)-max(lst)
else:  
    m = abs(lst[0])
    for i in range(n):
        if abs(lst[i])<m:
            m=abs(lst[i])
    ans=sum(lst)-m
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

apples = [L+n for n in range(N)]
apples = sorted(apples, key=lambda a: abs(a))

print(sum(apples[1:]))

Submission status: Accepted

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

if L >= 0:
    ans = real_sum - L
elif L <= -N:
    ans = real_sum - (L + N - 1)
else:
    ans = real_sum

print(ans)

Submission status: Accepted

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

sum = 0

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

x = 0
ans = 0
for i in range(1,n+1):
  x = sum - (l+i-1)
#  print("x:{}  ans:{} sum:{}".format(x,ans,sum))
  if abs(sum-x) < abs(sum-ans):
    ans = x
print(ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
sum = 0
min = abs(l)
num = 0
for i in range(n):
    sum += l + i
    if(min > abs(l + i)):
        min = abs(l + i)
        num = i
sum -= l + num
print(sum)

Submission status: Accepted

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

if apple[0]>0:
    print(sum(apple)-apple[0])
elif apple[n-1]<0:
    print(sum(apple)-apple[n-1])
else:
    print(sum(apple))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n,l=map(int,input().split())
aa=[l+i for i in range(n)]
s=sum(aa)
m=min(aa, key=abs)
print(s-m)

Submission status: Accepted

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

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

# 絶対値がもっとも小さい値のインデックスを求める

min_apple = 99999999
for i in range(len(apples)):
    if min_apple > abs(apples[i]):
        min_apple = abs(apples[i])
        omit = i

ans = 0
for i in range(len(apples)):
    if i == omit:
        continue
    else:
        ans += apples[i]

print(ans)

Submission status: Accepted

Solution code:
N, L = [int(x) for x in input().split()]
pie = 0
for i in range(1, N + 1):
	pie += L + i - 1
	if i == 1:
		minimum = L + i - 1
	elif i == N:
		maximum = L + i - 1

if minimum < 0:
	if maximum > 0:
		eat = 0
	else:
		eat = maximum
else:
	eat = minimum

print(pie - eat)

Submission status: Accepted

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

pie = 0
minimum = [0, float('inf')]
for i in range(1, N + 1):
	pie += L + i - 1
	if abs(L + i - 1) < minimum[1]:
		minimum[0] = i
		minimum[1] = abs(L + i - 1)

print(pie - (L + minimum[0] - 1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,l = map(int,input().split())
taste = np.array([l+i-1 for i in range(1,n+1)])
taste[np.fabs(taste).argmin()]=0
print(taste.sum())

Submission status: Accepted

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

lst = []
for i in range(n):
     lst.append(l + i)

avg = [sum(lst) - i for i in lst]

cnt = 0
tmp = 999
for n in range(len(avg) ):
    ans = abs(sum(lst) - avg[n])
    if abs(sum(lst) - avg[n]) < tmp:
        cnt = n
        tmp = ans
print(sum(lst) - lst[cnt])

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
S = 0
b = abs(L)
for i in range(1,N+1):
  a = L + i - 1
  S += a
  b = min(abs(a),b)
if -N < L:
  ans = S - b
else:
  ans = S + b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    N, L = list(map(int, input().split()))
    all_taste = 0
    eat_taste = float("inf")
    for i in range(1, N+1):
        all_taste += L+i-1
        eat_taste = min(eat_taste, abs(L+i-1))
    
    if all_taste > 0:
        ans = all_taste - eat_taste
    else:
        ans = all_taste + eat_taste
    print(ans)



if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

a = sorted(a)

if 0 in a:
    print(sum(a))
    
elif a[-1] < 0:
    print(sum(a[:-1]))
    
else:
    print(sum(a[1:]))

Submission status: Accepted

Solution code:
from sys import exit

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

taste = list(range(L, L + N))
n_sum = sum(taste)

exclude = min(list(map(abs, taste)))

if exclude in taste:
    print(n_sum - exclude)
else:
    print(n_sum + exclude)

Submission status: Accepted

Solution code:
input = list(map(int, input().split()))
N = input[0]
L = input[1]
# 2 <= N <= 200
# -100 <= L <= 100
# flavor = L + i - 1
minimum = -1000
i = 0
flavor = 0
sum = 0

X = 1 - L
if X >= 2 and X <= N:
    for x in range(1,N+1):
        if x != 1 - L:
            flavor = L + x - 1
            sum += flavor
elif X > N:
    for x in range(1,N+1):
        if x != N:
            flavor = L + x - 1
            sum += flavor
else:
    for x in range(1,N+1):
        if x != 1:
            flavor = L + x - 1
            sum += flavor
print(sum)

Submission status: Accepted

Solution code:
N,L = [int(a) for a in input().split(" ")]
tastes = [L + n for n in range(N)]
min_tastes = min(tastes,key=lambda a: abs(a))
print(sum(tastes)-min_tastes)

Submission status: Accepted

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

taste = 0
for i in range(1,n+1):
  if i == ate_ix:
    pass
  else:
    taste = taste+l+i-1
print(taste)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def main():
    # 整数の入力
    N, L = map(int, input().split())
    each_aji = [L + i - 1 for i in range(1,N+1)]
    abs_arg_min = np.argmin(np.abs(each_aji))
    each_aji.pop(abs_arg_min)
    print(sum(each_aji))


if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, A = input().split()[0:]
    assert 2<=int(N)<=200
    assert -100<=int(A)<=100

    L = int(A)
    R = int(A)+int(N)-1

    if R <= 0:
        eat = R
    elif L >= 0:
        eat = L
    else:
        eat = 0

    ans = (R+L)*(R-L+1)//2-eat
    print(ans)

Submission status: Accepted

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

total = (2*L + (N-1)) * N / 2

if L * (L+N-1) < 0:
    print(int(total))
else:
    if L < 0:
        print(int(total - L - (N-1)))
    else:
        print(int(total - L))

Submission status: Accepted

Solution code:
x = input().split()

u = 100
y = 0
is_minus = False
for i in range(int(x[0])):
    if abs(i+int(x[1])) < u:
        u = abs(i + int(x[1]))
        if (i + int(x[1])) < 0:
            is_minus = True
        else:
            is_minus = False
    y += i + int(x[1])

if is_minus:
    print(y + u)
else:
    print(y-u)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
 
total = 0
min_taste = 1000000000
 
for i in range(n):
    taste = l + i
    total += taste
    if abs(taste) < abs(min_taste):
        min_taste = taste
 
print(total - min_taste)

Submission status: Accepted

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

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

print(sum(sorted_values[1:]))

Submission status: Accepted

Solution code:
import math

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

# N 個のリンゴ全てを材料としてできるアップルパイの「味」
taste_all = L * N + N * (N - 1) // 2

# taste_all と 食べていない N−1 個のリンゴを材料としてできる
# アップルパイの「味」との差の絶対値が最小のものを求める

# 絶対値が最小の1個のリンゴの「味」を求める
taste_abs_min = 0
if L >= 0:
    taste_abs_min = L
elif L + N - 1 < 0:
    taste_abs_min = L + N - 1
else:
    taste_abs_min = 0

result_taste = taste_all - taste_abs_min

print(result_taste)

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))
list=[]
i=0
p=abs(i+s[1])
for i in range(s[0]):
  list.append(i+s[1])
  if min(list)+s[1]==0:
    p=0
  else:
    if p>abs(i+s[1]):
      p=abs(i+s[1])
a=sum(list)
if a<0:
  print(a+p)
else:
  print(a-p)

Submission status: Accepted

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

Submission status: Accepted

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

taste = list(map(int, list(range(L, N + L))))
dam = [0] * N

for c in range(N):
    dam[c] = abs(taste[c])
print(sum(taste) - taste[dam.index(min(dam))])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,l = LI()
    a = [l+i for i in range(n)]
    s = sum(a)

    if 0 in a:
        return s

    if a[0] < 0:
        return s - a[-1]

    return s - a[0]


print(main())

Submission status: Accepted

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

Submission status: Accepted

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

tastes = []
for i in range(0, N):
    tastes.append(L+i)

abs_tastes = list(map(abs, tastes))

min_v = min(abs_tastes)
min_i = abs_tastes.index(min_v)

del tastes[min_i]
print(sum(tastes))

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
dis_min = 1000000000

for i in range(n):
    taste = l + i
    total += taste
    if abs(taste) < abs(dis_min):
        dis_min = taste

print(total - dis_min)

Submission status: Accepted

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

taste_list = []

dis_min = 1000000000

for i in range(n):
    taste = l + i
    taste_list.append(taste)
    if abs(taste) < abs(dis_min):
        dis_min = taste

print(sum(taste_list) - dis_min)

Submission status: Accepted

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

print(sum(range(1,N+1))+L*N-N-num)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
taste = [(L+i) for i in range(N)]
taste_abs = [abs(taste[i]) for i in range(N)] 
p = taste_abs.index(min(taste_abs))
taste[p] = 0
print(str(sum(taste)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, L = map(int,input().split())
s = []
eat = 9999

for i in range(1,N+1):
    value = i + L - 1
    s.append(value)
    if abs(eat) > abs(value):
        eat = value

print(sum(s) - eat)

Submission status: Accepted

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

del taste[apple.index(min(apple))]
print(sum(taste))

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
c = [i+b for i in range(a)]
d = [abs(j+b) for j in range(a)]
print(sum(c)-c[d.index(min(d))])

Submission status: Accepted

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

N = lis[0]
L = lis[1]

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(N):
  A.append(L+i)
a=sum(A)
for i in range(N):
  B.append(a-A[i])
for i in range(N):
  C.append(abs(a-B[i]))
c=float('inf')
ans=0
for i in range(N):
  if C[i]<c:
    ans=i
    c=C[i]
print(B[ans])

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-
# @Date    : 2019-06-24 21:15:56
# @Author  : raj lath (oorja.halt@gmail.com)
# @Link    : link
# @Version : 1.0.0

import sys
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


n, L = RMI()
arr = [ L + i -1  for i in range(1, n + 1)]
count_0 = arr.count(0)
sums    = sum(arr)
if count_0 == 1: del arr[arr.index(0)]
elif count_0 == 0 and sums >= 1: del arr[arr.index(min(arr))]
elif count_0 == 0 and sums <= -1:del arr[arr.index(max(arr))]
else:pass
print(sum(arr))

Submission status: Accepted

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

print(int(res))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apple = L
for i in range(N):
    if abs(L+i) < abs(apple):
        apple = L+i
    
print(int((L+L+N-1)/2 * N -apple))

Submission status: Accepted

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

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

import itertools
c = itertools.combinations(Apple, N-1)
apple_sum = sum(Apple)
near = (apple_sum + 1 )* 100
ans = 0

if 0 in Apple:
  print(apple_sum)
else:
  for v in c:
    vv = sum(v)
    if abs(apple_sum - vv) <= abs(near):
      near = apple_sum - vv
      ans = vv
  print(ans)

Submission status: Accepted

Solution code:
import math

N, L = list(map(int, input().split(" ")))
apples = [L + i - 1 for i in range(1, N + 1)]
abss = list(map(abs, apples))
m = apples[abss.index(min(abss))]
print(sum(apples) - m)

Submission status: Accepted

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

N_all = []
for i in range(N):
    N_all.append(L + (i + 1) - 1)
#print(sum(N_all))
#print(N_all)

if N_all.count(0) == 1:
    x = N_all.index(0)
    del N_all[x]
elif N_all.count(0) == 0 and sum(N_all) >= 1:
    x = min(N_all)
    x = N_all.index(x)
    del N_all[x]
elif N_all.count(0) == 0 and sum(N_all) <= -1:
    x = max(N_all)
    x = N_all.index(x)
    del N_all[x]
else:
    pass
print(sum(N_all))

Submission status: Accepted

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

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

arr = [None] * N

for i in range(N):
    arr[i] = L + i

minV = 1e20

for i in range(N):
    if abs(arr[i]) < abs(minV):
        minV = abs(arr[i])
        d = arr[i]

print(sum(arr) - d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
eat = float('inf')
ans = 0

for i in range(1, N+1):
    tmp = L+i-1
    ans += tmp
    if abs(eat) > abs(tmp):
        eat = tmp

print(ans - eat)

Submission status: Accepted

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

eats = 999
is_minus = False

for i in range(n):
    azi = l + (i + 1) - 1

    if eats > abs(azi):
        eats = abs(azi)
        is_minus = True if azi < 0 else False


w = eats if is_minus == False else eats * -1

print(sum([l + (e + 1) - 1 for e in range(n)]) - w)

Submission status: Accepted

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

T=[]
t=1000
for i in range(N):
    if t>abs(L+i+1-1):
        t=abs(L+i+1-1)
        x=i
    T.append(L+i+1-1)
print(sum(T)-T[x])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ans = l*n + n*(n-1)//2

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

Submission status: Accepted

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

total_taste = 0
min_taste = float('inf')
for i in range(1, N + 1):
    taste = L + i - 1
    total_taste += taste
    if abs(taste) < abs(min_taste):
        min_taste = taste

print(total_taste - min_taste)

Submission status: Accepted

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

del apples[0]
print(sum(apples))

Submission status: Accepted

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

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

ans = (L + (L + N - 1)) * N // 2 - eaten
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if apple[0] >= 0:
   apple.pop(0)
elif apple[N-1] < 0:
    apple.pop(N-1)
else:
    apple.pop(-apple[0])
    
print(sum(apple))

Submission status: Accepted

Solution code:
import numpy as np
i = list(map(int, input().split()))
arr = np.linspace(i[1],i[0]+i[1]-1,i[0])
abs_arr = np.abs(arr)
min_index = np.argmin(abs_arr)
print(int(arr.sum() - arr[min_index]))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apple = []
for i in range(1, N+1):
    apple.append(L + i - 1)
    
apple_eating = []
sum_apple = sum(apple)
for j in apple:
    apple_eating.append(sum_apple - j)
    
temp = 100
ans = 0
for k in apple_eating:
    if abs(sum_apple - k) <= temp:
        temp = abs(sum_apple - k)
        ans = k
        
print(ans)

Submission status: Accepted

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

apples = [i for i in range(L, L+N)]
abs_apples = [abs(i) for i in apples]
eaten_apple_taste = apples[abs_apples.index(min(abs_apples))]

taste_N = sum(apples)
ans = taste_N - eaten_apple_taste
print(ans)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
taste=[l+i-1 for i in range(1,n+1)]
ttastee=[]
for i in taste:
	if i<0:
		ttastee.append(i*(-1))
	else:
		ttastee.append(i)

taste.pop(ttastee.index(min(ttastee)))
print(sum(taste))

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(N):
    flag = True
    for j in range(N-1):
        if abs(apple[j]) > abs(apple[j+1]):
            apple[j],apple[j+1] = apple[j+1],apple[j]
            flag = False
    if flag == True :
        break

del(apple[0])
print(sum(apple))

Submission status: Accepted

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

lst_A = []

for i in range(N):
    lst_A.append(L)
    L += 1

eat = 999

for i in range(N):
    if abs(lst_A[i]) < abs(eat):
        eat = lst_A[i]

i = 0
while 1:
    if lst_A[i] == eat:
        del lst_A[i]
        break
    i += 1

print(sum(lst_A))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
sum_py = 0
apple_list = []
eat_num = 0
eat_i = 0

for i in range(1, N + 1):
    if eat_num < abs(L + i - 1):
        eat_num = abs(L + i - 1)

for i in range(1, N + 1):
    if abs(L + i - 1) < eat_num:
        eat_num = abs(L + i - 1)
        eat_i = i
    apple_list.append(L + i - 1)

del apple_list[eat_i - 1]
sum_py = sum(apple_list)

print(sum_py)

Submission status: Accepted

Solution code:
import sys
n,l=map(int,input().split())
ls=[]
for i in range(n):
    ls.append(l+i)  #iは0から始まるので-1した。

ls.sort()
st=0
hoge=0
sum_ls=sum(ls)

def i_hantei(k):
    if k!=0:
        return True
    return False

#上限と下限が0以下または0以上ではないか調べる。
if ls[-1]<0:
    print(sum_ls-ls[-1])
    sys.exit()
if ls[0]>0:
    print(sum_ls-ls[0])
    sys.exit()

for i in range(n):
    if ls[i]<0:
        continue
    else:
        if i_hantei(i)==False:
            hoge=ls[i]
            break
        if abs(ls[i-1])<=abs(ls[i]):
            hoge=ls[i-1]
        else:
            hoge=ls[i]
        break
    
print(sum_ls-hoge)

Submission status: Accepted

Solution code:
N, L = input().split()
apples = [x + int(L) for x in list(range(int(N)))]
abs_apples = [abs(x) for x in apples]
abs_min_index = abs_apples.index(min(abs_apples))
print(sum(apples) - apples[abs_min_index])

Submission status: Accepted

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

apples = list(range(N)) 
apples = [x + L for x in apples]
abs_apples = [abs(x) for x in apples]
abs_min_index = abs_apples.index(min(abs_apples))

print(sum(apples) - apples[abs_min_index])

Submission status: Accepted

Solution code:
import numpy as np
def getNearestValue(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n,l=map(int,input().split())
ap=[i+l-1 for i in range(1,n+1)]
aps=sum(ap)
apsav=[aps-ap[i] for i in range(n)]
print(getNearestValue(apsav,aps))

Submission status: Accepted

Solution code:
import numpy as np
n, l = map(int,input().split())
q = np.array([l+i for i in range(n)])
s = np.argmin(np.abs(q))
print(np.sum(q)-q[s])

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
sumL = 0
mainasu = 0
plus = 0
aji = []
count = 0
for i in range(N):
  aji.append(L + i)
  sumL += L + i
  if L + i == 0:
    count = 1
  elif L + i  < 0:
    mainasu += 1
  elif L + i > 0:
    plus += 1
if count == 1:
  print(sumL)
elif mainasu > plus :
  print(sumL-max((aji)))
else:
  print(sumL-min((aji)))

Submission status: Accepted

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

addList = []
total = 0
for n in range(1, N+1):
    addList.append(L + n-1)
    total = total + L + n-1

exceptNum = 0
if addList[-1] <= 0:
    exceptNum = addList[-1]
elif addList[0] >= 0:
    exceptNum = addList[0]

print(total - exceptNum)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
mn=10**5
taste = [l+i for i in range(n)]
sm=sum(taste)
for i in range(n):
    if abs(taste[i])<mn:
        mn = abs(taste[i])
        ans = sm - taste[i]

print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
T = [L+i for i in range(N)]
T_abs = [abs(x) for x in T]
min_T_abs_idx = T_abs.index(min(T_abs))
print(sum(T) - T[min_T_abs_idx])

Submission status: Accepted

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

Submission status: Accepted

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

d = 10 ** 9
ans = 0

s = 0
for i in range(n):
    s += L + i

for i in range(n):
    if d > abs(L + i):
        d = abs(L + i)
        ans = s - (L + i)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
taste=0
if L>=0:
    for i in range(2,N+1):
        taste=taste+L+i-1
elif L+N-1>=0:
    for i in range(1,N+1):
        taste=taste+L+i-1
else:
    for i in range(1,N):
        taste=taste+L+i-1

print(taste)

Submission status: Accepted

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

prev_abs_min = 1000
abs_min = 0
for i in range(1, n+1):
    if prev_abs_min > abs(l + i - 1):
        prev_abs_min = abs(l + i - 1)
        abs_min = l + i - 1
ans -= abs_min
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


ApplesTaste=[]
for i in range(int(N)):
    taste=int(L)+i
    ApplesTaste.append(taste)


hu=0
zero=0
for i in ApplesTaste:
    
    if i is 0:
        zero+=1
    if i < 0:
        hu+=1

#0がある
if zero is 1:
    point=ApplesTaste.index(0)
    del ApplesTaste[point]
    print(sum(ApplesTaste))

#0がなく全部負
elif hu > 0 and zero is 0:
    point=len(ApplesTaste)-1
    
    del ApplesTaste[point]
    print (sum(ApplesTaste))

else:
    del ApplesTaste[0]
    print(sum(ApplesTaste))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
ls1=[]
for i in range(N):
    aj=L+i
    ls1.append(aj)
ls2=sorted(ls1,key=lambda x:abs(x))
del ls2[0]
print(sum(ls2))

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
dict_N = {}
min_zero = 100 + 200 - 1
min_id = 0
for i in range(1, N + 1):
    dict_N[i] = L + i - 1
    if min_zero > abs(dict_N[i]):
        min_zero = abs(dict_N[i])
        min_id = i

del dict_N[min_id]
print(sum(dict_N.values()))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
a = []
minabs = 1000
tmp = -1

for i in range(N):
    p = L + i
    a.append(L + i)#i = i - 1のため
    if abs(p) < minabs:
        minabs = abs(p)
        tmp = i

print(sum(a) - a[tmp])

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    n, l = map(int, input().split())
    MIN = l
    MAX = l + n - 1
    ans = l * n + n * (n - 1) / 2
    if MIN >= 0:
        print(int(ans - l))
    elif MIN < 0 and 0 < MAX:
        print(int(ans))
    else:
        print(int(ans - MAX))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input = input().split(' ')
N = int(input[0])
L = int(input[1])

tasts = [L + i -1 for i in range(1, N+1)]
abs_tasts = [abs(t) for t in tasts]
print(sum(tasts) - tasts[abs_tasts.index(min(abs_tasts))])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ans=0;count=100
for i in range(n):
    ans+=i+l
    if abs(i+l)<=abs(count):
        count=i+l
print(ans-count)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = [0] * n
i = 0
s = 0
while i < n:
    a[i] = l + i  # a = azi
    s += a[i]  # s = sum
    i += 1
f = 1e9
ans = 0
i = 0
while i < n:
    if f > abs(a[i]):
        f = abs(a[i])
        ans = s - a[i]
    i += 1
print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    n, l = list(map(int, input().split()))
    a = []
    for i in range(1, n+1):
        a.append(l + i - 1)

    ab = abs(sum(a))
    for i in a:
        if abs(ab) > abs(i):
            ab = i
    print(sum(a) - ab)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = list(range(L, L+N))
a.sort(key=abs)

print(sum(a[1:]))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
apple = [i + l for i in range(n)]
eat = 10 ** 10
num = 10 ** 10
for i in range(n):
  if eat >= abs(apple[i]):
    num = i
    eat = abs(apple[i])
print(sum(apple)-apple[num])

Submission status: Accepted

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