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: Wrong Answer

Solution code:
sowa=0
hajime=[]

for x in input().split(" "):
    hajime.append(int(x))

if hajime[1]>0:
    i=2
    while i<=hajime[0]:
        sowa+=hajime[1]+i-1
        i+=1

elif hajime[1]==0:
    i=1
    while i<=hajime[0]:
        sowa+=hajime[1]+i-1
        i+=1

else:
    if hajime[0]+hajime[1]+1>=0:
        i=1
        while i<=hajime[0]:
            sowa+=hajime[1]+i-1
            i+=1
    else:
        i=1
        while i<=hajime[0]-1:
            sowa+=hajime[1]+i-1
            i+=1

print(sowa)

Submission status: Wrong Answer

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

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

p = sum(t)

print(p - l)

Submission status: Wrong Answer

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

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

else:
    if N%2==0 :
        X=L+L+N-1

    else:
        X=L+L+N-1

print(X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def input_nums():
    return [ int(i) for i in input().split(" ") ]

nums = input_nums()

N = nums[0]
L = nums[1]

sum = 0
min = 10000
for i in range(N):
    n = (L+i+1) -1
    sum += n
    if(abs(n) < min):
        min = abs(n)

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

print(sum)

Submission status: Wrong Answer

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

    if sum(S) - j > 0:
        plu = True
    if sum(S) - j < 0:
        mini = True
if plu and mini:
    if 0 in ans:
        print(p[ans.index(0)])
    else:
        print(p[ans.index(min(ans))])       
elif plu:
    print(p[ans.index(max(ans))])
elif mini:
    print(p[ans.index(min(ans))])

Submission status: Wrong Answer

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: Wrong Answer

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

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

aji_list = sorted(aji_list)
aji_list = set(aji_list)

aji_list.remove(min(aji_list))

print(sum(aji_list))

Submission status: Wrong Answer

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

find = 10**9
for i in x:
    if abs(i)<find:
        find = i

print(s-find)

Submission status: Wrong Answer

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

    if sum(S) - j > 0:
        plu = True
    if sum(S) - j < 0:
        mini = True
if plu and mini:
    if 0 in ans:
        print(p[ans.index(0)])
    else:
        print(p[ans.index(max(ans))])       
elif plu:
    print(p[ans.index(max(ans))])
elif mini:
    print(p[ans.index(min(ans))])

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
l = []
absn = N + L
for i in range(0, N):
    l.append(i + L)
    absn = abs(i + L) if abs(i + L) < absn else absn

print(sum(l) - absn)

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
li = [l + i for i in range(n)]
if 0 <= l:
    print(sum(li[1:]))

else:
    if 0 <= n + l:
        print(sum(li))
    else:
        print(sum(li) + abs(n + l - 1))

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:
import collections
import itertools
N ,L = map(int,input().split())
tase = []
tmp = L
for i in range(N):
    tase.append(tmp)
    tmp += 1
tmp=0
result = []
for balls in itertools.combinations(tase,N-1):
    for i in range(len(balls)):
        tmp +=balls[i]
        result.append(tmp)
    tmp = 0
print(max(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 < 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: Wrong Answer

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

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

if l > 0:
    print(a-l)
elif n + l >= 0:
    print(a)
else:
    print(a-(n+l)+1)

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
aji = []
for i in range(n):
    aji.append(l+i)
sum_aji = sum(aji)
min_diff = float("inf")
ans = 0
for s in aji:
    if abs(s) < min_diff:
        ans = sum_aji-s
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n,l = map(int,input().split())
num = 1
sa = l+1-1
for i in range(1,n+1):
    if (l+i-1)**2 < sa**2:
        num = i

sum = 0
for i in range(1,n+1):
    if i != num:
        sum += l+i-1

print(str(sum))

Submission status: Wrong Answer

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

aji = []
for a in L:
    aji.append(sum(L)-a)
aji2 = []
for i in range(len(L)):
    aji2.append(abs(aji[i]-sum(L)))

m = 10*7
ans = 1
for i in range(len(L)):
    if m > abs(aji[i]-sum(L)):
        m = min(abs(aji[i]- sum(L)), m)
        ans = aji[i]

print(ans)

Submission status: Wrong Answer

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 + 1
    print(m)

Submission status: Wrong Answer

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):
    if abs(min_l) > max_l:
        ans = sum(l_list) - max_l
    elif abs(min_l) < max_l:
        ans = sum(l_list) - min_l
    elif abs(min_l) == max_l:
        ans = sum(l_list)
print(ans)

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    n, l = map(int, input().split())
    a = [i for i in range(l, l+n)]
    if l < 0 and abs(l) <= n:
        print(sum(a))

    elif l < 0 and abs(l) > n:
        print(sum(a)-max(a))
    else:
        print(sum(a)-min(a))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in azi:
    if abs(i) < mini:
        mini = i
azi.remove(mini)
print(sum(azi))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = 0
tmp = 0
L = [0]*n

for i in range(1,n+1):
    N += l+i-1
    L[i-1] = l+i-1
    
for i in range(1,n+1):
    tmp = max(N-L[i-1],tmp)

print(tmp)

Submission status: Wrong Answer

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

true_pie = (2 * L + N - 1) * N // 2
min_diff = true_pie
answer = None
for i in range(1, N + 1):
    apple = L + i - 1
    pie = (2 * L + N - 1) * N // 2 - apple
    diff = abs(true_pie - pie)
    
    if diff <= min_diff:
        min_diff = diff
        answer = pie

print(answer)

Submission status: Wrong Answer

Solution code:
lm = []
N,L = input().split()
N = int(N)
L = int(L)
for x in range(N):
    lm.append((abs(L+x-1),L+x-1))
lm.sort(reverse=True)
lm = lm[1::]
s = 0
for u in range(len(lm)):
    s = s + lm[u][1]
print('{}'.format(s))

Submission status: Wrong Answer

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<0 and N+L>=0) else (sum(lst) - max(lst)) )

Submission status: Wrong Answer

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

    if sum(S) - j > 0:
        plu = True
    if sum(S) - j < 0:
        mini = True
if plu and mini:
    if 0 in ans:
        print(p[ans.index(0)])        
elif plu:
    print(p[ans.index(max(ans))])
elif mini:
    print(p[ans.index(min(ans))])

Submission status: Wrong Answer

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

find = 10**9
for i in x:
    if abs(i)<find:
        find = i

print(s-i)

Submission status: Wrong Answer

Solution code:
N,L = map(int,input().rstrip().split(' '))
apple_pie = 0
ex = abs(L * N)
apple = []
for i in range(N):
    a = L + i 
    apple.append(a)
    apple_pie += a
apple = map(abs,apple)
for i in apple:
    if ex > i:
        ex = i
apple_pie-= ex
print(apple_pie)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

absol = []
for i in summer:
    absol.append(sum(summer) - i)

if max(absol) < 0:
    print(min(absol))
elif 0 in absol:
    print(0)
else:
    print(max(absol))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

#すべて正の数の場合：最小の値を除けば良い
if l > 0:
    for i in range(n-1):
        ans += l + i + 1
#すべて負の数の場合：最大の値を除けば良い
elif l + n < 0:
    for i in range(n-1):
        ans += l + i
#０を含む場合：０を除けば良い
else:
    for i in range(n):
        ans += l + i

print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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)
    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: Wrong Answer

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

def get_score(n):
    return L + n

score_total = 0
# select the apple to eat
for i in range(N):
    score_ = get_score(i)
    score_total += score_

if L >= 0:
    score_min = score_total - L
elif (L < 0) and (L + N < 0):
    score_min = score_total - get_score(N-1)
else:
    score_min = score_total
print(score_min)

Submission status: Wrong Answer

Solution code:

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

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

taste = 0


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: Wrong Answer

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

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

Submission status: Wrong Answer

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

apple_pi = sum(taste)

diff = 0
idx = 0
for i in range(N):
    if i == 0:
        diff = (apple_pi - (apple_pi - taste[i])) ** 2
        idx = i
    else:
        tmp = (apple_pi - (apple_pi - taste[i])) ** 2
        if diff > tmp:
            idx = i
print "{0}".format(apple_pi - taste[idx])

Submission status: Wrong Answer

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

true_pie = (2 * L + N - 1) * N // 2
min_diff = true_pie
answer = None
for i in range(1, N + 1):
    apple = L + i - 1
    pie = (2 * L + N - 1) * N // 2 - apple
    diff = abs(true_pie - pie)
    
    if diff < min_diff:
        min_diff = diff
        answer = pie
print(answer)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if erase_apple == N:
  erase_apple = N-1
  
print(erase_apple)
  
apples = []
for i in range(N):
  apples.append(L+i)

apples.pop(erase_apple)
print(sum(apples))

Submission status: Wrong Answer

Solution code:
# 2019 6/22
# ABC 131 B Bite Eating

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

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

if L >= 0:
    print("%d" % (apple_pie - L))

elif L <= 0 and (L + N - 1) >= 0:
    print(apple_pie)

else:
    print("%d" % (apple_pie - (L + N - 1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N,L = map(int,input().split())
s = []
for i in range(N):
    s.append(L+i)
ans_pre = abs(np.array([s]))
if L + N < 0:
    print(-1*(sum(ans_pre[0])-min(ans_pre[0])))
else:
    print(sum(s)-min(ans_pre[0]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if lis[0] < 0 and lis[N-1] < 0:
  print(sum(lis[:N-1]))
elif lis[0] < 0 and lis[N-1] >= 0:
  print(sum(lis))
elif lis[0] > 0:
  print(sum(lis[1:]))

Submission status: Wrong Answer

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

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


print(sum)

Submission status: Wrong Answer

Solution code:
N,L=map(int,input().split())
val=[L+i for i in range(N)]
print(sum(val)-min(val))

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
z = []
m = []
for i in range(n):
  z += [abs(i + l - 1)]
  m += [i+l-1]
a = -1
ind = 0
for i in m:
  a += 1
  short = 0
  if abs(short) > abs(i):
    short = i
    ind = a
del m[ind]
print(sum(m))

Submission status: Wrong Answer

Solution code:
def input_nums():
    return [ int(i) for i in input().split(" ") ]

nums = input_nums()

N = nums[0]
L = nums[1]

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

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

print(sum)

Submission status: Wrong Answer

Solution code:
import re
s = input()
pattern = ".{2,4}"
if re.search(pattern,s):
        print("Bad")
else:
        print("Good")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n, l = (int(_) for _ in input().split())
mi = 100000
ans = 0

for i in range(n):
    fla = l + i
    if abs(fla) < mi:
        minus = False
        mi = abs(fla)
        if abs(fla) != fla:
            minus = True
    ans += fla

if ans < 0:
    if minus:
        print(ans + mi)
else:
    print(ans - mi)

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
s=n*l+n*(n+1)/2-n
d2=n**2
x=0
for i in range(n):
    s1=s-i-l
    d=abs(s-s1)
    if d<d2:
        d2=d
        x=i
print(int(s-l-x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for i in range(n-1):
  s+=1
print(s+(n-1)*l-num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

apples = []

m = abs(L)
ind = 0

for i in range(N):
    apples.append(L+i)
    if m > abs(L+i):
        m = abs(L+i)
        ind = i
        
apples.remove(apples[i])

print(sum(apples))

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
a = 100
for i in range(l,l+n):
    a = min(a,abs(i))
print(sum(range(l,l+n))-a)

Submission status: Wrong Answer

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

aji = L * (N - 1)
eat = 0
if L < 0 and abs(L) <= N:
  eat = abs(L)
elif L < 0:
  eat = N - 1

for i in range(N):
  if i == eat:
    continue
  aji += i
print(aji)

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
s=n*l+n*(n+1)/2-n
d2=n**2
x=0
for i in range(n):
    s1=s-i-l
    d=abs(s-s1)
    if d<d2:
        d2=d
        x=i
print(s-l-x)

Submission status: Wrong Answer

Solution code:
line = input().split()
n, l = tuple([int(s) for s in line])
v = [0] * n
for i in range(n):
    v[i] = l + i
    
sum_l = sum(v)

if l < 0 and l + n < 0:
    print(sum_l - v[-1])
elif l < 0:
    print(sum_l)
else:
    print(sum_l - v[0])

Submission status: Wrong Answer

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]
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: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,L = input().split()
N = int(N)
L = int(L)
tastes = []
abs_tastes=[]
for i in range(N):
  tastes.append(L + i)
  abs_tastes.append(abs(L+i))
print(sum(tastes)-min(abs_tastes))

Submission status: Wrong Answer

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

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

if L >= 0:
    print(taste_n - L)
elif L < 0 and abs(L) <= N:
    print(taste_n)
else:
    print(taste_n - (L+N-1))

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
s=[]
m = abs(l)
a =0
for i in range(n):
    s.append(i+l)
    if m > abs(s[i]):
        a = i

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

Submission status: Wrong Answer

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

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

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

print(res)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

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

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

Taste.sort()

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

print(ans)

Submission status: Wrong Answer

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



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

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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
l = [i for i in range(l,l+n)]
minus = min(list(map(abs,l)))
minus = minus if minus<0 else -1*minus
print(sum(l)-minus)

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for i in range(n):
  s+=1
print(s+(n-1)*l-num)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N, L = [int(x) for x in stdin.readline().rstrip().split()]

# リンゴiの味は L+i-1
taste = []
for i in range(1, N+1):
    taste.append(L+i-1)

if abs(taste[0]) < abs(taste[-1]):
    print(sum(taste[1:]))
else:
    print(sum(taste[:N-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s = input()

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print("Bad")
        exit()
else:
    print("Good")

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left

class Solution:
    def main(self):
        N, L = map(int, input().split())
        print(list(range(L, L+N)))
        if L <= 0 < L+N:
            print(sum(list(range(L, L+N))))
        elif L + N <= 0:
            print(sum(list(range(L, L+N-1))))
        else:
            print(sum(list(range(L+1, L + N))))


if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

abs_min_taste = 9999
min_i = -1
for i in range(N):
    if abs_min_taste > abs(taste[i]):
        min_i = i
        abs_min_taste = abs(taste[i])

sum_taste = sum(taste)
ans = sum_taste - taste[min_i]

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
totalTaste = 0
tastes = []
minAbs = 9999

for i in range(1, n+1):
    totalTaste += l + i - 1
    tastes.append(l + i - 1)

for i in range(n):
    temp = abs(tastes[i])
    if temp < minAbs:
        minAbs = temp

#print(totalTaste)
#print(tastes)
print(totalTaste - minAbs)

Submission status: Wrong Answer

Solution code:
line = input().split()
n, l = tuple([int(s) for s in line])
v = [0] * n
for i in range(n):
    v[i] = l + i
    
sum_l = sum(v)

if l <= 0 and l + n < 0:
    print(sum_l - v[-1])
elif l <= 0:
    print(sum_l)
else:
    print(sum_l - v[0])

Submission status: Wrong Answer

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

score=[]
for i in range(N):
    score.append(abs(L+i+1-1))
score.remove(min(score))

print(sum(score))

Submission status: Wrong Answer

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