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

N = int(input())
a = list(map(int, list(input())))
x = [max(a[i], a[i+1]) - min(a[i], a[i+1]) for i in range(N-1)]

def make_x(l):
	n = len(l)
	if n == 1:
		return l
	l2 = [l[0]]
	cnt = 1
	length = 1
	for i in range(1, n):
		if l[i] != l2[-1]:
			if cnt % 2 == 0:
				l2.append(l2[-1])
			cnt = 1
			l2.append(l[i])
			length += 1
		else:
			cnt += 1
	if length == 1:
		return [0]
	return l2

def next_x(l):
	n = len(l)
	return [max(l[i], l[i+1]) - min(l[i], l[i+1]) for i in range(n-1)]

f0,f1,f2 = False, False, False
for n in x:
	if n == 0:
		f0 = True
	elif n == 1:
		f1 = True
	else:
		f2 = True
	if f0 and f1 and f2:
		break

if f1:
	x = [n if n != 2 else 0 for n in x]
while len(x) > 1:
	x = make_x(next_x(x))
print(x[0])

### FIXED CODE ###

N = int(input())
a = list(map(int, list(input())))
t = [0 for i in range(N+1)]
i = 2
while i < N:
	for j in range(i, N+1, i):
		t[j] += 1
	i *= 2
sum_t = [0]
for i in range(1, N+1):
	sum_t.append(sum_t[-1] + t[i])

x = [max(a[i], a[i+1]) - min(a[i], a[i+1]) for i in range(N-1)]


def isCombOdd(n,k):
	bunshi = sum_t[n] - sum_t[n-k]
	bunbo = sum_t[k]
	return bunshi == bunbo

f1 = False
for n in x:
	if n == 1:
		f1 = True
		break
if f1:
	x = [n if n != 2 else 0 for n in x]

candidate = 1 if f1 else 2
ans = 0
for i in range(N-1):
	if x[i] > 0 and isCombOdd(N-2, i):
		ans = 1 - ans

print(0 if ans == 0 else candidate)
### BUGGY CODE ###

x = int(input())
N = len(str(x))
s = 0
while N != 0: 
    s =s +( x % 10) 
    N -= 1
    x = x // 10
if s % 9 == 0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

x = int(input())
N = str(x)
array = list(map(int, N))
if sum(array) % 9 == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
s = []
count = 0

for i in range(n):
    inp = sorted(input())
    s.append(inp)

for j in range(n - 1):
    for k in range(j + 1, n):
        if s[j] == s[k]:
            count += 1

print(count)

### FIXED CODE ###

from operator import itemgetter

n = int(input())
s = [sorted(input()) for _ in range(n)]

# 2次元配列の文字を、左から優先にソート
s_sort = sorted(s, key = itemgetter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

count = 0
s_count = 0

l = s_sort[0]

for i in range(1, n):
    if l == s_sort[i]:
        #同じ文字があるごとにカウントの数が増える（同じ文字が2つなら1個の組み合わせ、3つなら3つの組み合わせがある）
        s_count += 1
        count += s_count
    else:
        l = s_sort[i]
        s_count = 0

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

N,M = map(int,input().split())
edge_from = [set() for _ in range(N+1)]
edge_to = [set() for _ in range(N+1)]
ans = [-1]*(N+1)
child = set()
parent = -1
for _  in range(N-1+M):
    go,to = map(int,input().split())
    edge_from[go].add(to)
    edge_to[to].add(go)
    child.add(to)
for i in range(1,N+1):
    if i not in child:
        parent = i
from collections import deque
stack = deque()
stack.append(parent)
distance = [-1]*(N+1)
distance[parent] = 0
while stack:
    v = stack.popleft()
    for u in edge_from[v]:
        distance[u] = max(distance[v] + 1,distance[u])
        stack.append(u)
dis = [set() for _ in range(max(distance)+1)]
for i in range(1,N+1):
    dis[distance[i]].add(i)
for i in range(1,N+1):
    if i == parent :
        ans[i] = 0
    else:
        for j in dis[distance[i]-1]:
            if j in edge_to[i]:
                ans[i] = j
                break
for i in range(1,N+1):
    print(ans[i])           

### FIXED CODE ###

from collections import defaultdict, deque
import heapq
v, n = map(int, input().split())
es = [[int(x) for x in input().split()] for _ in range(v+n-1)]

outs = defaultdict(list)
ins = defaultdict(int)
edge_from = [[] for _ in range(v+1)]
edge_to = [[] for _ in range(v+1)]
ans = [-1]*(v+1)
for v1, v2 in es:
    edge_from[v1].append(v2)
    edge_to[v2].append(v1)
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
rev = [0]*(v+1)
for i in range(1,v+1):
    rev[res[i]] = i
redge_to = [[] for _ in range(v+1)]
for i in range(1,v+1):
    for j in edge_to[i]:
        ri = rev[i]
        rj = rev[j]
        heapq.heappush(redge_to[ri],-rj)
for ri in range(1,v+1):
    if redge_to[ri]:
        rj = redge_to[ri][0]
        i = res[ri]
        j = res[-rj]
        ans[i] = j
    else:
        i =res[ri]
        ans[i] = 0
for i in ans[1:]:
    print(i)
### BUGGY CODE ###

import numpy as np

# スペース区切りの整数入力
h,n = map(int, input().split())

#指定数分の2つの整数を順番に受けてリストに入力
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())

#下から順に最小の積み上げを作る
bsum = np.zeros(h+1)
for i in range(1,h+1):
    min_bsum = 9999999999999
    for atk in range(n):
        min_bsum = min(min_bsum,bsum[max(0,i-a[atk])]+b[atk])
    bsum[i] = min_bsum

#指定のHのコストを表示
print(int(bsum[h]))


### FIXED CODE ###

# スペース区切りの整数入力
h,n = map(int, input().split())

#指定数分の2つの整数を順番に受けてリストに入力
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())

#下から順に最小の積み上げを作る
bsum=[0]
for i in range(1,h+1):
    min_bsum = 9999999999999
    for atk in range(n):
        if bsum[max(0,i-a[atk])]+b[atk] < min_bsum:
            min_bsum = bsum[max(0,i-a[atk])]+b[atk]
    bsum.append(min_bsum)

#指定のHのコストを表示
print(bsum[h])
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    from itertools import combinations

    def prime_factorization_turple(n: int):
        """
        入力された整数nを素因数分解し，タプルを要素とするリストで返却
        Parameters
        ----------
        n : int
            素因数分解したい整数
        Returns
        -------
        prime_factorization_lst : lst
            [(素因数,累乗)]の形で素因数が列挙された素因数分解結果
        """
        fct = set()     # prime factor
        b, e = 2, 0  # base factor
        while b * b <= n:
            while n % b == 0:
                n //= b
                e += 1
            if e > 0:
                fct.add(b)
            b += 1
            e = 0
        if n > 1:
            fct.add(n)
        return fct

    _ = int(input())
    A = sorted([int(x) for x in input().split()])

    # Aの素因数分解
    fac_A = [prime_factorization_turple(a) for a in A]

    # pairwiseの判定
    pairwise_coprime = True
    for a, b in combinations(fac_A, 2):
        for i in a:
            if i in b:
                pairwise_coprime = False
                break
        if pairwise_coprime is False:
            break
    if pairwise_coprime:
        print('pairwise coprime')
        return

    # setwise
    setwise_coprime = True
    for b in fac_A[0]:
        cnt = 0
        for a in A:
            if a % b == 0:
                cnt += 1
        if cnt == len(A):
            setwise_coprime = False
            break

    if setwise_coprime:
        print('setwise coprime')
    else:
        print('not coprime')


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    from math import gcd

    N = int(input())
    A = []
    INF = 10 ** 6 + 5
    frequency = [0] * INF
    for a in [int(x) for x in input().split()]:
        A.append(a)
        frequency[a] += 1
    
    pairwise = True
    for i in range(2, INF):
        cnt = 0
        for j in range(i, INF, i):
            cnt += frequency[j]
        if cnt > 1:
            pairwise = False
    if pairwise:
        print("pairwise coprime")
        return

    g = 0
    for i in range(N):
        g = gcd(g, A[i])
        if g == 1:
            print('setwise coprime')
            return
    
    print('not coprime')


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

H, W, D = map(int, input().split())
position = {}

for h in range(H):
    L = list(map(int, input().split()))
    for w in range(W):
        position[L[w] - 1] = (h, w)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    if L == R:
        print(0)
        continue
    
    res = 0
    for i in range(L-1, R - 1, D):
        A = position[i + D]
        B = position[i]
        res += abs(A[0] - B[0]) + abs(A[1] - B[1])
        
    print(res)


### FIXED CODE ###

H, W, D = map(int, input().split())
position = {}

for h in range(H):
    L = list(map(int, input().split()))
    for w in range(W):
        position[L[w] - 1] = (h, w)

cost = [0] * (H * W)
for r in range(D):
    for j in range(r + D, H *W, D):
        A = position[j]
        B = position[j - D]
        cost[j] = cost[j - D] + abs(A[0] - B[0]) + abs(A[1] - B[1])

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(cost[R - 1] - cost[L - 1])
### BUGGY CODE ###

from sys import stdin

input = stdin.readline

m, *t = map(int, open(0).read().split())


def cal(d, c):

    if c == 1:
        return [0, d]
    t = 1 + (d + d >= 10)
    a = (d + d >= 10) + (d + d) % 10

    ca = cal(a, c // 2)

    if c % 2:
        return [(c // 2) * t + ca[0] + 1 + (ca[1] + d >= 10), (ca[1] + d >= 10) + (ca[1] + d) % 10]
    else:
        return [(c // 2) * t + ca[0], ca[1]]


ans = 0
now = []
for d, c in zip(*[iter(t)] * 2):
    ca = cal(d, c)
    ans += ca[0]
    now.append(ca[1])

pre = 0
for i in now:
    pre = pre + i
    ans += 1
    if pre >= 10:
        ans += 1
        pre = pre % 10 + 1

print(ans - 1)

### FIXED CODE ###

from sys import stdin

input = stdin.readline

m = int(input())
dc = []
for _ in range(m):
    d, c = map(int,input().split())
    dc.append((d, c))

def cal(d, c):
    if c == 1:
        return [0, d]
    t = 1 + (d + d >= 10)
    a = (d + d >= 10) + (d + d) % 10

    ca = cal(a, c // 2)

    if c % 2:
        return [(c // 2) * t + ca[0] + 1 + (ca[1] + d >= 10), (ca[1] + d >= 10) + (ca[1] + d) % 10]
    else:
        return [(c // 2) * t + ca[0], ca[1]]


ans = 0
now = []
for d, c in dc:
    ca = cal(d, c)
    ans += ca[0]
    now.append(ca[1])

pre = 0
for i in now:
    pre = pre + i
    ans += 1
    if pre >= 10:
        ans += 1
        pre = pre % 10 + 1

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

a=list(map(int,input()))
n=len(a)
ans=0
d=[0]*2019
d2=[0]*2019
d2[a[0]]+=1
for i in range(1,n):
    d[a[i]]+=1
    for j in range(2019):
        d[(10*j+a[i])%2019]+=d2[j]
    ans+=d[0]
    for j in range(2019):
        d2[j]=d[j]
        d[j]=0
print(ans)

### FIXED CODE ###

f=[0]*22209
def main():
    a=list(map(int,input()))
    n=len(a)
    ans=0
    d=[0]*2019
    d2=[0]*2019
    d2[a[0]]+=1
    for i in range(11):
        for j in range(2019):
            f[2019*i+j]=j
    for i in range(1,n):
        d[a[i]]+=1
        for j in range(2019):
            d[f[10*j+a[i]]]+=d2[j]
        ans+=d[0]
        for j in range(2019):
            d2[j]=d[j]
            d[j]=0
    print(ans)
main()
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
#print(a)

prev = 0
now = 1
for i in range(n - (k - 1)):
#    print(i)#
    if i ==0:
        for j in a[i: k + i]:
    #        print(j)#
            now *= j
    elif i >= 1:
#        print(a[i - 1], a[k+i-1]) #
#        print(prev,now)#
        now = (prev / a[i - 1]) * a[k+i-1]
#        print(prev,now)#
        if prev >= now:
            print("No")
        else:
            print("Yes")
    prev = now
    now = 1
#    print(prev,now)#

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
#print(a)

for i in range(n - (k - 1)):
    if i >=1:
        if a[i - 1] < a[k+i-1]:
            print("Yes")
        else:
            print("No")
### BUGGY CODE ###

class UnionFindBySize():
    def __init__(self, n):
        self.parents = list(range(n))
        self.size = [1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.size[x] < self.size[y]:
            self.size[y] += self.size[x]
            self.parents[x] = y
        else:
            self.size[x] += self.size[y]
            self.parents[y] = x

    # 全ての要素の親を求める
    def calc_parents(self):
        self.parents = [self.find(i) for i in self.parents]

    # 根を出力する
    def roots(self):
        self.calc_parents()
        return list(set(self.parents))

    # rootを親として持つ
    def groupcounts(self, root):
        self.calc_parents()
        return self.parents.count(root)


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

for i in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

groups = uf.roots()
counts = [uf.groupcounts(group) for group in groups]
print(max(counts))


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
n,m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a,b = map(int, input().split())
    uf.union(a-1, b-1)
ans = 0
roots = uf.roots()
cnt = []
for r in roots:
    cnt.append(uf.size(r))
cnt.sort(reverse=True)
ans = cnt[0]
print(ans)
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    prize = input()
    if prize in s:
        continue
    else:
        s.append(prize)
print(len(s))

### FIXED CODE ###

n = int(input())
s = set()
for i in range(n):
    s.add(input())
print(len(s))
### BUGGY CODE ###

n = int(input())
A = []
for _ in range(n):
    tmp = int(input())
    A.append(tmp)

for i in range(n):
    L = A.pop(0)
    print(max(A))
    A.append(L)

### FIXED CODE ###

n = int(input())
A = []
for _ in range(n):
    tmp = int(input())
    A.append(tmp)

m = max(A)
L = sorted(A)
L.sort(reverse = True)

if L[1] == m:
    for _ in range(n):
        print(m)
else:
    for i in range(n):
        if A[i] == m:
            A.pop(i)
            print(max(A))
            A.append(0)
        else:
            print(m)
### BUGGY CODE ###

S = input()
Q = int(input())
Qry = [input().split() for i in range(Q)]
for q in Qry:
    if q[0] == '1':
        S = S[::-1]
    else:
        if q[1] == '1':
            S = q[2] + S
        else:
            S += q[2]
print(S)


### FIXED CODE ###

S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])
### BUGGY CODE ###

import collections

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

c = collections.Counter(A)

for i in range(1,N+1):
    print(A.count(i))

### FIXED CODE ###

import collections

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

c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])
### BUGGY CODE ###

N = int(input())
d = sorted(list(map(int, input().split())))
res = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        tmp = d[i] + d[j]
        for k in range(j + 1, N):
            if tmp > d[k]:
                res = res + 1
            else:
                break
print(res)

### FIXED CODE ###

from bisect import bisect_left

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

L.sort()
result = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        result += bisect_left(L, L[i] + L[j]) - j - 1
print(result)
### BUGGY CODE ###

#coding:utf-8
import sys
N,K,C=map(int,input().split())
S=input()
S_R=S[::-1]
L=[0]*N
R=[0]*N
L_cnt=1
R_cnt=K
for i in range(N):
	if S[i]=="o" and L_cnt<=K:
		if L_cnt==1:
			L[i]=1
			L_cnt+=1
		elif i>(L.index(L_cnt-1)+C):
			L[i]=L_cnt
			L_cnt+=1
	if S_R[i]=="o" and R_cnt>=1:
		if R_cnt==K:
			R[N-1-i]=K
			R_cnt-=1
		elif (N-1-i)<(R.index(R_cnt+1)-C):
			R[N-1-i]=R_cnt
			R_cnt-=1	
result=[]
for i in range(N):
	if L[i]!=0 and R[i]!=0 and L[i]==R[i]:
		print(i+1)

### FIXED CODE ###

#coding:utf-8
import sys
N,K,C=map(int,input().split())
S=input()
S_R=S[::-1]
L=[]
R=[]
loop=0
cnt=0
while (loop<N):
	if S[loop]=="o":
		L.append(loop+1)
		cnt+=1
		loop+=C+1
	else:
		loop+=1
	if cnt>K:
		break
if cnt<K:
	exit()
loop=0
cnt=0

while (loop<N):
	if S_R[loop]=="o":
		R.append(N-loop)
		cnt+=1
		loop+=C+1
	else:
		loop+=1
	if cnt>K:
		break
if cnt<K:
	exit()

R=R[::-1]
for i in range(K):
	if L[i]==R[i]:
		print(L[i])
### BUGGY CODE ###

# coding: utf-8
# Your code here!
N=int(input())
l=[]

for i in range(N):
    l.append(i)
    
print(sum(l))


### FIXED CODE ###

# coding: utf-8
# Your code here!
N=int(input())
 
print(int(N*(N-1)//2))
### BUGGY CODE ###

N = int(input())
M = 0
m = 10**9
c = 0
for i in range(N):
  a,b = map(int,input().split())
  if m >= a:
    m = a
  if M < a:
    M = a
    c = b + 1
ans = c+M-m
for i in range(m-1):
  ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
M = 0
m = 10**9
c = 0
for i in range(N):
  a,b = map(int,input().split())
  if m >= a:
    m = a
  if M < a:
    M = a
    c = b + 1
ans = c+M-1
print(ans)
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    sum_val = 0
    for i in range(len(A)):
        for j in range(i + 1, len(A)):
            sum_val += (A[i] * A[j]) % (10**9 + 7)
    return sum_val % (10**9 + 7)

if __name__ == '__main__':
    print(main())

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    all_val = sum(A)
    A = A[::-1]

    sum_val = 0
    for i in range(len(A)):
        all_val -= A[i]
        sum_val += all_val * A[i] % (10**9 + 7)
    return sum_val % (10**9 + 7)

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

from math import ceil


def main():
    n = int(input())
    # if n % 2 == 0:
    #     print(n * (n // 2) + n // 2)
    # else:
    #     print(n * ceil(n / 2))
    t = 0
    for i in range(n):
        t += i
    print(t)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from math import ceil


def main():
    n = int(input()) - 1
    if n % 2 == 0:
        print(n * (n // 2) + n // 2)
    else:
        print(n * ceil(n / 2))


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

import itertools

n,k = map(int,input().split())

td = []
for i in range(n):
    td_tmp = list(map(int,input().split()))
    td.append(td_tmp)

# 貪欲で

td_comb = list(itertools.combinations(td, k))

ans = 0

for i in td_comb:
    tmp_ans = 0
    cnt = 0
    t_lst = []
    for j in i:
        tmp_ans += j[1]
        if j[0] not in t_lst:
            cnt += 1
            t_lst.append(j[0])
    tmp_ans += cnt**2
    ans = tmp_ans if tmp_ans>ans else ans

print(ans)

### FIXED CODE ###

N, K = map( int, input().split())
T = [(0,0)]*N
for i in range(N):
    t, d = map( int, input().split())
    T[i] = (d,t)
T.sort( key= None, reverse = True)
C = T[:K]
AC = T[K:]
kiso = 0
s = 0
S = [0]*(N+1)
for i in range(K):
    d, t = T[i]
    kiso += d
    if S[t] == 0:
        S[t] = 1
        s += 1
    else:
        S[t] += 1
ans = kiso + s**2
C.sort()
r = 0
 
for i in range(K):
    d, t = C[i]
    if S[t] >= 2:
        while r < N-K:
            if S[ AC[r][1]] == 0:
                S[t] -= 1
                S[ AC[r][1]] += 1
                s += 1
                kiso -= d
                kiso += AC[r][0]
                r += 1
                break
            r += 1
    ans = max( ans, kiso + s**2)
print( ans)
### BUGGY CODE ###

from collections import deque

S = list(input())

mod = [0] * (2019+1)

tmp = deque([])
for i in range(1, len(S)+1):
    tmp.appendleft(S[-i])
    mod[int("".join(tmp)) % 2019] += 1

ans = mod[0]
for i in range(1, 2020):
    if mod[i] >= 2:
        ans += (mod[i] * (mod[i]-1)) // 2
print(ans)

### FIXED CODE ###

S = input()

n_i_to_j_mod = [0] * (2019+1) # 2019で割った余りがiになるようなSの部分連続文字列の個数
i_to_end_mod = [0] * (len(S)+1) # S[-i:](Sの後方i文字)を2019で割ったときの余り

for i in range(1, len(S)+1):
    if i == 1:
        i_to_end_mod[1] = int(S[-1]) % 2019
    else:
        i_to_end_mod[i] = (i_to_end_mod[i-1] + int(S[-i]) * pow(10, i-1, 2019)) % 2019
    n_i_to_j_mod[i_to_end_mod[i]] += 1

ans = n_i_to_j_mod[0] + (n_i_to_j_mod[0] * (n_i_to_j_mod[0]-1))//2
for i in range(1, 2019):
    if n_i_to_j_mod[i] >= 2:
        ans += (n_i_to_j_mod[i] * (n_i_to_j_mod[i]-1)) // 2
print(ans)
### BUGGY CODE ###

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

base = 1

for ai in A[:K]:
  base *= ai

score = [0] * N
score[K-1] = base

for i in range(K, N):
  score[i] = score[i-1] // A[i-K] * A[i]
  print('Yes' if score[i] > score[i-1] else 'No')

### FIXED CODE ###

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

for i in range(N - K):
  score_2 = A[i+K]
  score_1 = A[i]
  print('Yes' if score_1 < score_2 else 'No')
### BUGGY CODE ###

N,M = [int(v) for v in input().split()]
ad_list = [[] for _ in range (N+1)]
ad_num = [0 for _ in range(N)]
topo = []

for _ in range(N-1+M):
    l,r = [int(v) for v in input().split()]
    ad_list[l].append(r)
    ad_num[r-1] += 1

for i in range(1,N+1):
    if ad_num[i-1] == 0:
        topo.append(i)
queue = topo[:]
topo = [[0,topo[0]]]
while queue:
    n1 = queue.pop(0)
    for n2 in ad_list[n1]:
        ad_num[n2-1] -= 1
        if ad_num[n2-1] == 0:
            topo.append([n1,n2])
            queue.append(n2)
topo.sort(key=lambda x:x[1])
for i,v in topo:
    print(i)
#  visited = [False for _ in range(N)]

#  ans = 0
#  path_len = 0
#  def dfs(node,cnt=1):
    #  global ans
    #  if visited[node-1]: return 0
    #  visited[node-1] = True
    #  ans = max(ans,cnt)
    #  for n in ad_list[node]:
        #  dfs(n,cnt+1)

#  for n in range(1,N+1):
    #  dfs(n)
#  print(ans)


### FIXED CODE ###

from collections import deque

N,M = [int(v) for v in input().split()]
ad_list = [[] for _ in range (N+1)]
ad_num = [0 for _ in range(N)]
topo = []

for _ in range(N-1+M):
    l,r = [int(v) for v in input().split()]
    ad_list[l].append(r)
    ad_num[r-1] += 1

for i in range(1,N+1):
    if ad_num[i-1] == 0:
        topo.append(i)
queue = deque(topo[:])
topo = [[0,topo[0]]]
while queue:
    n1 = queue.popleft()
    for n2 in ad_list[n1]:
        ad_num[n2-1] -= 1
        if ad_num[n2-1] == 0:
            topo.append([n1,n2])
            queue.append(n2)
topo.sort(key=lambda x:x[1])
for i,v in topo:
    print(i)
#  visited = [False for _ in range(N)]

#  ans = 0
#  path_len = 0
#  def dfs(node,cnt=1):
    #  global ans
    #  if visited[node-1]: return 0
    #  visited[node-1] = True
    #  ans = max(ans,cnt)
    #  for n in ad_list[node]:
        #  dfs(n,cnt+1)

#  for n in range(1,N+1):
    #  dfs(n)
#  print(ans)