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:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans=0
x=[]
y=[]

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

allapples = sum(apples)

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

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

T = [L + x for x in range(N)]
# print(N, L, T)
candidate = sum(T)
# print(candidate)
ans = 100000000
index = 0
for i in range(N):
   t = candidate - (L + i)
   d = abs(candidate - t)
   if d <= ans:
        index = i
        ans = d

# print(candidate, index)
print(candidate - (L + index))
# if L < 0 and L + N >= 0:
#     print(candidate)
# elif L + N - 1 <= 0:
#     print(candidate - (L + N - 1))
# else:
#     print(candidate - (L))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans = sum(ls) - m

print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())
# ##############
mod = 1e9+7
n,l = ip()
ans = 0
k=abs(l)
for i in range(l,l+n):
    ans+=i
    if abs(i) < abs(k):
        k = i
ans -= k
print(ans)

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

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

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

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

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

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

mymath = mymath()

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

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

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

    sabun = 1145141919
    ans = 0

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

        if a < sabun:
            sabun = a
            ans = pi

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

Submission status: Accepted

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

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

print(round(ans))

Submission status: Accepted

Solution code:
N, L=map(int,input().split())
tar=0
for i in range(N):
    tar += L + i
ANS = []
for i in range(N):
    ANS.append(tar - (L + i))
ans = 1000000
tmp2 = 1000000
for a in ANS:
    tmp = abs(tar - a)
    if tmp < tmp2:
        ans = a
        tmp2 = tmp
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

sum = (N * (2 * L + (N-1))) / 2

X = np.arange(L, L+N)
X_sum = abs(sum - (sum-X))
print(int(sum - X[X_sum == min(X_sum)]))

Submission status: Accepted

Solution code:
#B問題
N, L =map(int,input().split())
apple =  [i+1 for i in range(N)]
apple_taste = [L+i-1 for i in apple]
delete = min(apple_taste)
if delete < 0:
    abs_apple_taste = [abs(L+i-1) for i in apple]
    delete = -min(abs_apple_taste)
apple_taste.remove(delete)
print(sum(apple_taste))

Submission status: Accepted

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


def min_abs(ts):
    if ts[0] <= 0 and ts[-1] >= 0:
        return 0
    if ts[-1] <= 0:
        return ts[-1]
    else:
        return ts[0]


def solv(n, l1):
    ts = list(range(l1, l1+n))
    eat = min_abs(ts)
    return sum(ts) - eat


if __name__ == '__main__':

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

    ans = solv(n, l1)

    print(ans)

Submission status: Accepted

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

total = ((m)+(m+n-1))*n/2

min_abs = 101
min = 0
for i in range(n):
  now = abs(m + i)
  if now < min_abs:
    min_abs = now
    min = m + i

if total > 0:
    if min > 0:
        min_total = int(total - min)
    else:
        min_total = int(total + min)
else:
    if min > 0:
        min_total = int(total + min)
    else:
        min_total = int(total - min)
    

print(min_total)

Submission status: Accepted

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

T = []

for i in range(N):
    T.insert(i, L+i-1+1)

for i in range(101):
    if T.count(i) != 0:
        T.remove(i)
        break
    elif T.count(-i) != 0:
        T.remove(-i)
        break

print(sum(T))

Submission status: Accepted

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

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

print(S)

Submission status: Accepted

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

absaji = []
for i in range(N):
    absaji.append(abs(aji[i]))

#newaji = np.abs(aji)
minaji = min(absaji)

if sum(aji) < 0:
    sumaji = sum(aji) + minaji
else:
    sumaji = sum(aji) - minaji
print(sumaji)

Submission status: Accepted

Solution code:
import numpy as np

def main():

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

min_apple = 10**10
ans = 0
index = 0
for i in range(1, n+1):
    ans += l+i-1
    min_apple = min(abs(l+i-1), min_apple)
    index = i
    if min_apple > abs(l+i-1):
        min_apple = min(abs(l+i-1), min_apple)
        index = i
print(ans - min_apple if l+index-1>0 else ans + min_apple)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
s = list(range(1,n+1))
azi = []
ab = 100
for i in range(n):
    azi.append(l + i)
    if abs(ab) > abs(l + i):
        ab = l + i

print(sum(azi)-ab)

Submission status: Accepted

Solution code:
import numpy as np

def main():
    nl = list(map(int, input().split(" ")))
    apple = list(range(nl[1], nl[0]+nl[1]))
    mi = np.array(list(map(abs, apple)))
    index = np.argsort(mi)

    s = 0
    for i in index[1:]:
        s += apple[i]
    print(s)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = input().split(" ")
n = int(a[0])
l = int(a[1])
m = 0
if l >= 0:
    for i in range(n - 1):
        m += l + i + 1
    print(m)
elif l + n - 1 >= 0:
    for i in range(n):
        m += l + i
    print(m)
else:
    for i in range(n - 1):
        m += l + i
    print(m)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = [i + l for i in range(n)]
a_abs = list(map(abs, a))
min_i = a_abs.index(min(a_abs))
min = a[min_i]
print(sum(a) - a[min_i])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = []
m = 999999999
for i in range(1, N + 1):
    t = L + i - 1
    apples.append(t)
    if abs(m) > abs(t):
        m = t
apples.remove(m)
print(sum(apples))

Submission status: Accepted

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

p=l.index(min(l))
li.pop(p)
print(sum(li))

Submission status: Accepted

Solution code:
import numpy as np

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


N,L=acinput()


aji=L+np.arange(1,N+1)-1
sm=np.sum(aji)

arg=np.argmin(np.abs(aji))
if aji[arg]>=0:
        print(sm-aji[arg])
else:
        print(sm-aji[arg])

Submission status: Accepted

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

if 0 in apple:
    print(sum(apple))
elif apple[0] > 0:
    print(sum(apple) - min(apple))
else:
    print(sum(apple) - max(apple))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
A=[L+i for i in range(N)]
sum = N*(L-1)+(int)(N*(N+1)/2)

eat = 0
tmpabs =101
for i in range(N):
    if abs(A[i])<tmpabs:
        tmpabs =abs(A[i])
        eat = i

print(sum-A[eat])

Submission status: Accepted

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

if 0 in taste:
    ans = sum(taste)
else:
    if min(taste) > 0:
        ans = sum(taste) - min(taste)
    else:
        ans = sum(taste) - max(taste)

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

# 味
LL = np.arange(L,L+N)

m = abs(LL[0])

for i in range(N):
    if abs(m) > abs(LL[i]):
        m = LL[i]

print(np.sum(LL)-m)

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
maxscore = N*(L-1) + N*(N+1)/2
minscore = float("inf")
for i in range(1, N+1):
    if minscore > abs(L - 1 + i):
        minscore = abs(L-1+i)
        keisanyou = L-1+i
print(int(maxscore - keisanyou))

Submission status: Accepted

Solution code:
#ABC131
N,L = map(int,input().split())
f = 0
k = 0
j = []
for i in range(1,N+1):
    f += L+i-1
for i in range(1,N+1):
    k = L+i-1
    n = f-k
    p = abs(f-n)
    j.append(p)
if f >0:
    print(int(f-min(j)))
else:
    print(int(f+min(j)))

Submission status: Accepted

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    tokens = lines[0].split(" ")
    n = int(tokens[0])
    l = int(tokens[1])

    return (n, l)


def solve(n, l):

    min_abs = abs(l)
    removed = l
    sum = 0
    for i in range(l, l+n):
        sum = sum + i
        if abs(i) < min_abs:
            min_abs = abs(i)
            removed = i

    return sum - removed


def main():
    # 出力

    print("%s" % solve(*parse_input()))

#    solve(*parse_input())

if __name__ == '__main__':

    main()

Submission status: Accepted

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

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

tmp = float("inf")
minn = 0
for a in t:
    if abs(a) < tmp:
        minn = a
        tmp = abs(a)
print(sum(t) - minn)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
MAX_INT = sys.maxsize

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

s = 0
eat = MAX_INT
for i in range(N):
    taste = L+i
    if abs(eat) > abs(taste):
        eat = taste
    s += taste

print(s-eat)

Submission status: Accepted

Solution code:
import copy
N,L = map(int,input().split())
flaver = []
for i in range(1,N + 1):
    flaver.append(L + i - 1)
flaver_sum = sum(flaver)
for i in range(len(flaver)):
    c_flaver = copy.deepcopy(flaver)
    del c_flaver[i]
    if i == 0:
        tmp_min = abs(flaver_sum - sum(c_flaver))
        index = i
    if abs(flaver_sum - sum(c_flaver)) < tmp_min:
        tmp_min = abs(flaver_sum - sum(c_flaver))
        index = i
del flaver[index]
print(sum(flaver))

Submission status: Accepted

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

taist = [0] * n
abs_taist = [0] * n
for ii in range(n):
    taist[ii] = (ii + 1) + l - 1
    abs_taist[ii] = abs(taist[ii])

index = abs_taist.index(min(abs_taist))
taist.remove(taist[index])
print(sum(taist))

Submission status: Accepted

Solution code:
N, L = [int(s) for s in input().split()]
apples = [i+L for i in range(N)]
abstaste = [abs(i) for i in apples]
if min(apples) == min(abstaste):
  ans = sum(apples) - min(abstaste)
else:
  ans = sum(apples) + min(abstaste)
print(ans)

Submission status: Accepted

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

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

absol = []
for i in range(len(summer)):
    absol.append(abs(sum(summer) - sum(summer[0:i]) - sum(summer[i+1:len(summer)])))

s = absol.index(min(absol))

print(sum(summer) - summer[s])

Submission status: Accepted

Solution code:
import copy

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

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

#print(taste)

plan = sum(taste)

diff = []
ans = []

for i in range(0, N):
    apples = copy.deepcopy(taste)
    apples.pop(i)
    diff.append(abs(plan - sum(apples)))
    ans.append(sum(apples))
    
#print(diff)
#print(ans)

#print(min(diff))
print(ans[diff.index(min(diff))])

Submission status: Accepted

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

print(int(taste))

Submission status: Accepted

Solution code:
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    N, L = inputs()
    apple = range(L, N + L)
    apple = np.array(apple)
    apple = np.delete(apple, np.argmin(np.abs(apple)))
    return sum(apple)


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

Submission status: Accepted

Solution code:
import numpy as np

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


if 0 in L:
  print(sum(L))
else:
  if min(L) > 0:
    print(sum(L)-min(L))
  else:
    print(sum(L)-max(L))

Submission status: Accepted

Solution code:
lis=list(map(int,input().split()))
taste=[]
for i in range(lis[0]):
    taste.append(lis[1]+i)
if 0 in taste:
    ans=sum(taste)
else:
    big=min(abs(taste[0]),abs(taste[-1]))
    if big==abs(taste[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())
A = []
mn = 10**9
for i in range(N):
    A.append(L+i)
sum_A = sum(A)

for i in range(N):
    aji = sum(A[:i]) + sum(A[i+1:])
    tmp = abs(sum_A - aji)
    if tmp < mn:
        mn = tmp
        ans = aji
print(ans)

Submission status: Accepted

Solution code:
# ABC131
def main():
    n, l = list(map(int, input().rstrip().split()))
    lst = []
    for i in range(1, n + 1):
        lst += [i + l - 1]
    if 0 in lst:
        print(sum(lst))
    else:
        if l > 0:
            print(sum(lst[1:]))
        else:
            print(sum(lst[:-1]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

if L > 0:
  print(sum(range(L+1, L+N)))
elif N + L >0:
  print(sum(range(L, L+N)))
else:
  print(sum(range(L, L+N-1)))

Submission status: Accepted

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

Submission status: Accepted

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

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

if L < 0 and 0 not in A:
  A.remove(A[-1])
  print(sum(A))
elif 0 in A:
  print(sum(A))
elif L >= 0:
  A.remove(A[0])
  print(sum(A))

Submission status: Accepted

Solution code:
import numpy as np

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

apple = [L+i for i in range(N)]
N_tast = sum(apple)
sub = [abs(N_tast-(sum(apple)-apple[i])) for i in range(N)]

print(sum(apple)-apple[sub.index(min(sub))])

Submission status: Accepted

Solution code:
from sys import stdin

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

    apple = [L + i for i in range(N)]
    taste = sum(apple)
    n = float('inf')
    for a in apple:
        if n > abs(a):
            eat = a
            n = abs(a)
    print(taste - eat)

input = lambda: stdin.readline()
main()

Submission status: Accepted

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

saisho=100000000

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

aji=[l+i for i in range(n)]
absaji=[abs(l+i) for i in range(n)]
absaji.sort()
if absaji[0] in aji:
  print(all-absaji[0])
else:
  print(all+absaji[0])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n=input().rstrip().split(" ")
n[0]=int(n[0])
n[1]=int(n[1])
if n[1]>=0:
    terget=0
elif n[1]+n[0]<=0:
    terget=n[0]-1
else:
    terget=-(n[1])
ans=n[1]*(n[0]-1)
#print(ans)
ans=ans+int(n[0]*(n[0]-1)/2)
#print(int(n[0]*(n[0]-1)/2))
print(ans-terget)
#print(terget)

Submission status: Accepted

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

ans = 0
for i in range(1, n + 1):
    ans = ans + (i + l - 1)

s = 1 + l - 1
e = n + l - 1
if e < 0:
    ans = ans - e
elif s > 0:
    ans = ans - s

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, l):
    n_min = 100000
    v_min = n_min
    pre_n_min = 100000
    sum_n = 0
    for i in range(1, n+1):
        n_min = min(n_min, abs(l + i - 1))
        if pre_n_min != n_min:
            pre_n_min = n_min
            v_min = l + i - 1

        # print i, l + i - 1, n_min
        sum_n += (l + i - 1)

    return sum_n - v_min


if __name__ == '__main__':

    n, l = map(int, sys.stdin.readline().strip().split(" "))
    print solve(n, l)

Submission status: Accepted

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

Submission status: Accepted

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

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

# print(list)

tmp=list[0]

rem=0

for i in range(1,N):
  if(abs(tmp)<abs(list[i])):
    rem= tmp
    break
  else:
    tmp= list[i]
  if(i== N-1):
    rem= list[i]

print(sum(list)- rem)

Submission status: Accepted

Solution code:

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

N = NL[0]
L = NL[1]

tasteSUM = 0
tasteABS = 2000

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

    tasteSUM+=taste

    if abs(taste) < abs(tasteABS):
        tasteABS = taste


tasteSUM = tasteSUM - tasteABS

print(tasteSUM)


# if L<0 and (abs(N) < abs(L)):
#     for i in range(N):
#         if i == N-1:
#             continue
#         else:
#             taste += L + (i + 1) - 1
#
# elif L < 0:
#     for i in range(N):
#         taste += L+(i+1)-1
#
#
# else:
#     for i in range(N):
#         if i == 0:
#             continue
#         else:
#             taste += L+(i+1)-1


# print(taste)

Submission status: Accepted

Solution code:
#B
N, L = map(int,input().split())
lb = L
rb = L+N-1
if lb <= 0 <= rb: #ok
    pass
elif rb < 0:
    rb -= 1
elif 0 < lb:
    lb += 1
ans = sum(range(lb,rb + 1))
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, L = [int(n) for n in input().split()]
    arr = [L + (i+1) - 1 for i in range(N)]
    s = sum(arr)
    arr = sorted(arr, key=lambda x: abs(x))
    del arr[0]
    print(sum(arr))

main()

Submission status: Accepted

Solution code:
nl = input().split(' ')
n = int(nl[0])
l = int(nl[1])

taste = 0
judge = True
for i in range(n):
	taste_i = l + (i + 1) - 1 
	if taste_i == 0:
		judge = False
	taste += l + (i + 1) - 1

if judge:
	if taste_i < 0:
		taste = taste - taste_i
	else:
		taste = taste - (l + 1 - 1)

print(taste)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
nl=n+l
ls=[]
for i in range(l,nl):
    ls.append(i)
mn=500
for j in ls:
    if abs(j)<abs(mn):
        mn=j
    else:
        continue
ls.remove(mn)
ans=sum(ls)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


min_aji = 10**9+7
ind = 0
for i in range(n):
    if min_aji > abs(aji[i]):
        ind = i
        min_aji = abs(aji[i])

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
listA = []
for i in range(n):
    listA.append(l+i)
b = 201
c = -1
for j in range(n):
    if abs(listA[j])<b:
        b=abs(listA[j])
        c=j
listA.pop(c)
print(sum(listA))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import copy

N, L = map(int, input().split())
aji = [0]*N
for i in range(1, N+1):
    aji[i-1] = L+i-1
aji_sum = sum(aji)
ansl = [0]*N
for i in range(N):
    aji_tmp = copy.copy(aji)
    aji_tmp.pop(i)
    ansl[i] = abs(aji_sum - sum(aji_tmp))
ans_ind = ansl.index(min(ansl))
aji.pop(ans_ind)
print(sum(aji))

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n, l = map(int, input().split())

    flavors = [ l + i - 1 for i in range(1, n+1)]
    flavor_abs = [ abs(l + i - 1) for i in range(1, n+1)]
    eat = min(flavor_abs)
    del flavors[flavor_abs.index(eat)]

    print(sum(flavors))

Submission status: Accepted

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

a = range(l, l+n)
b = []
for i in a:
  b.append(abs(i))
  
if 0 in a:
  print(sum(a))
elif max(a) < 0:
  print(sum(a)-max(a))
else:
  print(sum(a)-min(b))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
alst = [i + l for i in range(n)]
lst2 = [(i+l)**2 for i in range(n)]
del alst[lst2.index(min(lst2))]
  
print(sum(alst))

Submission status: Accepted

Solution code:
n , l = map(int, input().split())
l_list = [l + i for i in range(n)]
min_l = min(l_list)
max_l = max(l_list)
if max_l <= 0:
    ans = sum(l_list) - max_l
elif min_l >= 0:
    ans = sum(l_list) - min_l
elif (max_l > 0) & (min_l < 0):
    ans = sum(l_list)
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, L = LI()
    per = 0
    for i in range(N):
        per += i + L
    
    cur_min = inf
    ans = inf
    for i in range(N):
        c = i + L
        if abs(c) < cur_min:
            ans = c
            cur_min = abs(c)
    print(per - ans)
main()

Submission status: Accepted

Solution code:
import sys

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

tastes = []
bestAppleIndex = -1
bestAppleTaste = 9999999999

for i in range(0,n):

    tastes.append( l + i + 1 - 1 )

    if abs(bestAppleTaste) > abs(tastes[i]) :
        bestAppleTaste = tastes[i]
        bestAppleIndex = i

tastes[ bestAppleIndex ] = 0

print(sum(tastes))

Submission status: Accepted

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

appletaste = []

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

appletaste.insert(0, 0)

applesum = sum(appletaste)
abslog = 9999
eat = 0

# 総和と１個抜いたパイの味を比べる
for apple in range(1, N + 1):
    pie = applesum - appletaste[apple]
    if abs(applesum - pie) < abslog:
        abslog = abs(applesum - pie)
        eat = apple

print(applesum - appletaste[eat])

Submission status: Accepted

Solution code:
def proc(begin_val, end_val, **keyargs):
  if begin_val * end_val > 0:
    return sum(list(range(begin_val, end_val + 1))) - min(abs(begin_val), abs(end_val)) * end_val // abs(end_val)
  
  if begin_val * end_val <= 0:
    return sum(list(range(begin_val, end_val + 1)))


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

begin_val = L
end_val = L + N - 1

print(proc(**locals()))

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
la = [abs(L+i) for i in range(N)]
min_l = la.index(min(la))
res = 0
for i in range(N):
  if i != min_l:
    res += L+i
print (res)

Submission status: Accepted

Solution code:
parents = list(map(int,input().split(' ')))
L = parents[1]
if L>0:
    not_add = 0
elif abs(L) > parents[0]-1:
    not_add = parents[0]-1
else:
    not_add = abs(L)
sum = 0
for i in range(parents[0]):
    if not i == not_add:
        sum += (i+L)

print(sum)

Submission status: Accepted

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

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

absout = []
for i in outputlist:
  absout.append(abs(i))

a = absout.index(min(absout))

output = sum(outputlist[:a] + outputlist[a+1:])

print(output)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7


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

ans=-1*a
for i in range(1,N+1):
	ans += L+i-1

print(ans)

Submission status: Accepted

Solution code:
n,l= list(map(int,input().split()))
ans = 0
taste_list = []
for i in range(n):
    taste_list.append(l+i)
    ans += (l+i)
if 0 in taste_list:
    print(ans)
else:
    mini = min(taste_list)
    if mini > 0:
        print(ans-mini)
    else:
        mini2 = taste_list[-1]
        print(ans-mini2)

Submission status: Accepted

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

ans = 0
min = min([abs(x + l) for x in range(n)])
if l + n <= 0:
    min = min * -1
for i in range(n):
    ans += l + i

print(ans - min)