input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
N = int(eval(input()))
lst_a = list(map(int, input().split()))
total = sum(lst_a)
ans = float("INF")
for i in range(N - 1):
x = sum(lst_a[:i+1])
y = total - x
ans = min(ans, abs(x - y))
print(ans)
|
N = int(eval(input()))
lst_a = list(map(int, input().split()))
total = sum(lst_a)
x = 0
ans = float("INF")
for i in range(N - 1):
x += lst_a[i]
y = total - x
ans = min(ans, abs(x - y))
print(ans)
|
p03659
|
n=int(eval(input()))
a=list(map(int,input().split()))
cnt = n//2
ans=abs(sum(a[:cnt]) - sum(a[cnt:]))
for i in range(1,cnt):
if ans > abs(sum(a[:cnt+i]) - sum(a[cnt+i:])):
ans = abs(sum(a[:cnt+i]) - sum(a[cnt+i:]))
for i in range(1,cnt):
if ans > abs(sum(a[:cnt-i]) - sum(a[cnt-i:])):
ans = abs(sum(a[:cnt-i]) - sum(a[cnt-i:]))
print(ans)
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**100
x=sum(a)
b=0
for i in a[:-1]:
b+=i
x-=i
ans=min(ans,abs(x-b))
print(ans)
|
p03659
|
N = int(eval(input()))
a = [int(x) for x in input().split()]
ans = 10**9*N
for i in range(1,N):
front = a[:i]
back = a[i:]
ans = min(ans, abs(sum(front)-sum(back)))
print(ans)
|
N = int(eval(input()))
a = [int(x) for x in input().split()]
ans = 10**9*N
front = 0
back = sum(a)
for i in range(N-1):
front += a[i]
back -= a[i]
ans = min(ans, abs(front-back))
print(ans)
|
p03659
|
# ABC067C - Splitting Pile
def main():
n = int(eval(input()))
lst = list(map(int, input().rstrip().split()))
l, r, ans = 0, sum(lst), float("inf")
for i in lst[:-1]:
l += i
r -= i
ans = min(ans, abs(l - r))
print(ans)
if __name__ == "__main__":
main()
|
# ABC067C - Splitting Pile
def main():
n = int(eval(input()))
lst = tuple(map(int, input().rstrip().split()))
l, r, ans = 0, sum(lst), float("inf")
for i in lst[:-1]:
l += i
r -= i
ans = min(ans, abs(l - r))
print(ans)
if __name__ == "__main__":
main()
|
p03659
|
# ARC078C - Splitting Pile (ABC067C)
from itertools import accumulate
def main():
n = int(eval(input()))
lst = tuple(accumulate(list(map(int, input().rstrip().split()))))
ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])
print(ans)
if __name__ == "__main__":
main()
|
# ARC078C - Splitting Pile (ABC067C)
from itertools import accumulate
def main():
n = int(eval(input()))
lst = tuple(accumulate(list(map(int, input().rstrip().split()))))
total = lst[-1]
ans = min(abs(total - i * 2) for i in lst[:-1])
print(ans)
if __name__ == "__main__":
main()
|
p03659
|
def main():
n = int(eval(input()))
a = list(input_list())
sa = sum(a)
ans = 10**10
r = 0
for v in list(a)[:-1]:
r += v
ans = min(ans, abs(sa - (2*r)))
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
import math
import fractions
from functools import reduce
main()
|
import collections
def main():
n = int(eval(input()))
a = input_list()
sum_a = sum(a)
wa = []
for i, v in enumerate(a):
if i == 0:
wa.append(v)
else:
wa.append(v+wa[i-1])
ans = float('inf')
for i in range(n-1):
ans = min(ans, abs(sum_a-(wa[i]*2)))
print(ans)
def input_list():
return list(map(int, input().split()))
if __name__ == '__main__':
main()
|
p03659
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=n*10**9
b=[0]
for i in range(1,n+1):
b.append(a[i-1]+b[i-1])
for i in range(n-1):
t_ans=abs(b[i+1]-(b[-1]-b[i+1]))
ans=min(ans,t_ans)
print(ans)
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=n*10**9
t=sum(a)
s=0
for i in range(n-1):
# s=sum(a[:i])
s+=a[i]
ans=min(ans,abs(t-2*s))
print(ans)
|
p03659
|
N = int(eval(input()))
A = [int(i) for i in input().split()]
res = []
for i in range(1, N-1):
snk = sum(A[:i])
arg = sum(A[i:])
res.append(abs(snk-arg))
if N == 2:
print((abs(A[0] - A[1])))
else:
print((min(res)))
|
N = int(eval(input()))
A = [int(i) for i in input().split()]
A_sum = sum(A)
deltas = [A_sum]
res = []
for i in range(N-1):
deltas.append(deltas[-1] - 2*A[i])
res.append(abs(deltas[-1]))
print((min(res)))
|
p03659
|
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 10000000000000
for i in range(1,n):
x = abs(sum(li[:i])-sum(li[i:]))
if x < ans:
ans = x
print(ans)
|
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 10000000000000
x = 0
y = sum(li)
for i in range(0,n-1):
x += li[i]
y -= li[i]
z = abs(x-y)
if z < ans:
ans = z
print(ans)
|
p03659
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**10
cnt=0
for i in range(len(a)-1):
cnt+=a[i]
ans=min(ans,abs(cnt*2-sum(a)))
print(ans)
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**10
cnt=0
rest=sum(a)
for i in range(len(a)-1):
cnt+=a[i]
rest-=a[i]
ans=min(ans,abs(rest-cnt))
print(ans)
|
p03659
|
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
x = 0
ans = 10000000007
for i in range(N):
x += A[i]
if i+1<N : ans=min(ans,abs(total-2*x))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
X = sum(A)
x = 0
ans = 10000000000007
for i in range(N):
x += A[i]
if i+1<N : ans=min(ans,abs(2*x-X))
print(ans)
|
p03659
|
n = int(eval(input()))
li_a = list(map(int, input().split()))
sm = sum(li_a)
result = -1
for c in range(1, len(li_a)):
x = sum(li_a[0:c])
a = abs(sm - 2 * x)
result = min(result, a) if result >= 0 else a
print(result)
|
n = int(eval(input()))
li_a = list(map(int, input().split()))
sm = sum(li_a)
li_ruiseki = list()
for a in li_a:
if len(li_ruiseki) == 0:
li_ruiseki.append(a)
else:
li_ruiseki.append(li_ruiseki[-1] + a)
result = -1
for x in li_ruiseki[:-1]:
a = abs(sm - 2 * x)
result = min(result, a) if result >= 0 else a
print(result)
|
p03659
|
N=int(eval(input()))
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*(N-1)
for i in range(N-1):
number_sum[i]=abs(sum(number[:i+1])*2-SUM)
print((min(number_sum)))
|
N=int(eval(input()))
number=list(map(int,input().split()))
Sum=sum(number)
number_sum=[0]*N
number_sum[0]=number[0]
result=[0]*(N-1)
for i in range(1,N):
number_sum[i]=number_sum[i-1]+number[i]
result[0]=abs(number_sum[0]*2-Sum)
for i in range(1,N-1):
result[i]=abs(((number_sum[i])*2-Sum))
print((min(result)))
|
p03659
|
n = int(eval(input()))
a = list(map(int, input().split()))
s = sum(a)
ans = float('inf')
for i in range(n-1):
x = sum(a[:i+1])
ans = min(ans, abs(s-2*x))
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
s = sum(a)
ans = float('inf')
x = 0
for i in range(n-1):
x += a[i]
ans = min(ans, abs(s-2*x))
print(ans)
|
p03659
|
# input
N = int(eval(input()))
A = list(map(int, input().split()))
sum_A = sum(A)
ans = abs(2 * A[0] - sum_A)
for i in range(1, N - 1):
temp = 0
for j in range(i):
temp += A[j]
temp = abs(2 * temp - sum_A)
if temp < ans:
ans = temp
print(ans)
|
# input
N = int(eval(input()))
A = list(map(int, input().split()))
sum_A = sum(A)
temp = 2 * A[0] - sum_A
ans = abs(temp)
for i in range(1, N - 1):
temp = temp + 2 * A[i]
if abs(temp) < ans:
ans = abs(temp)
print(ans)
|
p03659
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
dp = [0] * N
dp[0] = sum(a)
res = float("inf")
for i in range(N - 1):
dp[i + 1] = dp[i] - a[i]
for i in range(1, N):
res = min(abs(2 * dp[i] - dp[0]), res)
print(res)
|
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]
res = float("inf")
for i in range(1, N):
res = min(res, abs(cs[i] - (cs[-1] - cs[i])))
print(res)
|
p03659
|
n=int(eval(input()))
a=list(map(int,input().split()))
total=sum(a)
ans=[]
for i in range(n-1):
x=sum(a[:i+1:])
ans.append(abs(2*x-total))
print((min(ans)))
|
n=int(eval(input()))
a=list(map(int,input().split()))
total=sum(a)
ans=[]
x=0
for i in range(n-1):
x+=a[i]
ans.append(abs(2*x-total))
print((min(ans)))
|
p03659
|
import bisect
ans = float('inf')
n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(1, n):
ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)
|
N = int(eval(input()))
a = list(map(int, input().split()))
c = [0] * (N + 1)
for i in range(N):
c[i + 1] = c[i] + a[i]
ans = float('inf')
for n in c[1:-1]:
ans = min(ans, abs(c[-1] - 2 * n))
print(ans)
|
p03659
|
N = int(eval(input()))
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
for i in range(1,N):
su = sum(a[:i])
ar = deck - su
ans = min(ans, abs(su-ar))
print(ans)
|
N = int(eval(input()))
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
su = 0
for i in range(0,N-1):
su = su + a[i]
ar = deck - su
ans = min(ans, abs(su-ar))
print(ans)
|
p03659
|
N = int(eval(input()))
a = list(map(int,(input().split())))
X = sum(a)
A = X-a[0]*2
for i in range(N-1):
B = X -sum(a[0:i+1])*2
if abs(B) < abs(A):
A = B
print((abs(A)))
|
N = int(eval(input()))
A = list(map(int,input().split()))
total = sum(A)
snk = A[0]
ari = total - snk
ans = abs(snk - ari)
for i in range(1,N-1):
snk += A[i]
ari -= A[i]
ans = min(ans,abs(snk - ari))
print(ans)
|
p03659
|
n = int(eval(input()))
a = list(map(int, input().split()))
s = sum(a)
t = 0
ans = float("inf")
for i in range(n-1):
t += a[i]
s -= a[i]
ans = min(ans, abs(s-t))
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
x = 0
y = sum(a)
ans = float("inf")
for i in range(n-1):
x += a[i]
y -= a[i]
z = abs(x-y)
if z < ans: ans = z
print(ans)
|
p03659
|
N=int(eval(input()))
A=[int(i) for i in input().split()]
CS=[A[0]]
for i in range(1,N-1):
CS.append(CS[-1]+A[i])
SUM=sum(A)
ans=10**20
for s in CS:
ans=min(ans,abs(SUM-s-s))
print(ans)
|
#C
N=int(eval(input()))
A=[int(i) for i in input().split()]
CS=[A[0]]
for i in range(1,N-1):
CS.append(CS[-1]+A[i])
ans=10**19
SUM=sum(A)
for s in CS:
ans=min(ans,abs(SUM-s-s))
print(ans)
|
p03659
|
N = int(eval(input()))
A = [int(s) for s in input().split()]
def main():
ans = float('inf')
for i in range(N - 1):
A[i] *= -1
ans = min(ans, abs(sum(A)))
print(ans)
if __name__ == '__main__':
main()
|
N = int(eval(input()))
A = [int(s) for s in input().split()]
def main():
sum_n = sum(A)
mid = sum_n / 2
a = 0
abs_list = []
for i in range(N - 1):
a += A[i]
abs_list.append((abs(mid - a), i))
abs_list.sort()
idx = abs_list[0][1]
left = sum(A[:idx + 1])
right = sum(A[idx + 1:])
print((abs(left - right)))
if __name__ == '__main__':
main()
|
p03659
|
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
if __name__ == '__main__':
n = int(eval(input()))
a = list(map(int, input().split()))
# See:
# https://atcoder.jp/img/arc078/editorial.pdf
total_a = sum(a)
diff = float('inf')
for i in range(1, n):
diff = min(diff, abs(total_a - 2 * sum(a[:i])))
print(diff)
|
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest
# Problem C
if __name__ == '__main__':
from itertools import accumulate
n = int(eval(input()))
a = list(map(int, input().split()))
# See:
# https://atcoder.jp/img/arc078/editorial.pdf
# total_a = sum(a)
summed_a = [0] + list(accumulate(a))
total_a = sum(a)
diff = float('inf')
for i in range(1, n):
diff = min(diff, abs(total_a - 2 * summed_a[i]))
print(diff)
|
p03659
|
n = int(eval(input()))
a = list(map(int, input().split()))
ans = []
for i in range(1, n):
ans.append(abs(sum(a[0:i]) - sum(a[i:n])))
print((min(ans)))
|
N = int(eval(input()))
a = list(map(int, input().split()))
m = sum(a[:1])
n = sum(a[1:])
ans = [abs(m-n)]
for i in range(1, N-1):
m += a[i]
n -= a[i]
ans.append(abs(m-n))
print((min(ans)))
|
p03659
|
N = int(eval(input()))
A = list(map(int, input().split()))
tmp = 0
diffs = []
for i in range(N - 1):
tmp += A[i]
diffs.append(abs(sum(A) - tmp - tmp))
print((min(diffs)))
|
N = int(eval(input()))
A = list(map(int, input().split()))
tmp = 0
ans = 10 ** 10
Asum = sum(A)
for i in range(N - 1):
tmp += A[i]
a = abs((Asum - tmp) - tmp)
if ans > a:
ans = a
print(ans)
|
p03659
|
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**100
for i in range(1,n):
x=a[:i]
y=a[i:]
ans=min(ans,abs(sum(x)-sum(y)))
print(ans)
|
n=int(eval(input()))
a=list(map(int,input().split()))
x=a[0]
y=sum(a[1:])
ans=abs(x-y)
for i in range(1,n-1):
x+=a[i]
y-=a[i]
ans=min(ans,abs(x-y))
print(ans)
|
p03659
|
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = [int(a) for a in input().split()]
s = [None] * n; s[0] = a[0]
for i in range(n-1): s[i+1] = s[i] + a[i+1]
mixi = abs(s[0] - (s[n-1] - s[0]))
for i in range(1, n-1): # 全部取るのはダメ
x, y = s[i], s[n-1] - s[i]
mixi = min(mixi, abs(x - y))
print(mixi)
|
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = [int(a) for a in input().split()]
s = [None] * n; s[0] = a[0]
for i in range(n-1): s[i+1] = s[i] + a[i+1]
mixi = abs(s[0] - (s[n-1] - s[0]))
for i in range(1, n-1): mixi = min(mixi, abs(s[i] - (s[n-1] - s[i]))) # 全部取るのはダメ
print(mixi)
|
p03659
|
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse=False):
data.sort(key=lambda x:x[col],reverse=revese)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def mydictvaluesort(dictionary):
return sorted( list(dictionary.items()), key=lambda x:x[1] )
def mydictkeysort(dictionary):
return sorted( list(dictionary.items()), key=lambda x:x[0] )
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int,input().split()))
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(eval(input())) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(eval(input()))
def CS(n):
return [ eval(input()) for _ in range(n) ]
def LS(n):
return [ list(eval(input())) for _ in range(n) ]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
n = I()
a = RI()
m = INF
for i in range(1,n):
x = sum(a[:i])
y = sum(a[i:])
m = min(m,abs(x-y))
print(m)
|
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse=False):
data.sort(key=lambda x:x[col],reverse=revese)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def mydictvaluesort(dictionary):
return sorted( list(dictionary.items()), key=lambda x:x[1] )
def mydictkeysort(dictionary):
return sorted( list(dictionary.items()), key=lambda x:x[0] )
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print((" ".join(ls)))
elif type(ls[0])==int:
print((" ".join(map(str,ls))))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print(("".join(ls)))
elif type(ls[0])==int:
print(("".join(map(str,ls))))
else:
print("Output Error")
def I():
return int(eval(input()))
def MI():
return list(map(int,input().split()))
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(eval(input())) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return eval(input())
def MS():
return input().split()
def RS():
return list(eval(input()))
def CS(n):
return [ eval(input()) for _ in range(n) ]
def LS(n):
return [ list(eval(input())) for _ in range(n) ]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
n = I()
a = RI()
ls_x = []
x = 0
for i in range(n):
x += a[i]
ls_x.append(x)
S = sum(a)
m = INF
for i in range(n-1):
x = ls_x[i]
y = S - x
m = min(m,abs(x-y))
print(m)
|
p03659
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float('inf')
for i in range(1, N):
x = sum(A[:i])
y = sum(A[i:])
d = abs(x-y)
ans = min(ans, d)
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float('inf')
s = sum(A)
x = A[0]
y = s - x
d = abs(x-y)
ans = min(ans, d)
for i in range(1, N-1):
x += A[i]
y = s - x
d = abs(x-y)
ans = min(ans, d)
print(ans)
|
p03659
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float('inf')
s = sum(A)
x = A[0]
y = s - x
d = abs(x-y)
ans = min(ans, d)
for i in range(1, N-1):
x += A[i]
y = s - x
d = abs(x-y)
ans = min(ans, d)
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float('inf')
s = sum(A)
x = A[0]
ans = min(ans, abs(2*A[0]-s))
for i in range(1, N-1):
x += A[i]
ans = min(ans, abs(2*x-s))
print(ans)
|
p03659
|
N = int(eval(input()))
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = []
acu_r.append(A[-1])
for i in range(1,N-1):
acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
acu_r.append(acu_r[-1] + A[i])
#print(acu)
#print(acu_r)
ans = float("inf")
for i in range(N-1):
ans = min(ans,abs(acu[i] - acu_r[N - (i + 2)]))
print(ans)
|
N = int(eval(input()))
A = list(map(int,input().split()))
ans = float("inf")
S = sum(A)
acu = []
acu.append(A[0])
for i in range(1,N-1):
acu.append(acu[-1] + A[i])
for i in range(N-1):
ans = min(ans,abs((S - acu[i]) - acu[i]))
print(ans)
|
p03659
|
# -*- coding:utf-8 -*-
N = int(eval(input()))
a = list(map(int,input().split()))
SUM_CARD = sum(a)
i=1
diff_sum = 0
sunuke = sum(a[0:i])
diff_sum = abs(sunuke*2-SUM_CARD)
i+=1
while(i<N):
sunuke = sum(a[0:i])
diff_sum_new = abs(sunuke*2-SUM_CARD)
if diff_sum_new<diff_sum:
diff_sum = diff_sum_new
i += 1
print(diff_sum)
|
# -*- coding:utf-8 -*-
N = int(eval(input()))
a = list(map(int,input().split()))
SUM_CARD = sum(a)
i=0
sum_before = a[i]
diff_sum = abs(sum_before*2-SUM_CARD)
i+=1
while(i<N-1):
sum_before = sum_before + a[i]
diff_sum_new = abs(sum_before*2-SUM_CARD)
if diff_sum_new<diff_sum:
diff_sum = diff_sum_new
i += 1
print(diff_sum)
|
p03659
|
N = int(eval(input()))
cards = list(map(int, input().split()))
x, y = 0, 0
ans = float("inf")
for i in range(1, N):
x = sum(cards[:i])
y = sum(cards[i:])
if(abs(x-y) < ans):
ans = abs(x-y)
print(ans)
|
N = int(eval(input()))
cards = list(map(int, input().split()))
ans = float("inf")
y = sum(cards)
x = 0
L = []
for card in cards:
x += card
y -= card
L.append(abs(x-y))
del L[N-1]
print((min(L)))
|
p03659
|
N = int(eval(input()))
A = list(map(int, input().split()))
if N == 2:
print((abs(A[0] - A[1])))
exit()
ans = []
for i in range(1, N-1):
cards1 = A[:i]
cards2 = A[i:]
ans.append(abs(sum(cards1) - sum(cards2)))
print((min(ans)))
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float('inf')
X = sum(A)
partial_sum = 0
for i in range(N-1):
partial_sum += A[i]
ans = min(ans, abs(X - 2 * partial_sum))
print(ans)
|
p03659
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
mn_list = []
for i in range(1,n):
sunuke = sum(a[:i])
araiguma = sum(a[i:])
mn_list.append(abs(sunuke-araiguma))
print((min(mn_list)))
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
mn_list = []
sunuke = a[0]
araiguma = sum(a[1:])
res = abs(sunuke-araiguma)
for i in range(1,n-1):
sunuke += a[i]
araiguma -= a[i]
res = min(res,abs(sunuke-araiguma))
print(res)
|
p03659
|
n=int(eval(input()))
b=[]
a=list(map(int,input().split()))
k=a[0]
for i in range(n-1):
b.append(abs(sum(a)-k*2))
k+=a[i+1]
print((min(b)))
|
n=int(eval(input()))
b=[]
a=list(map(int,input().split()))
k=a[0]
s=sum(a)
for i in range(n-1):
b.append(abs(s-k*2))
k+=a[i+1]
print((min(b)))
|
p03659
|
N=int(eval(input()))
C=list(map(int,input().split()))
Sf=[0]
for i in range(N):
Sf.append(Sf[i]+C[i])
#print(Sf)
C=C[::-1]
Sb=[0]
for i in range(N):
Sb.append(Sb[i]+C[i])
Sb=Sb[::-1]
#print(Sb)
ans=10**10
for i in range(1,N):
ans=min(ans,abs(Sf[i]-Sb[i]))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
Sf = [A[0]]
for i in range(1, N):
Sf.append(Sf[-1] + A[i])
A = A[::-1]
Sb = [A[0]]
for i in range(1, N):
Sb.append(Sb[-1] + A[i])
Sb = Sb[::-1]
answer = 10 ** 15
for i in range(N - 1):
answer = min(answer, abs(Sf[i] - Sb[i + 1]))
print(answer)
|
p03659
|
n = int(eval(input()))
A = list(map(int, input().split()))
cum_sum = [sum(A[:i+1]) for i in range(len(A))]
b = cum_sum[-1]
ans = float("inf")
for a in cum_sum[:-1]:
ans = min(ans, abs(2 * a - b))
print(ans)
|
n = int(eval(input()))
A = list(map(int, input().split()))
b = sum(A)
ans = float("inf")
cum_sum = 0
for a in A[:-1]:
cum_sum += a
ans = min(ans, abs(2 * cum_sum - b))
print(ans)
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10 ** 10
for i in range(1, N):
ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)
|
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10 ** 10
total = sum(a)
tmp = 0
for i in range(N - 1):
tmp += a[i]
ans = min(ans, abs(total - (2 * tmp)))
print(ans)
|
p03659
|
N, = list(map(int, input().split()))
a = list(map(int, input().split()))
sl = [0]*N
sl[0] = a[0]
for i in range(N-1):
sl[i+1] = sl[i]+a[i+1]
sr = [0]*N
sr[N-1] = a[N-1]
for i in range(N-1,0,-1):
sr[i-1] = sr[i]+a[i-1]
r = abs(sl[0]-sr[1])
for i in range(1, N-1):
r = min(r, abs(sl[i]-sr[i+1]))
print(r)
|
N, = list(map(int, input().split()))
a = list(map(int, input().split()))
x = a[0]
y = sum(a) - a[0]
r = abs(x-y)
for ai in a[1:N-1]:
x += ai
y -= ai
r = min(r, abs(x-y))
print(r)
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
X = sum(a)
ans = abs(X - 2*a[0])
for i in range(2, N):
tmp = abs(X-2*sum(a[:i]))
if (ans > tmp):
ans = tmp
print(ans)
|
N = int(eval(input()))
a = list(map(int, input().split()))
X = sum(a)
x = a[0]
ans = abs(X - 2*x)
for i in range(1, N-1):
x += a[i]
tmp = abs(X-2*x)
if (ans > tmp):
ans = tmp
print(ans)
|
p03659
|
N = int(input())
a = list(map(int, input().split()))
diff = [abs(sum(a[select:])-sum(a[:select])) for select in range(1,N)]
print(min(diff))
|
N = int(input())
a = list(map(int, input().split()))
sum1 = a[0]
sum2 = sum(a[1:])
diff = [abs(sum1-sum2)]
for i in range(1,N-1):
sum1 += a[i]
sum2 -= a[i]
diff.append(abs(sum1-sum2))
# diff = [abs(sum(a[select:])-sum(a[:select])) for select in range(1,N)]
print(min(diff))
|
p03659
|
n = int(eval(input()))
a = list(map(int,input().split()))
sm = sum(a)
sn = a[0]
ar = sm - a[0]
ans = abs(sn - ar)
for i in range(1,len(a)-1):
sn += a[i]
ar -= a[i]
ans = min(ans,abs(sn-ar))
print(ans)
|
def main():
_ = int(eval(input()))
a = list(map(int,input().split()))
sm = sum(a)
sn = a[0]
ar = sm - a[0]
ans = abs(sn - ar)
for i in range(1,len(a)-1):
sn += a[i]
ar -= a[i]
ans = min(ans,abs(sn-ar))
print(ans)
if __name__ == "__main__":
main()
|
p03659
|
N = int(eval(input()))
a = input().split()
sum0 = 0
for i in range(N):
a[i] = int(a[i])
sum0 += a[i]
for i in range(N-1):
if(i == 0):
b = a[0]
min = abs(2*b-sum0)
elif(1<=i<=int(N/2)-1):
b = a[:i+1]
#print(b)
tmp = abs(2*sum(b)-sum0)
if(min > tmp):
min = tmp
else:
b = a[i+1:]
#print(b)
tmp = abs(2*sum(b)-sum0)
if(min > tmp):
min = tmp
#print(min)
print(min)
|
N = int(eval(input()))
A = list(map(int,input().split()))
sum_all = sum(A)
min_dif = float('inf')
s1 = 0
for i in range(N):
if(i != N-1):
s1 += A[i]
s2 = sum_all - s1
tmp_dif = abs(s1 - s2)
min_dif = min(min_dif,tmp_dif)
print(min_dif)
|
p03659
|
from collections import deque
if(__name__ == "__main__"):
N = int(eval(input()))
a = [int(i) for i in input().split()]
#print(a,b)
#print(maxlist)
sunuke = a[:1]
arai = a[1:]
darai = deque(arai)
#print(sunuke)
#print(darai)
distmin = abs(sum(sunuke) - sum(darai))
for i in range(1,N-1):
sunuke.append(a[i])
darai.popleft()
#print(sunuke)
#print(darai)
dist = abs(sum(sunuke) - sum(darai))
if(distmin > dist):
distmin = dist
print(distmin)
|
if(__name__ == "__main__"):
N = int(eval(input()))
a = [int(i) for i in input().split()]
#print(a,b)
#print(maxlist)
sumsunuke = a[0]
arai = a[1:]
sumarai = sum(arai)
#darai = deque(arai)
#print(sumsunuke)
#print(sumarai)
distmin = abs(sumsunuke - sumarai)
for i in range(1,N-1):
sumsunuke += a[i]
sumarai -= a[i]
#print(sunuke)
#print(darai)
dist = abs(sumsunuke - sumarai)
if(distmin > dist):
distmin = dist
print(distmin)
|
p03659
|
n, *a = list(map(int, open(0).read().split()))
s = sum(a)
print((min(abs(s - sum(a[:i])*2) for i in range(1, n))))
|
from itertools import*
_, *d = list(map(int, open(0).read().split()))
*a, s = list(accumulate(d))
print((min(abs(s - x*2) for x in a)))
|
p03659
|
from itertools import*;*a,s=list(accumulate(list(map(int,open(0).read().split()[1:]))));print((min(abs(s-x*2)for x in a)))
|
from itertools import*;eval(input());*a,s=accumulate(list(map(int,input().split())));print((min(abs(s-x*2)for x in a)))
|
p03659
|
n = int(eval(input()))
a =[int(i) for i in input().split()]
b = sum(a) // 2
z = sum(a)
ans = 10**20
for i in range(1,n):
c = sum(a[:i])
d = z - c
if abs(c-d) < ans:
ans = abs(c-d)
print(ans)
|
n = int(eval(input()))
a =[int(i) for i in input().split()]
z = sum(a)
ans = 10**20
c = 0
for i in range(n-1):
c += a[i]
z -= a[i]
if abs(c-z) < ans:
ans = abs(c-z)
print(ans)
|
p03659
|
N=int(eval(input()))
a=list(map(int,input().split()))
List=[]
for i in range(1,N):
x=sum(a[0:i])
y=sum(a[i:N])
List.append(abs(x-y))
print((min(List)))
|
N=int(eval(input()))
a=list(map(int,input().split()))
List=[]
x1=a[0]
y1=sum(a[1:N])
List.append(abs(x1-y1))
for i in range(1,N-1):
x1+=a[i]
y1-=a[i]
List.append(abs(x1-y1))
print((min(List)))
|
p03659
|
N = int(eval(input()))
L = list(map(int, input().split()))
tmp = 10 ** 12
for i in range(1,N):
if abs(sum(L[:i]) - sum(L[i:])) < tmp:
tmp = abs(sum(L[:i]) - sum(L[i:]))
print(tmp)
|
N = int(eval(input()))
L = list(map(int, input().split()))
tmp = 10 ** 12
after = sum(L)
before = 0
for i in range(N-1):
before += L[i]
after -= L[i]
if abs(before -after) < tmp:
tmp = abs(before -after)
print(tmp)
|
p03659
|
N = int(eval(input()))
a = list(map(int,input().split()))
total = sum(a)
ans = float('inf')
for i in range(1,N):
ans = min(abs(total-2*sum(a[:i])),ans)
print (ans)
|
N = int(eval(input()))
a = list(map(int,input().split()))
total = sum(a)
ans = float('inf')
x = 0
for i in range(N-1):
x += a[i]
ans = min(abs(total-2*x),ans)
print (ans)
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10000000000
total = sum(a)
for i in range(1, N):
sunuke = a[:i]
Sum = sum(sunuke)
if abs(Sum - (total - Sum)) <= ans:
ans = abs(Sum - (total - Sum))
print(ans)
|
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10000000000
total = sum(a)
sunuke = 0
for i in range(N-1):
sunuke += a[i]
dif = abs(2 * sunuke - total)
if dif <= ans:
ans = dif
print(ans)
|
p03659
|
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 10**10
for i in range(1, n):
g1 = a[0:i]
g2 = a[i:n]
tmp = abs(sum(g1) - sum(g2))
if tmp < ans:
ans = tmp
print(ans)
|
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int, input().split()))
g1 = a[0]
g2 = sum(a[1:n])
ans = abs(g1 - g2)
if n > 2:
for i in range(1, n-1):
g1 += a[i]
g2 -= a[i]
tmp = abs(g1 - g2)
if tmp < ans:
ans = tmp
print(ans)
|
p03659
|
N = int(eval(input()))
a_list = list(map(int, input().split()))
a_sum = sum(a_list)
min_num = float("inf")
for i in range(1, N):
x = sum(a_list[:i])
y = a_sum - x
if min_num >= abs(x-y):
min_num = abs(x-y)
print(min_num)
|
N = int(eval(input()))
a_list = list(map(int, input().split()))
a_sum = sum(a_list)
min_num = float("inf")
r = []
for i in range(1, N):
if len(r) == 0:
r.append(a_list[0])
else:
r.append(r[i-2] + a_list[i-1])
x = r[i-1]
y = a_sum - x
if min_num >= abs(x-y):
min_num = abs(x-y)
print(min_num)
|
p03659
|
n = int(eval(input()))
a = list(map(int,input().split()))
X = sum(a)
x = list(sum(a[:i+1]) for i in range(n))
ans = min(list(abs(X-2*x[i]) for i in range(n-1)))
print(ans)
|
n = int(eval(input()))
a = list(map(int,input().split()))
X = sum(a)
x =[a[0]]
for i in range(n-1):
x.append(x[i]+a[i+1])
ans = min(list(abs(X-2*x[i]) for i in range(n-1)))
print(ans)
|
p03659
|
N = int(eval(input()))
A = [int(x) for x in input().split()]
S = sum(A)
x = 0
ans = float('inf')
for i in range(N):
x += A[i]
if i < N - 1:
ans = min(ans, abs(S - x * 2))
print(ans)
|
N = int(eval(input()))
A = [int(x) for x in input().split()]
S = sum(A)
x = 0
ans = float('inf')
for i in range(N - 1):
x += A[i]
ans = min(ans, abs(S - x * 2))
print(ans)
|
p03659
|
n = int(eval(input()))
a = list(map(int, input().split()))
z = sum(a)
ln = []
for i in range(1, n):
ln.append(abs(z - 2 * sum(a[0: i])))
print((min(ln)))
|
n = int(eval(input()))
a = list(map(int, input().split()))
z = sum(a)
ln = []
x = 0
for i in range(n - 1):
x += a[i]
ln.append(abs(z - 2 * x))
print((min(ln)))
|
p03659
|
N=int(eval(input()))
an=list(map(int,input().split()))
s=sum(an)
l=[]
for i in range(1,N):
b = sum(an[:i])
l.append(abs(s-2*b))
print((min(l)))
|
N=int(eval(input()))
an=list(map(int,input().split()))
s=sum(an)
b = an[0]
l=[]
a = abs(s-2*b)
for i in range(1,N-1):
b = b + an[i]
a=min(a,abs(s-2*b))
print(a)
|
p03659
|
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:14:43 2020
@author: H_Hoshigi
"""
N = int(eval(input()))
a_list = list(map(int, input().split()))
sunuke = a_list[0]
araiguma = sum(a_list[1:])
min_difference = abs(sunuke - araiguma)
for i in range(1,N-1):
sunuke += a_list[i]
araiguma -= a_list[i]
min_difference = min(min_difference,
abs(sunuke - araiguma))
print(min_difference)
|
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:29:09 2020
@author: H_Hoshigi
"""
import sys
N = int(eval(input()))
a_list = list(map(int, input().split()))
#sunuke = a_list[0]
#araiguma = sum(a_list[1:])
#min_difference = abs(sunuke - araiguma)
sunuke = 0
sum_a = sum(a_list)
min_difference = sys.maxsize
#abs(sunuke - araiguma)は、abs(sum(a_list)-sunuke*2)として求められる。
#range(1,N-1)ではなく、最初の一枚目から比較する形にした。
for i in range(N-1):
sunuke += a_list[i]
#araiguma -= a_list[i]
min_difference = min(min_difference,
abs(sum_a - 2*sunuke))
print(min_difference)
|
p03659
|
n=int(eval(input()))
a=[int(i) for i in input().split()]
x=0
y=0
l=float("inf")
for i in range(n-1):
x+=a[i]
y=sum(a)-x
l=min(l,abs(x-y))
print(l)
|
n=int(eval(input()))
a=[int(i) for i in input().split()]
x=0
y=sum(a)
l=float("inf")
for i in range(n-1):
x+=a[i]
y=y-a[i]
l=min(l,abs(x-y))
print(l)
|
p03659
|
n = int(eval(input()))
a = list(map(int, input().split()))
ans = []
for x in range(1, n):
y = n - x
dis = abs(sum(a[:x]) - sum(a[x:]))
ans.append(dis)
print((min(ans)))
|
n = int(eval(input()))
a = list(map(int, input().split()))
total = sum(a)
ans = []
for x in range(n-1):
total -= 2*a[x]
ans.append(abs(total))
print((min(ans)))
|
p03659
|
N = int(eval(input()))
a= list(map(int, input().split()))
left = [0] * N
right = [0] * N
left[0] = a[0]
right[-1] = a[-1]
for i in range(1, N):
left[i] = a[i] + left[i-1]
for i in range(N-2, -1, -1):
right[i] = a[i] + right[i+1]
# print(left)
# print(right)
ans = abs(left[0] - right[1])
for i in range(1, N-1):
ans = min(ans, abs(left[i] - right[i+1]))
print(ans)
|
import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
a = list(map(int, input().split()))
left = [0] * N
left[0] = a[0]
for i in range(1, N):
left[i] = left[i-1] + a[i]
# print(left)
ans = abs(left[-1] - 2 * left[0])
for i in range(1, N-1):
ans = min(ans, abs(left[-1] - 2 * left[i]))
print(ans)
if __name__ == "__main__":
main()
|
p03659
|
#
# abc067 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """6
1 2 3 4 5 6"""
output = """1"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
10 -10"""
output = """20"""
self.assertIO(input, output)
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float("inf")
S = sum(A)
if N == 2:
ans = abs(A[0]-A[1])
else:
for i in range(1, N-1):
t = sum(A[:i])
ans = min(ans, abs(S-2*t))
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
#
# abc067 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """6
1 2 3 4 5 6"""
output = """1"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
10 -10"""
output = """20"""
self.assertIO(input, output)
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float("inf")
S = sum(A)
T = []
T.append(A[0])
for i in range(1, N):
T.append(T[i-1]+A[i])
if N == 2:
ans = abs(A[0]-A[1])
else:
for i in range(1, N-1):
ans = min(ans, abs(S-2*T[i]))
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
p03659
|
#
# abc067 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """6
1 2 3 4 5 6"""
output = """1"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
10 -10"""
output = """20"""
self.assertIO(input, output)
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float("inf")
S = sum(A)
T = []
T.append(A[0])
for i in range(1, N):
T.append(T[i-1]+A[i])
if N == 2:
ans = abs(A[0]-A[1])
else:
for i in range(1, N-1):
ans = min(ans, abs(S-2*T[i]))
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
#
# abc067 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """6
1 2 3 4 5 6"""
output = """1"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2
10 -10"""
output = """20"""
self.assertIO(input, output)
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float("inf")
S = sum(A)
T = []
T.append(A[0])
for i in range(1, N-1):
T.append(T[i-1]+A[i])
for t in T:
ans = min(ans, abs(S-2*t))
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
p03659
|
def splittingplie(n , a):
ans = 100000000000000
for i in range(1 , n):
rldifference = abs(sum(a[:i]) - sum(a[i:]))
ans = min(ans , rldifference)
return ans
def main():
n = int(eval(input()))
a = list(map(int , input().split()))
print((splittingplie(n , a)))
if __name__ == '__main__':
main()
|
def splittingplie(n , a):
ans = 10**18
allsum = int(sum(a))
asum = 0
for i in range(n - 1):
asum += a[i]
rldifference = abs(allsum - asum*2)
ans = min(ans , rldifference)
return ans
def main():
n = int(eval(input()))
a = list(map(int , input().split()))
print((splittingplie(n , a)))
if __name__ == '__main__':
main()
|
p03659
|
n = int(eval(input()))
A = list(map(int, input().split()))
sunuke = sum(A)
arai = 0
f_inf = float("inf")
res = f_inf
for i in range(n - 1):
arai += A[i]
sunuke -= A[i]
res = min(res, abs(sunuke - arai))
print(res)
|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
A = list(map(int, input().split()))[::-1]
snuke = sum(A)
arai = 0
res = f_inf
for i in range(n - 1):
snuke -= A[i]
arai += A[i]
res = min(res, abs(snuke - arai))
print(res)
if __name__ == '__main__':
resolve()
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
ans =2*10**9
for i in range(1, N):
ans = min(ans, abs(sum(a[:i])-sum(a[i:])))
print(ans)
|
n = int(eval(input()))
a = list(map(int, input().split()))
sunu = sum(a)
arai = 0
ans = 2*10**9
for i in range(n-1):
sunu -= a[i]
arai += a[i]
ans = min(ans,abs(sunu-arai))
print(ans)
|
p03659
|
import itertools
N = int(eval(input()))
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = sum(a)
ans = 10**100
for i in range(N-1):
ans = min(ans,abs(sum(a[:i+1])*2-b))
print(ans)
|
import itertools
N = int(eval(input()))
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = sum(a)
ans = 10**100
for i in range(N-1):
ans = min(ans,abs(ruiseki[i]*2-b))
print(ans)
|
p03659
|
n=int(eval(input()))
a=list(map(int,input().split()))
result=10000000000
total=0
for i in range(n-1):
total +=a[i]
if abs(sum(a)-2*total)<result:
result=abs(sum(a)-2*total)
print(result)
|
n=int(eval(input()))
a=list(map(int,input().split()))
result=10000000000
total=0
suma=sum(a)
for i in range(n-1):
total +=a[i]
sa = abs(suma - 2*total)
if sa <result:
result=sa
print(result)
|
p03659
|
N = int(eval(input()))
a = list(map(int,input().split()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
suma = 0
for j in range(i+1):
suma+=a[j]
kari = abs(SUM-2*suma)
MIN = min(MIN,kari)
print(MIN)
|
def solve(N,a):
suma = 0
SUM = sum(a)
MIN = 10**15
for i in a[:(N-1)]:
suma+=i
MIN = min(MIN,abs(2*suma-SUM))
return abs(MIN)
if __name__ == "__main__":
N = int(eval(input()))
a = list(map(int,input().split()))
print((solve(N,a)))
|
p03659
|
n = int(eval(input()))
a = list(map(int,input().split()))
ans = 2*10**9
X = sum(a)
for i in range(n-1):
x = sum(a[:i+1])
ans = min(ans,abs(X-x*2))
print(ans)
|
n = int(eval(input()))
a = list(map(int,input().split()))
s = sum(a)
ans = 10**20
x = 0
for i in range(n-1):
x += a[i]
y = s - x
tmp = abs(x-y)
ans = min(ans,tmp)
print(ans)
|
p03659
|
N = int(eval(input()))
a = list(map(int,input().split()))
x = 0
y = 0
min = abs(sum(a[0:1])-sum(a[1:N]))
for i in range(3,N):
x = sum(a[0:i])
y = sum(a[i:N])
if abs(x-y) <= min:
min = abs(x-y)
print(min)
|
N = int(eval(input()))
a = list(map(int,input().split()))
x = a[0]
y = sum(a[1:])
ans = abs(x-y)
for i in range(1,N-1):
x += a[i]
y -= a[i]
ans = min(abs(x-y),ans)
print(ans)
|
p03659
|
N = int(eval(input()))
A = list(map(int,input().split()))
ruisekiwa = [0]*(N+1)
now = 0
minimum = 10**10
for i in range(N):
now += A[i]
ruisekiwa[i+1] = now
for i in range(N-1):
snuke = ruisekiwa[i+1]
arai = ruisekiwa[N]-snuke
K = abs(snuke-arai)
if K < minimum:
minimum = K
print(minimum)
|
N = int(eval(input()))
A = list(map(int,input().split()))
r = [0]*(N+1)
#累積和
a = 0
for i in range(N):
a += A[i]
r[i+1] = a
minimum = 10**18
for i in range(1,N):
snuke = r[i]
arai = r[N]-r[i]
if minimum > abs(snuke-arai):
minimum = abs(snuke-arai)
print(minimum)
|
p03659
|
def inpl(): return input().split()
n = int(eval(input()))
a = list(map(int, inpl()))
sa = sum(a)
b = [a[0]]
for i in range(1, n - 1):
b.append(a[i] + b[i - 1])
ans = float('inf')
for x in b:
ans = min(ans, abs(sa - 2 * x))
print(ans)
|
n = int(eval(input()))
*a, = list(map(int, input().split()))
ret = 10 ** 15
s = 0
t = sum(a)
a.pop() # 最後の要素は取れない
for x in a:
s += x
t -= x
ret = min(ret, abs(s - t))
print(ret)
|
p03659
|
# coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
X = sum(A)
ans = float("inf")
x = 0
for i in range(N):
x += A[i]
if i < N-1:
ans = min(ans, abs(X - 2 * x))
print(ans)
|
# coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
sunuke = sum(A)
ara = 0
ans = float("inf")
for i in range(N-1, 0, -1):
sunuke -= A[i]
ara += A[i]
ans = min(ans, abs(sunuke - ara))
print(ans)
|
p03659
|
n = int(eval(input()))
As = list(map(int, input().split()))
Sc = list()
for i in range(1, n):
Sc.append(abs( sum(As[:i]) - sum(As[i:])))
print((min(Sc)))
|
import sys
n = int(eval(input()))
As = list(map(int, input().split()))
Sc = list()
dp = [10**9] * (n-1)
ep = [10**9] * (n-1)
s = sum(As)
if n-2 == 0:
print((abs(As[0] - As[1])))
sys.exit()
for i in range(n-2):
if i == 0:
dp[i] = As[i]
else:
dp[i] = dp[i-1] + As[i]
ep[i] = abs(dp[i] - s + dp[i])
print((min(ep)))
|
p03659
|
N=int(eval(input()))
A=list(map(int,input().split()))
S=sum(A)
print((min(abs(S-2*sum(A[i:])) for i in range(1,N))))
|
N=int(eval(input()))
A=list(map(int,input().split()))
S=sum(A)
T=[0]*N
for i in range(N-1):
T[i+1]=T[i]+A[i]
print((min(abs(S-2*T[i]) for i in range(1,N))))
|
p03659
|
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 10**10
for i in range(1, N):
a = sum(A[0:i])
b = sum(A[i:N+1])
ans = min(ans, abs(a - b))
print(ans)
|
N = int(eval(input()))
A = list(map(int, input().split()))
arai = sum(A)
sunuke = 0
ans = 10**10
for i in range(0, N-1):
sunuke += A[i]
arai -= A[i]
ans = min(ans, abs(sunuke - arai))
print(ans)
|
p03659
|
def main():
N = int(eval(input()))
l = list(map(int, input().split()))
ans = []
sunuke = 0
arai = sum(l)
for i in range(N-1):
sunuke += l[i]
arai -= l[i]
ans.append(abs(sunuke-arai))
print((min(ans)))
if __name__ == '__main__':
main()
|
def main():
N = int(eval(input()))
l = list(map(int, input().split()))
ans = []
X = sum(l)
x = 0
for i in range(N-1):
x += l[i]
ans.append(abs(X-2*x))
print((min(ans)))
if __name__ == '__main__':
main()
|
p03659
|
N = int(eval(input()))
A = [int(i) for i in input().split()]
su = sum(A)
x = 0
mi = 1e15
for a in A[:-1]:
x += a
mi = min(mi, abs(su - 2 * x))
print(mi)
|
from itertools import accumulate
N = int(eval(input()))
A = [int(i) for i in input().split()]
*B, su = list(accumulate(A))
print((min(abs(su - 2 * b) for b in B)))
|
p03659
|
n=int(eval(input()))
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
for i in range(1,n):
ans=abs(2*sum(a[:i])-suma)
if ans < minans:
minans = ans
print(minans)
|
n=int(eval(input()))
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
#print(minans)
mydata=0
for i in range(0,n-1):
mydata+=a[i]
ans=abs(2*mydata-suma)
if ans < minans:
minans = ans
print(minans)
|
p03659
|
# coding: utf-8
# Your code here!
import math
N = int(eval(input()))
lst = list(map(int,input().split()))
ans = float('inf')
for i in range(N-1):
#print(sum(lst[:i+1]) , sum(lst[i+1:]))
ans = min(ans,math.fabs(sum(lst[:i+1]) - sum(lst[i+1:])))
print((int(ans)))
|
# coding: utf-8
# Your code here!
import math
N = int(eval(input()))
lst = list(map(int,input().split()))
x = lst[0]
y = sum(lst[1:])
ans = abs(y - x)
for i in range(1,N-1):
x+=lst[i]
y-=lst[i]
ans = min(ans,abs(x-y))
print(ans)
|
p03659
|
#Python
N = eval(input())
a = list(map(int, input().split()))
b=[]
for i in range(N-1):
i=i+1
#print "x::"+str(sum(a[:i]))
#print "sum-2x::"+str( abs( sum(a) - sum(a[:i])*2 ) )
b.append( abs( sum(a) - sum(a[:i])*2 ) )
#print b
print(min(b))
|
#Python
N = eval(input())
a = list(map(int, input().split()))
b=[]
ans=0
sum=sum(a)
x=0
for i in range(N-1):
x+=a[i]
#print "x::"+str(x)
if i==0:
ans= abs( sum - x*2 )
if ans>abs( sum - x*2 ):
ans= abs( sum - x*2 )
#print "ans::"+str(ans)
print(ans)
|
p03659
|
from itertools import accumulate as acc
eval(input())
S=tuple(acc(list(map(int,input().split()))))
print((min(abs(S[-1]-2*x)for x in S[:-1])))
|
from itertools import accumulate as acc
eval(input())
s=list(acc(list(map(int,input().split()))));S=s.pop()
print((min(abs(S-2*x)for x in s)))
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x-y==0:
ans = 0
else:
ans = abs(x-y)
for i in range(2,N):
s = a[:i]
t = a[i:]
x = sum(s)
y = sum(t)
if x-y==0:
ans = 0
break
elif abs(x-y)<ans:
ans = abs(x-y)
print(ans)
|
N = int(eval(input()))
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x==y:
ans = 0
else:
ans = abs(x-y)
for i in range(1,N-1):
x += a[i]
y -= a[i]
if x==y:
ans = 0
break
elif abs(x-y)<ans:
ans = abs(x-y)
print(ans)
|
p03659
|
N = int(eval(input()))
A = list(map(int,input().split()))
B = [0]
for i in range(N):
B.append(B[i]+A[i])
dmin = 10**15
for i in range(1,N):
dmin = min(dmin,abs(B[N]-2*B[i]))
print(dmin)
|
N = int(eval(input()))
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
B[i] = B[i-1]+A[i-1]
cmin = 10**15
for i in range(1,N):
cmin = min(cmin,abs(2*B[i]-B[N]))
print(cmin)
|
p03659
|
def main():
n=int(eval(input()))
a=list(map(int,input().split()))
ans=float('inf')
for i in range(1,n):
ans=min(ans,abs(sum(a[i:])-sum(a[:i])))
print(ans)
if __name__=='__main__':
main()
|
def main():
n=int(eval(input()))
a=list(map(int,input().split()))
ans,s,x=abs(sum(a)-2*a[0]),sum(a),a[0]
for i in range(1,n-1):
x+=a[i]
ans=min(ans,abs(s-2*x))
print(ans)
if __name__=='__main__':
main()
|
p03659
|
# encoding:utf-8
def main():
N = int(eval(input()))
cards = list(map(int, input().split()))
if N == 2:
print((abs(cards[0] - cards[1])))
else:
print((min([abs(calcDif(cards, x)) for x in range(1, N - 1)])))
def calcDif(cards, k):
# k >= 1
#print(k)
x = cards[:k]
y = cards[k:len(cards)]
return(sum(x) - sum(y))
if __name__ == '__main__':
main()
|
# encoding:utf-8
def main():
N = int(eval(input()))
cards = list(map(int, input().split()))
x = cards[0]
y = sum(cards[1:])
i = 1
val = abs(x - y)
while i < len(cards) - 1:
x += cards[i]
y += -cards[i]
temp = abs(x - y)
if temp == 0:
val = 0
break
if temp < val:
val = temp
i += 1
print(val)
if __name__ == '__main__':
main()
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
for i in range(N-1):
s1 = sum(a[0:i + 1])
s2 = sum(a[i+1:])
mindiff = min(mindiff, abs(s1 - s2))
print(mindiff)
|
N = int(eval(input()))
a = list(map(int, input().split()))
mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
s1 = 0
s2 = sum(a)
for i in range(N-1):
s1 += a[i]
s2 -= a[i]
mindiff = min(mindiff, abs(s1 - s2))
print(mindiff)
|
p03659
|
#!/usr/bin/env python
n = int(eval(input()))
a = list(map(int, input().split()))
ans = float('inf')
for i in range(1, n):
ans = min(ans, abs(sum(a[:i])-sum(a[i:])))
print((int(ans)))
|
#!/usr/bin/env python
n = int(eval(input()))
a = list(map(int, input().split()))
total = sum(a)
ans = float('inf')
tmp = 0
for i in range(n):
tmp += a[i]
if i==n-1:
continue
ans = min(ans, abs(tmp-(total-tmp)))
print((int(ans)))
|
p03659
|
N = int(eval(input()))
card = list(map(int,input().split(' ')))
sum_card = sum(card)
dif_list = []
min_value = 1000000000
for i in range(1,N,1):
sunuke = sum(card[:i])
if abs(sum_card/2 - sunuke) < min_value:
min_value = abs(sum_card/2 - sunuke)
print((int(2*min_value)))
|
N = int(eval(input()))
card = list(map(int,input().split(' ')))
sum_card = sum(card)
min_value = 10000000000
sunuke = 0
for i in range(0,N-1,1):
sunuke += card[i]
if abs(sum_card - 2*sunuke) < min_value:
min_value = abs(sum_card - 2*sunuke)
print((int(min_value)))
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
ans = float('inf')
for i in range(1, N):
ans = min(abs(sum(a[:i])-sum(a[i:])), ans)
print(ans)
|
N = int(eval(input()))
a = list(map(int, input().split()))
arai = sum(a)-a[0]
sunuke = a[0]
ans = abs(sunuke-arai)
for i in a[1:-1]:
sunuke += i
arai -= i
ans = min(abs(sunuke-arai), ans)
print(ans)
|
p03659
|
N = int(eval(input()))
a = list(map(int, input().split()))
c = []
for i in range(N-1):
b = a[0:i+1]
c.append(abs(sum(a)-2*sum(b)))
print((min(c)))
|
N = int(eval(input()))
a = list(map(int, input().split()))
c = [2*a[0]-sum(a)]
d = [abs(c[0])]
for i in range(N-2):
c.append(c[i]+2*a[i+1])
d.append(abs(c[i+1]))
print((min(d)))
|
p03659
|
n = int(eval(input()))
a = list(map(int,input().split()))
min_v = float('inf')
for i in range(1,n):
tmp1 = a[:i]
tmp2 = a[i:]
min_v = min(abs(sum(tmp1) - sum(tmp2)), min_v)
print(min_v)
|
n = int(eval(input()))
l = list(map(int,input().split()))
x = 0
y = sum(l)
xy = [10**15]*n
for i in range(n-1):
x += l[i]
y -= l[i]
xy[i] = abs(x-y)
print((min(xy)))
|
p03659
|
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10**10
x = 0
for i in range(N-1):
x+=A[i]
ans = min(ans, abs(sum(A)-2*x))
print(ans)
|
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
Asum = sum(A)
ans = 10**10
x = 0
for i in range(N-1):
x+=A[i]
ans = min(ans, abs(Asum-2*x))
print(ans)
|
p03659
|
n = int(eval(input()))
dec = list(map(int, input().split()))
diff = []
for i in range(1, n):
diff.append(abs(sum(dec[:i])-sum(dec[i:])))
print((min(diff)))
|
n = int(eval(input()))
a = list(map(int, input().split()))
snk = a[0]
ari = sum(a)-snk
ans = abs(snk-ari)
for i in range(n-2):
snk += a[i+1]
ari -= a[i+1]
ans = min(ans, abs(snk-ari))
print(ans)
|
p03659
|
n,x,*a=list(map(int,open(0).read().split()))
y=sum(a)
z=abs(x-y)
for i in a[:-1]:x+=i;y-=i;z=min(z,abs(x-y))
print(z)
|
n,x,*a,b=list(map(int,open(0).read().split()))
y=sum(a)+b
z=abs(x-y)
for i in a:x+=i;y-=i;z=min(z,abs(x-y))
print(z)
|
p03659
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
x = sum(a)
answer = abs(x-2*a[0])
for i in range(1,n):
y = sum(a[i:])
if answer>abs(x-2*y):
answer = abs(x-2*y)
print(answer)
|
n = int(eval(input()))
a = [int(i) for i in input().split()]
x,y = a[0],sum(a)-a[0]
answer = abs(x-y)
for i in range(1,n-1):
x += a[i]
y -= a[i]
if answer > abs(x-y):
answer = abs(x-y)
print(answer)
|
p03659
|
import math
ans = math.inf
n = int(eval(input()))
c = list(map(int, input().split()))
s, a = 0, 0
for i in range(n - 1):
s = sum(c[:i+1])
a = sum(c[i+1:])
ans = min(ans, abs(s-a))
print(ans)
|
import math
ans = math.inf
n = int(eval(input()))
c = list(map(int, input().split()))
acm = [0]*(n+1)
for i, v in enumerate(c, 1):
acm[i] += acm[i-1] + v
s, a = 0, acm[n]
for i in range(1, n):
s = acm[i]
ans = min(ans, abs((a-s)-s))
print(ans)
|
p03659
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.