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

import sys
input = sys.stdin.buffer.readline

r, c, k = map(int, input().split())
v = [[0]*(c+1) for i in range(r+1)]
for i in range(k):
    cr, cc, cv = map(int, input().split())
    v[cr][cc] = cv

dp = [[[0]*4 for _ in range(c+1)] for i in range(r+1)]
for cr in range(1, r+1):
    for cc in range(1, c+1):
        upper = max(dp[cr-1][cc][0], dp[cr-1][cc][1], dp[cr-1][cc][2], dp[cr-1][cc][3])
        
        dp[cr][cc][0] = max(upper, dp[cr][cc-1][0], dp[cr][cc][0])
        dp[cr][cc][1] = max(dp[cr][cc-1][1], dp[cr][cc-1][0]+v[cr][cc], upper+v[cr][cc])
        dp[cr][cc][2] = max(dp[cr][cc-1][2], dp[cr][cc-1][1]+v[cr][cc])
        dp[cr][cc][3] = max(dp[cr][cc-1][3], dp[cr][cc-1][2]+v[cr][cc])
print(max(dp[r][c]))

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

r, c, k = map(int, input().split())
v = [[0]*(c+1) for i in range(r+1)]
for i in range(k):
    cr, cc, cv = map(int, input().split())
    v[cr][cc] = cv

dp = [[0]*4 for _ in range(c+1)]
last = [[0]*4 for _ in range(c+1)]
for cr in range(1, r+1):
    for cc in range(1, c+1):
        upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3])
        dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0])
        dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc])
        dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc])
        dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc])
        last = dp
print(max(dp[c]))
### BUGGY CODE ###

a,b,x = map(int, input().split())
cnt = 0
for i in range(a, b+1):
   if i%x ==0:
      cnt += 1
print(cnt)

### FIXED CODE ###

a,b,x = map(int, input().split())
ans = 0
if a == 0:
   n_a = 0
   ans += 1
else:
   n_a = (a-1)//x

n_b = b//x

ans += n_b-n_a
print(ans)
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
a = ['#' * (w+2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w+2)]
for i in range(h+2):
    a[i] = list(a[i])

d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
x = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            x.append((i, j))

ans = 0
while x:
    y = []
    for i, j in x:
        for di, dj in d:
            if a[i+di][j+dj] == '.':
                a[i+di][j+dj] = '#'
                y.append((i+di, j+dj))
    x = y.copy()
    ans += 1
    # for i in range(h+2):
    #     print("".join(a[i]))
    # print()

ans -= 1
print(ans)


### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
a = ['#' * (w+2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w+2)]
for i in range(h+2):
    a[i] = list(a[i])

d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
x = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            x.append((i, j))

ans = 0
while x:
    y = []
    for i, j in x:
        for di, dj in d:
            if a[i+di][j+dj] == '.':
                a[i+di][j+dj] = '#'
                y.append((i+di, j+dj))
    x = y
    ans += 1
    # for i in range(h+2):
    #     print("".join(a[i]))
    # print()

ans -= 1
print(ans)
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
import numpy as np
X0=np.zeros((a, b),int)
X1=np.zeros((a, b),int)
X2=np.zeros((a, b),int)
X0[a-1][b-1]=1
for j in range(b,d):
  if d>b:
    X0=np.hstack((X0,np.zeros((a,1),int)))
    X1=np.hstack((X1,np.zeros((a,1),int)))
    X2=np.hstack((X2,np.zeros((a,1),int)))
    X0[a-1][j]=(X0[a-1][j-1]*(a-1))% 998244353
    X1[a-1][j]=((X0[a-1][j-1]+X1[a-1][j-1]*(a-1)))% 998244353
    X2[a-1][j]=(X1[a-1][j-1]+(X2[a-1][j-1]*a))% 998244353
for i in range(a,c):
  if c>a:
    X1=np.vstack((X1,np.zeros((1,X1.shape[1]),int)))
    X2=np.vstack((X2,np.zeros((1,X2.shape[1]),int)))
    for j in range(b,d+1):
      if i>a:
        X1[i][j-1]=((X1[i-1][j-1]+X2[i-1][j-1])*j) % 998244353
      else:
        X1[i][j-1]=((X0[i-1][j-1]+X1[i-1][j-1]+X2[i-1][j-1])*j) % 998244353
      if j>=2:
        X2[i][j-1]=(X1[i][j-2]+X2[i][j-2] *(i+1)) % 998244353
if a==c:
  print((X0[c-1][d-1]+X1[c-1][d-1]+X2[c-1][d-1])%998244353)
else:
  print((X1[c-1][d-1]+X2[c-1][d-1])%998244353)

### FIXED CODE ###

a,b,c,d=map(int,input().split())
def amari(a):
  return a % 998244353
X0=[[0]*d for i in range(c)]
X1=[[0]*d for i in range(c)]
X2=[[0]*d for i in range(c)]
X0[a-1][b-1]=1
for j in range(b,d):
 X0[a-1][j]=amari(X0[a-1][j-1]*(a-1))
 X1[a-1][j]=amari(X0[a-1][j-1]+X1[a-1][j-1]*(a-1))
 X2[a-1][j]=amari(X1[a-1][j-1]+X2[a-1][j-1]*a)
for i in range(a,c):
 for j in range(b,d+1):
  X1[i][j-1]=amari((X0[i-1][j-1]+X1[i-1][j-1]+X2[i-1][j-1])*j)
  if j>=2:
   X2[i][j-1]=amari(X1[i][j-2]+X2[i][j-2] *(i+1))
print(amari(X0[c-1][d-1]+X1[c-1][d-1]+X2[c-1][d-1]))
### BUGGY CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

def combination(n,r):
    return factorial(n) // (factorial(n-r) * factorial(r))

MOD = 10**9 + 7

n, a, b = LI()

total = pow(2, n) - 1

ans = total - (combination(n, a) + combination(n,b))

print(ans % MOD)

### FIXED CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

MOD = 10**9 + 7

n, a, b = LI()

def combination(r):
    numerator = reduce(lambda x, y: x * y % MOD, [n - r + i + 1 for i in range(r)])
    denominator = reduce(lambda x, y: x * y % MOD, [i + 1 for i in range(r)])

    return numerator * pow(denominator, MOD-2, MOD) % MOD

ans = pow(2, n, MOD) - 1 - combination(a) - combination(b)

print(ans % MOD)
### BUGGY CODE ###

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

n = input()
class DoubleLinkedList(object):
    def __init__(self):
        pass
        
    def insert(self, value):
        new = DoubleLinkedList()
        new.next = self.next
        new.prev = self
        self.next.prev = new
        self.next = new
        new.value = value
        
    def delete(self):
        next = self.next
        prev = self.prev
        self.next.prev = prev
        self.prev.next = next
        self = None

head = DoubleLinkedList()
tail = DoubleLinkedList()
head.next = tail
tail.prev = head

for i in xrange(n):
    command = raw_input().split()
    if command[0] == "insert":
        head.insert(int(command[1]))
    elif command[0] == "delete":
        key = int(command[1])
        e = head.next
        while True:
            if e is tail:
                break
            if e.value == key:
                e.delete()
                break
            e = e.next
    elif command[0] == "deleteFirst":
        if not head.next is tail:
            head.next.delete()
    elif command[0] == "deleteLast":  
        if not tail.prev is head:
            tail.prev.delete()
    
e = head.next
while True:
    if e is tail:
        break
    print e.value,
    e = e.next

### FIXED CODE ###

# -*- coding: utf-8 -*-
n = input()
l = []
tail = 0
for i in xrange(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        l.append(cmd[1])
    elif cmd[0] == "delete":
        try:
            l.pop(len(l) - l[::-1].index(cmd[1]) -1)
        except ValueError:
            pass
    elif cmd[0] == "deleteFirst":
        l.pop()
    elif cmd[0] == "deleteLast":
        tail += 1

print " ".join(l[tail:][::-1])
### BUGGY CODE ###

H, W = map(int, input().split())

List = list(range(H) for i in range(W))
count = 0

for i in range(W):
  for j in range(H):
    if List[i][j]%2 == 0 and i%2 ==0:
      count +=1
    elif List[i][j]%2 == 1 and i%2 ==1:
      count +=1
      
print(count)


### FIXED CODE ###

H, W = map(int, input().split())

if H==1 or W==1:
  Answer =1

elif W%2 ==0:
  Answer = W/2*H
  
else:
  count = (W-1)/2 +1
  if H%2 ==0:
    Answer = count*H - H/2
  else:
    Answer = count*H - (H-1)/2

print(int(Answer))
### BUGGY CODE ###

import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    for _ in range(k):
        imos = [0 for _ in range(n)]

        for i, ai in enumerate(a):
            imos[max(0, i - ai)] += 1
            if i + ai + 1 < n:
                imos[i + ai + 1] -= 1

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        if min(a) == n:
            break

    print(*a, sep=" ")


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    for _ in range(min(k,42)):
        imos = [0 for _ in range(n)]

        for i, ai in enumerate(a):
            imos[max(0, i - ai)] += 1
            if i + ai + 1 < n:
                imos[i + ai + 1] -= 1

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        # if min(a) == n:
        #     break

    print(*a, sep=" ")


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

n,q = map(int, input().split())
s = list(input())
lr_list = [list(map(int,input().split())) for _ in range(q)]

for l,r in lr_list:
    count = 0
    tmp_str = ''.join(s[l-1:r])
    v = [0 for i in range(0, len(tmp_str)) if tmp_str[i: i+2]=='AC']
    print(len(v))

### FIXED CODE ###

n,q = map(int, input().split())
s = list(input())
lr_list = [list(map(int,input().split())) for _ in range(q)]
tmp_list = [0]*(n+1)

for i in range(1,n):
    if s[i-1]=='A' and s[i]=='C':
        tmp_list[i] = tmp_list[i-1]+1
    else:
        tmp_list[i] = tmp_list[i-1]

for l,r in lr_list:
    print(tmp_list[r-1]-tmp_list[l-1])
### BUGGY CODE ###

#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7


def main():
    N = II()
    targets = LI()

    ttl_bins = [[0]*60 for i in range(N)]
    for i in range(1, N):
        target = targets[N-i]
        target_str = format(target, f"0{60}b")
        for keta in range(60):
            ttl_bins[N-i-1][keta] = ttl_bins[N -
                                             i][keta] + int(target_str[keta])

    ttl_final = [0]*60
    for i in range(N-1):
        target = targets[i]
        target_str = format(target, f"0{60}b")
        for keta in range(60):
            keta_int = int(target_str[keta])
            if keta_int == 0:
                ttl_others_1 = ttl_bins[i][keta]
                ttl_final[59 - keta] += ttl_others_1
            if keta_int == 1:
                ttl_others_0 = (N - i - 1) - ttl_bins[i][keta]
                ttl_final[59 - keta] += ttl_others_0

    ans = 0
    for i in range(60):
        ans += (ttl_final[i] * pow(2, i, MOD)) % MOD
        ans %= MOD

    print(ans)


main()


### FIXED CODE ###

#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7


def main():
    N = II()
    targets = LI()

    ttl_bins = [0]*60
    for i in range(N):
        target = targets[i]
        target_str = format(target, f"0{60}b")
        for keta in range(60):
            ttl_bins[keta] += int(target_str[keta])

    ans = 0
    for i in range(60):
        ttl = ttl_bins[i] * (N - ttl_bins[i])
        ans += pow(2, 59-i, MOD) * ttl
        ans %= MOD

    print(ans)


main()
### BUGGY CODE ###

A, B, C, D = list(map(int, input().split()))
while A and C:
    A -= D
    C -= B
    if C <= 0:
        print("Yes")
    elif A <= 0:
        print("No")


### FIXED CODE ###

A, B, C, D = list(map(int, input().split()))
t1 = (A + D - 1) // D
t2 = (C + B - 1) // B
print("Yes" if t2 <= t1 else "No")
### BUGGY CODE ###

a, b, c = map(int, input().split())
n=0
while True:
    if c%a == 0:
        n += 1
    a += 1
    if a == b:
        break
print(n)



### FIXED CODE ###

a, b, c = map(int, input().split())
n=0
while True:
    if c%a == 0:
        n += 1
    a += 1
    if a > b:
        break
print(n)
### BUGGY CODE ###

#17:11
n,m = map(int,input().split())
pre = [-1 for i in range(n)]
for _ in range(m):
  x,y,z = map(int,input().split())
  x -= 1
  y -= 1
  X = 0
  while pre[x] != -1:
    X += 1
    x = pre[x]
  Y = 0
  while pre[y] != -1:
    Y += 1
    y = pre[y]
  if x != y:
    if X > Y:
      pre[x] = y
    else:
      pre[y] = x
father = set()
ans = 0
for i in range(n):
  if pre[i] == -1:
    ans += 1
#print(pre)
print(ans)

### FIXED CODE ###

#解説チラ見
n,m = map(int,input().split())
ans = n
pre = [i for i in range(n)]
for _ in range(m):
  x,y,z = map(lambda x: int(x)-1, input().split())
  X = [x]
  while pre[x] != x:
    x = pre[x]
    X.append(x)
  Y = [y]
  while pre[y] != y:
    y = pre[y]
    Y.append(y)
  if x != y:
    ans -= 1
    for xx in X:
      pre[xx] = y
    for yy in Y:
      pre[yy] = y
    pre[x] = y
print(ans)
### BUGGY CODE ###

from numba import jit
import numpy as np

@jit
def solve():
    
    s = np.array(list(input())[::-1])
    num = len(s)
    #print(s, num)
    
    l = []
    for i in range(1,num+1):
        l.append(int(''.join(s[:i][::-1])))
    #print(l)
    l = np.array(l)
    mod = []
    for j in range(num):
        mod.append(l[j] % 2019)
    mod = np.array(mod)
    
    ans = 0
    for p in range(num):
        if mod[p] == 0:
            ans += 1
        tmp = 1
        for q in range(p+1,num):
            if mod[p] == mod[q]:
                tmp += 1
        ans += (tmp-1)*tmp//2
    
    print(ans)

solve()

### FIXED CODE ###

s = input()[::-1]

cnts = [1] + [0] * (2019 - 1)
tmp = 0
d = 1

for i in s:
    tmp += int(i) * d
    cnts[tmp % 2019] += 1
    d = d * 10 % 2019 # 桁数が大きくなりすぎる → 10と2019が素だから可能

ans = 0
for cnt in cnts:
    ans += (cnt - 1) * cnt // 2

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

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

from heapq import heappop, heappush

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

q = []
push = lambda x,i: heappush(q, (-x,i))
def pop():
    x,i = heappop(q)
    return -x,i

for i,x in enumerate(B):
    push(x,i)

answer = 0
while q:
    x,i = pop()
    if x < A[i]:
        answer = -1
        break
    dx = x-A[i]
    nbd = B[(i-1)%N] + B[(i+1)%N]
    t = dx // nbd
    if t == 0:
        if x == A[i]:
            continue
        answer = -1
        break
    B[i] -= nbd * t
    answer += t
    push(B[i],i)

print(answer)



### FIXED CODE ###

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

from heapq import heappop, heappush

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

q = []
push = lambda x,i: heappush(q, (-x,i))
for i,x in enumerate(B):
    push(x,i)

answer = 0
while q:
    x,i = heappop(q)
    x = -x
    if x < A[i]:
        answer = -1
        break
    dx = x-A[i]
    nbd = B[(i-1)%N] + B[(i+1)%N]
    t = dx // nbd
    if t == 0:
        if x == A[i]:
            continue
        answer = -1
        break
    B[i] -= nbd * t
    answer += t
    push(B[i],i)

print(answer)
### BUGGY CODE ###

import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = list(zip(A, B))
    bigger_diff = list(map(lambda ab: max(ab[0] - ab[1], 0), AB))
    lesser_diff = list(map(lambda ab: min(ab[0] - ab[1], 0), AB))
    exceeded = sum(bigger_diff)
    shortage = sum(lesser_diff)

    if exceeded < abs(shortage):
        print(-1)
        sys.exit()

    if all(map(lambda ab: ab[0] > ab[1], AB)):
        print(0)
        sys.exit()



    ans = len(list(filter(lambda d: d<0, lesser_diff)))

    bigger_diff = sorted(bigger_diff, reverse=True)

    for i in range(len(bigger_diff)):
        if sum(bigger_diff[:i]) >= abs(shortage):
            ans += i
            break
    print(ans)



if __name__=='__main__':
    main()


### FIXED CODE ###

import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = list(zip(A, B))
    bigger_diff = list(map(lambda ab: max(ab[0] - ab[1], 0), AB))
    lesser_diff = list(map(lambda ab: min(ab[0] - ab[1], 0), AB))
    exceeded = sum(bigger_diff)
    shortage = sum(lesser_diff)

    if exceeded < abs(shortage):
        print(-1)
        sys.exit()

    if all(map(lambda ab: ab[0] >= ab[1], AB)):
        print(0)
        sys.exit()



    ans = len(list(filter(lambda d: d<0, lesser_diff)))

    bigger_diff = sorted(bigger_diff, reverse=True)

    ss = 0
    for i in range(len(bigger_diff)):
        ss += bigger_diff[i]
        if ss >= abs(shortage):
            ans += i + 1
            break
    print(ans)



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


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

    # 移動直前の偏りをkとし、移動先のマス(i, j)
    # についてd = abs(A[i][j] - B[i][j])
    # とした際に、移動後の偏りをabs(k - d)
    # とするかabs(k + d)とするか」を考えることと同値である。
    # dp[i][j][k] : マス (i, j) までの経路の偏りが k になることがあるか？
    max_k = 160 * 80
    dp = [[[False] * (max_k + 1) for _ in range(W + 1)] for _ in range(H + 1)]

    dp[0][1][0] = True
    dp[1][0][0] = True

    for i in range(H):
        for j in range(W):
            for k in range(max_k + 1):
                d = abs(A[i][j] - B[i][j])
                # i+1移動
                if k + d <= max_k:
                    dp[i + 1][j + 1][k + d] |= dp[i + 1][j][k]
                if abs(k - d) <= max_k:
                    dp[i + 1][j + 1][abs(k - d)] |= dp[i + 1][j][k]
                # j+1移動
                if k + d <= max_k:
                    dp[i + 1][j + 1][k + d] |= dp[i][j + 1][k]
                if abs(k - d) <= max_k:
                    dp[i + 1][j + 1][abs(k - d)] |= dp[i][j + 1][k]

    for k in range(max_k + 1):
        if dp[H][W][k]:
            return print(k)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###


def resolve():
    # (O):80（縦最大） × 80（横最大） × 80（各マスの最大の偏り）× 160（最大何回移動する必要があるか）
    H, W = map(int, input().split())
    A = [tuple(map(int, input().split())) for _ in range(H)]
    B = [tuple(map(int, input().split())) for _ in range(H)]
    Sub = [[0] * W for i in range(H)]
    for i in range(H):
        for j in range(W):
            Sub[i][j] = abs(A[i][j] - B[i][j])

    # 移動直前の偏りをkとし、移動先のマス(i, j)
    # についてd = abs(A[i][j] - B[i][j])とした際に、
    # 移動後の偏りを abs(k - d) とするか abs(k + d) とするか」を考えることと同値である。
    # dp[i][j][k] : マス (i, j) までの経路の偏りが k になることがあるか？

    # Bitset演算 (3次元TLE)
    max_k = 80 * (H + W)
    dp = [[0] * W for _ in range(H)]
    dp[0][0] = 1 << (max_k + Sub[0][0]) | 1 << (max_k - Sub[0][0])

    for i in range(H):
        for j in range(W):
            d = Sub[i][j]
            if i:
                dp[i][j] |= dp[i - 1][j] << d | dp[i - 1][j] >> d
            if j:
                dp[i][j] |= dp[i][j - 1] << d | dp[i][j - 1] >> d

    ans = 10 ** 18
    for i in range(max_k * 2 + 1):
        if dp[H - 1][W - 1] & (1 << i):
            ans = min(ans, abs(max_k - i))
    print(ans)


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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i in xrange(1, n):
        if i == exclude:
            continue
        g = gcd(g, a_list[i])
        if g <= max_g:
            break
    if g > max_g:
        max_g = g
print(max_g)


### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    g = gcd(b, a % b)
    return g

n = input()
a_list = map(int, raw_input().split())

gs1 = [None] * n
gs1[0] = a_list[0]
for i in xrange(1, n):
    gs1[i] = gcd(gs1[i - 1], a_list[i])

gs2 = [None] * n
gs2[n - 1] = a_list[n - 1]
for i in reversed(xrange(n - 1)):
    gs2[i] = gcd(gs2[i + 1], a_list[i])

max_g = 0
for exclude in xrange(n):
    if exclude == 0:
        g = gs2[1]
    elif exclude == n - 1:
        g = gs1[n - 2]
    else:
        g = gcd(gs1[exclude - 1], gs2[exclude + 1])
    if g > max_g:
        max_g = g
print(max_g)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
count=0
flag=False
while any(a%2==0 for a in A):
  count+=1
  flag=False
  for i in range(n):
    if A[i]%2==0 and flag==False:
      A[i]//=2
      flag=True
    else:
      A[i]*=3
print(count)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=0
for i in A:
  while i%2==0:
    i//=2
    ans+=1
print(ans)
### BUGGY CODE ###

n=int(input())

#1～nまでの数列
p = [i+1 for i in range(n)]
print(sum(p[:n-1]))


### FIXED CODE ###

n=int(input())

#1～n-1までの数列の和
print((n-1)*n//2)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [float('inf')]*len(a)
dp[0] = 0
for i in range(len(a)):
    for j in range(i+1, min(i+k+1, len(a))):
        dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]))
print(dp[-1])

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [float('inf')]*len(a)
dp[0] = 0
for i in range(len(a)):
    for j in range(i+1, min(i+k+1, len(a))):
        dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]))
print(dp[-1])
### BUGGY CODE ###

N = int(input())
ret = 0
a = ['3','5','7']
for i in range(357, N+1):
    t = list(set(str(i)))
    t.sort()
    if t == a:
        ret += 1
print(ret)

### FIXED CODE ###

N = int(input())
cnt = 0
def dfs(n, cnt):
    if int(n) > N:
        return cnt
    if n.count("3") >= 1 and n.count("5") >= 1 and n.count("7") >= 1:
        cnt += 1

    for i in ("3","5","7"):
        cnt = max(cnt, dfs(n+i, cnt))
    return cnt

print(dfs("0", 0))