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:
n,l= map(int, input().split())
ans=[l]
b=[]

    
if l > 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1
        print(sum(ans)-ans[0])
if l == 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1    
    print(sum(ans))
    
if l < 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1
    
    for j in range(n-1):
        b.append(abs(ans[j]))
        
    m = min(b)
    print(sum(ans)+m-1)

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
pi = [(L-1+i) for i in range(1, N+1)]
pi_sum = sum(pi)
for i in range(N):  
  diff = abs(pi_sum + pi[i])
  
  if i == 0:
    diff_min = diff
    diff_index = i
  elif diff_min > diff:
    diff_min = diff
    diff_index = i

print(pi_sum - pi[diff_index])

Submission status: Wrong Answer

Solution code:
n, l = map(int,input().split())
num = 0
l1 = []
for i in range(n):
  num += l + i
  print(num)
  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().strip().split())

ringo=[]

for i in range(n):
	ringo.append(l+i)
print(ringo,sum(ringo))
min = abs(ringo[0])
min_num = 0
for i in range(len(ringo)):
	if min > abs(ringo[i]):
		min = abs(ringo[i])
		min_num = i
out = 0
for i in range(len(ringo)):
	if i != min_num:
		out = out + ringo[i]
print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sum = n * (l - 1) + (n * (n + 1)) / 2.0

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

Submission status: Wrong Answer

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

aaa = list(range(L, N + L))
n = sum(aaa)
if L <= 0 and N + L >= 0:
    print(0)
elif n < 0:
    print(n - max(aaa))
else:
    print(n - min(aaa))

Submission status: Wrong Answer

Solution code:
x = input()
x = str(x).split(" ")
x[0] = int(x[0])
x[1] = int(x[1])
if(x[1] >= 0):
  x[0] -= 1
  if(x[0]%2 == 1):
    print( (1+x[0])*int(x[0]/2)+x[0]/2+1 + x[1]*x[0] )
  else:
    print( (1+x[0])*int(x[0]/2) + x[1]*x[0] )
    
elif (x[0] >= x[1]*-1):
  hu = 0
  sei = 0
  x[1] *= -1
  sein = x[0] - x[1] - 1
  if(x[1]%2 == 1):
    hu = (1+x[1])*2+x[1]/2+1
  else:
    hu = (1+x[1])*2
  
  if( sein % 2 == 1):
    sei = (1+sein)*2+sein/2+1
  else:
    sei = (1+sein)*2
  print(int(sei - hu))
  
else:
  x[0] -= 1
  x[1] = -1*x[1] - x[0] +1
  if(x[0]%2 == 1):
    print( -1*( (1+x[0])*int(x[0]/2) + int(x[0]/2)+1 + x[1]*x[0] ) )
  else:
    print( -1 * ( (1+x[0])*int(x[0]/2) + x[1]*x[0] ) )

Submission status: Wrong Answer

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

sum = n * (l - 1) + (n * (n + 1)) / 2.0

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

Submission status: Wrong Answer

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

p = []
pi = []
pi_s = []


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

all_t = sum(p)

for i in range(N):
    pi.append(all_t - p[i])
    pi_s.append(abs(all_t - pi[i]))

# print(p, pi,pi_s)
min_abs = pi_s[0]
ans = 0

for i in range(1,N):
    if min_abs > pi_s[i]:
        min_abs = pi_s[i]
        ans = i
        print(i)

# print(ans,pi[ans],pi_s[ans])

print(pi[ans])

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
n_flavor = []
for i in range(1,n+1):
  flavor = l + i - 1
  n_flavor.append(flavor)
rem_abs = abs(n_flavor[0])
rem = n_flavor[0]
for j in range(1,n):
  if rem_abs >= abs(n_flavor[j]):
    rem = abs(n_flavor[j])
    rem = n_flavor[j]
  else:
    continue
n_flavor.remove(rem)
print(sum(n_flavor))

Submission status: Wrong Answer

Solution code:
import numpy as np

a,b = map(int, input().split())
s_max = b + a -1
s_min = b 
ans = 0 

if s_min > 0 and s_max > 0:
    for i in range(s_min + 1,s_max+1):
        ans += i
           
    print (ans)
elif s_min < 0 and s_max > 0:
    for i in range(s_min,s_max+1):
        ans += i
           
    print (ans)
else:
    for i in range(s_min,s_max):
        ans += i
           
    print (ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum = 0
s = []
k = []
for i in range(1, N+1):
    sum = sum + L + i -1
for i in range(1, N+1):
    if (sum*(L + i -1) >= 0):
        s.append(abs(L + i -1))
        k.append(1)
    else:
        s.append(abs(L + i -1))
        k.append(-1)


a = min(s)
b = s.index(min(s))
print(sum - a*k[b])

Submission status: Wrong Answer

Solution code:
x = input()
x = str(x).split(" ")
x[0] = int(x[0])
x[1] = int(x[1])
if(x[1] >= 0):
  x[0] -= 1
  if(x[0]%2 == 1):
    print( (1+x[0])*int(x[0]/2)+x[0]/2+1 + x[1]*x[0] )
  else:
    print( (1+x[0])*int(x[0]/2) + x[1]*x[0] )
    
elif (x[0] > x[1]*-1):
  hu = 0
  sei = 0
  x[1] *= -1
  sein = x[0] - x[1] - 1
  if(x[1]%2 == 1):
    hu = (1+x[1])*2+x[1]/2+1
  else:
    hu = (1+x[1])*2
  
  if( sein % 2 == 1):
    sei = (1+sein)*2+sein/2+1
  else:
    sei = (1+sein)*2
  print(int(sei - hu))
  
else:
  x[0] -= 1
  x[1] = -1*x[1] - x[0] 
  if(x[0]%2 == 1):
    print( -1*( (1+x[0])*int(x[0]/2) + int(x[0]/2)+1 + x[1]*x[0] ) )
  else:
    print( -1 * ( (1+x[0])*int(x[0]/2) + x[1]*x[0] ) )

Submission status: Wrong Answer

Solution code:
n,l = map(int,input().split())
aji = n*(l-1)+n*(n+1)/2
sa = [abs(aji-(l+i-1))for i in range(1,n+1)]
saReal = [aji-(l+i-1)for i in range(1,n+1)]
print(int(saReal[sa.index(max(sa))]))

Submission status: Wrong Answer

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

i = range(a[0])
L = a[1]

x = L+sum(i)-1

d = set()

for b in range(a[0]):
    d.add(abs(b))
c = min(d)
print(x-c)

Submission status: Wrong Answer

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

al = int((L-1)*N + 0.5*N*(N+1))
if L > 0:
    tmp = L
elif L < 0 and abs(N) > abs(L):
    tmp = 0
else:
    tmp = L + N - 1

print(al -tmp)

Submission status: Wrong Answer

Solution code:
x = input()
x = str(x).split(" ")
x[0] = int(x[0])
x[1] = int(x[1])
if(x[1] >= 0):
  x[0] -= 1
  if(x[0]%2 == 1):
    print( (1+x[0])*int(x[0]/2)+x[0]/2+1 + x[1]*x[0] )
  else:
    print( (1+x[0])*int(x[0]/2) + x[1]*x[0] )
    
elif (x[0] > x[1]*-1):
  hu = 0
  sei = 0
  x[1] *= -1
  sein = x[0] - x[1] - 1
  if(x[1]%2 == 1):
    hu = (1+x[1])*2+x[1]/2+1
  else:
    hu = (1+x[1])*2
  
  if( sein % 2 == 1):
    sei = (1+sein)*2+sein/2+1
  else:
    sei = (1+sein)*2
  print(int(sei - hu))
  
else:
  x[0] -= 1
  x[1] = -1*x[1] - x[0] 
  print(x[0])
  print(x[1])
  if(x[0]%2 == 1):
    print( -1*( (1+x[0])*int(x[0]/2) + int(x[0]/2)+1 + x[1]*x[0] ) )
  else:
    print( -1 * ( (1+x[0])*int(x[0]/2) + x[1]*x[0] ) )

Submission status: Wrong Answer

Solution code:
# 190622_sat_B

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

a = []
b = []

for i in range(1, N+1):
    a.append(L+i-1)
    b.append(abs(L+i-1))

# print("a: ", a)
# print("b: ", min(b))

print("answer:", sum(a) - a[b.index(min(b))])

Submission status: Wrong Answer

Solution code:
input=input().split()

N=int(input[0])
L=int(input[1])
taste=0
LA=L
if L>0:
	for i in range(N-1):
		LA+=1
		taste+=LA
		
	print(taste)

elif L<-4:
	for i in range(N-1):
		taste+=LA
		LA+=1
	print(taste)
else:
	for i in range(N-2):
		LA+=1
		taste+=LA
	print(taste)

Submission status: Wrong Answer

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

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

sum_taste = sum(taste)
#print(taste)
min_diff = 10^9
min_diff_sum = 0

for i in range(N):
    diff = abs(sum_taste - taste[i])
    if diff < min_diff:
        min_diff = diff
        min_diff_sum = sum_taste - taste[i]

#print(min_diff)
#print(min_diff_sum)
print(sum_taste - min_diff)
#print(sum_taste - min_diff)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

sum_taste = sum(taste)
print(taste)
min_diff = 10^9
min_diff_sum = 0

for i in range(N):
    diff = abs(sum_taste - taste[i])
    if diff < min_diff:
        min_diff = diff
        min_diff_sum = sum_taste - taste[i]

#print(min_diff)
#print(min_diff_sum)
print(sum_taste - min_diff)
#print(sum_taste - min_diff)

Submission status: Wrong Answer

Solution code:
N,L=map(int,input().split())
x=10000
xx = 10000
c=0
S=0
for i in range(N):
	x=max(x,abs(L+i-1))
	S=S+L+i-1
	if xx != x:
		if L+i-1<0:
			c=1
		else:
			c=0
	xx = x
  
r=S-((-1)**c)*x+S
print(r)

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
azi = sum([i + l - 1 for i in range(1, n)])
u = 100000
for x in range(1, n):
  t = azi - (azi - (l + x -1))
  if t < u:
    u = int(t)
print(u)

Submission status: Wrong Answer

Solution code:
import sys

B, A = map(int, input().split())  # list() を使っても構いません

abs_A=abs(A)
#print (abs_A)

if A > 1:  ##Aは正か否か
    flag=True
else:
    flag=False

result=0
temp=A
for i in range(B):
    result = result + temp
    temp= temp + 1

#print("first result---")
#print(result)

#print("flag---")
#print(flag)

if abs_A > B:
    if flag:
        print(result)
    else:
        result=result-temp+1
        print(result)
else:
    if flag:
        result=result-A
        print(result)
    else:
        print(result)

Submission status: Wrong Answer

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

apple1 = float('inf')
apple2 = -float('inf')
flag = 0
for i in taste:
    if i == 0:
        apple = i
        flag = 0
        break
    elif (apple2 < i < 0):
        apple2 = i
        flag = 1
    elif (0 < i < apple1):
        apple1 = i
        flag = 2
        
if flag == 1:        
    pie = abs(sum(taste) - apple2)
elif flag == 2:
    pie = abs(sum(taste) - apple1)
else:
    pie = abs(sum(taste) - apple)
    
print(pie)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum = n * (l - 1) + (n * (n + 1)) / 2.0

s = []

for i in range(1, n+1):
    s.append(abs(l + i - 1))

pos = s.index(min(s))
print(int(sum - s[pos]))

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
pi = [(L-1+i) for i in range(1, N+1)]
pi_sum = sum(pi)
for i in range(N):  
  diff = abs(pi_sum - pi[i])
  
  if i == 0:
    diff_min = diff
    diff_index = i
  elif diff_min > diff:
    diff_min = diff
    diff_index = i
print(pi_sum - pi[diff_index])

Submission status: Wrong Answer

Solution code:
x = input()
x = str(x).split(" ")
x[0] = int(x[0])
x[1] = int(x[1])
if(x[1] >= 0):
  x[0] -= 1
  if(x[0]%2 == 1):
    print( (1+x[0])*int(x[0]/2)+x[0]/2+1 + x[1]*x[0] )
  else:
    print( (1+x[0])*int(x[0]/2) + x[1]*x[0] )
    
elif (x[0] > x[1]*-1):
  hu = 0
  sei = 0
  x[1] *= -1
  sein = x[0] - x[1] - 1
  if(x[1]%2 == 1):
    hu = (1+x[1])*2+x[1]/2+1
  else:
    hu = (1+x[1])*2
  
  if( sein % 2 == 1):
    sei = (1+sein)*2+sein/2+1
  else:
    sei = (1+sein)*2
  print(int(sei - hu))
  
else:
  x[0] -= 1
  x[1] = -1*x[1] - x[0] + 1
  print(x[0])
  print(x[1])
  if(x[0]%2 == 1):
    print( -1*( (1+x[0])*int(x[0]/2) + int(x[0]/2)+1 ) )
  else:
    print( -1 * ( (1+x[0])*int(x[0]/2) + x[1]*x[0] ) )

Submission status: Wrong Answer

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

s = l - 1 
t = 0
for i in range(1, n+1):
    t += (i + s)
if (s <= 0) and (abs(s) <= n) :
    print(t)
elif s >= 0:
    print(t - (s + 1))
else:
  	print(t - ( s + n))

Submission status: Wrong Answer

Solution code:
num, l = map(int, input().split())
sum = 0
for i in range(1, num + 1):
    sum += i

all_pie = num * l + sum - num
if l >= 0:
    print(all_pie - l)
elif abs(l) <= num:
    print(all_pie)
else:
  print(all_pie - (l + num - 1))

Submission status: Wrong Answer

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

sum = n * (l - 1) + (n * (n + 1)) / 2.0

s = []

for i in range(1, n+1):
    s.append(abs(l + i - 1))

pos = s.index(min(s))
print(sum - s[pos])

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
pi = [(L-1+i) for i in range(1, N+1)]
pi_sum = sum(pi)
for i in range(N):  
  diff = abs(pi_sum - pi[i])
  
  if i == 0:
    diff_min = diff
    diff_index = i
  elif diff_min > diff:
    diff_min = diff
    difff_index = i
print(pi_sum - pi[diff_index])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = l - 1 
t = 0
for i in range(1, n+1):
    t += (i + s)
if (s <= 0) and (abs(s) <= n) :
    print(t)
elif s >= 0:
    print(t - 1)
else:
  	print(t - ( s + n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,l=map(int,input().split())
m=100
s=10000
Q=0

for i in range(1,n+1):
    if m>abs(l+i-1):
        m=abs(i+l-1)
        s=i
    Q=Q+i

Q=Q+(n-1)*(l-1)-s

print(Q)

Submission status: Wrong Answer

Solution code:
line = input().strip()
N,K = line.split(" ")
N = int(N)
K = int(K)
result = 0

flavors = [K + i for i in range(N)]
if 0 in flavors: result = sum(flavors)
else:
    min_data = min(flavors)
    result = sum(flavors) - min_data

print(result)

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-1))
else:
  print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
x = 3
y = -1
A = []

for i in range(x):
    A.append(y)
    y += 1

B = np.abs(A)

we = min(B)

A.remove(we)
cnt = 0
for i in A:
    v = int(i)
    cnt += v

print(cnt)

Submission status: Wrong Answer

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

al = (L-1)*N + 0.5*N*(N+1)
if L > 0:
    tmp = L
elif L < 0 and abs(N) > abs(L):
    tmp = 0
else:
    tmp = L + N - 1
print(int(al - tmp))

Submission status: Wrong Answer

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

apple1 = float('inf')
apple2 = -float('inf')
flag = 0
for i in taste:
    if i == 0:
        apple = i
        break
    elif (apple2 < i < 0):
        apple2 = i
        flag = 1
    elif (0 < i < apple1):
        apple1 = i
        flag = 2
if flag == 1:        
    pie = abs(sum(taste) - apple2)
elif flag == 2:
    pie = abs(sum(taste) - apple1)
else:
    pie = abs(sum(taste) - apple)
    
print(pie)

Submission status: Wrong Answer

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

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 = abs(c)
print(sum - min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

a,b = map(int, input().split())
s_max = b + a -1
s_min = b 
ans = 0 

if s_min > 0 and s_max > 0:
    for i in range(3,s_max+1):
        ans += i
           
    print (ans)
elif s_min < 0 and s_max > 0:
    for i in range(s_min,s_max+1):
        ans += i
           
    print (ans)
else:
    for i in range(s_min,s_max):
        ans += i
           
    print (ans)

Submission status: Wrong Answer

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())

n,l = Is()
lis = []
minus = False
m = 10**10
for i in range(l,n+l):
    lis.append(i)
if 0 in range(l,n+l):
    print(sum(lis))
elif n+l < 0:
    print(sum(lis) - (n+l-1))
else:
    print(sum(lis) - l)

Submission status: Wrong Answer

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


pie = 0
ans = 10**9

for i in range(1,N+1):
  pie += L + i - 1
  
if L >= 1:
  ans = pie - L
elif abs(L) <= N:
  ans = pie
else:
  ans = pie - (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())

taste_lst = []
for i in range(n):
    taste = l + i
    taste_lst.append(taste)

sm = sum(taste_lst)
ans = 0

if sm > 0:
    ans = sm - min(taste_lst)
elif sm < 0:
    ans = sm - max(taste_lst)
else:
    pass

print(ans)

Submission status: Wrong Answer

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

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

s = sum(apple)

m = 1000000000000000000
for x in apple:
  if abs(m) > abs(x):
    m = abs(x)

print(s-x)

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
pi = [(L-1+i) for i in range(1, N+1)]
pi_sum = sum(pi)
for i in range(N):  
  diff = abs(pi_sum - pi[i])
  if 0 == 0:
    dif_minn = diff
    diff_index = i
  elif diff_min > diff:
    diff_min = diff
    difff_index = i

print(pi_sum - pi[diff_index])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

if l>0:
  print(N-tmp)
else:
  print(-(N-tmp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum = 0

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

elif abs(L) <= N:
    for i in range(N):
        sum += int(i) + L

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

print(sum)

Submission status: Wrong Answer

Solution code:
N , X =map(int,input().split())
sums = []
i = X
result =[]
a = []
for i in range(N):
    sums.append(i+X)
for j in range(N):
    a.append(abs(sums[j]))

print(sum(sums) - min(a))

Submission status: Wrong Answer

Solution code:
n,l = list(map(int,input().split()))
apple = []
for i in range(n):        apple.append(l+i)
if 0 in apple:
        print(sum(apple))
elif n+l < 0:
        print(sum(apple)-apple[len(apple)-1])
else:
        print(sum(apple[1:len(apple)+1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,L=input().split( )
a=0
b=0
c=0
d=1
if int(L)>=0:
    for n in range(int(N)-1):
        a=a+int(L)+(n+2)-1
else:
    while True:
        b=c+int(L)+(d)-1
        if b>=0:
            break
        c=b
        d=d+1
    if b>abs(c):
        e=d
    else:
        e=d-1
    for m in range(int(N)):
        a=a+int(L)+(m+1)-1
    a=a-int(L)-e+1
print(a)

Submission status: Wrong Answer

Solution code:
n,l = list(map(int,input().split()))
apple = []
for i in range(n):        apple.append(l+i)
print(apple)
if 0 in apple:
        print(sum(apple))
elif n+l < 0:
        print(sum(apple)-apple[len(apple)-1])
else:
        print(sum(apple[1:len(apple)+1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().strip()
N,K = line.split(" ")
N = int(N)
K = int(K)
result = 0

flavors = [K + i - 1 for i in range(N)]
if 0 in flavors: result = sum(flavors)
else:
    min_data = min(flavors)
    result = sum(flavors) - min_data

print(result)

Submission status: Wrong Answer

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

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

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

print( result)

Submission status: Wrong Answer

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

s=b-1
m=0

r=0

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

print(s,m)

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

print(r-m)

Submission status: Wrong Answer

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

min = abs(taste[0])
sum = taste[0]
index = 0
for i in range(1, N):
    if abs(taste[i]) < min: 
        index = i
    sum += taste[i]
sum = sum - taste[index]
print(sum)

Submission status: Wrong Answer

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

apple1 = 10 ** 8
apple2 = -(10 ** 8)
for i in taste:
    if i == 0:
        apple = i
        break
    elif (apple2 < i < 0) or (0 < i < apple1):
        apple = i
        
pie = abs(sum(taste) - apple)
    
print(pie)

Submission status: Wrong Answer

Solution code:
N , X =map(int,input().split())
sums = []
i = X
result =[]
a = []
for i in range(N):
    sums.append(i+X)
for j in range(N):
    a.append(abs(sums[j]))

print(sum(sums) - min(a) * 2)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
min = L + N
ans = 0
for n in range(1, N+1):
    tmp = L+n-1
    ans += tmp
    if abs(min) > abs(tmp):
        min = tmp

print(ans-min)

Submission status: Wrong Answer

Solution code:
N,L=input().split()
N=int(N)
L=int(L)
A=0
B=[]
for j in range(1,N+1):
    A+=L+j-1
for i in range(1,N+1):
    B.append(A-(L+i-1))
print(max(B))

Submission status: Wrong Answer

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

rng = list(range(l, l+n))
min_abs = abs(l + n)
val = 0
for r in rng:
  if min_abs > abs(r):
    min_abs = abs(r)
    val = r

print(sum(rng) - val)

Submission status: Wrong Answer

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

sum = 0

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

elif abs(L) <= N:
    for i in range(N):
        sum += int(i) + L

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

print(sum)

Submission status: Wrong Answer

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

taste_lst = []
for i in range(n):
    taste = l + (i+1) - 1
    taste_lst.append(taste)

sm = sum(taste_lst) 
ans = 0
for i in taste_lst:
    if sm > 0:
        ans = sm - min(taste_lst)
    elif sm < 0:
        ans = sm - max(taste_lst)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

apple_azi = [L + (x + 1) - 1 for x in range(N)]

original_pai = sum(apple_azi)

# tabeta_azi = [abs(original_pai - i) for i in apple_azi]

if original_pai > 0:
    tabeta_azi = min(apple_azi)
elif original_pai == 0:
    tabeta_azi = 0
else:
    tabeta_azi = max(apple_azi)

print(sum(apple_azi) - tabeta_azi)

Submission status: Wrong Answer

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


total = []
for i in range(1,n+1):
  total.append(l+i-1)
total2 = sum(total)

if n <= 1:
    print(0)
elif l >= 0:
  print(total2-l)
elif abs(l) <= n:
  print(total2)
elif abs(l) > n:
  print(total2 - (l+n-1))

Submission status: Wrong Answer

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

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

minimum_value = 0
for v in value_list:
    tmp_value = total_value - v
    if abs(total_value - tmp_value) == 0:
        minimum_value = tmp_value
        break
    if abs(total_value - tmp_value) >= minimum_value:
        minimum_value = tmp_value

print(minimum_value)

Submission status: Wrong Answer

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

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

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

print( result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

apples = [0] * N

ate_apple = 100
apple_pie = 0

for i in range(N):
  apples[i] = L + i
  apple_pie += apples[i]
  if ate_apple > apples[i]:
    ate_apple = apples[i]

print(apple_pie - (ate_apple * 2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, L = map(int,input().split())
taste = []
ans = 0
d = 1000
for i in range(1,N+1):
  ans += L+i-1
  d = min(abs(L+i-1), d)
print(ans - d)

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
aji = []
ans = 0
for i in range(1, n+1):
    aji.append(l + i - 1)
aji_sum = sum(aji)
sa = 1000000007
for i in range(n):
    tmp = aji[i]
    del aji[i]
    if abs(sum(aji) - aji_sum) <= sa:
        sa = abs(sum(aji) - aji_sum)
        ans = sum(aji)
    aji.insert(tmp, i)
print(ans)

Submission status: Wrong Answer

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

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

sum_taste = sum(taste)
diff = []
#print(sum_taste)

for i in range(N):
    diff.append(abs(taste[i] - sum_taste))

#print(taste)
#print(diff)
print(diff[diff.index(max(diff))])

Submission status: Wrong Answer

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