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

import sys
sys.setrecursionlimit(1000000)
N = int(input())
h_list = list(map(int,input().split()))

costs = [None for _ in range(N)]

def func(stone_num):
    if stone_num == 0:
        return 0
    if stone_num == 1:
        return func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num])
    return min(
        func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num]),
        func(stone_num-2) + abs(h_list[stone_num-2] - h_list[stone_num])
    )

print(func(N-1))

### FIXED CODE ###

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

costs = [None for _ in range(N)]

for i in range(N):
    if i == 0:
        cost = 0
    elif i == 1:
        cost = costs[i-1] + abs(h_list[i-1] - h_list[i])
    else:
        cost = min(
            costs[i-1] + abs(h_list[i-1] - h_list[i]),
            costs[i-2] + abs(h_list[i-2] - h_list[i])
        )
    costs[i] = cost

print(costs[-1])
### BUGGY CODE ###

import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)

### FIXED CODE ###

import sys
 
input = sys.stdin.readline
 
 
def main():
    H, W, M = map(int, input().split())
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    ans = row_max + col_max - 1
    c = False
    for x in row_index_list:
        for y in col_index_list:
            if not (x + 1, y + 1) in bomb:
                c = True
                break
        if c:
            break
    if c:
        ans += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(1, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        if r > n-1:
            continue
        ans[r] += 1

print("\n".join(map(lambda u: str(u//2), ans[1:])))

### FIXED CODE ###

n, x, y = map(int, input().split())
ans = [0] * n
for i in range(1, n+1):
    for j in range(i, n+1):
        r = min(
            abs(i-j),
            abs(x-i) + 1 + abs(y-j),
            abs(y-i) + 1 + abs(x-j)
        )
        ans[r] += 1

print("\n".join(map(str, ans[1:])))
### BUGGY CODE ###

def find(parents, x):
    if parents[x] == x:
        return x
    else:
        parents[x] = find(parents, parents[x])
        return parents[x]

def union(parents, x1, x2):
    y1 = find(parents, x1)
    y2 = find(parents, x2)
    if y1 != y2:
        parents[y1] = y2


n, k, l = map(int, input().split())

parents1 = list(range(n))
for _ in range(k):
    p, q = map(int, input().split())
    union(parents1, p - 1, q - 1)

parents2 = list(range(n))
for _ in range(l):
    r, s = map(int, input().split())
    union(parents2, r - 1, s - 1)

counter = [1] * n
for i in range(n):
    for j in range(i + 1, n):
        if find(parents1, i) == find(parents1, j) and find(parents2, i) == find(parents2, j):
            counter[i] += 1
            counter[j] += 1
print(' '.join(map(str, counter)))


### FIXED CODE ###

def find(parents, x):
    if parents[x] == x:
        return x
    else:
        parents[x] = find(parents, parents[x])
        return parents[x]

def union(parents, x1, x2):
    y1 = find(parents, x1)
    y2 = find(parents, x2)
    if y1 != y2:
        parents[y1] = y2


n, k, l = map(int, input().split())

parents1 = list(range(n))
for _ in range(k):
    p, q = map(int, input().split())
    union(parents1, p - 1, q - 1)

parents2 = list(range(n))
for _ in range(l):
    r, s = map(int, input().split())
    union(parents2, r - 1, s - 1)

import collections

counter = collections.defaultdict(int)
for i in range(n):
    p1, p2 = find(parents1, i), find(parents2, i)
    counter[(p1, p2)] += 1

ans = ' '.join(str(counter[(find(parents1, i), find(parents2, i))]) for i in range(n))
print(ans)
### BUGGY CODE ###

x=int(input())
a=0
while True:
    for b in range(10**2):
        if a**5-b**5==x:
            print(a,b)
            exit()
        elif a**5+b**5==x:
            print(a,-b)
            exit()
        elif -a**5+b**5==x:
            print(-a,-b)
            exit()
    a+=1


### FIXED CODE ###

x=int(input())
x5=[i**5 for i in range(0,10**3+1,1)]
for i in range(len(x5)):
    for j in range(len(x5)):
        if x5[i]-x5[j]==x:
            print(i,j)
            exit()
        if -x5[i]+x5[j]==x:
            print(-i,-j)
            exit()
        if x5[i]+x5[j]==x:
            print(i,-j)
            exit()
        if -x5[i]-x5[j]==x:
            print(-i,j)
            exit()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
S = input()
T = input()


def operate(i, j):
    group = {i, j}
    if group == {"A"}: return "B"
    elif group == {"B"}: return "A"
    elif group == {""}: return ""
    elif group == {"", "A"}: return "A"
    elif group == {"", "B"}: return "B"
    elif group == {"A", "B"}: return ""

def initialize(L):
    d, length = 2, len(L)
    while d < length:
        d *= 2
    BT = [""] * (2 * d - 1)
    for i in range(length):
        K = d + i -1
        BT[d + i - 1] = L[i]
        while K > 0:
            K = (K - 1)//2
            BT[K] = operate(BT[2 * K + 1], BT[2 * K + 2])
    return BT

def Search(i, j, l, r, level, BT):
    if r < i or j < l: return ""
    elif i <= l <= r <= j: return BT[level]
    else:
        sl = Search(i, j, l, (l+r)//2, 2*level+1, BT)
        sr = Search(i, j, (l+r)//2 + 1, r, 2*level+2, BT)
        ans = operate(sl, sr)
        return ans


ST, TT = initialize(S), initialize(T)
maxS, maxT = len(ST)//2, len(TT)//2
Q = int(input())
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    if Search(a-1, b-1, 0, maxS, 0, ST) == Search(c-1, d-1, 0, maxT, 0, TT): print("YES")
    else: print("NO")

### FIXED CODE ###

import sys
F = sys.stdin
S = F.readline().replace("A", "1").replace("B", "2").strip("\n")
T = F.readline().replace("A", "1").replace("B", "2").strip("\n")

sSum = [0] * (len(S)+1)
tSum = [0] * (len(T)+1)
for i in range(len(S)):
    sSum[i+1] = sSum[i] + int(S[i])
for i in range(len(T)):
    tSum[i+1] = tSum[i] + int(T[i])

Ans = ""
Q = int(F.readline().strip("\n"))
for _ in range(Q):
    a, b, c, d = map(int, F.readline().strip("\n").split(" "))
    if (sSum[b] - sSum[a-1]) % 3 == (tSum[d] - tSum[c-1]) % 3: Ans += "YES\n"
    else: Ans += "NO\n"
print(Ans)
### BUGGY CODE ###

N,K=map(int,input().split())
if(N<K):
  K=N
h=list(map(int,input().split()))
dp=[0 for i in range(N)]
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-K),i))
print(dp[N-1])                      
                      
                      
                  

### FIXED CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-K),i))
print(dp[N-1])
### BUGGY CODE ###

h, w, m = map(int, input().split())
targets = []
targets_count_yoko = [0]*w
targets_count_tate = [0]*h
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets.append((y, x))

max_row = max(targets_count_yoko)
max_line = max(targets_count_tate)
y_idx = []
x_idx = []
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx.append(i)
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx.append(i)


ans = max_line + max_row - 1
for y in y_idx:
    for x in x_idx:
        if (y, x) not in targets:
            ans += 1
            break
    else:
        continue
    break

print(ans)


### FIXED CODE ###

from collections import defaultdict
h, w, m = map(int, input().split())
targets = defaultdict(int)
targets_count_yoko = defaultdict(int)
targets_count_tate = defaultdict(int)
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_yoko[x] += 1
    targets_count_tate[y] += 1
    targets[(y, x)] = -1

max_row = max(targets_count_yoko.values())
max_line = max(targets_count_tate.values())
y_idx = defaultdict(bool)
x_idx = defaultdict(bool)
max_count_x = 0
max_count_y = 0
for i in range(w):
    if targets_count_yoko[i] == max_row:
        x_idx[i] = True
        max_count_x += 1
for i in range(h):
    if targets_count_tate[i] == max_line:
        y_idx[i] = True
        max_count_y += 1


ans = max_line + max_row
kumi = max_count_x*max_count_y
for key_y, key_x in targets.keys():
    if y_idx[key_y] and x_idx[key_x]:
        kumi -= 1
    if kumi == 0:
        break

if kumi == 0:
    print(ans-1)
else:
    print(ans)
### BUGGY CODE ###

from collections import defaultdict
N, X, Y = map(int, input().split())

dic = defaultdict(int)

X = X - 1
Y = Y - 1

for i in range(N):
    for j in range(i + 1, N):
        if i <= X and Y <= j:
            v = X - i + 1 + j - Y
        elif (i <= X) and (X <= j and j <= Y):
            v = min(j - i, X - i + 1 + Y - j)
        elif (X <= i and i <= Y) and Y <= j:
            v = min(j - i, i - X + 1 + j - Y)
        elif (X <= i and i <= Y) and (X <= j and j <= Y):
            v = min(j - i, i - X + 1 + Y - j)
        else:
            v = j - i

        dic[v] += 1


for i in range(1, N):
    print(dic[i])


### FIXED CODE ###

N, X, Y = map(int, input().split())


dic = {}

X = X - 1
Y = Y - 1

for i in range(N):
    for j in range(i + 1, N):
        if i <= X and Y <= j:
            v = X - i + 1 + j - Y
        elif (i <= X) and (X <= j and j <= Y):
            v = min(j - i, X - i + 1 + Y - j)
        elif (X <= i and i <= Y) and Y <= j:
            v = min(j - i, i - X + 1 + j - Y)
        elif (X <= i and i <= Y) and (X <= j and j <= Y):
            v = min(j - i, i - X + 1 + Y - j)
        else:
            v = j - i

        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1


for i in range(1, N):
    if i in dic:
        print(dic[i])
    else:
        print(0)
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7




pair_flg=1
n=I()
A=LI()
t_set=set()
D=defaultdict(set)
ret=A[0]

for j in range(n):
    a=A[j]
    ret = gcd(ret,a)
    prime_set = D[A[j]]
    flg=0
    if not prime_set:
        for i in range(2, int(a ** 0.5) + 1):
            while a % i == 0:
                a //= i
                prime_set.add(i)
                if D[a]:
                    prime_set|=D[a]
                    flg=1
                    break
            if a == 1 or flg:
                break
        if a != 1:
            prime_set.add(a)
        D[A[j]]=prime_set
    if prime_set&t_set:
        pair_flg=0
    t_set|=prime_set


if pair_flg:
    print("pairwise coprime")
elif ret==1:
    print("setwise coprime")
else:
    print("not coprime")




### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()
A=LI()
l=A[0]
num=[0]*(10**6+1)
for i in range(1,n):
    num[A[i]]+=1
    l=gcd(l,A[i])



if l!=1:
    print("not coprime")
    exit()


for j in range(2,10**6):
    ret=0
    for k in range(j,10**6+1,j):
        ret+=num[k]
    if ret>1:
        print("setwise coprime")
        exit()

print("pairwise coprime")
### BUGGY CODE ###

try:
    K, S = map(int, input().split())
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            for z in range(K+1):
                if x+y+z==S:
                    cnt += 1
    print(cnt)
except EOFError:
    pass

### FIXED CODE ###

try:
    K, S = map(int, input().split())
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S-x-y
            if 0<=z<=K:
                cnt += 1
    print(cnt)
except EOFError:
    pass
### BUGGY CODE ###

data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
k = int(data[3])

count = 0
ans = 0

while count < k:
  if count < a:
    ans += 1
  elif count >= a + b and count < a + b + c:
    ans -= 1
  count += 1
print(ans)

### FIXED CODE ###

data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
k = int(data[3])
ans = 0

if k - a >0:
    ans += a
    k -= a
else:
    ans += k
    k = 0
if k - b >0:
    k -= b
else:
    k = 0
ans -= k
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = []
for i in range(M):
  A.append(int(input()))

dp = [0] * (N+1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1
div = 1000000007

for i in range(2,N+1):
  if (dp[i-1] == 0) & (dp[i-2]==0):
    print(0)
    exit()
  elif i in A:
    continue
  else:
    dp[i] = dp[i-1]+dp[i-2]

print(dp[N]%div)


### FIXED CODE ###

N, M = map(int, input().split())
A = []
for i in range(M):
  A.append(int(input()))

A = set(A)
dp = [0] * (N+1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1
mod = 1000000007

for i in range(2,N+1):
  if (dp[i-1] == 0) & (dp[i-2]==0):
    print(0)
    exit()
  elif i in A:
    continue
  else:
    dp[i] = dp[i-1]+dp[i-2]

print(dp[N]%mod)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [[0 for j in range(2)] for i in range(L)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        x[j][int(s)] += 1
b = 1
for i, (x0, x1) in enumerate(x):
    ans += x0 * x1 * b % MOD
    ans %= MOD
    b *= 2
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [0 for i in range(L)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        if s == '1':
            x[j] += 1
b = 1
for i, xi in enumerate(x):
    ans += xi * (n - xi) * b % MOD
    ans %= MOD
    b *= 2
    b %= MOD
print(ans)
### BUGGY CODE ###

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

mb=format(max(a),'b')
arr=[0]*len(mb)

for i in range(n):
    b=format(a[i],'b')
    for j in range(len(b)):
        if b[-j-1]=='1':
            arr[j]+=1

ans=0

for i in range(len(mb)):
    ans+=arr[i]*(n-arr[i])*(2**i)
print(ans%mod)

### FIXED CODE ###

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

mb=format(max(a),'b')
arr=[0]*len(mb)

for i in range(n):
    b=format(a[i],'b')
    for j in range(len(b)):
        if b[-j-1]=='1':
            arr[j]+=1

ans=0

for i in range(len(mb)):
    ans+=arr[i]*(n-arr[i])*(2**i)
print(ans%mod)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
D - Practical Skill Test
https://beta.atcoder.jp/contests/abc089/tasks/abc089_d

"""
import sys
from sys import stdin
from functools import lru_cache
input = stdin.readline


@lru_cache(maxsize=None)
def sub_solve(l, r, D):
    ans = 0
    while True:
        if l == r:
            break
        sx, sy = numbers[l]
        gx, gy = numbers[l+D]
        ans += abs(sx - gx) + abs(sy - gy)
        l += D
    return ans


def solve(numbers, queries, D):
    for l, r in queries:
        ans = sub_solve(l, r, D)
        print(ans)

numbers = dict()
def main(args):
    global numbers
    H, W, D = map(int, input().split())
    board = []
    for _ in range(H):
        board.append([int(x) for x in input().split()])
    Q = int(input())
    queries = []
    for _ in range(Q):
        queries.append([int(x) for x in input().split()])

    for y, row in enumerate(board, start=1):
        for x, i in enumerate(row, start=1):
            numbers[i] = [x, y]

    solve(numbers, queries, D)


if __name__ == '__main__':
    main(sys.argv[1:])
    


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
D - Practical Skill Test
https://beta.atcoder.jp/contests/abc089/tasks/abc089_d

"""
import sys
from sys import stdin
input = stdin.readline


def sub_solve(l, r):
    sx, sy = numbers[l]
    gx, gy = numbers[r]
    return abs(sx - gx) + abs(sy - gy)


def solve(queries, H, W, D):
    dp = [0] * (H*W+1)
    for i in range(D+1, H*W+1):
        dp[i] = dp[i-D] + sub_solve(i-D, i)

    for l, r in queries:
        ans = dp[r] - dp[l]
        print(ans)


numbers = dict()
def main(args):
    global numbers
    H, W, D = map(int, input().split())

    for y in range(1, H+1):
        tmp = [int(x) for x in input().split()]
        for x, i in enumerate(tmp, start=1):
            numbers[i] = (x, y)

    Q = int(input())
    queries = []
    for _ in range(Q):
        queries.append([int(x) for x in input().split()])

    solve(queries, H, W, D)


if __name__ == '__main__':
    main(sys.argv[1:])
### BUGGY CODE ###

n = int(input())
arr = [i for i in range(1, n)]
print(int(sum(arr)))

### FIXED CODE ###

n = int(input())

res = n * ((n - 1) // 2)
if (n - 1) % 2 == 1:
    res += ((n - 1) // 2) + 1

print(int(res))
### BUGGY CODE ###

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n= ii()
a= li()

ans=1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        ans = -1
print(ans)

### FIXED CODE ###

from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n= ii()
a= li()

ans=1
a.sort()
a.reverse()

if a[-1] == 0:
    print(0)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
    elif a[i] == 0:
        print(0)
        exit()
print(ans)
### BUGGY CODE ###

def gcd(a, b):
    for i in range(100):
      a, b = b, a%b
      if b == 0:
        return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)
### BUGGY CODE ###

from collections import Counter
from math import factorial
N=int(input())
A=list(map(int,input().split(" ")))
count=Counter(A)
com={}
def combo(n):
    if n>=2:
        return factorial(n)//(factorial(n-2)*2)
    else:
        return 0

for k,v in count.items():
    com[k]=combo(v)
s=sum(com.values())
for i in range(N):
    su=s-combo(count[A[i]])+combo(count[A[i]]-1)
    print(su)

### FIXED CODE ###

from collections import Counter
from operator import mul
from functools import reduce

def combo(n):
    if n<1:
        return 0
    r = min(n-2,2)
    if r == 0: return 1
    over = reduce(mul, range(n, n - 2, -1))
    under = reduce(mul, range(1,2 + 1))
    return over // under

N=int(input())
A=list(map(int,input().split(" ")))
count=Counter(A)
com={}

for k,v in count.items():
    com[k]=combo(v)
s=sum(com.values())
for i in range(N):
    su=s-combo(count[A[i]])+combo(count[A[i]]-1)
    print(su)
### BUGGY CODE ###

from collections import Counter
import sys
input = sys.stdin.readline


def main():
    mod = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        a_sub = a[i+1:]
        a_sub_dict = dict(Counter(a_sub))
        for j in a_sub_dict:
            ans += a_sub_dict[j] * (a[i] ^ j)
    print(ans % mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

n = int(input())
a = map(int, input().split())
mod = 10**9 + 7
p=[0] * 60
for a_ in a:
  for i in range(60):
    p[i] += (a_ >> i) & 1
ans = 0
for i in range(60):
  sn = (n - p[i]) * p[i]
  ans = (ans + (sn << i)) % mod
print(ans)
### BUGGY CODE ###

from copy import deepcopy
from array import array

while True:
    m = int(raw_input())
    n = int(raw_input())

    if m == 0 and n == 0:
        break

    begin = [array('b', [False] * m) for y in xrange(n)]

    for y in xrange(n):
        line = map(int, raw_input().split(' '))
        for x in xrange(m):
            if line[x] == 1:
                begin[y][x] = True

    # (stage, current position(x, y), current point)
    que = []
    for x in xrange(m):
        for y in xrange(n):
            if begin[y][x]:
                stage = deepcopy(begin)
                stage[y][x] = False
                que.append((stage, (x, y), 1))


    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    ans = 0

    while que:
        stage = que.pop()
        for i in xrange(4):
            nx = dx[i] + stage[1][0]
            ny = dy[i] + stage[1][1]
            if 0 <= nx < m and 0 <= ny < n and stage[0][ny][nx]:
                field = deepcopy(stage[0])
                field[ny][nx] = False
                ans = max(ans, stage[2] + 1)
                que.append((field, (nx, ny), stage[2] + 1))

    print ans

### FIXED CODE ###

from copy import deepcopy

while True:

    m = int(raw_input())
    n = int(raw_input())

    if m == 0 and n == 0:
        break

    field = [[False] * m for y in xrange(n)]

    for y in xrange(n):
        line = map(int, raw_input().split(' '))
        for x in xrange(m):
            if line[x] == 1:
                field[y][x] = True

    ans = 0

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    def search(x, y, d):
        global ans

        if d > ans:
            ans = d

        for i in xrange(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < m and 0 <= ny < n and field[ny][nx]:
                field[ny][nx] = False
                search(nx, ny, d + 1)
                field[ny][nx] = True

    for x in xrange(m):
        for y in xrange(n):
            if field[y][x]:
                field[y][x] = False
                search(x, y, 1)
                field[y][x] = True

    print ans
### BUGGY CODE ###

import math
n=int(input())

a=int(math.sqrt(n))

if n%2 != a%2: a+=1
while n%a != 0:a+=2

b=int(n/a)

a_dig = len(str(a))
b_dig = len(str(b))

ans=max(a_dig,b_dig)

print(ans)


### FIXED CODE ###

import math
n = int(input())
nn = int(math.sqrt(n))
while n%nn != 0: nn-=1
ans = len(str(n//nn))
print(ans)