input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
n = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
sm = 0
for i in range(n):
if i % 2 == 0:
if sm + A[i] > 0:
sm += A[i]
elif sm + A[i] <= 0:
num = -(sm + A[i]) + 1
sm += A[i] + num
ans += num
else:
if sm + A[i] < 0:
sm += A[i]
elif sm + A[i] >= 0:
num = -(sm + A[i]) - 1
sm += A[i] + num
ans += -num
ans1 = ans
ans, sm = 0, 0
for i in range(n):
if i % 2 != 0:
if sm + A[i] > 0:
sm += A[i]
elif sm + A[i] <= 0:
num = -(sm + A[i]) + 1
sm += A[i] + num
ans += num
else:
if sm + A[i] < 0:
sm += A[i]
elif sm + A[i] >= 0:
num = -(sm + A[i]) - 1
sm += A[i] + num
ans += -num
print((min(ans, ans1)))
| import sys
input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
sm = 0
for i in range(n):
if i % 2 == 0:
if sm + A[i] > 0:
sm += A[i]
elif sm + A[i] <= 0:
num = -(sm + A[i]) + 1
sm += A[i] + num
ans += num
else:
if sm + A[i] < 0:
sm += A[i]
elif sm + A[i] >= 0:
num = -(sm + A[i]) - 1
sm += A[i] + num
ans += -num
ans1 = ans
ans, sm = 0, 0
for i in range(n):
if i % 2 != 0:
if sm + A[i] > 0:
sm += A[i]
elif sm + A[i] <= 0:
num = -(sm + A[i]) + 1
sm += A[i] + num
ans += num
else:
if sm + A[i] < 0:
sm += A[i]
elif sm + A[i] >= 0:
num = -(sm + A[i]) - 1
sm += A[i] + num
ans += -num
print((min(ans, ans1)))
| p03739 |
n,a=int(eval(input())),list(map(int,input().split()));ans=0
if a[0]==0:
bol=True
for i in range(1,n):
if a[i-1]!=a[i]:
bol=False
if a[i]>0:a[0]=(1if i%2==0else-1)
else:a[0]=(1if i%2!=0else-1)
ans+=1;break
if bol:print((n*2-1));exit()
b=[a[0]];m=("+"if a[0]<0else"-")
for i in range(1,n):
while b[-1]*(b[-1]+a[i])>=0:
ans+=1
a[i]+=eval(m+"1")
b.append(b[-1]+a[i])
m=("+"if b[i]<0else"-")
print(ans) | n=int(eval(input()))
A=list(map(int,input().split()))
ans=10**15
for i in[-1,1]:
ansi,sum=0,0
for a in A:
sum+=a
if sum*i<=0:ansi+=abs(sum-i);sum=i
i*=-1
ans=min(ans,ansi)
print(ans) | p03739 |
n = int(eval(input()))
a = list(map(int,input().split()))
count=0
if a[0]>0:
for i in range(n):
if i%2==0:
if sum(a[:i+1])<0:
count+=-1*sum(a[:i+1])+1
a[i]+=-1*sum(a[:i+1])+1
else:
if sum(a[:i+1])>0:
count+=sum(a[:i+1])+1
a[i]-=sum(a[:i+1])-1
else:
for i in range(n):
if i%2==0:
if sum(a[:i+1])>0:
count+=sum(a[:i+1])+1
a[i]+=-1*sum(a[:i+1])-1
else:
if sum(a[:i+1])<0:
count+=-1*sum(a[:i+1])+1
a[i]+=-1*sum(a[:i+1])+1
if sum(a)==0:
count+=1
print(count) | n=eval(input())
a=[int(i) for i in input().split()]
def chk(a,t):
ans=0
x=0
for i in a:
x+=i
if t==True and x<1:
ans+=1-x
x=1
elif t==False and x>-1:
ans+=x+1
x=-1
t=not t
return ans
print((min(chk(a,True),chk(a,False)))) | p03739 |
N = int(eval(input()))
A = list(map(int, input().split()))
x = 0
tmp = 0
for i in range(N):
tmp += A[i]
if i & 1 == 0:
if tmp < 1:
x += 1-tmp
tmp = 1
else:
if tmp > -1:
x += 1+tmp
tmp = -1
y = 0
tmp = 0
for i in range(N):
tmp += A[i]
if i & 1:
if tmp < 1:
y += 1-tmp
tmp = 1
else:
if tmp > -1:
y += 1+tmp
tmp = -1
print((min(x,y))) | n = int(eval(input()))
a = list(map(int, input().split()))
def check(flag):
acc = 0
cnt = 0
flag = flag
for i in a:
acc += i
if (flag == 1 and flag > acc) or (flag == -1 and flag < acc) or i == 0:
cnt += abs(flag - acc)
acc = flag
flag *= -1
return cnt
print((min(check(1), check(-1))))
| p03739 |
n = int(eval(input()))
a = list(map(int, input().split()))
# プラススタート ------------------
ans01 = 0
temp = a[0]
if (temp > 0):
pass
else:
add = abs(temp) + 1
ans01 += add
temp = 1
for i in range(1, n):
tar = temp + a[i]
if (tar * temp < 0):
temp = tar
else:
add = abs(tar) + 1
ans01 += add
if (temp > 0):
temp = -1
else:
temp = 1
#print(tar, ans)
# マイナススタート ------------------
ans02 = 0
temp = a[0]
if (temp < 0):
pass
else:
add = abs(temp) + 1
ans02 += add
temp = -1
for i in range(1, n):
tar = temp + a[i]
if (tar * temp < 0):
temp = tar
else:
add = abs(tar) + 1
ans02 += add
if (temp > 0):
temp = -1
else:
temp = 1
#print(tar, ans)
ans = min(ans01, ans02)
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
def calc(val):
# valには、1か−1を入れる。
if (val * a[0] > 0):
# 狙った符号のパターン
temp = a[0]
ans01 = 0
else:
# 違うパターン
add = abs(a[0]) + 1
ans01 = add
temp = val
for i in range(1, n):
tar = temp + a[i]
if (tar * temp < 0):
temp = tar
else:
add = abs(tar) + 1
ans01 += add
if (temp > 0):
temp = -1
else:
temp = 1
return ans01
ans = min(calc(1), calc(-1))
print(ans)
| p03739 |
import sys
def solve():
n = int(eval(input()))
a = [int(i) for i in input().split()]
ans1 = 0 if a[0] > 0 else abs(a[0] - 1)
v = a[0] if a[0] > 0 else 1
for i in range(1, n):
if v * (v + a[i]) < 0:
v += a[i]
else:
if v > 0:
ans1 += abs(v + a[i] + 1)
v = -1
else:
ans1 += abs(v + a[i] - 1)
v = 1
ans2 = 0 if a[0] < 0 else abs(a[0] + 1)
v = a[0] if a[0] < 0 else -1
for i in range(1, n):
if v * (v + a[i]) < 0:
v += a[i]
else:
if v > 0:
ans2 += abs(v + a[i] + 1)
v = -1
else:
ans2 += abs(v + a[i] - 1)
v = 1
ans = min(ans1, ans2)
print(ans)
if __name__ == '__main__':
solve() | import sys
def solve():
n = int(eval(input()))
a = [int(i) for i in input().split()]
ans1 = scan(a, -1)
ans2 = scan(a, 1)
ans = min(ans1, ans2)
print(ans)
def scan(a, sgn):
if a[0] * sgn > 0:
res = 0
v = a[0]
else:
res = abs(a[0] - sgn)
v = sgn
for ai in a[1:]:
if v * (v + ai) < 0:
v += ai
else:
if v > 0:
res += abs(v + ai + 1)
v = -1
else:
res += abs(v + ai - 1)
v = 1
return res
if __name__ == '__main__':
solve() | p03739 |
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 0
cnt = 0
s = 0
for i in range(n):
if i == 0:
ans += li[i]
if ans > 0:
s = 1
else:
s = -1
else:
ans += li[i]
if ans <= 0 and s == -1:
while True:
ans += 1
cnt += 1
if ans > 0:
s == 1
break
if ans >= 0 and s == 1:
while True:
ans -= 1
cnt += 1
if ans < 0:
s == -1
break
s *= -1
print(cnt) | n = int(eval(input()))
li = list(map(int,input().split()))
ans = 0
cnt = 0
s = 1
for i in range(n):
ans += li[i]
if ans <= 0 and s == -1:
cnt += abs(ans) + 1
ans = 1
if ans >= 0 and s == 1:
cnt += abs(ans) + 1
ans = -1
s *= -1
res1 = cnt
ans = 0
cnt = 0
s = -1
for i in range(n):
ans += li[i]
if ans <= 0 and s == -1:
cnt += abs(ans) + 1
ans = 1
if ans >= 0 and s == 1:
cnt += abs(ans) + 1
ans = -1
s *= -1
res2 = cnt
print((min(res1,res2))) | p03739 |
import copy
n=int(eval(input()))
a=[int(x) for x in input().rstrip().split()]
ac=copy.deepcopy(a)
now=0
ans1=0
for i in range(n):
now+=a[i]
if i%2==0:
if now<=0:
ans1+=abs(now)+1
now=1
else:
if 0<=now:
ans1+=abs(now)+1
now=-1
now=0
ans2=0
for i in range(n):
now+=a[i]
if i%2==0:
if 0<=now:
ans2+=abs(now)+1
now=-1
else:
if now<=0:
ans2+=abs(now)+1
now=1
print((min(ans1,ans2))) | import copy
n=int(eval(input()))
a=[int(x) for x in input().rstrip().split()]
now=0
ans1=0
for i in range(n):
now+=a[i]
if i%2==0:
if now<=0:
ans1+=abs(now)+1
now=1
else:
if 0<=now:
ans1+=abs(now)+1
now=-1
now=0
ans2=0
for i in range(n):
now+=a[i]
if i%2==0:
if 0<=now:
ans2+=abs(now)+1
now=-1
else:
if now<=0:
ans2+=abs(now)+1
now=1
print((min(ans1,ans2))) | p03739 |
n = int(eval(input()))
a_list = list(map(int, input().split()))
total = 0
count = 0
pos_or_neg = True # True = +, False = -
if sum(a_list) >= 0:
if n % 2 == 0:
pos_or_neg = False
else:
pos_or_neg = True
else:
if n % 2 == 0:
pos_or_neg = True
else:
pos_or_neg = False
for a in a_list:
total += a
if pos_or_neg:
while total <= 0:
total += 1
count += 1
pos_or_neg = False
else:
while total >= 0:
total -= 1
count += 1
pos_or_neg = True
print(count) | n = int(eval(input()))
a_list = list(map(int, input().split()))
total = 0
count = 0
pos_or_neg = True # True = +, False = -
for a in a_list:
total += a
if pos_or_neg:
if total <= 0:
count += -total + 1
total += -total + 1
pos_or_neg = False
else:
if total >= 0:
count += total + 1
total -= total + 1
pos_or_neg = True
first_count = count
count = 0
total = 0
pos_or_neg = False
for a in a_list:
total += a
if pos_or_neg:
if total <= 0:
count += -total + 1
total += -total + 1
pos_or_neg = False
else:
if total >= 0:
count += total + 1
total -= total + 1
pos_or_neg = True
print((min(count, first_count))) | p03739 |
n = int(eval(input()))
a = list(map(int, input().split()))
sum = a[0]
count = 0
for i in range(1, n) :
temp = sum
sum += a[i]
if temp > 0 and sum > 0 :
while sum >= 0 :
count += 1
sum -= 1
elif temp < 0 and sum < 0 :
while sum <= 0 :
count += 1
sum += 1
if sum == 0 :
count += 1
print(count)
| n = int(eval(input()))
a = list(map(int, input().split()))
sum = a[0]
count1 = 0
count2 = 0
sum1 = 0
sum2 = 0
for i in range(n) :
sum1 += a[i]
sum2 += a[i]
if i % 2 == 0 :
if sum1 >= 0 :
count1 += abs(sum1) + 1
sum1 = -1
if sum2 <= 0 :
count2 += abs(sum2) + 1
sum2 = 1
elif i % 2 == 1 :
if sum1 <= 0 :
count1 += abs(sum1) + 1
sum1 = 1
if sum2 >= 0 :
count2 += abs(sum2) + 1
sum2 = -1
print((min(count1, count2)))
| p03739 |
n = int(eval(input()))
a = list(map(int,input().split()))
A = [n for n in a]
cnt1 = 0
cnt2 = 0
S = 0
if a[0] > 0:
for i in range(n-1):
S += a[i]
if a[i] > 0:
while S + a[i+1] >= 0:
a[i+1] -= 1
cnt1 += 1
elif a[i] < 0:
while S + a[i+1] <= 0:
a[i+1] += 1
cnt1 += 1
A[0] = -1
cnt2 = a[0] + 1
for i in range(n-1):
S += A[i]
if A[i] > 0:
while S + A[i+1] >= 0:
A[i+1] -= 1
cnt2 += 1
elif A[i] < 0:
while S + A[i+1] <= 0:
A[i+1] += 1
cnt2 += 1
elif a[0] < 0:
for i in range(n-1):
S += a[i]
if a[i] > 0:
while S + a[i+1] >= 0:
a[i+1] -= 1
cnt1 += 1
elif a[i] < 0:
while S + a[i+1] <= 0:
a[i+1] += 1
cnt1 += 1
A[0] = 1
cnt2 = -a[0] + 1
for i in range(n-1):
S += A[i]
if A[i] > 0:
while S + A[i+1] >= 0:
A[i+1] -= 1
cnt2 += 1
elif A[i] < 0:
while S + A[i+1] <= 0:
A[i+1] += 1
cnt2 += 1
else:
a[0] = 1
cnt1 = 1
for i in range(n-1):
S += a[i]
if a[i] > 0:
while S + a[i+1] >= 0:
a[i+1] -= 1
cnt1 += 1
elif a[i] < 0:
while S + a[i+1] <= 0:
a[i+1] += 1
cnt1 += 1
A[0] = -1
cnt2 = 1
for i in range(n-1):
S += A[i]
if A[i] > 0:
while S + A[i+1] >= 0:
A[i+1] -= 1
cnt2 += 1
elif A[i] < 0:
while S + A[i+1] <= 0:
A[i+1] += 1
cnt2 += 1
cnt = cnt2 if cnt1 >= cnt2 else cnt1
print(cnt)
| n = int(eval(input()))
a = list(map(int,input().split()))
S1 = 0
S2 = 0
#S1が奇数番目が正の場合、S2が偶数番目が負の場合
cnt1 = 0
cnt2 = 0
for i,num in enumerate(a):
S1 += num
if i % 2 == 0 and S1 <= 0:
cnt1 += 1 - S1
S1 = 1
if i % 2 != 0 and S1 >= 0:
cnt1 += 1 + S1
S1 = -1
S2 += num
if i % 2 == 0 and S2 >= 0:
cnt2 += 1 + S2
S2 = -1
if i % 2 != 0 and S2 <= 0:
cnt2 += 1 - S2
S2 = 1
print((cnt1 if cnt1 <= cnt2 else cnt2))
| p03739 |
n = int(eval(input()))
a = tuple(list(map(int, input().split())))
#aをtupleにしておかないとb = aとしたときにb変更するとa変更されてしまう リストーのコピー
def puramai(a):
b = list(a)
hikaku = 0
ans = 0
for i in range(n):
if i % 2 == 0 and hikaku + b[i] <= 0:
b[i] = -hikaku+1
ans += abs(b[i]-a[i])
elif i % 2 != 0 and hikaku + b[i] >= 0:
b[i] = -hikaku-1
ans += abs(b[i]-a[i])
hikaku += b[i]
return ans
def maipura(a):
b = list(a)
hikaku = 0
ans = 0
for i in range(n):
if i % 2 == 0 and hikaku + b[i] >= 0:
b[i] = -hikaku-1
ans += abs(b[i]-a[i])
elif i % 2 != 0 and hikaku + b[i] <= 0:
b[i] = -hikaku+1
ans += abs(b[i]-a[i])
hikaku += b[i]
return ans
print((min(maipura(a), puramai(a)))) | N = int(eval(input()))
a = [int(i) for i in input().split()]
def pura(a):
A = a[:]
ans = 0
check = 0
if A[0] <= 0:
ans += 1 + abs(A[0])
A[0] = 1
check += A[0]
for i in range(1, N):
if i % 2 != 0:
if check + A[i] >= 0:
ans += abs(A[i] + 1 + check)
A[i] = -1 - check
else:
if check + A[i] <= 0:
ans += abs(A[i] - (1 - check))
A[i] = 1 - check
check += A[i]
return ans
def mai(a):
A = a[:]
ans = 0
check = 0
if A[0] >= 0:
ans +=1 + abs(A[0])
A[0] = -1
check += A[0]
for i in range(1, N):
if i % 2 != 0:
if check + A[i] <= 0:
ans += abs(A[i] - (1 - check))
A[i] = 1 - check
else:
if check + A[i] >= 0:
ans += abs(A[i] +( 1 + check))
A[i] = -1 - check
check += A[i]
return ans
print((min(pura(a), mai(a)))) | p03739 |
n = int(eval(input()))
al = list(map(int, input().split()))
import itertools
alsum = list(itertools.accumulate(al))
temp1 = 0
temp2 = 0
for i in range(n):
if i % 2 ==0:
if alsum[i] >0:
pass
else:
y = abs(alsum[i])+1
temp1 += y
alsum = list([x +y for x in alsum])
else:
if alsum[i] <0:
pass
else:
y = alsum[i]+1
temp1 += y
alsum = list([x-y for x in alsum])
import itertools
alsum = list(itertools.accumulate(al))
for j in range(n):
if j % 2 ==0:
if alsum[j] <0:
pass
else:
y = abs(alsum[j])+1
temp2 += y
alsum = list([x-y for x in alsum])
else:
if alsum[j] >0:
pass
else:
y = abs(alsum[j])+1
temp2 += y
alsum = list([x+y for x in alsum])
print((min(temp1,temp2))) | n = int(eval(input()))
al = list(map(int, input().split()))
import itertools
alsum = list(itertools.accumulate(al))
temp1 = 0
temp2 = 0
res = 0
for i in range(n):
res += al[i]
if i % 2 ==0:
if res >0:
pass
else:
y = res*(-1)+1
temp1 += y
res =1
else:
if res <0:
pass
else:
y = res+1
temp1 += y
res = -1
res= 0
for j in range(n):
res += al[j]
if j % 2 ==0:
if res <0:
pass
else:
y = res+1
temp2 += y
res = -1
else:
if res >0:
pass
else:
y = res*(-1)+1
temp2 += y
res = 1
print((min(temp1,temp2))) | p03739 |
from itertools import accumulate
n, *A = list(map(int, open(0).read().split()))
B = list(accumulate(A))
p0 = n0 = p1 = n1 = 0
for i, b in enumerate(B):
if i % 2 == 0:
if b+p0-n0 <= 0:
p0 += abs(b+p0-n0)+1
if b+p1-n1 >= 0:
n1 += abs(b+p1-n1)+1
else:
if b+p0-n0 >= 0:
n0 += abs(b+p0-n0)+1
if b+p1-n1 <= 0:
p1 += abs(b+p1-n1)+1
print((min(p0+n0, p1+n1)))
| n = int(eval(input()))
a = list(map(int,input().split()))
def calc(t):
ans = su = 0
for i in range(n):
su += a[i]
if i % 2 == t:
if su > 0:
pass
else:
x = 1 - su
ans += abs(x)
su = 1
else:
if su < 0:
pass
else:
x = - 1 - su
ans += abs(x)
su = -1
return ans
print((min(calc(1), calc(0)))) | p03739 |
n = int(eval(input()))
a = [int(_) for _ in input().split()]
new_a_plus = [a[i] for i in range(n)]
new_a_minus = [a[i] for i in range(n)]
count_plus = 0
if a[0] <= 0:
new_a_plus[0] = 1
count_plus += 1 - a[0]
for i in range(1, n):
if i % 2 == 0:
if sum(new_a_plus[:i+1]) <= 0:
new_a_plus[i] = -sum(new_a_plus[:i])+1
count_plus += new_a_plus[i] - a[i]
else:
if sum(new_a_plus[:i+1]) >= 0:
new_a_plus[i] = -sum(new_a_plus[:i])-1
count_plus += a[i] - new_a_plus[i]
count_minus = 0
if a[0] >= 0:
new_a_minus[0] = -1
count_minus += a[0] + 1
for i in range(1, n):
if i % 2 == 0:
if sum(new_a_minus[:i+1]) >= 0:
new_a_minus[i] = -sum(new_a_minus[:i])-1
count_minus += a[i] - new_a_minus[i]
else:
if sum(new_a_minus[:i+1]) <= 0:
new_a_minus[i] = -sum(new_a_minus[:i])+1
count_minus += new_a_minus[i] - a[i]
print((min(count_plus, count_minus))) | n = int(eval(input()))
a = [int(_) for _ in input().split()]
new_a_plus = [a[i] for i in range(n)]
new_a_minus = [a[i] for i in range(n)]
count_plus = 0
now_total_plus = 0
for i in range(0, n):
if i % 2 == 0:
if now_total_plus + a[i] <= 0:
new_a_plus[i] = - now_total_plus + 1
count_plus += new_a_plus[i] - a[i]
else:
if now_total_plus + a[i] >= 0:
new_a_plus[i] = - now_total_plus - 1
count_plus += a[i] - new_a_plus[i]
now_total_plus += new_a_plus[i]
count_minus = 0
now_total_minus = 0
for i in range(0, n):
if i % 2 == 0:
if now_total_minus + a[i] >= 0:
new_a_minus[i] = - now_total_minus - 1
count_minus += a[i] - new_a_minus[i]
else:
if now_total_minus + a[i] <= 0:
new_a_minus[i] = - now_total_minus + 1
count_minus += new_a_minus[i] - a[i]
now_total_minus += new_a_minus[i]
print((min(count_plus, count_minus))) | p03739 |
from copy import copy
n = int(eval(input()))
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]
b=copy(a)
res_b=0
c=copy(a)
res_c=0
for i in range(n):
if ans1[i]*sum(b[:i+1])>0:
pass
else:
b[i]=ans1[i]-sum(b[:i])
res_b+=abs(b[i]-a[i])
if -1*ans1[i]*sum(c[:i+1])>0:
pass
else:
c[i]=-1*ans1[i]-sum(c[:i])
res_c+=abs(c[i]-a[i])
print((min(res_b,res_c))) | from copy import copy
n = int(eval(input()))
a = [int(x) for x in input().split()]
ans1=[(-1)**i for i in range(n)]
b=copy(a)
res_b=0
sb=0
c=copy(a)
res_c=0
sc=0
for i in range(n):
sb+=a[i]
if ans1[i]*sb>0:
pass
else:
b[i]=ans1[i]-(sb-b[i])
sb=sb-a[i]+b[i]
res_b+=abs(b[i]-a[i])
sc+=a[i]
if -1*ans1[i]*sc>0:
pass
else:
c[i]=-1*ans1[i]-(sc-c[i])
sc=sc-a[i]+c[i]
res_c+=abs(c[i]-a[i])
print((min(res_b,res_c))) | p03739 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = [int(i) for i in input().split()]
# i番目までの和が正(i: 奇数)
res1 = 0
cum = 0
for i in range(n):
cum += a[i]
if i % 2 == 1:
while cum <= 0:
cum += 1
res1 += 1
else:
while cum >= 0:
cum -= 1
res1 += 1
# i番目までの和が負(i: 奇数)
res2 = 0
cum = 0
for i in range(n):
cum += a[i]
if i % 2 == 0:
while cum <= 0:
cum += 1
res2 += 1
else:
while cum >= 0:
cum -= 1
res2 += 1
print((min(res1,res2))) | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = [int(i) for i in input().split()]
# i番目までの和が正(i: 奇数)
res1 = 0
cum = 0
for i in range(n):
cum += a[i]
if i % 2 == 1:
if cum <= 0:
res1 += (1 - cum)
cum = 1
else:
if cum >= 0:
res1 += (cum + 1)
cum = -1
# i番目までの和が正(i: 偶数)
res2 = 0
cum = 0
for i in range(n):
cum += a[i]
if i % 2 == 0:
if cum <= 0:
res2 += (1 - cum)
cum = 1
else:
if cum >= 0:
res2 += (cum + 1)
cum = -1
print((min(res1,res2))) | p03739 |
def sign(x):
if x>0:
return 1
elif x<0:
return -1
else:
return 0
n = int(eval(input()))
a = [int(i) for i in input().split()]
s = [sum(a[:i+1]) for i in range(n)]
sp = [s[i] for i in range(n)]
sm = [s[i] for i in range(n)]
P0=0
M0=0
if s[0]==0:
P0+=1
M0+=1
for j in range(n):
sp[j]+=1
sm[j]+=1
elif s[0]>0:
M0+=abs(s[0]+1)
for j in range(n):
sm[j]-=(abs(s[0])+1)
else:
P0+=abs(s[0]+1)
for j in range(n):
sp[j]+=(abs(s[0])+1)
for i in range(1,n):
if sm[i-1]*sm[i]>=0:
M0+=abs(sm[i])+1
h=sign(sm[i-1])*(-1)*(abs(sm[i])+1)
for j in range(i,n):
sm[j]+=h
if sp[i-1]*sp[i]>=0:
P0+=abs(sp[i])+1
h=sign(sp[i-1])*(-1)*(abs(sp[i])+1)
for j in range(i,n):
sp[j]+=h
print((min([M0,P0])))
| def sign(p):
if p<0:
return -1
elif p>0:
return 1
else:
return 0
N=int(eval(input()))
a=[int(i) for i in input().split()]
m=[0,0]
for sgn in [-1,1]:
x=0
S=0
for i in range(N):
S+=a[i]
if sign(S)==sgn*(-1)**(i%2) or sign(S)==0:
x+=abs(S)+1
S=sgn*(-1)**((i+1)%2)
m[(sgn+1)//2]=x
print((min(m)))
| p03739 |
n=int(eval(input()))
a=list(map(int,input().split()))
# 0 1 2 3 evn odd
# kevn + - + - + -
# kodd - + - + - +
a0=a[0]
if a0<0:
kevn=1-a0
sevn=1
elif a0==0:
kevn=1
sevn=1
elif a0>0:
kevn=0
sevn=a0
for i in range(1,n):
ai=a[i]
if i%2==0:
if sevn+ai<0:
kevn=kevn+1-(ai+sevn)
sevn=1
elif sevn+ai==0:
kevn=kevn+1
sevn=1
elif sevn+ai>0:
kevn=kevn
sevn=sevn+ai
elif i%2==1:
if sevn+ai<0:
kevn=kevn
sevn=sevn+ai
elif sevn+ai==0:
kevn=kevn+1
sevn=-1
elif sevn+ai>0:
kevn=kevn+1+(ai+sevn)
sevn=-1
kevn1=kevn
a0=-a[0]
if a0<0:
kevn=1-a0
sevn=1
elif a0==0:
kevn=1
sevn=1
elif a0>0:
kevn=0
sevn=a0
for i in range(1,n):
ai=-a[i]
if i%2==0:
if sevn+ai<0:
kevn=kevn+1-(ai+sevn)
sevn=1
elif sevn+ai==0:
kevn=kevn+1
sevn=1
elif sevn+ai>0:
kevn=kevn
sevn=sevn+ai
elif i%2==1:
if sevn+ai<0:
kevn=kevn
sevn=sevn+ai
elif sevn+ai==0:
kevn=kevn+1
sevn=-1
elif sevn+ai>0:
kevn=kevn+1+(ai+sevn)
sevn=-1
kevn=min(kevn,kevn1)
print(kevn)
| n=int(eval(input()))
a=list(map(int,input().split()))
# 0 1 2 3 evn odd
# kevn + - + - + -
# kodd - + - + - +
def kf(a,flag,n):
a0=a[0]*flag
if a0<=0:
kevn=1-a0
sevn=1
elif a0>0:
kevn=0
sevn=a0
for i in range(1,n):
ai=a[i]*flag
if i%2==0:
if sevn+ai<=0:
kevn=kevn+1-(ai+sevn)
sevn=1
elif sevn+ai>0:
kevn=kevn
sevn=sevn+ai
elif i%2==1:
if sevn+ai<0:
kevn=kevn
sevn=sevn+ai
elif sevn+ai>=0:
kevn=kevn+1+(ai+sevn)
sevn=-1
return kevn
print((min(kf(a,1,n),kf(a,-1,n))))
| p03739 |
n = int(eval(input()))
a = list(map(int, input().split()))
minA = 0
sumA = 0
# 奇数項を正としたときの操作回数minA
for i in range(n):
sumA += a[i]
if i%2 == 0:
if sumA <= 0:
minA += abs(sumA)+1
sumA += abs(sumA)+1
else:
if sumA >= 0:
minA += abs(sumA)+1
sumA -= abs(sumA)+1
temp = 0
# 偶数項を正としたときの操作回数minB
minB = 0
sumB = 0
for i in range(n):
sumB += a[i]
if i%2 != 0:
if sumB <= 0:
minB += abs(sumB)+1
sumB += abs(sumB)+1
else:
if sumB >= 0:
minB += abs(sumB)+1
sumB -= abs(sumB)+1
print((min(minA, minB))) | def F(list_A, sign):
total = 0
cnt = 0
for a in list_A:
total += a
if sign==True and total < 1:
cnt += 1- total
total = 1
elif sign==False and total > -1:
cnt += total + 1
total = -1
sign = not sign
return cnt
N = int(eval(input()))
A = list(map(int, input().split()))
ans = min(F(A, True), F(A, False))
print(ans) | p03739 |
import copy
n = int(eval(input()))
a = list(map(int,input().split()))
b = copy.copy(a)
#sum_a = []
#sum_b = []
ans_a = 0
ans_b = 0
for i in range(n):
if i%2==0:
if sum(a[:i+1])>0:
#sum_a.append(sum(a[:i+1]))
tmp = 0
else:
tmp = abs(sum(a[:i+1]))+1
a[i] += tmp
ans_a += tmp
#sum_a.append(sum(a[:i+1]))
else:
if sum(a[:i+1])<0:
#sum_a.append(sum(a[:i+1]))
tmp = 0
else:
tmp = abs(sum(a[:i+1]))+1
a[i] -= tmp
ans_a += tmp
#sum_a.append(sum(a[:i+1]))
if i%2==1:
if sum(b[:i+1])>0:
#sum_b.append(sum(b[:i+1]))
tmp = 0
else:
tmp = abs(sum(b[:i+1]))+1
b[i] += tmp
ans_b += tmp
#sum_b.append(sum(b[:i+1]))
else:
if sum(b[:i+1])<0:
#sum_b.append(sum(b[:i+1]))
tmp = 0
else:
tmp = abs(sum(b[:i+1]))+1
b[i] -= tmp
ans_b += tmp
#sum_b.append(sum(b[:i+1]))
#print(a)
#print(sum_a)
print((min(ans_a,ans_b))) | import copy
n = int(eval(input()))
a = list(map(int,input().split()))
b = copy.copy(a)
ans_a = 0
ans_b = 0
sum_a = 0
sum_b = 0
for i in range(n):
if i%2==0:
if sum_a+a[i]>0:
tmp = 0
else:
tmp = abs(sum_a+a[i])+1
a[i] += tmp
ans_a += tmp
else:
if sum_a+a[i]<0:
tmp = 0
else:
tmp = abs(sum_a+a[i])+1
a[i] -= tmp
ans_a += tmp
sum_a+=a[i]
if i%2==1:
if sum_b+b[i]>0:
tmp = 0
else:
tmp = abs(sum_b+b[i])+1
b[i] += tmp
ans_b += tmp
else:
if sum_b+b[i]<0:
tmp = 0
else:
tmp = abs(sum_b+b[i])+1
b[i] -= tmp
ans_b += tmp
sum_b+=b[i]
#print(a)
#print(sum_a)
print((min(ans_a,ans_b))) | p03739 |
from collections import defaultdict
def solve(pre_is_positive, total, ans, a_list):
for a in a_list:
total += a
if pre_is_positive:
if total == 0:
ans += 1
total = -1
elif total > 0:
ans += abs(total) + 1
total = -1
elif not pre_is_positive:
if total == 0:
ans += 1
total = 1
elif total < 0:
ans += abs(total) + 1
total = 1
pre_is_positive = total > 0
return ans
def main():
n = int(eval(input()))
a_list = list(map(int, input().split()))
total = a_list[0]
if total == 0:
ans = solve(True, 1, 1, a_list[1:])
ans = min(ans, solve(False, -1, 1, a_list[1:]))
elif total > 0:
ans = solve(True, total, 0, a_list[1:])
ans = min(ans, solve(False, -1, abs(total) + 1, a_list[1:]))
else:
ans = solve(False, total, 0, a_list[1:])
ans = min(ans, solve(True, 1, abs(total) + 1, a_list[1:]))
print(ans)
if __name__ == '__main__':
main()
| from collections import defaultdict
def solve(pre_is_positive, a_list):
total = 0
ans = 0
for a in a_list:
total += a
if pre_is_positive and total >= 0:
ans += abs(total) + 1
total = -1
elif not pre_is_positive and total <= 0:
ans += abs(total) + 1
total = 1
pre_is_positive = total > 0
return ans
def main():
n = int(eval(input()))
a_list = list(map(int, input().split()))
print((min(solve(True, a_list), solve(False, a_list))))
if __name__ == '__main__':
main()
| p03739 |
n = int(eval(input()))
a = list(map(int,input().split()))
sum1 = sum2 = cost1 = cost2 = 0
for i in range(n):
cur = a[i]
sum1 += cur
if (sum1<=0, sum1>=0)[i%2]:
cost1 += 1+sum1*[-1,1][i%2]
sum1 = [1,-1][i%2]
sum2 += cur
if (sum2>=0, sum2<=0)[i%2]:
cost2 += 1+sum2*[1,-1][i%2]
sum2 = [-1,1][i%2]
print((min(cost1, cost2))) | def solve():
n = int(eval(input()))
a = list(map(int,input().split()))
sum1 = sum2 = cost1 = cost2 = 0
for i in range(n):
cur = a[i]
sum1 += cur
if (sum1<=0, sum1>=0)[i%2]:
cost1 += 1+sum1*[-1,1][i%2]
sum1 = [1,-1][i%2]
sum2 += cur
if (sum2>=0, sum2<=0)[i%2]:
cost2 += 1+sum2*[1,-1][i%2]
sum2 = [-1,1][i%2]
print((min(cost1, cost2)))
if __name__ == '__main__':
solve() | p03739 |
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
sm, r1 = 0, 0
for n in range(N):
sm += A[n]
if n % 2 == 0 and sm < 1:
r1 += abs(sm) + 1
sm = 1
elif n % 2 != 0 and sm > -1:
r1 += abs(sm) + 1
sm = -1
sm, r2 = 0, 0
for n in range(N):
sm += A[n]
if n % 2 == 0 and sm > -1:
r2 += abs(sm) + 1
sm = -1
elif n % 2 != 0 and sm < 1:
r2 += abs(sm) + 1
sm = 1
print((min(r1, r2)))
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
# 偶数番目の合計を負
# 奇数番目の合計を正にするパターン
sm, r1 = 0, 0
for n in range(N):
sm += A[n]
if n % 2 == 0 and sm < 1:
r1 += abs(sm) + 1
sm = 1
elif n % 2 != 0 and sm > -1:
r1 += abs(sm) + 1
sm = -1
# 偶数番目の合計を正
# 奇数番目の合計を負にするパターン
sm, r2 = 0, 0
for n in range(N):
sm += A[n]
if n % 2 == 0 and sm > -1:
r2 += abs(sm) + 1
sm = -1
elif n % 2 != 0 and sm < 1:
r2 += abs(sm) + 1
sm = 1
# 操作数が小さいほうを出力
print((min(r1, r2)))
if __name__ == '__main__':
main()
| p03739 |
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
# 偶数番目の合計を負
# 奇数番目の合計を正にするパターン
sm, r1 = 0, 0
for n in range(N):
sm += A[n]
if n % 2 == 0 and sm < 1:
r1 += abs(sm) + 1
sm = 1
elif n % 2 != 0 and sm > -1:
r1 += abs(sm) + 1
sm = -1
# 偶数番目の合計を正
# 奇数番目の合計を負にするパターン
sm, r2 = 0, 0
for n in range(N):
sm += A[n]
if n % 2 == 0 and sm > -1:
r2 += abs(sm) + 1
sm = -1
elif n % 2 != 0 and sm < 1:
r2 += abs(sm) + 1
sm = 1
# 操作数が小さいほうを出力
print((min(r1, r2)))
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
cnt, q1 = 0, 0
ism = False
for a in A:
cnt += a
if ism and cnt >= 0:
q1 += abs(cnt) + 1
cnt = -1
elif not ism and cnt <= 0:
q1 += abs(cnt) + 1
cnt = 1
if ism:
ism = False
else:
ism = True
cnt , q2 = 0, 0
ism = True
for a in A:
cnt += a
if ism and cnt >= 0:
q2 += abs(cnt) + 1
cnt = -1
elif not ism and cnt <= 0:
q2 += abs(cnt) + 1
cnt = 1
if ism:
ism = False
else:
ism = True
print((min(q1,q2)))
if __name__ == '__main__':
main()
| p03739 |
eval(input())
iter_ = iter(map(int, input().rstrip("\n").split()))
sum_ = next(iter_)
ans = 0
for num in iter_:
if sum_ == 0:
sum_ += 1
ans += 1
presum = sum_
sum_ += num
while presum * sum_ >= 0:
sum_ += -1 if presum > 0 else 1
ans += 1
print(ans) | eval(input())
seq = list(map(int, input().rstrip("\n").split()))
iter_ = iter(seq)
ans1 = 0
for i, num in enumerate(iter_):
if i == 0:
sum_ = num
if sum_ > 0:
pass
else:
ans1 += abs(sum_ - 1)
sum_ = 1
else:
sum_ += num
if i % 2:
if sum_ < 0:
pass
else:
ans1 += abs(sum_ + 1)
sum_ = -1
else:
if sum_ > 0:
pass
else:
ans1 += abs(sum_ - 1)
sum_ = 1
iter_ = iter(seq)
ans2 = 0
for i, num in enumerate(iter_):
if i == 0:
sum_ = num
if sum_ < 0:
pass
else:
ans2 += abs(sum_ + 1)
sum_ = -1
else:
sum_ += num
if i % 2:
if sum_ > 0:
pass
else:
ans2 += abs(sum_ - 1)
sum_ = 1
else:
if sum_ < 0:
pass
else:
ans2 += abs(sum_ + 1)
sum_ = -1
print((min(ans1, ans2)))
| p03739 |
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,fractions
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
def inpl_str(): return list(sys.stdin.readline().split())
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
n = inp()
a = inpl()
acc = list(itertools.accumulate(a))
#+-+-+-
cnt = 0
tmp = 0
for i in range(n):
if i%2==0:
tt = acc[i] + tmp
if tt <= 0:
cnt += 1 - tt
tmp += 1 - tt
else:
tt = acc[i] + tmp
if tt >= 0:
cnt += tt + 1
tmp -= tt + 1
ans = cnt
#-+-+-+
cnt = 0
tmp = 0
for i in range(n):
if i%2:
tt = acc[i] + tmp
if tt <= 0:
cnt += 1 - tt
tmp += 1 - tt
else:
tt = acc[i] + tmp
if tt >= 0:
cnt += tt + 1
tmp -= tt + 1
# print(i,cnt,tmp,tt)
print((min(ans,cnt))) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
now = 0
res = INF
cnt = 0
for i in range(n):
now += a[i]
if i%2 == 0:
if now <= 0:
cnt += 1-now
now = 1
else:
if now >= 0:
cnt += now+1
now = -1
# print(i,now,cnt)
res = min(res,cnt)
now = 0
cnt = 0
for i in range(n):
now += a[i]
if i%2:
if now <= 0:
cnt += -now + 1
now = 1
else:
if now >= 0:
cnt += now + 1
now = -1
# print(i,now,cnt)
res = min(res,cnt)
print(res) | p03739 |
# -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
if S<0 and S+int(a[i])<=0:
counter_1+=-S-int(a[i])+1
a[i]=-S+1
elif S>0 and S+int(a[i])>=0:
counter_1+=S+int(a[i])+1
a[i]=-S-1
S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
if S<0 and S+int(b[i])<=0:
counter_2+=-S-int(b[i])+1
b[i]=-S+1
elif S>0 and S+int(b[i])>=0:
counter_2+=S+int(b[i])+1
b[i]=-S-1
S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
if S<0 and S+int(c[i])<=0:
counter_3+=-S-int(c[i])+1
c[i]=-S+1
elif S>0 and S+int(c[i])>=0:
counter_3+=S+int(c[i])+1
c[i]=-S-1
S+=int(c[i])
print((min(counter_1,counter_2,counter_3))) | # -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
if S<0 and S+int(a[i])<=0:
counter_1+=-S-int(a[i])+1
a[i]=-S+1
elif S>0 and S+int(a[i])>=0:
counter_1+=S+int(a[i])+1
a[i]=-S-1
S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
if S<0 and S+int(b[i])<=0:
counter_2+=-S-int(b[i])+1
b[i]=-S+1
elif S>0 and S+int(b[i])>=0:
counter_2+=S+int(b[i])+1
b[i]=-S-1
S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
if S<0 and S+int(c[i])<=0:
counter_3+=-S-int(c[i])+1
c[i]=-S+1
elif S>0 and S+int(c[i])>=0:
counter_3+=S+int(c[i])+1
c[i]=-S-1
S+=int(c[i])
print((min(counter_1,counter_2,counter_3))) | p03739 |
# -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
if S<0 and S+int(a[i])<=0:
counter_1+=-S-int(a[i])+1
a[i]=-S+1
elif S>0 and S+int(a[i])>=0:
counter_1+=S+int(a[i])+1
a[i]=-S-1
S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
if S<0 and S+int(b[i])<=0:
counter_2+=-S-int(b[i])+1
b[i]=-S+1
elif S>0 and S+int(b[i])>=0:
counter_2+=S+int(b[i])+1
b[i]=-S-1
S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
if S<0 and S+int(c[i])<=0:
counter_3+=-S-int(c[i])+1
c[i]=-S+1
elif S>0 and S+int(c[i])>=0:
counter_3+=S+int(c[i])+1
c[i]=-S-1
S+=int(c[i])
print((min(counter_1,counter_2,counter_3))) | # -*- coding: utf-8 -*-
# 整数の入力
n=int(eval(input()))
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
if S<0 and S+a[i]<=0:
counter_1+=-S-a[i]+1
a[i]=-S+1
elif S>0 and S+a[i]>=0:
counter_1+=S+a[i]+1
a[i]=-S-1
S+=a[i]
# a[0]を1に変えた場合の計算
counter_2=abs(b[0]-1)
b[0]=1
S=b[0]
for i in range(1,n):
if S<0 and S+b[i]<=0:
counter_2+=-S-b[i]+1
b[i]=-S+1
elif S>0 and S+b[i]>=0:
counter_2+=S+b[i]+1
b[i]=-S-1
S+=b[i]
# a[0]を-1に変えた場合の計算
counter_3=abs(c[0]+1)
c[0]=-1
S=c[0]
for i in range(1,n):
if S<0 and S+c[i]<=0:
counter_3+=-S-c[i]+1
c[i]=-S+1
elif S>0 and S+c[i]>=0:
counter_3+=S+c[i]+1
c[i]=-S-1
S+=c[i]
print((min(counter_1,counter_2,counter_3))) | p03739 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
n = NI()
bit = [0] * (n+1)
A = LI()
def add(i,x):
while i <= n:
bit[i] += x
i += i & -i
def query(i):
x = 0
while i > 0:
x += bit[i]
i -= i & -i
return x
for i,a in enumerate(A):
add(i+1,int(a))
ans = INF
bit_c = copy.deepcopy(bit)
for s in (1,-1):
bit = copy.deepcopy(bit_c)
cnt = 0
x = s
for i in range(1,n+1):
z = query(i)
if z * x <= 0:
add(i,x-z)
cnt += abs(x-z)
x = -x
ans = min(ans,cnt)
print(ans)
if __name__ == '__main__':
main() | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
n = NI()
bit = [0] * (n+1)
def add(i,x):
while i <= n:
bit[i] += x
i += i & -i
def query(i):
x = 0
while i > 0:
x += bit[i]
i -= i & -i
return x
for i,a in enumerate(LI()):
add(i+1,int(a))
ans = INF
b = [bit,copy.copy(bit)]
for s in (1,-1):
bit = b[(s+1)//2]
cnt = 0
x = s
for i in range(1,n+1):
z = query(i)
if z * x <= 0:
add(i,x-z)
cnt += abs(x-z)
x = -x
ans = min(ans,cnt)
print(ans)
if __name__ == '__main__':
main() | p03739 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
n = NI()
bit = [0] * (n+1)
def add(i,x):
while i <= n:
bit[i] += x
i += i & -i
def query(i):
x = 0
while i > 0:
x += bit[i]
i -= i & -i
return x
for i,a in enumerate(LI()):
add(i+1,int(a))
ans = INF
b = [bit,copy.copy(bit)]
for s in (1,-1):
bit = b[(s+1)//2]
cnt = 0
x = s
for i in range(1,n+1):
z = query(i)
if z * x <= 0:
add(i,x-z)
cnt += abs(x-z)
x = -x
ans = min(ans,cnt)
print(ans)
if __name__ == '__main__':
main() | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
n = NI()
a = LI()
ans = INF
for s in (1,-1):
acc = 0
cnt = 0
x = s
for i in range(n):
acc += a[i]
if acc * x <= 0:
cnt += abs(x-acc)
acc = x
x = -x
ans = min(ans,cnt)
print(ans)
if __name__ == '__main__':
main() | p03739 |
N = int(eval(input()))
A = list(map(int, input().split()))
currentSum = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in range(N):
restSum = currentSum
currentSum += A[i]
if currentSum <= 0 and restSum < 0:
count1 += abs(currentSum) + 1
currentSum = 1
elif currentSum >= 0 and restSum > 0:
count1 += abs(currentSum) + 1
currentSum = -1
elif currentSum == 0 and restSum == 0:
count1 += 1
currentSum = -1
currentSum = 0
for i in range(N):
restSum = currentSum
currentSum += A[i]
if currentSum <= 0 and restSum < 0:
count2 += abs(currentSum) + 1
currentSum = 1
elif currentSum >= 0 and restSum > 0:
count2 += abs(currentSum) + 1
currentSum = -1
elif currentSum == 0 and restSum == 0:
count2 += 1
currentSum = 1
currentSum = 0
for i in range(N):
restSum = currentSum
currentSum += A[i]
if currentSum <= 0 and restSum < 0:
count3 += abs(currentSum) + 1
currentSum = 1
elif currentSum >= 0 and restSum > 0:
count3 += abs(currentSum) + 1
currentSum = -1
elif A[i] <= 0 and restSum == 0:
count3 += abs(currentSum) + 1
currentSum = 1
currentSum = 0
for i in range(N):
restSum = currentSum
currentSum += A[i]
if currentSum <= 0 and restSum < 0:
count4 += abs(currentSum) + 1
currentSum = 1
elif currentSum >= 0 and restSum > 0:
count4 += abs(currentSum) + 1
currentSum = -1
elif A[i] >= 0 and restSum == 0:
count4 += abs(currentSum) + 1
currentSum = -1
print((min(count1, count2, count3, count4)))
| N = int(eval(input()))
A = list(map(int, input().split()))
currentSum = 0
count3 = 0
count4 = 0
currentSum = 0
for i in range(N):
restSum = currentSum
currentSum += A[i]
if currentSum <= 0 and restSum < 0:
count3 += abs(currentSum) + 1
currentSum = 1
elif currentSum >= 0 and restSum > 0:
count3 += abs(currentSum) + 1
currentSum = -1
elif A[i] <= 0 and restSum == 0:
count3 += abs(currentSum) + 1
currentSum = 1
currentSum = 0
for i in range(N):
restSum = currentSum
currentSum += A[i]
if currentSum <= 0 and restSum < 0:
count4 += abs(currentSum) + 1
currentSum = 1
elif currentSum >= 0 and restSum > 0:
count4 += abs(currentSum) + 1
currentSum = -1
elif A[i] >= 0 and restSum == 0:
count4 += abs(currentSum) + 1
currentSum = -1
print((min(count3, count4)))
| p03739 |
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
if a[0] < 0:
flag = -1
else:
flag = 1
for i in range(1,n):
if flag == -1:
if sum(a[0:i]) + a[i] <= 0:
cnt += -(sum(a[0:i]) + a[i]) + 1
a[i] = -sum(a[0:i]) + 1
flag = 1
elif flag == 1:
if sum(a[0:i]) + a[i] >= 0:
cnt += sum(a[0:i]) + a[i] + 1
a[i] = -sum(a[0:i]) - 1
flag = -1
print(cnt) | n = int(eval(input()))
a = list(map(int,input().split()))
ans1,ans2 = 0,0
sum1,sum2 = 0,0
for i in range(n):
sum1 += a[i]
if i%2 == 1 and sum1 >= 0:
ans1 += sum1 + 1
sum1 = -1
elif i%2 == 0 and sum1 <= 0:
ans1 += -sum1 + 1
sum1 = 1
for i in range(n):
sum2 += a[i]
if i%2 == 0 and sum2 >= 0:
ans2 += sum2 + 1
sum2 = -1
elif i%2 == 1 and sum2 <= 0:
ans2 += -sum2 + 1
sum2 = 1
print((min(ans1,ans2))) | p03739 |
n = int(eval(input()))
a = list(map(int, input().split(" ")))
res1 = 0
sum = 0
# sei, hu, sei, hu....
# guu, ki, guu, ki
for i in range(n):
sum += a[i]
if sum <= 0 and i%2 == 0:
res1 += abs(sum) + 1
sum = 1
elif sum >= 0 and i%2 == 1:
res1 += abs(sum) + 1
sum = -1
# hutuunitoku
res2 = 0
sum = 0
# hu, sei, hu, sei....
# guu, ki, guu, ki
for i in range(n):
sum += a[i]
if sum <= 0 and i%2 == 1:
res2 += abs(sum) + 1
sum = 1
elif sum >= 0 and i%2 == 0:
res2 += abs(sum) + 1
sum = -1
# hutuunitoku
print((min(res1, res2)))
|
n = int(eval(input()))
a = list(map(int, input().split(" ")))
def solve(s1, s2):
"if start == true, assume the first of the sum is positive."
res = 0
sum = 0
for i in range(n):
sum += a[i]
if sum <= 0 and i % 2 == s1:
res += abs(sum) + 1
sum = 1
elif sum >= 0 and i % 2 == s2:
res += abs(sum) + 1
sum = -1
return res
print((min(solve(0, 1), solve(1, 0))))
| p03739 |
n = int(eval(input()))
A = list(map(int,input().split()))
ans = 10**15
for i in [-1,1]:
ansi,sum=0,0
for a in A:
sum+=a
if sum*i<=0:
ansi+=abs(sum-i)
sum=i
i*=-1
ans=min(ans,ansi)
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 10**15
for s in [1,-1]:
cos = 0
tot = 0
for a in A:
tot+=a
if s*tot<=0:
cos+=abs(tot-s)
tot=s
s*=-1
ans=min(ans,cos)
print(ans) | p03739 |
N = int(eval(input()))
src = list(map(int, input().split()))
sum1 = sum2 = src[0]
op1 = op2 = 0
if sum1 < 1:
op1 += (1 - sum1)
sum1 = 1
if sum2 > -1:
op2 += (sum2 + 1)
sum2 = -1
for i in range(1,N):
if i%2 == 1:
if sum1 + src[i] > -1:
op1 += (sum1 + src[i] + 1)
sum1 = -1
else:
sum1 += src[i]
if sum2 + src[i] < 1:
op2 += (1 - sum2 - src[i])
sum2 = 1
else:
sum2 += src[i]
else:
if sum2 + src[i] > -1:
op2 += (sum2 + src[i] + 1)
sum2 = -1
else:
sum2 += src[i]
if sum1 + src[i] < 1:
op1 += (1 - sum1 - src[i])
sum1 = 1
else:
sum1 += src[i]
print((min(op1,op2)))
| N = int(eval(input()))
src = list(map(int,input().split()))
cum1 = cum2 = 0
ans1 = ans2 = 0
for i,a in enumerate(src):
cum1 += a
cum2 += a
if i%2:
if cum1 >= 0:
ans1 += cum1+1
cum1 = -1
if cum2 <= 0:
ans2 += 1-cum2
cum2 = 1
else:
if cum1 <= 0:
ans1 += 1-cum1
cum1 = 1
if cum2 >= 0:
ans2 += cum2+1
cum2 = -1
print((min(ans1,ans2)))
| p03739 |
N = int(eval(input()))
A = list(map(int,input().split()))
ans1 = c = 0
for i,a in enumerate(A):
c += a
if i%2:
if c < 1:
ans1 += 1-c
c = 1
else:
if c > -1:
ans1 += c+1
c = -1
ans2 = c = 0
for i,a in enumerate(A):
c += a
if i%2==0:
if c < 1:
ans2 += 1-c
c = 1
else:
if c > -1:
ans2 += c+1
c = -1
print((min(ans1,ans2))) | N = int(eval(input()))
A = list(map(int,input().split()))
ans1 = 0
s = 0
for i,a in enumerate(A):
s += a
if i%2:
if s > -1:
ans1 += s+1
s = -1
else:
if s < 1:
ans1 += 1-s
s = 1
ans2 = 0
s = 0
for i,a in enumerate(A):
s += a
if i%2==0:
if s > -1:
ans2 += s+1
s = -1
else:
if s < 1:
ans2 += 1-s
s = 1
print((min(ans1, ans2))) | p03739 |
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#Binary Indexed Tree (1-index!!!!!!!!)
class BinaryIndexedTree():
def __init__(self, size):
self.__node=[0]*(size+1)
self.size = size
#node[index]にvalueを足して、BITを更新
def add(self, index, value):
while index <= self.size:
self.__node[index] += value
index += index&-index
#indexまでの和を返す
def sum(self, index):
ret = 0 #零元・単位元
while index > 0:
ret += self.__node[index]
index -= index&-index
return ret
def update_max(self, index, value):
while index <= self.size:
self.__node[index] = max(self.__node[index], value)
index += index & -index
#indexまでの最大値を返す
def query_max(self, index):
ret = 0
while index > 0:
ret = max(ret, self.__node[index])
index -= index & -index
return ret
#0-indexでの添字を受け取って、1-indexでの添字での値を返す
def get_node(self, index):
return self.__node[index]
def main():
N=I()
A=LI()
def solve(is_minus):
B=BinaryIndexedTree(N)
# print(is_minus)
for i,a in enumerate(A,start=1):
B.add(i,a)
res = 0
for i in range(1,N+1):
s = B.sum(i)
# print("sum",B.sum(i),"is_minus",is_minus)
if is_minus:
if s>=0:
res += abs(s-(-1))
B.add(i,(-1-s))
else:
if s<=0:
res += abs(s-1)
B.add(i,abs(s-1))
# print(res)
is_minus ^= 1
return res
ans = min(solve(True), solve(False))
print(ans)
# *cumsum, = accumulate(A)
# print(cumsum)/
if __name__ == '__main__':
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
N=I()
A=LI()
def solve(is_minus):
now = 0
res = 0
for a in A:
now += a
if is_minus:#累積和が負でないといけない
if now >= 0:#負じゃない
res += abs(now-(-1))
now = -1
else:#累積和が負でないといけない
if now <= 0:#負じゃない
res += abs(now-1)
now = 1
is_minus ^= 1 #true/falseを反転
return res
ans = min(solve(True), solve(False)) ##ポケットモンスター 奇数から始める/偶数から始める
print(ans)
if __name__ == '__main__':
main()
| p03739 |
def f(flg, an):
accum = 0
ret = 0
for i, ai in enumerate(an):
accum += ai
if i % 2:
if flg and 0 <= accum:
ret += accum + 1
accum = -1
elif not flg and accum <= 0:
ret += -accum + 1
accum = 1
else:
if flg and accum <= 0:
ret += -accum + 1
accum = 1
elif not flg and 0 <= accum:
ret += accum + 1
accum = -1
return ret
def main():
n, *an = list(map(int, open(0).read().split()))
print((min(f(0, an), f(1, an))))
return
main()
| def f(flg, an):
accum = 0
ret = 0
for i, ai in enumerate(an):
accum += ai
if flg:
flg = False
if accum <= 0:
ret += -accum + 1
accum = 1
else:
flg = True
if 0 <= accum:
ret += accum + 1
accum = -1
return ret
def main():
n, *an = list(map(int, open(0).read().split()))
print((min(f(False, an), f(True, an))))
return
main()
| p03739 |
n=int(eval(input()))
a=list(map(int,input().split()))
b=a[:]
for i in range(n):
if i%2:b[i]=min(-sum(b[j] for j in range(i))-1,b[i])
else: b[i]=max(-sum(b[j] for j in range(i))+1,b[i])
s=sum(abs(b[i]-a[i]) for i in range(n))
c=a[:]
for i in range(n):
if i%2:c[i]=max(-sum(c[j] for j in range(i))+1,c[i])
else: c[i]=min(-sum(c[j] for j in range(i))-1,c[i])
t=sum(abs(c[i]-a[i]) for i in range(n))
print((min(s,t))) | n=int(eval(input()))
a=list(map(int,input().split()))
s1=c1=s2=c2=0
for i in range(n):
if i%2:
c1+=max(0,a[i]+s1+1); s1+=min(-s1-1,a[i])
c2+=max(0,-s2+1-a[i]); s2+=max(-s2+1,a[i])
else:
c1+=max(0,-s1+1-a[i]); s1+=max(-s1+1,a[i])
c2+=max(0,a[i]+s2+1); s2+=min(-s2-1,a[i])
print((min(c1,c2))) | p03739 |
import itertools
n = int(eval(input()))
a = list(map(int,input().split()))
sum = list(itertools.accumulate(a))
#'+-+-...'と'-+-+...'でそれぞれ求める
res1 = 0
res2 = 0
dif1 = 0
dif2 = 0
for i in range(n):
s = sum[i] + dif1
t = sum[i] + dif2
if i%2==0:
if s<1:
dif1 += 1 - s
res1 += 1 - s
if t>-1:
dif2 -= 1 + t
res2 += 1 + t
else:
if s>-1:
dif1 -= 1 + s
res1 += 1 + s
if t<1:
dif2 += 1 - t
res2 += 1 - t
#print(dif1,res1,dif2,res2)
print((min(res1,res2)))
#print(res1,res2)
| import itertools
n = int(eval(input()))
a = list(map(int,input().split()))
#'+-+-...'と'-+-+...'でそれぞれ求める
res1 = 0
res2 = 0
dif1 = 0
dif2 = 0
for i,j in enumerate(itertools.accumulate(a)):
s = j + dif1
t = j + dif2
if i%2==0:
if s<1:
dif1 += 1 - s
res1 += 1 - s
if t>-1:
dif2 -= 1 + t
res2 += 1 + t
else:
if s>-1:
dif1 -= 1 + s
res1 += 1 + s
if t<1:
dif2 += 1 - t
res2 += 1 - t
print((min(res1,res2)))
| p03739 |
n = int(eval(input()))
a = list(map(int,input().split()))
s = []
for i in range(n):
s.append(sum(a[0:i+1]))
count = 0
ans1 = 0
for i in range(n):
if i%2 == 0:
if s[i]+count > 0:
continue
else:
ans1 += 1-(s[i]+count)
count += 1-(s[i]+count)
else:
if s[i]+count < 0:
continue
else:
ans1 += (s[i]+count) + 1
count -= (s[i]+count) + 1
count1 = 0
ans2 = 0
for i in range(n):
if i%2 == 1:
if s[i]+count1 > 0:
continue
else:
ans2 += 1-(s[i]+count1)
count1 += 1-(s[i]+count1)
else:
if s[i]+count1 < 0:
continue
else:
ans2 += (s[i]+count1) + 1
count1 -= (s[i]+count1) + 1
print((min(ans1,ans2)))
| n = int(eval(input()))
a = list(map(int,input().split()))
s = []
for i in range(n):
if i == 0:
s.append(a[0])
else:
s.append(a[i]+s[-1])
count = 0
ans1 = 0
for i in range(n):
if i%2 == 0:
if s[i]+count > 0:
continue
else:
ans1 += 1-(s[i]+count)
count += 1-(s[i]+count)
else:
if s[i]+count < 0:
continue
else:
ans1 += (s[i]+count) + 1
count -= (s[i]+count) + 1
count1 = 0
ans2 = 0
for i in range(n):
if i%2 == 1:
if s[i]+count1 > 0:
continue
else:
ans2 += 1-(s[i]+count1)
count1 += 1-(s[i]+count1)
else:
if s[i]+count1 < 0:
continue
else:
ans2 += (s[i]+count1) + 1
count1 -= (s[i]+count1) + 1
print((min(ans1,ans2)))
| p03739 |
# -*- coding: utf-8 -*-
n = int(eval(input()))
a = list(map(int, input().split()))
def solve(bl):
if bl:
tmp = -1
else:
tmp = 0
sm = 0
cnt = 0
for i, ele in enumerate(a):
sm += ele
if i % 2 + tmp:
if sm < 1:
cnt += 1 - sm
sm = 1
else:
if sm > -1:
cnt += sm + 1
sm = -1
return cnt
ans = min(solve(True), solve(False))
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
sm = a[0]
def f(sm):
ret = 0
for e in a[1:]:
if sm * (sm + e) < 0:
sm += e
continue
else:
if sm > 0:
a_mx = -sm - 1
ret += e - a_mx
sm += a_mx
else:
a_mn = -sm + 1
ret += a_mn - e
sm += a_mn
return ret
if sm > 0:
ans = min(f(sm), f(-1) + sm + 1)
elif sm < 0:
ans = min(f(sm), f(1) - sm + 1)
else:
ans = min(f(1), f(-1)) + 1
print(ans)
| p03739 |
n = int(eval(input()))
a = [int(i) for i in input().split()]
b = a[:]
s1 = s2 = 0
for i in range(n):
c = sum(a[0:i+1])
if (i % 2 == 0 and c <= 0):
s1 += abs(c) + 1
a[i] += abs(c) + 1
elif(i % 2 == 1 and c >= 0):
s1 += abs(c) + 1
a[i] -= abs(c) + 1
for i in range(n):
c = sum(b[0:i+1])
if (i % 2 == 0 and c >= 0):
s2 += abs(c) + 1
b[i] -= abs(c) + 1
elif (i % 2 == 1 and c <= 0):
s2 += abs(c) + 1
b[i] += abs(c) + 1
print((min(s1,s2))) | n = int(eval(input()))
a = [int(i) for i in input().split()]
s1 = s2 = su = 0
for i in range(n):
su += a[i]
if (i % 2 == 0 and su <= 0):
s1 += abs(su) + 1
su = 1
elif(i % 2 == 1 and su >= 0):
s1 += abs(su) + 1
su = -1
su = 0
for i in range(n):
su += a[i]
if (i % 2 == 0 and su >= 0):
s2 += abs(su) + 1
su = -1
elif (i % 2 == 1 and su <= 0):
s2 += abs(su) + 1
su = 1
print((min(s1,s2))) | p03739 |
n = int(eval(input()))
an = list(map(int, input().split()))
sum_an = []
tmp = 0
for a in an:
tmp += a
sum_an.append(tmp)
c = 0
before_positive = sum_an[0] <= 0
for i in range(n):
if before_positive and sum_an[i] >= 0:
p = abs(sum_an[i]) + 1
c += p
for j in range(i, n):
sum_an[j] -= p
before_positive = False
elif not before_positive and sum_an[i] <= 0:
p = abs(sum_an[i]) + 1
c += p
for j in range(i, n):
sum_an[j] += p
before_positive = True
else:
before_positive = not before_positive
print(c)
| n = int(eval(input()))
an = list(map(int, input().split()))
c1 = 0
c2 = 0
sum1 = 0 # 偶数番目が正
sum2 = 0 # 奇数番目が正
for i in range(n):
sum1 += an[i]
sum2 += an[i]
if i%2 == 0:
if sum1 <= 0:
p = abs(sum1) + 1
c1 += p
sum1 += p
if sum2 >= 0:
p = abs(sum2) + 1
c2 += p
sum2 -= p
else:
if sum1 >= 0:
p = abs(sum1) + 1
c1 += p
sum1 -= p
if sum2 <= 0:
p = abs(sum2) + 1
c2 += p
sum2 += p
print((min(c1, c2)))
| p03739 |
def c_Sequence(N, A):
total = 0 # 変化量の総量
tmp1 = 0 # 条件を満たすために今見ている項をどれだけ変化させるか
for i in range(N):
total += A[i]
# 奇数番目を正に、偶数番目を負にする(0-indexedで)
if i % 2 == 0:
if total >= 0:
tmp1 += abs(-1 - total)
total -= abs(-1 - total)
else:
if total <= 0:
tmp1 += 1 - total
total += 1 - total
total = 0
tmp2 = 0
for i in range(N):
total += A[i]
# 奇数番目を負に、偶数番目を正にする
if i % 2 == 0:
if total <= 0:
tmp2 += 1 - total
total += 1 - total
else:
if total >= 0:
tmp2 += abs(-1 - total)
total -= abs(-1 - total)
ans = min(tmp1, tmp2)
return ans
N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_Sequence(N, A))) | def c_sequence():
N = int(eval(input()))
A = [int(i) for i in input().split()]
def solver(sign):
ret, total = 0, 0
for a in A:
total += a
if sign * total <= 0:
ret += abs(sign - total) # 総和がsignになるまでaを変化させる
total = sign
sign *= -1
return ret
# 1: 奇数番目を正、偶数番目を負にする場合。 -1: その逆
return min(solver(1), solver(-1))
print((c_sequence())) | p03739 |
n = int(eval(input()))
A = list(map(int,input().split()))
cnt = 0
for i in range(1,n):
if A[0] >= 0:
if i%2!=0 and A[i]>=0:
cnt += A[i]
A[i] -= A[i]
while sum(A[:i+1])>=0:
A[i] -= 1
cnt += 1
elif i%2==0 and A[i]<0:
cnt += abs(A[i])
A[i] += abs(A[i])
while sum(A[:i+1])<=0:
A[i] += 1
cnt += 1
else:
if A[i] >= 0:
while sum(A[:i+1])<=0:
A[i] += 1
cnt += 1
else:
while sum(A[:i+1])>=0:
A[i] -= 1
cnt += 1
else:
if i%2!=0 and A[i]<0:
cnt += abs(A[i])
A[i] += abs(A[i])
while sum(A[:i+1])<=0:
A[i] += 1
cnt += 1
elif i%2==0 and A[i]>=0:
cnt += A[i]
A[i] -= A[i]
while sum(A[:i+1])>=0:
A[i] -= 1
cnt += 1
else:
if A[i] >= 0:
while sum(A[:i+1])<=0:
A[i] += 1
cnt += 1
else:
while sum(A[:i+1])>=0:
A[i] -= 1
cnt += 1
print(cnt) | n = eval(input())
a = [int(i) for i in input().split()]
def chk(a, t):
ans = 0
x = 0
for i in a:
x += i
if t == True and x < 1:
ans+=1-x
x=1
elif t == False and x>-1:
ans+=x+1
x=-1
t=not t
return ans
print((min(chk(a,True),chk(a,False)))) | p03739 |
def main():
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
A = []
A_append = A.append
cnt = 0
for i in range(n-1):
A_append((a[i]))
x = sum(A)
if x > 0 and x + a[i+1] > 0:
y = -(x + a[i+1] + 1)
cnt -= y
a[i+1] += y
elif x < 0 and x + a[i+1] < 0:
y = -(x - a[i+1]+ 1)
cnt += y
a[i+1] += y
if sum(a) == 0:
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | n = eval(input())
A = list(map(int, input().split()))
def Chk(a, pos):
cnt = 0
tmp = 0
for a in A:
tmp += a
if pos and tmp < 1:
cnt += 1 - tmp
tmp = 1
elif not pos and tmp > -1:
cnt += 1 + tmp
tmp = -1
pos = not pos
return cnt
print((min(Chk(A, True), Chk(A, False)))) | p03739 |
n=int(eval(input()))
count=0
A=[int(i) for i in input().split()]
if A[0]==0:
A[0]+=1
count+=1
elif A[0]<0:
for i in range(len(A)):
A[i]*=(-1)
for i in range(1,len(A)):
s=sum(A[:i+1])
if i%2==0:
if s<=0:
A[i]+=1-s
count+=1-s
else:
if s>=0:
A[i]-=1+s
count+=1+s
print(count) | n=eval(input())
a=[int(i) for i in input().split()]
def chk(a,t):
ans=0
x=0
for i in a:
x+=i
if t==True and x<1:
ans+=1-x
x=1
elif t==False and x>-1:
ans+=x+1
x=-1
t=not t
return ans
print((min(chk(a,True),chk(a,False)))) | p03739 |
n = int(eval(input()))
A = [int(i) for i in input().split()]
def f(A, op, acc = 0, cnt = 0):
for i in range(n):
acc += A[i]
if i % 2 == 0 and acc * op >= 0:
cnt += op * acc + 1
acc = - op
if i % 2 == 1 and acc * op <= 0:
cnt += - op * acc + 1
acc = op
if acc == 0:
cnt += 1
return cnt
print((min(f(A, -1), f(A, 1)))) | n = int(eval(input()))
A = [int(i) for i in input().split()]
def f(A, op, acc = 0, cnt = 0):
for i in range(n):
acc += A[i]
if i % 2 == 0 and op * acc <= 0:
cnt += - op * acc + 1
acc = op
if i % 2 == 1and op * acc >= 0:
cnt += op * acc + 1
acc = -op
if acc == 0:
cnt += 1
return cnt
print((min(f(A, 1), f(A, -1)))) | p03739 |
n = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
cnt = 0
for i in range(n):
if i % 2 == 0:
if cnt + A[i] < 0:
cnt += A[i]
else:
ans += abs(cnt + A[i] - (-1))
cnt = -1
else:
if cnt + A[i] > 0:
cnt += A[i]
else:
ans += abs(cnt + A[i] - 1)
cnt = 1
ans2 = 0
cnt2 = 0
for i in range(n):
if i % 2 == 1:
if cnt2 + A[i] < 0:
cnt2 += A[i]
else:
ans2 += abs(cnt2 + A[i] - (-1))
cnt2 = -1
else:
if cnt2 + A[i] > 0:
cnt2 += A[i]
else:
ans2 += abs(cnt2 + A[i] - 1)
cnt2 = 1
print((min(ans, ans2))) | n = int(eval(input()))
A = [int(i) for i in input().split()]
def f(x):
ans = 0
cnt = 0
for i in range(n):
if i % 2 == x:
if cnt + A[i] < 0:
cnt += A[i]
else:
ans += abs(cnt + A[i] - (-1))
cnt = -1
else:
if cnt + A[i] > 0:
cnt += A[i]
else:
ans += abs(cnt + A[i] - 1)
cnt = 1
return ans
print((min(f(0), f(1)))) | p03739 |
def main():
n = int(eval(input()))
A = list(map(int, input().split()))
res = 0
sums = []
for i in range(n):
sums.append(sum(A[:i]) + A[i])
if i == 0:
if A[i] == 0:
index = -1
for num in A:
if num != 0:
index = A.index(num)
break
if index == -1:
res += 3
A[i] = 1
A[i+1] = -2
sums[i] = 1
elif (index % 2 and A[index] > 0) or (index % 2 == 0 and A[index] < 0):
A[i] = -1
sums[i] = -1
res += 1
else:
A[i] = 1
sums[i] = 1
res += 1
else:
if sums[i] == 0:
if sums[i-1] > 0:
A[i] -= 1
sums[i] = sums[i-1] + A[i]
res += 1
else:
A[i] += 1
sums[i] = sums[i-1] + A[i]
res += 1
elif (sums[i-1] > 0) and (sums[i] > 0):
res += A[i] - (-sums[i-1] - 1)
A[i] = -sums[i-1] - 1
sums[i] = sums[i-1] + A[i]
elif (sums[i-1] < 0) and (sums[i] < 0):
res += 1 - (sums[i-1] + A[i])
A[i] = abs(sums[i-1]) + 1
sums[i] = sums[i-1] + A[i]
print(res)
if __name__ == '__main__':
main() | def main():
n = int(eval(input()))
A = list(map(int, input().split()))
res = 0
sums = []
for i in range(n):
if i == 0:
sums.append(A[i])
if A[i] == 0:
sums[i] = 1
res += 1
elif A[i] < 0:
res += 1 - A[i]
sums[i] = 1
else:
sums.append(sums[i-1] + A[i])
if sums[i] == 0:
if sums[i-1] > 0:
sums[i] = -1
res += 1
else:
sums[i] = 1
res += 1
elif (sums[i-1] > 0) and (sums[i] > 0):
res += 1 + sums[i]
sums[i] = -1
elif (sums[i-1] < 0) and (sums[i] < 0):
res += 1 - sums[i]
sums[i] = 1
sums = []
res1 = 0
for i in range(n):
if i == 0:
sums.append(A[i])
if A[i] == 0:
sums[i] = -1
res1 += 1
elif A[i] > 0:
res1 += 1 + A[i]
sums[i] = -1
else:
sums.append(sums[i-1] + A[i])
if sums[i] == 0:
if sums[i-1] > 0:
sums[i] = -1
res1 += 1
else:
sums[i] = 1
res1 += 1
elif (sums[i-1] > 0) and (sums[i] > 0):
res1 += 1 + sums[i]
sums[i] = -1
elif (sums[i-1] < 0) and (sums[i] < 0):
res1 += 1 - sums[i]
sums[i] = 1
print((min(res, res1)))
if __name__ == '__main__':
main() | p03739 |
import collections
N=int(eval(input()))
A=list(map(int,input().split()))
c = collections.Counter(A)
for i in range(N):
if list(c.values())[i]>1:
print('NO')
exit()
print('YES') | import collections
N=int(eval(input()))
A=list(map(int,input().split()))
li=list(collections.Counter(A).values())
for i in range(len(li)):
if li[i]>1:
print('NO')
exit()
print('YES') | p02779 |
def hantei(n,data):
for x in range(n-1):
for y in range(x+1,n):
if data[x] == data[y]:
return "NO"
return "YES"
n = int(eval(input()))
data = [int(x) for x in input().split()]
print((hantei(n,data)))
| def hantei(n,data):
data.sort()
for x in range(n-1):
if data[x] == data[x+1]:
return "NO"
return "YES"
n = int(eval(input()))
data = [int(x) for x in input().split()]
print((hantei(n,data))) | p02779 |
n=int(eval(input()))
l=input().split()
q=[]
f=1
for i in l:
if i not in q:
q.append(i)
else:
f=0
break
if f==1:
print('YES')
else:
print('NO')
| n=int(eval(input()))
l=input().split()
l.sort()
flag=1
for i in range(n-1):
if l[i]==l[i+1]:flag=0
if flag==1:print("YES")
else:print("NO")
| p02779 |
l=int(eval(input()))
list = list(map(int, input().split()))
i=0
r="YES"
while(i<l):
j=i+1
while(j<l):
if(list[i]==list[j]):
r="NO"
j+=1
i+=1
print(r) | l=int(eval(input()))
list = list(map(int, input().split()))
def has_duplicates(seq):
return len(seq) != len(set(seq))
r=has_duplicates(list)
if(str(r)=="False"):
print("YES")
else:
print("NO") | p02779 |
n=int(eval(input()))
a=list(map(int,input().split()))
s="YES"
for i in range(n):
for j in range(i+1,n):
if a[i]==a[j]:
s="NO"
break
print(s) | n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
s="YES"
for i in range(n-1):
if a[i]==a[i+1]:
s="NO"
break
print(s) | p02779 |
n = int(eval(input()))
a = list(map(int, input().split()))
l = [0 for _ in range(max(a)+1)]
for i in range(n):
if l[a[i]] == 0:
l[a[i]] += 1
else:
print('NO')
break
else:
print('YES') | n = int(eval(input()))
a = list(map(int, input().split()))
if len(a) != len(set(a)):
print('NO')
else:
print('YES') | p02779 |
eval(input())
l=input().split()
for i in l:
if l.count(i)!=1:
print("NO")
exit(0)
print("YES") | N=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
for i in range(N-1):
if a[i]==a[i+1]:
print("NO")
exit(0)
print("YES") | p02779 |
n = eval(input())
a = input().split()
n = int(n)
a = [int(s) for s in a]
s =0
for f in range(n):
ai = a[f]
for g in range(n):
if g != f:
if ai == a[g]:
s = s+1
if s>0: print("NO")
else: print('YES') | n = eval(input())
a = input().split()
n = int(n)
a = [int(s) for s in a]
a.sort()
#print(a)
s=0
for i in range(len(a)-1):
#print(a[i],a[i+1])
if a[i]==a[i+1]:
print("NO")
s=s+1
break
if s == 0: print("YES") | p02779 |
n = eval(input())
N = int(n)
a = input().split()
A = list(map(int, a))
c = 0
for i in range(N):
for j in range(i + 1, N):
if A[i] == A[j]:
print("NO")
c += 1
break
if c == 0:
print("YES") | n = eval(input())
N = int(n)
a = input().split()
A = list(map(int, a))
b = set(A)
B = list(map(int, b))
if len(A) == len(B):
print("YES")
else:
print("NO") | p02779 |
N=int(eval(input()))
a=list(map(int,input().split()))
p=0
for i in range(N-1):
for j in range(i+1,N):
if a[i]==a[j]:
p=1
if p==0:
print('YES')
else:
print('NO') | N=int(eval(input()))
a=list(map(int,input().split()))
a=sorted(a)
p=0
for i in range(N-1):
if a[i]==a[i+1]:
p=1
if p==0:
print('YES')
else:
print('NO') | p02779 |
n=input().split()
li=[]
a=list(map(int,input().split()))
flag=0
for i in a:
if i in li:
print("NO")
flag=1
break
else:
li.append(i)
if flag==0:
print("YES") | n=input().split()
li=[]
a=list(map(int,input().split()))
p=set(a)
if len(a)==len(p):
print("YES")
else:
print("NO") | p02779 |
N = int(eval(input()))
A = list(map(int, input().split()))
answer = 'YES'
for i in range(N):
c = A.count(A[i])
if c >= 2:
answer = 'NO'
break
print(answer)
| N = int(eval(input()))
A = list(map(int, input().split()))
answer = 'YES'
AA = sorted(A)
for i in range(N - 1):
if AA[i] == AA[i + 1]:
answer = 'NO'
break
print(answer)
| p02779 |
import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
for i in range(N):
for j in range(i+1, N):
if A[i] == A[j]:
print("NO")
exit()
print("YES")
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
for i in range(1, N):
if A[i-1] == A[i]:
print("NO")
exit()
print("YES")
if __name__ == '__main__':
main()
| p02779 |
n = int(eval(input()))
a = list(map(int, input().split()))
isDiff = True
cache = [0] * n
for i in range(n) :
for j in range(n) :
if i == j :
continue
if cache[j] == -1 :
continue
if a[i] == a[j] :
isDiff = False
break
cache[i] = -1
if isDiff :
print('YES')
else :
print('NO')
| n = int(eval(input()))
a = list(map(int, input().split()))
aa = set(a)
if len(a) == len(aa) :
print('YES')
else :
print('NO')
| p02779 |
flag = True
n = int(eval(input()))
a = input().split()
if n != len(a):
print("error")
start = 0
for i in a:
start += 1
for j in a[start:]:
if i == j:
flag = False
break
if flag:
print('YES')
else:
print('NO') | flag = True
n = int(eval(input()))
a = input().split()
a.sort()
start = 0
for i in a:
for j in a[start-1:start+1:2]:
if i == j:
flag = False
break
start += 1
if flag:
print('YES')
else:
print('NO')
| p02779 |
n = int(eval(input()))
a = [int(i) for i in input().split()]
a.sort()
for i in range(n-1):
if a[i] == a[i+1]:
print("NO")
exit()
print("YES") | n = int(eval(input()))
a = [int(i) for i in input().split()]
aset = set(a)
print(("YES" if len(a) == len(aset) else "NO")) | p02779 |
n=int(eval(input()))
a=list(map(int,input().split()))
for i in range(n-1):
for j in range(i+1,n):
if a[i]==a[j]:
print("NO")
exit()
print("YES") | n=int(eval(input()))
a=list(map(int,input().split()))
b=list(set(a))
if len(a)==len(b):
print("YES")
else:
print("NO") | p02779 |
num = eval(input())
inp = input().split()
res = []
final = ""
tem = 0
for i in inp:
tem = inp.count(i)
res.append(tem)
tem = 0
for i in res:
if i >= 2:
final = "NO"
break
else:
final = "YES"
print(final)
| num = eval(input())
inp = input().split()
len1 = len(inp)
out = set(inp)
len2 = len(out)
if len1 == len2:
print("YES")
else:
print("NO") | p02779 |
N = int(eval(input()))
A = list(map(int, input().split()))
L = []
for i in range(N):
if A[i] in L:
print('NO')
break
L.append(A[i])
else:
print('YES') | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
for i in range(N-1):
if A[i] == A[i+1]:
print("NO")
break
else:
print('YES') | p02779 |
n = int(eval(input()))
num_list = list(map(int, input().split()))
out = "YES"
for j in range(len(num_list)):
for k in num_list[j + 1:]:
out = "NO" if num_list[j] == k else out
print(out)
| n = int(eval(input()))
num_list = list(map(int, input().split()))
out = "YES" if len(num_list) == len(set(num_list)) else "NO"
print(out) | p02779 |
N = int(eval(input()))
A = list(map(int, input().split()))
i = 0
flag = 0
while(i<N-1):
for j in range(1,len(A)):
if(A[0]==A[j]):
flag = 1
break
if(flag == 1):
break
else:
A.pop(0)
i += 1
if(flag == 1):
print("NO")
else:
print("YES") | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
flag = 0
for i in range(N-1):
if(A[i]==A[i+1]):
flag = 1
break
if(flag == 1):
print("NO")
else:
print("YES") | p02779 |
import math
def main():
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = {}
for val in a:
cnt[val] = cnt.get(val, 0) + 1
distinct = True
for val in cnt:
if cnt[val] > 1:
distinct = False
if distinct:
print("YES")
else:
print("NO")
if __name__ == '__main__':
main() | n=int(eval(input()))
a=list(input().split())
if len(list(a))==len(set(a)):
print('YES')
else:
print('NO')
| p02779 |
n = int(eval(input()))
a = list(map(int,input().split()))
flag = False
for i in range(n-1):
for j in range (i+1,n):
if a[i] == a[j]:
flag = True
break
print(('YES' if flag == False else 'NO')) | n=int(eval(input()))
a=[int(v) for v in input().split()]
a.sort()
kt=1
for i in range(0,n-1):
if a[i]==a[i+1]:
kt=0
break
if kt==0:
print("NO")
else:
print("YES")
| p02779 |
N = int(eval(input()))
A_List = list(map(int,input().split()))
for i in range(N):
for j in range(i+1,N):
if A_List[i]==A_List[j]:
print("NO")
exit()
print("YES") | N = int(eval(input()))
A_List = list(map(int,input().split()))
print(("YES" if len(A_List)==len(set(A_List)) else "NO")) | p02779 |
n=int(eval(input()))
a=list(map(int,input().split()))
print(('YES' if len(list(set(a)))==n else 'NO')) | n=int(eval(input()))
a=list(map(int,input().split()))
print(('YES' if len(set(a))==n else 'NO')) | p02779 |
N = int(eval(input()))
List = [int(i) for i in input().split(" ")]
flag = 0
for j in range(N-1):
for k in range(j+1,N):
if List[j]==List[k]:
flag = 1
break
if flag==1:
break
if flag==1:
print("NO")
else:
print("YES") | N = int(eval(input()))
List = [i for i in input().split(" ")]
Dict = {}
flag=0
for i in range(N):
try:
Dict[List[i]] += 1
except KeyError:
Dict[List[i]] = 1
list2 = list(Dict.values())
for j in range(len(list2)):
if list2[j]>1:
flag=1
if flag==1:
print("NO")
else:
print("YES") | p02779 |
n = int(eval(input()))
a = list(map(int,input().split()))
status = 0
for i in range(n):
if a.count(a[i]) != 1:
status = 1
break
else:
pass
if status == 0:
print("YES")
else:
print("NO")
|
n = int(eval(input()))
a = list(map(int,input().split()))
b = set(a)
if len(a) == len(b):
print("YES")
else:
print("NO")
| p02779 |
n = int(eval(input()))
List = list(map(int, input().split()))
ans = 'YES'
for i in range(n - 1):
for j in range(n - i - 1):
if List[i] == List[i + j + 1]:
ans = 'NO'
break
if ans == 'NO':
break
print(ans) | n = int(eval(input()))
List = list(map(int, input().split()))
Sorted = sorted(List)
ans = 'YES'
for i in range(n - 1):
if Sorted[i] == Sorted[i + 1]:
ans = 'NO'
break
print(ans) | p02779 |
a=int(eval(input()))
b=list(map(int, input().split()))
for i in b:
if b.count(i)==1:
continue
elif b.count(i)>1:
print('NO')
break
else:
print('YES')
| a=int(eval(input()))
b=list(map(int, input().split()))
if len(b) != len(set(b)):
print('NO')
else:
print('YES') | p02779 |
n = int(eval(input()))
l = list(map(int, input().split()))
check = True
for i in range(n):
if l.count(l[i]) > 1:
check = False
break
if check:
print("YES")
else:
print("NO") | n = int(eval(input()))
l = list(map(int, input().split()))
m = list(set(l))
if len(l) == len(m):
print("YES")
else:
print("NO") | p02779 |
N = int(eval(input()))
A = list(map(int,input().split()))
flg = 'YES'
for i,a in enumerate(A):
if a in A[i+1:]:
flg = 'NO'
break
print(flg) | N = int(eval(input()))
A = list(map(int,input().split()))
X = set(A)
if len(A) == len(X):
print('YES')
else:
print('NO') | p02779 |
def main():
N = int(eval(input()))
A = list(map(int,input().split()))
count = 0
flag = False
'''
for i in A:
if(A.count(i) > 1):
flag = True
break
if(flag):
print('NO')
else:
print('YES')
'''
for i in A:
for j in A:
if(i == j):
count += 1
if(count > 1):
flag = True
break
count = 0
if(flag):
break
if(flag):
print('NO')
else:
print('YES')
if __name__ == "__main__":
main() | def main():
N = int(eval(input()))
A = list(map(int,input().split()))
count = 0
flag = False
set_A = set(A)
if(len(set_A) == len(A)):
print('YES')
else:
print('NO')
'''
for i in A:
if(A.count(i) > 1):
flag = True
break
if(flag):
print('NO')
else:
print('YES')
'''
'''
for i in A:
for j in A:
if(i == j):
count += 1
if(count > 1):
flag = True
break
count = 0
if(flag):
break
if(flag):
print('NO')
else:
print('YES')
'''
if __name__ == "__main__":
main() | p02779 |
print((['YES','NO'][int(eval(input()))>len(set(map(int,input().split())))])) | print(('YNEOS'[int(eval(input()))>len(set(input().split()))::2])) | p02779 |
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 'YES'
for i in range(n):
for j in range(i+1,n):
if a[i] == a[j]:
ans = 'NO'
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
b = set(a)
if len(a) == len(b):
print('YES')
else:
print('NO') | p02779 |
N=int(eval(input()))
A=list(map(int,input().split()))
s=0
for i in range(N-1):
for j in range(i+1,N):
if A[i]!=A[j]:
s=s
else:
s+=1
if s!=0:
print("NO")
else:
print("YES") | N=int(eval(input()))
A=list(map(int,input().split()))
n=len(set(A))
if N!=n:
print("NO")
else:
print("YES") | p02779 |
n = int(eval(input()))
import sys
an = list(map(int, sys.stdin.readline().split()))
for i in range(n):
for j in range(i+1, n):
if an[i] == an[j]:
print('NO')
exit(0)
print('YES') | n = int(eval(input()))
import sys
an = list(map(int, sys.stdin.readline().split()))
if len(set(an))==n:
print('YES')
exit(0)
print('NO') | p02779 |
N = int(eval(input()))
A = list(map(int, input().split()))
check = []
for a in A:
if not a in check:
check.append(a)
else:
print('NO')
break
else:
print('YES') | N = int(eval(input()))
A = list(map(int, input().split()))
if len(set(A)) == len(A):
print('YES')
else:
print('NO')
| p02779 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
s = set()
for x in a:
if x in s:
print("NO")
exit(0)
s.add(x)
print("YES") | import sys
input = sys.stdin.readline
N = int(eval(input()))
a = set(map(int, input().split()))
if N == len(a): print("YES")
else: print("NO") | p02779 |
n =int(eval(input()))
# print(n)
List=list(map(int,input().split()))
count = 0
# print(List)
# print(List[1])
for i in range(n):
# print(List[i])
count += List.count(List[i])
# print(count)
if count == n:
print('YES')
else:
print('NO') | def has_duplicates(seq):
return len(seq) != len(set(seq))
n =int(eval(input()))
List=list(map(int,input().split()))
if has_duplicates(List) == False:
print('YES')
else:
print("NO") | p02779 |
n = int(eval(input()))
a = list(map(int, input().split()))
frag = False
for i in range(n):
for j in range(n):
if i != j and a[i] == a[j]:
frag = True
if frag:
print("NO")
else:
print("YES") | n = int(eval(input()))
a = list(map(int, input().split()))
b = set(a)
if len(a) == len(b):
print("YES")
else:
print("NO") | p02779 |
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
N = INT()
A = LIST()
for x, y in list(combinations(A, 2)):
if x == y:
print("NO")
sys.exit()
print("YES")
if __name__ == '__main__':
main()
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
N = INT()
A = LIST()
b = [INF]
for i in range(N):
if b[bisect_left(b, A[i])] == A[i]:
print("NO")
sys.exit()
else:
insort_left(b, A[i])
print("YES")
if __name__ == '__main__':
main()
| p02779 |
# -*- coding: utf-8 -*-
import sys
N = int(eval(input()))
A = [int(i) for i in input().split()]
for i in range(len(A)):
a = A[i]
for aa in A[i+1:]:
if aa == a:
print('NO')
sys.exit()
print('YES') | # -*- coding: utf-8 -*-
import sys
N = int(eval(input()))
A = [int(i) for i in input().split()]
dp = {}
for a in A:
if a-2 in dp:
print('NO')
break
dp[a-2] = 1
else:
print('YES') | p02779 |
def main():
n = int(eval(input()))
vals = list(map(int, input().split()))
flg = 0
for i in vals:
if vals.count(i) > 1:
flg += 1
break
if flg == 0:
print('YES')
else:
print('NO')
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
vals = list(map(int, input().split()))
flg = 0
vals.sort()
for i in range(n-1):
if vals[i] == vals[i + 1]:
flg += 1
break
if flg == 0:
print('YES')
else:
print('NO')
if __name__ == "__main__":
main()
| p02779 |
dic={}
n=int(eval(input()))
lis=list(map(int,input().split()))
for i in range(len(lis)):
if dic.get(lis[i],0)==0:
dic[lis[i]]=1
else:
print("NO")
exit()
print("YES") | n=eval(input())
l=list(map(int,input().split()))
if len(l)==len(set(l)):
print("YES")
else:print("NO")
| p02779 |
N=int(eval(input()))
A=list(input().split())
X=0
for i in range(N):
X+=A.count(A[i])
if X==N:
print("YES")
else:
print("NO") | N=int(eval(input()))
A=list(map(int, input().split()))
if len(set(A))==len(A):
print("YES")
else:
print("NO") | p02779 |
num = input()
list = list(map(int,input().split()))
flg = False
for i in list:
if list.count(i) >= 2:
flg = True
break
print("NO") if flg else print("YES")
| num = input()
list = list(map(int,input().split()))
list2 = set(list)
print("YES") if len(list) == len(list2) else print("NO")
| p02779 |
# -*- coding:utf-8 -*-
n = int(eval(input()))
numbers = []
for i in map(int,input().split()):
numbers.append(i)
a = sorted(list(set(numbers)))
b = sorted(numbers)
if a == b:
print("YES")
else:
print("NO") | n = int(eval(input()))
a = list(map(int, input().split()))
b = list(set(a))
if sorted(a) == sorted(b):
print('YES')
else:
print('NO') | p02779 |
def merge(array):
mid = len(array)
if mid > 1:
mid = mid // 2
left = merge(array[:mid])
right = merge(array[mid:])
array = []
while len(left) != 0 and len(right) != 0:
if left[0] == right[0]:
print("NO")
exit()
elif left[0] < right[0]:
array.append(left.pop(0))
else:
array.append(right.pop(0))
if len(left) != 0:
array.extend(left)
elif len(right) != 0:
array.extend(right)
return array
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
merge(a)
print("YES") | N = int(eval(input()))
A = list(map(int, input().split()))
ans = {}
flag = 0
for i in A:
if (ans.get(i) != None):
flag = 1
break
else:
ans[i] = 1
if (flag == 0):
print("YES")
else:
print("NO") | p02779 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.