Harryxun/stf_run huggingface dataset:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b, c = MAP()
'''
n = 5 * pow(10, 8)
m = 3 * n * n + 2 * n * (a + b + c)
a -= n
b -= n
c -= n
'''
ans = 'No'
'''
aa = reversed(str((a - b - c) * a))
bb = reversed(str((b - c - a) * b))
cc = reversed(str((c - a - b) * c))
'''
#print(-m, aa + bb + cc)
if floor(2 * sqrt(a * b)) < c - a - b:
    ans = 'Yes'
print(ans)


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

from decimal import *

a, b, c = MAP()

if c - a - b > 0 and (c - a - b) ** 2 > 4 * a * b:
    print('Yes')
else:
    print('No')
from datetime import datetime

S = input()

nowDate = datetime.strptime(S, '%Y/%m/%d')
lastDate =datetime.strptime('2019/04/30', '%Y/%m/%d')

if lastDate < nowTime:
	print("TBD")
else:
	print("Heisei")

### FIXED CODE ###

from datetime import datetime

S = input()

nowDate = datetime.strptime(S, '%Y/%m/%d')
lastDate =datetime.strptime('2019/04/30', '%Y/%m/%d')

if lastDate < nowDate:
	print("TBD")
else:
	print("Heisei")
H, W, D = list(map(int, input().split()))
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int, input().split())))

d = [0 for i in range(H*W)]
sA = [0 for i in range(H*W+1)]

for i in range(len(A)):
        for j in range(len(A[i])):
            sA[A[i][j]] = [i, j]

for i in range(D+1, H*W):
    d[i] = d[i-D] + abs(sA[i][0]-sA[i-D][0]) + abs(sA[i][1]-sA[i-D][1])

for lr in LR:
    l, r = lr[0], lr[1]
    print(d[r] - d[l])

### FIXED CODE ###

H, W, D = list(map(int, input().split()))
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
Q = int(input())
LR = []
for i in range(Q):
    LR.append(list(map(int, input().split())))

d = [0 for i in range(H*W+1)]
sA = [0 for i in range(H*W+1)]

for i in range(len(A)):
        for j in range(len(A[i])):
            sA[A[i][j]] = [i, j]

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(sA[i][0]-sA[i-D][0]) + abs(sA[i][1]-sA[i-D][1])

for lr in LR:
    l, r = lr[0], lr[1]
    print(d[r] - d[l])
Print("A" if str.isupper(input()) else "a")

### FIXED CODE ###

N=input()
print("A" if str.isupper(N) else "a")
N = input()
A = list(map(int,input().split()))
count = 0
for a in A:
    count_local = 0
    while a%2 == 0:
        a = a/2
        count_local += 1
        if count_local <= count:
            count = count_local

print(count)

### FIXED CODE ###

print(input().count("1"))
N = int(input())
A = [0 for _ in range(9)]
for a in map(int,input().split()):
  A[a//400]+=1
rate_num = 8-A[:-1].count(0)
print(rate_num, min(8,rate_num+A[-1]))

### FIXED CODE ###

N = int(input())
A = [0 for _ in range(9)]
for a in map(int,input().split()):
  A[min(a//400,8)]+=1
rate_num = 8-A[:-1].count(0)
print(max(1,rate_num), rate_num+A[-1])
N,K = map(int, input().split())
trees = [int(input()) for _ in range(N)]

trees.sort()

diffs = []
for i,h in trees[:N-K]:
  min_h = h
  max_h = trees[i+K]
  diffs.append(max_h-min_h)

print(min(diffs))


### FIXED CODE ###

N,K = map(int, input().split())
trees = [int(input()) for _ in range(N)]

def solve(N,K,trees):
    trees.sort()

    diffs = []
    for i,h in enumerate(trees[:N-K+1]):
        min_h = h
        max_h = trees[i+K-1]
        #print(min_h,max_h)
        diffs.append(max_h-min_h)

    print(min(diffs))
    return

solve(N,K,trees)
blue = [input() for i in range(int(input()))]
red = [input() for i in range(int(input()))]
print(max(0, [blue.count(i) - red.count(i) for i in set(blue + red)]))

### FIXED CODE ###

a = [input() for _ in range(int(input()))]
b = [input() for _ in range(int(input()))]
l = list(set(a))
c = max(0, max([a.count(i) - b.count(i) for i in l]))
print(c)
print("bust" if sum(map(int, input().strip().split()) >= 22 else "win")

### FIXED CODE ###

print("bust" if sum(map(int, input().strip().split())) >= 22 else "win")
i = list(map(int,input().split()))
A = i[0]
B = i[1]
if A>=13:
  print(B)
elif A<=5:
    print(0)
else:
    print(B/2)
i = list(map(int,input().split()))
A = i[0]
B = i[1]
if A>=13:
  print(B)
elif A<=5:
    print(0)
elif A>=6 and A<=12:
    print(B/2)


### FIXED CODE ###

A,B = map(int,input().split())
if A<6:
  print(0)
elif A<13:
  print(B//2)
else:
  print(B)
N=int(input())
K=int(input())
import math
ans=0
n=str(N)
a=len(n)
print(a)
def combi(p,q):
    return math.factorial(p)//(math.factorial(q)*math.factorial(p-q))
if a<K:
    ans=0
else:
    if a>K:
        ans+=combi(a-1,K)*(9**K)
        print(ans)
    if K==1:
        ans+=int(n[0])
    elif K==2:ans+=int(n[0])*(a-2)*9+(int(n[0])-1)*9+int(n[1])
    else:ans+=(int(n[0])-1)*81*(combi(a-1,2))+combi(a-2,2)*81+9*(a-2)*(int(n[1])-1)+int(n[2])+(a-3)*9

print(ans)

### FIXED CODE ###

N=int(input())
K=int(input())
import math
ans=0
n=str(N)
a=len(n)
def combi(p,q):
    if p<q : return 0
    else: return math.factorial(p)//(math.factorial(q)*math.factorial(p-q))
def mi(i):
    if i==0:
        return 0
    else:
        return i-1
def zero(i):
    if int(n[i])==0:
        return 0
    else:
        return 1
if a<K:
    ans=0
else:
    if a>K:
        ans+=combi(a-1,K)*(9**K)
    if K==1:ans+=int(n[0])
    elif K==2:
        x=0
        i=1
        b=0
        bs=0
        while True:
            if (int(n[i])!=0) and (x==0):
                b=int(n[i])
                bs=a-i
                x+=1
            if (x==1) or (i==len(n)-1):
                break
            i+=1
        ans+=mi(int(n[0]))*(a-1)*9+mi(bs)*9+b
    elif a==3 : ans+=mi(int(n[0]))*81*(combi(a-1,2))+9*mi(int(n[1]))+int(n[2])
    else:
        x=0
        i=1
        b=0
        bs=0
        c=0
        cs=0
        while True:
            if (int(n[i])!=0) and (x==0):
                b=int(n[i])
                bs=a-i
                x+=1
            elif (int(n[i])!=0) and (x==1):
                c=int(n[i])
                cs=a-i
                x+=1
            if (x==2) or (i==len(n)-1):
                break
            i+=1
        ans+=mi(int(n[0]))*81*(combi(a-1,2))+combi(bs-1,2)*81+9*(a-2)*mi(b)+c+mi(cs)*9

print(ans)
b = input()
if b == "A":
  print("T")
elif b == "T":
  print("A")
elif b == "C":
  print("D")
else b == "D":
  print("C")

### FIXED CODE ###

b = input()
if b == "A":
  print("T")
elif b == "T":
  print("A")
elif b == "C":
  print("G")
else:
  print("C")
S = input().split("/")

if int(S[5]) < 5　and s[4] == 0 :
	print('Heisei')
else :
	print('TBD')

### FIXED CODE ###

s = input()

if s <= "2019/04/30":
    print("Heisei")
else:
    print("TBD")
import sys
H, W, M = map(int, input().split())
hList = {i+1: 0 for i in range(H)}
wList = {i+1: 0 for i in range(W)}
pList = set()
#print(hList, wList, pList)
for _ in range(M):
  h, w = list(map(int, input().split()))
  #print(h, w)
  hList[h] += 1
  wList[w] += 1
  pList.add((h, w))
#print(hList, wList, pList)

maxCount = max(hList.values())
maxHList = [h for h, count in hList.items() if count==maxCount]
if maxCount==0:
  print(0)
  sys.exit(0)


maxCount = max(wList.values())
maxWList = [w for w, count in wList.items() if count==maxCount]

#counterList = []
#for maxH in maxHList:
#  for maxW in maxWList:
#    counterList.append(hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0))
#print(max(counterList))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))
print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))
for maxH, maxW in (maxH, maxW for maxH in maxHList for maxW in maxWList):
	if (maxH, maxW) in pList:
		print(hList[maxH] + wList[maxW] - 1)
		sys.exit(0)

print(hList[maxH] + wList[maxW])


### FIXED CODE ###

import sys
H, W, M = map(int, input().split())
hList = {i+1: 0 for i in range(H)}
wList = {i+1: 0 for i in range(W)}
pList = set()
#print(hList, wList, pList)
for _ in range(M):
  h, w = list(map(int, input().split()))
  #print(h, w)
  hList[h] += 1
  wList[w] += 1
  pList.add((h, w))
#print(hList, wList, pList)

maxHCount = max(hList.values())
maxHList = [h for h, count in hList.items() if count==maxHCount]


maxWCount = max(wList.values())
maxWList = [w for w, count in wList.items() if count==maxWCount]

#counterList = []
#for maxH in maxHList:
#  for maxW in maxWList:
#    counterList.append(hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0))
#print(max(counterList))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))

#if M < len(maxHList)*len(maxWList):
#	print(maxHCount + maxWCount)
#	sys.exit(0)

for maxH in maxHList:
  for maxW in maxWList:
    if (maxH, maxW) not in pList:
      print(maxHCount + maxWCount)
      sys.exit(0)

print(maxHCount + maxWCount - 1)
import copy
n = int(input())
a = list(map(int,input().split()))
a_1 = a.copy()

ans = 0
ans_2 = 0
o = 0
for i in range(n):
    if i == 0:
        if a[i] == 0:
            f = "+"
            a[i] = 1
        elif a[0] > 0:
            f = "+"
        elif a[0] < 0:
            f = "-"
    else:
        o += a[i-1]
        if f == "+":
            if a[i] + o > 0:
                c = -1 - o
                ans += abs(c - a[i])
                a[i] = c
                f = "-"
            else:
                if a[i] + o == 0:
                    a[i] -= 1
                    ans += 1
                f = "-"
        elif f == "-":
            if a[i] + o < 0:
                c = 1 - o
                ans += abs(c - a[i])
                a[i] = c
                f = "+"
            else:
                if a[i] + o == 0:
                    a[i] += 1
                    ans += 1
                f = "+"
o = 0
a = a_1
#print(a)
for i in range(n):
    if i == 0:
        if a[i] == 0:
            f = "+"
            a[i] = 1
        elif a[0] > 0:
            f = "-"
            ans_2 += abs(-1 - a[0])
            a[i] = -1
        elif a[0] < 0:
            ans_2 += abs(1 - a[0])
            a[i] = 1
            f = "+"
    else:
        o += a[i-1]
        if f == "+":
            if a[i] + o > 0:
                c = -1 - o
                ans_2 += abs(c - a[i])
                a[i] = c
                f = "-"
            else:
                if a[i] + o == 0:
                    a[i] -= 1
                    ans_2 += 1
                f = "-"
        elif f == "-":
            if a[i] + o < 0:
                c = 1 - o
                ans_2 += abs(c - a[i])
                a[i] = c
                f = "+"
            else:
                if a[i] + o == 0:
                    a[i] += 1
                    ans_2 += 1
                f = "+"
#print(a)
print(min(ans,ans_2))


### FIXED CODE ###

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

ans = 0
f = 1
num = 0
for i in range(n):
    num += a[i]
    if f:
        if num <= 0:
            ans += 1 - num
            num = 1
        f = 0
    else:
        if num >= 0:
            ans += abs(-1 - num)
            num = -1
        f = 1

ans_2 = 0
f = 1
num = 0
for i in range(n):
    num += a[i]
    if f:
        if num >= 0:
            ans_2 += abs(-1 - num)
            num = -1
        f = 0
    else:
        if num <= 0:
            ans_2 += 1 - num
            num = 1
        f = 1

print(min(ans,ans_2))
import numpy as np

N, S = map(int, input().split())
x = [int(x) for x in input().split()]
x = [0, *x]
 
# 状態リストを作成
m = np.zeros((S+1,3))
p = np.zeros((S+1,3))
p[0,0] = 1

# 前状態から次状態の場合数を計算
for i in range(1,N+1):
    
    # x[i] を加えない場合
    m[:,0] = p[:,0]
    m[:,1] = p[:,0] + p[:,1]  # 今回から開始して加えない、もしくは既に開始しているが、加えない
    m[:,2] = p[:,0] + p[:,1] + p[:,2]  # 今回、開始・終了して加えない、今回開始して加えず終了。

    # x[i] を加える場合
    m[x[i]:,1] += p[:-x[i],0] + p[:-x[i],1]
    m[x[i]:,2] += p[:-x[i],0] + p[:-x[i],1]

    p[:,0] = m[:,0] % 998244353
    p[:,1] = m[:,1] % 998244353
    p[:,2] = m[:,2] % 998244353
            
print(int(m[S,2]))

### FIXED CODE ###

import numpy as np

N, S = map(int, input().split())
x = [int(x) for x in input().split()]
 
# 状態リストを作成
m = np.zeros((S+1,3))
p = np.zeros((S+1,3))
p[0,0] = 1

# 前状態から次状態の場合数を計算
for i in range(1,N+1):
    
    # x[i] を加えない場合
    m[:,0] = p[:,0]
    m[:,1] = p[:,0] + p[:,1]  # 今回から開始して加えない、もしくは既に開始しているが、加えない
    m[:,2] = p[:,0] + p[:,1] + p[:,2]  # 今回、開始・終了して加えない、今回開始して加えず終了。

    # x[i] を加える場合
    m[x[i-1]:,1] += p[:-x[i-1],0] + p[:-x[i-1],1]
    m[x[i-1]:,2] += p[:-x[i-1],0] + p[:-x[i-1],1]

    p[:,0] = m[:,0] % 998244353
    p[:,1] = m[:,1] % 998244353
    p[:,2] = m[:,2] % 998244353
            
print(int(p[S,2]))
while True:
    N, M = map(int, raw_input().split())
    if N == 0 and M == 0: break
    h = [input() for _ in range(N)]
    for i in range(N-1):
        h[i+1] += h[i]
    w = [input() for _ in range(M)]
    for i in range(M-1):
        w[i+1] += w[i]
    h = [0] + h
    w = [0] + w
    hl = [0] * (1000 * 1000 + 1)
    wl = [0] * (1000 * 1000 + 1)
    for i in range(N):
        for j in range(i+1, N+1):
            hl[h[j]-h[i]] += 1
    for i in range(M):
        for j in range(i+1, M+1):
            wl[w[j]-w[i]] += 1

    ans = 0
    for i, j in zip(hl, wl):
        ans += i*j
    print ans

### FIXED CODE ###

while True:
    N, M = map(int, raw_input().split())
    if N == 0 and M == 0: break
    h = [input() for _ in range(N)]
    for i in range(N-1):
        h[i+1] += h[i]
    w = [input() for _ in range(M)]
    for i in range(M-1):
        w[i+1] += w[i]
    h = [0] + h
    w = [0] + w
    hl = [0] * (h[-1] + 1)
    wl = [0] * (w[-1] + 1)
    for i in range(N):
        for j in range(i+1, N+1):
            hl[h[j]-h[i]] += 1
    for i in range(M):
        for j in range(i+1, M+1):
            wl[w[j]-w[i]] += 1

    ans = 0
    for i, j in zip(hl, wl):
        ans += i*j
    print ans
import numpy as np


### FIXED CODE ###

import sys

lines = []
for line in sys.stdin:
    lines.append(line.strip().split(','))

field = [[0 for i in range(10)] for j in range(10)]

def drop(x, y, z):
    if z==1:
        for i in range(-1,2):
            for j in range(-1,2):
                if abs(i)+abs(j)<2 and 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1
    elif z==2:
        for i in range(-1,2):
            for j in range(-1,2):
                if 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1
    else:
        for i in range(-2,3):
            for j in range(-2,3):
                if abs(i)+abs(j)<3 and 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1



for line in lines:
    x,y,z = map(int, line)
    drop(x,y,z)

n = 0
m = 0
for f in field:
    for e in f:
        if e > m:
            m = e
        if e==0:
            n+=1

print(n)
print(m)
# coding: utf-8
# Here your code !

Dice = [1,2,3] # top,front,right

def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
    
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
    
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d

def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d

def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d

def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d



while True:
    n = int(input())
    if n == 0:
        break
    
    dice = [1,2,3]
    result = 1
    
    for _ in range(n):
        direction = input()
        dice = eval(direction+"(dice)")
        #print(dice)
        
        result += dice[0]
    
    print(result)
        

### FIXED CODE ###

# coding: utf-8
# Here your code !
import sys
f = sys.stdin

def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
      
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
      
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d
  
def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d
  
def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d
  
def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d
  
  
  
while True:
    n = int(f.readline())
    if n == 0:
        break
      
    dice = [1,2,3]
    result = 1
      
    for _ in range(n):
        direction = f.readline().rstrip()
   
        dice = eval(direction+"(dice)")
     
          
        result += dice[0]
      
    print(result)
import sys
n = int(input())
past_t = past_x = past_y = 0
i = 0
while(i <= n-1):
    t, x, y = map(int,input().split())
    i += 1 
for j in range(n):
    if t - past_t < x + y or ((t-past_t)-(x+y)) % 2 != 0:
        sys.exit('No')
print('Yes')


### FIXED CODE ###

n = int(input())
judge = 'Yes'
past_t = past_x = past_y = 0
for i in range(n):
    t, x, y = map(int,input().split())
    if t - past_t < x + y or ((t-past_t)-(x+y)) % 2 != 0:
        judge = 'No'
print(judge)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    table = [0] * (10**5+5)
    for i in range(len(a)):
        table[a[i]-1] += 1

    for i in range(n):
        print(table[i])


main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    table = [0] * (2*10**5+5)
    for i in range(len(a)):
        table[a[i]-1] += 1

    for i in range(n):
        print(table[i])


main()
n, k = map(int, input().split())
h = [int(x) for x in input().split()]
dp = [None] * n
 
INF = float('inf')
 
dp[0] = 0
for x in range(1, n):
  dp[x] = min(dp.get(x - i, INF) + abs(h[x] - h[x - i]) for i in range(1, min(k,x) + 1))
 
print(dp[n-1])

### FIXED CODE ###

dp = {}

n = int(input())
h = [int(x) for x in input().split()]

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for x in range(2, n):
  dp[x] = min(
    dp[x - 1] + abs(h[x] - h[x - 1]),
    dp[x - 2] + abs(h[x] - h[x - 2])
  )

print(dp[n-1])
from functools import lru_cache

n = int(input())
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# メモ用のDP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

@lru_cache(None)
# メモ化再帰の関数
def rec(i):
    # # DPの値が更新されている場合はその値を返す
    # if dp[i] <  f_inf:
    #     return dp[i]
    
    # 再帰の終了条件。足場0のコストは0
    if i == 0:
        return 0
    
    # i-1, i-2　を再帰
    res = f_inf
    # i-1 から来た場合
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    # i-2 から来た場合
    if i > 1:
        res = chmin(res, rec(i-2) + abs(h[i] - h[i-2]))
    
    # # 結果をメモする
    # dp[i] = res
    return res

ans = rec(n-1)
print(ans)

### FIXED CODE ###

n = int(input())
h = [int(i) for i in input().split()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
    
# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i-1]))
    # 一番目の足場では一つ前しか存在しない
    if i > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i -2]))

print(dp[n-1])
n=int(input())
a = list(map(int,input().split()))
a = a.sort(reverse=true)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        ans = -1
        break
print(ans)

### FIXED CODE ###

n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 1000000000000000000:
        if a[n-1] == 0:
            ans = 0
        else:
            ans = -1
        break

print(ans)
def step(n, lis):
  return [l+n for l in lis]

def func(lis):
  if len(lis)==0:
    return -1
  maxval = max(lis)
  lis.pop(lis.index(maxval))
  if maxval==2:
    lis.append(1)
  if maxval>2:
    lis.append(maxval-1)
    lis.append(maxval-2)
  lis.sort()
  lis = lis[:maxA]
  return maxval
N = int(input())
A = list(map(int, input().split()))
maxA = max(A)

lis = [0]
count = 0
ans = 0
flag=False
for i in range(N+1):
  count += 1
  if flag:
    break
  if A[i]==0:
    continue
  lis = step(count, lis)
  count=0
  a = A[i]
  #print(i,lis)
  for j in range(a):
    
    res = func(lis)
    #print(i, res, lis)
    if res == -1:
      flag=True
      break
    else:
      ans += res
  
if flag:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

H1, M1, H2, M2, K = map(int, input().split())
ans = (H2*60 + M2) - (H1*60 + M1) - K
print(ans)
H, W = map(int,input().split())

s = []
for i in range(H):
    ss = input()
    s.append(ss)

shift = [[1,0],[-1,0],[0,1],[0,-1]]

for j in range(H):
    for i in range(W):
        if s[j][i] == "#":
            flag = False
            for dx, dy in shift:
                nx = i + dx
                ny = j + dy
                if nx >= 0 and nx < W and ny >= 0 and ny < H:
                    if s[ny][nx] == "#":
                        flag = True
            if not flag:
                break

if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

H,W = map(int,input().split())
s = []
for _ in range(H):
    s.append(input())

shift = [[1,0],[-1,0],[0,-1],[0,1]]

flag = True
for j in range(H):
    for i in range(W):
        if s[j][i] == ".":
            continue
        else:
            flag = False
            for dx,dy in shift:
                nx = i + dx
                ny = j + dy
                
                if nx >= 0 and nx < W and ny >= 0 and ny < H:
                    if s[ny][nx] == "#":
                        flag = True
            if not flag:
                print("No")
                exit(0)

print("Yes")
while True:
    N, M = map(int, raw_input().split())
    if N == 0 and M == 0: break
    h = [input() for _ in range(N)]
    for i in range(N-1):
        h[i+1] += h[i]
    w = [input() for _ in range(M)]
    for i in range(M-1):
        w[i+1] += w[i]
    h = [0] + h
    w = [0] + w
    hl = [0] * (1000 * 1000)
    wl = [0] * (1000 * 1000)
    for i in range(N):
        for j in range(i+1, N+1):
            hl[h[j]-h[i]] += 1
    for i in range(M):
        for j in range(i+1, M+1):
            wl[w[j]-w[i]] += 1

    ans = 0
    for i, j in zip(hl, wl):
        ans += i*j
    print ans

### FIXED CODE ###

while True:
    N, M = map(int, raw_input().split())
    if N == 0 and M == 0: break
    h = [input() for _ in range(N)]
    for i in range(N-1):
        h[i+1] += h[i]
    w = [input() for _ in range(M)]
    for i in range(M-1):
        w[i+1] += w[i]
    h = [0] + h
    w = [0] + w
    hl = [0] * (h[-1] + 1)
    wl = [0] * (w[-1] + 1)
    for i in range(N):
        for j in range(i+1, N+1):
            hl[h[j]-h[i]] += 1
    for i in range(M):
        for j in range(i+1, M+1):
            wl[w[j]-w[i]] += 1

    ans = 0
    for i, j in zip(hl, wl):
        ans += i*j
    print ans