Harryxun/stf_run huggingface dataset:
import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = mix(y, y_max)

print(x_min, x_max, y_min, y_max)
if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))

### FIXED CODE ###

import sys
w,h,n = map(int, sys.stdin.readline().split())

x_min = 0
x_max = w
y_min = 0
y_max = h

for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x_min = max(x, x_min)
    elif a == 2:
        x_max = min(x, x_max)
    elif a == 3:
        y_min = max(y, y_min)
    else:
        y_max = min(y, y_max)

if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))
def resolve():
    N = int(input())
    ary = [N] + list(range(1, N))
    print(N*(N-1)//2)



if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    print(int(N*(N-1)//2))



if '__main__' == __name__:
    resolve()
s=input()
s="2018"+s[4:]
print s

### FIXED CODE ###

s=input()
s="2018"+s[4:]
print(s)
class Node(object):
	def __init__(self):
		self.val = 0
		self.children = []
	
	def add_child(self, child):
		self.children.append(child)

	def add_counter(self, val):
		self.val += val
		for child in self.children:
			child.add_counter(val)

n, q = map(int, input().split())
nodes = [Node() for i in range(n)]

for i in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].add_child(nodes[b - 1])

for i in range(q):
	p, x = map(int, input().split())
	nodes[p - 1].add_counter(x)

for node in nodes:
	print(node.val, end=" ")
	

### FIXED CODE ###

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

n, q = map(int, input().split())
vals = [0] * n
node_idxes = [[] for _ in range(n)]

for i in range(n - 1):
	a, b = map(int, input().split())
	node_idxes[a - 1].append(b - 1)
	node_idxes[b - 1].append(a - 1)

for i in range(q):
	p, x = map(int, input().split())
	vals[p - 1] += x

def dfs(chi_idx, parent):
	for child in node_idxes[chi_idx]:
		if child == parent:
			continue
		vals[child] += vals[chi_idx]
		dfs(child, chi_idx)

dfs(0, -1)
print(*vals)
import collections

n = int(input())
d = list(map(int, input().split()))

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

c = sorted(c.items(), key=lambda x:x[0])

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    ans %= 998244353
    if ans == 0:
        jug = False
    
if jug == False:
    print(0)
else:
    print(ans)

### FIXED CODE ###

n = int(input())

if n % 2 == 0:
  ans = n / 2 - 1
else:
  ans = n / 2
  
print(int(ans))
# -*- coding: utf-8 -*-
# E

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

mod = 10**9 + 7

A.sort()
# print(A)

def cmb(n, r):
    from operator import mul
    from functools import reduce

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


ans = 0
num1=None
num2=None

for i in range(N):
    if N - i - 1 >= K-1:
        if num1 is None:
            num1 = cmb(N-i-1, K-1)
        else:
            num1 = int(num1 * (N-i-K+1) / (N-i))
        # print(N-i-1, K-1, num1)
        if A[i] * num1 < 0:
            ans += (-A[i] * num1) % mod
        else:
            ans -= (A[i] * num1) % mod
        # print(f'-: {i}, {num}, {A[i]}')
    if i >= K-1:
        if num2 is None:
            num2 = cmb(i, K-1)
        else:
            num2 = int(num2 * i / (i-K+1))
        # print(i, K-1, num2)
        if A[i] * num2 < 0:
            ans -= (-A[i] * num2) % mod
        else:
            ans += (A[i] * num2) % mod
        # print(f'+: {i}, {num}, {A[i]}')

print(ans % mod)


### FIXED CODE ###

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mod = 10**9 + 7


class Cmb(object):
    def cmb_precalc(self, n, r, mod: int = 10 ** 9 + 7):
        if (r < 0) or (r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % mod

    def cmb_prep(self, N: int, mod: int = 10 ** 9 + 7):
        self.g1 = [1, 1]  # 元テーブル
        self.g2 = [1, 1]  # 逆元テーブル
        inverse = [0, 1]  # 逆元テーブル計算用テーブル

        for i in range(2, N + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)


ans = 0
cmb = Cmb()
cmb.cmb_prep(N + 5)

for i in range(N):
    if i >= K-1:
        ans += A[i] * cmb.cmb_precalc(i, i-K+1)
    if N - i - 1 >= K-1:
        ans -= A[i] * cmb.cmb_precalc(N-i-1, K-1)

print(ans % mod)
a=input()
c=False
f=False
for i in range(len(a))
  if c:
    if a[i]=='F'
    f=True
  else:
    if a[i]=='C'
    c=True
if c and f:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=input()
c=False
f=False
for i in range(len(a)):
    if c==True:
        if a[i]=='F':
            f=True
    else:
        if a[i]=='C':
            c=True
if c==True and f==True:
    print("Yes")
else:
    print("No")
import fractions
a, b, c, d = map(int, input().split())
e = (c*d)/fractions.gcd(c,d)
bb = b-((b//c) + (b//d)- (b//e))
aa = a-1-(((a-1)//c)+((a-1)//d)-((a-1)//e))
z = bb-aa
print(int(z))

### FIXED CODE ###

n = int(input())
d = list(map(int, input().split()))
d.sort()
if d[int((n/2))] == d[int(n/2)-1]:
    print(0)
else:
    print(d[int(n/2)]-d[int((n/2)-1)])
X.sort()

memo = dict()
def get_min(n,x):
    key = str((n,x))
    tmp = memo.get(key,None)
    if tmp != None:
        return tmp
    if x == []:
        tmp = 10**8
        memo[key] = tmp
        return tmp
    elif len(x) == 1:
        memo[key] = 0
        return 0
    x0 = x[0]
    if n == 1:
        tmp = x[-1]-x0
        memo[key] = tmp
        return tmp
    tmp = min([y - x0 + get_min(n-1,x[i+1:]) for i,y in enumerate(x)])
    memo[key] = tmp
    return tmp
if N >= M:
    print(0)
else:
    print(get_min(N,X))

### FIXED CODE ###

N,M = map(int,input().split())
X = list(map(int,(input().split())))

X.sort()

dif_X = [X[i+1]-x for i,x in enumerate(X[:-1])]
dif_X.sort()
print(sum(dif_X[:max(0,M-N)]))
#!usr/bin/env python3

def string_three_numbers_spliter():
    a, b, c = [int(i) for i in input().split()]
    return a, b, c


def count_nums_of_factors_of_c_in_a_and_b(a, b, c):
    count = 0
    # XXX Refactor the algorithm below as it is exhaustive and inefficient.
    for i in range(1, c+1):
        if (c % i == 0):
            if i >= a and i <= b:
                count += 1
    return count


def main():
    a, b, c = string_two_numbers_spliter()
    print(count_nums_of_divisors_of_c_in_a_and_b(a, b, c))


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!usr/bin/env python3

def string_three_numbers_spliter():
    a, b, c = [int(i) for i in input().split()]
    return a, b, c


def count_nums_of_factors_of_c_in_a_and_b(a, b, c):
    count = 0
    # XXX Refactor the algorithm below as it is exhaustive and inefficient.
    for i in range(1, c+1):
        if (c % i == 0):
            if i >= a and i <= b:
                count += 1
    return count


def main():
    a, b, c = string_three_numbers_spliter()
    print(count_nums_of_factors_of_c_in_a_and_b(a, b, c))


if __name__ == '__main__':
    main()
n,k=input().split(" ")
if k==1:
    return 0
else:
    return n-k

### FIXED CODE ###

n,k= [int(i) for i in input().split()]
if k==1:
    print (0)
else:
    print (n-k)
a, b, k = map(int, input().split())

l = list(range(a, b + 1))
ans = []
ans.extend(l[:min(b,k)])
ans.extend(l[max(len(l) - k,a):])

ans = list(set(ans))
ans = sorted(ans)
for a in ans:
   print(a)

### FIXED CODE ###

a, b, k = map(int, input().split())

for i in range(a, min(b, a + k - 1) + 1):
    print(i)
for i in range(max(a + k, b - k + 1), b + 1):
    print(i)

exit()
l = list(range(a, b + 1))
ans = []
ans.extend(l[:min(k,len(l))])
ans.extend(l[max(0,len(l) - k):])

ans = sorted(list(set(ans)))
for a in ans:
   print(a)
import sys
N, M = map(int, input().split())

C = []
S = []

for i in range(M):
    c, s = map(int, input().split())
    C.append(c)
    S.append(s)

for x in range(1000):
    keta = 1
    nx = x//10
    d = [x%10]


    while(nx):
        keta += 1
        d.append(nx%10)
        nx = nx // 10
    d = list(reversed(d))

    isOk = True
    
    for i in range(M):
        if( d[C[i]-1] != S[i-1] ):
            isOk = False

    if isOk :
        num = "".join(map(str, d))
        print(num)
        sys.exit

print(-1)
sys.exit

### FIXED CODE ###

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

ans = [0 for i in range(N)]
isTerms = [0 for i in range(N)]
jadge = True

for i in range(M):
    s, c = map(int, input().split())
    if( ans[s-1] != c and isTerms[s-1] != 0):
        jadge = False
    elif( s == 1 and c == 0):
        jadge = False
    else:
        ans[s-1] = c
        isTerms[s-1] = 1

if( N != 1 and ans[0] == 0 and jadge):
    ans[0] = 1

if( N == 1 and ans[0] == 0):
    jadge = True

if jadge:
    if(N==1):
        print(ans[0])
    else:
        for i in range(N-1):
            print(ans[i] ,end = "")
        print(ans[i+1])
else:
    print(-1)
n,m=map(int,input().split())
a=[0]*n
for i in range(n):
  a[i]=int(input().split())
num=sum(a)
tmp=num//(4*m)
count=0
for i in range(n):
  if a[i]>=tmp:
    count+=1
if count==m:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int, input().split()))
num=sum(a)
tmp=float(num)/float(4.0*m)
count=0
for i in range(n):
  if a[i]>=tmp:
    count+=1
if count>=m:
  print("Yes")
else:
  print("No")
s = int(input().replace(' ',''))
if s**0.5.is_integer:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import math
s = int(input().replace(' ',''))
if int(math.sqrt(s))**2 == s:
    print("Yes")
else:
    print("No")
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    # pairがpairでない
    if c[ma] % 2 != 0:
        return False
    x = ma - c[ma] // 2
    if x < 0:
        return False
    # pair以外、すべてalone(crowdが0個)
    if x == c[mi]:
        return True
    # crowdを1つ以上作れるなら0以上c[mi]-2以下の好きな數を作れる
    return x <= c[mi] - 2

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ma, mi = max(a), min(a)
    if ma >= N or mi < 1:
        raise
    if ma - mi > 1:
        return False
    if ma == mi:
        return ma == N - 1 or  2 * ma <= N
    c = Counter(a)
    # pairがpairでない
    if c[ma] % 2 != 0:
        return False
    x = ma - c[ma] // 2
    if x < 0:
        return False
    # pair以外、すべてalone(crowdが0個)
    if x == c[mi]:
        return True
    # crowdを1つ以上作れるなら0以上c[mi]-2以下の好きな數を作れる
    return x <= c[mi] - 2

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(N, a) else NO)

if __name__ == '__main__':
    main()
def fibcmb(start,end):
    start += 1
    end -= 1
    up = end - start
    a1 = 1
    a2 = 2
    if up < 0:
        return 0
    elif up == 0:
        return 1
    elif up == 1:
        return a1
    elif up == 2:
        return a2
    else:
        for _ in range(up-2):
            an = a1 + a2
            a1 = a2
            a2 = an
        return an

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
ans = 1
cmb = [0]*(m+1)
cmb[0] = fibcmb(-1,a[0])
for i in range(1,m):
    cmb[i] = fibcmb(a[i-1],a[i])
cmb[-1] = fibcmb(a[-1],n+1)
for i in range(m+1):
    ans *= cmb[i]
print(ans%1000000007)

### FIXED CODE ###

def fibcmb(start,end):
    start += 1
    end -= 1
    up = end - start
    a1 = 1
    a2 = 2
    if up < 0:
        return 0
    elif up == 0:
        return 1
    elif up == 1:
        return a1
    elif up == 2:
        return a2
    else:
        for _ in range(up-2):
            an = a1 + a2
            a1 = a2
            a2 = an
        return an

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
ans = 1
cmb = [0]*(m+1)
if m == 0:
    ans = fibcmb(-1,n+1)
else:
    cmb[0] = fibcmb(-1,a[0])
    for i in range(1,m):
        cmb[i] = fibcmb(a[i-1],a[i])
    cmb[-1] = fibcmb(a[-1],n+1)
    for i in range(m+1):
        ans *= cmb[i]
print(ans%1000000007)
a, b = int(x) for x in input().split()
print(a*b)

### FIXED CODE ###

a, b = (int(x) for x in input().split())
print(a*b)
n = int(input())
h = input()
str_list = []
ans = "YES"
for i in range(len(h)):
  if(i % 2 == 0):
    str_list += h[i]

for j in range (len(str_list)-1):
  if(int(str_list[j]) > int(str_list[j]) + 1):
    str_list[j] = str(int(str_list[j])-1)
  if(int(str_list[j]) > int(str_list[j]) + 1):
    ans = "NO"
    break

print(ans)

### FIXED CODE ###

n = int(input())
h = input()
str_list = []
ans = "Yes"
str_list = h.split(" ")

for j in range (len(str_list)-1):

  if(int(str_list[j]) < int(str_list[j+1])):
    str_list[j+1] = str(int(str_list[j+1])-1)
  elif(int(str_list[j]) > int(str_list[j+1])):
    ans = "No"
    break

print(ans)
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if k == 1:
  print(0)
else:
  for i in range(1,n+1):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1)
    ans -= a[i-1]*cmb(n-i,k-1)
  print(ans%1000000007)

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

from operator import mul
from functools import reduce
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5
fact = [1, 1]  
factinv = [1, 1]
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if k == 1:
  print(0)
else:
  for i in range(1,n):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1,p)
    ans -= a[i-1]*cmb(n-i,k-1,p)
  print(ans%1000000007)
n = int(input())
print(int(n*(n+1)/2)

### FIXED CODE ###

n = int(input())
print(int(n*(n+1)/2))
a = int(input())
b = int(input())
print(str(a*b)+" ", end="")
print(a*2+b*2)

### FIXED CODE ###

l = input().split()
a = int(l[0])
b = int(l[1])
print(a*b, a*2+b*2)
from typing import List


N = int(input())

L: List[int] = [None] * (N + 1)
L[0] = 2
L[1] = 1

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

print(L[N])


### FIXED CODE ###

N = int(input())

L = [None] * (N + 1)
L[0] = 2
L[1] = 1

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

print(L[N])
#!/usr/bin/env python
# coding: utf-8

# In[27]:


import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for i in range(H)])
"""
4 6
#..#..
.....#
....#.
#.#...
"""


# In[51]:


row_beam = np.zeros((H, W))
col_beam = np.zeros((H, W))
sh, sw = np.where(S=='#')


# In[52]:


#np.where()
for i in range(H):
    #print(i)
    #print(row_beam)
    row = S[i]
    #sharp_pos = np.where(row=='#')[0]
    sharp_pos = sw[sh==i]
    #print(sharp_pos)
    if len(sharp_pos) == 0:
        row_beam[i] = W
    else:
        s = 0
        for sp in sharp_pos:
            contin = sp-s
            row_beam[i, s:sp] = contin
            s = sp+1
        if s != W:
            row_beam[i, s:W] = W-s
            
for i in range(W):
    #print(i)
    #print(col_beam)
    col = S[:,i]
    #sharp_pos = np.where(col=='#')[0]
    sharp_pos = sh[sw==i]
    #print(sharp_pos)
    if len(sharp_pos) == 0:
        col_beam[:, i] = H
    else:
        s = 0
        for sp in sharp_pos:
            contin = sp-s
            col_beam[s:sp, i] = contin
            s = sp+1
        if s != W:
            col_beam[s:H, i] = H-s


# In[53]:


print(int(np.max(row_beam+col_beam-1)))


# In[54]:


#print(row_beam)
#print(col_beam)


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[2]:


P, Q, R = map(int, input().split())


# In[3]:


t = [P, Q, R]
print(sum(t)-max(t))


# In[ ]:
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(mod_min % (m % mod_min))

### FIXED CODE ###

import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(math.gcd(m, mod_min))
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=input()
????????if n==0: break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????ans+=T
????????print ans

### FIXED CODE ###

while(1):
    num=int(raw_input())
    if num==0:
        break
    else:
        d=[0,1,2,3,4,5,6]
        sum=1
        for i in range(num):
            dir=num=raw_input()
            if dir=="North":
                d=[0,d[2],d[6],d[3],d[4],d[1],d[5]]
            elif dir=="East":
                d=[0,d[4],d[2],d[1],d[6],d[5],d[3]]
            elif dir=="West":
                d=[0,d[3],d[2],d[6],d[1],d[5],d[4]]
            elif dir=="South":
                d=[0,d[5],d[1],d[3],d[4],d[6],d[2]]
            elif dir=="Right":
                d=[0,d[1],d[3],d[5],d[2],d[4],d[6]]
            else:
                d=[0,d[1],d[4],d[2],d[5],d[3],d[6]]
            sum=sum+d[1]
        print sum
import math

instr = input()
instrSp = instr.split()

a = int(instrSp[0])

print("{a:5f} {b:5f}".format(a=a * a * math.pi, b=2 * a * math.pi))



### FIXED CODE ###

from math import pi

instr = input()
instrSp = instr.split()

a = float(instrSp[0])

print("{a:5f} {b:5f}".format(a=a * a * pi, b=2 * a * pi))
n,m = map(int,input().split())
a = []
b = []
mem = {}
ans = 0
def flip(a,f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j):
                a[i][j] = - a[i][j]
def solve(n,m):
    if(mem.get((n,m))!=None):
        return mem[(n,m)]
    if m == 0:
        return 0
    if n == m:
        mem[(n,m)] = sum(b[:n])
        return mem[(n,m)]
    ans = max([solve(n-1,m-1) + b[n-1] , solve(n-1,m)])
    mem[(n,m)] = ans
    return ans
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    b.clear()
    flip(a,f)
    for x in a:
        b.append(sum(x))
    mem.clear()
    ans = max([ans,solve(n,m)])
    flip(a,f)
print(ans)

### FIXED CODE ###

a = []
b = []
ans = 0
def flip(f):
    for i in range(len(a)):
        for j in range(3):
            if f & (1 << j) != 0:
                a[i][j] = - a[i][j]
n,m = map(int,input().split())
for i in range(n):
    a.append(list(map(int,input().split())))
for f in range(8):
    del(b[:])
    flip(f)
    for x in a:
        b.append(sum(x))
    b.sort(reverse = True)
    ans = max([ans,sum(b[:m])])
    flip(f)
print(ans)
n = int(input())
t, a = map(int, input().split())
list = list(map(input().split()))

count = t
result = 0

for i in range(n):
    test = t - list[i]*0.006
    if test >= a:
        if test-a <= count:
            count = test - a
            result = i
        else:
            pass
    else:
        if a-test <= count:
            count = a - test
            result = i
        else:
            pass
          
print(result)

### FIXED CODE ###

n = int(input())
t, a = map(int, input().split())
list_original = list(map(int, input().split()))

list = []

for i in range(n):
    temperature = t - list_original[i]*0.006
    list.append(abs(a - temperature))

point = list.index(min(list)) + 1

print(point)
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

total_price = ((k * X) + ((N - K) * Y))
print(total_price)

### FIXED CODE ###

N=int(input())
K=int(input())
X=int(input())
Y=int(input())
 
a=K
b=N-K
c=N
 
if b>0:
	print(a*X+b*Y)
else:
	print(c*X)
K, N = map(int, input().split())
A = list(map(int, input().split()))
longest = 0
for i in range(N):
  longest = max(longest, A[i + 1] - A[i])
longest = max(longest, A[0] + K - A[-1])
print(K - longest)

### FIXED CODE ###

K, N = map(int, input().split())
A = list(map(int, input().split()))
longest = 0
for i in range(N - 1):
  longest = max(longest, A[i + 1] - A[i])
longest = max(longest, A[0] + K - A[-1])
print(K - longest)
S = input()

N = len(S)

mod2019 = []
ans = 0

for _ in range(N+1):
  mod2019.append(0)


count = []
for _ in range(2019):
  count.append(0)



for i in range(1,N+1):
  Smod = mod2019[i-1] + int(S[N-i])*10**(i-1)
  mod2019.append(Smod%2019)
  count[Smod%2019] += 1


for i in range(2019):
  ans += ((count[i])*(count[i])-1))//2



print(ans)

### FIXED CODE ###

S = input()
counts =[0] * 2019
counts[0] = 1
num, d = 0,1

for s in S[::-1]:
  num += int(s) *d
  d *= 10
  num %= 2019
  d %= 2019
  counts[num] += 1

ans = 0
for count in counts:
  ans += count * (count - 1) //2
print(ans)
n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数

for a in range(9): #1文字目
  for b in range(9): #2文字目
    for c in range(9): #3文字目
      for i in range(n-3):
        if str(a) = s[i]:
          tmp_i = i + 1
          for j in range(tmp_i,n-2):
            if str(b) = s[j]:
              tmp_i = j + 1
              for k in range(tmp_i,n-1):
                if str(c) = s[k]:
                  cnt = cnt + 1
print(cnt)
 

### FIXED CODE ###

n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数

for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
      flg = False
      check_a = s.find(str(a))
      if check_a != -1:
        tmp_s = s[check_a + 1:]
        check_b = tmp_s.find(str(b))
        if check_b != -1:
          tmp_t = tmp_s[check_b + 1:]
          check_c = tmp_t.find(str(c))
          if check_c != -1:
            cnt = cnt + 1            
print(cnt)