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

from collections import deque
import sys
sys.setrecursionlimit(10**8)

def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1
    S = [list(input()) for _ in range(H)]
    visited = [[False] * W for _ in range(H)]
    cnt = [[float('inf')] * W for _ in range(H)]
    dh = [1,0,-1,0]
    dw = [0,1,0,-1]
    visited[Ch][Cw] = True
    cnt[Ch][Cw] = 0
    Q = deque([[Ch,Cw]])
    while Q:
        h, w = Q.popleft()
        if h == Dh and w == Dw:
            break
        for i in range(4):
            nh = h + dh[i]
            nw = w + dw[i]
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                if visited[nh][nw] == False:
                    cnt[nh][nw] = cnt[h][w]
                    visited[nh][nw] = True
                    Q.append([nh,nw])
                else:
                    if cnt[nh][nw] > cnt[h][w]:
                        cnt[nh][nw] = cnt[h][w]
                        Q.append([nh,nw])
        for j in range(-2,3):
            for k in range(-2,3):
                nh = h + j
                nw = w + k
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                    if cnt[nh][nw] > cnt[h][w]:
                        cnt[nh][nw] = cnt[h][w] + 1
                        visited[nh][nw] = True
                        Q.append([nh,nw])

    if cnt[Dh][Dw] == float('inf'):
        print(-1)
    else:
        print(cnt[Dh][Dw])




if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**8)

def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1
    S = [list(input()) for _ in range(H)]
    visited = [[False] * W for _ in range(H)]
    cnt = [[float('inf')] * W for _ in range(H)]
    dh = [1,0,-1,0]
    dw = [0,1,0,-1]
    visited[Ch][Cw] = True
    cnt[Ch][Cw] = 0
    Q = deque([[Ch,Cw]])
    while Q:
        h, w = Q.popleft()
        c = cnt[h][w]
        if h == Dh and w == Dw:
            break
        for i in range(4):
            nh = h + dh[i]
            nw = w + dw[i]
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                if cnt[nh][nw] > c:
                    cnt[nh][nw] = c
                    Q.appendleft([nh,nw])
        nc = c + 1
        for j in range(-2,3):
            for k in range(-2,3):
                nh = h + j
                nw = w + k
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                    if cnt[nh][nw] > nc:
                        cnt[nh][nw] = nc
                        Q.append([nh,nw])

    if cnt[Dh][Dw] == float('inf'):
        print(-1)
    else:
        print(cnt[Dh][Dw])




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

check=dict()
N,b,d=0,[],0
#ttfは235、chaはabc
inf=10**(30)
def dfs_sub(n,ttf,cha):
    global check,d
    check[0]=min(check[n]+n*d,check.get(0,inf))
    if n//ttf==0:
        check[n//ttf]=min(check.get(n//ttf,inf),check[n]+(n%ttf)*d)
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global b,check,d
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0}
    dfs(N)
    print(check[0])

### FIXED CODE ###

import sys
check=dict()
N,a,b,c,d=0,0,0,0,0
#ttfは235、chaはabc
def dfs_sub(n,ttf,cha):
    global check,d
    if 0 in check:
        check[0]=min(check[n]+n*d,check[0])
    else:
        check[0]=check[n]+n*d
    if n//ttf==0:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d:
                check[n//ttf]=check[n]+(n%ttf)*d
        else:
            check[n//ttf]=check[n]+(n%ttf)*d
    else:
        if n//ttf in check:
            if check[n//ttf]>check[n]+(n%ttf)*d+cha:
                check[n//ttf]=check[n]+(n%ttf)*d+cha
                dfs(n//ttf)
        else:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global check,a,b,c,d
    dfs_sub(n,2,a)
    dfs_sub(n,3,b)
    dfs_sub(n,5,c)

t=int(input())
ans=[0]*t
for i in range(t):
    N,a,b,c,d=map(int,input().split())
    check={N:0}
    dfs(N)
    ans[i]=check[0]
for i in range(t):
    print(ans[i])
### BUGGY CODE ###

def main():
    buttons = int(input())
    next_lighten_up = [int(input()) for _ in range(buttons)]
    searched = [1]
    answer = 1
    while True:
        if next_lighten_up[searched[-1] - 1] == 2:
            break
        elif next_lighten_up[searched[-1] - 1] in searched:
            answer = -1
            break
        else:
            answer += 1
            searched.append(next_lighten_up[searched[-1] - 1])
    print(answer)


if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    buttons = int(input())
    next_lighten_up = [int(input()) for _ in range(buttons)]
    searched = [False] * (buttons + 1)
    answer = 1
    index = 1
    while True:
        if next_lighten_up[index - 1] == 2:
            break
        elif searched[next_lighten_up[index - 1]]:
            answer = -1
            break
        else:
            searched[next_lighten_up[index - 1]] = True
            answer += 1
            index = next_lighten_up[index - 1]
    print(answer)


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

h,w = map(int,input().split())
S = [input() for i in range(h)]

A = [[[0,0] for i in range(w)] for j in range(h)]

a = -1
b = -1
for i in range(h):
    a = -1
    for j in range(w):
        if S[i][j] == "#":
            if a != -1:
                for k in range(a,j):
                    A[i][k][0] = j-a
                a = -1
        else:
            if a == -1:
                a = j
                #print(j)
    if a != -1:
        for k in range(a,j+1):
            A[i][k][0] = j+1-a

for i in range(w):
    a = -1
    for j in range(h):
        if S[j][i] == "#":
            if a != -1:
                for k in range(a,j):
                    A[k][i][1] = j-a
                a = -1
        else:
            if a == -1:
                a = j
    if a != -1:
        for k in range(a,j+1):
            A[k][i][1] = j+1-a
#print(A)

ans = 0
for i in range(h):
    for j in range(w):
        su = sum(A[i][j])
        ans = max(ans, su)

print(ans-1)

### FIXED CODE ###

h,w = map(int,input().split())
S = [input() for i in range(h)]

A = [[0 for i in range(w)] for j in range(h)]

a = -1
b = -1
for i in range(h):
    a = -1
    for j in range(w):
        if S[i][j] == "#":
            if a != -1:
                for k in range(a,j):
                    A[i][k] += j-a
                a = -1
        else:
            if a == -1:
                a = j
                #print(j)
    if a != -1:
        for k in range(a,j+1):
            A[i][k] += j+1-a

for i in range(w):
    a = -1
    for j in range(h):
        if S[j][i] == "#":
            if a != -1:
                for k in range(a,j):
                    A[k][i] += j-a
                a = -1
        else:
            if a == -1:
                a = j
    if a != -1:
        for k in range(a,j+1):
            A[k][i] += j+1-a
#print(A)

ans = 0
for i in range(h):
    ans = max(ans, max(A[i]))

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

def update_points(points, current_ansewr):
    return list(
        map(
            lambda x: x[1] if (x[0] + 1) == current_ansewr else x[1] - 1,
            enumerate(points),
        )
    )


N, K, Q = [int(i) for i in input().split()]
points = [K] * N
for _ in range(Q):
    answer = int(input())
    points = update_points(points, answer)
for p in points:
    print("Yes" if p > 0 else "No")


### FIXED CODE ###

N, K, Q = [int(i) for i in input().split()]
points = [(K - Q)] * N
for _ in range(Q):
    answer = int(input())
    points[answer - 1] += 1
for p in points:
    print("Yes" if p > 0 else "No")
### BUGGY CODE ###

import itertools
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a, b, c, d))

max_score = 0
for p in itertools.product(range(1, m + 1), repeat=n):
    if any(p[i] > p[i + 1] for i in range(n - 1)):
        continue
    score = 0
    for a, b, c, d in queries:
        if p[b - 1] - p[a - 1] == c:
            score += d
    max_score = max(score, max_score)
print(max_score)


### FIXED CODE ###

import itertools
n, m, q = map(int, input().split())
queries = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    queries.append((a, b, c, d))

max_score = 0

p = [1] * n
cur = n-1
while cur >= 0:
    score = 0
    for a, b, c, d in queries:
        if p[b - 1] - p[a - 1] == c:
            score += d
    max_score = max(score, max_score)
    updated = False
    for i in range(n - 1, -1, -1):
        if p[i] != m:
            p[i] += 1
            for j in range(i + 1, n):
                p[j] = p[i]
            updated = True
            break
    if not updated:
        break

print(max_score)
### BUGGY CODE ###

# coding: utf-8
import math
memo={}
def f(x,y,Y):
    if (x,y,Y) in memo:
        return memo[(x,y,Y)]
    ans=0
    if x==0:
        memo[(x,y,Y)]=1
        return 1
    for i in range(y,Y):
        tmp=f(x-1,i,Y)
        memo[(x-1,i,Y)] = tmp
        ans+=tmp
    memo[(x,y,Y)] = ans
    return ans
n,m=map(int,input().split())
s=2
d=[]
count=0
while s<=m:
    if m%s==0:
        m//=s
        count+=1
    else:
        if count:
            d.append(count)
        count=0
        s+=1
d.append(count)
ans=1
d=sorted(d)[::-1]
for x in d:
    ans = (ans*f(x,0,n))%(10**9+7)
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
memo={}
def primes(n):
    primefac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            if d in memo:
                memo[d]+=1
            else:
                memo[d]=1
            n //= d
        d += 1
    if n > 1:
        if n in memo:
            memo[n]+=1
        else:
            memo[n]=1
primes(m)

def cmb(n,r,mod):
    if (r<0 or r>n):
        return 0
    r = min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

mod = 10**9+7
N = 10**5*2
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]

for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

ans=1
for x in memo.items():
    ans*=cmb(x[1]+n-1,x[1],mod)
    ans%=mod

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

while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    D = 0 #目的地までの総距離
    L = []
    for i in range(N):
        d,p = map(int,input().strip().split(" "))
        for j in range(d):
            L.append(p)
    L.sort()
    S = 0 #Sが襲われる回数の期待値
    for k in range(len(L)-M):
        S = S + L[k]
    print(S)


### FIXED CODE ###

while True:
    N,M = map(int,input().strip().split(" "))
    if [N,M] == [0,0]:
        break
    L = []
    S = 0
    for i in range(N):
        l = list(map(int,input().strip().split(" ")))
        l.reverse()
        L.append(l)
        S = S + l[0]*l[1]
    L.sort()
    for j in range(0,N):
        t = N-j-1
        if M >= L[t][1]:
            S = S - L[t][0]*L[t][1]
            M = M - L[t][1]
        elif 0 < M:
            S = S - L[t][0]*M
            M = M - L[t][1]
    print(S)
### BUGGY CODE ###

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


class Node(object):
    def __init__(self, key, prev=None, nex=None):
        self.key = key
        self.prev = prev
        self.next = nex


class DoublyLinkedLiset(object):
    def __init__(self):
        self.nil = Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil

    def insert(self, x):
        X = Node(x)
        X.next = self.nil.next
        self.nil.next.prev = X
        self.nil.next = X
        X.prev = self.nil

    def listSearch(self, x):
        cur = self.nil.next
        while (cur != self.nil and cur.key != x):
            cur = cur.next

        return cur

    def deleteNode(self, X):
        if X == self.nil:
            return
        X.prev.next = X.next
        X.next.prev = X.prev
        del X

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

    def deleteLast(self):
        self.deleteNode(self.nil.prev)

    def deleteKey(self, x):
        self.deleteNode(self.listSearch(x))

    def printList(self):
        cur = self.nil.next
        ret = []

        while cur.key is not None:
            ret.append(cur.key)
            cur = cur.next

        print(' '.join(ret))


if __name__ == '__main__':

    n = int(input())
    dll = DoublyLinkedLiset()

    for i in range(n):
        command = input().split(" ")
        if command[0] == "insert":
            dll.insert(command[1])
        elif command[0] == "delete":
            dll.deleteKey(command[1])
        elif command[0] == "deleteFirst":
            dll.deleteFirst()
        elif command[0] == "deleteLast":
            dll.deleteLast()

    dll.printList()



### FIXED CODE ###

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

from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()

    for _ in range(n):
        command = input().split(" ")
        if command[0] == "insert":
            L.appendleft(command[1])
        elif command[0] == "delete":
            try:
                L.remove(command[1])
            except:
                pass
        elif command[0] == "deleteFirst":
            L.popleft()
        elif command[0] == "deleteLast":
            L.pop()

    print(" ".join(L))
### BUGGY CODE ###

from bisect import bisect_left, bisect_right

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

ans = 0
while len(A) > 1:
    pow2 = 1 << (len(bin(A[-1])) - 2)
    idx = bisect_left(A, pow2 - A[-1])
    if A[idx] + A[-1] == pow2 and idx != len(A) - 1:
        A.pop(idx)
        ans += 1
    A.pop(-1)
print(ans)

### FIXED CODE ###

from bisect import bisect_left, bisect_right
from collections import deque

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    while len(bin(A[-1])) - 2 > t:
        A.pop()
        if len(A) < 2: break
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        r = A.pop()
        idx = bisect_left(A, pow2 - r)
        for _ in range(idx):
            A_tmp.appendleft(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)
### BUGGY CODE ###

n=int(input())

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

ans=int(1)

for i in range(n):
    ans*=A[i]
if ans>1e18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n=int(input())

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

ans=int(1)

for i in range(n):
    ans*=A[i]
    if ans>1e18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

N=int(input())
dic=[]
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic.append(s)
    else:
        print("yes" if s in dic else "no")


### FIXED CODE ###

N=int(input())
dic={}
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic[s]=True
    else:
        print("yes" if s in dic else "no")
### BUGGY CODE ###

n, m = map(int, input().split())
lr = [[int(l), int(r)] for l, r in [input().split() for i in range(m)]]
for j in range(m):
  lr[j] = [l for l in range(lr[j][0], lr[j][1]+1)]
  lr[j] = set(lr[j])
lr_intersection = lr[0]
for k in range(1,m):
  lr_intersection = lr_intersection.intersection(lr[k])
print(len(lr_intersection))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
lr = []
heap1 = []
heap2 = []
for i in range(m):
    lr.append(list(map(int, input().split())))
for j in range(m):
    heapq.heappush(heap1, -lr[j][0])
    heapq.heappush(heap2, lr[j][1])
d = heapq.heappop(heap2) + heapq.heappop(heap1) +1 
if d < 0:
    print(0)
else:
    print(d)
### BUGGY CODE ###

S = list(input())
count = 0

tmpJ = 0
for i in range(len(S)):
  if S[i] == 'W':
    for j in range(tmpJ,i):
      if S[j] == 'B':
        tmpJ = j + 1
        S[i] = 'B'
        S[j] = 'W'
        count += (i-j)
        break
print(count)

### FIXED CODE ###

S = list(input())
count = 0
valueA = 0
for i in range(len(S)):
  if S[i] == 'B':
    count += 1
    valueA += i

valueB = 0
for i in range(count):
  valueB += (len(S) - 1 - i)
  
print(valueB - valueA)
### BUGGY CODE ###

H,W = [int(x) for x in input().split()]
A = [[x for x in input()] for _ in range(H)]
#%%
maps = [[-1]*W for _ in range(H)]
mv=[[1,0],[-1,0],[0,1],[0,-1]]
cnt = 0
li=[]
que = []
for h,i in enumerate(A):
    for w,j in enumerate(i):
        if(j=='#'):
            maps[h][w]=0
            que.append([h,w])
while(True):
    next_que=[]
    while(que):
        x = que.pop()
        now = maps[x[0]][x[1]]
        for i in mv:
            if(0<=x[0]+i[0]<H and 0<=x[1]+i[1]<W):
                if(maps[x[0]+i[0]][x[1]+i[1]]==-1):
                    maps[x[0]+i[0]][x[1]+i[1]]=now+1
                    next_que.append([x[0]+i[0],x[1]+i[1]])
    if(len(next_que)==0):
        break
    else:
        cnt += 1
        que=next_que
print(cnt)


### FIXED CODE ###

H,W = [int(x) for x in input().split()]
A = [[x for x in input()] for _ in range(H)]
#%%
maps = [[-1]*W for _ in range(H)]
mv=[[1,0],[-1,0],[0,1],[0,-1]]
cnt = 0
li=[]
que = []
for h,i in enumerate(A):
    for w,j in enumerate(i):
        if(j=='#'):
            maps[h][w]=0
            que.append([h,w])
while(True):
    next_que=[]
    while(que):
        x = que.pop()
        now = maps[x[0]][x[1]]
        for i in mv:
            if(0<=x[0]+i[0]<H and 0<=x[1]+i[1]<W):
                if(maps[x[0]+i[0]][x[1]+i[1]]==-1):
                    maps[x[0]+i[0]][x[1]+i[1]]=now+1
                    next_que.append([x[0]+i[0],x[1]+i[1]])
    if(len(next_que)==0):
        break
    else:
        cnt += 1
        que=next_que
print(cnt)
### BUGGY CODE ###

n,m = map(int,input().split())
A =[ list(map(int,input().split())) for i in range(n)]
A.sort(key=lambda x: x[1])
dp=[0]*(m+1)
ans = 0
for i in range(n):
    k=m-A[n-1-i][0]
    while True:
        if k < 0:
            break
        elif dp[k] ==0:
            dp[k] =1
            ans += A[n-1-i][1]
            break
        else:
            k -= 1
        
print(ans)


### FIXED CODE ###

import heapq

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

for i in s:
    if i[0] <= M:
        jobs[i[0]-1].append(-i[1])

condidate=[]
rewards=0
for k in range(M):
    for reward in jobs[k]:
        heapq.heappush(condidate, reward)
    if len(condidate) > 0:
        reward = heapq.heappop(condidate)
        rewards += -reward

print(rewards)
### BUGGY CODE ###

x, y = map(int, input().split())

tmp = x
count = 0
if x < 0:
    count += 1
    x = x * (-1)
    
while True:
    if x == y or x == -y:
        break
    x += 1
    count += 1
    
if x != y:
    count += 1
print(count)
    

### FIXED CODE ###

x, y = map(int, input().split())

if x == 0 and y < 0:
  print(abs(y) + 1)

elif x < 0 and y == 0:
  print(abs(x))

elif x > 0 and y == 0:
  print(x+1)

elif x >= 0 or y >= 0:
  if x == y:
    print(0)

  elif x == -y:
    print(1)

  elif x > y:
    # (11, 7)
    if y >= 0:
      ans = 2
      ans += x - y
      print(ans)

    # (11, -7)
    else:
      print(1 + abs(abs(x) + y))

  else:
    # (7, 11)
    if x >= 0:
      print(y - x)

    # (-7, 11)
    else:
      print(1 + abs(abs(y) + x))

else:
  if x == y:
    print(0)


  else:
    if x > y:
      print(abs(y) - abs(x) + 2)
    else:
      print(abs(x) - abs(y))
### BUGGY CODE ###

def iter_p_adic(p, n):
    '''
    連続して増加するp進数をリストとして返す。nはリストの長さ
    return
    ----------
    所望のp進数リストを次々返してくれるiterator
    '''
    from itertools import product
    tmp = [range(p+1)] * n
    return product(*tmp)


N, M, Q = map(int, input().split())

a, b, c, d = [], [], [], []
for i in range(Q):
    A, B, C, D = map(int, input().split())
    a.append(A)
    b.append(B)
    c.append(C)
    d.append(D)

MAX = 0
iterator = iter_p_adic(M,N)
for idxs in iterator:
    f = 0
    #print(idxs)
    A = list(idxs)
    A = sorted(A)
    for i in range(N):
        if A[i] == 0:
            f = 1
            break
    if f == 1:
        continue
    total = 0
    for i in range(Q):
        if c[i] == A[b[i]-1] - A[a[i]-1]:
            total += d[i]
    
    MAX = max(MAX, total)

print(MAX)

### FIXED CODE ###

def permutations(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutations(data):
                ret.append([i] + j)

        return ret
        

N, M, Q = map(int, input().split())

bou = [1] * N
ball = [2] * (M-1)

junretsu = permutations(bou + ball)

a, b, c, d = [], [], [], []
for i in range(Q):
    A, B, C, D = map(int, input().split())
    a.append(A)
    b.append(B)
    c.append(C)
    d.append(D)

ans = 0
for i in range(len(junretsu)):
    souwa = 0
    check = 0
    A = []
    for j in range(N+M-1):
        if junretsu[i][j] == 1:
            A.append(j - check + 1)
            check += 1
    for j in range(Q):
        if (A[b[j]-1] - A[a[j]-1]) == c[j]:
            souwa += d[j]
    
    ans = max(ans, souwa)

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

from collections import Counter

# def create_count_dic(text):
#     count_dic = {}
#     for t in text:
#         if t in count_dic:
#             count_dic[t] += 1
#         else:
#             count_dic[t] = 1
#     return count_dic

def is_anagram(text1, text2):
    # text1_dic = create_count_dic(text1)
    # text2_dic = create_count_dic(text2)
    if Counter(text1) == Counter(text2):
        return True
    else:
        return False

N = int(input())
S = [input() for x in range(N)]
ans = 0

for i in range(N):
    for j in range(i+1, N):
        if is_anagram(S[i], S[j]):
            ans += 1

print(ans)


### FIXED CODE ###

from collections import defaultdict
counter = defaultdict(int)
N = int(input())
for i in range(N):
    counter[tuple(sorted(list(input())))] += 1
ans = 0
for n in counter.values():
    ans += n * (n - 1) // 2
print(ans)
### BUGGY CODE ###

n = int(input())
l = sorted(list(map(int,input().split())),reverse = True)
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[i] + l[j]:
                ans += 1
            else:
                break
            
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect.bisect_left(l,l[i] + l[j]) - j - 1
print(ans)