Harryxun/stf_run huggingface dataset:
N,C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]

G = [list(map(int,input().split())) for _ in range(N)]
g1 = []
g2 = []
g3 = []
for i in range(N):
    for j in range(N):
        G[i][j] -= 1
        if (i+j)%3 == 0:
            g1.append(G[i][j])
        if (i+j)%3 == 1:
            g2.append(G[i][j])
        if (i+j)%3 == 2:
            g3.append(G[i][j])



cost = [[0]*C for _ in range(3)]
for c in range(C):
    for g in range(3):
        if g == 0:
            cost[c][0] = sum(D[clr_g1][c] for clr_g1 in g1)
        if g == 1:
            cost[c][1] = sum(D[clr_g2][c] for clr_g2 in g2)
        if g == 2:
            cost[c][2] = sum(D[clr_g3][c] for clr_g3 in g3)



ans = float('inf')
for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            temp = 0
            if c1 == c2 or c2 == c3 or c3 == c1:
                continue
            # temp += sum(D[clr_g1][c1] for clr_g1 in g1)
            # temp += sum(D[clr_g2][c2] for clr_g2 in g2)
            # temp += sum(D[clr_g3][c3] for clr_g3 in g3)
            temp = cost[c1][0] + cost[c2][1] + cost[c3][2]
            ans = min(ans,temp)
print(ans)

### FIXED CODE ###

N,C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]

G = [list(map(int,input().split())) for _ in range(N)]
g1 = []
g2 = []
g3 = []
for i in range(N):
    for j in range(N):
        G[i][j] -= 1
        if (i+j)%3 == 0:
            g1.append(G[i][j])
        if (i+j)%3 == 1:
            g2.append(G[i][j])
        if (i+j)%3 == 2:
            g3.append(G[i][j])



cost = [[0]*3 for _ in range(C)]
for c in range(C):
    for g in range(3):
        if g == 0:
            cost[c][0] = sum(D[clr_g1][c] for clr_g1 in g1)
        if g == 1:
            cost[c][1] = sum(D[clr_g2][c] for clr_g2 in g2)
        if g == 2:
            cost[c][2] = sum(D[clr_g3][c] for clr_g3 in g3)



ans = float('inf')
for c1 in range(C):
    for c2 in range(C):
        for c3 in range(C):
            temp = 0
            if c1 == c2 or c2 == c3 or c3 == c1:
                continue
            # temp += sum(D[clr_g1][c1] for clr_g1 in g1)
            # temp += sum(D[clr_g2][c2] for clr_g2 in g2)
            # temp += sum(D[clr_g3][c3] for clr_g3 in g3)
            temp = cost[c1][0] + cost[c2][1] + cost[c3][2]
            ans = min(ans,temp)
print(ans)
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
  x[i],y[i] = map(int, input().split())

if n == 1:
  print(1)

ans = []
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    p = x[i]-x[j]
    q = y[i]-y[j]
    count = 0
    for k in range(n):
      for l in range(n):
        if p == x[k]-x[l] and q == y[k]-y[l]:
          count += 1
          ans.append(count)
print(n-max(ans))


### FIXED CODE ###

n = int(input())
x = [0]*n
y = [0]*n

if n == 1:
  print(1)
else:
  for i in range(n):
    x[i],y[i] = map(int, input().split())
  ans = []
  for i in range(n):
    for j in range(n):
      if i == j:
        continue
      p = x[i]-x[j]
      q = y[i]-y[j]
      count = 0
      for k in range(n):
        for l in range(n):
          if p == x[k]-x[l] and q == y[k]-y[l]:
            count += 1
            ans.append(count)
  print(n-max(ans))
n = int(input())
b=list(map(int, input().split())) 

sum =b[0]

if len(b) >= 2:
    for i in range(1,len(b)):
        if b[i-1]<b[i]:
            sum+=b[i-1]
        else:
            sum+=b[i]
        
sum+=b[i]
        
print(sum)

### FIXED CODE ###

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

sum =b[0]

if len(b) >= 2:
    for i in range(1,len(b)):
        if b[i-1]<b[i]:
            sum+=b[i-1]
        else:
            sum+=b[i]
        
sum+=b[-1]
        
print(sum)
N = int(input())
L = [int(i) for i in input().split()]

count_list = []
for i in range(0,N):
	counter = 0
	for j in range(i+1,N):
		print(L[i],L[j])
		if L[i] > L[j]:
			counter = counter + 1
			
		elif L[i] <= L[j]:
			count_list.append(counter)
			break
			
print(max(count_list))

### FIXED CODE ###

N = int(input())
L = [int(i) for i in input().split()]

Max =  0
Count = 0
for i in range(N-1):
    if L[i] >= L[i+1]:
        Count += 1
    else:
        Count = 0
    if Count >= Max:
        Max = Count
print(Max)
# -*- coding: utf-8 -*-

"""
計算式は以下のように示される
C_n = (1/n)*(1+C_(n-1)) + ((n-1)/n)*C_(n-1)  =  C_(n-1)+(1/n)
"""
import math
N = int(input())
X = list(map(int, input().split()))

def calc(i):
    if i==1:
        return 1
    return calc(i-1)+(1.0/i)

result = []
for i in range(1, N):
    temp = (X[i]-X[i-1])*calc(i)
    result.append(temp)
    
print(int(sum(result)*math.factorial(N-1)))

### FIXED CODE ###

# -*- coding: utf-8 -*-

mod = 10**9 +7
N = int(input())
X = list(map(int, input().split()))

factorial=[1]
for i in range(1,N):
    factorial.append(factorial[-1] *i %mod)

ans=0
for i in range(1,N):
    ans = (ans*i + (X[-1]-X[i-1])*factorial[i-1]) %mod

print(ans)
N=input();print('YNeos'[int(N)%sum(map(int,n))!=0::2])


### FIXED CODE ###

N=input();a=list(map(int,N));print('YNeos'[int(N)%sum(a)!=0::2])
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
for i in range(1,10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==1:
	print(kane)
else:
	print("Error!!")

### FIXED CODE ###

[a,b,c]=map(int, input().split())
list1=[a,b,c]
list1.sort()
if list1==[5,5,7]:
	print("YES")
else:print("NO")
inf = float('inf')

# distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0
# True - >正常に更新, False -> 負閉路有り
def bellmanford(dist,edges,N):
    for i in range(N):
        for v ,nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                # 頂点数Nなら更新は高々N-1回で済む
                # N回目に更新を行うなら負閉路があるということ
                if i == N-1 nv == N-1:
                    return False
    return True

N,M = map(int,input().split())
info = []
for _ in range(M):
    a,b,c = map(int,input().split())
    a -= 1; b -= 1; c = -c
    info.append((a,b,c))
 
dist = [inf for _ in range(N)]
dist[0] = 0

flag = bellmanford(dist,info,N)
ans = -dist[N-1] if flag is True else "inf"
print(ans)

### FIXED CODE ###

inf = float('inf')

N,M = map(int,input().split())
info = []
for _ in range(M):
    a,b,c = map(int,input().split())
    a -= 1; b -= 1
    info.append((a,b,c))
 
dist = [-inf for _ in range(N)]
dist[0] = 0
for i in range(N):
    for v,nv,w in info:
        if dist[nv] < dist[v] + w:
            dist[nv] = dist[v] + w
            if i == N-1 and nv == N-1:
                print("inf")
                exit()
ans = dist[N-1]
print(ans)
s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			k=d[1]
			print(s[:-i-1]+k)
			print(2/0)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)

### FIXED CODE ###

s=input()
if len(s)==26:
	d=[]
	for i in range(26):
		if list(s[-i-1:][::-1])!=sorted(s[-i-1:]):
			for j in range(i+1):
				d.append(s[-j-1])
			d.sort()
			if d[0]==s[-i-1]:
				k=d[1]
			else:
				for j in range(len(d)):
					if d[j]>s[-i-1]:
						k=d[j]
						break
			print(s[:-i-1]+k)
			exit()
	print(-1)
	exit()
d=[0]*26
for i in range(len(s)):
	d[ord(s[i])-ord("a")]+=1
for i in range(26):
	if d[i]==0:
		x=chr(ord("a")+i)
		break
print(s+x)
import math
n, k = map(int, input().split())
arr = list(map(int, input().split()))

max_length = max(arr)
low = 0
high = max_length-1

while low <= high:
  mid = (low + high) //2
  cnt = 0
  for i in range(n):
    cnt += math.ceil(arr[i]/mid) - 1
    #if cnt > k:
      #break
  if cnt > k:
    low = mid + 1
  else:
    high = mid -1
    max_length = mid

print(max_length)


### FIXED CODE ###

import math
n, k = map(int, input().split())
arr = list(map(int, input().split()))

max_length = max(arr)
low = 1
high = max_length - 1

while low <= high:
  mid = (low + high) //2
  cnt = 0
  for i in range(n):
    cnt += math.ceil(arr[i]/mid) - 1
  if cnt > k:
    low = mid + 1
  else:
    high = mid -1
    max_length = mid

print(max_length)
N = input()
if N%2 == 1:
  N*=2
print(N)

### FIXED CODE ###

N=int(input())
if N%2==1 :
  N*=2
print(N)
A=int(input())
B=int(input())
C=int(input())
while A<1 or A>100 or B<1 or B>100 or C<1 or C>100:
 A=int(input()),B=int(put()),C=int(input())
D=B//A-C
if D>0:
  print(C)
else:
  print(B//A)

### FIXED CODE ###

A,B,C=map(int,input().split())
D=B//A-C
if D>0:
  print(C)
else:
  print(B//A)
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
B = [0]*N
 
for k in range(K):
 
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
 
for k in range(K):
  B = [0]*N
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)
A,B,K = map(str, input().split())     

takahashi_cookie = A
aoki_cookie = B
iteration = K
     
while(0 < iteration):
    if(1 <= takahashi_cookie):
        takahashi_cookie -= 1
     
    elif(1 <= aoki_cookie):
        aoki_cookie -= 1
     
    else:
        pass
     
    iteration -= 1
     
    print(str(takahashi_cookie) + ' ' + str(aoki_cookie))
     A,B,KT = map(str, input().spl
          it())

### FIXED CODE ###

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

takahashi_cookie = A
aoki_cookie = B
iteration = K

if 0 <= takahashi_cookie - iteration:
  takahashi_cookie -= iteration
 
elif 0 <= aoki_cookie + takahashi_cookie - iteration:
  aoki_cookie = aoki_cookie + takahashi_cookie - iteration
  takahashi_cookie = 0

else:
  takahashi_cookie = 0
  aoki_cookie = 0

print(str(takahashi_cookie) + ' ' + str(aoki_cookie))
X = int(input())
A = [0] * 200
m = 0
n = 0
for i in range(400):
  A[i] = i ** 5
for i in range(400):
  x = A[i]
  for j in range(400):
    y = A[j]
    if ((x + y) == X):
      m = i
      n = (-1) * j
    elif ((x - y) == X):
      m = i
      n = j
print(m, n)

### FIXED CODE ###

X = int(input())
A = [0] * 400
m = 0
n = 0
for i in range(400):
  A[i] = i ** 5
for i in range(400):
  x = A[i]
  for j in range(400):
    y = A[j]
    if ((x + y) == X):
      m = i
      n = (-1) * j
    elif ((x - y) == X):
      m = i
      n = j
print(m, n)
N = int(input())
X = int(input(),2)

def pcrem(n,cnt):
  if (n==0):
    print(cnt)
    return 0
  pc = bin(n).count("1")
  pcrem(n%pc,cnt+1)

for i in range(N):
  f = X^(1<<N-i-1)
  pcrem(f,0)

### FIXED CODE ###

L,R,d = map(int,input().split())
ans=0
for i in range(L,R+1):
  if (i%d == 0):
    ans+=1
    
print(ans)
n,q = map(int,input().split())
r = [[] for _ in range(n+1)]
bonus = [0] * (n+1)
score = [0] * (n+1)

for i in range(n-1):
    a,b = map(int,input().split())
    r[a].append(b)
for i in range(q):
    p,x = map(int,input().split())
    bonus[p] += x 

def dfs(d,u):
    s[u] = True
    score[u] += bonus[d]
    
    for v in r[u]:
        if not s[v]:
            dfs(d,v)
    
for i in range(1,n+1):
    s = [False] * (n+1)
    dfs(i,i)
        
print(*score[1:])

### FIXED CODE ###

from collections import deque

n,q = map(int,input().split())
r = [[] for _ in range(n)]
bonus = [0] * n
score = [0] * n

for i in range(n-1):
    a,b = map(int,input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(q):
    p,x = map(int,input().split())
    bonus[p-1] += x
q = deque()
q.append(0)
used = [False]*n
used[0] = True
score[0] = bonus[0]

while q:
    p = q.popleft()
    for i in r[p]:
        if not used[i]:
            used[i] = True
            score[i] += score[p] + bonus[i]
            q.append(i)
        
print(*score)
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i+ 1- pidx
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)

### FIXED CODE ###

import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i + 1
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        cyc -=st
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)
str = input()

char_count = 1
for i in range(3):
    if str[0] == str[i+1]:
        char_count += 1
    else:
        char2 = i+1
        char2_count = 0
        
if char_count == 2:
    for char in str:
        if str[char2] == char:
            char2_count += 1
            
    if char2_count == 2:
        print("Yes")
        
    else:
        print("No")
        
else:
    ("No")
    
    
print(char_count, char2_count)

### FIXED CODE ###

str = input()

chars = {}
for char in str:
    if char in chars:
        chars[char] += 1
    else:
        chars[char] = 1
        
if len(chars) == 2 and chars[str[0]] == 2:
    print("Yes")
    
else:
    print("No")
N = int(input())
n = N % 1000
if n == 0;
  	print(0)
else;
  	print(1000-n)

### FIXED CODE ###

N = int(input())
n = N%1000
if n==0:
  	print(0)
else:
  	print(1000-n)
n=int(input())
m==1
for i in range(100000):
    if i**2<=n:
        m=max(i,m)
print(m)
    


### FIXED CODE ###

n=int(input())
a=[]
for i in range(1,100000):
    if i**2<=n:
        a.append(i)
print((max(set(a)))**2)
N, Q = map(int, input().split())

g = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*N

for _ in range(Q):
    p, x = map(int, input().split())
    add[p-1] += x

ans = [0]*N

def func(v, p, val):
    val += add[v]
    ans[v] = val
    for c in g[v]:
        if c==p: continue
        func(c, v, val)

func(0, -1, 0)

print(*ans)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q = map(int,readline().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:N+N-2])
PX = iter(ABPX[N+N-2:])

graph = [[] for _ in range(N+1)]
for a,b in zip(AB,AB):
    graph[a].append(b)
    graph[b].append(a)

val = [0] * (N+1)
for p,x in zip(PX,PX):
    val[p] += x

stack = [1]
parent = [0] * (N+1)
while stack:
    x = stack.pop()
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        val[y] += val[x]

print(' '.join(map(str,val[1:])))
a=int(input())
b=int(input())
print(a*b)

### FIXED CODE ###

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

print(A*B)
a, b = input().strip().split()
print(max[a+b,a-b,a*b])

### FIXED CODE ###

a, b = input().strip().split()
a, b = [int(a), int(b)]
print(max([a+b,a-b,a*b]))
s=input()
n=len(s)
if s[0]==s[-1] ^ n%2==0:
  print('Second')
else:
  print('First')

### FIXED CODE ###

s=input()
n=len(s)
moji1=s[0]
moji2=s[1]
count=0
flag=False
for i in range(n-2):
  if (i+count)%2==0:
    if s[i+2]!=moji1:
      count+=1
      if i+2==n-1:
        flag=True
  else:
    if s[i+2]!=moji2:
      count+=1
      if i+2==n-1:
        flag=True
  if count==2:
    break
if count==0:
  print('Second')
  exit()
if count==1:
  if flag:
    if (n-2)%2==0:
      print('Second')
    else:
      print('First')
  else:
    print('First')
  exit()
if s[0]==s[-1]:
  if (n-3)%2==0:
    print('Second')
  else:
    print('First')
else:
  if (n-2)%2==0:
    print('Second')
  else:
    print('First')
s=input()
t=input()
s.sort()
t.sort(reverse=True)
if s>t:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
if s>=t:
  print("No")
else:
  print("Yes")
N, i = map(int, input().split())
print(N - i +　1)

### FIXED CODE ###

N, i = map(int, input().split())
print(N - i + 1)
inport numpy as np

N,A,B = map(int,input().split(" "))
costs = A*N , B

print(min(costs))


### FIXED CODE ###

import numpy as np

N,A,B = map(int,input().split(" "))
costs = A*N , B

print(min(costs))
def func(N):
    tmp=N
    arr=[]
    for i in range(2,int(-(-N**0.5//1))+1):
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
            
    if temp!=1:
        arr.append([tmp, 1])
    if arr==[]:
        arr.append([tmp,1])
   
    return arr

N=int(input())
a=func(N)
ans=0
if a[0][0]==1:
        print(0)
        exit()
        
b=[1,3,6,10,15,21,28,36,45]
for i in a:
    for j in range(len(b)):
       if  i[1]<b[j]:
          ans+=j
          break
print(ans)
    
            

### FIXED CODE ###

def func(N):
    tmp=N
    arr=[]
    for i in range(2,int(-(-N**0.5//1))+1):
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
            
    if tmp!=1:
        arr.append([tmp, 1])
    if arr==[]:
        arr.append([tmp,1])
   
    return arr

N=int(input())
a=func(N)
ans=0
if a[0][0]==1:
        print(0)
        exit()
        
b=[1,3,6,10,15,21,28,36,45]
for i in a:
    for j in range(len(b)):
       if  i[1]<b[j]:
          ans+=j
          break
print(ans)
a = [*map(int,input().split(' '))]
b = [*map(int,input().split(' '))]
for i in range(4):
	if a[i] == b[i]:
		hit += 1
	if a[i] == b[i-1]:
		blow += 1
print(hit, blow)


### FIXED CODE ###

while 1:
	hit = blow = 0
	try: a = list(map(int,input().split()))
	except: break
	b = list(map(int,input().split()))
	for i in range(4):
		if a[i] == b[i]:
			hit += 1
		elif a[i] in b:
			blow += 1
	print(hit, blow)
def main():
	s = str(input())
	t = str(input())
	
	if len(s) > len(t):
		print(0)
	
	else:
		l = []
		for i in range(len(s)-len(t)):
			l.append(s[i:i+len(t)])
		
		ans = []
		for c in l:
			counter = 0
			for i in range(len(c)):
				if list(c)[i] == t[i]:
					counter += 1
			ans.append(counter)
			
		print(len(t)-max(ans))





	

if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	s = str(input())
	t = str(input())
	
	
	if len(s) == len(t):
		ans = 0
		for i in range(len(t)):
			if list(s)[i] == list(t)[i]:
				ans += 1
		print(len(t)-ans)

	else:
		l = []
		for i in range(len(s)-len(t)):
			l.append(s[i:i+len(t)])
		
		ans = []
		for c in l:
			counter = 0
			for i in range(len(c)):
				if list(c)[i] == list(t)[i]:
					counter += 1
			ans.append(counter)

		if not ans:
			print(len(t))
		else:
			print(len(t)-max(ans))





	

if __name__ == '__main__':
	main()
N = int(input())
S = []
for i in range(N):
  S.append(input())
m = max(S.count(S[i]), for i in range(N))
S_new = set(S)
for s in S_new:
  if m == S.count(s):
    print(s)
  

### FIXED CODE ###

import collections
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))
A = collections.Counter(S)
m = max(A.values())
for s in sorted(set(S)):
  if A[s] == m:
    print(s)
import math
A,B,C,D = list(map(int, input().split()))

cd = int((C * D) / math.gcd(C, D))

bc = B // C
bd = B // D
bcd = B // cd
ac = (A - 1) // C
ad = (A - 1) // D
acd = (A - 1) // cd

bdiv = bc + bd - bcd
adiv = ac + ad - acd

alldiv = bdiv - adiv

ans = B - A + 1 - alldiv

print(int(ans))

### FIXED CODE ###

# (A ~ B までの個数) - (Cで割り切れるもの + Dで割り切れるもの - CDの最小公倍数で割り切れるもの)
A,B,C,D = list(map(int, input().split()))

def euc(a, b):
    a, b = [max(a, b), min(a, b)]
    if b == 0:
        return a
    else:
        return euc(b, a % b)

Cdiv = (B // C) - ((A-1) // C)
Ddiv = (B // D) - ((A-1) // D)
E = (C * D) // euc(C, D)
CDdiv = (B // E) - ((A-1) // E)

print((B - A + 1) - (Cdiv + Ddiv - CDdiv))
S,T=input().split()
count=0
for i in range(3):
  if S[i] == T[i]:
    count += 1
print(count)

### FIXED CODE ###

S = input()
T = input()
count=0
for i in range(3):
  if S[i] == T[i]:
    count += 1
print(count)
n,b=input().split()
n,b=int(n),int(b)
def b(n,b):
    return "safe" if n>b else "No"
print(b(n,b))

### FIXED CODE ###

n,m=map(int,input().split())
def func(n,m):
    return "unsafe" if n<=m else "safe"
print(func(n,m))
def solve():

    n = int(input())
    a = list(map(int, input().split()))
    b = [a[i] for i in range(n)]

   # print(a)
   # print(b)

    i = 0
    sum = 0

    ans = 0

    for i in range(n-1):
        sum += a[i]
        if sum > 0 and sum+a[i+1] > 0:
            tmp = -1 - sum
            ans += abs(tmp - a[i+1])
            a[i+1] = tmp
        elif sum < 0 and sum+a[i+1] < 0:
            tmp = 1 - sum
            ans += abs(tmp - a[i+1])
            a[i+1] = tmp

   # print(ans)
   # print(a)

    tmp_ans_1 = ans

    ans = 0
    sum = 0
    i = 0

    if b[0] > 0:
        ans += abs(-1 - b[0])
        b[0] = -1
    elif b[0] < 0:
        ans += abs(1 - b[0])
        b[0] = 1
    for i in range(n-1):
        sum += b[i]
        if sum > 0 and sum+b[i+1] > 0:
            tmp = -1 - sum
            ans += abs(tmp - b[i+1])
            b[i+1] = tmp
        elif sum < 0 and sum+b[i+1] < 0:
            tmp = 1 - sum
            ans += abs(tmp - b[i+1])
            b[i+1] = tmp

   # print(ans)
   # print(b)           
    
    tmp_ans_2 = ans
    
    if tmp_ans_1 <= tmp_ans_2:
        ans = tmp_ans_1
    elif tmp_ans_2 < tnp_ans_1:
        ans = tmp_ans_2

    print(ans)

if __name__ ==  "__main__":
    solve()


### FIXED CODE ###

def solve():

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

    b = [a[i] for i in range(n)]

   # print(a)
   # print(b)

    #Even
    sum_e = 0
    ans_e = 0

    for i in range(n):
        sum_e += a[i]
        if i%2 == 0:
            if sum_e <= 0:
                ans_e += abs(sum_e) + 1
                sum_e += abs(sum_e) + 1
        else:
            if sum_e >= 0:
                ans_e += abs(sum_e) + 1
                sum_e -= abs(sum_e) + 1

    #Odd
    sum_o = 0
    ans_o = 0

    for i in range(n):
        sum_o += b[i]
        if i%2 == 1:
            if sum_o <= 0:
                ans_o += abs(sum_o) + 1
                sum_o += abs(sum_o) + 1
        else:
            if sum_o >= 0:
                ans_o += abs(sum_o) + 1
                sum_o -= abs(sum_o) + 1

    if ans_o <= ans_e:
        ans = ans_o
    else:
        ans = ans_e


    print(ans)

if __name__ ==  "__main__":
    solve()
count = 1
while 1:
  x = int(raw_input())
  if x == 0:
    break
  print 'Case {0}: {1}'.format(count += 1+, x)

### FIXED CODE ###

count = 1
while 1:
  x = int(raw_input())
  if x == 0:
    break
  print 'Case {0}: {1}'.format(count, x)
  count += 1