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

from collections import Counter
N = int(input())
S = input()
Sc = Counter(S)
rgb = Sc["R"] * Sc["G"] * Sc["B"]
for j in range(1, N-1):
    for i in range(j):
        k = j + (j-i)
        assert i < j < k
        if k < N:
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                rgb -= 1
print(rgb)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = input()
Sc = Counter(S)
rgb = Sc["R"] * Sc["G"] * Sc["B"]
for j in range(1, N-1):
    for i in range(j):
        k = j + (j-i)
        assert i < j < k
        if k < N:
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                rgb -= 1
print(rgb)
### BUGGY CODE ###

import numpy as np
H, W, N = map(int, input().split())
d = 10**9+1
L = []
for _ in range(N):
    a, b = map(int, input().split())
    L.append(a*d+b)
S = set(L)
Map = np.zeros([5, 5], dtype = 'int')
ans = [0]*10
for i in L:
    a, b = i//d, i%d
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j
            if (1<=a1<=H) and (1<=b1<=W):
                if (a1*d+b1) in S:
                    Map[i+2][j+2] = 1
                else:
                    Map[i+2][j+2] = 0
            else:
                Map[i+2][j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            k = Map[i+1:i+4, j+1:j+4].sum()
            if k>=0:
                ans[k]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)
        

### FIXED CODE ###

H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map =[[0]*5 for _ in range(5)]
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j

            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2][j+2] = 1
                else:
                    Map[i+2][j+2] = 0
            else:
                Map[i+2][j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            res = 0
            for k in range(3):
                for l in range(3):
                    res+=Map[i+1+k][j+1+l]
            if res>=0:
                ans[res]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)
### BUGGY CODE ###

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

# for _ in range(k):
#     next_a = [0] * n
#     for i, brightness in enumerate(a):
#         begin = max(0, i - brightness)
#         end = min(i + brightness + 1, n)
#         for j in range(begin, end):
#             next_a[j] += 1
#     print(next_a)
#     a = next_a.copy()
for t in range(k):
    finish = True
    stack = []
    for i, brightness in enumerate(a):
        if brightness != n:
            finish = False
        begin = i - brightness - 0.5
        end = i + brightness + 0.5
        stack.append((begin, "IN"))
        stack.append((end, "OUT"))
    if finish:
        break
    stack.sort(key=lambda x: x[0])
    now = 0
    pos = 0
    for inout in stack:
        if pos > n-1:
            break
        while pos < inout[0]:
            if pos > n-1:
                break
            a[pos] = now
            pos += 1
        if inout[1] == "IN":
            now += 1
        elif inout[1] == "OUT":
            now -= 1
print(*a, sep=" ")


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    for _ in range(k):
        imos = [0]*(n+1)
        finish = True
        for i, brightness in enumerate(a):
            if finish and brightness != n:
                finish = False
            begin = max(i - brightness, 0)
            end = i + brightness
            imos[begin] += 1
            if end < n:
                imos[end + 1] -= 1
        if finish:
            break
        for i in range(n-1):
            imos[i+1] += imos[i]
        a = imos[:-1]
    print(*a, sep=" ")


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

n = int(input())
s = list(map(int, input()))

used_i = [False] * 10
ans = []
for i in range(n - 2):
    if not used_i[s[i]]:
        used_j = [False] * 10
        for j in range(i + 1, n - 1):
            if not used_j[s[j]]:
                for k in set(s[j + 1 : n]):
                    pin = f"{s[i]}{s[j]}{k}"
                    if pin not in ans:
                        ans.append(pin)
print(len(ans))

### FIXED CODE ###

n = int(input())
s = list(map(int, input()))

ans = []

for i in range(10):
    if i in s:
        a = s.index(i)
        for j in range(10):
            if j in s[a + 1 :]:
                b = [x for x, y in enumerate(s) if x > a and y == j][0]
                for k in range(10):
                    if k in s[b + 1 :]:
                        ans.append(f"{i}{j}{k}")
print(len(ans))
### BUGGY CODE ###

S = input()
s = 0
e = 0
ans = 0
for k in range(len(S)-1):
    if S[k]=="A":
        s = k
        e = k+1
        for l in range(k+1,len(S)):
            if S[l]=="Z":
                e = max(e,l)
    ans = max(ans,e-s+1)
print(ans)


### FIXED CODE ###

S = input()
s = S.index("A")
e = len(S)-S[::-1].index("Z")
print(e-s)
### BUGGY CODE ###

N = int(input())
c = list(map(int, input().split()))
c.sort(reverse = True)
mod = 10 ** 9 + 7
tmp = 2 ** (N - 1)
d = tmp // 2
ans = 0
for ci in c:
    ans += (ci * tmp) % mod
    ans %= mod
    tmp = (tmp + d) % mod
print((ans * 2 ** N) % mod)


### FIXED CODE ###

N = int(input())
c = list(map(int, input().split()))
c.sort(reverse = True)
mod = 10 ** 9 + 7
tmp = (2 ** (N - 1)) % mod
d  = (2 ** (N - 2)) % mod
ans = 0
for ci in c:
    ans += (ci * tmp) % mod
    ans %= mod
    tmp = (tmp + d) % mod
print((ans * 2 ** N) % mod)
### BUGGY CODE ###

aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
  x1, y1, c1 = list(map(int,input().split()))
  x.append(x1)
  y.append(y1)
  c.append(c1)

price = []
  
for i in range(aa):
  price1 = a[i] + min(b)
  price.append(price1)
  
for i in range(m):
  price.append(a[x[i] - 1] + b[y[i] - 1] - c[i])
  
print(min(price))

### FIXED CODE ###

aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
  x1, y1, c1 = list(map(int,input().split()))
  x.append(x1)
  y.append(y1)
  c.append(c1)

price = []
  
for i in range(m):
  price.append(a[x[i] - 1] + b[y[i] - 1] - c[i])
  
  
  
print(min(min(price), min(a) + min(b)))
### BUGGY CODE ###


import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




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


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

S=list(map(int,list(input())[:-1]))[::-1]
#print(S)

smod=[]
bef=0
for i in range(len(S)):
    bef+=(S[i]*(10**i))%2019
    smod.append(bef%2019)
    
cnt=[0]*2020
for sm in smod:
    cnt[sm]+=1

cnt[0]+=1

res=0
for sc in cnt:
    res+=sc*(sc-1)/2
    
    
print(int(res))

#print(smod)

#print(cnt[:10])

### FIXED CODE ###



from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




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


def II():
    return int(input())

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

#S=list(map(int,list(input())[:-1]))[::-1]
S=list(map(int,list(input())[:-1]))
#print(S)

N=len(S)
smod=[0]*N
bef=0
b=1

for i in range(len(S)):
    l=N-i-1
    bef+=(S[l]*(b))%2019
    smod[l]=bef%2019
    #smod.append(bef%2019)
    b=(b*10)%2019
    
cnt=[0]*2020
for sm in smod:
    cnt[sm]+=1

cnt[0]+=1

res=0
for sc in cnt:
    res+=sc*(sc-1)/2
    
    
print(int(res))

#print(smod)

#print(cnt[:10])
### BUGGY CODE ###

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

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
  if i-1 not in a:
    dp[i] += dp[i-1]
  if i-2 not in a:
    dp[i] += dp[i-2]
  
  dp[i] = dp[i] % 1000000007
print(dp[n])

### FIXED CODE ###

n,m=map(int,input().split())
a=set()
for i in range(m):
  a.add(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if 1 not in a:
  dp[1] = 1

for i in range(2,n+1):
  if i in a:
    continue

  dp[i] += dp[i-1] + dp[i-2]
  dp[i] = dp[i] % 1000000007
print(dp[n])
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1, n + 1):
  for j in range(i, n + 1, i):
    ans += j
print(ans)


### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n + 1):
  for j in range(i, n + 1, i):
    ans += j
print(ans)
### BUGGY CODE ###

#imsosorryididntwanttoimplementmodpow
import math
n,m = [int(x) for x in input().split()]

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))

i = 2
ans = 1
while (i<=m):
    if m%i==0:
        mult = 0
        while (m%i==0):
            mult += 1
            m //= i
        ans *= comb(n+mult-1,n-1)
    i += 1
if m!=1:
    ans *= comb(n,n-1)

print(ans%int(1e9+7))


### FIXED CODE ###

#imsosorryididntwanttoimplementmodpow
import math
n,m = [int(x) for x in input().split()]

def comb(n, r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))

i = 2
ans = 1
while (i<=m):
    if m%i==0:
        mult = 0
        while (m%i==0):
            mult += 1
            m //= i
        ans *= comb(n+mult-1,n-1)
    i += 1
if m!=1:
    ans *= comb(n,n-1)

print(ans%int(1e9+7))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

def main():
    S = input()
    N = len(S)

    # S = [int(s) if s!="?" else -1 for s in S ]
    dp = [[0] * 13 for _ in range(N+1)]

    s = S[0]
    if s == "?":
        for j in range(10):
            dp[0][j] += 1
    else:
        dp[0][int(s)%13] += 1
    for i in range(1,N):
        s = S[i]
        if s == "?":
            X = range(10)
        else:
            X = [int(s)]

        for j in range(0,13):
            ten_j = j*10
            for x in X:
                k = (ten_j+x)%13
                dp[i][k] += dp[i-1][j]
                # print(i,j,k)

    # print(dp)
    print(dp[N-1][5] % (10**9+7))



if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def main():
    S = input()
    N = len(S)
    MOD = 10**9+7

    # S = [int(s) if s!="?" else -1 for s in S ]
    dp = [[0] * 13 for _ in range(N+1)]

    s = S[0]
    if s == "?":
        for j in range(10):
            dp[0][j] += 1
    else:
        dp[0][int(s)%13] += 1
    for i in range(1,N):
        s = S[i]
        if s == "?":
            for j in range(0,13):
                for x in range(10):
                    k = (j*10+x)%13
                    dp[i][k] += dp[i-1][j]
                    dp[i][k] %= MOD
        else:
            for j in range(0,13):
                k = (j*10+int(s))%13
                dp[i][k] += dp[i-1][j]
                dp[i][k] %= MOD


    print(dp[N-1][5])


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

import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))

for j in range(m):
    A.sort()
    b,c = map(int, input().split())
    if b <= n:
        if A[b-1] > c:
            for i in range(c-A[0]):
                f = my_index(A, c-i)
                if f != -1:
                    A[:f]=[c]*f
                    break
        else:
            A[:b]=[c]*b


print(sum(A))


### FIXED CODE ###

import sys
import heapq

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = [list(map(int,input().split())) for _ in range(m)]

d.sort(key=lambda x:-x[1])
total = sum(A)
heapq.heapify(A)

for i in range(m):
    for j in range(d[i][0]):
        tmp = heapq.heappushpop(A, d[i][1])
        if tmp < d[i][1]:
                total += (d[i][1] - tmp)
        else:
            break

print(total)
### BUGGY CODE ###

from math import factorial
mod = 10**9+7
bouquet = 0
n,a,b = map(int,input().split())
for i in range(1,n+1):
    if i != a and i != b:
        bouquet += factorial(n)//factorial(i)//factorial(n-i) % mod
print(bouquet % mod)

### FIXED CODE ###

def pow(a,b,c):
    ans = 1
    while b > 0:
        if b & 1:
            ans = ans*a % c
        a = a*a % c
        b = b >> 1
    return ans
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(n-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num*pow(den,c-2,c) % c
mod = 10**9+7
n,a,b = map(int,input().split())
ans  = (pow(2,n,mod)-cmb(n,a,mod)-cmb(n,b,mod)-1) % mod
if ans < 0:
    ans = ans + mod
print(ans)
### 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 %= 10**9+7

print(power)
### BUGGY CODE ###

# D - 2017-like Number
# https://atcoder.jp/contests/abc084/tasks/abc084_d

prime = []
is_prime = []
is_prime.append(False)
is_prime.append(False)

def sieve(r):
    start = len(is_prime)
    if start >= r:
        return 

    for i in range(start, r + 1):
        is_prime.append(True)

    for i in prime:
        j = 2 * i
        while j <= r:
            if j < start:
                j = j + i
                continue

            is_prime[j] = False
            j = j + i

    for i in range(start, r + 1):
        if is_prime[i]:
            prime.append(i)

            j = 2 * i
            while j <= r:
                is_prime[j] = False
                j = j + i

def main():
    # answers = []
    Q = int(input())
    querys = []
    max_r = 0
    for i in range(Q):
        l, r = map(int, input().split())
        querys.append((l, r))
        if max_r < r:
            max_r = r

    sieve(max_r)

    for l, r in querys:
        like_numbers = [n for n in prime if n % 2 == 1 and l <= n <= r and is_prime[(n + 1) // 2]]
        # answers.append(len(like_numbers))
        print(len(like_numbers))
    
    # for answer in answers:
    #     print(answer)

main()

### FIXED CODE ###

# D - 2017-like Number
# https://atcoder.jp/contests/abc084/tasks/abc084_d

counts = []
counts.append(0)
counts.append(0)
counts.append(0)

prime = []

is_prime = []
is_prime.append(False)
is_prime.append(False)

def sieve(r):
    for i in range(2, r + 1):
        is_prime.append(True)

    for i in range(2, r + 1):
        if is_prime[i]:
            prime.append(i)

            j = 2 * i
            while j <= r:
                is_prime[j] = False
                j = j + i

def calc_like_number_count(r):
    for i in range(3, r + 1):
        if i % 2 == 1 and is_prime[i] and is_prime[(i + 1) // 2]:
            counts.append(1)
        else:
            counts.append(0)
    
    for i in range(3, r + 1):
        counts[i] = counts[i] + counts[i - 1]


def main():
    Q = int(input())
    querys = []
    max_r = 0
    for i in range(Q):
        l, r = map(int, input().split())
        querys.append((l, r))
        if max_r < r:
            max_r = r

    sieve(max_r)
    calc_like_number_count(max_r)

    for l, r in querys:
        print(counts[r] - counts[l - 1])
    
main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
i = 0
SUM = 1
for a in A:
    SUM = SUM * a

if SUM > 10**18:
    print(-1)
    
else:
    print(SUM)

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    SUM = 1

    if 0 in A:
        print(0)
        return

    for a in A:
        SUM = SUM * a
        if SUM > 1000000000000000000:
            print(-1)
            return

    print(SUM)
main()
### BUGGY CODE ###

from operator import mul
from functools import reduce

N = int(input())
S = input()
MOD = 998244353

# make A, B, C oredesr
r, g, b = 0, 0, 0
T = {'R': 0, 'G': 0, 'B': 0}
ABC = ''
for s in S:
    T[s] += 1
    ge = [t >= T[s] for t in T.values()].count(True)
    lt = [t < T[s] for t in T.values()].count(True)
    if ge == 1:
        ABC += 'A'
    elif lt == 0:
        ABC += 'C'
    else:
        ABC += 'B'

la, rc = 0, 0  # selectable num of left A and right C
ans = 1

# from left for A
for d in ABC:
    if d == 'A':
        la += 1
    elif d == 'B':
        ans *= la
        ans %= MOD
        la -= 1

# from right for C
for d in ABC[::-1]:
    if d == 'C':
        rc += 1
    elif d == 'B':
        ans *= rc
        ans %= MOD
        rc -= 1

# human permutation
ans *= reduce(mul, range(1, N+1))
ans %= MOD
print(ans)


### FIXED CODE ###

N = int(input())
S = input()
MOD = 998244353

# make A, B, C oredesr
r, g, b = 0, 0, 0
T = {'R': 0, 'G': 0, 'B': 0}
ABC = []  # means, A: 0, B: 1, C: 2
for s in S:
    T[s] += 1
    ge = [t >= T[s] for t in T.values()].count(True)
    lt = [t < T[s] for t in T.values()].count(True)
    if ge == 1:
        ABC.append(0)
    elif lt == 0:
        ABC.append(2)
    else:
        ABC.append(1)

la, rc = 0, 0  # selectable num of left A and right C
ans = 1

# from left for A
for d in ABC:
    if d == 0:
        la += 1
    elif d == 1:
        ans *= la
        ans %= MOD
        la -= 1

# # from right for C
for d in ABC[::-1]:
    if d == 2:
        rc += 1
    elif d == 1:
        ans *= rc
        ans %= MOD
        rc -= 1

# human permutation
for i in range(1, N+1):
    ans *= i
    ans %= MOD
print(ans)
### BUGGY CODE ###

#! /usr/bin/env python3

def main():
    N, L = map(int, input().split())
    A = list(map(int, input().split()))
    a, b = 1, N-1
    l = []
    la = N
    for i in range(N-1):
        if A[i] + A[i+1] >= L:
            la = i
            break
    if la == N:
        print('Impossible')
        return
    while len(A) > 2:
        if a-1 != la:
            l += [a]
            a += 1
            A = A[1:]
        else:
            l += [b]
            b -= 1
            A = A[:-1]
    print('Possible')
    l+=[la+1]
    for i in l : print(i)
if __name__ == '__main__':
    main()

### FIXED CODE ###

#! /usr/bin/env python3

def main():
    N, L = map(int, input().split())
    A = list(map(int, input().split()))
    la = N
    for i in range(N-1):
        if A[i] + A[i+1] >= L:
            la = i
            break
    if la == N:
        print('Impossible')
        return
    print('Possible')
    for i in range(la) : print(i+1)
    for i in range(N-la-2) : print(N-i-1)
    print(la+1)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

class Work:
    count=0
    def __init__(self,payday,money):
        Work.count+=1
        self.count=Work.count
        self.payday=payday
        self.money=money
 #moneyが大きい方、同じなら早くもらえる方、それも同じなら最初に書いてある方が強い方
    def __gt__(self,other):
        if self.money>other.money:
            return True
        if self.money==other.money:
            if self.payday<other.payday:
                return True
            if self.payday==other.payday:
                if self.count<other.count:
                    return True
        return False

    def __ft__(self,other):
        if self.money<other.money:
            return True
        if self.money==other.money:
            if self.payday>other.payday:
                return True
            if self.payday==other.payday:
                if self.count>other.count:
                    return True
        return False

#バイトの数、いつまでに稼ぐのか 
n,limit=[int(i) for i in input().split()]

#バイトのリストを作り、クラスを入れる O(n)
baitolist=[]
for i in range(n):
    payday,money=[int(i) for i in input().split()]
    work=Work(payday,money)
    baitolist.append(work)

#日数でランク付け　O(n)
summoney=0    
rank=[[] for i in range(limit+1)]
for baito in baitolist:
    if baito.payday<=limit:
        rank[baito.payday].append(baito)

accessible=[]
count=1
while baitolist and count<=limit:#最悪O(limit)
    for baito in rank[count]:
        accessible.append(baito)
    accessible.sort()
    if accessible!=[]:
        dowork=accessible.pop()
        summoney+=dowork.money
    count+=1
    
    
print(summoney)        


### FIXED CODE ###

class Work:
    count=0
    def __init__(self,payday,money):
        Work.count+=1
        self.count=Work.count
        self.payday=payday
        self.money=money
 #moneyが大きい方、同じなら早くもらえる方、それも同じなら最初に書いてある方が強い方
    def __ft__(self,other):
        if self.money>other.money:
            return True
        if self.money==other.money:
            if self.payday<other.payday:
                return True
            if self.payday==other.payday:
                if self.count<other.count:
                    return True
        return False

    def __gt__(self,other):
        if self.money<other.money:
            return True
        if self.money==other.money:
            if self.payday>other.payday:
                return True
            if self.payday==other.payday:
                if self.count>other.count:
                    return True
        return False

#バイトの数、いつまでに稼ぐのか 
n,limit=[int(i) for i in input().split()]

#バイトのリストを作り、クラスを入れる O(n)
baitolist=[]
for i in range(n):
    payday,money=[int(i) for i in input().split()]
    work=Work(payday,money)
    baitolist.append(work)

#日数でランク付け　O(n)
summoney=0    
rank=[[] for i in range(limit+1)]
for baito in baitolist:
    if baito.payday<=limit:
        rank[baito.payday].append(baito)

        
import heapq
accessible=[]
count=1


for i in range(limit):
    for baito in rank[count]:
        heapq.heappush(accessible,baito)
    if accessible!=[]:
        dowork=heapq.heappop(accessible)
        summoney+=dowork.money
    count+=1
    
    
print(summoney)