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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n, l = MAP()
s = (n - 1) * n // 2 + n * l
arr = []
for i in range(n):
    arr.append([l + i, abs(l + i)])
arr.sort(key=lambda x:x[1])
debug(arr)
debug(s)
print(s - arr[0][0])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste_list = list(range(L, N + L, 1))
print(sum(taste_list) - min(taste_list, key=lambda x: -x if x < 0 else x))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
lis=[]
for i in range(N):
    lis.append(L+i)
if 0 in lis:
    print(sum(lis))
else:
    lis2=sorted(lis)
    ans=sum(lis2[1:-1])
    if lis2[0]/abs(lis2[0])==-1:
        ans+=lis2[0]
    else:
        ans+=lis2[-1]
    print(ans)

Submission status: Accepted

Solution code:
def solve_131b(n, l):
    sum = 0
    min = 100000
    for i in range(1, n+1):
        sum += (l + i - 1)
    
    if l >= 0:
        min = l
    elif l + n - 1 <= 0:
        min = l + n - 1
    else:
        min = 0
    
    return sum - min

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
num = []
for i in range(1, x+1):
    num.append(i+n-1)
if 0 in num:
    print(sum(num))
else:
    ma = max(num)
    mi = min(num)
    if ma < 0:
        print(sum(num)-ma)
    else:
        print(sum(num)-mi)

Submission status: Accepted

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 <= 0 <= l+n-1:
     for i in range(n):
          ans += l+i
else:
     for i in range(n-1):
          ans += l + i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
ans=sum(sorted([L+i for i in range(N)],key=abs)[1:])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,L=map(int, input().split())
taste_list = np.zeros(N)
for i in range(N):
  taste_list[i]=L+i+1-1
taste_sum = sum(taste_list) - taste_list[np.abs(taste_list)==min(np.abs(taste_list))]
print('{:.0f}'.format(taste_sum[0]))

Submission status: Accepted

Solution code:
nim, lima = map(int, input().split())
if lima<=0<=lima+nim-1:
    print(sum(range(lima,lima+nim)))
elif lima<0:
    print(sum(range(lima,lima+nim-1)))
else:
    print(sum(range(lima+1,lima+nim)))

Submission status: Accepted

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

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

if l > 0 and l+n-1 > 0:
    sum = sum - l

elif l < 0 and 0 < l+n-1:
    sum = sum - 0

elif l < 0 and l+n-1 < 0:
    sum = sum - (l+n-1)

print(sum)

Submission status: Accepted

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

R = L + N - 1

eat = 0
if R <= 0:
    eat = R
elif L >= 0:
    eat = L
else:
    eat = 0

ans = (R + L) * (R - L + 1) // 2 - eat
print(ans)

Submission status: Accepted

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

a = [L + int(x) for x in range(N)]
for i in range(len(a)):
    if a[i] < 0:
        if i == len(a)-1:
            a.pop(i)
    else:
        a.pop(i)
        break
print(sum(a))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
deri = [L]
for num in range(1,N):
    num2 = L + num
    deri.append(num2)

deri.sort() #おいしさの小さい順に並び替え
if (0 in deri) == True:
    deri.remove(0) #remove Zero
elif sum(deri) < 0:
    del deri[-1]
else:
    del deri[0]

deru = sum(deri)
print(deru)

Submission status: Accepted

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

for i in range(n):
  flavour.append(l+i)
  
if flavour[0]<=0:
  if flavour[n-1]<=0:
  	print(sum(flavour)-flavour[n-1])
  else:
    print(sum(flavour))
else:
  print(sum(flavour)-flavour[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
aji=[]
for i in range(n):
    aji.append(l+i)
apple=200
for i in range(n):
    if apple>abs(aji[i]):
        apple=abs(aji[i])
        apple_i=i
print(sum(aji)-aji[apple_i])

Submission status: Accepted

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

num = l + n - 1

cnt = 0
if l <= 0 and num <= 0 :
    for i in range(n - 1):
        cnt += l + i
elif l <= 0 and 0 < num:
    for i in range(n):
        cnt += l + i
else:
    for i in range(n - 1):
        cnt += l + i + 1
        
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,l=MI()
tastes=[]
sche=n*(n-1)//2+n*l
dif=10**8
for i in range(1,n+1):
    taste=sche-(l+i-1)
    if abs(l+i-1)<dif:
        dif=abs(l+i-1)
        ans=taste
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

res = []
ans = 0

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

if max(res)<0:
    eaten = max(res)
elif min(res)>0:
    eaten = min(res)
else:
    eaten = 0

print(ans - eaten)

Submission status: Accepted

Solution code:
N, L =map(int, input().split())
Apple = list(range(L,L+N))
#print(Apple)
if Apple[0] > 0:
  B = Apple[0]

elif Apple[-1] < 0:
  B = Apple[-1]
  
else:
  B = 0
print(sum(Apple)-B)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
 
taste = []
mini = 10**9
suf = 0
for i in range(1,n+1):
    if abs(l+i-1) < mini:
        mini = abs(l+i-1)
        suf = i
    taste.append(l+i-1)
 
taste.pop(suf-1)
print(sum(taste))

Submission status: Accepted

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

for j in range(len(m)):
    k.append(abs(sum(m)-(sum(m)-m[j])))

for d in range(len(k)):
    if min(k)==k[d]:
        print(sum(m)-m[d])

Submission status: Accepted

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

num=1+l-1
number=[]
for _ in range(n):
  number.append(num)
  num+=1

if 0 in number:
  print(sum(number))
    
else:
  if all(i<0 for i in number):
    print(sum(number)-max(number))
    
  else:
    print(sum(number)-min(number))

Submission status: Accepted

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

for i in range(1 ,n+1):
    apple.append(l+i-1)
apple_pai = sum(apple)

if l >0:
    eat =l
elif l+n-1 <0:
    eat =l+n-1
ans =apple_pai - eat
print(ans)

Submission status: Accepted

Solution code:
inputted = list(map(int, input().split()))
N = inputted[0]
L = inputted[1]

delicious = (lambda L: lambda i: L + i - 1)(L)
delicious_N = sum([delicious(i) for i in range(1, N + 1)])


i = -L + 1
i = max(1, i)
i = min(i, N)
delicious2 = delicious(i)

answer = delicious_N - delicious2

print(answer)

Submission status: Accepted

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

apple = []
for i in range(1,n+1):
    apple.append(i+l-1)
pai = sum(apple)
ans = 10**9
for i in range(n):
    if ans > abs(apple[i]):
        ans = abs(apple[i])
        eat = apple[i]
print(pai-eat)

Submission status: Accepted

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

if L>0:
    print(N*(2*L+N-1)//2-L)
else:
    print(N*(2*L+N-1)//2-min(L+N-1,0))

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N, L = LI()

A = [x for x in range(L, L+N)]
A.sort(key=lambda x : abs(x))

print(sum(A[1:]))

Submission status: Accepted

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

def taste(i):
  return L + i
m = 1e+10
t = 0
appleN = [taste(i) for i in range(N)]
for n in range(N):
  appleN_1 = [taste(i) for i in range(N) if i != n]
  m = min(m, abs(sum(appleN) - sum(appleN_1)))
  if m == abs(sum(appleN) - sum(appleN_1)):
    t = sum(appleN_1)
print(t)

Submission status: Accepted

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

x = []
y = []
for i in range(N):
  a = L + (i + 1) - 1
  x.append(a)
  y.append(abs(a))
z = min(y)
if z in x:
  x.remove(z)
else:
  j = -z
  x.remove(j)
print(sum(x))

Submission status: Accepted

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

Submission status: Accepted

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

d = float('inf')
for i in range(1,n+1):
  if abs(d) > abs(l+i-1):
    d = l+i-1
print(s-d)

Submission status: Accepted

Solution code:
import bisect

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

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

index = bisect.bisect_left(aji,0)
if index == n:
	index -= 1
print(sum(aji) - aji[index])

Submission status: Accepted

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

if l >= 0:
    print(sum(p)-l)
else:
    if max(p) >= 0:
        print(sum(p))
    else:
        print(sum(p)-max(p))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p,q= input().split()
a,b =(int(p), int(q))
key_num = 0
azi_list = []
for i in range(a):
    azi_list.append(b + i)
if key_num in azi_list:
    print(sum(azi_list))
elif key_num not in azi_list and azi_list[0] > 0:
    print(sum(azi_list[1:]))
else:
    print(sum(azi_list[:-1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q2():
    N, L = (int(i) for i in input().split())
    aji = [L+i for i in range(N)]
    aji_min_i = 999
    aji_min = 999
    for i, a in enumerate(aji):
        if abs(a) < aji_min:
            aji_min = abs(a)
            aji_min_i = i
    aji.pop(aji_min_i)
    print(sum(aji))

if __name__ == '__main__':
    q2()

Submission status: Accepted

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

total_taste = 0
temp = 1000000007
ans = 0
for i in range(n):
    total_taste += l + i
    if abs(l + i) < temp:
        temp = abs(l + i)
        ans = l + i

print(total_taste - ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
l = [i+b for i in range(a)]
sum_a = sum(l)
if sum_a > 0:
    print(sum_a - min(abs(i) for i in l))
else:
    print(sum_a + min(abs(i) for i in l))

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n,l = map(int,input().split())
  APPLE = []
  for i in range(n):
    APPLE.append(l+(i+1)-1)
  if 0 in APPLE:
    print(sum(APPLE))
    exit()
  if sum(APPLE) > 0:
    print(sum(APPLE[1:]))
  elif sum(APPLE) < 0:
    APPLE = APPLE[::-1]
    print(sum(APPLE[1:]))
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

# 本来作りたかったアップルパイの味
assumed_apple_pie = ( L - 1 ) * N + sum( range( 1, N + 1 ) )

# 食べるりんごの味
## 食べるりんごは0に近い方が良い
edible_apple = 0
if L > 0:
  edible_apple = L
elif ( L + N - 1 ) < 0:
  edible_apple = L + N - 1
# 実際のアップルパイ
real_apple_pie = assumed_apple_pie - edible_apple

print( real_apple_pie )

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apple = [l+i for i in range(n)]
absmin = float('inf')
idx = 0
for i in range(n):
    if absmin >= abs(apple[i]):
        absmin = abs(apple[i])
        idx = i

print(sum(apple)-apple[idx])

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,l = iim()
aji = 0
flag = False

for i in range(1,n+1):
    if l+i-1 == 0:
        flag = True
    aji += l+i-1


if flag:
    print(aji)
elif l > 0:
    print(aji - l)
else:
    print(aji - (l+n-1))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
mcount=0
go=1000
a=[0]*n
for i in range(1,n+1):
  a[i-1]=l+i-1
  mcount+=a[i-1]
  
for i in range(n):
  if go>=abs(mcount-(mcount-a[i])):
    go=abs(mcount-(mcount-a[i]))
    c=mcount-a[i]
    
print(c)

Submission status: Accepted

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


def solve(N: int, L: int):
    a = tuple(range(L, L+N))
    return sum(a) - min(a, key=abs)


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if L+N-1 < 0:
    m = L+N-1
elif L > 0:
    m = L
else:
    m = 0

print(ans-m)

Submission status: Accepted

Solution code:
n, l = map(int,input().split())
m = list(range(l, l+n))

if 0 in m:
  print(sum(m))
  
else:
  if m[0] < 0:
    print(sum(m)-max(m))
  else:
    print(sum(m)-min(m))

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,l=INTM()
    ls=[]
    ct=9999999
    for i in range(n):
        ls.append(l+i)
    ls=sorted(ls,key=lambda x:abs(x))
    print(sum(ls)-ls[0])
if __name__ == '__main__':
    do()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
applepi = sum([l + i - 1 for i in range(1,n+1)])
minas = 100000000000
for j in range(1, n+1):
  a = l + j - 1
  if abs(a) <= abs(minas):
    minas = a
print(applepi - minas)

Submission status: Accepted

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

taste = []
mini = 10**9
suf = 0
for i in range(1,n+1):
    if abs(l+i-1) < mini:
        mini = abs(l+i-1)
        suf = i
    taste.append(l+i-1)

taste.pop(suf-1)
print(sum(taste))

Submission status: Accepted

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

if taste.count(0) == 1:
  ans = sum(taste)
elif max(taste) < 0:
  taste.remove(max(taste))
  ans = sum(taste)
else:
  taste.remove(min(taste))
  ans = sum(taste)
print(ans)

Submission status: Accepted

Solution code:
import heapq

n, l = map(int, input().split())
taste = list(range(l, n + l))
ans = 0

if taste.count(0) == 1:
  ans = sum(taste)
elif max(taste) < 0:
  taste = list(map(lambda x: x * (-1), taste))
  heapq.heapify(taste)
  heapq.heappop(taste)
  ans = sum(taste) * (-1)
else:
  heapq.heapify(taste)
  heapq.heappop(taste)
  ans = sum(taste)
print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
scores = [ i+l for i in range(n) ]
min_abs = float("inf")

for s in scores:
    if abs(s) < abs(min_abs):
        min_abs = s

print(sum(scores)-min_abs)

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())

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

min_diff = 10e20
for i in range(N):
    diff = abs(aji[i])
    if diff < min_diff:
        min_diff = diff
        true_aji = sum(aji) - aji[i]

print(true_aji)

Submission status: Accepted

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

App=[L+j for j in range(N)]
abs_App=[abs(L+j) for j in range(N)]
print(sum(App)-App[abs_App.index(min(abs_App))])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
aji = [(L + i) for i in range(N)]
Naji = [abs(j) for j in aji]
del aji[Naji.index(min(Naji))]
print(sum(aji))

Submission status: Accepted

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

total = (l - 1) * n + n * (n + 1) // 2
min_diff = 1e20
for i in range(n):
  apple = l + i
  apple_pie = total - apple
  diff = abs(apple)
  if diff < min_diff:
    min_diff = diff
    min_apple_pie = apple_pie
print(min_apple_pie)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ref = []
ans = n*l + n*(n - 1)/2

if l >= 0:
    ans = ans - l
else:
    for i in range(n):
        ref.append(-l - i)
    ref = map(abs, ref)
    ref = min(ref)
    ans = ans + ref

print(int(ans))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
total = 0
total = n*l + n*(n - 1)/2
ref0 = (n - 1)*l + n*(n - 1)/2

for i in range(n):
    ref1 = 0
    ref1 = (n - 1)*l + n*(n - 1)/2 - i
    if abs(total - ref0) > abs(total - ref1):
        ref0 = ref1

print(int(ref0))

Submission status: Accepted

Solution code:
n , l = map ( int , input ( ).split ( ) ) 
lst = [i + l - 1 for i in range ( 1 , n + 1 )]
ans=1000000 
sum1=sum(lst) 
for i in lst: 
	if abs(i)<abs(ans): 
		ans=i
print(sum1-ans)

Submission status: Accepted

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

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

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

print(sum(taste[1:]))

Submission status: Accepted

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

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

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

print(sum(taste[1:]))

Submission status: Accepted

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

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

before = sum(taste)

ans = 999999999999
for t in taste:
  if abs(t) < abs(before - ans):
    ans = before - t

print(ans)

Submission status: Accepted

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

if N > abs(L) and L < 0:
    print(sum(A))
elif max(B) < 0:
    print(min(B))
else:
    print(max(B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
azi = (l-1)*n + (n*(n+1))//2
x = []
y = []
for i in range(1,n+1):
    x.append(l+i-1)
    y.append(abs(l+i-1))
print (azi-x[y.index(min(y))])

Submission status: Accepted

Solution code:
#B
n, l = map(int, input().split())
min = abs(l)
s = 0
for i in range(n):
    s += l + i
    if abs(l + i) < abs(min):
        min = l + i
print(s-min)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n,l=input().split()

n=int(n)
l=int(l)
v=[]
vv=[]
for i in range(1,n+1):
    v.append(abs(l+i-1))
    vv.append(l+i-1)
v.sort()
#print(v)
#print(vv)
ss=sum(vv)
for i in range(1,n+1):
    if abs(l+i-1)==v[0]:
        print(ss-(l+i-1))
        sys.exit()
#print(ss-v[0])

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
a = [0 for i in range(n)]
for i in range(n):
  a[i] = l+i
a.sort(key=lambda x:abs(x))
print(sum(a[1:]))

Submission status: Accepted

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


def solve(N: int, L: int):
    sum = 0
    minAbs = 10**16
    minVal = 10**16
    for i in range(N):
        c = L + i
        sum += c
        if abs(c) < minAbs:
            minAbs = abs(c)
            minVal = c
    print(sum - minVal)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
m=[l+i for i in range(n)]
s=sum(m)
t=101
d=0
for i in range(n):
  if t>abs(m[i]):
    t=abs(m[i])
    d=m[i]
print(s-d)

Submission status: Accepted

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

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

ans = sum(l)
res = 10 ** 9
d = 0
for i in range(N):
    tmp = l[:i] + l[i+1:]
    solve = sum(tmp)
    c = abs(ans - solve)

    if(res > c):
        res = c
        d = solve

print(d)

Submission status: Accepted

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

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

diff_min = abs(taste)
result = 0
for i in range(n):
    taste2 = 0
    for j in range(n):
        if j == i:
            pass
        else:
            taste2 = taste2 + l + j

    diff = abs(taste - taste2)
    if diff < diff_min:
        diff_min = diff
        result = taste2


print(result)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
li = [l + i - 1 for i in range(1, n + 1)]
mi = 10 ** 10
for a in li:
    if abs(a) < abs(mi):
        mi = a
print(sum(li) - mi)

Submission status: Accepted

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

zero_apple = 100000
for i in range(1, N + 1):
    if abs(L + i - 1) < zero_apple:
        zero_apple = abs(L + i - 1)
        ind = i

taste = 0
for k in range(1, N + 1):
    if k != ind:
        taste += L + k - 1
print(taste)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = sorted(tmp, key=abs)
print(sum(ans)-ans[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
s = sum(L + i - 1 for i in range(1, N + 1))
ans = sum(L + i - 1 for i in range(2, N + 1))
for i in range(1, N + 1):
    s1 = s - (L + i - 1)
    if abs(s - ans) > abs(s - s1):
        ans = s1
print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import scipy as scp

# 入力の受け取り
n,l = map(int,input().split())

apple = [l+i-1 for i in range(1,n+1)]
apple = np.array(apple)
abs_apple = abs(apple)
min_idx = np.argmin(abs_apple)

ans = sum(apple) - apple[min_idx]

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
x = 100
y = 100
for i in range(n):
    if abs(l+i) < x:
        x = abs(l+i)
        y = l+i
print(l*n+sum(range(1, n+1))-n-y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l  = [int(_) for _ in input().split()]
a = []
for i in range(n):
    a.append(l + i)
a.sort(key=lambda x:abs(x))
print(sum(a[1:]))

Submission status: Accepted

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

Submission status: Accepted

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

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

total = sum(apples)

pies = []
for j in range(n):
    pies.append(total-apples[j])

tmp = 1000000000
for k in range(n):
    if abs(total-pies[k]) < tmp:
        aji = pies[k]
        tmp = abs(total-pies[k])

print(aji)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
n=[]
for i in range(N):
    n.append(L+i)
b=[]
for j in range(len(n)):
    b.append(abs(n[j]))
min_abs=b.index(min(b))
n.pop(min_abs)
print(sum(n))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
r=l+n-1;s=(l+r)*n//2
print([s-r,s,s-l][(l>0)+(r>0)])

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    apples.append(l + i)

ans = sum(apples)
if( l > 0):
    ans -= apples[0]
elif( l+n-1 <  0 ):
    ans -= apples[-1]

print(ans)

Submission status: Accepted

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