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

Solution (Python):
import copy

line = list(map(int, input().split()))

apple_count = line[0]
apple_taste = line[1]

apple_list = []
taste_list = []

for i in range(1, apple_count+1):
  apple_list.append(i)
  taste_i = apple_taste+i-1
  taste_list.append(taste_i)

risou = sum(taste_list)
results = []

for a in range(len(taste_list)):
  tastes = copy.copy(taste_list)
  tastes.pop(a)
  hikaku = sum(tastes)
  
  abs_a = abs(risou-hikaku)
  results.append(abs_a)

pop_index = results.index(min(results))
taste_list.pop(pop_index)

print(sum(taste_list))

Solution (Python):
a = input().split()
num = int(a[0])
L = int(a[1])
apple = dict()
orig_taste = 0
for i in range(1, num + 1) :
    apple[i] = L + i - 1
    orig_taste += L + i - 1

if(L + num - 1 > 0 and L > 0):
    print(orig_taste - L)
elif(L + num - 1 > 0 and L < 0):
    print(orig_taste)
elif(L + num - 1 < 0 and L < 0):
    print(orig_taste - L - num + 1)
else:
    print(orig_taste)

Solution (Python):
import numpy as np

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

taste_list = []
for i in range(N):
  taste_i = M + (i+1) - 1
  taste_list.append(taste_i)
  
taste_list = np.array(taste_list)

if M >= 0:
	ind = np.argmin(taste_list)
else:
  if N - 1 >= M * -1:
    ind = M * -1
  else:
    ind = N -1
    

taste_n1 = 0
for i in range(N):
  if i != ind:
  	taste_n1 += M + (i+1) -1
    
print(taste_n1)

Solution (Python):
N, L = map(int, input().split())
if L >= 0:
  l = map ( lambda x : x + L, range(1, N))
  print(sum(l))
elif -L < N :
  l = map ( lambda x : x + L, range(0, N))
  print(sum(l))
else:
  l = map ( lambda x : x + L, range(0, N))
  print(sum(l) - (N+L-1))

Solution (Python):
number, taste_base = map(int, input().split(' '))

pie_all = int(number * ((number + 1) / 2 + taste_base - 1))

taste_range = range(taste_base, taste_base + number)
taste_range_abs = [abs(i) for i in taste_range]
abs_min = min(taste_range_abs)
minimum = 0

if abs_min in taste_range:
    minimum = abs_min
else:
    minimum = -abs_min

print(pie_all - minimum)

Solution (Python):
l = list(map(int,input().split()))
N = l[0]
L = l[1]

apple =[]

for i in range(N):
    apple.append(L + i)

pie = 0
flag = 1
min = abs(L)
for i in range(N):
    pie = pie + apple[i]
    if abs(apple[i]) < min:
        min = abs(apple[i])
        if apple[i]<0:
            flag = -1
        else:
            flag = 1

pie = pie - flag * min

print(pie)

Solution (Python):
n, l = map(int, input().split())
m = 100000000
ans = 0
for i in range(n):
    ans += i + l
    if abs(m) > abs(i + l):
        m = i + l

ans -= m
print(ans)

Solution (Python):
n, l = map(int, input().split())
dat_a = []

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

total = sum(dat_a)


res = 100000
m = 10000

for i in range(n):
    if abs(dat_a[i] < m):
        m = abs(dat_a[i])
        res = dat_a[i]

print(total - res)

Solution (Python):
import bisect
N,L=map(int,input().split())
S=[]
M=[]
a=0
for i in range(N):
    S.append(abs(L+i))
    M.append(L+i)
S.sort()
for i in range(N):
    if abs(M[i])==S[0]:
        a=M[i]
print(sum(M)-a)

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

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

pie = sum(tastes)
absmin = max(abs(tastes[-1]),abs(tastes[0]))

for i in tastes:
    if abs(i) < abs(absmin):
        absmin = i
print(pie-absmin)

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

Nsum=0
sum=0
for i in range(N):
    Nsum+=L+i

sa=1000000000
for i in range(N):
    a = (L+i)
    if(a<0):
      a=-a
    if(sa > a):
        sa=a

if(Nsum<0):
	print(Nsum+sa)
else:  
	print(Nsum-sa)

Solution (Python):
N, L = map(int,input().split())
total_taste = N*(L-1)+N*(N+1)/2
min_diff = 10**8
for i in range(1,N+1):
    
    apple_taste = L+i-1
    pie_taste = total_taste - apple_taste
    taste_diff = abs(total_taste-pie_taste)
    
    if taste_diff < min_diff:
        min_diff = taste_diff
        ans = pie_taste
        
print(int(ans))

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

all_taste = N*(L-1)+N*(N+1)/2
tastes_list=[0]*N

for i in range(1,N+1):
    tastes_list[i-1] = L+i-1
abs_list = [abs(x) for x in tastes_list]
min_idx = abs_list.index(min(abs_list))
ans = sum(tastes_list) - tastes_list[min_idx]
print(ans)

Solution (Python):


import numpy as np
n,l  = map(int, input().split())
a = np.arange(l,l + n, 1)
amax = l + n -1
amin = l
if amax * amin >0:
    if abs(amax) - abs(amin)>0:
        print(sum(a) - (amin))
    else:
        print(sum(a) - (amax))
elif amax * amin <= 0:
    print(sum(a))
else:
    pass

Solution (Python):
import numpy as np

li = input().split()
N = int(li[0])
L = int(li[1])
apple = []

for i in range(N):
  apple.append(L+i)

if sum(apple) >= 0:
	m = min(np.abs(apple))
else:
	m = -min(np.abs(apple))

ans = sum(apple) - m
print(ans)

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

b = l
s = 0
for a in range(n+1)[1::]:
  m = l + a - 1
  if abs(b) > abs(m):
    b = m
  s += m

print(s - b)

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

lst = [l+i for i in range(0, n)]

abs_lst = list(map(abs, lst))
min_lst = abs_lst.index(min(abs_lst))

lst.remove(lst[min_lst])
res = sum(lst)


print(res)

Solution (Python):
def main():
    N, L = map(int, input().split())
    pia = 0
    for i in range(1, N+1):
        pia += L + i - 1

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

    print(pia - eat)


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
n,l=map(int,input().split())
li=[]
liabs=[]
for i in range(n):
    li.append(l+i+1-1)
    
if 0 in set(li):
    print(sum(li))
elif li[0]>0:
    print(sum(li)-min(li))
else:
    print(sum(li)-max(li))

Solution (Python):



def sumSuccessionNum(n):
    s = 0
    for i in range(n):
        s += i + 1
    
    return s

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

ans = sumSuccessionNum(N) + (L - 1) * N
tasteMax = L + N - 1
tasteMin = L

if(tasteMax > 0 and tasteMin > 0):
    ans -= tasteMin
elif(tasteMax < 0 and tasteMin < 0):
    ans -= tasteMax

print(ans)

Solution (Python):
import numpy as np
N, L = map(int,input().split())
apple_list = [L+i for i in range(N)]
apple_list_abs = np.abs(apple_list)
min_index = np.argmin(apple_list_abs)
del apple_list[min_index]
ans = sum(apple_list)
print(ans)

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

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

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

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

Solution (Python):
N,L=map(int,input().split())
l=[0]*N
for i in range(N):
	l[i]=L+i
if 0 not in l:
	l.remove(l[-1] if l[0] < 0 else l[0])
print(sum(l))

Solution (Python):
N,L = [int(x) for x in input().split()]
A = list(range(L,L+N))
Min = 100
for i in A:
    if Min >= abs(i):
        youso = i
        Min = abs(i)
A.remove(youso)
print(sum(A))

Solution (Python):
x = input().split()
x = [int(i) for i in x]
apples = []
for i in range(x[0]):
  apples.append(i+x[1])
ab_apples = [abs(i) for i in apples]
max_ap = max(apples)
min_ab = min(ab_apples)
if max_ap > min_ab:
  apples.remove(min_ab)
  print(sum(apples))
else:
  apples.remove(max_ap)
  print(sum(apples))

Solution (Python):
import numpy as np

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

tastes = np.array([L+(i+1)-1 for i in range(N)])

if 0 in tastes:
    print(tastes.sum())
else:
    if np.sign(tastes[0]) == 1:
        print(tastes[1:].sum())
    else:
        print(tastes[:-1].sum())

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

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

n_sum = sum(a)
answer = 0    
calc = []
for i in range(n) :
    diff = n_sum - a[i]
    calc.append((diff,abs(n_sum-diff)))    

from operator import itemgetter
calc = sorted(calc, key=itemgetter(1), reverse=False)    
    
print(calc[0][0])

Solution (Python):
N,L=list(map(int,input().split()))
tmp=[i+L-1 for i in range(1,N+1)]
if 0 in tmp:
    print(sum(tmp))
else:
    if sum(tmp)<0:
        print(sum(tmp[:-1]))
    else:
        print(sum(tmp[1:]))

Solution (Python):
import numpy as np
n, l = map(int, input().split())

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


num = 0

def nearvalue(x, num):
        idx = np.abs(np.asarray(x) - num).argmin()
        del x[idx]
        
        print(sum(x))

nearvalue(x, 0)

Solution (Python):
N,L = map(int,input().split())
sum_list=[]
l2=[]
l3=[]
for i in range(1,N+1):
  sum_list.append(L+i-1)
  
if 0 in sum_list:
  print(sum(sum_list))
else:
  for j in sum_list:
    l3.append(abs(j))

l2=[k for k in sum_list if not 0 in sum_list and abs(k) == min(l3)]

if not 0 in sum_list:
  print(sum(sum_list)-l2[0])

Solution (Python):
N, L = map(int,input().split())
azi = [L+i-1 for i in range(1,N+1)]
mini = abs(azi[0])

for i in azi:
    if abs(i) < abs(mini):
        mini = i
azi.remove(mini)
print(sum(azi))

Solution (Python):
N,L=map(int,input().split())
sum=L
m=abs(L)
b=L
for i in range(1,N):
    a=L+i
    sum+=L+i
    if(abs(a)<=m):
        m=abs(a)
        b=a
print(sum-b)

Solution (Python):
n, l = list(map(int, input().split(' ')))

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

idx_eaten = -1
if taste[0] <= 0:
    if taste[n-1] < 0:
        idx_eaten = n - 1
    else:
        idx_eaten = -taste[0]
else:
    idx_eaten = 0
    
result = 0
for i in range(n):
    if i == idx_eaten:
        continue
    result += taste[i]
    
print(result)

Solution (Python):
sowa=0
hajime=[]

for x in input().split(" "):
    hajime.append(int(x))

if hajime[1]>0:
    i=2
    while i<=hajime[0]:
        sowa+=hajime[1]+i-1
        i+=1

elif hajime[1]==0:
    i=1
    while i<=hajime[0]:
        sowa+=hajime[1]+i-1
        i+=1

else:
    if hajime[0]+hajime[1]-1>=0:
        i=1
        while i<=hajime[0]:
            sowa+=hajime[1]+i-1
            i+=1
    else:
        i=1
        while i<=hajime[0]-1:
            sowa+=hajime[1]+i-1
            i+=1

print(sowa)

Solution (Python):
lista = input().split(" ")
a, b = lista
a = int(a)
b = int(b)
s = 0
a1=[]

while(a!=0):
    s+=b
    a1.append(b)
    b+=1
    a-=1
if 0 in a1:
    print((int(s)))
elif(b>0):
    print((int(s)-min(a1)))
else:
    print((int(s)-max(a1)))

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

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

ap = float("inf")

for a in A :
    if ap > abs(a) :
        ap = abs(a)

applepie = sum(A)


if abs(applepie-ap) < abs(applepie+ap) :
    ans = applepie-ap
else :
    ans = applepie+ap





print(ans)

Solution (Python):




import sys
import math
from pprint import pprint
import numpy as np


text =input()
N=int(text.split()[0])
sentounoaji=int(text.split()[1])


saigonoaji=sentounoaji+N-1

goukei = int((sentounoaji*N) + (saigonoaji-sentounoaji)*N/2)

if sentounoaji<=0 and 0<=saigonoaji : 
    print(goukei)
elif 0<sentounoaji :
    print(goukei-sentounoaji)
else :
    print(goukei-saigonoaji)

Solution (Python):
inp = input()
split_inp = inp.split()
n = int(split_inp[0])
l = int(split_inp[1])

total_number = 0
abs_min = -1
abs_l = 0
for i in range(l, l+n):
    
    if abs_min == -1:
        abs_min = abs(i)
        abs_l = i
    elif abs(i) < abs_min:
        abs_min = abs(i)
        abs_l = i
    total_number += i
print(total_number - abs_l)

Solution (Python):
N, L = map(int, input().split())
t = [0]*N
for i in range(N):
    t[i] = L+i
a = list(map(abs, t))
idx = a.index(min(a))
t.pop(idx)
print(sum(t))

Solution (Python):
import numpy as np
N,L = map(int,input().split())
aji_all = aji_all = N*L + (N-1)*N/2
aji_list = np.arange(L,L+N,1)
idx = np.argmin(np.abs(aji_list))
ans = aji_all - aji_list[idx]
print(int(ans))

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

aji = 0  
mini = 1000
for i in range(0, n) :
    aji = aji + i + l
    if (abs(mini) > abs(i + l)) :
        mini = (i + l)

print(aji-mini)

Solution (Python):
n, l = [int(i)  for i in input().split()]
apple=[]
sub=[]
for i in range(1,n +1):
    apple.append(l + i -1)
    
for i in range(n):
    ap=apple.copy()
    ap[i]=0
    sub.append(sum(apple) - sum(ap))


a=list(map(abs, sub))
b=a.index(min(a))
apple.pop(b)
print(sum(apple))

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

pre_t = (n * (n-1) // 2) + (n * l)
if l >= 0:
    fix = -l
elif l + n - 1 < 0:
    fix = -(l + n -1)
else:
    fix = 0
print(pre_t + fix)

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

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

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

sum_n = []
for i in range(1,n+1):
    sum_n.append(l + i - 1)
num = 1000000000
for i in range(len(sum_n)):
    t = abs(sum_n[i])
    if num > t:
        num = t
        ans = i
print(sum(sum_n) - sum_n[ans])

Solution (Python):
N,L = map(int,input().split(" "))
ans = 0
absmin = 300
for i in range(N):
    taste = i+L
    ans+=taste
    if(abs(taste)<abs(absmin)):
        absmin = taste
print(ans-absmin)

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

A = []

for i in range(1,N+1):
    A.append(L+i-1)

if A[0] > 0:
    A[0] = 0

elif A[N-1] < 0:
    A[N-1] = 0

else:
    pass

print(sum(A))

Solution (Python):
a=[]
a=input().split(" ")
N=int(a[0])
L=int(a[1])


if L>=0 :
    X=N*L+N*(N-1)*0.5-L
    print(int(X))
else:
    if abs(L)>=N:
        X=N*L+N*(N-1)*0.5-(L+N-1)
        print(int(X))
    else:
        X=N*L+N*(N-1)*0.5
        print(int(X))

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

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

if L<=0 and L+N-1 >= 0:
    ans = sum(N_list)
if L > 0:
    ans = sum(N_list)-L
if L+N-1 < 0:
    ans = sum(N_list)-(L+N-1)

print(ans)

Solution (Python):
def main():
	N, L = map(int, input().split())
	f_apple = [L + (i + 1) - 1 for i in range(N)]
	f_all = sum(f_apple)

	ans, tmp = 10 ** 8, 0
	for i in range(N):
		tmp = f_all - f_apple[i]
		if abs(tmp - f_all) < abs(ans - f_all):
			ans = tmp

	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
N,L=map(int, input().split())
sum=0

if L>=1:
  for i in range(1,N):
    sum=sum+(L+i)
else:
  if N>-1*L:
    for i in range(0,N):
      sum=sum+(L+i)
  else:
    for i in range(0,N-1):
      sum=sum+(L+i)

print(sum)

Solution (Python):
import numpy as np

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


nums = np.arange(L, L + N)



if 0 in nums:
    pass
elif L < 0:
    nums = nums[:-1]
elif L > 0:
    nums = nums[1:]


print(np.sum(nums))

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

wa = 0
ans = []
for i in range(N):
    wa += L + i

b = 0
for i in range(N):
    b = wa - (L + i)
    ans.append([abs(wa - b), b])

ans.sort()
print(min(ans)[1])

Solution (Python):
N,L=map(int,input().split())
val=L*N+0.5*N*(N+1)-N
if L>0:
    val-=L
elif L+N-1<0:
    val-=(L+N-1)
print(int(val))

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

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

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

if 0 in b:
  print(sum(b))
  exit()

c = [abs(0-x) for x in b]

d = c.index(min(c))
print(sum(b)-b[d])

Solution (Python):
n,l=map(int,input().split())
if(-n+1<=l<=0):
  print('{0}'.format(n*(2*l+n-1)//2))
elif(l>0):
  print('{0}'.format(n*(2*l+n-1)//2-l))
else:
  print('{0}'.format(n*(2*l+n-1)//2-l-n+1))

Solution (Python):
n,l = map(int, input().split(' '))
apples = []
for i in range(1, n+1):
  apples.append(l + i - 1)
pie = sum(apples)
for i in range(n):
  partial = pie - apples[i]
  if i == 0:
    diff = abs(pie - partial)
    ans = pie - partial
  else:
    d = abs(pie - partial)
    if d < diff:
      diff = d
      ans = pie - partial
print(pie - ans)

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

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

taste = [L+i-1 for i in range(1,N+1)]
amount_taste = sum(taste)

if L < 0 and L+N-1 < 0:
    ans = amount_taste - max(taste)
elif L <= 0 and 0 <= L+N-1:
    ans = amount_taste
elif 0 < L and 0 < L+N-1:
    ans = amount_taste - min(taste)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n, l = map(int, input().split())
sum = 0
a = float('inf')
for i in range(1,n+1):
    sum += l + i - 1
    if a > abs(l + i - 1):
        a = abs(l + i - 1)






if sum >= 0:
    print(sum - a)
else:
    print(sum + a)

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

Solution (Python):
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
from operator import itemgetter, mul
from copy import deepcopy,copy
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

def main():
    n, l = MAP()

    m = INF
    ind=0
    s = l*n + sum(list(range(1, n + 1))) - n

    
    for i in range(1, n + 1):
        if m>abs((l+i-1)*2):
            m = min(m, abs((l+i-1)*2))
            ind=i

    print(s - l - ind + 1)

    
if __name__ == '__main__':
    main()

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

Solution (Python):
N, L = map(int, input().split())
 
ans = float('inf')
diff_ = float('inf')
max_taste = (L-1) * N + (N*(N+1)) // 2

for i in range(1, N+1):
    tgt = L+i-1
    taste = max_taste - tgt
    diff = abs(max_taste - taste)
    if diff < diff_:
        diff_ = diff
        ans = taste

print(ans)

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

Solution (Python):
from sys import stdin
import copy
N, L = [int(_) for _ in stdin.readline().rstrip().split()]
tastes = [(L+i-1) for i in range(1, N+1)]
origin = sum(tastes)
ans = 10**9
ans_sum = 0
for i in range(N):
    c_tastes = copy.deepcopy(tastes)
    c_tastes.pop(i)
    tmp = abs(origin-sum(c_tastes))
    if ans > tmp:
        ans = tmp
        ans_sum = sum(c_tastes)
print(ans_sum)

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

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

if l < 0 and n+l <= 0:
    kei = sum(list(x for x in range(l,l+n-1)))
    
if l < 0 and n+l > 0:
    kei = sum(list(x for x in range(l,l+n)))
    
if l >= 0:
    kei = sum(list(x for x in range(l+1,l+n)))
    
print(kei)

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

mi = 300
choice = 0

for i in range(1, n+1):
  tmp = abs(l + i - 1)
  if tmp < mi:
    mi = tmp
    choice = i
    
ans = 0

for i in range(1, n+1):
  if i == choice:
    continue
  ans += l + i - 1
  
print(ans)

Solution (Python):
n,l=map(int,input().split())
ans=0
for i in range(n):
    ans=ans+l+i
if l>=0:
    ans=ans-l
if l<0 and n+l-1<0:
    ans=ans-(l+n)+1
print(ans)

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



sum = 0
tmp_list = []
tmp_abs  = []
for i in range(1,n+1):
  tmp = l + i -1
  sum += tmp
  
  tmp_list.append(tmp)
  tmp_abs.append(abs(tmp))

index = tmp_abs.index(min(tmp_abs))
print(sum-tmp_list[index])

Solution (Python):
N, L = map(int, input().split())
taste = [L+x-1 for x in range(1, N+1)]
tmp = [abs(x) for x in taste]
v = tmp.index(min(tmp))
taste.pop(v)
print(sum(taste))

Solution (Python):
def main():
    n,l = map(int,input().split(' '))
    h = l
    t = l+n-1
    if t<0:
        m = t
    elif h > 0:
        m = h
    else:
        m = 0
    print(int((2*l+n-1)*n/2-m))

main()

Solution (Python):
n,l = map(int,input().split())
taste_list = list(map(lambda x:l+x-1, list(range(1,n+1))))
pre_sum = sum(taste_list)

min_sum = 10000000
n_taste_list = list(map(abs, taste_list))

for i in taste_list:
    if abs(min_sum) > abs(i):
        min_sum = i

print(sum(taste_list)-min_sum)

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

Solution (Python):
n, l = map(int, input().split())
ls = [int(l+i) for i in range(n)]
absl = [abs(l) for l in ls]
z = min(absl)
s = sum(ls)
if l < 0:
    print(s+z)
else :
    print(s-z)

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

ans = 10 ** 9
ans2 = 0
tmp = sum(taste)


for i in range(n):

    tmp2 = sum(taste) - taste[i]

    if abs(tmp - tmp2) < ans:

        ans = abs(tmp - tmp2)
        ans2 = tmp2



print(ans2)

Solution (Python):
n, l = map(int, input().split())
ans = 0
if l >= 0:
    for i in range(1,n):
        ans += l + i
    print(ans)
else:
    if abs(l) >= n:
        for i in range(n-1):
            ans += l + i
        print(ans)
    else:
        for i in range(n):
            ans += l + i
        print(ans)

Solution (Python):
str = input()
N = int(str.split()[0])
L = int(str.split()[1])

l = []
for i in range(N) :
	l.append(L + i)

sum = 0
for i in range(N) :
	sum += l[i]
list = []
for i in range(N) :
	s = 0
	for j in range(N) :
		if (i != j) :
			s += l[j]
	list.append(s)
k = 0
min = 0
for i in range(N) :
	if (i == 0) :
		min = abs(sum - list[0])
		k = list[0]
	else :
		if (min > abs(sum - list[i])):
			min = abs(sum - list[i])
			k = list[i]
print(k)

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

sum=0

if(L>=0):
    for i in range(2,N+1):
        sum += L+i-1

else:
    if(abs(L)>=N):
        for i in range(1,N):
            sum += L+i-1

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


print(sum)

Solution (Python):
N, L = map(int,input().split())
A = []
B = []
for i in range(N) :
    A.append(L+i)
    B.append(abs(L+i))
del A[B.index(min(B))]
print(sum(A))

Solution (Python):
nl = input().split(" ")
ls = []
al = []
for i in range(int(nl[0])):
    ls.append(int(nl[1])+i)
    al.append(abs(int(nl[1])+i))
if max(ls) < 0:
    print(sum(ls) + min(al))
    exit()
print(sum(ls) - min(al))

Solution (Python):
N, L = map(int, input().split())
tmp = L
total = 0
aLst = [0] * N
for i in range(N):
    aLst[i] = tmp + i
    total += aLst[i]

ansL = [0] * N
ansM = [0] * N
for i in range(N):
    tmp = 0
    for j in range(N):
        if i == j:
            continue
        tmp += aLst[j]
    ansL[i] = tmp
    ansM[i] = abs(total - tmp)

ans = ansL[0]
tmp = ansM[0]
for i in range(1, N):
    if tmp > ansM[i]:
        tmp = ansM[i]
        ans = ansL[i]


print(ans)

Solution (Python):
n,l=map(int,input().split())
ans=888
SUM=0
s=0
for i in range(l,l+n):
        SUM+=i
        s=i
        if i<0:
                s=1
                i*=-1
        else:
                s=-1
        if ans>i:
                ans=i
       
y=range(l,l+n)
ANS=SUM+s*ans
print(ANS)

Solution (Python):
n,l = map(int,input().split())
apple_taste = []
abs_taste = []

for i in range(n):
    point = abs(l+i)
    abs_taste.append(point)
    apple_taste.append(l+i)
 
min_point = min(abs_taste)
index = abs_taste.index(min_point)


 
sums = (n**2)/2 + (l-1/2)*n
print(int(sums - apple_taste[index]))

Solution (Python):
N,M=map(int,input().split())

R=[]
for i in range(N):
    R.append(M+i)


n=10**9
for i in range(N):
    if abs(R[i])<abs(n):
        n=R[i]

if n>0:
    print(sum(R)-n)
else:
    print(sum(R)-n)

Solution (Python):
import numpy as np
N, L = map(int, input().split())
if L > 0:
    s = np.sum(np.arange(L+1, L+N))
elif L < -N+1:
    s = np.sum(np.arange(L, L+N-1))
else:
    s = np.sum(np.arange(L, L+N))
print(s)

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

apples = []
apples_abs = []

for i in range(1, N+1):
    apple = L+i - 1
    apples.append(apple)
    apples_abs.append(abs(apple))

min_apple_idx = apples_abs.index(min(apples_abs))
apples.pop(min_apple_idx)
print(sum(apples))

Solution (Python):
n,l = map(int,input().split())
s = sum([i for i in range(l,l+n)])
x = [i for i in range(l,l+n) ]

find = 10**9
data = 0
for i in x:
    if abs(i)<find:
        find = abs(i)
        data = i

print(s-data)

Solution (Python):

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

if L >= 0:
    sub = L
elif L < 0 and abs(L) < N:
    sub = 0
elif L < 0 and abs(L) >= N:
    sub = L+N-1

result = int(N*(L-1) + (N*(N+1))/2 - sub)

print(result)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, l = readmi()
s = 0
t = []
for i in range(1, n + 1):
    s += i + l - 1
    t.append(i + l - 1)
mn = 0x1FFFFFFF
index = 0
for i in range(len(t)):
    if mn > abs(s - s - t[i]):
        mn = abs(s - s - t[i])
        index = i
print(s - t[index])

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

apples = []
apples_abs = []
for i in range(n):
    apples += [l + i]
    apples_abs += [abs(l + i)]

if min(apples_abs) in apples:
    print(sum(apples) - min(apples_abs))
else:
    print(sum(apples) + min(apples_abs))

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

ans=0
x=[]
y=[]

for i in range(1,n+1):
    ans=ans+l+i-1
    x.append(l+i-1)
    y.append(abs(l+i-1))

if min(x)<0:
    ans=ans+min(y)
    print(ans)
else:
    ans=ans-min(y)
    print(ans)

Solution (Python):


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

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

allapples = sum(apples)

applepies = [sum(apples[:i]) + sum(apples[i+1:]) for i in range(N)]

diffs = [abs(allapples-applepie) for applepie in applepies]

print(applepies[diffs.index(min(diffs))])

Solution (Python):
import sys
inputs = sys.stdin.readlines()

n, l = [int(x) for x in inputs[0].split(' ')]
values = list(range(l, l+n))
tmp = [abs(x) for x in values]
values.pop(tmp.index(min(tmp)))
print(sum(values))

Solution (Python):
import numpy as np

N,L = list(map(lambda x: int(x),input().split()))
a = [L+i for i in range(N)]
c = 1000
b = 1000
for i in a:
    if abs(i)<c:
        c = abs(i)
        b = i
print(int(np.sum(a))-b)

Solution (Python):
l = input().split()
N = int(l[0])
L = int(l[1])

T = [L + x for x in range(N)]

candidate = sum(T)

ans = 100000000
index = 0
for i in range(N):
   t = candidate - (L + i)
   d = abs(candidate - t)
   if d <= ans:
        index = i
        ans = d


print(candidate - (L + index))

Solution (Python):
N,L=map(int,input().split())
ans=0
f=0
min=10000
for i in range(1,N+1):
    tmp=L+i-1
    ans+=tmp
    if abs(tmp) < min:
        min = abs(tmp)
        if tmp < 0:
            f=1
if f == 0:
    ans-=min
else:
    ans+=min
print(ans)

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

ls = list(range(l, l + n))

m = 100
for l in ls:
    if l < 0:
        m = l
    else:
        if abs(m) > l:
            m = l
            break

ans = sum(ls) - m

print(ans)

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

FirstVal = L
LastVal = L + N -1
ans = 0

for i in range(N) :
  ans += L + i

if FirstVal >= 1 :
  ans -= FirstVal
elif LastVal <= -1 :
  ans -=LastVal
else :
  next

print(ans)

Solution (Python):
import collections as c
ip = lambda : map(int, input().split())

mod = 1e9+7
n,l = ip()
ans = 0
k=abs(l)
for i in range(l,l+n):
    ans+=i
    if abs(i) < abs(k):
        k = i
ans -= k
print(ans)

Solution (Python):






import sys
import math
import array


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

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

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

















def main():
    N, L = [int(x) for x in input().split()]
    
    azi = [(L+i) for i in range(N)]
    risou = sum(azi)

    sabun = 1145141919
    ans = 0

    for i in range(N):
        pi = sum(azi) - azi[i]
        
        a = (risou - pi)**2 

        if a < sabun:
            sabun = a
            ans = pi

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


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

if l > 0:
    print(int((2 + n) * (n - 1) / 2 + (l - 1) * (n - 1)))
elif (l * -1) < n:
    print(int((1 + n) * (n - 0) / 2 + (l - 1) * (n - 0)))
else:
    print(int((1 + n - 1) * (n - 1) / 2 + (l - 1) * (n - 1)))

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

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

print(round(ans))