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:
s = input().split(' ')
n = int(s[0])
l = int(s[1])
if l > 0:
  m = (l + n+l-1) * n / 2 - l
  print(int(m))
elif l < 0 and (n+l-1) < 0:
  m = (l + n+l-1) * n / 2 - (n+l-1)
  print(int(m))
else:
  m = (l + n+l-1) * n / 2
  print(int(m))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
c = [l+i-1 for i in range(1,n+1)]
k = sum(c) #n elements
z = []
for i in range(len(c)):
    z.append(k-c[i])  #n-1 elements
l = []
for i in range(len(z)):
    l.append(abs(k-z[i]))
print(z[l.index(min(l))])

Submission status: Accepted

Solution code:
# using main() makes code faster from the point of view of "access to variables in global name-space"
# def main():

# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from operator import itemgetter 
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)

# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
    # evaluate reciprocal using Fermat's little theorem:
    # a**(p-1) is identical to 1 (mod p) when a and p is coprime
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    # fac_list = modfactorial_list(100)
    # print(modcomb(100, 5, modfactorial_list(100)))
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))


# initialize variables and set inputs
#initialize variables
    # to initialize list, use [0] * n
    # to initialize two dimentional array, use [[0] * N for _ in range(N)]
# set inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
# calculate and output
    # output pattern
    # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6

# # set test data
# sys.stdin = open('sample.txt') # for test

# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: map(int, r().split())

# set inputs
N, L = R()
A = [L + (i + 1) - 1 for i in range(N)]
print(sum(A)-min(A, key=abs))

# if __name__ == '__main__':
#     main()

Submission status: Accepted

Solution code:
def resolve():
    (N, L) = list(map(int, input().split(" ")))
    Ts = []
    offset = L - 1
    absmin = float('inf')
    mini = float('inf')
    for i in range(1, N+1):
        Ts.append(i+offset)
        if abs(i + offset) < absmin:
            absmin = abs(i + offset)
            mini = i + offset
    print(sum(Ts)-mini)
        
    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

cnt = 0
m = None
for i in range(L, L+N):
    cnt += i
    if m is None:
        m = i
    elif abs(i) < abs(m):
        m = i
print(cnt-m)

Submission status: Accepted

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

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


print("{}".format(ans))

Submission status: Accepted

Solution code:
import numpy as np

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

tastes = np.arange(N) + L
idx = np.argmin(np.abs(tastes))
tastes[idx] = 0
print(np.sum(tastes))

Submission status: Accepted

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

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


m = 1000
M = -1000
f = 0
for s in S_list:
    if s < m:
        m = s
    if M < s:
        M = s
    if s == 0:
        f = 1
        break

if f == 0:
    if S > 0:
        S = S - m
    else:
        S = S - M

print(S)

Submission status: Accepted

Solution code:
from sys import stdin

N, L = list(map(int, stdin.readline().split()))

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

absAppleList = [abs(s) for s in appleList]


print(sum(appleList)-appleList[absAppleList.index(min(absAppleList))])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
absmin = 10**9
absmint = 10**9
sum_ = 0
for i in range(n):
    t = i+l
    sum_ += t
    #print(sum_)
    if absmin > abs(t):
        absmin = abs(t)
        absmint = t
        
sum_ -= absmint 
print(sum_)

Submission status: Accepted

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

mingo = 1000

cnt = 0
sumringo = 0
while cnt < N:
    sumringo += L
    if abs(L) < mingo:
        eatringo = L
        mingo = abs(L)
    L += 1
    cnt += 1

print(sumringo - eatringo)

Submission status: Accepted

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

tastes = [L+i for i in range(N)]
m = 100

for t in tastes:
    if abs(t) < abs(m):
        m = t

print(sum(tastes) - m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inp = [int(i) for i in input().split()]
aa = []
for d in range(inp[1],inp[1]+inp[0]):
    aa.append(d)

if 0 in aa:
    pass
elif aa[-1] <= 0:
    aa.pop(-1)
else:
    aa.pop(0)

print(sum(aa))

Submission status: Accepted

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

elif N>abs(L):
    for i in range(N):
        total += L
        L += 1

else:
    for i in range(N-1):
        total += L
        L += 1
print(total)

Submission status: Accepted

Solution code:
def sgn(X):
    if X > 0:
        return 1
    elif X < 0:
        return -1
    else:
        return 0

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

taste = [0] * N
taste[0] = 10000

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

taste2 = list(map(abs, taste))

print(sum(taste) - sgn(sum(taste)) * min(taste2))

Submission status: Accepted

Solution code:
import numpy as np
N, L =  list(map(int,input().split(" ")))
taste = np.arange(N) +  L
diff_taste_min = np.argmin(np.abs(taste))
print(np.sum(taste) - taste[diff_taste_min])

Submission status: Accepted

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

sum_n = 0
min_abs = 20000
for i in range(N):
    sum_n+=L+i
    min_abs=min(min_abs, abs(L+i))
if sum_n>0:
    print(sum_n-min_abs)
else:
    print(sum_n+min_abs)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, l = list(map(int, input().split()))
ringos = np.array([l + i for i in range(n)])
eatringo = min(np.abs(ringos))
if eatringo in ringos :
    print(sum(ringos)-eatringo)
else :
    print(sum(ringos)+eatringo)

Submission status: Accepted

Solution code:
def bite_eating(N: int, L: int)->int:
    total = N*(N-1)//2 + L*N

    if L >= 0:
        # L が正の値なら一番小さいものを食べる。
        return total-L

    if N+L-1 < 0:
        # L が負の値かつ一番大きい値も負であるなら一番大きいものを食べる。
        return total-(N+L-1)

    # 上述の条件に当てはまらない場合は、必ず美味しさ 0
    # のものが存在するのでそれを食べる。
    return total


if __name__ == "__main__":
    N, L = map(int, input().split())

    ans = bite_eating(N, L)
    print(ans)

Submission status: Accepted

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


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

aji_abs = list(map(abs, aji))
min_tmp = float('inf')
indx = -1
for i, x in enumerate(aji_abs):
    if x < min_tmp:
        min_tmp = x
        indx = i

ans = sum(aji)
ans -= (aji[indx])

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, L = i2nn()
    a = L
    b = L + N - 1
    n = 0
    for i in range(a, b+1):
        n += i
    if a <= 0 and b >= 0:
        n -= 0
    else:
        c = abs(a)
        d = abs(b)
        if c < d:
            n -= a
        else:
            n -= b
    print(n)

main()

Submission status: Accepted

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

# 0を範囲に含む
if L <= 0 and (L + N - 1) >= 0:
    print((2 * L + N - 1) * N // 2)
    exit()

# 全部自然数
if L > 0:
    print((2 * L + N) * (N - 1) // 2)
    exit()

# 全部負の数
print((2 * L + N - 2) * (N - 1) // 2)

Submission status: Accepted

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

minScore = l

sum = 0
for i in range(1, n + 1):
    score = l + i - 1
    sum += score
    if abs(score) < abs(minScore):
        minScore = score

print(sum - minScore)

Submission status: Accepted

Solution code:
s=input().split()
N,L=int(s[0]),int(s[1])
a=int(N*(L+N/2-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:
# -*- coding: utf-8 -*-

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

wk = 101

for apple in apples:
    if abs(apple) < abs(wk):
        wk = apple
        
print(sum(apples) - wk)

Submission status: Accepted

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


if __name__ == "__main__":
    [n, l] = li()
    sum_taste = (2 * l + n - 1) * n // 2
    if l <= 0 <= l + n - 1:
        print(sum_taste)
    elif l < 0:
        print(sum_taste - (l + n - 1))
    else:
        print(sum_taste - l)

# L, L+1, ..., L+N-1
# (L+L+N-1)*N//2
#

Submission status: Accepted

Solution code:
import math

#n = int(input())
n, l = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)

kotae = 0

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

print(int(kotae))

Submission status: Accepted

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

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

j, k = 0, 99999
for i in range(N):
    if k > abs(T[i]):
        j, k = i, abs(T[i])

print(sum(T) - T[j])

Submission status: Accepted

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

t = [l + i - 1 for i in range(1, n + 1)]
t_min = 9999
for i in t:
    if abs(i) < abs(t_min):
        t_min = i
print(sum(t) - t_min)

Submission status: Accepted

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

aji = []
aji_abs = []
for i in range(1, N+1):
    aji.append(L+i-1)
    aji_abs.append(abs(L+i-1))
eaten = min(aji_abs)
if eaten*(-1) in aji:
    eaten = - eaten

all = sum(aji) - eaten
print(all)

Submission status: Accepted

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

apple = [L + i -1 for i in range(1,N+1) ]
apple.remove(min(apple, key=abs))

print(sum(apple))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
min = 9999999
wa = 0
pm = 'p'
for i in range(1, n+1):
    wa += l+i-1
    if abs(l+i-1) < min:
        min = abs(l+i-1)
        if 0 < l+i-1:
            pm = 'm'
        else:
            pm = 'p'
if pm != 'p':
    print(wa-min)
else:
    print(wa+min)

Submission status: Accepted

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

Submission status: Accepted

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

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

taste.sort()
ans = 0
if 0 in taste:
    ans = sum(taste)
elif taste[0] > 0:
    ans = sum(taste) - taste[0]
else:
    ans = sum(taste) - taste[-1]

print(ans)

Submission status: Accepted

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

x = [L+i-1 for i in range(1, N+1)]
x_abs = [abs(L+i-1) for i in range(1, N+1)]
min_index = x_abs.index(min(x_abs))

x.remove(x[min_index])

print(sum(x))

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
  N, L = map(int, input().split())
  apples = list(range(L, N + L))
  eat = min(apples, key=abs)
  return sum(apples) - eat

print(solve())

Submission status: Accepted

Solution code:
N, L=map(int, input().split())
a=list(range(L, N+L))
if min(a)>=0:
    b=min(a)
elif max(a)<=0:
    b=max(a)
else:
    b=0
print(sum(a)-b)

Submission status: Accepted

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

N, L = map(int, input().split())
m = [None] * N

for i in range(N):
    m[i] = L + i
    
a = 10 ** 18
index = 0
for i in range(N):
    t = abs(sum(m) - (sum(m) - m[i]))
    
    if a > t:
        a = t
        index = i
        
ans = 0
for i in range(N):
    if i != index:
        ans += m[i]
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

tlist=[]
for i in range(N):
  tlist.append(L+i)
  
#print(tlist)
sum_all = sum(tlist)
min_diff = 10000
aji = 0
for i in range(N):
  ringo = tlist[i]
  sum_min1 = sum_all-ringo
  
  if abs(sum_all-sum_min1) < min_diff:
    min_diff = abs(sum_all-sum_min1)
    aji = sum_min1
    
print(aji)

Submission status: Accepted

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

eat = abs_aji.index(min(abs_aji))
print(sum(aji) - aji[eat])

Submission status: Accepted

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

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

if (0 < l):
    print(s - l)
elif (l+n-1 < 0):
    print(s- (l + n - 1))
else:
    print(s)

Submission status: Accepted

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

aji = [L + i + 1 - 1 for i in range(N)]
saishouzettai = 999999
for v in aji:
    if abs(v) < abs(saishouzettai):
        saishouzettai = v

print(sum(aji)-saishouzettai)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
Min = L
Max = L + N - 1
answer = L*N
for x in range(N):
    answer += x
if Min > 0:
        answer -= L
else:
    if Max < 0:
        answer -= Max
print(answer)

Submission status: Accepted

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

taste = [l + i for i in range(n)]
abs_taste = [abs(i) for i in taste]
min_idx = abs_taste.index(min(abs_taste))
print(sum(taste) - taste[min_idx])

Submission status: Accepted

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

Submission status: Accepted

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

t = []
for i in range(n):
    t.append(i+l)
max = sum(t)

d = 10**9
ans = 0
for i in range(n):
    if d >= abs(max-(max-t[i])):
        ans = max-t[i]
        d = abs(max-(max-t[i]))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

arr = np.array(range(n)) + l
arr_abs = abs(arr)
a = np.argmin(arr_abs)
lst = list(arr)
lst.pop(a)
print(sum(lst))

Submission status: Accepted

Solution code:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

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

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

ans = sum(L)
L1 = list(filter(lambda x: x >= 0, L))
L2 = list(filter(lambda x: x < 0, L))

if len(L2) == 0:
    ans -= min(L1)
elif len(L1) == 0:
    ans -= max(L2)
else:
    if abs(min(L1)) < abs(max(L2)):
        ans -= min(L1)
    else:
        ans -= min(L2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split(' '))
ans = 300
flag = True
total = 0
for i in range(1,N+1):
    tmp = L+i-1
    if ans>abs(tmp):
        ans = abs(tmp)
        if tmp>=0:
            flag = True
        else:
            flag = False
    total += tmp

if flag:
    total -= ans
else:
    total += ans
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
import math
N ,L= map(int, input().split())
applesum=(L+L+N-1)*N//2
if 0 >= L and L+N-1 >= 0:
	print(applesum)
elif 0 > L+N-1 :
	print(applesum-L-N+1)
else:
	print(applesum-L)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
x = 1000
a = 0
for i in range(1, n + 1):
    xi = l + i - 1
    if abs(x) > abs(xi):
        x = xi
    a += xi
print(a - x)

Submission status: Accepted

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

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

tmp = 1000000
for i in range(N):
    if abs(arr[i]) < tmp:
        tmp = abs(arr[i])
        ans = i

print(sum(arr) -  arr[ans])

Submission status: Accepted

Solution code:
n,l=map(int, input().split())
ll = sorted(list(map(lambda x: x+l-1, list(range(1,n+1)))))
tmp, ind = 10 ** 8, 10 ** 8
for i, ringo in enumerate(ll):
    if abs(ringo) < tmp:
        ind = i
        tmp = abs(ringo)
ll.pop(ind)
print(sum(ll))

Submission status: Accepted

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

s = sum(range(L, L+N))
LL = L + N - 1
if L >= 0:
    print(s - L)
elif L < 0 and LL >= 0:
    print(s)
elif L < 0 and LL < 0:
    print(s - LL)

Submission status: Accepted

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - B

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

psum = 0
pmin = 1000

for i in range(n):
    wkl = l + i
    psum += wkl
    if abs(wkl) < pmin:
        pmin = abs(wkl)
        pmin_v = wkl

psum -= pmin_v

# Output
print(psum)

Submission status: Accepted

Solution code:

def debug(*args):
    import sys
    print(*args, file=sys.stderr)

def solve(N, L):
    A = [0] * N
    for i in range(1, N+1):
        A[i-1] = L+i-1

    m = float("inf")
    debug(A)
    for i in range(0, N):
        res = sum(A[:i]) + sum(A[i+1:])
        t = abs(sum(A) - sum(A[:i]) - sum(A[i+1:]))
        #debug("i=%d"%i, "t=%d"%t, A[i], A[:i], A[i+1:], "res:%d"%res)
        if t < m:
            m = t
            ans = sum(A[:i]) + sum(A[i+1:])
    return ans

def main():
    N, L = [int(x) for x in input().split()]
    print(solve(N, L))

main()

Submission status: Accepted

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

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)]
apples_minus = sorted([x for x in apples if x <= 0], reverse=True)
apples_minus.append(-10 ** 8)
apples_plus = sorted([x for x in apples if x >= 0])
apples_plus.append(10 ** 8)
eat = 0
if abs(apples_minus[0]) <= abs(apples_plus[0]):
    eat = apples_minus[0]
else:
    eat = apples_plus[0]
print(sum(apples) - eat)

Submission status: Accepted

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

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

if 0 in apples:
  print(sum(apples))
elif apples[0] > 0:
  print(sum(apples[1:]))
else:
  print(sum(apples[:-1]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


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

    

def main():
    
    tot = 0
    for i in range(1,N+1):
        tot+=L+i-1
    
    if L >= 0:
        tot -= L
    else:
        if N >= 1-L:
            pass
        else:
            tot -= L+N-1
    print(tot)
          
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

min_apple_abs = 10000
min_apple = 10000
for a in apples:
    if abs(a) < min_apple_abs:
        min_apple_abs = abs(a)
        min_apple = a

pie = sum(apples)
_pie = pie - min_apple

print(_pie)

Submission status: Accepted

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

ls = []

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

s = sum(ls)

if 0 in ls:
    print(s)
elif L < 0:
    print(s - ls[N - 1])
else:
    print(s - ls[0])

Submission status: Accepted

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

ans = 9999999999

for a in A:
  if abs(a) < abs(ans):
    ans = a
    
print(sum(A) - ans)