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:
#!/usr/local/bin/python3

def solve(n, l):
	minaji = 9999999999
	res = -1
	for i in range(n):
		aji = i + l
		if abs(aji) < minaji:
			minaji = abs(aji);
			res = i
	sumaji = 0
	for i in range(n):
		aji = i + l
		if i != res:
			sumaji = sumaji + aji
	return sumaji


n, l = map(int, input().split())
ans = solve(n, l)
print(ans)

Submission status: Accepted

Solution code:

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

Vs=[0]*N
for i in range(N):
    Vs[i] = L+i

sumv = sum(Vs)

minv = 999999
v = 0
for i in range(N):
    t = sumv-Vs[i]
    d = abs(sumv-t)
    if d<minv:
        minv = d
        v = t
print(v)

Submission status: Accepted

Solution code:
# coding:utf-8


def main():
    # N = int(input())
    N, L = map(int, input().split())
    ans = 0
    min_azi = 101
    min_i = 0
    for i in range(1, N+1):
        temp = abs(L+i-1)
        # print(temp)
        if min_azi > temp:
            min_azi = temp
            min_i = i

    # print(min_i, min_azi)
    for i in range(1, N+1):
        if i == min_i:
            continue
        else:
            ans += L+i-1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys

n, l = [ int(x) for x in sys.stdin.readline().split() ]

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

if l-1<0: s-= min(1-l,n)
else: s-=1

print( s )

Submission status: Accepted

Solution code:
N, L = [int(i) for i in input().split()]
A = list(range(L, L + N))
su = sum(A)

ans = su - A[0]
mi = abs(A[0])
for a in A:
    if mi > abs(a):
        ans = su - a
        mi = abs(a)
print(ans)

Submission status: Accepted

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

solve()

Submission status: Accepted

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

sum = 0
min = 100000
min2 = 0
for i in range(0, N):
    aji = L+i
    sum += aji
    if(abs(aji) < min):
        min = abs(aji)
        min2 = aji

print(sum - min2)

Submission status: Accepted

Solution code:
n,L= map(int,input().split())
u = [i+L for i in range(n)]
a = 100000000
for i in u:
    a = min(a,abs(i))
    if a == abs(i):
        b = i
u.remove(b)
print(sum(u))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = [L + i for i in range(N)]
_, idx = min([(abs(a), i) for i, a in enumerate(apples)])
print(sum([a for i, a in enumerate(apples) if i != idx]))

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0
lst = []
for i in range(N):
    lst += [[abs(L + (i+1) -1), L + (i+1) -1]]
    ans += L + (i+1) -1

lst.sort()
# print (lst)
print (ans - lst[0][1])

Submission status: Accepted

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

start = L
end = L + N - 1

def aji(n):
    return n * (n+1) // 2

if start * end <= 0:
    print(aji(N-1) + L * N)
elif start > 0:
    print(aji(N-1) + L * (N-1))
elif end < 0:
    print(aji(N-2) + L * (N-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
tot=l*n+n*(n-1)//2
a=float("inf")
ans=0
for i in range(n):
  if a>abs(l+i):
    a=abs(l+i)
    ans=i
print(tot-(l+ans))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,l = f()
    fsum = sum([ l+i for i in range(n)])

    minabs = min([abs(l+i) for i in range(n)])

    for i in range(n):
        if abs(l+i) == minabs:
            print(fsum - (l+i))
            return

    


solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

apples = []
abss = []
for i in range(0, n):
    apples.append(l + i)
    abss.append(abs(l + i))

tmp = zip(abss, apples)
tmp = sorted(tmp)
abss, apples = zip(*tmp)

after = sum(apples[1:])
print(after)

Submission status: Accepted

Solution code:
# 0からの差が小さいもの（絶対値が0に近いもの）を選ぶ
n, l = map(int, input().split())
arr = [i + l for i in range(n)]
s = sum(arr)
idx = -1
mindif = 10 ** 9
for i, a in enumerate(arr):
    if mindif > abs(a):
        mindif = abs(a)
        idx = i
print(s - arr[idx])

Submission status: Accepted

Solution code:
N , L = map(int, input().split())
sum_a = 0
min_a = 10000000

for i in range(N):
    a = L + i
    sum_a += a
    if abs(a) == min(min_a, abs(a)):
        min_a = abs(a)
        min_aa = a


print(sum_a - min_aa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N, L = map(int, input().split())
    if L*(L+N-1) <= 0:
        return sum(L+i for i in range(N))
    elif L > 0:
        return sum(L+i for i in range(N)) - L
    else:
        return sum(L+i for i in range(N)) - ((L+N-1))

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

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

N, L = getlist()

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

ans = sum(a)
vv = float("inf")
v = float("inf")
for i in a:
	if abs(i) < v:
		v = abs(i)
		vv = i

print(ans - vv)

Submission status: Accepted

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

Submission status: Accepted

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

_, k = min((abs(L + i - 1), i) for i in range(1, N+1))
print sum(L + i - 1 for i in range(1, N+1) if i != k)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
aa = [(abs(l + i - 1), l + i - 1) for i in range(1, n + 1)]
rest = list(sorted(aa))[1:]
print(sum(map(lambda x: x[1], rest)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, L: int):
    ls = [L + i - 1 for i in range(1, N + 1)]
    return sum(ls) - ls[min([(abs(l), i) for i, l in enumerate(ls)])[1]]




def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    result = solve(N, L)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:


def read_input():
    n, l = map(int, input().split())

    return n, l


def submit():
    n, l = read_input()
    tastes = [l + i for i in range(n)]

    total = sum(tastes)
    left = 0
    right = total

    mindiff = abs(total) + 1
    ans = None

    for curr in tastes:
        right -= curr

        absdiff = abs(total - (left + right))
        if absdiff < mindiff:
            mindiff = absdiff
            ans = left + right

        left += curr

    print(ans)




if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())  # 複数数値入力
minaji = float('inf')
ans = 0
for i in range(n):
    if abs(minaji) > abs(i + l):
        minaji = i + l
    ans += i+l

print(ans - minaji)

Submission status: Accepted

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

taste = [0] * N

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

taste.sort(key=lambda i : abs(i))

ans = sum(taste[1:N])

print(ans)

Submission status: Accepted

Solution code:
N, L = [int(i) for i in input().split()]
taste = [L + i - 1 for i in range(1, N + 1)]
absolute = float('inf')
ans = float('inf')
total = sum(taste)
for i in range(N):
    total_b = sum(taste[:i] + taste[i + 1:])
    if abs(total - total_b) < absolute:
        ans = total_b
        absolute = abs(total - total_b)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

if t[0] > 0 :
    print(s - t[0])
elif t[-1] < 0 :
    print(s - t[-1])
else :
    print(s)

Submission status: Accepted

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

abs_ringos=[abs(i) for i in ringos]

min_key=0
amin_ringo=99999
for i in range(len(abs_ringos)):
    if amin_ringo != min(amin_ringo,abs_ringos[i]):
        amin_ringo = abs_ringos[i]
        min_key=i

print(sum(ringos)-ringos[min_key])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
pi = []
for i in range(N):
    pi.append([L+i, abs(L+i)])
pi.sort(key=lambda x:x[1])
pi = pi[1:]
ret = 0
for p, _ in pi:
    ret += p
print(ret)

Submission status: Accepted

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

pos = [10000]
neg = [10000]
for a in apple:
    if a>=0:
        pos.append(a)
    else:
        neg.append(-a)
        
pos.sort()
neg.sort()

m = pos[0] if pos[0]<=neg[0] else -neg[0]

print(sum(apple) - m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

smallest_abs = 100000000000
elem = 0
for i in range(1, N + 1):
    if abs(L - 1 + i) < smallest_abs:
        smallest_abs = abs(L - 1 + i)
        elem = L - 1 + i

print(all_flavor - elem)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, L = mi()
tastes = [L+i for i in range(N)]
absmintaste = 10**9
for t in tastes:
  if abs(absmintaste) > abs(t):
    absmintaste = t

print(sum(tastes)-absmintaste)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,L=map(int,input().split())
A=[]
B=[]
ans=0
for i in range(n):
  A.append(abs(L+i))
  B.append(L+i)
ans=B[A.index(min(A))]
print(sum(B)-ans)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
taste=[l+i for i in range(n)]
absTaste=[abs(l+i) for i in range(n)]
eat=min(enumerate(absTaste),key=lambda x:x[1])[0]
# print(taste,eat)
ans=0
for i in range(n):
    if i!=eat:
        ans+=taste[i]

print(ans)

Submission status: Accepted

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

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

for i in range(N):
    taste[i] = L + (i+1) - 1
    taste2[i] = abs(L + (i+1) - 1)
eat = min(taste2)
taste.pop(taste2.index(eat))
print(sum(taste))

Submission status: Accepted

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

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

ans=sum(Good)

x=100000
for i in range(len(Good)):
    if abs(Good[i])<abs(x):
        x=Good[i]

print(ans-x)

Submission status: Accepted

Solution code:
n, l = [int(i) for i in input().split()]
if l <= 0 and l + n - 1 >= 0:
    print((l-1)*n + n*(n+1)//2)
elif l > 0:
    print((l-1)*n + n*(n+1)//2 - l)
else:
    print((l-1)*n + n*(n+1)//2 - (l+n-1))

Submission status: Accepted

Solution code:
N,L=(int(x) for x in input().split())
aji=[]
aji_abs=[]
for n in range(N):
    a=L+n
    aji.append(a)
    aji_abs.append(abs(a))
ba=aji_abs.index(min(aji_abs))
wa=0
for n in range(N):
    wa=wa+aji[n]
print(wa-aji[ba])

Submission status: Accepted

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

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

taste = []
for i in range(n):
    taste.append(i + l)
s = sum(taste)
m = 100000000
for i in range(n):
    tmp = 0
    for j in range(n):
        if i != j:
            tmp += taste[j]
    if abs(s - tmp) < m:
        m = abs(s - tmp)
        t = tmp

print(t)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
f=[i for i in range(l,l+n)]
sf=sum(f)
s=f[0]
for i in f:
    if abs(i)<abs(s):
        s=i
print(sf-s)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    n, l = map(int, input().split())

    absmn = 10**9
    mn = None
    sm = 0
    for i in range(n):
        index = i + 1
        aji = l + index - 1
        if absmn > abs(aji):
            absmn = abs(aji)
            mn = aji
        sm += aji
    dprint(sm, absmn)
    print(sm - mn)

solve()

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
mo = 10000
ans = 0
for i in range(0,n):
    if abs(mo) > abs(l+i):
        mo = l+i
    ans += l+i
    #print(l+i)

print(ans-mo)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, raw_input().split())
a, b = l, l + n - 1
s = (a + b) * n / 2


if a <= 0 and b >= 0:
    print s
elif l > 0:
    print s - a
else:
    print s - b

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
T = []
for i in range(N):
  T.append(L+i)
if max(T) >= 0 and min(T) <= 0:
  print(sum(T))
else:
  if max(T) < 0:
    print(sum(T)-max(T))
  else:
    print(sum(T)-min(T))

Submission status: Accepted

Solution code:

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

S = 0
ss = L
for i in range(N):
    S += i + L
    if abs(i+L) < abs(ss):
        ss = i + L
        
print(S - ss)

Submission status: Accepted

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

answer=0
mi=10**9
for i in range(N):
  flabor=L+i
  if abs(flabor)<abs(mi):
    mi=flabor
  answer+=flabor
print(answer-mi)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min_abs = 1000
for i in range(N):
    if abs(min_abs) > abs(L + i):
        min_abs = L + i
ans = 0

for i in range(N):
    if min_abs == L + i:
        continue
    ans += L + i
print(ans)

Submission status: Accepted

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


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

    min_abs = float("inf")
    st = float("inf")
    for t in T:
        if min_abs > abs(t):
            min_abs = abs(t)
            st = t

    print(sum(T) - st)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
sys.dont_write_bytecode = True
stdin = sys.stdin
input = stdin.readline
sys.setrecursionlimit(10000000)

#import numpy as np
#import scipy as sp

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce, lru_cache
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5.  Import from math after it.
from fractions import gcd
from fractions import Fraction as Frac

inf = float('inf')

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

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(func = input, sep = None, conv = int):
    return list(map(conv, func().split(sep = sep)))

################################################################################


def main():
    N, L = list(map(int, input().split()))
    aji = [None for i in range(N)]
    for i in range(N):
        aji[i] = L + i
    mi = inf
    for i in range(N):
        if abs(aji[i]) < mi:
            mi = abs(aji[i])
            mi_real = aji[i]
    print(sum(aji) - mi_real)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N, L = inpl()
S = [L+i for i in range(N)]

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in A:
    print(sum(A))
else:
    if abs(A[0]) < abs(A[-1]):
        print(sum(A)-A[0])
    else:
        print(sum(A)-A[-1])

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
arr=[]
de=9999999999999999999
denum=0
for i in range(a):
    arr.append(i+b)
    if abs(i+b)<de:
        de=abs(i+b)
        denum=i
#print(arr)
#print(denum)
del arr[denum]
print(sum(arr))

Submission status: Accepted

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

for i in range(n):
    ans += l + i
    
if l + n - 1 < 0:
    ans -= l+n-1
elif l > 0:
    ans -= l

print(ans)

Submission status: Accepted

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

mn = 10**9
for i in range(N):
  if mn > abs(a[i]):
    mn = abs(a[i])
    agmn = i

sm = 0
for i in range(N):
  if i!=agmn:
    sm += a[i]

# print(mn, agmn)
print(sm)

Submission status: Accepted

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

for i in range(N):
	taste[i] = (abs(L + i), L + i)
	
taste.sort()
ans = 0

for i in range(1, N):
	ans += taste[i][1]
	
print(ans)

Submission status: Accepted

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

j = min(
    range(1, N + 1),
    key=lambda i: abs(L + i - 1)
)
ans = sum(L + i - 1 for i in range(1, N + 1)) - (L + j - 1)

print(ans)

Submission status: Accepted

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

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


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


ans = taste
if 0 in apple_list:
    ans = taste
elif taste < 0:
    ans = taste - apple_list[-1]
else:
    ans = taste - apple_list[0]

print(ans)

Submission status: Accepted

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

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

min_idx = 0
min_abs = abs(dat[0])
for i in range(n):
    if abs(dat[i])<min_abs:
        min_abs = abs(dat[i])
        min_idx = i

print(sum(dat) - dat[min_idx])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

n, k = [int(i) for i in input().split()]
a = []
for i in range(n):
    a.append(k+i)
temp = float('inf')
for apple in a:
    if abs(temp) > abs(apple):
        temp = apple
print(sum(a)-temp)

Submission status: Accepted

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

ans = 0
margin = float("inf")
for i in range(1, N + 1):

    tar = 0
    for j in range(1, N + 1):
        tar += L + j - 1

    res = 0
    for j in range(1, N + 1):
        if j == i:
            continue
        else:
            res += L + j - 1

    if abs(tar - res) < margin:
        ans = res
        margin = abs(tar - res)


print(ans)

Submission status: Accepted

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

a = [0] * n

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

total = sum(a)

ap = 100 * 2000

tmp = 0
for i in range(n):
    tmp = total - a[i]
    if abs(total - tmp) < ap:
        ap = abs(total - tmp)
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
apple=[]
total=0
min_effect=0
for i in range(0,N):
    apple.append(L+i)
    total+=(L+i)
if(apple[0]*apple[N-1]<=0):
    min_effect=0
elif(apple[N-1]<0):
    min_effect=apple[N-1]
elif(apple[0]>0):
    min_effect=apple[0]
print(total-min_effect)

Submission status: Accepted

Solution code:
# B問題
N, L = map(int, input().split())
lst = []
for i in range(N):
    lst.append(L + i)
if L > 0:
    lst = lst[1:]
    print(sum(lst))
elif 0 in lst:
    print(sum(lst))
else:
    lst = lst[:-1]
    print(sum(lst))

Submission status: Accepted

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	N, L = map(int, input().split())
	sum = L * N + N * (N - 1) / 2
	if L >= 0:
		eat = L
	elif L + N - 1 >= 0:
		eat = 0
	else:
		eat = L + N -1
	print(int(sum - eat))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = []
no = L
for i in range(N):
  a.append(L+i)
  if abs(no) > abs(L+i):
    no = L+i
print(sum(a)-no)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = list(range(L, L + N, 1))
org = sum(A)
if A[0] <= 0 <= A[-1]:
  print(org)
elif A[0] <= 0:
  print(org - A[-1])
else:
  print(org - A[0])

Submission status: Accepted

Solution code:
##!/usr/bin/env python3
import sys
# from operator import itemgetter
# gcd
# from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_1.txt', 'r')
# sys.stdin = fin
# 提出時はコメントアウト+上のshebangを有効にする
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int

    # write code
    A = [L + i - 1 for i in range(1, N + 1)]
    subA = deepcopy(A)
    sum_A = sum(A)
    # print(A)
    A = list(map(abs, A))
    A.sort()
    if A[0] in subA:
        print(sum_A - A[0])
    else:
        print(sum_A + A[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n, l = map(int, input().split())
  total = sum([l + i for i in range(n)])
  mina = pow(10, 9)
  for i in range(n):
    _l = l + i
    if abs(_l) < abs(mina):
      mina = _l
  print(total - mina)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

taste = np.array([l + i for i in range(n)], dtype=np.int)
taste_abs = np.abs(taste)
i = np.argmin(taste_abs)

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

print(s)

Submission status: Accepted

Solution code:
def main():
    n,l = map(int,input().split())
    min_diff = float('inf')
    pies = []
    for i in range(1,n+1):
        pies.append(l+i-1)

    total = sum(pies)
    ans = 0

    for i in range(n):
        new = total
        new -= pies[i]
        if abs(new-total) < min_diff:
            min_diff = abs(new-total)
            ans = new

    print(ans)


main()

Submission status: Accepted

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

  if u * l <= 0:
    print(v)
  elif u > 0:
    print(v - l)
  else:
    print(v - u)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n,l=intinput()
li=[l+i for i in range(n)]
k=sum(li)
ans=float("inf")
for i in range(len(li)):
    v=sum(li[:i]+li[i+1:])
    if abs(ans-k) > abs(v-k):
        ans=v
print(ans)

Submission status: Accepted

Solution code:
# coding=utf-8


N, L = map(int, raw_input().split())
A = range(L, L + N)
print sum(A) - min([i for i in A], key=abs)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
t=[]
for i in range(n):
    t.append(l+i)
#print(t)
T=sum(t)
S=[]
for i in range(n):
    k=t[:i]+t[i+1:]
#    print(k)
    S.append([abs(T-sum(k)),sum(k)])
S.sort(key=lambda x:x[0])
#print(S)
print(S[0][1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

n, l = LI()
sums = [l + i for i in range(n)]
sums_sum = sum([l + i for i in range(n)])
if 0 in sums:
    print(sums_sum)
elif l > 0:
    print(sums_sum - l)
else:
    print(sums_sum - sums[-1])

Submission status: Accepted

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


absmin = 1000
ans_minus = 0
ans = 0
for i in range(N):
    if abs(L+i)<absmin:
        absmin = abs(L+i)
        ans_minus = L+i
    ans += L+i

print(ans-ans_minus)

Submission status: Accepted

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

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

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

for i in range(N):
    if L + i == 0:
        ans = i
        break
else:
    if L + N - 2 < 0: ans = N - 1
    else: ans = 0

print(Lsum - (L + ans))

Submission status: Accepted

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

mn = l
mx = l+n-1
s = sum(range(mn, mx+1))
if l >= 0:
    s -= mn
elif mx < 0:
    s -= mx

print(s)

Submission status: Accepted

Solution code:
N, L = [int(c) for c in input().split()]
S = L * N + (N-1)*N // 2

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

Submission status: Accepted

Solution code:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N, L = InputToInt()
    if L > 0:
        print(sum(range(L+1,N+L)))
    elif N+L-1>0:
        print(sum(range(L,N+L)))
    else:
        print(sum(range(L,N+L-1)))