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())
s=[]


for i in range(n):
    s.append(i+l)
a = sum(s)
m=0
c = abs(s[0])
for i in range(n):
    if c > abs(s[i]):
        c = abs(s[i])
        m = i
        

print(a-s[m])

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    apple = [i+L for i in range(N)]
    if L >= 0:
        apple = apple[1:]
        print(sum(apple))
    elif 0 in apple:
        print(sum(apple))
    else:
        apple = apple[:N-1]
        print(sum(apple))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
azi = [L+i-1 for i in range(1,N+1)]
b = sum(azi)
zero_count = 0
for i in range(N):
    if azi[i] == 0:
        print(b)
        zero_count = 1
        break

if zero_count == 0:
    if b<0:
        print(b-azi[N-1])
    else:
        print(b-azi[0])

Submission status: Accepted

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

original_apple_pie = 0
li = []
mi = 10e9
for i in range(N):
    tmp = L + i 
    li.append(tmp)
    original_apple_pie += tmp
    if mi > abs(tmp):
        mi = abs(tmp)
        ans = tmp

if original_apple_pie<0 and ans < 0:
    print(original_apple_pie-ans)
else:
    print(original_apple_pie-ans)

Submission status: Accepted

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

tastes = [l + i - 1 for i in range(1, n + 1)]
sum_tastes = sum(tastes)
sum_tastes_eat = [sum_tastes - tastes[i] for i in range(n)]
dif_tastes = [abs(sum_tastes - x) for x in sum_tastes_eat]
#print(dif_tastes)
idx = dif_tastes.index(min(dif_tastes))
print(sum_tastes_eat[idx])

Submission status: Accepted

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

# cal process
aji_min = L + 1 -1
aji_max = L + N -1
if aji_max <= 0:
    print(sum(range(aji_min, aji_max - 1 + 1)))
    exit()
if aji_min >= 0:
    print(sum(range(aji_min + 1, aji_max + 1)))
    exit()
print(sum(range(aji_min, aji_max + 1)))

Submission status: Accepted

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

apple=[int(x+1) for x in range(int(a))]
taste=[int(int(b)+x+1-1) for x in range(int(a))]

if 0 in taste:
    taste.pop(taste.index(0))
    print(sum(taste))
elif taste[0]<0:
    taste.pop(-1)
    print(sum(taste))
else:
    taste.pop(0)
    print(sum(taste))

Submission status: Accepted

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

apple=[]

for num in range(1,N+1):
  apple.append(L + num -1)

taberu = min(map(abs,apple))

if taberu > max(apple):
  print(sum(apple)+taberu)
else:
  print(sum(apple)-taberu)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [L+i-1 for i in range(1,N+1)]
taste_list = [abs(L+i-1) for i in range(1,N+1)]
pos = taste_list.index(min(taste_list))
print(sum(taste)-taste[pos])

Submission status: Accepted

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

first = L
end = N + L -1
 

if first>=0:
    print((first+1 + end)*(N-1)//2)
elif (first<=0 and end>=0):
    print((first+end)*N//2)
else:
    print((first + end -1)*(N-1)//2)

Submission status: Accepted

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

apple1 = float('inf')
apple2 = -float('inf')
flag = 0
for i in taste:
    if i == 0:
        apple = i
        flag = 0
        break
    elif (apple2 < i < 0):
        apple2 = i
        flag = 1
    elif (0 < i < apple1):
        apple1 = i
        flag = 2
        
if flag == 1:
    pie = (sum(taste) - apple2)
elif flag == 2:
    pie = (sum(taste) - apple1)
else:
    pie = (sum(taste) - apple)
    
print(pie)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
tabenai = [(L+_-1) for _ in range(1,N+1)]
abs_tabenai = [abs(L+_-1) for _ in range(1,N+1)]
min_index = abs_tabenai.index(min(abs_tabenai))
ans = sum(tabenai)-tabenai[min_index]
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
result = 0
Min = L
Max = L + N - 1
flg = 0
for i in range(1,N+1):
  x = L + i - 1
  if x == 0:
    flg = 1
  result = result + x

if flg == 1:
  print(result)
else:
  if Min < 0:
    print(result-Max)
  else:
    print(result-Min)

Submission status: Accepted

Solution code:
N, L = (int(x) for x in input().split())
def func(i):
    return (N*(2*L+N-1)//2) - (L+i-1)

if -L+1 <= 1:
    print(func(1))
elif 1 <= -L+1 and -L+1 <= N:
    print(func(-L+1))
else:
    print(func(N))

Submission status: Accepted

Solution code:
import numpy as np

a,b = map(int, input().split())
s_max = b + a -1
s_min = b 
ans = 0 

if s_min >= 0 and s_max >= 0:
    for i in range(s_min + 1,s_max+1):
        ans += i
           
    print (ans)
elif s_min < 0 and s_max > 0:
    for i in range(s_min,s_max+1):
        ans += i
           
    print (ans)
else:
    for i in range(s_min,s_max):
        ans += i
           
    print (ans)

Submission status: Accepted

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

al = [i + l - 1 for i in range(1, n+1)]
res=100000
ans=0
total = sum(al)

for i in range(0, len(al)):
    if abs(total - (total - al[i])) < res:
        res = abs(total - (total - al[i]))
        ans = total - al[i]
        
        
print(ans)

Submission status: Accepted

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

sum = n * (l - 1) + (n * (n + 1)) / 2.0

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

Submission status: Accepted

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

aaa = list(range(L, N + L))
n = sum(aaa)
if n == 0:
    print(0)
elif n < 0:
    print(n - max(aaa))
else:
    print(n - max(0,min(aaa)))

Submission status: Accepted

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

apple_azi = [L + (x + 1) - 1 for x in range(N)]

original_pai = sum(apple_azi)

test = []
for i in apple_azi:
    # print(original_pai - i)
    test.append(abs(original_pai - (original_pai - i)))

tabeta_azi = min(test)

if original_pai >= 0:
    print(original_pai - tabeta_azi)
else:
    print(original_pai + tabeta_azi)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    t = L + i
    if t**2 < min**2:
        min = t
    max += t

print(max-min)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
applepie = N * L + sum(range(N))
apple = L if L >= 0 else (0 if (L + N - 1) >= 0 else (L + N - 1))
print(applepie - apple)

Submission status: Accepted

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

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

ringo=[]

for i in range(n):
	ringo.append(l+i)
min = abs(ringo[0])
min_num = 0
for i in range(len(ringo)):
	if min > abs(ringo[i]):
		min = abs(ringo[i])
		min_num = i
out = 0
for i in range(len(ringo)):
	if i != min_num:
		out = out + ringo[i]
print(out)

Submission status: Accepted

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

Submission status: Accepted

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

al = int((L-1)*N + 0.5*N*(N+1))
if L >= 0:
    tmp = L
elif L < 0 and abs(N) > abs(L):
    tmp = 0
else:
    tmp = L + N - 1

print(al -tmp)

Submission status: Accepted

Solution code:
num, l = map(int, input().split())
sum = 0
for i in range(1, num + 1):
    sum += i

all_pie = num * l + sum - num
if l >= 0:
    print(all_pie - l)
elif abs(l) <= num -1:
    print(all_pie)
else:
  print(all_pie - (l + num - 1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste_all = 0
for i in range(N):
    taste_all += L + i
if abs(L) < N and L < 0:
    print(taste_all)
elif L == 0:
    print(taste_all)
elif L < 0:
    print(taste_all - (L + N - 1))
elif L > 0:
    print(taste_all - L)

Submission status: Accepted

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

p = []
pi = []
pi_s = []


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

all_t = sum(p)

for i in range(N):
    pi.append(all_t - p[i])
    pi_s.append(abs(all_t - pi[i]))

# print(p, pi,pi_s)
min_abs = pi_s[0]
ans = 0

for i in range(1,N):
    if min_abs > pi_s[i]:
        min_abs = pi_s[i]
        ans = i

# print(ans,pi[ans],pi_s[ans])

print(pi[ans])

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
zenbu=[]
for i in range(N):
  aj=L+i
  zenbu.append(aj)
aji=sum(zenbu)
zenbu_abs=np.abs(zenbu)
a=zenbu_abs.argmin()


eat=zenbu[a]
kotae=aji-eat
print(kotae)

Submission status: Accepted

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

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

diff_tastes      = {}
for i in range(0, len(tastes)):
    diff_total_taste = 0
    for j in range(0, len(tastes)):
        if(i != j):
            diff_total_taste += tastes[j]
    diff = abs(total_taste - diff_total_taste)
    diff_tastes[diff_total_taste] = diff

print(min(diff_tastes, key=diff_tastes.get))

Submission status: Accepted

Solution code:
N,L = [int(i) for i in input().split()] 
bi=None
if 2<=1-L and 1-L<=N:
    bi =1-L
elif 1-L>=N:
    bi = N
elif 2>=1-L:
    bi =1
ajis = [L+i for i in range (N)]
org_sum = sum(ajis)
ans = org_sum -(L+bi-1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
apples =str(input())
apples_list = apples.split(" ")
N = int(apples_list[0])
L = int(apples_list[-1])
pai_values = []
 
for i in range(1,N+1):
    pai_value = i + L -1
    pai_values.append(pai_value)
    
min_pai = abs(pai_values[0])
target_number = 0
 
for j in range(N):
    if min_pai > abs(pai_values[j]):
        min_pai = abs(pai_values[j])
        target_number = j
        
pai_values.pop(target_number)
 
answer = sum(pai_values)
 
print(int(answer))

Submission status: Accepted

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

def eat():
    if L > 0:
        return L
    elif L > (-N):
        return 0
    else:
        return L + N - 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
sum = 0
for i in range(1, N+1):
	sum += L + i - 1
min = 5000000000000000
mintaste = 0
for i in range(1, N+1):
	taste = sum - (L+i-1)
	if abs(sum-taste) < min:
		min = abs(sum-taste)
		mintaste = taste
print(mintaste)

Submission status: Accepted

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

flavor = int(n*(l+(l+n-1))/2)

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

else:
  print(flavor-l)

Submission status: Accepted

Solution code:
'''n,l=map(int,input().split( ))
f=[0]*(n+1)
for i in range(1,n+1):
	f[i]=l+i-1
p=[0]*(n+1)
s=[0]*(n+1)
sum=0
for i in range(1,n+1):
	p[i]=sum+f[i]
	sum=p[i]
sum=0
for i in range(n,0,-1):
	s[i]=sum+f[i]
	sum=s[i]
ans=10**9+7
total=s[1]
for i in range(1,n+1):
	if i==n:
		temp=total-f[i]
		if temp<ans:
			ans=temp
	else:
		temp=total-(p[i-1]+s[i+1])
		if temp<ans:
			ans=temp
print(ans)
print(total-ans)

'''
n,l=map(int,input().split( ))
f=[0]*(n+1)
for i in range(1,n+1):
	f[i]=l+i-1
total=sum(f)
x=10**9+7
for i in range(1,n+1):
	r=total-f[i]
	c=abs(total-r)
	if c<x:
		ans=r
		x=c
print(ans)

Submission status: Accepted

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

for i in range(N):
    aji = L + i+1 - 1
    aji_list.append(aji)
    aji_list_abs.append(abs(aji))

aji_list = sorted(aji_list)
min_abs_aji = min(aji_list_abs)

#絶対値化して一番小さい値がaji_listに存在しないなら符号反転
if not min_abs_aji in aji_list:
    min_abs_aji = min_abs_aji * -1

aji_list.remove(min_abs_aji)

print(sum(aji_list))

Submission status: Accepted

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

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

Submission status: Accepted

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

min_apple = L

total_taste = 0

for i in range(N):
    taste = L + i
    if abs(0 - min_apple) > abs(0 - taste):
        min_apple = taste

    total_taste += taste

print(total_taste - min_apple)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 190622_sat_B

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

a = []
b = []

for i in range(1, N+1):
    a.append(L+i-1)
    b.append(abs(L+i-1))

# print("a: ", a)
# print("b: ", min(b))

# print("answer:", sum(a) - a[b.index(min(b))])
print(sum(a) - a[b.index(min(b))])

Submission status: Accepted

Solution code:
class BiteEat:
    def __init__(self):
        self.N, self.L = map(int, input().split())

    def __taste(self, i):
        return self.L + i - 1

    def cal(self):
        first = self.__taste(1)
        last = self.__taste(self.N)
        total = (first + last) * self.N // 2

        if first >= 0:
            print(total - first)
        elif last <= 0:
            print(total - last)
        else:
            print(total)


biteEat = BiteEat()
biteEat.cal()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
aji = []
for i in range(1, n+1):
    aji.append(l + i - 1)
aji_sum = sum(aji)
sa = 1000000007
for i in range(n):
    if abs(sum(aji[:i]) + sum(aji[i+1:]) - aji_sum) <= sa:
        sa = abs(sum(aji[:i]) + sum(aji[i+1:]) - aji_sum)
        ans = sum(aji[:i]) + sum(aji[i+1:])
print(ans)

Submission status: Accepted

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

azi = [v for v in range(l,l+n,1)]
moto = sum(azi)

m = float("inf")

for i in azi:
  if abs(m) > abs(i):
    m = i

print(moto - m)

Submission status: Accepted

Solution code:
num_apple, num = map(int, input().split())

taste_list = []
for i in range(num_apple):
  taste_list.append(num + i)

def func_abs(n):
    return abs(n)
  
min_abs = min(taste_list, key=func_abs)
taste_list.remove(min_abs)
print(sum(taste_list))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
x, y = map(int, input().split())
A = []

for i in range(x):
    A.append(y)
    y += 1

B = np.abs(A)

we = min(B)
if we not in A:
    we = - + we
    A.remove(we)
else:
    A.remove(we)

cnt = 0
for i in A:
    cnt += i

print(cnt)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
lisu = [L+i-1 for i in range(1,N+1)]
abs_l = [abs(i) for i in lisu]
mii = min(abs_l)
auu = sum(lisu)
ans = auu - lisu[abs_l.index(mii)]
print(ans)

Submission status: Accepted

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

pies = [l+i-1 for i in range(1,n+1)]
pie_plan = sum(pies)
pie_real = 0
diff_plan_real = float("inf")
for i in range(1,n+1):
    pie_provisonal = sum([l+j-1 for j in range(1,n+1) if j != i])
    if abs(pie_plan - pie_provisonal) < diff_plan_real:
        diff_plan_real = abs(pie_plan - pie_provisonal)
        pie_real = pie_provisonal
    
print(pie_real)

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N, L = map(int, input().split())

    mn = 2 * 10 ** 9
    ans = -1
    x = 0
    for i in range(N):
        x += L + i

    for i in range(N):
        cur = 0
        for j in range(N):
            if i == j:
                continue
            cur += L + j
        if abs(x-cur) < mn:
            mn = abs(x-cur)
            ans = cur

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = input().split()
# print(a)
b = int(a[0])
c = int(a[1])
d = []
for i in range(b):
    d.append(c + i)
# print(d)
if d.count(0) == 1:
    d.remove(0)
elif c < 0:
    del d[-1]
elif c > 0:
    del d[0]
# print(d)
e = sum(d)
print(e)

Submission status: Accepted

Solution code:
N,L=(int(i) for i in input().split())
x=0
y=[]
z=[]
zy=[]
for i in range(1,N+1):

    x+=i+L-1
    y.append(i+L-1)
    z.append(i+L-1)


for i in y:

    z.remove(i)

    zy.append(sum(z))


    z.append(i)

sa=x-zy[0]



for i in zy:
    if((x-i)<abs(sa)):
        sa=x-i
num=zy.index(x-sa)
print(zy[num])

Submission status: Accepted

Solution code:
from sys import stdin

n,l = [int(x) for x in stdin.readline().rstrip().split()]
aji_arr = []
total = 0

for i in range(1,n+1):
    aji = l+i-1
    total += aji
    
    if(i == 1):
        aji_min = abs(aji)
        del_aji = aji
    elif(aji_min >= abs(aji)):
        aji_min = abs(aji)
        del_aji = aji
total = total - del_aji
print(total)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
sum = 0
min = 100
minabs = 100
for i in range(a):
    c = b + i
    sum += c
    if minabs > abs(c):
        minabs = abs(c)
        min = c
print(sum - min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=[0]*(n)
c=[0]*(n+1)
for i in range(n):
    a[i]=l+i

aas=sum(a)

ans=(10**10)
for i in range(n):
    aji=aas-a[i]
    if ans>abs(aas-aji):
        ans=abs(aas-aji)
        ans2=aji
print(ans2)

Submission status: Accepted

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

eatApple = -101

i = 1
sumApple = 0
while i <= N:
    now = L + i - 1
    if abs(now) < abs(eatApple):
        eatApple = now
    sumApple += now
    i += 1

print(sumApple - eatApple)

Submission status: Accepted

Solution code:
import copy
n,l = map(int,input().split())
taste = []
for i in range(0,n):
    taste.append(l + i + 1 -1)

all_t = sum(taste)

save = copy.copy(taste)
azi = []

for i in range(0,n):
    del taste[i]
    azi.append(abs(all_t - sum(taste)))
    taste  = copy.copy(save)

a = azi.index(min(azi))
del taste[a]
print(sum(taste))

Submission status: Accepted

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

apples = [0] * N

ate_apple = 100
apple_pie = 0

for i in range(N):
  apples[i] = L + i
  apple_pie += apples[i]
  if abs(ate_apple) > abs(apples[i]):
    ate_apple = apples[i]

print(apple_pie - ate_apple)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
taste = []
ans = 0
d = 100000
for i in range(1,N+1):
  ans += L+i-1
  d = min(abs(L+i-1), d)
print(ans - d if ans > 0 else ans + d)

Submission status: Accepted

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


pie = 0
ans = 10**9

for i in range(1,N+1):
  pie += L + i - 1
  
if L >= 1:
  ans = pie - L
elif abs(L-1) <= N:
  ans = pie
else:
  ans = pie - (L+N-1)
print(ans)

Submission status: Accepted

Solution code:
str = input().split(" ")
n = int(str[0])
l = int(str[1])
aji = []
for i in range(1, n+1):
    aji.append(l+ i-1)
    #print("aji: ", aji)
sa = sum(aji)
mina = 1000
min_index = None
for i in range(0, n):
    tmp = aji.copy()
    tmp.pop(i)
    dif = abs(sa - sum(tmp))
    if mina > dif:
        mina = dif
        min_index = i
        #print('mina: ',mina, "index: ", i)

#aji = sorted(aji)
aji.pop(min_index)
#print(aji)
print(sum(aji))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
total = 0
for i in range(N):
    total += (L + i)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N,L = map(int,input().split())
    taste = []
    ABS = []
    for i in range(N):
        taste.append(L+i+1-1)
        #print(taste)
    for j in taste:
        ABS.append(abs(j))
        #print(ABS)
    taste.pop(ABS.index(min(ABS)))
    print(sum(taste))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())

n,l = Is()
lis = []
for i in range(l,n+l):
    lis.append(i)
if 0 in range(l,n+l):
    print(sum(lis))
elif n+l-1 < 0:
    print(sum(lis) - (n+l-1))
else:
    print(sum(lis) - l)

Submission status: Accepted

Solution code:
import copy

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

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

pie_taste = sum(apple_taste)

min_diff = 100000
for i in range(N):
    ap = copy.deepcopy(apple_taste)
    ap[i] = 0

    pie_taste2 = sum(ap)
    diff = abs(pie_taste - pie_taste2)

    if diff < min_diff:
        min_diff = diff
        min_index = i


apple_taste[min_index] = 0

print(sum(apple_taste))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
sum1=0
sum2=0
ans=0
min=100000000000000000000000000000
result=0

taste_list=[1]*N
for i in range(N):
    taste_list[i]=(L+i)
    

for i in range(N):
    sum1=sum(taste_list)
    sum2=sum(taste_list[:i])+sum(taste_list[i+1:])
    ans=abs(sum1-sum2)
    if min>ans:
        min=ans
        result=sum2
        

print(result)

Submission status: Accepted

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

rng = list(range(l, l+n))
min_abs = 400
val = 0
for r in rng:
  if min_abs > abs(r):
    min_abs = abs(r)
    val = r

print(sum(rng) - val)

Submission status: Accepted

Solution code:
import numpy as np
a = input()
n, l = [int(i) for i in a.split(" ")]
apples = np.array([i for i in range(n)])
aji = apples + l
abss = [np.abs(aji[apples != i].sum() - aji.sum()) for i in range(n)]
i = abss.index(np.min(abss))
print(aji[apples != i].sum())

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

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

elif abs(L) < N:
    for i in range(N):
        sum += int(i) + L

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in arr:
    arr.remove(0)
else:
    if L + N <= 0:
        arr.sort(reverse=True) 
    arr.pop(0)

print(sum(arr))

Submission status: Accepted

Solution code:
import numpy as np

n,l = [int(x) for x in input().split()] 
x = np.arange(l,l+n)
y = np.abs(x)
x = np.delete(x, np.argmin(y))
print(np.sum(x))

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
num=b
s=0
minA = 500
store= []
ans = []
final = []
c=-1
for i in range(a):
    store.append(num);
    s+=num
    num+=1
for v in store:
    cur = s-v
    final.append([abs(s-cur),cur])
final.sort()
print(final[0][1])

Submission status: Accepted

Solution code:
import numpy as np

n, l = map(int, input().split())
a = list(l + i - 1 for i in range(1, n + 1))
idx = np.abs(np.asarray(a) - 0).argmin()

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split(" "))
taste = [L + i - 1 for i in range(1, N + 1)]
abs_taste = [abs(t) for t in taste]
eaten = abs_taste.index(min(abs_taste))
taste[eaten] = 0
print(sum(taste))

Submission status: Accepted

Solution code:
import numpy as np
N,L = map(int, input().split())
taste=np.arange(N)+1 +L-1

if 0 in taste:
    print(taste.sum())
else:
    if taste[-1]>0:
        print(taste[1:].sum())
    else:
        print(taste[:-1].sum())

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min = abs(L) + N
ans = 0
for n in range(1, N+1):
    tmp = L+n-1
    ans += tmp
    if abs(min) > abs(tmp):
        min = tmp

print(ans-min)

Submission status: Accepted

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

ls = []
for i in range(1,n+1):
  ls.append(l+i-1)
total = sum(ls)

flag=0
ans = abs(total-(total-ls[0]))
for i in range(n):
  tst = total - ls[i]
  dif = abs(total-tst)
  if dif<ans:
    flag = i
    ans = dif
print(total-ls[flag])

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
s = 0
r = []
for t in range(n):
    s += l
    r.append(abs(l))
    l += 1
m = min(r)
if r[0] > r[-1]:
    print(s + m)
else:
    print(s - m)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[67]:


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


# In[68]:


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


# In[69]:


choice_index = list(map(abs, taste)).index(min(list(map(abs, taste))))
del taste[choice_index]
print(sum(taste))


# In[ ]:

Submission status: Accepted

Solution code:
# 絶対値が一番低くなるものを食べる
N, L = map(int, input().split())

sum_apple=L*N+N*(N+1)//2-N
#print(sum_apple)

worst = L
for n in range(N):
  if abs(worst)>abs(L+n):
    worst=L+n
worst=worst-L+1
#print(worst)
worst_score=L+worst-1
print(sum_apple-worst_score)

Submission status: Accepted

Solution code:
nl = input().split(" ");
n = int(nl[0]);
l = int(nl[1]);
taste = [0]*n;
eat = 100;
j = 0;
for i in range(n) :
	taste[i] = l + i;
	if abs(l + i) < eat :
		eat = abs(l+i);
		j = i;
print(sum(taste)-taste[j]);

Submission status: Accepted

Solution code:

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

ringo = []
abs_list = []

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

minus = True

minabs = 100000

for i in ringo:
    if abs(i) < minabs :
        minabs = abs(i)
        if i > 0 :
            minus = False

ans = sum(ringo)

if minus == True :
    print(ans + minabs)
else:
    print(ans - minabs)

Submission status: Accepted

Solution code:
import numpy as np

if __name__ == '__main__':
    n, l = map(int, input().split())
    apples = np.arange(start=1, stop=n + 1, step=1)
    apples_taste = apples + l - 1
    apples_taste_abs = np.abs(apples_taste)
    index_can_eat_apple = apples_taste_abs.argmin()
    nokori_apples = np.delete(apples_taste, index_can_eat_apple)
    print(np.sum(nokori_apples))

Submission status: Accepted

Solution code:
N , X =map(int,input().split())
sums = []
i = X
result =[]
a = []
for i in range(N):
    sums.append(i+X)
for j in range(N):
    a.append(abs(sums[j]))

if sum(sums) ==abs(sum(sums)):
    print(sum(sums) - min(a))
else :
    print(sum(sums) + min(a))

Submission status: Accepted

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

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

s = sum(apple)

m = 10000000000000
for x in apple:
  if abs(m) > abs(x):
    m = x

print(s-m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
all_taste = 0
taste_list = list()
for i in range(n):
  taste = l+(i+1)-1
  taste_list.append(taste)
  all_taste += taste

www = float("inf")
for i in range(n):
  if abs(taste_list[i]) < www:
    www = abs(taste_list[i])
    ind = i
ans = all_taste - taste_list[ind]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


total = []
for i in range(1,n+1):
  total.append(l+i-1)
total2 = sum(total)

if l >= 0:
  print(total2-l)
elif abs(l) < n:
  print(total2)
elif abs(l) >= n:
  print(total2 - (l+n-1))

Submission status: Accepted

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

Submission status: Accepted

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

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

# if (l >= 0):
#     ax = l
# else:
#     if (-l <= n):
#         ax = 0
#     else:
#         ax = l - 1 + n

# s -= ax

d = 1000
rtn = s

for i in range(1,n+1):
    s_tmp = s - (l + i - 1)
    if (abs(s - s_tmp) < d):
        d = abs(s - s_tmp)
        rtn = s_tmp

print(int(rtn))