Harryxun/stf_run huggingface dataset:
while True:
    N = int(input())
    if N == 0:break
    flgs = [0 for i in range(N)]
    for i in range(N):
        src = map(int,input().split())
        for k in src[1:]:
            flgs[i] |= (1 << k)
    target = 0
    src = map(int,input().split())
    for k in src[1:]:
        target |= (1 << k)

    ans = -1
    for i in range(N):
        if (flgs[i] | target) == flgs[i]:
            if ans < 0:
                ans = i+1
            else:
                ans = -1
                break
    print(ans)

### FIXED CODE ###

while True:
    N = int(input())
    if N == 0:break
    flgs = [0 for i in range(N)]
    for i in range(N):
        src = list(map(int,input().split()))
        for k in src[1:]:
            flgs[i] |= (1 << k)
    target = 0
    src = list(map(int,input().split()))
    for k in src[1:]:
        target |= (1 << k)

    ans = -1
    for i in range(N):
        if (flgs[i] | target) == flgs[i]:
            if ans < 0:
                ans = i+1
            else:
                ans = -1
                break
    print(ans)
a,b,c=map(str,input().split())
if b==“+”:
  print(int(a)+int(c))
else:
  print(int(a)-int(c))

### FIXED CODE ###

a,b,c=map(str,input().split())

if b=="+":
  print(int(a)+int(c))
else:
  print(int(a)-int(c))
# 右と下の両方に#があったら終了だしどちらにもなくても終了
# なんやこのクソみたいな実装は

h, w = map(int, input().split())
table = []
for _ in range(h):
    table.append(input())

flag = False
pos = [0, 0]
while True:
    if pos == [h - 1, w - 1]:
        flag = True
        break
    if (
        pos[0] < h - 1
        and pos[1] < w - 1
        and table[pos[0] + 1][pos[1]] == "#"
        and table[pos[0]][pos[1] + 1] == "#"
    ):
        break
    if pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#":
        pos[0] += 1
        continue
    elif pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        continue
    if pos[0] == h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        continue
    elif pos[0] < h - 1 and pos[1] == w - 1 and table[pos[0] + 1][pos[0]] == "#":
        pos[0] += 1
        continue
    else:
        break

print("Possible" if flag else "Impossible")


### FIXED CODE ###

# 右と下の両方に#があったら終了だしどちらにもなくても終了
# なんやこのクソみたいな実装は

h, w = map(int, input().split())
table = []
sharp = 0
for _ in range(h):
    get = input()
    table.append(get)
    sharp += get.count("#")

flag = False
pos = [0, 0]
path = 0
while True:
    if pos == [h - 1, w - 1]:
        path += 1
        flag = True
        break
    if h <= pos[0] or w <= pos[1]:
        break
    if (
        pos[0] < h - 1
        and pos[1] < w - 1
        and table[pos[0] + 1][pos[1]] == "#"
        and table[pos[0]][pos[1] + 1] == "#"
    ):
        break
    if pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#":
        pos[0] += 1
        path += 1
        continue
    elif pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        path += 1
        continue
    if pos[0] == h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        path += 1
        continue
    elif pos[0] < h - 1 and pos[1] == w - 1 and table[pos[0] + 1][pos[1]] == "#":
        pos[0] += 1
        path += 1
        continue
    else:
        break

print("Possible" if flag and path == sharp else "Impossible")
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    c = s.count("0")
    print(2*min(c,len(s)-c))
    return

#B
def B():
    n = I()
    h = LI()
    ans = 0
    m = min(h)
    while m:
        ans += m
        k = max(h)
        for i in range(n):
            if h[i] >= m:
                h[i] -= m
                if h[i]:k = min(k,h[i])
            else:break
        m = k
    print(ans)
    return

#C
def C():
    n,k = LI()
    x = LI()
    ans = float("inf")
    j = bisect.bisect_left(x,0)
    if n == 1:
        print(abs(x[0]))
        quit()
    if x[j] == 0:
        k -= 1
        x.pop(j)
        n -= 1
    for i in range(n):
        if i < j:
            if abs(i-j) > k:continue
            elif abs(i-j) == k:ans = min(ans,abs(x[i]))
            elif k+i-1 < n:
                ans = min(ans,abs(x[i])+x[k+i-1]-x[i])
        else:
            if abs(i-j)+1 > k:continue
            elif abs(i-j)+1 == k:ans = min(ans,x[i])
            elif i-k+1 >= 0:
                ans = min(ans,abs(x[i])+x[i]-x[i-k+1])

    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    C()


### FIXED CODE ###

import bisect

n,k = map(int, input().split())
x = list(map(int, input().split()))
j = bisect.bisect_right(x,0)
if x[-1] > 0:
    j += 1
ans = float("INF")
for i in range(max(j-1-k,0), max(min(j,n-k+1),0)):
    key = x[i+k-1]-x[i]
    ans = min(ans, min(abs(x[i])+key, abs(x[i+k-1])+key))
print(ans)
import math

n = int(raw_input())
a = []
for i in range(n):
    a.append(int(raw_input))

r = max(a)+1
sqrt = math.sqrt(r)
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1,r,i+1] = [0 for i in range(2*i+1,r,i+1)]

count = 0
for i in a:
    count += p[i-1]
    
print count

### FIXED CODE ###

def isPrime(p):
	if p == 2: return 1
	if p < 2 or p&1 == 0: return 0
	return 1 if pow(2,p-1,p) == 1 else 0
	
n = int(raw_input())
print sum(isPrime(int(raw_input())) for i in range(n))
import sys    #インタプリタや実行環境に関する情報を扱うためのライブラリ
import os     #フォルダやファイルを操作
import math

N=input()
count=0

for i in range(N):
    if i==0:
        continue
    if i<10:
        count +=1
    elif i<1000:
        count +=1
    elif i<100000:
        count+=1

print(count)
input()



### FIXED CODE ###

import sys    #インタプリタや実行環境に関する情報を扱うためのライブラリ
import os     #フォルダやファイルを操作
import math

N=int(input())
count=0

for i in range(N+1):
    if i==0:
        continue
    if i<10:
        count +=1
    if i<100:
        continue
    elif i<1000:
        count +=1
    elif i<10000:
        continue
    elif i<100000:
        count+=1

print(count)
s = [input() for i in range(3)]
t = {'a':0, 'b':1, 'c':2}
winner = {0:'A', 1:'B', 2:'C'}
index = [0,0,0]
length = [len(s[i]) for i in range(3)]
turn = 0
while True:
  if index[turn] >= length[turn]:
    print(winner[turn])
  c = s[turn][index[turn]]
  index[turn] += 1
  turn = t[c]

### FIXED CODE ###

s = [input() for i in range(3)]
t = {'a':0, 'b':1, 'c':2}
winner = {0:'A', 1:'B', 2:'C'}
index = [0,0,0]
length = [len(s[i]) for i in range(3)]
turn = 0
while True:
  if index[turn] >= length[turn]:
    print(winner[turn])
    exit()
  c = s[turn][index[turn]]
  index[turn] += 1
  turn = t[c]
a, b = int(input().split)

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

list = input().split()
a, b = int(list[0]), int(list[1])

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
n = input()
dic = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
for i in range(26):
  if n.count(str(dic[i]))%2!=0:
    print("No")
    exit()
print("Yes")

### FIXED CODE ###

n = input()
dic = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
  if n.count(str(dic[i]))%2!=0:
    print("No")
    exit()
print("Yes")
from fractions import gcd


def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())
SUM = B - A + 1
c = (B // C - (A - 1) // C)
d = (B // D - (A - 1) // D)
cd = (B // lcm(C, D) - (A - 1) // lcm(C, D))
print(B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - cd)))


### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


A, B, C, D = map(int, input().split())
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
c_d = B // lcm(C, D) - (A - 1) // lcm(C, D)
print(B - A + 1 - c - d + c_d)
n,k = map(int,input().split())
a = list(map(int,input().split()))

li = [-1] * n
li[0] = 0
town = [0]
now = 0

for i in range(k):
    now = a[now] - 1
    if li[now] != -1:
        s = li[now]
        break
    else:
        li[now] = i + 1
        town.append(now)

if s == n:
    print(town[-1])
    exit()
town2 = town[s:]
m = len(town2)
l = len(town) - len(town2)

if m == 0:
    print(town[-1])
else:
    print(town2[(k - l) % m]+1)


### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))

li = [-1] * n
li[0] = 0
town = [0]
now = 0
flag = False

for i in range(k):
    now = a[now] - 1
    if li[now] != -1:
        s = li[now]
        break
    else:
        li[now] = i + 1
        town.append(now)
    if i == k-1:
        flag = True

if flag:
    print(now+1)
    exit()

town2 = town[s:]
m = len(town2)
l = len(town) - len(town2)

print(town2[(k - l) % m]+1)
import math

A,B,H,M = map(int, input().split())

total_min = 60 * H + M
ch = (360/(12*60)) * total_min
cm = 360/60 * M

print(math.sqrt(A*A + B*B - 2*A*B*math.cos(ch-cm)) )

### FIXED CODE ###

a = input()
n = len(a)
if (int(a[n-1])==3):
  print("bon")
elif(int(a[n-1]) in [0,1,6,8]):
  print("pon")
elif(int(a[n-1]) in [2,4,5,7,9]):
  print("hon")
S=input()
elif S==MON:
  print(6)
elif S==TUE:
  print(5)
elif S==WED:
  print(4)
elif S==THU:
  print(3)
elif S==FRI:
  print(2)
elif S==SAT:
  print(1)
elif S==SUN:
  print(7)
  

### FIXED CODE ###

S=input()
if S=="MON":
  print(6)
elif S=="TUE":
  print(5)
elif S=="WED":
  print(4)
elif S=="THU":
  print(3)
elif S=="FRI":
  print(2)
elif S=="SAT":
  print(1)
elif S=="SUN":
  print(7)
h, w, k = map(int, input().split())

a = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        a[i][j] = int(s[j])

best_result = h * w + 1000

for m in range(2 ** (h - 1)):
    mask = m
    num_splits = 0
    splits = []
    i = 0
    while mask > 0:
        if (mask % 2) == 1:
            num_splits += 1
            splits.append(i)
        i += 1
        mask = mask // 2

    #print('mask = ', m, 'splits = ', splits, 'num_splits =', num_splits)

    counts = [0 for j in range(num_splits + 1)]
    current_counts = [0 for j in range(num_splits + 1)]
    result = num_splits

    for j in range(w):
        if result >= best_result:
            break
        split_index = 0
        success = True
        current_counts[0] = 0

        for i in range(h):
            if a[i][j] == 1:
                counts[split_index] += 1
                if counts[split_index] > k:
                    success = False

            current_counts[split_index] += a[i][j]

            if split_index < num_splits and i == splits[split_index]:
                split_index += 1
                current_counts[split_index] = 0

        if not success:
            result += 1
            #print('not success j = ', j, 'result = ', result, 'counts = ', counts)
            for x in range(num_splits + 1):
                counts[x] = current_counts[x]
            

    best_result = min(best_result, result)

print(best_result)

### FIXED CODE ###

a, b = map(int, input().split())
print ((a*(a - 1) + b*(b - 1)) // 2)
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 10 11:31:39 2015

@author: Ryuhei
"""

inf = float('inf')

def distance(p,n,x,y):
    D = 0
    s = []
    for i in range(0,n):
        s.append(x[i]-y[i])
        if s[i]<0.0:
            s[i]*=-1.0
        D += s[i]**p 
        
    if p==inf:
        return max(s)
    else:
        return D**(1.0/p)

if __name__ == '__main__':
    n = int(input())
    x = []
    y = []

    for i in range(0,n):
        x.append(int(input()))
    for i in range(0,n):
        y.append(int(input()))
        
    print float(distance(1,n,x,y))
    print float(distance(2,n,x,y))
    print float(distance(3,n,x,y))
    print float(distance(inf,n,x,y))

### FIXED CODE ###

inf = float('inf')

def distance(p,n,x,y):
    D = 0
    s = []
    for i in range(0,n):
        s.append(x[i]-y[i])
        if s[i]<0.0:
            s[i]*=-1.0
        D += s[i]**p 
        
    if p==inf:
        return max(s)
    else:
        return D**(1.0/p)

if __name__ == '__main__':
    n = int(input())
    x = map(int,raw_input().split())
    y = map(int,raw_input().split())
        
    print float(distance(1,n,x,y))
    print float(distance(2,n,x,y))
    print float(distance(3,n,x,y))
    print float(distance(inf,n,x,y))
def gcd(a, b):
    import math
    return math.gcd(a, b)


def pf(v):
    s, e = 3, v
    result = 2 if v & 1 == 0 else 1
    while v & 1 == 0:
        v >>= 1
    for i in range(s, e, 2):
        if v == 1:
            break
        if v % i == 0:
            result += 1
        while v > 1 and v % i == 0:
            v //= i
    return result


a, b = list(map(int, input().split()))
print(pf(gcd(a, b)))


### FIXED CODE ###

def gcd(a, b):
    while a != 0:
        a, b = b % a, a
    return b


def pf(v):
    result = 1
    for i in range(2, v + 1):
        if v < i * i:
            if v > 1:
                result += 1
            break
        if v % i == 0:
            result += 1
        while v > 1 and v % i == 0:
            v //= i
    return result


a, b = list(map(int, input().split()))
print(pf(gcd(a, b)))
#入力部
C= 998244353
N,M,K=map(int,input().split())

#定義部
U=max(N,K)
F=[0]*U
G=[0]*U

F[0]=1
for i in range(1,U):
    F[i]=(F[i-1]*i)%C

G[i]=pow(F[-1],C-2,C)

for j in range(U-2,-1,-1):
    G[j]=(G[j+1]*(j+1))%C

def nCr(n,r):
    if r<0 or n<r:
        return 0
    else:
        return (F[n]*G[r]*G[n-r])

#メイン部
S=0
for k in range(0,K+1):
    S=(S+M*pow(M-1,N-k-1,C)*nCr(N-1,k))%C
    
print(S%C)


### FIXED CODE ###

#入力部
C= 998244353
N,M,K=map(int,input().split())

#定義部
U=max(N+1,K)
F=[0]*U
G=[0]*U

F[0]=1
for i in range(1,U):
    F[i]=(F[i-1]*i)%C

G[i]=pow(F[-1],C-2,C)

for j in range(U-2,-1,-1):
    G[j]=(G[j+1]*(j+1))%C

def nCr(n,r):
    if r<0 or n<r:
        return 0
    else:
        return (F[n]*G[r]*G[n-r])

#メイン部
S=0
for k in range(0,K+1):
    S=(S+M*pow(M-1,N-k-1,C)*nCr(N-1,k))%C
    
print(S%C)
a, b = map(int, input().split())
print(a//b, " ", a%b, " ", "{10f}".format(a/b))


### FIXED CODE ###

a, b = map(int, input().split())
print("%d %d %.5f" % (a//b, a%b, a/b))
l = list(map(int,input().split()))
print(l[2]+' 'l[0]+' 'l[1])

### FIXED CODE ###

n = list(map(int,input().split()))
print(str(n[2])+' ' +str(n[0])+' '+str(n[1]))
a,b,c = map(int, raw_input().split())

if a < b:
    if b < c:
        print "Yes"\n
else:
    print "No"\n

### FIXED CODE ###

a,b,c = map(int,raw_input().split())

if (a < b and b < c):
    print 'Yes'
else:
    print 'No'
S=input();print(2*min(S.count("0")-S.count("1")))

### FIXED CODE ###

S=input()
N=len(S)
X=0
Y=0
for i in S:
    if i=="0":
        X+=1
    else:
        Y+=1
print(N-abs(X-Y))
x = imput()
print x**3



### FIXED CODE ###

x = input()
print (x ** 3)
def acinput():
    return list(map(int,input().split(" ")))


N,M=acinput()
a=[0]*(N+1)
for i in range(M):
    a[int(input())]=1


M=1000000007

def solve(x):
    if dp[x]>=0:
        return dp[x]

    res=0
    zeroflg=True
    if not a[x-1]:
        res+=solve(x-1)%M
        zeroflg=False
    if not a[x-2]:
        res+=solve(x-2)%M
        zeroflg=False
    
    if zeroflg:
        return 0
    dp[x]=res
    return res

dp=[-1]*(N+1)
dp[0]=1
dp[1]=1

print(solve(N)%M)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

def acinput():
    return list(map(int, input().split(" ")))


N, M = acinput()
a = [0]*(N+1)
for i in range(M):
    a[int(input())] = 1


Mod = 1000000007


def solve(x):
    global dp, Mod
    if dp[x] >= 0:
        return dp[x]

    if x < 0:
        return 0

    res = 0
    zeroflg = True

    if  a[x-2] != 1:
        res += solve(x-2) 
        zeroflg = False

    if a[x-1] != 1:
        res += solve(x-1)
        zeroflg = False

    if zeroflg:
        return 0
    dp[x] = res% Mod
    return res


dp = [-1]*(N+1)
dp[0] = 1
dp[1] = 1

print(solve(N) % Mod)


'''
5 1
1
'''
a,b = map(int,input().split())
li = list(map(int,input().split()))
li = [abs(x-b) for x in li]
from functools import reduce
from math import gcd
print(reduce(gcd,li))

### FIXED CODE ###

n, x = map(int,input().split())
li = list(input().split())
li = [abs(int(a)-x) for a in li]

def gcd(a,b):
    while a%b!=0:
        a,b = b,a%b
    return b
    
if n == 1:
    print(abs(li[0]))
    
elif n == 2:
    print(gcd(li[0],li[1]))
    
elif n >= 3:

    c = gcd(li[0],li[1])
    #print(c)
    for i in range(2,len(li)-1):
        c = gcd(c,li[i])
    print(c)
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x: x[1],reverse=True)
# print(a)
# print(bc)
i=0
for b,c in bc:
  tb=b
  while tb>0:
    if a[i]>=c:
      break
    a[i]=c
    tb-=1
    i+=1
  if a[i]>=c or n==i:
    break
print(sum(a))


### FIXED CODE ###

# ABC127 D-Integer Cards
from operator import itemgetter
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=itemgetter(1),reverse=True)
# print(A)
# print('sort',BC)
c = 0
for i in range(M):
    for j in range(BC[i][0]):
        if A[c] < BC[i][1]:
            A[c] = BC[i][1]
        else:
            print(sum(A))
            exit()
        c += 1
        if c == N:
            print(sum(A))
            exit()
# for i in range(M):
#     x = 0
#     while x < BC[i][0]:
#         A.sort()
#         print(i,A)
#         if BC[i][1] > A[0]:
#             A[0] = BC[i][1]
#         x += 1 
print(sum(A))
s=str()
x=s.count(1)
print(x)






### FIXED CODE ###

from sys import stdin
a=stdin.readline().rstrip()
x=a.count("1")
print(x)
def shortie (L):
 R= L/3
Return (R**3)

L+int(input())
Shortie (L)

### FIXED CODE ###

#hello
#password
#input
#understandign python
#less errors
#work now please
q = int(input())
w = q / 3
print(w ** 3)
A,B=int(input())

if A<6:
  print(0)
elif 6<=A<12:
  print(B/2)
else:
  print(B)



### FIXED CODE ###

A,B=map(int,input().split())

if A<6:
  print(0)
elif 6<=A<=12:
  print(B//2)
else:
  print(B)
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

# 入力
N = int(input())
adj = [[] for _ in range(N)]
ans = [None] * N

# グラフ探索で解いてみる
# c: 頂点vの色(0or1)
def dfs(v,parent,c):
    ans[v] = c
    for u,w in adj[v]:
        if u == parent:
            continue
        dfs(u,v,1-c) if w & 1 else dfs(u,v,c)

def main():
    for i in range(N-1):
        u, v, w = map(int, input().split())
        adj[u-1].append((v-1,w))
        adj[v-1].append((u-1,w))
    
    dfs(0,-1,1)
    [print(v) for v in ans]

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    adj = [[] for _ in range(N)]
    for i in range(N-1):
        u, v, w = map(int, input().split())
        adj[u-1].append((v-1,w))
        adj[v-1].append((u-1,w))
    
    queue = deque([0])
    visit = [-1] * N
    visit[0] = 1
    
    while queue:
        now = queue.popleft()
        for u,w in adj[now]:
            if visit[u] < 0:
                queue.append(u)
                if w % 2 == 0:
                    visit[u] = visit[now]
                else:
                    visit[u] = (visit[now]+1) % 2
    [print(v) for v in visit]


if __name__ == "__main__":
    main()
import itertools

def sign(num):
    if num < 0:
        return -1
    elif num > 0:
        return 1
    else:
        return 0

N = input()
a_i = list(map(int, input().split()))

a_sum = [a_i[0]]
for i, a in enumerate(a_i[1:]):
    i += 1
    a_sum.append(a_sum[-1]+a)

signs = [1, -1]
for i, sum_i in enumerate(a_sum):
    if sum_i != 0 && i%2 == 0:
        signs = [sign(sum_i), -sign(sum_i)]
        break
    elif sum_i != 0 && i%2 == 1:
        signs = [-sign(sum_i), sign(sum_i)]
        break

a_sum = 0
changes = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes += abs(a_sum) + 1
        a_sum = signs[i%2]
print(changes)

#
# for i, sum_i in enumerate(a_sum):
#     if i == 0:
#         signs = [sign(sum_i), -sign(sum_i)]
#     elif sign(sum_i) != signs[i%2]:
#         a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]]
#         changes += abs(sum_i) + 1
#     # print(a_sum)
# print(changes)


### FIXED CODE ###

import itertools

def sign(num):
    if num < 0:
        return -1
    elif num > 0:
        return 1
    else:
        return 0

N = input()
a_i = list(map(int, input().split()))

signs = [-1,1]
a_sum = 0
changes_1 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes_1 += abs(a_sum) + 1
        a_sum = signs[i%2]

signs = [1,-1]
a_sum = 0
changes_2 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes_2 += abs(a_sum) + 1
        a_sum = signs[i%2]

print(min(changes_1,changes_2))
n = int(input())
P = list(map(int, input().split()))

num = 0
for i in range(n):
    list_i = P[i:i+3]
    if list_i[1] == sorted(list_i)[-2]:
        num += 1
    else:
        num += 0

print(num)

### FIXED CODE ###

n = int(input())
P = list(map(int, input().split()))

num = 0
for i in range(n-2):
    list_i = P[i:i+3]
    if list_i[1] == sorted(list_i)[-2]:
        num += 1
    else:
        num += 0

print(num)
n=input()
t,a=map(int,input().split())
h=list(map(int,input()))
h2=[abs(t-x*0.006-a) for x in h]
print(h2.index(min(h2))+1)
    
    

### FIXED CODE ###

n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
h2=[abs(t-x*0.006-a) for x in h]
print(h2.index(min(h2))+1)