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

S = list(input())
S = [int(i) for i in S]
c = 0
#print(S)
while True:
    OK = 0
    flag = 0
    break_flag = 0
    for i in range(len(S)-1):
        if S[i] != S[i+1] and S[i] != 9 and S[i+1] != 9:
            S[i] = 9
            S[i+1] = 9
            OK = 1
            break
        else:
            flag += 1
    #print(S)
    if flag == len(S)-1:
        break_flag = 1
    if OK == 1:
        for i in range(2):
            S.remove(9)
            c += 1
    #print(S)
    #print(flag)
    if break_flag == 1 or len(S) <= 1:
        break
print(c)

### FIXED CODE ###

S = list(input())
S = [int(i) for i in S]
one = 0
zero = 0
for i in range(len(S)):
    if S[i] == 1:
      one += 1
    elif S[i] == 0:
      zero += 1
print(len(S)-abs(one-zero))
### BUGGY CODE ###


def main():
    n, m = [int(i) for i in input().split()]

    def flip(v):
        return '.' if v == '#' else '#'

    a = [['#' for _ in range(n)] for _ in range(m)]
    for i in range(n):
        for j in range(m):
            a[j  ][i  ] = flip(a[j  ][i  ])
            if j-1 >= 0:
                a[j-1][i  ] = flip(a[j-1][i  ])
            if i-1 >= 0:
                a[j  ][i-1] = flip(a[j  ][i-1])
            if j+1 < m:
                a[j+1][i  ] = flip(a[j+1][i  ])
            if i+1 < n:
                a[j  ][i+1] = flip(a[j  ][i+1])
            if j+1 < m and i+1 < n:
                a[j+1][i+1] = flip(a[j+1][i+1])
            if j-1 >= 0 and i-1 >= 0:
                a[j-1][i-1] = flip(a[j-1][i-1])
            if j+1 < m and i-1 >= 0:
                a[j+1][i-1] = flip(a[j+1][i-1])
            if j-1 >= 0 and i+1 < n:
                a[j-1][i+1] = flip(a[j-1][i+1])

    c = 0
    for i in range(n):
        for j in range(m):
            if a[j][i] == '.':
                c += 1

    print(c)

if __name__ == '__main__':
    main()


### FIXED CODE ###


def main():
    nm = [int(i) for i in input().split()]

    nm.sort()
    # 自身と周辺のカードの枚数を数えて、偶数なら表、奇数なら裏
    if nm[0] == 1 and nm[1] == 1:
        # 1枚の時
        print(1)
    elif nm[0] == 1 and nm[1] == 2:
        # 2枚の時
        print(2)
    elif nm[0] == 1 and nm[1] > 2:
        # 1列の時、両端は自身と隣接2枚、途中は3枚なので、途中が裏
        print(nm[1] - 2)
    elif nm[0] == 2:
        # 2列の時、4隅が自身と隣接4枚、他は6枚
        print(0)
    elif nm[0] > 2 and nm[1] > 2:
        # 3行3列以上の時、4隅が4枚、端は6枚、真ん中は9枚
        print((nm[0]-2) * (nm[1]-2))
    else:
        raise ValueError


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

n = int(input())
a = list(map(int, input().split()))
b = max(a)
che,re = [1 for i in range(b)],[]
for i in a:
    if i in re:
        che[i-1] = 0
    else:
        re.append(i)
        c = b // i
        for j in range(2,c+1):
            che[i*j-1] = 0
ans = 0
for i in re:
    if che[i-1] == 1:
        ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = max(a)
che = [1 for i in range(b)]
for i in a:
    if che[i-1] == 1:
        c = b // i
        for j in range(2,c+1):
            che[i*j-1] = 0
        che[i-1] = 2
    elif che[i-1] == 2:
        che[i-1] = 0
ans = 0
for i in a:
    if che[i-1] == 2:
        ans += 1
print(ans)
### BUGGY CODE ###

import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]
S=input().strip()
Z=[len(x) for x in re.split(r'1+',S)]
O=[len(x) for x in re.split(r'0+',S)]

m=0
i=0
if S[0]=='1':
    Z.pop(0)
l1=len(O)
l0=len(Z)
while True:
    c=sum(O[i:i+K+1])+sum(Z[i:i+K])
    if c > m:
        m = c
    i+=1
    if i+K>l1 or i+K>l0:
        break

print(m)

### FIXED CODE ###

import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]

f=1
cnt=0
S=[]
r=0
for s in input().strip():
    s=int(s)
    if s==f:
        cnt+=1
    else:
        r+=cnt
        S.append(r)
        cnt=1
        f=1-f
else:
    r+=cnt
    S.append(r)
if len(S)%2==0:
    S.append(r)

Max=0
i=0
if len(S)==1:
    Max=S[0]
else:
    while True:
        if i >=len(S):
            break
        r=i+2*K
        cnt=S[min(r,len(S)-1)]-S[max(i-1,0)]
        if cnt > Max:
            Max = cnt
        i+=2

print(Max)
### BUGGY CODE ###

l,r=map(int,input().split())
ans=2020
for i in range(l,r):
  for j in range(i+1,r+1):
    ans=min(ans,(i*j)%2019)
    if ans==0:
      break
print(ans)



### FIXED CODE ###

l,r=map(int,input().split())
ans=2020
for i in range(l,r):
  for j in range(i+1,r+1):
    ans=min(ans,(i*j)%2019)
    if ans==0:
      print(ans)
      exit()
print(ans)
### BUGGY CODE ###

h,n = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
inf = 10000000000
dp = [inf for _ in range(h+1)]
dp[0] = 0
for i in range(1,h+1):
    m = inf
    for a,b in ab:
        if i <= a:
            m = min(m,b)
        else:
            m = min(m,dp[i-a]+b)
    dp[i] = m
print(dp[-1])

### FIXED CODE ###

h,n = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
inf = 10000000000
dp = [inf for _ in range(h+1)]
dp[0] = 0
for i in range(1,h+1):
    m = inf
    for a,b in ab:
        if i <= a:
            m = min(m,b)
        else:
            m = min(m,dp[i-a]+b)
    dp[i] = m
print(dp[-1])
### BUGGY CODE ###

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

A.sort()
F.sort(reverse=True)

sumA = sum(A)
if  K >= sumA:
    print(0)
    exit()

def isok(x):
    k = 0
    for a, f in zip(A, F):
        if a > x//f:
            k += a - (x//f)
            if k > K:
                return False
    return True

ng = -1
ok = 10**12+1

while ok - ng > 1:
    mid = (ok - ng)//2
    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok)

### FIXED CODE ###

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

A.sort()
F.sort(reverse=True)

sumA = sum(A)
if  K >= sumA:
    print(0)
    exit()

def isok(x):
    k = 0
    for a, f in zip(A, F):
        if a > x//f:
            k += a - (x//f)
            if k > K:
                return False
    return True

ng = -1
ok = 10**12+1

while ok - ng > 1:
    mid = (ok + ng)//2
    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
l = [list(map(int, input().split())) for _ in range(Q)]

#print(N,Q)
#print(S)
#print(l)

ans = []
for i in range(Q):
    #print(l[i][1])
    #print(S[l[i][0] - 1], S[l[i][1] - 1])
    #print(S[l[i][0]-1 : l[i][1]])
    R = S[l[i][0]-1 : l[i][1]]
    #print(R)
    ans.append(R.count("AC"))
#print(ans)
for A in ans:
    print(A)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

t = [0] * (N + 1)

for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    # divisors.sort(reverse=True)
    return divisors

divs = []
for b in B:
    divs += make_divisors(b)

divs.sort(reverse=True)

ans = 1
for d in divs:
    count = 0
    for a in A:
        if a % d != 0:
            count += 1
            if count >= 2:
                break
    if count < 2:
        ans = d
        break

print(ans)

### FIXED CODE ###

# 解けなかった...orz

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

def gcd(i, j):
    if i <= 0:
        return j
    elif j <= 0:
        return i

    while i != j:
        if i < j:
            j %= i
            if j == 0: return i
        else:
            i %= j
            if i == 0: return j
    return i

# M = [0] * N
L = [0] * (N+1)
R = [0] * (N+1)
# L[0] = 0
# R[N] = 0

for i in range(N):
    L[i+1] = gcd(L[i], A[i])
    R[N-i-1] = gcd(R[N-i], A[N-i-1])

res = max(gcd(L[i], R[i+1]) for i in range(N))
print(res)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = list(map(int,input().split()))
count = Counter(S)
S = sorted(S)
T = sorted(list(set(S)))
M = len(T)
pre = {T[i]:T[i-1] if i > 0 else 0 for i in range(M)}

l = [S[-1]]
count[S[-1]] -= 1

while len(l) < 2**N:
    for n in l[:]:
        m = pre[n]
        if m == 0:
            print('No')
            exit()
        while count[m] == 0:
            pre[n] = pre[m]
            m = pre[n]
            if m == 0:
                print('No')
                exit()
        l.append(m)
        count[m] -= 1

print('Yes')



### FIXED CODE ###

from collections import Counter
N = int(input())
S = list(map(int,input().split()))
#N = 18
#S = list(range(1,2**N+1))

def solve():
    global S
    S += [0]
    count = Counter(S)
    S = sorted(S)
    T = sorted(list(set(S)))
    M = len(T)
    pre = {T[i]:T[i-1] if i > 0 else 0 for i in range(M)}

    l = [S[-1]]
    count[S[-1]] -= 1

    while len(l) < 2**N:
        for n in l[:]:
            m = pre[n]
            pl = []
            while count[m] == 0:
                pl.append(m)
                m = pre[m]
            if pl:
                pre[n] = m
                for p in pl:
                    pre[p] = m
            if m == 0:
                print('No')
                exit()
            l.append(m)
            count[m] -= 1

    print('Yes')
    #print(count)

solve()
### BUGGY CODE ###

#abc094c
from statistics import median

n=int(input())
x=list(map(int,input().split()))
res=[]
for i in range(n):
 y=x.copy()
 y.pop(i)
 res.append(median(y))
for i in range(n):
 print(res[i])


### FIXED CODE ###

#abc094c

n=int(raw_input())
x=map(int,raw_input().split())
y=sorted(x)
l=y[n/2]
r=y[n/2-1]
for i in x:
 print l if i<l else r
### BUGGY CODE ###

import math
n, a, b = map(int,input().split())
score = 1
total = 0
for i in range(1,n+1):
  score = score * (n-i+1) // i
  if i != a and i != b:
    total += score
print(total % (10**9 + 7))

### FIXED CODE ###

N, a, b = map(int,input().split())
p = pow(10,9) + 7
def comb(n,r):
  bunshi = 1
  for i in range(n-r+1, n+1):
    bunshi =bunshi * i % p
  bunbo = 1
  for i in range(1, r+1):
    bunbo = bunbo * i % p
  return bunshi * pow(bunbo, p-2, p)
print((pow(2,N, p) - 1 - comb(N,a) - comb(N,b)) % p)
### BUGGY CODE ###

N, M = map(int, input().split())
a = [0 for i in range(M)]
sosu = 10 ** 9 + 7
for i in range(M):
    a[i] = int(input())
dp = [0 for i in range(N+1)]
dp[0] = 1
for i in range(1, N+1):
    if i in a:
        pass
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % sosu
print(dp[N])

### FIXED CODE ###

N, M = map(int, input().split())
a = [0 for i in range(M)]
sosu = 10 ** 9 + 7
for i in range(M):
    a[i] = int(input())
seta = list(set(a))
seta.sort()
dp = [0 for i in range(N+1)]
dp[0] = 1
now = 0
for i in range(1, N+1):
    if now <= M-1 and i == seta[now]:
        now += 1
    elif i >= 2:
        dp[i] = (dp[i-2] + dp[i-1]) % sosu
    elif i == 1:
        dp[i] = dp[i-1]
#print(seta)
print(dp[N])
### BUGGY CODE ###

N = int(input())
#S = [input() for _ in range(N)]
S = []
for i in range(N):
    s = input()
    dup = False
    if s not in S:
        S.append(s)
print(len(S))


### FIXED CODE ###

N = int(input())
rewards = set()
for _ in range(N):
    rewards.add(input())
print(len(rewards))
### BUGGY CODE ###

n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if L[j] - L[i] < L[k] < L[i] + L[j]:
                ans += 1
            elif L[k] >= L[i] + L[j]:
                break

print(ans)


### FIXED CODE ###

import bisect

n = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

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

H, W = [int(_) for _ in input().split()]
C = [int(_) - 1 for _ in input().split()]
D = [int(_) - 1 for _ in input().split()]

S = [input() for _ in range(H)]
V = [[-1 for w in range(W)] for h in range(H)]


V[C[0]][C[1]] = 0
pool = [tuple(C)]

while(pool):
    y, x = pool.pop()
    for dx, dy in [(-1,0),(1,0),(0,-1),(0,1)]:
        if not y + dy in range(H):
            continue
        if not x + dx in range(W):
            continue
        if S[y+dy][x+dx] == "#":
            continue
        if V[y+dy][x+dx] == -1 or V[y+dy][x+dx] > V[y][x]:
            V[y+dy][x+dx] = V[y][x]
            pool.append((y+dy, x+dx))
    for dx in [-2,-1,0,1,2]:
        for dy in [-2,-1,0,1,2]:
            if not y + dy in range(H):
                continue
            if not x + dx in range(W):
                continue
            if S[y+dy][x+dx] == "#":
                continue
            if V[y+dy][x+dx] == -1 or V[y+dy][x+dx] > V[y][x]:
                V[y+dy][x+dx] = V[y][x] + 1
                pool.append((y+dy, x+dx))

print(V[D[0]][D[1]])


### FIXED CODE ###

from collections import deque

H, W = [int(_) for _ in input().split()]
C = [int(_) - 1 for _ in input().split()]
D = [int(_) - 1 for _ in input().split()]

S = [input() for _ in range(H)]
V = [[-1 for w in range(W)] for h in range(H)]

V[C[0]][C[1]] = 0

pool = deque()
pool.append(tuple([0, C[0], C[1]]))
while(pool):
    c, y, x = pool.popleft()
    if c != V[y][x]:
        continue
    for dx in [-2, -1, 0, 1, 2]:
        for dy in [-2, -1, 0, 1, 2]:
            if y + dy < 0 or H <= y + dy:
                continue
            if x + dx < 0 or W <= x + dx:
                continue
            if S[y+dy][x+dx] == "#":
                continue
            if (dx, dy) in [(-1,0),(1,0),(0,-1),(0,1)]:
                if V[y+dy][x+dx] == -1 or V[y+dy][x+dx] > V[y][x]:
                    V[y+dy][x+dx] = V[y][x]
                    pool.appendleft((c, y+dy, x+dx))
            elif V[y+dy][x+dx] == -1 or V[y+dy][x+dx] > V[y][x] + 1:
                V[y+dy][x+dx] = V[y][x] + 1
                pool.append((c+1, y+dy, x+dx))
print(V[D[0]][D[1]])
### BUGGY CODE ###

import sys
a, b, n = map(int, input().split())

if n < b:
    ans = a * n // b  
    print(ans)
    sys.exit()  
elif n == b:
    ans = a * (b-1) // b
    print(ans)
    sys.exit()

# n == 1のときは0 問題なし
r = n // b
ans = 0
for i in range(1, r + 1):
    t = i * b - 1
    ans_t = a * t // b - (a * (i - 1))
    ans = max(ans, ans_t) 
    # print(i, t, ans)

t = r * b - 1
ans_t = a * t // b - (a * (r - 1))
ans = max(ans, ans_t) 

ans_t = a * n // b - (a * (n // b))
ans = max(ans, ans_t) 

print(ans)

### FIXED CODE ###

import sys
a, b, n = map(int, input().split())

if n < b:
    ans = a * n // b  
    print(ans)
    sys.exit()  
elif n == b:
    ans = a * (b-1) // b
    print(ans)
    sys.exit()

# n == 1のときは0 問題なし
r = n // b
ans = 0
# for i in range(1, r + 1):
#     t = i * b - 1
#     ans_t = a * t // b - (a * (i - 1))
#     ans = max(ans, ans_t) 
    # print(i, t, ans)

t = r * b - 1
ans_t = a * t // b - (a * (r - 1))
ans = max(ans, ans_t) 

ans_t = a * n // b - (a * (n // b))
ans = max(ans, ans_t) 

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

import copy

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
b = copy.deepcopy(a)

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

while white:
    white = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] == '.':
                white = 1
            if a[i][j] == '#':
                for k in range(4):
                    ny = i + dy[k]
                    nx = j + dx[k]
                    if 0 <= ny < h and 0 <= nx < w:
                        b[ny][nx] = '#'
    ans += 1
    a = copy.deepcopy(b)

print(ans-1)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

def bfs():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    que = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                que.append((i, j))
                a[i][j] = 0

    while que:
        p = que.popleft()
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]

            if 0 <= nx < w and 0 <= ny < h and a[ny][nx] == '.':
                que.append((ny,nx))
                a[ny][nx] = a[p[0]][p[1]] + 1
    ans = 0
    for i in range(h):
        ans = max(ans, *a[i])
    return ans

print(bfs())
### BUGGY CODE ###

class Deque:
    #??????????????????
    class Node:
        def __init__(self, x, y = None, z = None):
            self.key = x
            self.next = y
            self.prev = z
    def __init__(self):
        head = Deque.Node(None)
        head.next = head
        head.prev = head
        self.size = 0
        self.head = head

    #insert x:??£??????????????????????????????x?????????????´???????????¶????
    def insert(self,x):
        h = self.head
        q = h.next
        p = Deque.Node(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    #deleteFirst:??£????????????????????????????´???????????????????
    def deleteFirst(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.next
        p = q.next
        p.prev = h
        h.next = p
        self.size -= 1

    #deleteLast:??£???????????????????°????????´???????????????????
    def deleteLast(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.prev
        p = q.prev
        p.next = h
        h.prev = p
        self.size -= 1

    #???????????????????????¢?´¢
    def listSearch(self, x):
        h = self.head
        cur = h.next
        while cur != None and cur.key != x:
            cur = cur.next
        return cur

    #delete:x???????????????????´??????????????????°?????¢?´¢???????§?
    def delete(self, x):
        if self.size == 0: raise IndexError
        if x == None: return
        h = self.listSearch(x)
        q = h.next
        p = h.prev
        p.next = q
        q. prev = p
        self.size -=1

    #??????
    def printList(self):
        h = self.head
        cur = h.next
        isf = 0
        while 1:
            if cur == h: break
            if isf > 0: print(" ", end="")
            print(cur.key, end="")
            isf = 1
            cur = cur.next
        print("")

n = int(input())
d = Deque()
for i in range(n):
    i = input().split()
    if i[0] == "insert":
        x = i[1]
        d.insert(x)
    if i[0] == "delete":
        x = i[1]
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] =="deleteLast":
        d.deleteLast()
d.printList()

### FIXED CODE ###

from collections import deque
n = int(input())
L = deque()

for i in range(n):
    cmdline = input().split()

    if cmdline[0] == "insert":
        L.appendleft(cmdline[1])
    elif cmdline[0] == "delete":
        try:
            L.remove(cmdline[1])
        except ValueError: pass
    elif cmdline[0] == "deleteFirst":
        L.popleft()
    elif cmdline[0] == "deleteLast":
        L.pop()

print(" ".join(L))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    dp = [[None for j in range(N)] for i in range(N)]
    for i in range(0, N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            dp[i][i+1] = 1
        else:
            dp[i][i+1] = 0
    def count(li, ri):
        assert li >= 0 and ri >= 0, "li or ri < 0"
        if dp[li][ri] is not None:
            return dp[li][ri]
        else:
            c = count(li, ri-1) + count(ri-1, ri)
            dp[li][ri] = c
            return c
    for q in range(Q):
        print(count(l[q] - 1, r[q] - 1))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    c = [0 for i in range(N+1)]
    for i in range(N):
        c[i+1] = c[i] + (1 if S[i:i+2] == "AC" else 0)
    for q in range(Q):
        print(c[r[q]-1] - c[l[q] - 1])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

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

import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    ds = [nm // d + 1 for d in range(s, 0, -1)]
    ds = [sb] + ds + [n + 1]
    # print(m, nm, sb, s, ds)
    dd = np.diff(ds)
    pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # print(dd, pd, dd * pd, sum(dd * pd))
    ans += sum(dd * pd)
print(ans)


### FIXED CODE ###

import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    p = s + 1 if m else s
    ps = sb
    for d in range(s, 0, -1):
        ds = nm // d + 1
        co = ds - ps
        ans += co * p
        ps = ds
        p -= 1
    ans += n + 1 - ps

    # ds = [nm // d + 1 for d in range(s, 0, -1)]
    # ds = [sb] + ds + [n + 1]
    # # print(m, nm, sb, s, ds)
    # dd = np.diff(ds)
    # pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # # print(dd, pd, dd * pd, sum(dd * pd))
    # ans += sum(dd * pd)
print(ans)
### BUGGY CODE ###

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

XOR = A
for i in range(A+1, B+1):
    XOR ^= i

print(XOR)


### FIXED CODE ###


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

A -= 1

if (A+1) % 2 == 0:
    a = (A+1) // 2 % 2
else:
    a = (A // 2 % 2) ^ A

if (B+1) % 2 == 0:
    b = (B+1) // 2 % 2
else:
    b = (B // 2 % 2) ^ B
    
#print(a, b)
print(a ^ b)
### BUGGY CODE ###

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

    dp=[[0 for i in range(N+1)] for _ in range(N+1)]

    A_index=[i for i in range(N)]

    AA=zip(A,A_index)
    AA=sorted(AA,reverse=True)
    A,A_index=zip(*AA)

    for i in range(N):
        for j in range(N-i):
            score=dp[i][j]

            dp[i+1][j]=max(dp[i+1][j],score+A[i+j]*(A_index[i+j]-i))
            dp[i][j+1]=max(dp[i][j+1],score+A[i+j]*((N-1-j)-A_index[i+j]))

    res=0
    for i in range(N+1):
        res=max(res,dp[i][N-i])

    print(res)

if __name__=="__main__":
    main()


### FIXED CODE ###

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

    dp=[[0 for i in range(N+1)] for _ in range(N+1)]

    A_index=[i for i in range(N)]

    AA=zip(A,A_index)
    AA=sorted(AA,reverse=True)
    A,A_index=zip(*AA)

    for i in range(N):
        for j in range(N-i):
            score=dp[i][j]

            dp[i+1][j]=max(dp[i+1][j],score+A[i+j]*(A_index[i+j]-i))
            dp[i][j+1]=max(dp[i][j+1],score+A[i+j]*((N-1-j)-A_index[i+j]))

    res=0
    for i in range(N+1):
        res=max(res,dp[i][N-i])

    print(res)

if __name__=="__main__":
    main()