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

# cook your dish here
import bisect
n = int(input())
a = list(map(int,input().split()))
a.sort()
 

c = [0]*n #使ったら1
 
res = 0
 
for i in range(n-1,-1,-1):
    if c[i] == 0:
        b = 1
        while b <= a[i]:
            b = b*2
        w1 = bisect.bisect_left(a,b-a[i])
        w2 = bisect.bisect_right(a,b-a[i])
        if w2 >w1:
            p = w1
            while p != w2:
                if c[p] == 0 and i != p:
                    res += 1
                    c[p] = 1
                    c[i] = 1
                    p = w2-1
                p += 1

print(res)

### FIXED CODE ###

import bisect
 
N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)
 
c = 0
for i in range(N - 1 , -1, -1):
    if A[i] == int(A[i]):
        b = 1
        while b <= A[i]:
            b <<= 1
 
        j = bisect.bisect_left(A, b - A[i])
        if i > j:
            if b - A[i] == A[j]:
                c += 1
                A[j] = A[j] - 0.5
                A[i] = A[i] + 0.5
print(c)
### BUGGY CODE ###

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

ad=[1]*n
an=n

for i in range(n-1):
    if ad[i]==1:
        for j in range(i+1,n):
            wk1,wk0=divmod(a[j],a[i])
            if wk0==0 and ad[j]==1:
                if wk1==1:
                    ad[i]=0
                ad[j]=0

print(sum(ad))

### FIXED CODE ###

import numpy as np

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

amax=max(a)+1
ah=[0]*amax

for i in a:
    for j in range(i,amax,i):
        ah[j]+=1

an=0
for i in a:
    if ah[i]==1:
        an+=1
print(an)
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
ans=1
for i in a:
    ans*=i

print(ans if ans<=10**18 else -1)


### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]
if 0 in a:
    print(0)
    exit()
a.sort(reverse=True)
ans=1
x=10**18
for i in a:
    ans*=i
    if ans>x:
        print(-1)
        exit()

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

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

maximized = [False] * N
allmax = [N] * N

for k in range(K):
    B = [0] * N


    # 全玉maxになったとき
    if A == allmax:
        break
    if all(maximized):
        break

    for i in range(N):
        # 強さはN超にはならない
        if A[i] == N:
            B[i] = A[i]
            maximized[i] = True
        else:
            # 照らせる範囲
            l = max(0, i - A[i])
            r = min(N - 1, i + A[i])

            for j in range(l, r + 1):
                B[j] += 1

                if B[j] == N:
                    maximized[j] = True
    A = B

A = [str(a) for a in A]
print(' '.join(A))


### FIXED CODE ###

import numpy as np
from numba import njit

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
a = np.array(A, dtype=int)


fin = [N] * N

@njit(cache=True)
def calc_b(a):
    b = np.zeros(N, dtype=np.int64)
    for i, _a in enumerate(a):
        l = max(0, i - _a)
        r = min(N - 1, i + _a)

        # imos hou
        b[l] += 1
        if r + 1 < N:
            b[r + 1] -= 1

    b = np.cumsum(b)
    # print('b_sum', b)
    return b


for k in range(min(K,100)):
    # print('a', a)
    a = calc_b(a)
    # if all(a == fin):
    #     break

a = [str(_) for _ in a]
print(' '.join(a))
# print('step=', k)
### BUGGY CODE ###

K,S=map(int,input().split())
c=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z==S:
                c+=1
print(c)


### FIXED CODE ###

K,S=map(int,input().split())
c=0
for x in range(K+1):
    for y in range(K+1):
        if S-x-y>=0 and S-x-y<=K:
            c+=1
        """
        for z in range(K+1):
            if x+y+z==S:
                c+=1
        """
print(c)
### BUGGY CODE ###

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

ans = 1
flag = 0

for i in range(N):
    if A[i]== 0:
        print(0)
        exit(0)
    if len(str(ans))+len(str(A[i]))>20:
        flag = 1
    ans*=A[i]
    if ans > 1000000000000000000:
        flag = 1

if flag == 0:
    print(ans)
else :
    print(-1)

### FIXED CODE ###

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

ans = 1
l = 0;
flag = 0

for i in range(N):
    if A[i]== 0:
        print(0)
        exit(0)

    l+=(len(str(A[i])) -1)
    if l>18:
        flag=1
        continue
    
    ans*=A[i]
    if ans > 1000000000000000000:
        flag = 1

if flag == 0:
    print(ans)
else :
    print(-1)
### BUGGY CODE ###

data = input()
#data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]

m = max(height)
water = [m for h in height]

height00 = [0] + height + [0]
water00 = [0] + water + [0]

roop = True
while roop:
	temp = water00[:]
	for i in range(1,len(water00)-1):
		water00[i] = max(height00[i],min(water00[i-1:i+2]))
	roop = temp != water00

water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]

paddles = [0]
for d1,d2 in zip(depth[:-1],depth[1:]):
	if d1==0 and d2>0:
		paddles.append(0)
	paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)

paddles = [int(p) for p in paddles[1:]]
print(sum(paddles))
print(len(paddles), *paddles)

### FIXED CODE ###

data = input()
#data = '\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'
diff = {'\\':-1, '_':0, '/':1}
height = [0]
[height.append(height[-1]+diff[i]) for i in data]
bottom = min(height)
height = [h-bottom for h in height]

m = max(height)
water = [m for h in height]

height00 = [0] + height + [0]
water00 = [0] + water + [0]

idx = list(range(1,len(water00)-1))
for i in idx + idx[::-1]:
	water00[i] = max(height00[i],min(water00[i-1:i+2]))

water = water00[1:-1]
depth = [w-h for w,h in zip(water,height)]

paddles = [0]
for d1,d2 in zip(depth[:-1],depth[1:]):
	if d1==0 and d2>0:
		paddles.append(0)
	paddles[-1] += min(d1,d2) + 0.5*abs(d1-d2)

paddles = [int(p) for p in paddles[1:]]
print(sum(paddles))
print(len(paddles), *paddles)
### BUGGY CODE ###

N,M=map(int,input().split())
A=[]
MOD=10**9+7
for _ in range(M):
    A.append(int(input()))

a,b,n=0,1,1
while n<=N:
    if n in A:
        a,b=b,0
    else:
        a,b=b,a+b
    n+=1

print(b%MOD)

### FIXED CODE ###

N,M=map(int,input().split())
MOD=10**9+7
p,q,n=0,1,1
for _ in range(M):
    a=int(input())
    while n<=a:
        p,q=q,p+q
        n+=1
    q=0
while n<=N:
    p,q=q,p+q
    n+=1

print(q%MOD)
### BUGGY CODE ###

h,w = map(int,input().split())
s =["#"*(w+2)] + ["#"+input()+"#" for i in range(h)] + ["#"*(w+2)]
# print(s)
ans = 0
opt = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            cnt = 1
            for k in opt:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            ans = max(ans,cnt)
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
s =["#"*(w+2)] + ["#"+input()+"#" for i in range(h)] + ["#"*(w+2)]
# print(s)
ans = 1
opt = [(0,1),(0,-1),(1,0),(-1,0)]
s2 = [[0]*(w+2) for i in range(h+2)]
s3 = [[0]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "." and s2[i][j] == 0:
            cnt = 0
            for k in opt[0:2]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            for k in opt[0:2]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    s2[tempy+k[0]][tempx+k[1]] += cnt
                    tempy += k[0]
                    tempx += k[1]
            s2[i][j] += cnt
        if s[i][j] == "." and s3[i][j] == 0:
            cnt = 0
            for k in opt[2:4]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            for k in opt[2:4]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    s3[tempy+k[0]][tempx+k[1]] += cnt
                    tempy += k[0]
                    tempx += k[1]
            s3[i][j] += cnt
        ans = max(ans,1+s2[i][j]+s3[i][j])
# print(s2)
print(ans)
### BUGGY CODE ###

import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + (10**4))
dp[0] = 0
for a, b in AB:
    for n in range(H):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

print(min(dp[H:]))

### FIXED CODE ###

import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + (10**4))
dp[0] = 0
for a, b in AB:
    for n in range(H):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

print(min(dp[H:]))
### BUGGY CODE ###

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import queue

INF = float("inf")

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = queue.Queue()
		self.Q.put(s)
		self.dist = [INF] * N
		self.dist[s] = 0
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		self.prev = [None] * N
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.prev[i] = v
					self.Q.put(i)
					self.visit[i] = "Yes"

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, X, Y = getlist()
	G = Graph()
	G.add_edge(X - 1, Y - 1)
	G.add_edge(Y - 1, X - 1)
	for i in range(N - 1):
		G.add_edge(i, i + 1)
		G.add_edge(i + 1, i)

	ans = [0] * N
	for i in range(N):
		BF = BFS(G, i, N)
		for j in range(N):
			ans[BF.dist[j]] += 1

	# print(ans)
	for i in range(1, N):
		print(int(ans[i] // 2))




if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	N, X, Y = getlist()
	X -= 1; Y -= 1
	D = defaultdict(int)
	for i in range(N):
		for j in range(i + 1, N):
			var = min(j - i, abs(X - i) + abs(Y - j) + 1)
			D[var] += 1

	for i in range(1, N):
		print(D[i])




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

n,k = map(int, input().split())
p = [int(e) for e in input().split()]

max = 0
for i in range(n-k+1):
  j = i
  s = 0
  for _ in range(k):
    s += p[j]
    j += 1
  if max < s:
    max = s
    
print((max+k)/2.0)


### FIXED CODE ###

n,k = map(int, input().split())
p = [int(e) for e in input().split()]
s = sum(p[0:k])
max = s
for i in range(n-k):
  s = s - p[i] + p[i+k]
  if max < s:
    max = s
    
ex = (max+k)/2.0
print(ex)
### BUGGY CODE ###

from operator import mul #掛け算をする関数
from functools import reduce

# def cmb(n,r):
#     r = min(n-r,r) #nCrとnCn-rは等しいので小さい方を選ぶ
#     if r == 0: return 1 #nC0 = 1より
#     over = reduce(mul, range(n, n - r, -1))
#     under = reduce(mul, range(1,r + 1))
#     return over // under

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N, M, K = map(int, input().split())
ans = 0
col = M
mod = 998244353

for i in range(N)[::-1]:
    now = col
    # print('i:{}'.format(i))
    # print('col:{}'.format(col))
    now *= cmb(N-1,i)
    # print('cmb:{}'.format(cmb(N-1, i)))
    if i <= K:
        ans += now
        # print('\ni:{} now:{} ans:{}'.format(i, now, ans))
    col *= M-1

print(ans%mod)

### FIXED CODE ###

import sys

input = sys.stdin.readline

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

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

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = (fact[i-1] * i) % mod #n!を計算
# print('fact:{}'.format(fact))
revfact = [1] * (N + 1) #逆元を定義
revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算
# print('revfact:{}'.format(revfact))
for i in reversed(range(1, N)): #N-1から1まで
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
# print('revfact:{}'.format(revfact))

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)
### BUGGY CODE ###


def counting_sort(a, b, c, k):
	for i in range(1, k + 1):
		c[i] += c[i - 1]
	for i in range(len(a) - 1, -1, -1):
		c[a[i]] -= 1
		b[c[a[i]]] = a[i]
		
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
c = [0] * 10000
k = 0
for i in range(n):
	c[a[i]] += 1
	k = max(k, a[i])

counting_sort(a, b, c, k)
print(b[0], end='')
for i in range(1, n):
	print(' ' + str(b[i]), end='')
print()



### FIXED CODE ###

n=int(input())
A=[0]*(n+1)
B=[0]*(n+1)
i=0
mx=(1<<30)*-1
for v in list(map(int,input().split())):
	A[i+1] = v
	mx=max(mx,A[i+1])
	i+=1	

C=[0]*(mx+1)
for i in range(n):
	C[A[i+1]]+=1
for i in range(1,mx+1):
	C[i] += C[i-1]
for i in range(n,0,-1):
	B[C[A[i]]] = A[i]
	C[A[i]]-=1

st=str(B[1])
for i in range(2,n+1):
	st += ' ' + str(B[i])
print(st)
### BUGGY CODE ###

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

dp = [0]*n
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
  dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(i,k)+1)])
  
print(dp[-1])

### FIXED CODE ###

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

dp = [0]*n
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
  dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,min(i,k)+1)])
  
print(dp[-1])
### BUGGY CODE ###

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

ans = 0
for i1 in range(k+1):
    for i2 in range(k+1):
        for i3 in range(k+1):
            if i1 + i2 + i3 == s:
                ans += 1
print(ans)

### FIXED CODE ###

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

ans = 0
for i1 in range(min(k+1, s+1)):
    for i2 in range(0, min(k+1, s - i1 + 1)):
        if s - (i1 + i2) <= k:
            ans += 1

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

S = list(input())
T = [1 for i in range(len(S))]


for i in range(10**(5)):
  U = [0 for k in range(len(S))]
  U[1]+=T[0]
  U[len(S)-2]+=T[len(S)-1]
  for j in range(1,len(S)-1):
    if S[j]=='R':
      U[j+1]+=T[j]
    else:
      U[j-1]+=T[j]
  T = U
  
for i in T:
  print(i, end=' ')

### FIXED CODE ###

S=input()
#偶数回
#左右からfor
N=len(S)
odd=0
even=0
ans=[0]*N
for i in range(N-1):
    if i%2==0 and S[i]=="R":
        even+=1
    if i%2!=0 and S[i]=="R":
        odd+=1

    if S[i]=="R" and S[i+1]=="L":
        if i%2==0:
            ans[i]+=even
            ans[i+1]+=odd
        else:
            ans[i]+=odd
            ans[i+1]+=even
        odd=0
        even=0
odd=0
even=0
for i in range(N-1,0,-1):
    if i%2==0 and S[i]=="L":
        even+=1
    if i%2!=0 and S[i]=="L":
        odd+=1
    if S[i]=="L" and S[i-1]=="R":
        if i%2==0:
            ans[i]+=even
            ans[i-1]+=odd
        else:
            ans[i]+=odd
            ans[i-1]+=even
        odd=0
        even=0
print(*ans)
### BUGGY CODE ###

from bisect import bisect_left, bisect_right
from collections import defaultdict

N = int(input())
S = input()

pos = defaultdict(lambda: [])
for i, s in enumerate(S) :
  pos[s].append(i)

def color(a, b) :
  for c in 'RGB' :
    if c != S[a] and c != S[b] :
      return c

ret = 0
for a in range(N) :
  for b in range(a + 2, N) :
    if S[a] == S[b] : continue
    c = color(a, b)
    ret += bisect_right(pos[c], b) - 1
    ret -= bisect_right(pos[c], a) - 1
    if (a + b) % 2 == 0 and S[(a + b) // 2] == c :
      ret -= 1
      
print(ret)

### FIXED CODE ###

from collections import defaultdict
from itertools import permutations

N = int(input())
S = input()

pos = defaultdict(lambda: [])
for i, s in enumerate(S) :
  pos[s].append(i)

ret = 0
for a, b, c in (permutations('RGB')) :
  for center in pos[b] :
    cnt = [0] * (N + 1)
    left, right = 0, 0
    for l in pos[a] :
      if l >= center :
        break
      cnt[center-l] += 1
      left += 1
    for r in pos[c][::-1] :
      if r <= center :
        break
      cnt[r-center] += 1
      right += 1
    ret += left * right - cnt.count(2)
     

  
print(ret)
### BUGGY CODE ###

a, b, k = map(int, input().split())
ans =  [i for i in range(a, b + 1) if a <= i < a + k or b - k < i <=b]
for e in ans:
  print(e)

### FIXED CODE ###

a, b, k = map(int, input().split())
ans = []
for i in range(k):
  if a + i <= b:
    ans.append(a + i)
  if b - i >= a:
    ans.append(b - i) 
for i in sorted(set(ans)):
    print(i)
### BUGGY CODE ###

import sys

def biser(lst,func):
    n=len(lst)
    nh=n//2
    if n==1:
        if func(lst[0]):
            return lst[0]
        else:
            return -1
    if func(lst[nh]):
        return biser(lst[nh:],func)
    else:
        return biser(lst[:nh],func)

def mkns(a,s,m):
    if a==0:
        return s
    else:
        return (((s+1)<<a)|s) & m

def main():
    N,K=map(int,sys.stdin.readline().strip().split())
    a=list(map(int,sys.stdin.readline().strip().split()))
    a.sort()
    ss=[0]*(N+1)
    pm=(1<<K)-1
    mask=lambda c:(1<<K)-(1<<c)
    nn=0
    for i in range(N):
        ss[i+1]=mkns(a[i],ss[i],pm)
    def isunnec(i):
        if a[i]>=K:
            return False
        for j in range(i+1,N):
            if a[j]>=K:
                break
            ss[i]=mkns(a[j],ss[i],pm)
        if ss[i]&mask(K-a[i])==0:
            return True
        return False
    nn=biser(list(range(N)),isunnec)+1
    print(nn)

if __name__=='__main__':
    main()


### FIXED CODE ###

#4 9
#1 3 5 6
#の時に1（正解は0）と出力されるがACになる

N, K = map(int, input().split())
a=list(map(int, input().split()))
a.sort()
ans = N
t = 0
for i in range(N-1, -1, -1) :
  if t+a[i] < K:
    t += a[i]
  else:
    ans = min(ans, i)
print(ans)
### BUGGY CODE ###

num, K, *line = map(int, open(0).read().split())

dp = [float("inf")]* num
dp[0] = 0
 
for i in range(1, num):
  I = min(i + 1 , K + 1)
  dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , I)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
print(dp[-1])

### FIXED CODE ###

def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()
### BUGGY CODE ###

def handstand2(n):
    c = 0
    for i in range(10):
        for j in range(10):
            c_i_j = 0
            c_j_i = 0
            for k in range(n):
                if str(k+1)[0] == str(i) and str(k+1)[-1] == str(j):
                    c_i_j += 1
                if str(k+1)[0] == str(j) and str(k+1)[-1] == str(i):
                    c_j_i += 1
            c += c_i_j * c_j_i
    return c

n = int(input())

print(handstand2(n))

### FIXED CODE ###

def handstand2(n):
    c = 0
    c_list = [[0 for j in range(10)] for i in range(10)]

    for k in range(n):
        c_list[int(str(k+1)[0])][int(str(k+1)[-1])] += 1

    for i, _ in enumerate(c_list):
        for j, c_i_j in enumerate(_):
            c += c_i_j*c_list[j][i]
    return c

n = int(input())

print(handstand2(n))
### BUGGY CODE ###

N = int(input())
A = []
B = []
for _ in range(N):
    s = input().split()
    A.append(int(s[0]))
    B.append(int(s[1]))

def set_list(es):
    return len(list(set(es))) == 1

ind = 0

a_happy = 0
b_happy = 0

for i in range(N):
    if i%2 == 0:
        if set_list(A):
            ind = B.index(max(B))
        else:
            ind = A.index(max(A))
        a_happy += A[ind]
        A.pop(ind)
        B.pop(ind)
    if i%2 == 1:
        if set_list(B):
            ind = A.index(max(A))
        else:
            ind = B.index(max(B))
        b_happy += B[ind]
        A.pop(ind)
        B.pop(ind)
    #print(a_happy, b_happy)

print(a_happy - b_happy)


### FIXED CODE ###

import numpy as np

N = int(input())
C = []
for _ in range(N):
    a, b = map(int, input().split())
    C.append([a+b, a, b])

D = sorted(C, reverse=True)

ans = 0

for i in range(N):
    if i % 2 == 0:
        ans += D[i][1]
    elif i % 2 == 1:
        ans -= D[i][2]

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


def main():
    M = 2019
    s = input()

    x = 0
    dp = [0] * M
    for c in s:
        dp2 = [0] * M
        for j in range(M):
            dp2[(j*10 + int(c)) % M] += dp[j]
        dp2[int(c)] += 1
        dp = dp2
        x += dp[0]
    print(x)

main()


### FIXED CODE ###

M = 2019
dp = [0] * M
s = input()
x = 0
for c in s:
    c = int(c)
    dp2 = [0] * M
    for j in range(M):
        index = (j*10 + c) % M
        dp2[index] += dp[j]
    dp = dp2
    dp[c] += 1
    x += dp[0]
print(x)
### BUGGY CODE ###

import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
n = int(input())
#n, k = map(int, sys.stdin.readline().split())
s = input()
#a = list(map(int, sys.stdin.readline().split()))


r = []
g = []
b = []

for i in range(n):
    if s[i] == "R":
        r.append(i)
    elif s[i] == "G":
        g.append(i)
    else:
        b.append(i)

R = len(r)
G = len(g)
B = len(b)

if min(R, G, B) == R:
    if max(R, G, B) == G:
        w = r
        x = b
        y = g
    else:
        w = r
        x = g
        y = b
elif min(R, G, B) == G:
    if max(R, G, B) == R:
        w = g
        x = b
        y = r
    else:
        w = g
        x = r
        y = b
else:
    if max(R, G, B) == R:
        w = b
        x = g
        y = r
    else:
        w = b
        x = r
        y = g


ans = 0
z = len(y)
for i in range(len(w)):
    for j in range(len(x)):
        d = abs(w[i] - x[j])
        e = 0
        p = min(w[i], x[j]) - d
        q = max(w[i], x[j]) + d
        if (w[i] + x[j]) % 2 == 0:
            t = int((w[i] + x[j]) / 2)
        else:
            t = 10000
        if p in y:
            e += 1
        if q in y:
            e += 1
        if t in y:
            e += 1

        ans += (z - e)

print(ans)
            

    


### FIXED CODE ###

import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
n = int(input())
#n, k = map(int, sys.stdin.readline().split())
s = input()
#a = list(map(int, sys.stdin.readline().split()))

def main():
    r = []
    g = []
    b = []

    for i in range(n):
        if s[i] == "R":
            r.append(i)
        elif s[i] == "G":
            g.append(i)
        else:
            b.append(i)


    ans = 0
    z = len(b)
    for i in range(len(r)):
        for j in range(len(g)):
            d = abs(r[i] - g[j])
            e = 0
            p = min(r[i], g[j]) - d
            q = max(r[i], g[j]) + d
            if (r[i] + g[j]) % 2 == 0:
                t = int((r[i] + g[j]) / 2)
                if p >= 0:
                    if s[p] == "B":
                        e += 1
                if q < n:
                    if s[q] == "B":
                        e += 1
                if s[t] == "B":
                    e += 1
            else:
                if p >= 0:
                    if s[p] == "B":
                        e += 1
                if q < n:
                    if s[q] == "B":
                        e += 1

            ans += (z - e)

    print(ans)
            
main()