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

N,MA,MB = map(int,raw_input().split())
src = []
sum_a = sum_b = 0
for i in range(N):
  a,b,c = map(int,raw_input().split())
  src.append((a,b,c))
  sum_a += a
  sum_b += b

INF = 10**9
dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  ai,bi,ci = src[i]
  for a in range(sum_a+1 - ai):
    for b in range(sum_b+1 - bi):
      dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)

ans = INF
n = 1
while True:
  a,b = n*MA,n*MB
  if a > sum_a or b > sum_b: break
  ans = min(ans, dp[N][a][b])
  n += 1

print(ans if ans != INF else -1)

### FIXED CODE ###

N,MA,MB = map(int,raw_input().split())
src = []
sum_a = sum_b = 0
for i in range(N):
  a,b,c = map(int,raw_input().split())
  src.append((a,b,c))
  sum_a += a
  sum_b += b

INF = 10**9
dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  ai,bi,ci = src[i]
  for a in range(sum_a+1 - ai):
    for b in range(sum_b+1 - bi):
      if dp[i][a][b] == INF: continue
      dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)

ans = INF
n = 1
while True:
  a,b = n*MA,n*MB
  if a > sum_a or b > sum_b: break
  ans = min(ans, dp[N][a][b])
  n += 1

print(ans if ans != INF else -1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    n, m, l = map(int, input().split())
    dist = [[float('inf')]*n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    dist2 = [[float('inf')]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j])


    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if dist2[s][t] == float('inf'):
            print(-1)
            continue
        ans = dist2[s][t]
        print(ans-1)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N, M, L = map(int, input().split())
    dist = [[float('inf')] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        if C > L:
            continue
        A -= 1
        B -= 1
        dist[A][B] = C
        dist[B][A] = C

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    e = [[float('inf')] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                e[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                e[i][j] = min(e[i][j], e[i][k] + e[k][j])


    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if e[s][t] == float('inf'):
            print(-1)
            continue
        ans = e[s][t]
        print(ans-1)


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

K=int(input())
ans=0

import math

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += math.gcd(i,math.gcd(j,k))

print(ans)

### FIXED CODE ###

K=int(input())
ans=0
 
import math
 
for i in range(1,K+1):
  for j in range(1,K+1):
    x = math.gcd(i,j)
    for k in range(1,K+1):
      ans += math.gcd(x,k)

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

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

MOD = 10 ** 9 + 7
N = int(input())

graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    x,y = map(int,input().split())
    graph[x].append(y)
    graph[y].append(x)

"""
包除の原理。各頂点を根として
・偶数個を選ぶ、そこが反例となっている、他は何でもよい、
・奇数個を選ぶ、そこが反例となっている、他は何でもよい
・根を含む成分は保留してある。保留している頂点の数を持っておく。
・偶数個の場合と奇数の場合の差分だけ持っておく
"""

def dp_merge(data1,data2):
    N1 = len(data1) - 1
    N2 = len(data2) - 1
    data = np.zeros(N1+N2, dtype = np.int64)
    for n in range(1,N1+1):
        data[n:n+N2] += data1[n] * data2[1:] % MOD
    data %= MOD
    return data

fact_2 = [1,0,1]
for n in range(3,N+10):
    fact_2.append(fact_2[n-2] * (n-1) % MOD)
fact_2 = np.array(fact_2, dtype = np.int64)

def dp_add_edge(data):
    N = len(data) - 1
    data1 = np.zeros(N+2, dtype=np.int64)
    # 辺を反例に加えない
    data1[1:] = data
    # 辺を反例に加える
    data1[1] = - (data * fact_2[:N+1] % MOD).sum() % MOD
    return data1

def dfs(v, parent = None):
    data = None
    for y in graph[v]:
        if y == parent:
            continue
        data1 = dfs(y, v)
        # mergeする前に、最後の辺をひとつ加える
        data1 = dp_add_edge(data1)
        if data is None:
            data = data1
        else:
            data = dp_merge(data, data1)
    if data is None:
        return np.array([0,1],dtype=np.int64)
    return data

data = dfs(1)

answer = (data * fact_2[:N+1] % MOD).sum() % MOD

print(answer)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7
N = int(input())

graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    x,y = map(int,input().split())
    graph[x].append(y)
    graph[y].append(x)

"""
包除の原理。各頂点を根として
・偶数個を選ぶ、そこが反例となっている、他は何でもよい、
・奇数個を選ぶ、そこが反例となっている、他は何でもよい
・根を含む成分は保留してある。保留している頂点の数を持っておく。
・偶数個の場合と奇数の場合の差分だけ持っておく
"""

def dp_merge(data1,data2):
    N1 = len(data1) - 1
    N2 = len(data2) - 1
    if N1 > N2:
        N1,N2 = N2,N1
        data1,data2 = data2,data1
    data = np.zeros(N1+N2, dtype = np.int64)
    for n in range(1,N1+1):
        data[n:n+N2] += data1[n] * data2[1:] % MOD
    data %= MOD
    return data

fact_2 = [1,0,1]
for n in range(3,N+10):
    fact_2.append(fact_2[n-2] * (n-1) % MOD)
fact_2 = np.array(fact_2, dtype = np.int64)

def dp_add_edge(data):
    N = len(data) - 1
    data1 = np.zeros(N+2, dtype=np.int64)
    # 辺を反例に加えない
    data1[1:] = data
    # 辺を反例に加える
    data1[1] = - (data * fact_2[:N+1] % MOD).sum() % MOD
    return data1

def dfs(v, parent = None):
    data = None
    for y in graph[v]:
        if y == parent:
            continue
        data1 = dfs(y, v)
        # mergeする前に、最後の辺をひとつ加える
        data1 = dp_add_edge(data1)
        if data is None:
            data = data1
        else:
            data = dp_merge(data, data1)
    if data is None:
        return np.array([0,1],dtype=np.int64)
    return data

data = dfs(1)

answer = (data * fact_2[:N+1] % MOD).sum() % MOD

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

n, k = map(int,input().split())
a = [int(i) for i in input().split()]
best = 0
for i in range(k+1):
    tmp = 0
    for num in a:
        tmp += i ^ num
        if best < tmp:
            best = tmp
print(best)

### FIXED CODE ###

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

# 最大値を取るf(x)のxを求める
# digitsは下位桁 < 上位桁で1になっているbitをカウントする
digits = [0] * 40
for i in range(40):
    for a in A:
        if (a >> i) & 1:
            digits[i] += 1

# Kを考慮してmax_xを求める方法がわからない
# 桁ごとに最適なbitはすでにわかっていて、他の桁のbitに影響を受けることはないので、
# 上位桁から見ていって、Kが1になっている部分ならフラグを立てる
# 上位桁から見てKが1のbitが出てから、K:1,max_x:0のフラグを立てたら、その桁より下位桁のbitはなんでもよくなる
check_K = True
max_x = 0
for i, d in enumerate(reversed(digits)):
    i = 40 - i - 1
    if check_K and K < pow(2, i):
        continue
    if d <= (N-d) and ((K >> i) & 1 == 1 or not check_K):
        max_x += 2 ** i
    elif (K >> i) & 1 == 1:
        check_K = False
    
#print(max_x)
ans = 0
for a in A:
    ans += a ^ max_x

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

import math
def get_prime(n):
    if n<=1:
      return []
    prime=[2]
    limit=int(math.sqrt(n))
    
    data=[i+1 for i in range(2,n,2)]
    while limit>data[0]:
      prime.append(data[0])
      
      data=[j for j in data if j % data[0]!=0]
      
    return prime+data

xx=get_prime(100000)

xxx=[False]*100001

for i in xx:
  xxx[i]=True

xxxx=[False]*100001

for i in xx:
  xxxx[i]=True

for i in range(1,100001):
  if xxx[i]==True:
    if xxxx[(i+1)//2]==False:
      xxx[i]=False

q=int(input())

for i in range(q):
  l,r=map(int,input().split())
  print(sum(xxx[:r+1])-sum(xxx[:l]))


### FIXED CODE ###

import math
import itertools

def get_prime(n):
    if n<=1:
      return []
    prime=[2]
    limit=int(math.sqrt(n))
    
    data=[i+1 for i in range(2,n,2)]
    while limit>data[0]:
      prime.append(data[0])
      
      data=[j for j in data if j % data[0]!=0]
      
    return prime+data

xx=get_prime(100000)

xxx=[False]*100001

for i in xx:
  xxx[i]=True

xxxx=[False]*100001

for i in xx:
  xxxx[i]=True

for i in range(1,100001):
  if xxx[i]==True:
    if xxxx[(i+1)//2]==False:
      xxx[i]=False

q=int(input())

for i in range(100001):
  if xxx[i]==True:
    xxx[i]=1
  else:
    xxx[i]=0
    
xxx=list(itertools.accumulate(xxx))
    

for i in range(q):
  l,r=map(int,input().split())
  print(xxx[r]-xxx[l-1])
### BUGGY CODE ###

import sys
import time

def main():
    N = int(input())
    As = list(map(int, input().split()))
    As.sort()
    made = As[-1]
    lis = [True for _ in range(made)]
    for i in range(len(As)):
        if As.count(As[i]) > 1:
            lis[As[i]-1] = False

    for i in As:
        for j in range(2, int(made/i)+1):
            if lis[i*j-1] == False:
                continue
            lis[i*j-1] = False
    answer = len([int(x) for x in As if lis[x-1]])
    

    print(answer)

if __name__ == '__main__':
    #start = time.time()
    main()
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

### FIXED CODE ###

#import time

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

    As.sort()
    amax = max(As) + 1
    lis = [True] * amax
    ans = 0

    for i in range(N-1):
        if lis[As[i]]:
            for j in range(As[i], amax, As[i]):
                lis[j] = False
            if As[i] < As[i+1]:
                ans += 1
    if lis[-1]:
        ans += 1

    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
### BUGGY CODE ###

def solve():
    N = int(input())
    Ass = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N)]

    day = 0
    numMatch = 0
    iAs = [0] * N
    while True:
        day += 1
    #    print('\n##### day:', day)
        useds = [0] * N
        for i in range(N):
            if useds[i] or iAs[i] == N-1: continue
            j = Ass[i][iAs[i]]
            if not useds[j] and Ass[j][iAs[j]] == i:
    #            print(i, j)
                useds[i] = useds[j] = 1
                iAs[i] += 1
                iAs[j] += 1
                numMatch += 1
        if numMatch >= N*(N-1)//2:
            print(day)
            break
        if not any(useds):
            print(-1)
            break


solve()


### FIXED CODE ###

def solve():
    N = int(input())
    Ass = []
    for _ in range(N):
        As = list(map(lambda x: int(x)-1, input().split()))
        Ass.append(As+[N])

    games = []
    numReadyss = [[0]*(N) for _ in range(N)]
    iAs = [0] * N
    for i in range(N):
        j = Ass[i][iAs[i]]
        if j > i: i, j = j, i
        numReadyss[i][j] += 1
        if numReadyss[i][j] >= 2:
            games.append((i, j))
    ans = 1
    numOK = 0
    while True:
        if not games:
            print(-1)
            return
        game2s = []
        for i, j in games:
            iAs[i] += 1
            i2 = Ass[i][iAs[i]]
            if i2 == N:
                numOK += 1
            else:
                if i2 > i: i, i2 = i2, i
                numReadyss[i][i2] += 1
                if numReadyss[i][i2] >= 2:
                    game2s.append((i, i2))
            iAs[j] += 1
            j2 = Ass[j][iAs[j]]
            if j2 == N:
                numOK += 1
            else:
                if j2 > j: j, j2 = j2, j
                numReadyss[j][j2] += 1
                if numReadyss[j][j2] >= 2:
                    game2s.append((j, j2))
        if numOK >= N:
            print(ans)
            return
        ans += 1
        games = game2s


solve()
### BUGGY CODE ###

n=int(input())
def prime_factorize(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f**2<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return(a)

import collections
A=collections.Counter(prime_factorize(n-1))
ans=1
cnt=0
for a,b in A.items():
    ans*=(b+1)

import math
for i in range(1,math.floor(n**0.5)+1):
    x=n
    if n%i==0:
        while x%i==0:
            x//=i   
        if (x-1)%i==0:
            cnt+=1
        if (i-1)%(n//i)==0:
            cnt+=1

print(ans-2+cnt)



### FIXED CODE ###

n=int(input())
def prime_factorize(n):
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f**2<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return(a)

import collections
A=collections.Counter(prime_factorize(n-1))
ans=1
cnt=0
for a,b in A.items():
    ans*=(b+1)

import math
li=[]
for i in range(2,math.floor(n**0.5)+1):
    if n%i==0:
        li.append(i)
        if i!=n//i:
            li.append(n//i)
li.append(n)
for i in li:
    x = n
    while x % i == 0:
        x //= i
    if x % i == 1:
        cnt += 1
print(ans - 1 + cnt)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

ans = 0
candidates = {}
cand_len = 0
for reversed_day in range(1, m + 1):
  if reversed_day in conditions.keys():
    candidates[reversed_day] = conditions[reversed_day]
    cand_len += 1

  if cand_len == 0:
    continue

  maxval, maxkey = 0, 0
  for key, cands in candidates.items():
    if cands[0] > maxval:
      maxval = cands[0]
      maxkey = key
  ans += candidates[maxkey].pop(0)
  if len(candidates[maxkey]) == 0:
    del candidates[maxkey]
    cand_len -= 1
print(ans)


### FIXED CODE ###


import collections
import heapq

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = collections.deque([])
for i in range(n):
  conditions.append([int(x) for x in input().split()])

conditions = sorted(conditions)

cnt, ans = 0, 0
candidates = []
for reversed_day in range(1, m + 1):
  while cnt < len(conditions) and conditions[cnt][0] <= reversed_day:
    heapq.heappush(candidates, -conditions[cnt][1])
    cnt += 1

  if len(candidates) == 0:
    continue
  ans -= heapq.heappop(candidates)

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

from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    A = {
        i: list(reversed([int(a) - 1 for a in input().split()]))
        for i in range(N)
    }

    Q = set(range(N))

    count = 0
    while True:
        pool = []
        for i in Q:
            ai = A[i]
            if len(ai) == 0:
                continue
            target = ai[-1]
            if target < i:
                continue
            target_q = A[target]
            if target_q[-1] == i:
                # print(i,target)
                pool.append(i)
                pool.append(target)

        if len(pool) == 0:
            if not all(len(a) == 0 for a in A.values()):
                print(-1)
                return
        # print("11111")
        for i in pool:
            A[i].pop()
            if len(A[i]) == 0:
                Q.remove(i)

        count += 1
        if all(len(a) == 0 for a in A.values()):
            print(count)
            return


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    A = {
        i: list(reversed([int(a) - 1 for a in input().split()]))
        for i in range(N)
    }

    Q = set(range(N))

    count = 0
    while True:
        pool = []
        for i in Q:
            ai = A[i]
            if len(ai) == 0:
                continue
            target = ai[-1]
            # if target < i:
            #     continue
            target_q = A[target]
            if target_q[-1] == i:
                # print(i,target)
                pool.append(i)
                pool.append(target)

        if len(pool) == 0:
            if len(Q) != 0:
                print(-1)
                return
            else:
                raise ValueError("test")

        qq = []
        for i in set(pool):
            A[i].pop()
            if len(A[i]) != 0:
                qq.append(i)
        Q = set(qq)

        count += 1
        if len(Q) == 0:
            print(count)
            return


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

M, N = map(int, input().split())
def fraction(N):
  a = N
  for x in range(N-1,1,-1):
    a *= x
  return a

p = abs(M - N)
if p < 2:
  print(fraction(M) * fraction(N) * (2 - p) % (1000000007))
else:
  print(0)
        

### FIXED CODE ###

M, N = map(int, input().split())
def fraction(N):
  a = N
  for x in range(N-1,1,-1):
    a = a * x % (1000000007)
  return a

p = abs(M - N)
if p < 2:
  print(fraction(M) * fraction(N) * (2 - p) % (1000000007))
else:
  print(0)
### BUGGY CODE ###

N=int(input())
s=list(map(int,input().split()))
for i in range(N):
    t,ans=[],0
    t+=s
    t.pop(i)
    t.insert(0,0)
    t.append(0)
    for k in range(N):
        ans+=abs(t[k]-t[k+1])
    print(ans)    
        

### FIXED CODE ###

N=int(input())
s=list(map(int,input().split()))
s.insert(0,0)
s.append(0)
ans=0
for k in range(N+1):
    ans+=abs(s[k]-s[k+1])
for i in range(N):
    a,b,c=s[i]-s[i+1],s[i+1]-s[i+2],s[i]-s[i+2]
    if a*b>=0:
        print(ans)
    else:
        print(ans-abs(a)-abs(b)+abs(c))
### BUGGY CODE ###

n,t=map(int,input().split())
a=input().split()
for i in range(n):
    a[i]=int(a[i])

def calc(a,i):
    x=a[i]
    if i==len(a)-1:return 0
    else:
        nokori=a[i+1:]
        return max(nokori)-x

saidai=0
count=0
for i in range(n):
    ans=calc(a,i)
    if saidai<ans:
        saidai=ans
        count=1
    elif saidai==ans:count+=1
    
print(count)

### FIXED CODE ###

n,t=map(int,input().split())
a=list(map(int,input().split()))
saisyo=a[0]
saidai=0
count=0
for i in range(n):
    if a[i]<saisyo:saisyo=a[i]
    else:
        if a[i]-saisyo>saidai:
            saidai=a[i]-saisyo
            count=1
        elif a[i]-saisyo==saidai:
            count+=1
print(count)
### BUGGY CODE ###

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

ans = [A[0]]
for i in range(1, N):
    tmp = (-1, -1)
    for j in range(len(ans)):
        if ans[j] < A[i] and ans[j] > tmp[1]:
            tmp = (j, ans[j])

    if tmp[0] >= 0:
        ans[tmp[0]] = A[i]
    else:
        ans.append(A[i])

print(len(ans))


### FIXED CODE ###

import bisect
from collections import deque

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

ans = deque([A[0]])
for i in range(1, N):
    index = bisect.bisect_left(ans, A[i])
    if index > 0:
        ans[index - 1] = A[i]
    else:
        ans.appendleft(A[i])

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

N = int(input())
A = []

for i in range(N):
  tmp = int(input())
  if tmp not in A:
    A.append(tmp)
  else:
    A.remove(tmp)
    
print(len(A))



### FIXED CODE ###

from collections import Counter
N = int(input())
A = []

for i in range(N):
  tmp = int(input())
  A.append(tmp) 
B = Counter(A).values()
cnt = 0
for i in B:
  if i % 2 != 0:
    cnt += 1
  
print(cnt)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
from heapq import heappop,heappush
def dijkstra(s, n, edge):
  inf = 10**20
  ans = [inf]*n
  ans[s] = 0
  root = [-1]*n
  h = [[0, s]]
  while h:
    c, v = heappop(h)
    if ans[v] < c:
      continue
    for u, t in edge[v]:
      if c+t < ans[u]:
        ans[u] = c+t
        root[u] = v
        heappush(h, [c+t, u])
  return ans
h,w=map(int,input().split())
hw=lambda hh,ww:hh*w+ww
ch,cw=map(int,input().split())
s=hw(ch-1,cw-1)
dh,dw=map(int,input().split())
g=hw(dh-1,dw-1)
b=[list(input())for _ in range(h)]
edge=[[]for _ in range(h*w)]
for i in range(h):
  for j in range(w):
    if b[i][j]=="#":continue
    if i!=h-1:
      if b[i+1][j]==".":
        edge[hw(i,j)].append((hw(i+1,j),0))
        edge[hw(i+1,j)].append((hw(i,j),0))
    if j!=w-1:
      if b[i][j+1]==".":
        edge[hw(i,j)].append((hw(i,j+1),0))
        edge[hw(i,j+1)].append((hw(i,j),0))
    for ii in range(max(0,i-2),min(h,i+3)):
      for jj in range(max(0,j-2),min(w,j+3)):
        if i==ii and j==jj:continue
        if b[ii][jj]==".":
          edge[hw(i,j)].append((hw(ii,jj),1))
ans=dijkstra(s,h*w,edge)[g]
if ans==10**20:ans=-1
print(ans)

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
h,w=map(int,input().split())
ch,cw=map(int,input().split())
ch-=1
cw-=1
stack=[(ch,cw)]
dh,dw=map(int,input().split())
dh-=1
dw-=1
b=[w*[-1]for _ in range(h)]
for i in range(h):
  for j,t in enumerate(input()):
    if t=="#":b[i][j]=10**10
b[ch][cw]=0
dxy=((-1,0),(1,0),(0,-1),(0,1))
for ans in range(10**6):
  for x,y in stack:
    b[x][y]=1
    if x==dh and y==dw:
      print(ans)
      exit()
    for dx,dy in dxy:
      if 0<=x+dx<h and 0<=y+dy<w:
        if b[x+dx][y+dy]==10**10:continue
        if b[x+dx][y+dy]==-1:
          stack.append((x+dx,y+dy))
          b[x+dx][y+dy]=1
  stackk=[]
  for x,y in stack:
    for xx in range(max(0,x-2),min(h,x+3)):
      for yy in range(max(0,y-2),min(w,y+3)):
        if b[xx][yy]==-1:stackk.append((xx,yy))
  stack=stackk
print(-1)
### BUGGY CODE ###

n, c = map(int, input().split())
cnt = [[0 for _ in range(c)] for j in range(10 ** 5 + 1)]
cnt_sum = [0] * (10 ** 5 + 1)
for _ in range(n):
    s, t, _c = map(int, input().split())
    cnt[s - 1][_c - 1] += 1
    cnt[t][_c - 1] -= 1
for i in range(1, 10 ** 5 + 1):
    for j in range(c):
        cnt[i][j] += cnt[i - 1][j]
for i in range(10 ** 5 + 1):
    for j in range(c):
        cnt_sum[i] += (cnt[i][j] >= 1)
print(max(cnt_sum))

### FIXED CODE ###

n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

for _ in range(n):
    s, t, _c = map(int, input().split())
    for j in range(s, t + 1):
        cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
    ans = max(ans, sum(cnt[j][i] for j in range(c)))
print(ans)
### BUGGY CODE ###

n = int(input())

ans = 0

for i in range(1,n+1):
    for j in range(1,int(i**0.5)+1):
        if i%j == 0:
            ans += i
            if j**2 == i:
                continue
            ans += i

print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N + 1):
    n = N // i  # 項数n
    cnt = (n * (2 * i + (n - 1) * i)) // 2  # 初項i, 項数n の等差数列の和の公式
    ans += cnt
print(ans)