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

N, M = map(int, input().split())
AB = []

for i in range(N):
  ab = list(map(int, input().split()))
  #Ai > M の仕事はいらない
  if ab[0] <= M:
    AB.append(ab)

#最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ...
#終わりから考えればよさそう
AB.sort()
q = []
ans = 0
for i in range(1, M + 1):
  while len(AB) > 0 and AB[0][0] <= i:
    q.append(AB.pop(0)[1])
  if len(q) > 0:
    m = max(q)
    q.remove(m)
    ans += m

print(ans)

### FIXED CODE ###

from heapq import heappush, heappop

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

for i in range(N):
  ab = list(map(int, input().split()))
  #Ai > M の仕事はいらない
  if ab[0] <= M:
    jobs[ab[0] - 1].append(ab[1])

#最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ...
#終わりから考えればよさそう
hq = []
ans = 0
for i in range(M):
  for b in jobs[i]:
    heappush(hq, -1 * b)
  if len(hq) > 0:
    m = -1 * heappop(hq)
    ans += m

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

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

ans = 0
for i in range(0, N):
    if P[i] <= min(P[0:i+1]):
        ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
m = P[0]
for i in range(0, N):
    if m > P[i]:
        m = P[i]
    if P[i] <= m:
        ans += 1

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

import heapq
n = int(input())

def prim_heap():
    used = [False]*n
    edgelist = []
    for e in graph[0]:
        heapq.heappush(edgelist,e)
    used[0] = True
    ans = 0
    while edgelist:
        minedge = heapq.heappop(edgelist)
        v = minedge[1]
        if used[minedge[1]]:
            continue
        used[v] = True
        for e in graph[v]:
            if not used[e[1]]:
                heapq.heappush(edgelist,e)
        ans += minedge[0]
    return ans

graphx = []
graphy = []

for i in range(n):
    x,y = map(int,input().split())
    graphx.append([x,y,i])
    graphy.append([x,y,i])
graphx = sorted(graphx, key=lambda x:x[0])
graphy = sorted(graphy, key=lambda x:x[1])
graph = [[] for _ in range(n)]


def S(G):
    for k in range(n-1):
        i,j = G[k][2], G[k+1][2]
        x0,y0,x1,y1 = G[k][0],G[k][1],G[k+1][0],G[k+1][1]
        m = min(abs(x0-x1),abs(y0-y1))
        graph[i].append([m,j])
        graph[j].append([m,i])
S(graphx)
S(graphy)

print(prim_heap())

### 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 = int(input())
graphx = []
graphy = []

for i in range(n):
    x,y = map(int,input().split())
    graphx.append((x,y,i))
    graphy.append((x,y,i))
graphx = sorted(graphx, key=lambda x:x[0])
graphy = sorted(graphy, key=lambda x:x[1])
graph = []


for k in range(n-1):
    i,j = graphx[k][2], graphx[k+1][2]
    x0,x1 = graphx[k][0],graphx[k+1][0]
    m = abs(x0-x1)
    graph.append((m,i,j))

for k in range(n-1):
    i,j = graphy[k][2], graphy[k+1][2]
    y0,y1 = graphy[k][1],graphy[k+1][1]
    m = abs(y0-y1)
    graph.append((m,i,j))


graph.sort()
#print(graph)

ans = 0
uf = UnionFind(n)
for c,i,j in graph:
    if not uf.same(i,j):
        ans += c
        uf.union(i,j)
print(ans)
### BUGGY CODE ###

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

def solve(n,fr,to):
    rates = [(f,t) for f,t in zip(fr,to) if f < t]
    rates.sort()
    if not rates:
        return n
    dp = [i for i in range(n+1)]
    for f,t in rates:
        for i in range(f,n+1):
            dp[i] = max(dp[i], dp[i-f] + t)
    return dp[-1]

n = solve(N,A,B)
print(solve(n,B,A))

### FIXED CODE ###

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

def solve(n,fr,to):
    rates = [(f,t) for f,t in zip(fr,to) if f < t]
    rates.sort()
    if not rates:
        return n
    dp = [i for i in range(n+1)]
    for f,t in rates:
        for i in range(f,n+1):
            dp[i] = max(dp[i], dp[i-f] + t)
    return dp[-1]

n = solve(N,A,B)
print(solve(n,B,A))
### BUGGY CODE ###

n = int(input())
s = list(input())
ans_list = []

for _ in range(n):
    if s[_] == "E":
        s[_] = -1
    else:
        s[_] = 1

for i in range(n):
    ans_list.append(sum(s[:i]))

print(min(ans_list) + (sum(s)-n)//(-2))

### FIXED CODE ###

n = int(input())
s = list(input())
cnt = 0
ans_list = [0]
e_cnt = 0

for i in range(1,n):
    if s[i-1] == "E" and s[i] == "E":
        cnt -= 1
        e_cnt += 1
    if s[i-1] == "E" and s[i] == "W":
        cnt -= 0
    if s[i-1] == "W" and s[i] == "E":
        cnt += 0
        e_cnt += 1
    if s[i-1] == "W" and s[i] == "W":
        cnt += 1
    ans_list.append(cnt)

print(min(ans_list) + e_cnt)
### BUGGY CODE ###

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

### TESTCASE
test = ""
#test = \
"""
9 3
8 3
4 2
2 1
ans 4
"""

"""
5 2
4 4
2 3
ans 7
"""

"""
100 6
1 1
2 3
3 9
4 27
5 81
6 243
ans 100
"""

"""
9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
ans 139815
"""
############
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
####### MAIN
        
h, n = map(int, input2().split())    
ab = [tuple(map(int, input2().split())) for _ in range(n)]

dp = [0] * (h + 1)

for i in range(1, h+1):
    kouho = [10**15]
    for c in ab:     
        kouho.append(dp[max(i-c[0], 0)] + c[1])
    dp[i] = min(kouho)
    #print(i, kouho)
        
print(dp[-1])
    
    








### FIXED CODE ###

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

"""

9 3
8 3
4 2
2 1
ans 4

7 2
4 4
2 3
ans 8

100 6
1 1
2 3
3 9
4 27
5 81
6 243
ans 100

9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
ans 139815
"""; test = """
"""
import builtins
test = list(reversed(test.strip().splitlines()))
input = test.pop if test else builtins.input


import numpy as np
h, n = map(int, input().split())    
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])


dp = np.zeros(h + 1, dtype="int")
for i in range(1, h+1):
    dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1])
    ### dp[i] = min(dp[max(i-c[0], 0)] + c[1] for c in ab) ###
print(dp[-1])
### BUGGY CODE ###

import math,collections

def f(c):
  sum=0
  for i in c:
    sum+=g(i,2)
  return sum

def g(n,r):
  if n==0 or n==1:return 0
  else:return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

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

for i in range(n):
  l=k[0:i]
  l.extend(k[i+1:])
  c=collections.Counter(l).values()
#  print('l:',l,'c:',c)
  print(f(c))

### FIXED CODE ###

import collections
n=int(input())
k=list(map(int,input().split()))
c=collections.Counter(k)
ans=0

for i in c.values():
  ans+=i*(i-1)//2

for i in range(n):
  print(ans-c[k[i]]+1)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

N = int(input())
a_list=[]
b_list=[]
graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)
ten_col =[[] for i in range(N)]
def dfs(start,now):
    for (future,i) in graph[now-1]:
        if future == start:
            pass
        else:
            new_col = 1
            while new_col in ten_col[now-1]:
                new_col += 1
            ten_col[now-1].append(new_col)
            ten_col[future-1].append(new_col)
            ans[i] = new_col

            dfs(now,future)
            
dfs(-1,1)
print(max(ans))
for i in ans:
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append((b,i))
    graph[b-1].append((a,i))
    
ans = [0]*(N-1)

def dfs(past,now,edge_col):
    new_col = 1
    for (future,i) in graph[now-1]:
        if future == past:
            pass
        else:
            if new_col == edge_col:
                new_col += 1
            ans[i] = new_col
            dfs(now,future,new_col)
            new_col += 1
            
dfs(-1,1,-1)

print(max(ans))
for i in ans:
    print(i)
### BUGGY CODE ###

k, s = list(map(int, input().split()))
count = 0

for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                count += 1

print(count)

### FIXED CODE ###

k, s = list(map(int, input().split()))
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if z >= 0 and z <= k:
            count += 1
print(count)
### BUGGY CODE ###

import itertools


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

MOD = 1000000007

l = []
for i in range(N):
    l.append(i)

C = itertools.combinations(l, 2)

a = 0
for c in C:
    a += A[c[0]] % MOD * A[c[1]] % MOD
a %= MOD
print(a)

### FIXED CODE ###

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

MOD = 1000000007

a = 0
b = 0
for i in range(N):
    a += A[i] % MOD
    b += (A[i] ** 2) % MOD
a = a ** 2
ans = (a - b) * pow(2, MOD - 2, MOD) % MOD
print(ans)
### BUGGY CODE ###

m = 998244353
N, K = map(int, input().split())

jumps = []
for i in range(K):
    l, r = map(int, input().split())
    jumps.append([l, r])

dp = [0] * (N + 1)

dp[1] = 1
for i in range(2, N + 1):
    for j in jumps:
        mn = max(0, i - j[1])
        mx = max(mn, i - j[0])
        dp[i] = (dp[i] + sum(dp[mn:mx + 1])) % m
print(dp[N])


### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353


@njit((i8, i8[:]), cache=True)
def main(N, LR):
    L, R = LR[::2], LR[1::2]
    K = len(L)
    F = np.zeros(N + 10, np.int64)
    F[0] = 1
    for n in range(1, N + 10):
        F[n] += F[n - 1]
        for k in range(K):
            l, r = L[k], R[k] + 1
            if n - l >= 0:
                F[n] += F[n - l]
            if n - r >= 0:
                F[n] -= F[n - r]
        F[n] %= MOD
    ans = F[N - 1] - F[N - 2]
    return ans % MOD


N, K = map(int, readline().split())
LR = np.array(read().split(), np.int64)

print(main(N, LR))
### BUGGY CODE ###

import sys,itertools
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()

le = [S.count(s) for s in set(S)]
cnt = 0
for i in range(len(le)):
    for s in itertools.combinations(le,i+1):
        t=1
        for tt in [x for x in s if x > 1]:
            t*=tt
        cnt+=t
print(cnt%((10**9)+7))

### FIXED CODE ###

import sys,itertools
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()

le = [S.count(s)+1 for s in set(S)]
cnt=1
for i in le:
    cnt*=i
print((cnt-1)%((10**9)+7))
### BUGGY CODE ###

n = int(input())
X = list(map(int, input().split()))
xs = sorted(X)
x0, x1 = xs[n // 2 - 1:n // 2 + 1]
[print(x1) if xs.index(x) <= n // 2 - 1 else print(x0) for x in X]

### FIXED CODE ###

n = int(input())
X = list(map(int, input().split()))
x0, x1 = sorted(X)[n // 2 - 1:n // 2 + 1]
[print(x1) if x <= x0 else print(x0) for x in X]
### BUGGY CODE ###

def main():
  from collections import deque
  import sys
  input = sys.stdin.readline
  T = int(input())
  def res_1(lis,ans):
    flag = [False] * (N)
    for klr in lis:
      x = klr[0]
      for _ in range(N):
        if x<0:
          ans += klr[2]
          break
        if flag[x]:
          x -= 1
        else:
          flag[x] = True
          ans += klr[1]
          break
    return ans
  
  def res_2(lis,ans):
    flag = [False] * (N)
    for klr in right:
      x = klr[0] + 1
      for _ in range(N):
        if x>=N:
          ans += klr[1]
          break
        if flag[x]:
          x += 1
        else:
          flag[x] = True
          ans += klr[2]
          break
          
    return ans
  for _ in range(T):
    N = int(input())
    KLR = [list(map(int,input().split())) for _ in range(N)]
    left = deque([])
    right = deque([])
    ans = 0
    for K,L,R in KLR:
      x = L - R
      if x==0:
        ans += L
      elif x>0:
        left.append([K-1,L,R,x])
      else:
        right.append([K-1,L,R,x])

    left = sorted(left,key = lambda x:x[3],reverse = True)
    right = sorted(right, key = lambda x:x[3])
    ans = res_1(left,ans)
    ans = res_2(right,ans)

    print(ans)
    
main()

### FIXED CODE ###

def main():
  from collections import deque
  import sys
  input = sys.stdin.readline
  from heapq import heapify,heappop,heappush
  T = int(input())
  for _ in range(T):
    N = int(input())
    KLR = [list(map(int,input().split())) for _ in range(N)]
    left = deque([])
    right = deque([])
    ans = 0
    for K,L,R in KLR:
      x = L - R
      if x==0:
        ans += L
      elif x>0:
        left.append([K,L,R])
        ans += R
      else:
        right.append([K+1,L,R])
        ans += L

    left = sorted(left)
    right = sorted(right,reverse=True)
      
    S = []
    heapify(S)
    x = 1
    i = 0
    length = len(left)
    while x<=N:
      while i<length:
        klr = left[i]
        if klr[0]==x:
          heappush(S,klr[1]-klr[2])
          i += 1
          
        else:
          break
      
      y = len(S) - x
      if y<=0:
        x += 1
        continue
      else:
        for _ in range(y):
          heappop(S)
          
    ans += sum(S)
    
    S = []
    heapify(S)
    x = N+1
    i = 0
    length = len(right)
    while x>=0:
      while i<length:
        klr = right[i]
        if klr[0]==x:
          heappush(S,klr[2]-klr[1])
          i += 1
 
        else:
          break
      
      y = len(S) + x - N - 1
      if y<=0:
        x -= 1
        continue
      else:
        for _ in range(y):
          heappop(S)    
    ans += sum(S)
    print(ans)
    
main()
### BUGGY CODE ###

n, k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
af = [a[i]*f[i] for i in range(n)]

def check(x):
  r = 0
  for i in range(n):
    r += (max(0,(af[i]-x))+f[i]-1)//f[i]
  #print(r, x)
  if r<=k:
    return True
  else:
    return False
ok = 10**12+1
ng = -1
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    ok = mid
  else:
    ng = mid
print(ok)

### FIXED CODE ###

n, k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
af = [a[i]*f[i] for i in range(n)]

def check(x):
  r = 0
  for i in range(n):
    r += (max(0,(af[i]-x))+f[i]-1)//f[i]
  #print(r, x)
  if r<=k:
    return True
  else:
    return False
ok = 10**12+1
ng = -1
while ok-ng>1:
  mid = (ok + ng)//2
  if check(mid):
    ok = mid
  else:
    ng = mid
print(ok)
### BUGGY CODE ###

# coding:utf-8

import itertools

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def dijkstra(graph, start):
    MAX_SIZE = len(graph)
    visited = [False for _ in range(MAX_SIZE)]
    cost = [INF for _ in range(MAX_SIZE)]
    prev = [None for _ in range(MAX_SIZE)]

    cost[start] = 0
    prev[start] = start
    path = [start + 1]
    while True:
        min_cost = INF
        next = -1
        visited[start] = True
        # 頂点の選択
        for i in range(MAX_SIZE):
            if visited[i]: continue # 探索済みの頂点は飛ばす
            if graph[start][i]: # 頂点startと接続されているか判定
                dist = cost[start] + graph[start][i]
                if dist < cost[i]:
                    cost[i] = dist
                    prev[i] = start

            if cost[i] < min_cost:
                min_cost = cost[i]
                next = i

        start = next
        path.append(next + 1)
        if next == -1: break

    # print(cost)
    # print(path)
    return cost


def main():
    N, M, R = inpl()
    r = inpl()

    G = [[None for _ in range(N)] for _ in range(N)]
    for i in range(M):
        a, b, c = inpl()
        G[a - 1][b - 1] = c
        G[b - 1][a - 1] = c

    ans = INF
    for root in itertools.permutations(r, R):
        dist = 0
        for i in range(R - 1):
            dist += dijkstra(G, root[i] - 1)[root[i + 1] - 1]
        ans = min(ans, dist)

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

# coding:utf-8

import itertools

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def dijkstra(graph, start):
    MAX_SIZE = len(graph)
    visited = [False for _ in range(MAX_SIZE)]
    cost = [INF for _ in range(MAX_SIZE)]
    prev = [None for _ in range(MAX_SIZE)]

    cost[start] = 0
    prev[start] = start
    path = [start + 1]
    while True:
        min_cost = INF
        next = -1
        visited[start] = True
        # 頂点の選択
        for i in range(MAX_SIZE):
            if visited[i]: continue  # 探索済みの頂点は飛ばす
            if graph[start][i]:  # 頂点startと接続されているか判定
                dist = cost[start] + graph[start][i]
                if dist < cost[i]:
                    cost[i] = dist
                    prev[i] = start

            if cost[i] < min_cost:
                min_cost = cost[i]
                next = i

        start = next
        path.append(next + 1)
        if next == -1: break

    # print(cost)
    # print(path)
    return cost


def main():
    N, M, R = inpl()
    r = inpl()

    G = [[None for _ in range(N)] for _ in range(N)]
    for i in range(M):
        a, b, c = inpl()
        G[a - 1][b - 1] = c
        G[b - 1][a - 1] = c

    min_cost = {}
    for s in r:
        min_cost[str(s)] = dijkstra(G, s - 1)

    ans = INF
    for root in itertools.permutations(r, R):
        dist = 0
        for i in range(R - 1):
            s = str(root[i])
            dist += min_cost[s][root[i + 1] - 1]
        ans = min(ans, dist)

    print(ans)


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

import math
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

### FIXED CODE ###

from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))
### BUGGY CODE ###

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

num_ones = [0]*60
powers_of_two = [pow(2,x,1000000007) for x in range(60)]

ans = 0
for i in range(N-1,-1,-1):
  for j in range(60):
    if A[i] & 1:
      ans = (ans + powers_of_two[j] * (N - i - 1 - num_ones[j])) % 1000000007
      num_ones[j] += 1
    else:
      ans = (ans + powers_of_two[j] * num_ones[j]) % 1000000007
    A[i] >>= 1
print(ans)


### FIXED CODE ###

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

ans = 0
for i in range(60):
  p = 1 << i
  num_one = len([1 for x in A if x & p])
  ans = ans + p * num_one * (N - num_one)
print(ans % 1000000007)
### BUGGY CODE ###

# ABC162D - RGB Triplets

import numpy as np

def main():
    n=int(input())
    s=np.zeros(n,dtype=np.int64)
    a=input()
    for i in range(n):
        s[i]=ord(a[i])%3
    ans=0
    d=np.zeros((3,n),dtype=np.int64)
    m=np.zeros((3,n),dtype=np.int64)
    l=np.array([[0,2,1],[2,1,0],[1,0,2]])
    #print(s.dtype,d.dtype,m.dtype)

    for i in range(n):
        d[s[i],i]=1
        m[s[i],i]=1

    for j in range(3):
        for i in range(n-1,0,-1):
            m[j,i-1]+=m[j,i]

    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            if s[i]==s[j]:
                continue
            ans+=m[l[s[i]][s[j]],j+1]
            if (j*2-i)<n:
                ans-=d[l[s[i]][s[j]],j*2-i]
    
    print(ans)
        
main()


### FIXED CODE ###

def main():
    n=int(input())
    s=input()
    ans=0
    d=dict()
    dr=[0]*n
    dg=[0]*n
    db=[0]*n
    mr=[0]*n
    mg=[0]*n
    mb=[0]*n

    for i in range(n):
        if s[i]=='R':
            dr[i]=1
            mr[i]=1
        if s[i]=='G':
            dg[i]=1
            mg[i]=1
        if s[i]=='B':
            db[i]=1
            mb[i]=1

    for i in range(n-1):
        mr[n-2-i]+=mr[n-1-i]
        mg[n-2-i]+=mg[n-1-i]
        mb[n-2-i]+=mb[n-1-i]

    for i in range(n-2):
        for j in range(i,n-1):
            if s[i]==s[j]:
                continue
            if s[i]=='R' and s[j]=='G':
                k=1
            elif s[i]=='R' and s[j]=='B':
                k=2
            elif s[i]=='G' and s[j]=='R':
                k=1
            elif s[i]=='G' and s[j]=='B':
                k=0
            elif s[i]=='B' and s[j]=='R':
                k=2
            elif s[i]=='B' and s[j]=='G':
                k=0
            #print(k)
            
            if k==0:
                ans+=mr[j+1]
                if (j+(j-i))<n:
                    ans-=dr[j+(j-i)]
            if k==1:
                ans+=mb[j+1]
                if (j+(j-i))<n:
                    ans-=db[j+(j-i)]
            if k==2:
                ans+=mg[j+1]
                if (j+(j-i))<n:
                    ans-=dg[j+(j-i)]

    print(ans)
        



main()
### BUGGY CODE ###

N = int(input())

power = 1

for i in range(1,N+1):
	power *= i
	
print(power%(10**9+7))

### FIXED CODE ###

N = int(input())

power = 1

for i in range(1,N+1):
	power *= i
	power %= 1000000007
	
print(power)
### BUGGY CODE ###

import sys


# \n
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(input())

    ok =0
    ng =N//2
    ans =0
    for i in range(N-1):
        for j in range(i+1,N):
            for k in range(0,min(j-i,N-j)):
                if S[i+k] == S[j+k]:
                    ans =max(ans,k+1)
                else:
                    break

    print(ans)







if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    S = list(input())



    ans =0
    for k in range(1,N):
        i=0
        count =0
        while i<N-k:
            if S[i]==S[i+k]:
                count+=1
                ans =max(ans,min(count,k))
            else:
                count=0

            i+=1

    print(ans)









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

n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 9999999999999
for i in range(len(l) - k + 1):
    tl = l[i:i + k]
    min_l = min(0, min(tl))
    max_l = max(0, max(tl))
    min_abs = min(abs(min_l), abs(max_l))
    max_abs = max(abs(min_l), abs(max_l))
    ans = min(ans, min_abs * 2 + max_abs)
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 9999999999999
for i in range(len(l) - k + 1):
    min_l = min(0, l[i])
    max_l = max(0, l[i+k-1])
    min_abs = min(abs(min_l), abs(max_l))
    max_abs = max(abs(min_l), abs(max_l))
    ans = min(ans, min_abs * 2 + max_abs)
print(ans)