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

N,Q = map(int, input().split())
answer = (N-2)**2

q1 = [(N,N-2)]
q2 = [(N,N-2)]

def binary_search(q,n):
  left = 0
  right = len(q)-1
  while right-left>0:
    index = (left+right)//2
    if q[index][0] < n:
      left = index+1
    else:
      right = index
  return left

for _ in range(Q):
  n,x = map(int, input().split())
  if n == 1:
    index = binary_search(q1,x)
    q = q1[index]
    answer -= q[1]
    if index == 0:
      q1 = [(x,q[1])] + q1
      q2_0 = q2[0]
      q2[0] = (q2_0[0],x-2)
  if n == 2:
    index = binary_search(q2,x)
    q = q2[index]
    answer -= q[1]
    if index == 0:
      q2 = [(x,q[1])] + q2
      q1_0 = q1[0]
      q1[0] = (q1_0[0],x-2)
      
print(answer)

### FIXED CODE ###

N,Q = map(int, input().split())
answer = (N-2)**2

q1 = [(N,N-2)]
q2 = [(N,N-2)]

def binary_search(q,n):
  left = 0
  right = len(q) - 1
  while right > left:
    index = (left + right) // 2
    if q[index+1][0] > n:
      left = index + 1
    else:
      right = index
  return left

for _ in range(Q):
  n,x = map(int, input().split())
  if n == 1:
    index = binary_search(q1,x)
    q = q1[index]
    answer -= q[1]
    if index == len(q1)-1:
      q1.append((x,q[1]))
      q2_last = q2[-1]
      q2[-1] = (q2_last[0],x-2)
  if n == 2:
    index = binary_search(q2,x)
    q = q2[index]
    answer -= q[1]
    if index == len(q2)-1:
      q2.append((x,q[1]))
      q1_last = q1[-1]
      q1[-1] = (q1_last[0],x-2)
      
print(answer)
### BUGGY CODE ###

S = str(input())
count = 0;
while('BW'in S):
  count=count+S.count('BW');
  S = S.replace('BW','WB');
print(count)

### FIXED CODE ###

S = input()
ans = 0
tmp = 0
for i in range(len(S)):
  if S[i] == 'W':
    ans+=i-tmp
    tmp+=1
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0, float("inf"))

dp = [float("inf")] * (N + 1)
dp[1] = 0

for i in range(2, N + 1):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + abs(h[i - k] - h[i]))

print(dp[N])

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0, float("inf"))

dp = [float("inf")] * (N + 1)
dp[1] = 0

for i in range(2, N + 1):
    for k in range(1, K + 1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i - k] + abs(h[i - k] - h[i]))
        else:
            break

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

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7


S = list(input())
x, y = map(int, input().split())

N = 8010

X = [0]
Y = [0]
flag = True
for s in S:
    if s == 'F':
        if flag:
            X[-1] += 1
        else:
            Y[-1] += 1
    else:
        if flag:
            if Y[-1] != 0:
                Y.append(0)
        else:
            if X[-1] != 0:
                X.append(0)
        flag = not flag

dp = [[0] * (2 * N) for _ in range(2)]
if S[0] == 'F':
    dp[0][X[0] + N] = 1
else:
    dp[0][X[0] + N] = 1
    dp[0][-X[0] + N] = 1

for i in range(1, len(X)):
    x_ = X[i]
    for j in range(2 * N):
        dp[i % 2][j] = 0
        if j >= x_:
            if dp[(i - 1) % 2][j - x_]:
                dp[i % 2][j] = 1
        if j + x_ < 2 * N:
            if dp[(i - 1) % 2][j + x_]:
                dp[i % 2][j] = 1

# print (dp)
if dp[(len(X) - 1) % 2][x + N] == 0:
    print ('No')
    exit()

dp = [[0] * (2 * N) for _ in range(2)]
dp[0][Y[0] + N] = 1
dp[0][-Y[0] + N] = 1

for i in range(1, len(Y)):
    y_ = Y[i]
    for j in range(2 * N):
        dp[i % 2][j] = 0
        if j >= y_:
            if dp[(i - 1) % 2][j - y_]:
                dp[i % 2][j] = 1
        if j + y_ < 2 * N:
            if dp[(i - 1) % 2][j + y_]:
                dp[i % 2][j] = 1

if dp[(len(Y)-1) % 2][y + N] == 0:
    print ('No')
    exit()

print ('Yes')


### FIXED CODE ###

s = list(input())
x, y = map(int, input().split())

X = [0]
Y = [0]

flag = True
tmp = 0
for i in s:
    if i == 'F':
        tmp += 1
    else:
        if flag:
            X.append(tmp)
        else:
            Y.append(tmp)
        tmp = 0
        flag = not flag

if flag:
    X.append(tmp)
else:
    Y.append(tmp)

# print (X)
# print (Y)

x -= X[1]
X[1] = 0

x = abs(x)
y = abs(y)

total_X = sum(X)
total_Y = sum(Y)

lst_X = [0] * (total_X + 1)
lst_X[0] = 1
for i in X:
    if i == 0:
        continue
    for j in range(total_X - i, -1, -1):
        if lst_X[j] == 1:
            lst_X[j + i] = 1

# print (lst_X)

lst_Y = [0] * (total_Y + 1)
lst_Y[0] = 1
for i in Y:
    if i == 0:
        continue
    for j in range(total_Y - i, -1, -1):
        if lst_Y[j] == 1:
            lst_Y[j + i] = 1

# print (lst_Y)
if x > total_X or y > total_Y:
    print ('No')
    exit()

if (total_X - x) % 2 == (total_Y - y) % 2 == 0 and lst_X[(total_X - x) // 2] == 1 and lst_Y[(total_Y - y) // 2]:
    print ('Yes')
else:
    print ('No')
### BUGGY CODE ###

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h, 2)

    for a in A:
        h = hist[a-1]
        if h > 2:
            diff = combinations_count(h, 2) - combinations_count(h-1, 2)
            print(all - diff)
        elif h == 2:
            print(all - 1)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()

### FIXED CODE ###

import math

def combinations_count(n):
    return math.floor(n*(n-1)/2)

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    hist = [0] * 2*pow(10, 5)
    for a in A:
        hist[a-1] += 1

    all = 0
    for h in hist:
        if h >= 2:
            all += combinations_count(h)

    for a in A:
        h = hist[a-1]
        if h >= 2:
            diff = h-1
            print(all - diff)
        else:
            print(all)
    
if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

N=int(input())
S=list(map(int,input().split()))
ans=0
mod=10**9+7
for i in range(1,61):
   zero,one=0,0
   for j in S:
      tmp=bin(j)[2:]
      tmp=tmp.zfill(60)
      if tmp[-i]=="1":
         one+=1
      else:
         zero+=1
   ans+=(2**(i-1)*zero*one)%mod
   ans%=mod
print(ans)

### FIXED CODE ###

import numpy as np 
N=int(input())
a=np.array(list(map(int, input().split())))
ans=0
mod=10**9+7
for i in range(60):
   s=np.count_nonzero(a>>i&1)
   ans+=pow(2,i,mod)*s*(N-s)%mod
   ans%=mod
print(ans)
### BUGGY CODE ###

from bisect import bisect

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

ans = []

if len(A) == 2 :
    ans.append(A[::-1])
    calc = A[1] - A[0]

else :
    ind = bisect(A,0)

    X = A[:ind]
    Y = A[ind:]
    
    if len(X) == 0 :
        ans.append([Y[0],Y[1]])
        X.append(Y[0]-Y[1])
        Y.pop(0)
        Y.pop(0)
    elif len(Y) == 0 :
        ans.append([X[-1],X[-2]])
        Y.append(X[-1]-X[-2])
        X.pop(-1)
        X.pop(-1)
    
    while True :
        if len(X) >= 2 :
            ans.append([Y[0],X[-1]])
            Y[0] -= X.pop(-1)
        elif len(Y) >= 2 :
            ans.append([X[-1],Y[0]])
            X[-1] -= Y.pop(0)
        else :
            ans.append([Y[0],X[0]])
            calc = Y.pop(0) - X.pop(0)
            break
    
print(calc)
for i in range(len(ans)) :
    print(*ans[i])


### FIXED CODE ###

from bisect import bisect

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

ind = bisect(A,0)

X = A[:ind]
Y = A[ind:]
ans = []
if len(X) == 0 :
    ans.append([Y[0],Y[1]])
    X.append(Y[0]-Y[1])
    Y.pop(0)
    Y.pop(0)

if len(Y) == 0 :
    if len(X) != 1 :
        ans.append([X[-1],X[-2]])
        Y.append(X[-1]-X[-2])
        X.pop(-1)
        X.pop(-1)

if len(X) + len(Y) <= 1 :
    if len(X) == 0 :
        calc = Y[0]
    else :
        calc = X[0]

while len(X) + len(Y) >= 2 :
    if len(X) >= 2 :
        if len(Y) != 1 :
            ans.append([X[-1],Y[0]])
            X[-1] -= Y.pop(0)
        else :
            ans.append([Y[0],X[-1]])
            Y[0] -= X.pop(-1)
    elif len(Y) >= 2 :
        if len(X) != 1 :
            ans.append([Y[0],X[-1]])
            Y[0] -= X.pop(-1)
        else :
            ans.append([X[-1],Y[0]])
            X[-1] -= Y.pop(0)
    else :
        calc = Y[0]-X[0]
        ans.append([Y.pop(0),X.pop(0)])

print(calc)
#print(*ans,sep="\n")
for l in ans :
    print(*l)
### BUGGY CODE ###

'''
制約
2≦K≦2500
0≦S≦3K
K,S は整数である。

'''
# from collections import deque # キュー、スタックに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

# import numpy as np


def main():
    '''メイン処理'''
    k, s = map(int, input().split())

    counter = 0
    # x,y,zは全て0～kの値を取る。 x+y+z = sを満たす。
    for x in range(k+1):
        if x > s:
            # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
            break

        for y in range(k+1):
            if x+y > s:
                # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                break

            for z in range(k+1):
                if (x+y+z) == s:
                    counter += 1
                elif (x+y+z) > s:
                    # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                    break

    print(counter)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()


### FIXED CODE ###

'''
制約
2≦K≦2500
0≦S≦3K
K,S は整数である。

'''
# from collections import deque # キュー、スタックに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

# import numpy as np


def main():
    '''メイン処理'''
    k, s = map(int, input().split())

    counter = 0
    # x,y,zは全て0～kの値を取る。 x+y+z = sを満たす。
    for x in range(k+1):
        if x > s:
            # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
            break

        for y in range(k+1):
            if x+y > s:
                # 合計がsを超えたら、このforループでは条件を満たせないのでbreak
                break
            
            # 3重ループではTLEになる。x+y+z = s なので、z=s-x-yとなるzがあればカウントする
            z = s-x-y
            if z >= 0 and z <= k:
                counter += 1

    print(counter)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()
### BUGGY CODE ###

import copy

n = int(input())
a = [int(input()) for _ in range(n)]
b = []
for i in range(n):
  b = copy.copy(a)
  b.pop(i)
  print(max(b))
  b = []

### FIXED CODE ###

import copy

n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(copy.copy(a))
ma = b[-1]
mi = b[-2]
for i in range(n):
  if a[i] == ma:
    print(mi)
  else:
    print(ma)
### BUGGY CODE ###

import math
from functools import lru_cache
from operator import mul
from functools import reduce

def resolve():
    MOD = 10**9 + 7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    B = A[::-1]

    @lru_cache(maxsize=None)
    def combinations_count__(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    @lru_cache(maxsize=None)
    def combinations_count(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom

    sum = 0
    for i in range(K-1, N):
        sum += combinations_count(i, K-1) * A[i] % MOD - combinations_count(i, K-1) * B[i] % MOD

    print(sum % MOD)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

import math
from functools import lru_cache
from operator import mul
from functools import reduce


def resolve():
    import sys
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    B = A[::-1]

    @lru_cache(maxsize=None)
    def combinations_count__(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    @lru_cache(maxsize=None)
    def combinations_count____(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom

    def combinations_count_(n, r):
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result

    def modinv(a, mod=10**9+7):
        return pow(a, mod-2, mod)

    def combinations_count(n, r, mod=10**9+7):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n-r)
        return fact[n] * factinv[r] * factinv[n-r] % mod
    
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    sum = 0
    for i in range(K-1, N):
        sum += combinations_count(i, K-1) * A[i] % MOD - combinations_count(i, K-1) * B[i] % MOD

    print(sum % MOD)


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

n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

for i in range(n):
  tmp = l.pop(i)
  print(max(l))
  l.insert(i,tmp)
  

### FIXED CODE ###

n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

index = l.index(m)  

l.pop(index)

for i in range(n):
  if i == index:
  	print(max(l))
  else:
    print(m)
### BUGGY CODE ###

import math
K = int(input())

def gcd_plus(a,b,c):
  num_list = [a,b,c]
  num_list.sort()
  for i in range(2):
    num_list[i+1] = math.gcd(num_list[i],num_list[i+1])
  return num_list[2]

sum = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      sum += gcd_plus(a,b,c)
      
print(sum)

### FIXED CODE ###

import math
K = int(input())

sum = 0
gcd_a_b = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    gcd_a_b = math.gcd(a,b)
    for c in range(1,K+1):
      sum += math.gcd(gcd_a_b,c)
      
print(sum)
### BUGGY CODE ###

N, M = tuple(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
for i in range(M):
    A[-1] = A[-1] // 2
    A.sort()
print(sum(A))

### FIXED CODE ###

import heapq

N, M = tuple(map(int, input().split()))
A = list(map(int, input().split()))
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A) * (-1) // 2
    heapq.heappush(A, tmp * (-1))
print(sum(A) * (-1))
### BUGGY CODE ###

N,K=list(map(int,input().split()))
dp_list=[10**10]*110000
h=list(map(int,input().split()))
dp_list[0]=0
for i in range(N):
    for j in range(1,K+1):
        k=i+j
        if k<N:
            # if dp_list[j] is None:dp_list[j]=abs(h[j]-h[i])+dp_list[i]
            dp_list[k]=min(dp_list[k],abs(h[k]-h[i])+dp_list[i])
        else:break
print(dp_list[N-1])

### FIXED CODE ###

import numpy as np
N,K=list(map(int,input().split()))
dp_list=np.full(N,10**10,dtype=int)
h=list(map(int,input().split()))
h=np.array(h)
dp_list[0]=0
for i in range(1,N):
        dp_list[i:i+K] = np.fmin(dp_list[i:i+K], dp_list[i-1] + np.abs(h[i:i+K] - h[i-1]))
print(dp_list[-1])
### BUGGY CODE ###

string = str(input())
         
pairs = 0
limit = len(string)-4
secondLimit = len(string)
size = len(string)-1
for i in range(size, 2, -1):
  intValue = int(string[i])
  potency = 1
  for j in range(i-1, -1, -1):
    potency *= 10
    intValue += int(string[j])* potency
    if i-j >= 3 and intValue % 673 == 0:
      pairs += 1
print(pairs)

### FIXED CODE ###

number = str(input())[::-1]
remainderDictionary = {0: 1}
    
sum = 0
x = 1
for i in number:
  x = (x * 10) % 2019
  sum += int(i) * x
  sum %= 2019
  remainderValue = remainderDictionary.get(sum,0) + 1
  remainderDictionary[sum] = remainderValue
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)
### BUGGY CODE ###

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

import heapq

List = []
for i in range(N):
    List.append([L[i][0]-0.5-L[i][2], 1, L[i][2]])
    List.append([L[i][1]-0.5-L[i][2], -1, L[i][2]])
    
List.sort()

h_in = []
h_ex = []
ans = []
j = 0
for i in range(Q):
    while j < 2*N and List[j][0] < D[i]:
        if List[j][1] == 1:
            heapq.heappush(h_in, List[j][2])
        else:
            heapq.heappush(h_ex, List[j][2])
        j += 1
    while len(h_in) > 0 and len(h_ex) > 0 and h_in[0] == h_ex[0]:
        heapq.heappop(h_in)
        heapq.heappop(h_ex)
    if h_in:
        ans.append(h_in[0])
    else:
        ans.append(-1)
    
for i in range(Q):
    print(ans[i])

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)
### BUGGY CODE ###

import math
N, P = map(int, input().split())
p = math.ceil(P**(1/N))
ans = 1
for i in reversed(range(1, p+1)):

    if P % (i ** N) == 0:
        ans = i
        break
print(ans)


### FIXED CODE ###

import math
N, P = map(int, input().split())
p = P**(1/N)
ans = 1
flag=False
if N==1:
  print(P)
  exit(0)


divisors=[]

for i in range(2,round(P**(1/N))+1):
  if P%i==0:
    divisors.append(i)
for i in reversed(divisors):
    if P % (i ** N) == 0:
        ans = i
        break
print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
M = np.asarray(input().split(), dtype=int)
result = 0
for i in range(N):
  x = M[i]
  result += np.sum(M[i+x+1:]==np.arange(1,N-i-x))
print(result)

### FIXED CODE ###

N = int(input())
M = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i,m in enumerate(M):
  if i+m >= N:
    continue
  L[i+m] += 1
for i,m in enumerate(M[::-1]):
  if i+m >= N:
    continue
  R[i+m] += 1
R = R[::-1]
#print(L)
#print(R)
print(sum([l*r for l,r in zip(L,R)]))
### BUGGY CODE ###

def main():
    n, dis, dam = map(int, input().split())
    mon = [list(map(int, input().split())) for _ in range(n)]
    mon.sort(key=lambda x: x[0])
    imos = [0]*(n+1)
    dis = 2*dis + 1
    ans = 0
    for i in range(n):
        if 0 < i:
            imos[i] += imos[i-1]
        if imos[i] < mon[i][1]:
            tmp = (mon[i][1] - imos[i] + dam - 1) // dam
            ans += tmp
            tmp *= dam
            imos[i] += tmp
            L, R = i, n
            while L+1 < R:
                P = (L+R)//2
                if mon[P][0] < mon[i][0]+dis:
                    L = P
                else:
                    R = P
            imos[L+1] -= tmp
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from bisect import bisect_left
def main():
    n, dis, dam = map(int, input().split())
    mon = [list(map(int, input().split())) for _ in range(n)]
    mon.sort(key=lambda x: x[0])
    p = [v[0] for v in mon]
    imos = [0]*(n+1)
    dis = 2*dis + 1
    ans = 0
    for i in range(n):
        if 0 < i:
            imos[i] += imos[i-1]
        if imos[i] < mon[i][1]:
            tmp = (mon[i][1] - imos[i] + dam - 1) // dam
            ans += tmp
            tmp *= dam
            imos[i] += tmp
            idx = bisect_left(p, p[i]+dis)
            imos[idx] -= tmp
    print(ans)

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

n = int(input())

counter = 0
for i in range(0,n + 1):
  i_str = str(i)
  i_list = list(i_str)

  if i_list.count("0") ==0 and i_list.count("1") ==0 and i_list.count("2") == 0 and i_list.count("3") >=1 and i_list.count("4")==0 and i_list.count("6")==0 and i_list.count("8")==0 and i_list.count("9")==0 and i_list.count("5") >=1and i_list.count("7") >=1 :
    counter += 1
    
print(counter)  
  

### FIXED CODE ###

n = int(input())
def dfs(s,n):
  count = 0
  if s > n:
    return count
  if str(3) in list(str(s)) and str(5) in list(str(s)) and str(7) in list(str(s)):
    count += 1
  count += dfs(10*s + 3,n)
  count += dfs(10*s + 5,n)
  count += dfs(10*s + 7,n)
  return count


print(dfs(3,n) + dfs(5,n) + dfs(7,n))
### BUGGY CODE ###

import math 
[K, S] = list(map(int, input().split()))
count = 0
total = 0
for X in range(K+1):
  if X > S:
    break
  for Y in range(K+1):
    for Z in range(K+1):
      total = X + Y + Z 
      if total == S:
        count += 1
      if total > S:
        break
      if total < S/2:
        Z += math.floor(S/2)
            
print(count)

### FIXED CODE ###

[K, S] = list(map(int, input().split()))
count = 0
for X in range(K+1):
  for Y in range(K+1):
    Z = S - X - Y
    if 0 <= Z and Z <= K:
      count +=1

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

# まずDPを使う理由はあるs[i]=t[j]の時 そのs[i],t[j]を追加した時に増える部分列の場合の数は前の部分列の場合の数+1増えるから
# 前の要素を利用するということはDPを疑う

mod = 10**9 + 7
n,m = map(int, input().split())
s = input().split()
t = input().split()

dp = [[0] * (m+1) for i in range(n+1)]
S = [[0] * (m+1) for i in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] += (S[i][j] + 1)
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0 # i番目,j番目を追加すると増える場合の数 iとjが等しくないならば場合の数は増えないから0
        S[i+1][j+1] = S[i][j+1] + S[i+1][j] + dp[i+1][j+1] - S[i][j]
        S[i+1][j+1] %= mod

print(S[n][m]+1)

### FIXED CODE ###

# まずDPを使う理由はあるs[i]=t[j]の時 そのs[i],t[j]を追加した時に増える部分列の場合の数は前の部分列の場合の数+1増えるから
# 前の要素を利用するということはDPを疑う
import sys
input=sys.stdin.readline

mod = 10**9 + 7
n,m = map(int, input().split())
s = input().split()
t = input().split()

dp = [[0] * (m+1) for i in range(n+1)]
S = [[0] * (m+1) for i in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] += (S[i][j] + 1)
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0 # i番目,j番目を追加すると増える場合の数 iとjが等しくないならば場合の数は増えないから0
        S[i+1][j+1] = S[i][j+1] + S[i+1][j] + dp[i+1][j+1] - S[i][j]
        S[i+1][j+1] %= mod

print(S[n][m]+1)
### BUGGY CODE ###

def recur(ba,bb):
    if(ba <= 0 and bb <= 0):
        return 0
    if(ba <= 0):
        #only b twice
        return (bb*2)-1
    elif(bb<=0):
        return (ba*2)-1
    else:
        tb = max(bb+bb-1,recur(ba,bb-2))
        ta = max(ba+ba-1,recur(ba-2,bb))
        bt = max(ba+bb,recur(ba-1,bb-2))
        return max(max(tb,ta),bt)

a,b = [int(i) for i in input().split()]

print(recur(a,b))


### FIXED CODE ###

def recur(ba,bb):
    tb = (2*bb)-1
    ta = (2*ba)-1
    bt = ba+bb
    return max(max(tb,ta),bt)

a,b = [int(i) for i in input().split()]

print(recur(a,b))
### BUGGY CODE ###

N=int(input())
A=[*map(int,input().split())]
a=1
while A:
  a*=A.pop()
if a > 10**18:
  print(-1)
else:
  print(a)

### FIXED CODE ###

N=int(input())
A=[*map(int,input().split())]
a=1
if 0 in A:
  a=0
else:
  while A:
    a*=A.pop()
    if a>10**18:
      a=-1
      break
print(a)
### BUGGY CODE ###

import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.full(N, 0)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))