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

N, K, L = [int(_) for _ in input().split()]
memo = [[i, i] for i in range(N + 1)]

for _ in range(K):
    p, q = [int(_) for _ in input().split()]
    memo[p][0] = min(memo[p][0], memo[q][0])
    memo[q][0] = memo[p][0]
for _ in range(L):
    r, s = [int(_) for _ in input().split()]
    memo[r][1] = min(memo[r][1], memo[s][1])
    memo[s][1] = memo[r][1]


def dfs0(i):
    if i == memo[i][0]:
        return i
    else:
        memo[i][0] = dfs0(memo[i][0])
        return memo[i][0]


def dfs1(i):
    if i == memo[i][1]:
        return i
    else:
        memo[i][1] = dfs1(memo[i][1])
        return memo[i][1]


for i in range(1, N + 1):
    memo[i][0] = dfs0(i)
    memo[i][1] = dfs1(i)
count = [[0] * N for _ in range(N)]
for i in range(1, N + 1):
    count[memo[i][0] - 1][memo[i][1] - 1] += 1
print(' '.join(str(count[memo[i][0]-1][memo[i][1]-1])
               for i in range(1, N + 1)))


### FIXED CODE ###

class UFT():
    def __init__(self):
        self.par = {}
        self.rank = {}

    def find(self, x):
        if self.par.get(x, x) == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        self.rank[x] = self.rank.get(x, 0)
        self.rank[y] = self.rank.get(y, 0)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, K, L = [int(_) for _ in input().split()]

Road = UFT()
for _ in range(K):
    p, q = [int(_) for _ in input().split()]
    Road.unite(p, q)
Railway = UFT()
for _ in range(L):
    r, s = [int(_) for _ in input().split()]
    Railway.unite(r, s)
memo = {}
for i in range(1, N + 1):
    memo[Road.find(i), Railway.find(i)] = memo.get((Road.find(i), Railway.find(i)), 0) + 1
print(' '.join(str(memo[Road.find(i), Railway.find(i)]) for i in range(1, N + 1)))
### BUGGY CODE ###

N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[0],reverse=True)
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
while count < N:
  for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
      ans = "No"
      break
    else:
      count += 1
      ans = "Yes"
print(ans)


### FIXED CODE ###

N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
ans = "Yes"

for i in range(N):
  time += AB[i][0]
  if time > AB[i][1]:
    ans = "No"
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
dp = [[[0]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
I,J,K = 0,0,0
for i in a:
  if i == 1:
    I += 1
  elif i == 2:
    J += 1
  else:
    K += 1 
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if (i+j+k) <= n:
        if (i+j+k) != 0:
          dp[i][j][k] = n/(i+j+k)
        if i > 0:
          dp[i][j][k] += dp[i-1][j][k]*i / (i+j+k)
        if j > 0:
          dp[i][j][k] += dp[i+1][j-1][k]*j / (i+j+k)
        if k > 0:
          dp[i][j][k] += dp[i][j+1][k-1]*k / (i+j+k)
print(dp[I][J][K])

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
dp = [[[float(0)]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
I,J,K = 0,0,0
for i in a:
  if i == 1:
    I += 1
  elif i == 2:
    J += 1
  else:
    K += 1
for k in range(n+1):
  for j in range(n+1):
    for i in range(n+1):
      if (i+j+k) <= n:
        if (i+j+k) != 0:
          dp[i][j][k] = float(n)/float(i+j+k)
        if i > 0:
          dp[i][j][k] += dp[i-1][j][k]*float(i) / float(i+j+k)
        if j > 0:
          dp[i][j][k] += dp[i+1][j-1][k]*float(j) / float(i+j+k)
        if k > 0:
          dp[i][j][k] += dp[i][j+1][k-1]*float(k) / float(i+j+k)
print(dp[I][J][K])
### BUGGY CODE ###

H,W = list(map(int,input().split()))
A = [list(str(input())) for i in range(H)]

white = []
black = []

cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            black.append([i,j])

length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
        if l[1] != 0:
            c1 = [l[0],l[1]-1]
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] = "#"
        if l[1] != W-1:
            c2 = [l[0],l[1]+1]
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] = "#"
        if l[0] != 0:
            c3 = [l[0]-1,l[1]]
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] = "#"
        if l[0] != H-1:
            c4 = [l[0]+1,l[1]]
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] = "#"
    
    gray = list(map(list, set(map(tuple, gray))))
    black = [l for l in gray]
    
    cnt += 1
    length += len(black)
    
print(cnt)

### FIXED CODE ###

H,W = list(map(int,input().split()))
A = [list(str(input())) for i in range(H)]
 
black = []
 
cnt = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            black.append([i,j])
 
length = len(black)
            
while (length < H*W):
    gray = []
    for l in black:
        if l[1] != 0:
            c1 = (l[0],l[1]-1)
            if A[c1[0]][c1[1]] == ".":
                gray.append(c1)
                A[c1[0]][c1[1]] = "#"
        if l[1] != W-1:
            c2 = (l[0],l[1]+1)
            if  A[c2[0]][c2[1]] == ".":
                gray.append(c2)
                A[c2[0]][c2[1]] = "#"
        if l[0] != 0:
            c3 = (l[0]-1,l[1])
            if  A[c3[0]][c3[1]] == ".":
                gray.append(c3)
                A[c3[0]][c3[1]] = "#"
        if l[0] != H-1:
            c4 = (l[0]+1,l[1])
            if  A[c4[0]][c4[1]] == ".":
                gray.append(c4)
                A[c4[0]][c4[1]] = "#"
    
    gray = list(set(gray))
    black = [l for l in gray]
    
    cnt += 1
    length += len(black)
    
print(cnt)
### BUGGY CODE ###

import heapq

N, M, S = map(int, input().split())
Map = [[] for _ in range(N)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    Map[u].append((v, a, b))
    Map[v].append((u, a, b))

Exchange = [tuple(map(int, input().split())) for _ in range(N)]

Q = []
heapq.heappush(Q, (0, 0, S)) # 今の時間、場所、持っているお金
Ans = [-1] * N
Ans[0] = 0
while -1 in Ans:
    time, where, money = heapq.heappop(Q)
    if Ans[where] == -1:
        Ans[where] = time
    for nex, cost, take in Map[where]:
        if cost > money:
            continue
        heapq.heappush(Q, (time + take, nex, money - cost))
    heapq.heappush(Q, (time + Exchange[where][1], where, money + Exchange[where][0]))


for a in Ans[1:]:
    print(a)

### FIXED CODE ###

import heapq

N, M, S = map(int, input().split())
Map = [[] for _ in range(N)]
Ans = [[float('inf')] * 2500 for _ in range(N)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    Map[u].append((v, a, b))
    Map[v].append((u, a, b))

for i in range(N):
    c, d = map(int, input().split())
    Map[i].append((i, -c, d))

Q = []
heapq.heappush(Q, (0, 0, min(2499, S))) # 今の時間、場所、持っているお金
Ans[0][min(2499, S)] = 0
while Q:
    time, where, money = heapq.heappop(Q)
    for nex, cost, take in Map[where]:
        if cost > money:
            continue
        if Ans[nex][min(2499, money - cost)] > time + take:
            Ans[nex][min(2499, money - cost)] = time + take
            heapq.heappush(Q, (time + take, nex, money - cost))

for a in Ans[1:]:
    print(min(a))
### BUGGY CODE ###

n,m,s,t = map(int,input().split())
en = []
su = []
for i in range(m):
    x1,y1,z1,a1=[int(i) for i in input().split()]
    en.append([x1-1,y1-1,z1])
    su.append([x1-1,y1-1,a1])
def shortest_path(edge,num_v,start):
    inf = float("inf")
    d = [inf for f in range(num_v)]
    d[start] = 0;
    while True:
        update = False
        for e in edge:
            if d[e[0]] != inf and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                update = True
            elif d[e[1]] != inf and d[e[0]] > d[e[1]] + e[2]:
                d[e[0]] = d[e[1]] + e[2]
                update = True
        if not update:
            break
    return d
from collections import deque
ans = deque([])
tori = shortest_path(en,n,s-1)
kae = shortest_path(su,n,t-1)
sai = float("inf")
for i in range(n-1,-1,-1):
  kon = kae[i]+tori[i]
  if sai > kon:
     ans.appendleft(kon)
     sai = kon
  else:
    ans.appendleft(sai)
    
moti = 10**15
for i in range(n):
  print(moti-ans[i])

### FIXED CODE ###

import heapq
n,m,s,t = map(int,input().split())
en = []
su = []
for i in range(m):
    x1,y1,z1,a1=[int(i) for i in input().split()]
    en.append([x1-1,y1-1,z1])
    su.append([x1-1,y1-1,a1])
def shortest_path(edge,num_v,start):
    inf = float("inf")
    cost = [[] for i in range(n+1)]
    for path in edge:
      cost[path[0]].append((path[1],path[2]))
      cost[path[1]].append((path[0],path[2]))
    d = [inf for j in range(num_v)]
    q = []
    heapq.heappush(q, (0, start))
    d[start] = 0
    while len(q) != 0:
      prov_cost, src = heapq.heappop(q)
      if d[src] < prov_cost:
                continue
      for dest,weight in cost[src]:
        if weight != float('inf') and d[dest] > d[src] + weight:
          d[dest] = d[src] + weight
          heapq.heappush(q, (d[dest], dest))
    return d
 
 
from collections import deque
ans = deque([])
tori = shortest_path(en,n,s-1)
kae = shortest_path(su,n,t-1)
sai = float("inf")
for i in range(n-1,-1,-1):
  kon = kae[i]+tori[i]
  if sai > kon:
     ans.appendleft(kon)
     sai = kon
  else:
    ans.appendleft(sai)
    
moti = 10**15
for i in range(n):
  print(moti-ans[i])
### BUGGY CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
q=int(input())
query=[input().split() for i in range(q)]
# print(query)
now=0
for i in range(q):
    if query[i][0]=="1":
        now+=1
    else:
        if now%2==0:
            if query[i][1]=="1":
                s=query[i][2]+s
            else:
                s=s+query[i][2]
        else:
            if query[i][1]=="1":
                s=s+query[i][2]
            else:
                s=query[i][2]+s
if now%2==1:
    s=s[::-1]
print(s)

### FIXED CODE ###

import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
q=int(input())
query=[input().split() for i in range(q)]
now=0
d=deque(s)
# print(d)
for i in range(q):
    if query[i][0]=="1":
        now+=1
    else:
        if now%2==0:
            if query[i][1]=="1":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
        else:
            if query[i][1]=="1":
                d.append(query[i][2])
            else:
                d.appendleft(query[i][2])
if now%2==1:
    d.reverse()
print("".join(d))
### BUGGY CODE ###

import sys
from collections import namedtuple
from heapq import heappush, heappop

INF = sys.maxsize

P = namedtuple('P', 'cost v')
Edge = namedtuple('Edge', 'cost to')
X = namedtuple('X', 'x i')
Y = namedtuple('Y', 'y i')

N = int(input())

G = [[] for _ in range(N)]
xg = []
yg = []

for i in range(N):
  x, y = map(int, input().split())
  xg.append(X(x, i))
  yg.append(Y(y, i))

xg.sort()
yg.sort()

for i in range(N - 1):
  x1, a = xg[i]
  x2, b = xg[i + 1]
  G[a].append(Edge(abs(x1 - x2), b))
  G[b].append(Edge(abs(x1 - x2), a))

for i in range(N - 1):
  y1, a = yg[i]
  y2, b = yg[i + 1]
  G[a].append(Edge(abs(y1 - y2), b))
  G[b].append(Edge(abs(y1 - y2), a))

total = 0
costs = [INF] * N
costs[0] = 0  # 集合Xからの最短距離
used = set()

q = [P(0, 0)]

while q: 
  p = heappop(q)

  if p.v in used and p.cost >= costs[p.v]:
    continue

  costs[p.v] = 0
  total += p.cost
  used.add(p.v)

  for cost, to in G[p.v]:
    if costs[to] > costs[p.v] + cost:
      costs[to] = costs[p.v] + cost
      heappush(q, P(costs[to], to))

print(total)


### FIXED CODE ###

from collections import namedtuple


class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n + 1)]
    self.size = [1] * (n + 1)

  def is_same(self, a, b):
    return self.find(a) == self.find(b)

  def unite(self, a, b):
    a = self.find(a)
    b = self.find(b)  
    if self.size[a] < self.size[b]:
      a, b = b, a
    self.par[b] = a
    self.size[a] += self.size[b]

  def size_of(self, a):
    return self.size[self.find(a)]

  def find(self, a):
    if a == self.par[a]:
      return a
    self.par[a] = self.find(self.par[a])
    return self.par[a]

Edge = namedtuple('Edge', 'w s t')
X = namedtuple('X', 'x i')
Y = namedtuple('Y', 'y i')

N = int(input())

edges = []
xg = []
yg = []

for i in range(N):
  x, y = map(int, input().split())
  xg.append(X(x, i))
  yg.append(Y(y, i))

xg.sort()
yg.sort()

for i in range(N - 1):
  x1, a = xg[i]
  x2, b = xg[i + 1]
  edges.append(Edge(abs(x1 - x2), a, b))

for i in range(N - 1):
  y1, a = yg[i]
  y2, b = yg[i + 1]
  edges.append(Edge(abs(y1 - y2), a, b))

edges.sort()

u = UnionFind(N)
cost = 0

for w, s, t in edges:
  if u.is_same(s, t):
    continue
  u.unite(s, t)
  cost += w

print(cost)
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]

Point = []
Result = []

for i in range(N):
    Point.append(A.count(i+1))

for i in range(N):
    Point[i] = K - (Q - Point[i])

for i in range(N):
    if Point[i] > 0:
        Result.append("Yes")
    else:
        Result.append("No")

for i in range(N):
    print(Result[i])


### FIXED CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
A = sorted(A)
Acount = 0
j = 0

Point = []

for i in range(N):

    while j != len(A):
        if A[j] == i + 1:
            Acount += 1
            j +=1
        else:
            break

    Point.append(K - Q + Acount)

    Acount = 0

    if Point[i] > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
players = [K]*N
for i in range(Q):
	for j in range(N):
		if A[i]!=j+1:
			players[j]-=1
for p in players:
	if p<1:print("No")
	else:print("Yes")


### FIXED CODE ###

n, k, q = map(int, input().split())
point = [0 for i in range(n)]
for i in range(q):
    point[int(input())-1] -= 1
for i in range(n):
    if q + point[i] < k:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N=int(input())
P=list(map(int,input().split()))
count=0
flag=True
for i in range(N):
    for k in range(i):
        if P[i]>P[k]:
            flag=False
    if flag:
        count+=1
    else:
        flag=True
print(count)

### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
count=1
min=P[0]
for i in range(1,N):
    if min>P[i]:
      count+=1
      min=P[i]
print(count)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans, m = 0, int(1e9+7)
for i in range(n-1):
    ans = (ans + a[i]*sum(a[i+1:])) % m
print(ans)


### FIXED CODE ###

n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(1, n+1):  a[i] += a[i-1]
ans, m = 0, int(1e9+7)
for i in range(1, n):
    ans = (ans + (a[i]-a[i-1])*(a[n]-a[i])) % m

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

L, R = list(map(int,input().split()))

minimum = L * R
for i in range(L, R):
    for j in range(i+1, R+1):
        minimum = min(minimum, i * j % 2019)

print(minimum)

### FIXED CODE ###

L, R = list(map(int,input().split()))

minimum = L * R
for i in range(L, min(R, L+2020)):
    for j in range(i+1, min(R+1, i+2021)):
        
        minimum = min(minimum, i * j % 2019)
        

print(minimum)
### BUGGY CODE ###

import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n ,k = I2()
    h = [I() for _ in range(n)]
    h.sort()
    ans = float("inf")
    for i in range(n-k+1):
        l = h[i:i+k]
        #print(l)
        ans = min(ans,l[-1]-l[0])
    print(ans)

### FIXED CODE ###

import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n ,k = I2()
    h = [I() for _ in range(n)]
    h.sort()
    ans = float("inf")
    for i in range(n-k+1):
        a,b = h[i],h[i+k-1]
        #print(a,b)
        ans = min(ans,b-a)
    print(ans)
### BUGGY CODE ###

n = int(input())
d = [[] for i in range(n)]
for i in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    if u > v:
        d[u].append(v)
    else:
        d[v].append(u)
ans = 0
for l in range(n):
    ans += (l + 1) * (l + 2) // 2
    for r in range(l, n):
        for t in d[r]:
            if l <= t:
                ans -= (n - r)
print(ans)


### FIXED CODE ###

n = int(input())
d = [0] * n
present = [[] for i in range(n)]
for i in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    if u > v:
        u, v = v, u
    d[v] += 1
    present[u].append(v)
ans = 0
cur = 0
for v in range(n):
    cur += (n - v) * d[v]
for l in range(n):
    ans += (l + 1) * (l + 2) // 2
    ans -= cur
    for v in present[l]:
        cur -= (n - v)
print(ans)
### BUGGY CODE ###

"https://codeforces.com/contest/1328/problem/A"
import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs  = lambda: input()
ri  = lambda: int(input())
rm  = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]

from functools import reduce

def solve():
    N = ri()
    ans = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            if i%j == 0:
                ans += i
    return ans
print(solve())

### FIXED CODE ###

import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs  = lambda: input()
ri  = lambda: int(input())
rm  = lambda: map(int, input().split())
rai = lambda: [int(x) for x in input().split()]

def solve():
    N = ri()
    ans = 0
    for i in range(1, N + 1):
        n = N // i
        ans += i * n * (n + 1) // 2
    return ans
print(solve())
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int,input().split())) for i in range(n)]

xcal = [[0]*n for i in range(1<<n)]
ycal = [[0]*n for i in range(1<<n)]

for i in range(1<<n):
    for j in range(n):
        xcal[i][j] = abs(l[j][0])
        ycal[i][j] = abs(l[j][1])
        for k in range(n):
            if (i>>k) & 1:
                xcal[i][j] = min(xcal[i][j],abs(l[j][0]-l[k][0]))
                ycal[i][j] = min(ycal[i][j],abs(l[j][1]-l[k][1]))
        
ans = [float("INF")]*(n+1)

for i in range(1<<n):
    count = 0
    for j in range(n):
        if i >> j & 1:
            count += 1
    for j in range(i,-1,-1):
        j &= i
        cost = 0
        for k in range(n):
            if not (i>>k & 1):
                cost += min(xcal[j][k],ycal[i-j][k])*l[k][2]
        ans[count] = min(ans[count],cost)

for i in ans:
    print(i)

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    n = int(input())
    l = [list(map(int,input().split())) for i in range(n)]

    xcal = [[0]*n for i in range(1<<n)]
    ycal = [[0]*n for i in range(1<<n)]

    for i in range(1<<n):
        for j in range(n):
            xcal[i][j] = abs(l[j][0])
            ycal[i][j] = abs(l[j][1])
            for k in range(n):
                if (i>>k) & 1:
                    xcal[i][j] = min(xcal[i][j],abs(l[j][0]-l[k][0]))
                    ycal[i][j] = min(ycal[i][j],abs(l[j][1]-l[k][1]))
            xcal[i][j] *= l[j][2]
            ycal[i][j] *= l[j][2]
    ans = [float("INF")]*(n+1)

    for i in range(1<<n):
        count = 0
        for j in range(n):
            if i >> j & 1:
                count += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(n):
                if not (i>>k & 1):
                    cost += min(xcal[j][k],ycal[i-j][k])
                if cost > ans[count]:
                    break
            ans[count] = min(ans[count],cost)
            j -= 1

    for i in ans:
        print(i)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

S = input()

ans = 0
lists = [0 for i in range(2019)]
lists[0] += 1

for i in range(len(S)):
    lists[int(S[i:]) % 2019] += 1

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

print(ans)

### FIXED CODE ###

S = input()

ans = 0
lists = [0 for i in range(2019)]
lists[0] += 1

num = 0
for i in range(len(S) - 1, -1, -1):
    num += pow(10, len(S) - 1 - i, 2019) * int(S[i])
    lists[num % 2019] += 1

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

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

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

if a == b and b == c:
    ans = 0
else:
    dp = [a, b, c]
    for i in range(k):
        if abs(dp[0] - dp[1]) > 10 ** 18:
            ans = 'Unfair'
            break
        else:
            dp[0], dp[1], dp[2] = dp[1] + dp[2], dp[0] + dp[2], dp[0] + dp[1]
    else:
        ans = dp[0] - dp[1]

print(ans)

### FIXED CODE ###

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

if a == b and b == c:
    ans = 0
elif a - b > 10 ** 18:
    ans = 'Unfair'
else:
    if k % 2 == 0:
        ans = a - b
    else:
        ans = b - a
print(ans)
### BUGGY CODE ###

import math

K = int(input())
if K % 2 == 0:
    print(-1)
else:
    a = 9 * K + 7
    def ok(n):
        return 63 * 10 ** n >= a
    left = 1
    right = 10 ** 9
    while right - left > 1:
        mid = (right + left) // 2
        if ok(mid):
            right = mid
        else:
            left = mid
    print(right - 1)


### FIXED CODE ###

K = int(input())
res = 1
mod = 7
for i in range(K):
    if mod % K == 0:
        print(res)
        break
    res += 1
    mod = (mod * 10 + 7) % K
else:
    print(-1)
### BUGGY CODE ###

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

dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[int(s)]] < int(str(dp[i])+s):
            dp[i + l[int(s)]] = int(str(dp[i])+s)
            

print(dp[N])


                





### FIXED CODE ###

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

dp = [-1 for i in range(N+10)]
l = [0,2,5,5,4,5,6,3,7,6]
dp[0] = 0
for i in range(N-1):
    for s in A:
        if dp[i] == -1 and i!=0:
            continue
        if dp[i + l[s]] < dp[i]*10+s:
            dp[i + l[s]] = dp[i]*10+s
print(dp[N])