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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ctr= [0 for _ in range(N)]

A.sort()
B.sort()
C.sort()

# A固定
cur = 0

for i in range(N):
	for j in range(cur, N):
		if B[i] < C[j]:
			ctr[i] += N - j
			cur = j
			break
			
cur = 0
ans = 0
for i in reversed(range(1, N)):
	ctr[i - 1] += ctr[i]
for i in range(N):
	for j in range(cur, N):
		if A[i] < B[j]:
			ans += ctr[j]
			cur = j
			break
			
print(ans)

### FIXED CODE ###

import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ctr= [0 for _ in range(N)]

A.sort()
B.sort()
C.sort()

ans = 0

for i in range(N):
	insert_index_A = bisect.bisect_left(A, B[i])
	insert_index_C = N - bisect.bisect_right(C, B[i])
	ans += insert_index_A * insert_index_C
	
print(ans)
### BUGGY CODE ###

#2019/10/25
NQ, S, *lr = [s for s in open(0)]
# print(NQ, S, lr)
N, Q = map(int, NQ.split())
lr = [list(map(int, i.split())) for i in lr]
# print(N,Q,S,lr)
cnt=0
for l, r in lr:
    print(S[l-1:r].count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
# print(S)
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
#     print(i, t[i+1], t[i], S[i:i+2])
# print(t)

for i in range(Q):
    l, r = map(int, input().split())
#     print(r,l,t[r-1],t[l-1])
    print(t[r-1] - t[l-1])
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
XY=[]

for a in A:
    for b in B:
        XY.append(a+b)
XY.sort(reverse=True)
XY=XY[:K]
XYZ=[]
for xy in XY:
    for c in C:
        XYZ.append(xy+c)
XYZ.sort(reverse=True)
for i in range(K):
    print(XYZ[i])


### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
xy=[]
for a in A:
    for b in B:
        xy.append(a+b)
xy=sorted(xy,reverse=True)
xy=xy[:K]
xyz=[]
for c in C:
    for x in xy:
        xyz.append(x+c)
xyz=sorted(xyz,reverse=True)
for i in range(K):
    print(xyz[i])
### BUGGY CODE ###

import sys
import numpy as np

h, w = list(map(int, input().split()))
field = [line.rstrip() for line in sys.stdin]

l = [[0] * (w + 2) for _ in [0] * (h + 2)]
r = [[0] * (w + 2) for _ in [0] * (h + 2)]
u = [[0] * (w + 2) for _ in [0] * (h + 2)]
d = [[0] * (w + 2) for _ in [0] * (h + 2)]

for i in range(1, h + 1):
    fi = field[i - 1]
    l_tmp = 0
    li = l[i]
    for j in range(1, w + 1):
        c = fi[j - 1]
        u[i][j] = u[i - 1][j] + 1 if c == '.' else 0
        li[j] = l_tmp = l_tmp + 1 if c == '.' else 0
for i in range(h, 0, -1):
    fi = field[i - 1]
    r_tmp = 0
    ri = r[i]
    for j in range(w, 0, -1):
        c = fi[j - 1]
        d[i][j] = d[i + 1][j] + 1 if c == '.' else 0
        ri[j] = r_tmp = r_tmp + 1 if c == '.' else 0

print(sum(map(np.array, [l, r, u, d])).max() - 3)


### FIXED CODE ###

import sys

h, w = list(map(int, input().split()))
field = [line.rstrip() for line in sys.stdin]

l = [[0] * (w + 2) for _ in [0] * (h + 2)]
r = [[0] * (w + 2) for _ in [0] * (h + 2)]
u = [[0] * (w + 2) for _ in [0] * (h + 2)]
d = [[0] * (w + 2) for _ in [0] * (h + 2)]

for i in range(1, h + 1):
    fi = field[i - 1]
    li = l[i]
    for j in range(1, w + 1):
        c = fi[j - 1]
        u[i][j] = u[i - 1][j] + 1 if c == '.' else 0
        li[j] = li[j - 1] + 1 if c == '.' else 0
for i in range(h, 0, -1):
    fi = field[i - 1]
    ri = r[i]
    for j in range(w, 0, -1):
        c = fi[j - 1]
        d[i][j] = d[i + 1][j] + 1 if c == '.' else 0
        ri[j] = ri[j + 1] + 1 if c == '.' else 0

ans = 0
for i in range(1, h + 1):
    li, ri, ui, di = l[i], r[i], u[i], d[i]
    ans = max(ans, max(li[j] + ri[j] + ui[j] + di[j] for j in range(1, w + 1)))
print(ans - 3)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
for _ in range(n):
  b=a[0:_]+a[_+1:n]
  print(max(b))


### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a)
f=b[-1]
s=b[-2]
for ans in a:
  if ans < f:
    print(f)
  else:
    print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

s = input().strip()
q=int(input())
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        s = s[::-1]
    else:
        a,b,c = L
        if int(b)==2:
            s+=c
        else:
            v = list(s)
            v.insert(0,c)
            s = "".join(v)
print(s)
            
            


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
maxI = 0
maxT = 0
t = 0
for i in range(n):
    t += p[i]
    if k <= i:
        t -= p[i-k]
    if maxT < t:
        maxT = t
        maxI = i
ans = 0


def calc(n):
    ans = 0
    for i in range(1, n+1):
        ans += i/n
    return ans


for i in range(maxI-k+1, maxI+1):
    #print(i, p[i])
    ans += calc(p[i])
# print(p)
#print(maxT, maxI)
print(ans)


### FIXED CODE ###

# ABC154d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    pos = 0

    def cum(array):
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    def calc(N):
        t = 0
        for i in range(1, N+1):
            t += i / N
        return t

    p2 = cum(p)

    for i in range(n - k+1):
        if ans < p2[i+k]-p2[i]:
            ans = p2[i+k]-p2[i]
            pos = i

    ans = 0
    for i in range(pos, pos + k):
        ans += calc(p[i])
    print(ans)


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

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = [_I() for i in range(N)]

"""
何個色を使えば塗れるか
最も小さい数字からはじめれば？
最も左からはじめれば？
"""

def bisect(arr, val, cmp):
    l = -1
    r = len(arr)
    while r - l > 1:
        e = (l + r) >> 1
        if cmp(arr[e], val): l = e
        else: r = e
    return r

res = [] 
for a in A:
    #  print('a res', a, res)
    if len(res) == 0:
        res.append(a)
    else:
        if a <= res[-1]:
            # 小さいので追加
            res.append(a)
        else:
            # 入れ替え
            p = bisect(res, a, lambda x, y: x > y)
            while res[p] == a:
                p+=1
            else:
                res[p] = a

print(len(res))


### FIXED CODE ###

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = [_I() for i in range(N)]

"""
何個色を使えば塗れるか
最も小さい数字からはじめれば？
最も左からはじめれば？
"""

def bisect(arr, val, cmp):
    l = -1
    r = len(arr)
    while r - l > 1:
        e = (l + r) >> 1
        if cmp(arr[e], val): l = e
        else: r = e
    return r

res = [] 
for a in A:
    #  print('a res', a, res)
    if len(res) == 0:
        res.append(a)
    else:
        if a <= res[-1]:
            # 小さいので追加
            res.append(a)
        else:
            # 入れ替え
            p = bisect(res, a, lambda x, y: x > y)
            if res[p] == a:
                p = bisect(res, a-1, lambda x, y: x > y)
                res[p] = a
            else:
                res[p] = a

print(len(res))
### BUGGY CODE ###

import math
n,k=map(int,input().split())
if n%k==0:
    print(0)
else:
    while n>abs(n-k):
        n=abs(n-k)
    print(n)
            

### FIXED CODE ###

import math
n,k=map(int,input().split())
n=n%k
while n>abs(n-k):
    n=abs(n-k)
print(n)
### BUGGY CODE ###

n = int(input())
a = input().split()
q = int(input())

for i in range(q):
    stdins = input().split()
    for j in range(n):
        a[j] = a[j].replace(stdins[0], stdins[1])
    ans = sum([int(an) for an in a])
    print(ans)


### FIXED CODE ###

n = int(input())
a = input().split()

a_cnts = {}
a_sum = 0
for an in a:
    if an in a_cnts.keys():
        a_cnts[an] += 1
    else:
        a_cnts[an] = 1
    a_sum += int(an)

q = int(input())

for i in range(q):
    (b, c) = input().split()

    if b in a_cnts.keys():
        hit_cnt = a_cnts[b]
        del a_cnts[b]
        if c in a_cnts.keys():
            a_cnts[c] += hit_cnt
        else:
            a_cnts[c] = hit_cnt
        a_sum += (int(c) - int(b))*hit_cnt

    print(a_sum)
### BUGGY CODE ###

H = int(input())

cnt = H
B = [H]
for i in range(1000000000):
    cnt = cnt//2
    B.append(cnt)
    if cnt == 1:
        break

C =[1]
for i in range(1,100):
    C.append(C[i-1]*2)

ans= 0
for i in range(len(B)):
    ans +=C[i]
print(ans)

### FIXED CODE ###

H = int(input())
cnt = H
ans = 0
B = [H]

if H == 1:
    ans == 'NA'
else:
    for i in range(100000000000):
        cnt = cnt//2
        B.append(cnt)
        if cnt == 1:
            break

C =[1]
for i in range(1,1001):
    C.append(C[i-1]*2)

if ans == 'NA':
    print('0')
else:
    for i in range(len(B)):
        ans +=C[i]
print(ans)
### BUGGY CODE ###

A=input()
B=input()
C=input()
s="a"
while len(A)!=0 and len(B)!=0 and len(C)!=0:
  if s=="a":
    if A[0]=="b":
      s="b"
      continue
    if A[0]=="c":
      s="c"
      continue
  elif s=="b":
    if B[0]=="c":
      s="c"
      continue
    if B[0]=="a":
      s="a"
      continue
  else:
    if C[0]=="a":
      s="a"
      continue
    if C[0]=="b":
      s="b"
      continue
if len(A)==0:
  print("A")
elif len(B)==0:
  print("B")
else:
  print("C")

### FIXED CODE ###

A=input()
B=input()
C=input()
s="a"
while (len(A)!=0 or s!="a") and (len(B)!=0 or s!="b") and (len(C)!=0 or s!="c"):
  if s=="a":
    s=A[0]
    A=A[1:]
  elif s=="b":
    s=B[0]
    B=B[1:]
  else:
    s=C[0]
    C=C[1:]
if len(A)==0 and s=="a":
    print("A")
elif len(B)==0 and s=="b":
    print("B")
else:
    print("C")
### BUGGY CODE ###

S = input()
N = int(input())
for i in range(N):
    A = input().split()
    if len(A) == 1:
        S = S[::-1]
    elif A[1] == '1':
        S = A[2] + S
    else:
        S += A[2]
print(S)



### FIXED CODE ###

S = input()
N = int(input())
line = [''] * (N+1) * 2
rev = False
pos = N
line[pos] = S
leftPos = pos - 1
rightPos = pos + 1

for i in range(N):
    A = input().split()
    if len(A) == 1:
        rev = not rev
    else:
        if A[1] == '1':
            if rev == False:
                pos = leftPos
                leftPos -= 1
            else:
                pos = rightPos
                rightPos += 1
        else:
            if rev == False:
                pos = rightPos
                rightPos += 1
            else:
                pos = leftPos
                leftPos -= 1
        line[pos] = A[2]

ans = line[leftPos+1:rightPos]
ans = "".join(ans)
if rev == False:
    print(ans)
else:
    print(ans[::-1])
### BUGGY CODE ###

N = int(input())

M = 100000

c = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]


cache = {}


def solve(x, l):
    if len(l) == 0:
        return 10000000000

    if x in cache:
        if len(l) in cache[x]:
            return cache[x][len(l)]

    t = l[0]
    if x // t > 0:
        res = []
        for i in range(x // t + 1):
            count = i
            rest = x - (t * i)
            if rest == 0:
                return count

            val = solve(rest, l[1:])
            if rest not in cache:
                cache[rest] = {}
            cache[rest][len(l[1:])] = val
            res.append(count + val)
        return min(res)
    else:
        val = solve(x, l[1:])
        if x not in cache:
            cache[x] = {}
        cache[x][len(l[1:])] = val
        return val


# for i in range(10):
#     val = 9 ** i
#     if val <= M:
#         print(val)
#         c.append(val)
#
# for i in range(10):
#     val = 6 ** i
#     if val <= M:
#         print(val)
#         c.append(val)

# count = 0

result = solve(N, c)
# for i in c:
#     if rest // i > 0:
#         count += rest // i
#         print(str(i) + ', ' + str(rest // i) + ' times, rest = ' + str(rest % i))
#         rest = rest % i
#
#     if rest == 0:
#         break

print(result)


### FIXED CODE ###

# https://atcoder.jp/contests/abc099/tasks/abc099_c

def main():
    max_val = 10**5 + 1
    dp = [i for i in range(max_val)]

    for i in range(max_val):
        p = 1
        while p < max_val:
            dp[i] = min(dp[i], dp[i - p] + 1)
            p *= 6
        p = 1
        while p < max_val:
            dp[i] = min(dp[i], dp[i - p] + 1)
            p *= 9

    N = int(input())
    print(dp[N])


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

import queue
q=queue.Queue()
l=[]
n,m=map(int,input().split())
for i in range(m):
  p=int(input())
  q.put(p)
que=q.get()
for j in range(n+1):
  if j==0:
    l.append(1)
  elif j==1 and que!=1:
    l.append(1)
  elif j==que:
    l.append(0)
    que=q.get()
  else:
    l.append(l[j-2]+l[j-1])
print(l[n]%(10**9+7))

### FIXED CODE ###

n,m=map(int,input().split())
broken=[]
for i in range(m):
  broken.append(int(input()))
b=set(broken)
l=[1]
for j in range(1,n+1):
  if j in b:
    l.append(0)
  elif j==1:
    l.append(1)
  else:
    l.append(l[j-2]+l[j-1])
print(l[n]%(10**9+7))
### BUGGY CODE ###

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(S, i):
    D = [-1] * len(S)
    P = [set() for _ in range(len(S))]

    Q = deque()
    Q.append(i)
    D[i] = 1

    while Q:
        v = Q.popleft()

        for w in S[v]:
            if w in P[v]:
                continue
            
            if D[w] > 0 and D[w] < D[v] + 1:
                return -1

            P[w].add(v)
            D[w] = D[v] + 1
            Q.append(w)
    return D[v]


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    L = [set(j for j in range(N) if S[i][j] == "1") for i in range(N)]

    res = -1
    for i in range(N):
        r = f(L, i)
        res = max(res, r) 
    
    print(res)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(S, i):
    D = [-1] * len(S)
    P = [set() for _ in range(len(S))]
    
    Q = deque()
    Q.append(i)
    D[i] = 1

    while Q:
        v = Q.popleft()

        for w in S[v]:
            if w in P[v]:
                continue
            
            if D[w] > 0 and D[w] < D[v] + 1:
                return -1

            if D[w] < 0:
                Q.append(w)
            P[w].add(v)
            D[w] = D[v] + 1

    return D[v]


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    L = [set(j for j in range(N) if S[i][j] == "1") for i in range(N)]

    res = -1
    for i in range(N):
        r = f(L, i)
        res = max(res, r) 
    
    print(res)


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

from queue import Queue
import sys
input = sys.stdin.readline
INF = -1
H, W = map(int,input().split())
d = [[INF for i in range(W)] for j in range(H)]
tx = [1, 0, -1, 0]
ty = [0, 1, 0, -1]

q = Queue()
for i in range(H):
    line = list(input())
    for j in range(W):
        if line[j] == '#':
            d[i][j] = 0
            q.put([i, j, 0])

ans = 0

while not q.empty():
    p = q.get()
    ans = max(ans, p[2])
    for i in range(4):
        nx = p[0] + tx[i]
        ny = p[1] + ty[i]
        if 0 <= nx <= H-1 and 0 <= ny <= W-1 and d[nx][ny] == INF:
            d[nx][ny] = p[2] + 1
            q.put([nx, ny, p[2]+1])

print(ans)

### FIXED CODE ###

from collections import deque
INF = -1
H, W = map(int,input().split())
d = [[INF for i in range(W)] for j in range(H)]
tx = [1, 0, -1, 0]
ty = [0, 1, 0, -1]

q = deque()
for i in range(H):
    line = list(input())
    for j in range(W):
        if line[j] == '#':
            d[i][j] = 0
            q.append([i, j, 0])

ans = 0

while len(q) > 0:
    p = q.popleft()
    ans = max(ans, p[2])
    for i in range(4):
        nx = p[0] + tx[i]
        ny = p[1] + ty[i]
        if 0 <= nx <= H-1 and 0 <= ny <= W-1 and d[nx][ny] == INF:
            d[nx][ny] = p[2] + 1
            q.append([nx, ny, p[2]+1])

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

class UnionFind():
  def __init__(self,n):
    self.parents = [-1]*n
  
  def find(self,x):
    if self.parents[x] < 0:
      return x
    
    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

import numpy as np

N,M=map(int,input().split())
uf = UnionFind(N+1)

ans_max=(N)*(N-1)//2
ans=[]
A=[]
B=[]

for i in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)

A=A[::-1]
B=B[::-1]

for i in range(M):
  temp=np.array(uf.parents)
  temp_sum=sum(abs(temp[temp<0])*(abs(temp[temp<0])-1)//2)
  ans.append(ans_max-temp_sum)
  uf.union(A[i],B[i])  

ans=ans[::-1]
for i in range(M):
  print(ans[i])

### FIXED CODE ###

class UnionFind():
  def __init__(self,n):
    self.parents = list(range(n))
    self.size = [1]*n
  
  def find(self,x):
    if self.parents[x] == x:
      return x
	
    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]:
      x,y=y,x
	
    self.size[x]+=self.size[y]
    self.parents[y] = x
  
  def same(self,x,y):
    return self.find(x) == self.find(y)
  
  def sizeofset(self,x):
    return self.size[self.find(x)]


N,M=map(int,input().split())
uf = UnionFind(N+1)

cnt=(N)*(N-1)//2
L=[[int(x) for x in input().split()] for _ in range(M)]
ans=[]

for a,b in L[::-1]:
  ans.append(cnt)
  if not uf.same(a,b):
    cnt -= uf.sizeofset(a)*uf.sizeofset(b)
    uf.union(a,b)

for x in ans[::-1]:
  print(x)
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
ans = 0
for i in range(q):
  l,r = map(int,input().split())
  m = s[l-1:r]
  for j in range(r-l):
      if m[j]=='A' and m[j+1]=='C':
          ans += 1
  print(ans)
  ans = 0


### FIXED CODE ###

from itertools import accumulate


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

flg = []
for i in range(N-1):
    tmp_s = S[i:i+2]
    if tmp_s == 'AC':
        flg.append(1)
    else:
        flg.append(0)

flg2 = [0] + flg
flg2 = list(accumulate(flg2))

for a in A:
    print(flg2[a[1]-1] - flg2[a[0]-1])
### BUGGY CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0]*(1<<n)
ans[0] = 1
mod = 10**9 + 7

def popcnt(x):
  ret = 0
  for i in range(n):
    if x & (1<<i):
      ret += 1
  return ret

for bit in range(1<<n):
  if ans[bit]:
    i = popcnt(bit)
    v = 1
    for j in range(n):
      if not bit & v and a[i][j]:
        ans[bit|v] = (ans[bit|v] + ans[bit])%mod
      v <<= 1
print(ans[-1])

### FIXED CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0]*(1<<n)
ans[0] = 1
mod = 10**9 + 7

def popcnt(x):
  ret = 0
  for i in range(n):
    if x & (1<<i):
      ret += 1
  return ret

for bit in range(1<<n):
  if ans[bit]:
    i = popcnt(bit)
    v = 1
    for j in range(n):
      if not bit & v and a[i][j]:
        ans[bit|v] = (ans[bit|v] + ans[bit])%mod
      v <<= 1
print(ans[-1])
### BUGGY CODE ###

import bisect
N = int(input())
Ls = list(map(int, input().split()))
 
sls = sorted(Ls)
count = 0
for i, a in enumerate(sls):
    for j, b in enumerate(sls[i+1:]):
        cs = sls[i+j+2:]
        cmin, cmax = b - a, b + a
        left, right = bisect.bisect_right(cs, cmin), bisect.bisect_left(cs, cmax)
        count += (right - left)
print(count)

### FIXED CODE ###

import bisect
N = int(input())
Ls = list(map(int, input().split()))

sls = sorted(Ls)
count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        a, b = sls[i], sls[j]
        right = bisect.bisect_left(sls, b + a)
        count += right - j - 1
print(count)