Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###


def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  
  
  for k in d.keys():
    tmp = d.copy()
    tmp[k] -= 1
    h = list(tmp.values())
    i = list(map(func, h))
    ans = sum(i)
    e[k] = ans
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()
### BUGGY CODE ###

# from time import perf_counter


def main():
    r, g, b, n = list(map(int, input().split()))
    count = 0
    x1, x2, x3 = sorted([r, g, b], reverse=True)
    # print(x1, x2, x3)
    for i in range(n // x1 + 1):
        for j in range((n - i) // x2 + 1):
            for k in range((n - i - j) // x3 + 1):
                # print(f'{r}*{i} + {g}*{j} + {b}*{k} = {r*i+g*j+k+b*k}')
                if x1 * i + x2 * j + x3 * k == n:
                    count += 1

    print(count)


if __name__ == '__main__':
    # s = perf_counter()
    main()
    # e = perf_counter()
    # print('process:', e - s)


### FIXED CODE ###

# from time import perf_counter


def main():
    r, g, b, n = list(map(int, input().split()))
    count = 0
    x1, x2, x3 = sorted([r, g, b], reverse=True)
    # print(x1, x2, x3)
    for i in range(n // x1 + 1):
        for j in range((n - i) // x2 + 1):
            rest = n - (x1 * i) - (x2 * j)
            # print(f'{x1}*{i} + {x2}*{j} = {n - rest}')
            if rest == 0:
                # print(f'{x1}*{i} + {x2}*{j} + {x3}*0 = {n}')
                count += 1
            else:
                # print(f'{x1}*{i} + {x2}*{j} + {x3}*? = {n}')
                count += (1 if rest > 0 and rest % x3 == 0 else 0)
            # for k in range((n - i - j) // x3 + 1):
                # print(f'{r}*{i} + {g}*{j} + {b}*{k} = {r*i+g*j+k+b*k}')
            #    if x1 * i + x2 * j + x3 * k == n:
            #        count += 1

    print(count)


if __name__ == '__main__':
    # s = perf_counter()
    main()
    # e = perf_counter()
    # print('process:', e - s)
### BUGGY CODE ###

def main():
    from collections import deque
    import sys
    sys.setrecursionlimit(1000000)

    h, w = map(int, input().split())
    start = tuple(map(lambda x: int(x) - 1, input().split()))
    goal = tuple(map(lambda x: int(x) - 1, input().split()))

    maze = tuple([tuple(input()) for _ in range(h)])
    vis = [[False] * w for _ in range(h)]

    mw = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    mj = list(set((i, j) for i in range(-2, 3) for j in range(-2, 3)) - set(mw) - {(0, 0)})

    q = deque()
    q.append((start[0], start[1], 0))
    while q:
        y, x, c = q.popleft()
        if vis[y][x]:
            continue
        vis[y][x] = True
        if (y, x) == goal:
            print(c)
            break
        for a, b in mw:
            if 0 <= y + a < h and 0 <= x + b < w:
                if maze[y + a][x + b] == '.':
                    q.appendleft((y + a, x + b, c))
        for a, b in mj:
            if 0 <= y + a < h and 0 <= x + b < w:
                if maze[y + a][x + b] == '.':
                    q.append((y + a, x + b, c + 1))
    else:
        print(-1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from collections import deque

    h, w = map(int, input().split())
    ch, cw = map(lambda x: int(x) - 1, input().split())
    dh, dw = map(lambda x: int(x) - 1, input().split())

    m = [list(input()) for _ in range(h)]
    vis = [[False for _ in range(w + 2)] for _ in range(h + 2)]

    def walk(i, j):
        q = deque()
        q.append((i, j))
        edge = []
        while q:
            y, x = q.popleft()
            if vis[y][x]:
                continue
            vis[y][x] = True
            for s, t in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                if not 0 <= y + s <= h - 1 or not 0 <= x + t <= w - 1:
                    continue
                if m[y + s][x + t] == '#':
                    edge.append((y, x))
                    continue
                q.appendleft((y + s, x + t))
        return edge

    def jump(i, j, c):
        q = walk(i, j)
        if vis[dh][dw]:
            return c
        nx = []
        c += 1
        while q:
            y, x = q.pop()
            for s in range(-2, 3):
                for t in range(-2, 3):
                    if not 0 <= y + s <= h - 1 or not 0 <= x + t <= w - 1:
                        continue
                    if vis[y + s][x + t]:
                        continue
                    if m[y + s][x + t] == '#':
                        continue
                    nx += walk(y + s, x + t)
                    if vis[dh][dw]:
                        return c
            if len(q) == 0:
                c += 1
                q = nx
                nx = []

    ans = jump(ch, cw, 0)
    print(ans if ans is not None else -1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np

N=int(input())


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

sum=a[0]

for i in range(1,N):
    sum = sum*a[i]

if sum<=pow(10,18):
    print(sum)
else:
    print('-1')


### FIXED CODE ###

import numpy as np

N = int(input())

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

sum = a[0]


if 0 in a:
    print('0')
    exit()

for i in range(1, N):
    sum = sum * a[i]
    if sum > 10**18:
        print('-1')
        exit()

print(sum)
### BUGGY CODE ###

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

while len(set(A))!=1:
#for i in range(2):
    A.sort()
    for i in range(len(A)-1):
        if A.count(0):
            A.remove(0)
            break
        A[i+1]=A[i+1]%A[0]

print(max(A))

### FIXED CODE ###

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

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

A.sort()
y=A[0]
for i in range(1,N):
    y=gcd(y,A[i])
print(y)
### BUGGY CODE ###

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

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

for i in range(1, n):
    ans += sum(nums[:i]) * nums[i]
    ans = ans % x

print(ans)


### FIXED CODE ###

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

n = int(input())
nums = list(map(int, input().split()))
x = 10 ** 9 + 7

ans = 0

sums = [0] * (n - 1)

for j in range(n - 1):
    if j == 0:
        sums[0] = nums[0] % x
    else:
        sums[j] = (sums[j - 1] + nums[j]) % x

for i in range(1, len(nums)):
    ans += sums[i - 1] * nums[i]
    ans = ans % x

print(ans)
### BUGGY CODE ###

n=input()
a=map(int,raw_input().split())
for i in xrange(1,n+1):
    print a.count(i)

### FIXED CODE ###

n=input();a=map(int,raw_input().split());d={}
for i in xrange(1,n+1):d[i]=0
for i in a:d[i]+=1
for i in xrange(1,n+1):print d[i]
### BUGGY CODE ###

N = int(input())
List = list(map(int,input().split()))
counter=0
for i in range(N):
  if min(List[0:i+1])==List[i]:
    counter=counter+1
      
print(counter)

### FIXED CODE ###

n=int(input())
p=list(map(int,input().split()))
cnt=0
min_num=p[0]
for i in p:
    if i<=min_num:
        min_num=i
        cnt+=1
print(cnt)
### BUGGY CODE ###

def main():
    S = input()
    S = list(S[::-1])
    T = 'dreamer', 'dream', 'eraser', 'erase'
    for s in S:
        for t in T:
            t = t[::-1]
            if ''.join(S[:len(t)]) == t:
                S = S[len(t):]

    if len(S) > 0:
        print('NO')
    else:
        print('YES')

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    S = input()
    S = S[::-1]
    _T = 'dreamer', 'dream', 'eraser', 'erase'
    T = []
    for t in _T:
        T.append(t[::-1])
    i = 0
    while 1:
        temp = []
        bool = True
        for t in T:
            if S[i:len(t) + i] == t:
                i += len(t)
                bool = False
        if bool:
            break
    if len(S) != i:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()
### BUGGY CODE ###

s=input()
n=len(s)
#print(s,n)
count=0
for i in range(n-3):
  for j in range(4,n-i+1):
    if int(s[i:i+j])%2019==0:
      count+=1
      #print(i,i+j)
print(count)

### FIXED CODE ###

s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)
### BUGGY CODE ###

N = int(input())
res = 10**10 + 1
for A in range(1, N + 1):
    for B in range(1, A + 1):
        total = A * B
        if total == N:
            a = len(str(A))
            b = len(str(B))
            if a > b:
                num = a
            else:
                num = b
            if res > num:
                res = num
print(res)


### FIXED CODE ###

import math
N = int(input())
ans = float('Inf')
sq = int(math.sqrt(N)) + 1
for i in range(1, sq):
    if N % i == 0:
        a = len(str(i))
        b = len(str(N // i))
        if a > b:
            num = a
        else:
            num = b
        if ans > num:
            ans = num
print(ans)
### BUGGY CODE ###

N,C = list(map(int,input().split()))
imos = [[0 for j in range(10**5+1)] for i in range(C)]
for i in range(N):
    l,r,c = list(map(int,input().split()))
    c -= 1
    l -= 1
    imos[c][l] += 1
    imos[c][r] -= 1

for c in range(C):
    for i in range(1,10**5+1):
        imos[c][i] += imos[c][i-1]
for c in range(C):
    for i in range(10**5+1):
        if (imos[c][i] > 0):
            imos[c][i] = 1

ans = 0

for i in range(10**5):
    cnt = 0
    for c in range(C):
        cnt += imos[c][i]

    ans = max(cnt,ans)

print(ans)

### FIXED CODE ###

def merge(s):
    correct_s = []
    s.sort(key = lambda x:(x[2],x[0]))
    min_max = [s[0][0],s[0][1]]
    for i in range(1,len(s)):
        if s[i][2] == s[i-1][2] and s[i][0] == min_max[1]:
            min_max[1] = s[i][1]   
        else:
            correct_s.append([min_max[0],min_max[1],s[i-1][2]])
            min_max[0],min_max[1] = s[i][0],s[i][1]
    else:
        correct_s.append([min_max[0],min_max[1],s[len(s)-1][2]])

    return correct_s
        
        
    
import heapq
N,C = list(map(int,input().split()))
data = []
av = []
for i in range(N):
    data.append(list(map(int,input().split())))
    


s = merge(data)
s.sort()


for i in range(len(s)):
    if i == 0:
        heapq.heappush(av,s[i][1])
    elif s[i][0] <= av[0]:
        heapq.heappush(av,s[i][1])
    else:
        heapq.heappop(av)
        heapq.heappush(av,s[i][1])

print(len(av))
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1,n+1):
  tmp = int(n/i)
  ans += i * tmp * (tmp + 1)

print(int(ans/2))

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1,n+1):
  tmp = int(n/i)
  ans += i * tmp * (tmp + 1)

print(int(ans/2))
### BUGGY CODE ###

A=input()
list1=input().split()
A=int(A)
 
Ans=1
for i in range(0,A):
    Ans= Ans*int(list1[i])
    
if 10**18<Ans:
    print(-1)
else:   
    print(Ans)

### FIXED CODE ###

A=input()
list1=input().split()
A=int(A)
Ans=1
#---------------------------

if "0" in list1:
    print("0")
    
else:
    for i in range(0,A):
        Ans=Ans*int(list1[i])    
        if Ans >10**18:
                print(-1)
                break
    if Ans <=10**18:    
        print(Ans)
### BUGGY CODE ###

dif_max = 1-10**9
max = 1
min = 10**9
n_max = 0
n_max = int(raw_input())
 
price = [0]*n_max
for i in range(0, n_max):
  price[i] = int(raw_input())
for i in range(0, n_max-1):
  if min >= price[i]:
      min = price[i]
  for j in range(i+1, n_max):
      if max <= price[j]:
          max = price[j]
  if dif_max <= max - min:
      dif_max = max - min
  max = 1
  min = 10**9
print dif_max

### FIXED CODE ###

import sys

n = int(raw_input())

min_R = int(raw_input())
nums = map(int, sys.stdin.readlines())

ans = -10**9

for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
        
print ans
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def dfs(v, p):
        for u in edge_extend[p][v]:
            next_p = 0 if p == 2 else p + 1
            if dist[next_p][u] <= dist[p][v] + 1:
                continue
            else:
                dist[next_p][u] = dist[p][v] + 1
                dfs(u, next_p)

    n, m = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, input().split())
        edge[u - 1].append(v - 1)
    s, t = map(int, input().split())

    edge_extend = []
    for _ in range(3):
        edge_extend.append(edge)

    dist = [[f_inf] * n for _ in range(3)]
    dist[0][s - 1] = 0
    dfs(s - 1, 0)
    print(dist[0][t - 1] // 3 if dist[0][t - 1] != f_inf else -1)


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, input().split())
        edge[u - 1].append(v - 1)
    s, t = map(int, input().split())

    dist = [[f_inf] * 3 for _ in range(n)]
    que = deque([])
    que.append([s - 1, 0])
    dist[s - 1][0] = 0
    while que:
        v, l = que.popleft()
        for u in edge[v]:
            nl = (l + 1) % 3
            if dist[u][nl] == f_inf:
                dist[u][nl] = dist[v][l] + 1
                que.append([u, nl])

    res = dist[t - 1][0]
    print(-1 if res == f_inf else res // 3)


if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
P = [i-1 for i in P]
ans = -1e18
for si in range(N):
    x = si
    s = []
    tot = 0
    while True:
        x = P[x]
        s.append(C[x])
        tot += C[x]
        if x == si :
            break
    l = len(s)
    t = 0
    for i in range(l):
        t += s[i]
        if i+1 > K:
            break
        now = t
        if tot > 0:
            e = (K-i-1)//l
            now += tot*e
        ans = max(ans,now)
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
P = [int(t) - 1 for t in input().split()]
C = list(map(int,input().split()))

ans = -1e18
for si in range(N):
    x = si
    s = []
    tot = 0
    while True:
        x = P[x]
        s.append(C[x])
        tot += C[x]
        if x == si:
            break
    l = len(s)
    t = 0
    for i in range(l):
        t += s[i]
        if i+1 > K:
            break
        now = t
        if tot > 0:
            e = (K-(i+1))//l
            now += tot*e
        if ans < now:
            ans = now
print(ans)
### BUGGY CODE ###

from itertools import combinations

N = int(input())
strings = [input() for _ in range(N)]

sorted_strings = [''.join(sorted(s)) for s in strings]

num_anagram = 0
for i, j in combinations(sorted_strings, 2):
  if i == j:
    num_anagram += 1

print(num_anagram)

### FIXED CODE ###

from math import factorial
from collections import Counter


N = int(input())
strings = [input() for _ in range(N)]

sorted_strings = [''.join(sorted(s)) for s in strings]
num_strings = Counter(sorted_strings).values()

num_anagram = int(sum(factorial(num) / (factorial(num-2) * 2) if num >= 2 else 0
                      for num in num_strings))
print(num_anagram)
### BUGGY CODE ###

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

fi_flg = False
res = 0
while fi_flg is False:
  twice_flg = False
  for i in range(N):
    if a[i] % 2 == 0:
      if twice_flg is False:
        a[i] = int(a[i]/2)
        twice_flg = True
        break
 
  if twice_flg is False:
    fi_flg = True
  else:
    res += 1

print(res)

### FIXED CODE ###

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

res = 0
for i in range(N):
  fi_flg = False
  while fi_flg is False:
    if a[i] % 2 == 0:
      a[i] = int(a[i]/2)
      res += 1
    else:
      fi_flg = True
      
print(res)
### BUGGY CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    ans*=a[i]
if ans>10**18:
    print(-1)
    quit()
print(ans)

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    if a[i]==0:
        print(0)
        quit()
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        print(-1)
        quit()
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

N = int(input())
mon = input().split(" ")
for i in range(N):
    a = int(mon[i])
    mon[i]=a
def gcd(x,y):
    if y ==0:
        return x
    else:
        return gcd(y,x%y)
for i in range(N):
    for m in range(N):
        if i !=m:
            k = gcd(mon[i],mon[m])
            mon[i] =k
            mon[m] = k

print(min(mon))

### FIXED CODE ###

from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
x=gcd(a[0],a[1])
for i in range(2,len(a)):
  x=gcd(x,a[i])
print(x)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
ls = [1]*(10**6+1)
cnt = [0]*(10**6+1)
for i in range(n):
    cnt[a[i]] += 1
    if ls[a[i]] == 1:
        for j in range(a[i]*2, 10**6+1, a[i]):
            ls[j] = 0
ans = 0
for i in range(n):
    if ls[a[i]] == 1 and cnt[a[i]] == 1:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
ls = [1] * (10 ** 6 + 1)
cnt = [0] * (10 ** 6 + 1)
for i in range(n):
    cnt[a[i]] += 1
    if cnt[a[i]] == 1:
        if ls[a[i]] == 1:
            for j in range(a[i] * 2, 10 ** 6 + 1, a[i]):
                ls[j] = 0
ans = 0
for i in range(n):
    if ls[a[i]] == 1 and cnt[a[i]] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    n = int(input())

    def f(num):
        ans = 0
        x = 1
        while x**2 < num:
            y = 1
            while x**2 + y**2 + x*y < num:
                z = 1
                while x**2 + y**2 + z**2 + x*y + y*z + z*x <= num:
                    if x**2 + y**2 + z**2 + x*y + y*z + z*x ==num:
                        ans +=1
                    z += 1
                y += 1
            x += 1
        return ans

    for i in range(1, n+1):
        print(f(i))
    

if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    n = int(input())
    l = [0]*(n+1)
    for x in range(1,101):
        for y in range(1,101):
            for z in range(1,101):
                temp = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if temp <= n:
                    l[temp] += 1

    for i in range(1, n+1):
        print(l[i])


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())

m = []
for i in range(5):
	m.append(int(input()))

s = [n,0,0,0,0,0]
cnt = 0
while s[-1] != n:
	if s[4]-m[4] >= 0:
		s[4] -= m[4]
		s[5] += m[4]
	else:
		s[5] += s[4]
		s[4] = 0
	if s[3]-m[3] >= 0:
		s[3] -= m[3]
		s[4] += m[3]
	else:
		s[4] += s[3]
		s[3] = 0
	if s[2]-m[2] >= 0:
		s[2] -= m[2]
		s[3] += m[2]
	else:
		s[3] += s[2]
		s[2] = 0
	if s[1]-m[1] >= 0:
		s[1] -= m[1]
		s[2] += m[1]
	else:
		s[2] += s[1]
		s[1] = 0
	if s[0]-m[0] >= 0:
		s[0] -= m[0]
		s[1] += m[0]
	else:
		s[1] += s[0]
		s[0] = 0
	cnt += 1

print(cnt)

### FIXED CODE ###

import math

n = int(input())

m = []
for i in range(5):
	m.append(int(input()))

for i in range(4):
	if m[i] < m[i+1]:
		m[i+1] = m[i]

cnt = 5

cnt += math.ceil(n/m[0]) -1

l = []

for i in m:
	l.append(math.ceil(n/i))

for i in range(4):
	cnt +=(l[i+1] - l[i])

print(cnt)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
INF = 10**10

A = [tuple(map(int, input().split())) for _ in range(H)]
B = [tuple(map(int, input().split())) for _ in range(H)]

C = [[abs(a - b) for a, b in zip(rowA, rowB)] for rowA, rowB in zip(A, B)]

D = [[set() for _ in range(W)] for _ in range(H)]
D[0][0].add(0)

for h in range(H):
    for w in range(W):
        if h < H - 1:
            for d in D[h][w]:
                D[h + 1][w].add(d + C[h][w])
                D[h + 1][w].add(d - C[h][w])
        if w < W - 1:
            for d in D[h][w]:
                D[h][w + 1].add(d + C[h][w])
                D[h][w + 1].add(d - C[h][w])

ans = INF
c = C[H - 1][W - 1]
for d in D[H - 1][W - 1]:
    ans = min(ans, abs(d - c), abs(d + c))
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
M = (H + W) * 80

A = [tuple(map(int, input().split())) for _ in range(H)]
B = [tuple(map(int, input().split())) for _ in range(H)]

dp = [[0] * W for _ in range(H)]
dp[0][0] = (1 << (M - abs(A[0][0] - B[0][0])))

for h in range(H):
    for w, (a, b) in enumerate(zip(A[h], B[h])):
        d = abs(a - b)
        mask = 0
        if h > 0:
            mask |= (dp[h - 1][w] << d)
            mask |= (dp[h - 1][w] >> d)
        if w > 0:
            mask |= (dp[h][w - 1] << d)
            mask |= (dp[h][w - 1] >> d)
        dp[h][w] |= mask

state = dp[-1][-1]
nums = []
for digit, b in enumerate(bin(state)[2:][:: -1]):
    if b == '1':
        nums.append(digit - M)
ans = min(abs(n) for n in nums)
print(ans)
### BUGGY CODE ###

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

odd = False
count = 0

while True:
    for i in A:
        if i%2 != 0:
            odd = True
        else:
            i = int(i/2)
    if odd:
        break

    # for i in A:
    #     i = int(i/2)

    count += 1

print(count)


### FIXED CODE ###

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

count = -1
flag = True

while flag == True:
    count += 1
    for i in range(N):
        if A[i]%2 == 0:
            A[i] /= 2

        else:
            flag = False
            break



print(count)
### BUGGY CODE ###

n=int(input())
s=[list(input()) for _ in range(n)]
ss=[si+si for si in s]
ss=ss+ss
ans=0
for i in range(n):
  for j in range(n):
    a=[si[j:j+n] for si in ss[i:i+n]]
    flg=True
    for k in range(n):
      for l in range(n):
        if a[k][l]!=a[l][k]:
          flg=False
          break
      if not flg:
        break
    if flg:ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
s=[list(input()) for _ in range(n)]
import numpy as np
ss=[si+si for si in s]
ss=np.array(ss+ss)
ans=0
for i in range(n):
    a=ss[i:i+n,:n]
    if np.array_equal(a,a.T):
      ans+=1
print(ans*n)