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 = (int(i) for i in input().split())
tst = 0
max = l
for i in range(n):
    tst = tst + i + l
    max = i + l
if max < 0:
    print(tst - max)
elif max == 0:
    print(tst)
elif max > 0 and l < 0:
    print(tst)
elif max > 0:
    print(tst - l)

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
list = []
sum = 0
min = 10000
sign = 1
for i in range(1,N+1):
    sum += L+i-1
    list.append(L+i-1)
for num in list:
    if min > abs(num):
        min = abs(num)
        if num > 0:
            sign = 1
        else:
            sign = -1
print(sum-min*sign)

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
b=list(range(a[1],a[0]+a[1]))
c=min(b)
d=max(b)
if c==0 or d==0:
    e=0
elif c/d>0:
    if c>0:
        e=c
    else:
        e=d
else:
    e=0
print(sum(b)-e)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = list(map(int, input().split()))
import numpy as np
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:
#N個のりんごの数　L:味の基準
N, L = map(int, input().split())

#普通のアップルパイの味
nomal_sum = 0
for number in range(1,N+1):
  nomal_sum = nomal_sum + (L + number -1)
#print("普通のアップルパイ",nomal_sum)
  
#一つ欠けたアップルパイのパターンを作る
#lost_sum = 0
#for number in range(1,N+1):
#  if number == 1:
#    print("1だよ")
#  else:
#    lost_sum = lost_sum + (L + number -1)
#print(lost_sum)

#一つ欠けたアップルパイのリストをつくる
list = []
lost_sum = 0
for number in range(1,N+1):
  for number2 in range(1,N+1):
    if number != number2:
      lost_sum = lost_sum + (L + number2 -1)
  list.insert(number, lost_sum)
  lost_sum = 0
#print("list",list)

# 差の絶対値を取る
minimal1 = 100000
ans = 0
for list_aji in list:
  #print("list_aji",list_aji)
  #print("minimal1",minimal1)
  #print("abs(list_aji - nomal_sum)",abs(list_aji - nomal_sum))
  if minimal1 >= abs(list_aji - nomal_sum):
    minimal1 = abs(list_aji - nomal_sum)
    ans = list_aji
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, L] = [int(input_raw[0]), int(input_raw[1])]
    A = [L + i - 1 for i in range(1, N + 1)]

    abs_min_A = sys.maxint
    abs_min_i = 0
    for i in range(N):
        if abs(A[i]) < abs_min_A:
            abs_min_A = abs(A[i])
            abs_min_i = i
    sum1 = 0
    sum2 = 0
    for i in range(N):
        if i != abs_min_i:
            sum2 += A[i]
    print (sum2)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

def taste(x,l):
    return x+l-1
tastes=[]
for i in range(1,n+1):
    tastes.append(taste(i,l))
min = 0
cnt=0
for i in range(0,n):
    if abs(tastes[min]) >= abs(tastes[i]):
        min=i
del tastes[min]
# print(min)
# print(tastes)
print(sum(tastes))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if 0 <= l :
	result = taste_int - l
elif l <= -1 * n :
	result = taste_int - (n + l -1 )
else:
	result = taste_int

print( result)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
import statistics
S = []
for i in range(L,N+L):
    S.append(i)
ans = []
p = []
for j in S:
    ans.append(abs(sum(S) - sum(S) - j))
    p.append(sum(S)-j)

print(p[ans.index(min(ans))])

Submission status: Accepted

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

list=np.arange(L,N+L,1)

num=0
if np.sum(np.min(np.abs(list))==list)==1:
  num=np.min(np.abs(list))
else:
  num=-np.min(np.abs(list))

score=np.sum(list)-num
#print(list)
print(score)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
# N = 30
# L = -50
T_N = (N**2 + (2*L -1)*N)/2
# print(T_N)
array = []
num = 0
for i in range(1,N+1):
    T_i = L + i -1
    T_Ni = T_N - T_i
#     print(T_i)
    T_abs = abs(T_N - T_Ni)
    array.append(T_abs)
    if (min(array) == T_abs):
        num = T_Ni
# print(array)
print(int(num))

Submission status: Accepted

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

aji = [(i+1)+int(L)-1 for i in range(int(N))]
abs = list(map(abs, aji))
index = abs.index(min(abs))

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

Submission status: Accepted

Solution code:
from sys import stdin

n, l = [int(x) for x in stdin.readline().rstrip().split()]
apples = [l+i for i in range(n)]

apple_sum = (apples[0] + apples[n-1]) * n / 2
rm = 0

for i, apple in enumerate(apples):
    if abs(apple) < abs(apples[rm]):
        rm = i

apples.pop(rm)
print(sum(apples))

Submission status: Accepted

Solution code:
#B
N, L = map(int, input().split())
apple = []
for i in range(N):
    apple.append(L + i)
j = 0
for i in range(N):
    if apple[i] == 0:
        a = apple[i]
        del apple[i]
        j += 1
        break
#print(j)
#print(apple)
if j == 0:
    if not 0 in apple:
        if apple[0] < 0:
            del apple[-1]
        elif apple[0] > 0:
            del apple[0]
print(sum(apple))
#print(apple)

Submission status: Accepted

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

total_taste_all = (N**2 + (2*L - 1)*N)/2
min_err = 10000
for i in range(N):
  apple_taste = L + i 
  taste_err = abs(apple_taste)
  if taste_err <= min_err:
    min_err = taste_err
    apple_pie_taste = total_taste_all - apple_taste
    
print(int(apple_pie_taste))

Submission status: Accepted

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

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

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


print(sum - m)

Submission status: Accepted

Solution code:
l,m = map(int,input().split())
lis =[]
lis2=[]
for i in range(l):
  lis.append(m+i)
  lis2.append(abs(m+i))

lis.pop(lis2.index(min(lis2)))
print(sum(lis))

Submission status: Accepted

Solution code:
import numpy as np

N,L=map(int, input().split())
taste=0
Apple_taste=[]

for i in range(N):
    taste=L+i
    Apple_taste.append(taste)

Abs=[abs(t) for t in Apple_taste]

i_m=np.argmin(Abs)
del Apple_taste[i_m]

print(sum(Apple_taste))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
count = 0
if l == 0:
    for i in range(1, n+1):
        count += i + l - 1

    print(count)

if l > 0:
    for i in range(2, n+1):
        count += i + l -1

    print(count)

if (l < 0) and (n > 1 - l):
    for i in range(1, n+1):
        count += i + l - 1

    print(count)
    
if (l < 0) and (n < 1 - l):
    for i in range(1, n):
        count += i + l - 1
        
    print(count)
    
if (l < 0) and (n == 1 - l):
    for i in range(1, n):
        count += i + l -1
        
    print(count)

Submission status: Accepted

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

def getMin(arr):
    idx = 0
    curr = abs(arr[0])
    for i in range(1, len(arr)):
        if abs(arr[i]) < curr:
            curr = abs(arr[i])
            idx = i
    return (idx, curr)

f = [(L + i) for i in range(N)]
idx, m = getMin(f)
print(sum([i if i != f[idx] else 0 for i in f]))

Submission status: Accepted

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

elif L+N<=1:
    for i in range(N-1):
        X=X+L+i

else:
    for i in range(N):
        X=X+L+i
print(X)

Submission status: Accepted

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

s=b-1
m=0

r=0

if b < 1:
    if a + b > 0:
        m = 0
    else:
        m = b + a -1
else:
    m = b

for i in range(a):
    s += 1
    r = r + s
    #print(r)

print(r-m)

Submission status: Accepted

Solution code:
import numpy as np
N,L = [int(x) for x in input().split(' ')]
s = np.sum(range(N+1)) + (N - 1) * L - (N - 1)
#print(s)
off = L - 1
#print('off',off)

if off >= 0:
  s -= 1
else:
  if -off >= N:
    off = -N
  s += off
print(s)

Submission status: Accepted

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

taste = [L+i-1 for i in range(1,N+1)]
eat = min(map(abs,taste))
if L+N-1 < 0:
    eat *= -1

print(sum(taste) - eat)

Submission status: Accepted

Solution code:
def checkio(numbers_array):
    return sorted(numbers_array, key=lambda x: abs(x))


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

    
w_list=checkio(w_list)
ans=0
for i in range(n-1):
    ans=ans+w_list[i+1]
#print(w_list)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

lst = list(l+(i+1)-1 for i in range(n))

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

print(sum(lst))

Submission status: Accepted

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

if sum(taste) >= 0:
    print(sum(taste) - min(taste_abs))
else:
    print(sum(taste) + min(taste_abs))

Submission status: Accepted

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

mini = 100
index = 0
for i in range(N):
  if mini > abs(lis[i]):
    mini = abs(lis[i])
    index = i

print(sum(lis)-lis[index])

Submission status: Accepted

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

largest = L + N - 1
smallest = L

passZero = largest * smallest < 0

numSum = N * ( L + N / 2.0 - 0.5)

res = 0
if passZero:
    res = int(numSum)
else:
    if numSum > 0:
        res = int(numSum - L)
    elif numSum == 0:
        res = int(numSum)
    else:
        res = int(numSum-L-N+1)

print(res)

Submission status: Accepted

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

for i in range(1, N+1):
    li.append(i)

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

if li2[0] > 0:
    del li2[0]

if li2[-1] < 0:
    del li2[-1]

s = sum(li2)


print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list = list(map(int,input().split()))
exlist = [list[1] +i for i in range(list[0]) ]
sum = sum(exlist)
if exlist[0] > 0 and exlist[list[0]-1] > 0:
	print(sum-exlist[0])
elif exlist[0] <= 0 and exlist[list[0]-1] >= 0:
	print(sum)
else:
	print(sum-exlist[list[0]-1])

Submission status: Accepted

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

if L >= 0:
    aji = L + 1
    ajiTotal = 0
    for i in range(N - 1):
        ajiTotal = ajiTotal + aji
        aji = aji + 1
    print(ajiTotal)

else:
    if N + L > 0:
        aji = L
        ajiTotal = 0
        for i in range(N):
            ajiTotal = ajiTotal + aji
            aji = aji + 1
        print(ajiTotal)
    else:
        aji = L
        ajiTotal = 0
        for i in range(N - 1):
            ajiTotal = ajiTotal + aji
            aji = aji + 1
        print(ajiTotal)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
import numpy as np
# from fractions import gcd

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, l = ip.IL()
    memo = (1 + n) / 2 * n
    memo2 = memo + l * n
    m = np.arange(0, n)
    m += l
    idx = np.abs(np.asarray(m)).argmin()

    m = np.delete(m, idx)
    print(np.sum(m))

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import numpy as np


def resolve():
    N, L = map(int, input().split())
    taste = np.zeros(N)
    for i in range(N):
        taste[i] = L + i
    min_idx = np.argsort(np.abs(taste))[0]
    sum_taste = np.sum(taste) - taste[min_idx]
    print(np.int(sum_taste))

resolve()

Submission status: Accepted

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

taste = 0

# 味が0のりんごがある場合
if l <= 0 and 0 < n + l:
  for i in range(n):
    taste += l + i
# すべて負値の場合
elif l <= 0:
  for i in range(n -1):
    taste += l + i
# すべて正値の場合
else:
  for i in range(1, n):
    taste += l + i

print(taste)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
Sum = 0
Eaten = 114514

for i in range(N):
    if abs(Eaten) > abs(L + i):
        Eaten = L + i
    Sum = Sum + L + i

Sum = Sum - Eaten
print(Sum)

Submission status: Accepted

Solution code:
# 最初に入れておくとinputが早くなる
#import numpy as np
import sys
input = sys.stdin.readline

n, l = map(int, input().split())
azi = []
minn = n+l-1
for i in range(1, n+1):
    azi.append(i + l - 1)
    if (abs(minn) >= abs(i + l - 1)):
        minn = i + l - 1
print(sum(azi)-minn)
#arr = np.array(azi)
#ab = np.abs(arr)

#print(sum(azi) - azi[np.where(ab == ab.min()).tolist()[0]])

Submission status: Accepted

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

s = 0
# if N==2:
#     if L>0:
#         print(L+2-1)
#     elif L<0 and abs(L)>N:
#         print(L+1-1)
#     else:
#         print(L+1-1)
#     exit()

if L>0:
    for i in range(2,N+1):
        s += L+i-1
    print(s)
elif L<0 and L*(-1)>N-1:
    for i in range(1,N):
        s += L+i-1
    print(s)
else:
    for i in range(1,N+1):
        s += L+i-1
    print(s)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
R=[L+i for i in range(N)]
S=abs(sum(R))
S2=0
for r in R:
    if S >= abs(r) :
        S = abs(r)
        S2 = r
print("{}".format(sum(R)-S2))

Submission status: Accepted

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

tsum = 0
if L >= 0:
    # L+1, ..., L+N-1
    tsum = (L + N - 1) * (L + N) / 2 - L * (L + 1) / 2
elif L + N - 1 >= 0:
    # L, ..., L+N-1
    tsum = (L + N - 1) * (L + N) / 2 - (-L) * (-L + 1) / 2
else:
    # L, ..., L+N-1
    tsum = - ((-L) * (-L + 1) / 2 - (-(L+N-1)) * (-(L+N-1) + 1) / 2)

print(int(tsum))

Submission status: Accepted

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

# L+i-1の絶対値ができるだけ小さなものを選べば良い？
# L+i-1==0 -> i = 1-L and i=1 to N

i = min(max(1, 1-L), N)
total = N*(L-1) + int(N*(N+1)/2)
result = total - (L+i-1)
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,L = (int(x) for x in input().split())
sum = N*(2*L+N-1)/2
if L >= 0:
  print(int(sum - L))
elif(L < 0 and L+N-1>0):
  print(int(sum))
else:
  print(int(sum - (L+N-1)))

Submission status: Accepted

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

Submission status: Accepted

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

    #print(taste)
    abs_taste = []
    for i in taste:
        abs_taste.append(abs(i))

    m = abs_taste.index(min(abs_taste))
    #print(m)
    taste.pop(m)
    #print(taste)

    print(sum(taste))

main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
re=[]
for i in range(1,n+1):
  re.append(l+i-1)
if 0 in re:
  print(sum(re))
else:
  if l>0:
  	print(sum(re)-min(re))
  elif(l<0):
    print(sum(re)-max(re))
#print(6+7+8+9+10+11)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

del list[0]

print(sum(list))

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
aji=[i+L-1 for i in range(1,N+1)]
org=sum(aji)
aji_list=[]
for i in aji:
    aji_list.append([abs(i),org-i])

print(min(aji_list)[1])

Submission status: Accepted

Solution code:
num = input().split()
amount = int(num[0])
aji_list = [int(num[1])+i for i in range(amount)]

original_aji = sum(aji_list)
smallest = abs(aji_list[0])

for i in aji_list:
  if abs(i)<abs(smallest): smallest = i
    
print(original_aji-smallest)

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
if L > 0:
    current = L + 1
    for i in range(0, N - 1):
        result = result + current
        current = current + 1
elif L + N - 1 < 0:
    current = L
    for i in range(0, N - 1):
        result = result + current
        current = current + 1
else:
    current = L
    for i in range(0, N):
        result = result + current
        current = current + 1
print(result)

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, l = rli()
    taste = 0
    m = 999999999
    t_min = 0
    for i in range(n):
        t = l + i
        if abs(t) < m:
            m = min(m, abs(t))
            t_min = t
        taste += t
    print(taste-t_min)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

# 自然数の和を用いる
# 初項Lで，N個の自然数の和
total = N*(2*L + N-1)/2

# 味がなるべく変わらないには，途中の項で絶対値が一番小さいものを選べば良い
aji_list = range(L, L+N, 1)
aji_abs_list = list(map(abs, aji_list))
aji_abs_list.sort()
min_list = aji_abs_list[0]

min_minus = min_list * -1
if L <= min_minus <= L+N:
    min_list = min_minus

# 上記を選んでtotalから弾く
print(int(total - min_list))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, L = (int(x) for x in input().split())
a = [0] * N
for i in range(N):
    a[i] = L + i
a.sort()
if 0 in a:
    print(sum(a))
elif a[0] > 0 and a[-1] > 0:
    print(sum(a[1:N]))
else:
    print(sum(a[0:N-1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
def apple(a,b):
    if a == 0:
        return 0
    return apple(a-1,b)+ b+a-1

cor = apple(n,l)
wro = apple(n-1,l)
for i in range(1,n):
    if abs(l+i-1) < abs(wro-cor) :
        wro = cor -(l+i-1)
    else:
        wro += 0

print(wro)

Submission status: Accepted

Solution code:
def main():

    # 2 <= n <= 200
    # -100 <= l <= 100

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

    moto = 0

    min = l + 1 - 1
    min = abs(min)
    default_i = 1

    for i in range(n):
        i += 1
        aji = l + i -1
        abs_aji = abs(aji)
        if(abs_aji < min):
            min = abs_aji
            default_i = i

        moto += aji
    
    tabeta = moto - (l + default_i - 1)
    
    print(tabeta)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if L > 0:
  print(sum(taste)-taste[0])
elif L + N - 1 <= 0:
  print(sum(taste)-taste[N-1])
else:
  print(sum(taste))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# スペース区切りの整数の入力（別変数に格納）
N,L = map(int, input().split())
# N=30
# L=-50

a=[]
check=L
min_i=0
for i in range(N):
    a.append(L+i)
#     print(a[i], check)
    if(abs(a[i])<abs(check)):
        check=abs(a[i])
        min_i=i
    
print(sum(a)-a[min_i])

Submission status: Accepted

Solution code:
N,L = list(map(int, input().split()))
m = 1000000000
k = 0
s = 0

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

for i in range(1,N+1):
    if i != k:
        s = s + L + i - 1
        
print(s)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apples = list(range(l, l + n))
if 0 in apples:
    print(sum(apples))
elif l < 0:
    print(sum(apples) - max(apples))
else:
    print(sum(apples) - min(apples))

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
taste = [L+i-1 for i in range(1, N+1)]
abs_taste = list(map(lambda x: abs(x), taste))
argmin = abs_taste.index(min(abs_taste))
cnt = 0
x = sum([taste[n] for n in range(N) if n != argmin])
print(x)

Submission status: Accepted

Solution code:
import numpy as np
N,L = list(map(int, input().split()))
l_num = np.arange(L,(L+N))
wa = np.sum(l_num)
if any(l_num<0):
	print(wa + np.min(np.abs(l_num)))
else:
	print(wa-np.min(np.abs(l_num)))

Submission status: Accepted

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

ideal = sum(numlist)
salist = []
for i in range(N):
    a = numlist.pop(i)
    suma = sum(numlist)
    salist.append(suma)
    numlist.insert(i,a)


anslist = []
lastans = 0
for i in range(len(salist)):
    if i == 0:
        sa = salist[i] - ideal
        anser = i
    else:
        if abs(salist[i] - ideal) < sa:
            sa = salist[i] - ideal
            anser = i

print(salist[anser])

Submission status: Accepted

Solution code:
n, f  = input().split(' ')
flavors =  []
for i in range(int(n)):
    flavors.append(i + int(f))

#print(flavors)

min_v = abs(flavors[0])
for i in flavors:
    if abs(i) < abs(min_v):
        min_v = i
      #  print(min_v)

print(sum(flavors) - min_v)

Submission status: Accepted

Solution code:
import numpy as np
N,L = map(int,input().split())
azi = [i+L for i in range(N) ]
azi_abs = np.abs(azi)

if 0 in azi:
    print(sum(azi))
else:
    apple_azi = [abs(sum(azi)-sum(azi)-azi[i]) for i in range(len(azi))]
    if sum(azi) >= 0:
        print(sum(azi)-min(apple_azi))
    else:
        print(sum(azi)+min(apple_azi))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
if L >=0:
    Aji = list(range(L+1,L+N))
    ans = sum(Aji)
    print(ans)
elif L<0 and L+N >= 1:
    Aji = list(range(L,L+N))
    ans = sum(Aji)
    print(ans)
else:
    Aji = list(range(L,L+N-1))
    ans = sum(Aji)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N,L = [int(i) for i in input().split()]
list=[]
s=N*(L-1)
for i in range(1,N+1):
    s +=i
    list.append(abs(L+i-1))
a=0
if s<0:
    a=s+min(list)
else:
    a=s-min(list)

print(a)

Submission status: Accepted

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

Submission status: Accepted

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

azi = []
N,L = map(int,input().split())

for i in range(N):
    azi.append(L+i)
all = sum(azi)

wa = 0
ans=0
min = 999999

for i in range(N):
    wa = 0
    for j in range(N):
        if (i != j):
            wa += azi[j]
    if abs(all-wa) < min:
        min = abs(all-wa)
        ans = wa 

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

l = [L+i for i in range(N)]
total = sum(l)
for i in range(N):
    total2 = total - l[i]
    ans += [abs(total - total2)]
print(total-l[ans.index(min(ans))])