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

import queue
N,M=map(int,input().split())
G=[dict() for i in range(N)]
for i in range(M):
    u,v,s=map(int,input().split())
    G[u-1][v-1]=s
    G[v-1][u-1]=s
H=[[] for i in range(N)]
reached=[0 for i in range(N)]
q=queue.Queue()
for i in range(N):
    if reached[i]==0:
        q.put(i)
        H[i].append((0,1))
        while(not(q.empty())):
            r=q.get()
            reached[r]=1
            for p in G[r]:
                if reached[p]==0:
                    q.put(p)
                    for s in H[r]:
                        H[p].append((G[r][p]-s[0],-s[1]))
flag=0
x=-1
for i in range(N):
    if len(H[i])>=2:
        X=set()
        Y=set()
        for r in H[i]:
            if r[1]==-1:
                X.add(r)
            else:
                Y.add(r)
        if len(X)>=2 or len(Y)>=2:
            print(0)
            exit()
        else:
            a=list(X)[0]
            b=list(Y)[0]
            z=a[0]-b[0]
            if z%2==1:
                print(0)
                exit()
            x=z//2
            if x<0:
                print(0)
                exit()
        flag=1
if flag==1 and x!=-1:
    print(1)
elif flag==1 and x==-1:
    print(0)
else:
    L=[]
    R=[]
    for i in range(N):
        if H[i][0][1]==-1:
            L.append(H[i][0][0])
        else:
            R.append(H[i][0][0])
    print(max([min(L)+min(R)-1,0]))


### FIXED CODE ###

#(x,y)...xt+yが書かれる
from collections import deque
N,M=map(int,input().split())
G=[{} for i in range(N)]
for i in range(M):
    u,v,s=map(int,input().split())
    u-=1;v-=1
    G[u][v]=s;G[v][u]=s
H=[(0,0) for i in range(N)]
t=None
q=deque([0])
H[0]=(1,0)
while(q):
    r=q.pop()
    for p in G[r]:
        s=G[r][p]
        tmp=(-H[r][0],s-H[r][1])
        if H[p]==(0,0):
            H[p]=tmp
            q.append(p)
        elif H[p]==tmp:
            pass
        else:
            if H[p][0]==tmp[0]:
                print(0)
                exit()
            else:
                a=H[p][1]
                b=tmp[1]
                if H[p][0]==-1:
                    a,b=b,a
                #t+a=-t+b
                #2t=b-a
                if (b-a)%2:
                    print(0)
                    exit()
                else:
                    t=(b-a)//2
'''
t+a>=0:t>=-a
-t+b>=0:t<=b
inf=max(a)
sup=min(b)
'''
if t==None:
    inf=0
    sup=10**18
    for i in range(N):
        if H[i][0]==1:
            inf=max(inf,-H[i][1])
        else:
            sup=min(sup,H[i][1])
    print(max(sup-inf-1,0))
else:
    ans=[None for i in range(N)]
    q=deque([0])
    ans[0]=t
    while(q):
        r=q.pop()
        for p in G[r]:
            if ans[p]==None:
                ans[p]=G[r][p]-ans[r]
                q.append(p)
    flag=1
    for i in range(N):
        for j in G[i]:
            if ans[i]+ans[j]!=G[i][j]:
                flag=0
                break
        if flag==0:
            break
    if flag and min(ans)>0:
        print(1)
    else:
        print(0)
### BUGGY CODE ###

from collections import Counter

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

Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

d = Counter(A)

for b, c in BC:
    d[c] += d[b]
    d[b] = 0

    li = [k * v for k, v in d.items()]
    print(sum(li))


### FIXED CODE ###

from collections import Counter

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

Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

d = Counter(A)

sub_s = sum(A)

for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0

    print(sub_s)
### BUGGY CODE ###

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

### FIXED CODE ###

n,k=map(int,input().split())
n=n%k
print(n if abs(n-k)>n else abs(n-k))
### BUGGY CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
# MOD = 10 ** 9 + 7
MOD = 998244353


def main():
    N, K = map(int, readline().split())
    S = set()
    for k in range(K):
        L, R = map(int, readline().split())
        S |= set(range(L, R + 1))

    dp = [0] * (N + 20)
    dp[1] = 1
    S = list(S)
    S.sort()

    for i in range(1, N + 5):
        for s in S:
            if i - s > 0:
                dp[i] += dp[i - s]
                dp[i] %= MOD
            else:
                continue
    print(dp[N])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
M = 998244353


class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


def segfunc(x, y):
    return x + y


def main():
    N, K = map(int, readline().split())
    LR = list(list(map(int, readline().split())) for _ in range(K))
    LR.sort()

    A = [0] * (N + 1)
    A[1] = 1
    seg = SegTree(A, segfunc=segfunc, ide_ele=0)
    for i in range(2, N + 1):
        for l, r in LR:
            if i - l > 0:
                total = (seg.tree[i + seg.num] + seg.query(max(1, i - r), min(N, i - l + 1)) % M)
                seg.update(i, total)
            else:
                break
    print(seg.tree[seg.num + N] % M)


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

n = int(input())
s = input()

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                count = 0
                for l in s:
                    if l == str(k) and count == 2:
                        count += 1
                    elif l == str(j) and count == 1:
                        count += 1
                    elif l == str(i) and count == 0:
                        count += 1
                    if count == 3:
                        c += 1
                        break

print(c)


### FIXED CODE ###

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

def nc(n,s,i,j,k):
    c1 = -1
    for l in range(n):
        if s[l] == i:
            c1 = l
            break
    if c1 == -1:
        return 0
    c2 = -1
    for l in range(c1+1,n):
        if s[l] == j:
            c2 = l
            break
    if c2 == -1:
        return 0
    c3 = -1
    for l in range(c2+1,n):
        if s[l] == k:
            c3 = l
            break
    if c3 == -1:
        return 0
    return 1

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                c += nc(n,s,i,j,k)



print(c)
### BUGGY CODE ###

H,W,D = map(int,input().split())
A = [0]*(H*W+1)
for i in range(H):
    a = list(map(int,input().split()))
    for j in range(W):
        A[a[j]] = (i,j)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    ans = 0
    while R > L:
        ans += abs(A[L][0]-A[L+D][0]) + abs(A[L][1]-A[L+D][1])
        L += D
    print(ans)


### FIXED CODE ###

H,W,D = map(int,input().split())
A = [0]*(H*W+1)
for i in range(H):
    a = list(map(int,input().split()))
    for j in range(W):
        A[a[j]] = (i,j)
d = [0]*(H*W+1)
for i in range(D+1,H*W+1):
    d[i] = d[i-D]+abs(A[i][0]-A[i-D][0])+abs(A[i][1]-A[i-D][1])
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    print(d[R]-d[L])
### BUGGY CODE ###

n,m=[int(i) for i in input().split()]
P=[[int(i) for i in input().split()] for j in range(m)]

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[]
Z=[]

for i in range(m):
    P[i].append(i)
    W.append(P[i][0])

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    c=W.count(i+1)
    if c==0:
        P_c.append([])
    else:
        P_c.append(P[sum:c+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X="{0:06d}".format(x[j][0])
        Y="{0:06d}".format(j+1)
        X=str(X)
        Y=str(Y)
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])

### FIXED CODE ###

n,m=[int(i) for i in input().split()]
P=[[int(i) for i in input().split()] for j in range(m)]

def prefecturesort(i):
    return i[0]

def yearsort(i):
    return i[1]

W=[0 for i in range(n)]
Z=[]

for i in range(m):
    P[i].append(i)
    W[P[i][0]-1]+=1

P.sort(key=prefecturesort)
P_c=[]
sum=0
for i in range(n):
    c=W[i]
    if c==0:
        P_c.append([])
    else:
        P_c.append(P[sum:c+sum])
    sum+=c
    P_c[i].sort(key=yearsort)
for x in P_c:
    for j in range(len(x)):
        X=str("{0:06d}".format(x[j][0]))
        Y=str("{0:06d}".format(j+1))
        Z.append([X+Y,x[j][2]])
Z.sort(key=yearsort)
for i in range(m):
    print(Z[i][0])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
al = []
for i in range(1,n):
        sum1 = sum(a[0:i])
        sum2 = sum(a[i:])
        al.append(abs(sum1 - sum2))
        if sum1 == sum2:
                print(0)
                exit()

minDiffIdx = al.index(min(al))

# print("---")
# print(minDiffIdx)
# print("---")

tmp1 = sum(a[0:minDiffIdx])
tmp2 = sum(a[minDiffIdx:])
# print(tmp1)
# print(tmp2)
diff1 = abs(tmp1 - tmp2)

tmp3 = sum(a[0:minDiffIdx + 1])
tmp4 = sum(a[minDiffIdx + 1:])
# print(tmp3)
# print(tmp4)
diff2 = abs(tmp3 - tmp4)
print(min(diff1, diff2))

# d1 = diff1
# d2 = diff2

# if d1 < d2:
#         for i in range(n//2):
#                 if a[i] > 1:
#                         d1 -= a[i]
#                 if d1 < 0:
#                         ans += diff1 + d1
#                         break
#                 elif d1 == 0:
#                         ans += diff1
#                         break
#         if 
# else:

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
s = sum(a)
al = []

sum1 = 0

for i in range(0,n):
        # if i == 1:
        #         sum1 = sum(a[0:i])
        # else:
        #         sum1 += a[i]
        sum1 += a[i]
        sum2 = s - sum1
        # print("sum1:"+str(sum1))
        # print("sum2:"+str(sum2))
        al.append(abs(sum1 - sum2))
        if sum1 == sum2:
                print(0)
                exit()

minDiffIdx = al.index(min(al))

# print("---")
# print(minDiffIdx)
# print("---")

tmp1 = sum(a[0:minDiffIdx])
tmp2 = sum(a[minDiffIdx:])
# print(tmp1)
# print(tmp2)
diff1 = abs(tmp1 - tmp2)

tmp3 = sum(a[0:minDiffIdx + 1])
tmp4 = sum(a[minDiffIdx + 1:])
# print(tmp3)
# print(tmp4)
diff2 = abs(tmp3 - tmp4)
print(min(diff1, diff2))

# d1 = diff1
# d2 = diff2

# if d1 < d2:
#         for i in range(n//2):
#                 if a[i] > 1:
#                         d1 -= a[i]
#                 if d1 < 0:
#                         ans += diff1 + d1
#                         break
#                 elif d1 == 0:
#                         ans += diff1
#                         break
#         if 
# else:
### BUGGY CODE ###

from collections import Counter

input_line=int(input())
count=0
input_list=[]
while count < input_line:
  input_list.append(input())
  count+=1
ans={}
ans_list=[]
list_set=set(input_list)
max_appeard=Counter(input_list).most_common(1)[0][1]
for item in list_set:
    appeard=Counter(input_list)[item]
    if appeard >= max_appeard:
        max_appeard=appeard
        ans[item]=appeard
for key,value in ans.items():
    if value==max_appeard:
        ans_list.append(key)
ans_list.sort()
for item in ans_list:
  print (item)

### FIXED CODE ###

from collections import defaultdict

H=int(input())
d = defaultdict(int)
for _ in range(H):
    d[input()] += 1
max_appeard=max(d.items(), key=lambda x: x[1])[1]
ans=[k for k,v in d.items() if v == max_appeard]
ans.sort()
for item in ans:
  print (item)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))#N-1
count=0
list=[]
for i in range(1,N):
    for j in range(0,N-1):
        if not j==N-2 and A[j]==i:
            count+=1
        elif j==N-2 and A[j]==i:
            count+=1
            list.append(count)
            count=0
        elif j==N-2 and not A[j]==i:
            list.append(count)
            count=0

if not len(list)==N:
    for i in range(0,N-len(list)):
        list.append(0)

for i in range(0,len(list)):
    print(list[i])


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))#N-1
list=[]
for i in range(N):
    list.append(0)

for i in range(0,N-1):
    list[A[i]-1]+=1

for i in range(0,N):
    print(list[i])
### BUGGY CODE ###

import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61

    for a in A:
        for i, c in enumerate(format(a, '061b')):
            if c == '1':
                count[i] += 1
    ans = 0
    for j, a in enumerate(A):
        for i, c in enumerate(format(a, '061b')):
            if c == '1':
                count[i] -= 1
                ans = (ans + pow(2, 60-i, MOD) * (N-1-j-count[i]))%MOD
            else:
                ans = (ans + pow(2, 60-i, MOD) * count[i])%MOD
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61
    ans = 0
    for a in A:
        for i, c in enumerate(format(a, 'b')[::-1]):
            if c == '1':
                count[i] += 1

    for i, c in enumerate(count):
        tmp = (c*(N-c) * pow(2, i, MOD))%MOD
        ans = (ans + tmp)%MOD
    print(ans)


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

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

dp = [10**9+5] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, min(i, K)+1):
        dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
print(dp[N-1])

### FIXED CODE ###

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

dp = [1e10] * N
dp[0] = 0
for i in range(N):
    for j in range(i+1, i+K+1):
        if j >= N:
            break
        dp[j] = min([dp[j], dp[i]+abs(h[j]-h[i])])
print(dp[N-1])
### BUGGY CODE ###

N = int(input())
d = sorted(list(map(int, input().split())))
ans = 0
for i in range(1,d[-1] + 1):
    if sum(x <i for x in d) == N//2:
        ans += 1
    else:
        pass
print(ans)

### FIXED CODE ###

N = int(input())
d = sorted(list(map(int, input().split())))

print(d[N//2] - d[N//2 - 1])
### BUGGY CODE ###

import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

# random_denseがTLE, 他はAC
from bisect import bisect_left, bisect_right  # 二分探索
def main_tle():
    N, Q = i2nn()
    STX = ii2nnn(N) # 座標 X で時刻 [S, T) が工事
    D = ii2nn(Q)    # 昇順ソート済み
    E = [-1] * Q
    STX.sort(key=lambda v: v[2])
    for s, t, x in STX:
        a = bisect_left(D, s-x)
        b = bisect_left(D, t-x)
        for i in range(a, b):
            if E[i] == -1:
                E[i] = x
    for e in E:
        print(e)

def main():
    N, Q = i2nn()
    STX = ii2nnn(N) # 座標 X で時刻 [S, T) が工事
    D = ii2nn(Q)    # 昇順ソート済み

    events = []
    for i, d in enumerate(D):
        events.append(('D', d, i))
    for s, t, x in STX:
        events.append(('S', (s-x-0.4), x))
        events.append(('T', (t-x-0.6), x))  # 0.5 同士だと [1, 2), [0, 1) で吹き飛ぶ
    
    ans = [-1] * Q
    events.sort(key=lambda v: v[1])
    xset = set()
    xmin = None
    for event, time, xi in events:
        if event == 'S':
            xset.add(xi)
            if xmin is None or xmin > xi:
                xmin = xi
        elif event == 'T':
            xset.remove(xi)
            if xmin == xi:
                xmin = None
        elif event == 'D' and xset:
            if xmin is None:
                xmin = min(xset)
            ans[xi] = min(xset)

    for n in ans:
        print(n)

main()


### FIXED CODE ###

import sys;input=sys.stdin.readline

n,q=map(int, input().split())
event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x-0.5,1,x))
    event.append((t-x-0.5,-1,x))
for i in range(q):
    event.append((int(input()),0,i))

event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

n,ma,mb = map(int,input().split())

INF = 10**4
dp = [[[INF] * (n*10+1) for _ in range(n*10+1)] for _ in range(n+1)]
dp[0][0][0] = 0

for i in range(n):
    a,b,c = map(int,input().split())
    for ai in range(n*10):
        for bi in range(n*10):
            if ai>=a and bi>=b:
                tmp = dp[i][ai-a][bi-b] + c
            else:
                tmp = INF
            dp[i+1][ai][bi] = min(dp[i][ai][bi], tmp)

ans = min(dp[n][ma*i][mb*i] for i in range(1,n*10//max(ma,mb)+1) )
if ans == INF: ans = -1
    
print(ans)

### FIXED CODE ###

n,ma,mb = map(int,input().split())

INF = 10**4
dp = [[[INF] * (n*10+1) for _ in range(n*10+1)] for _ in range(n+1)]
dp[0][0][0] = 0

for i in range(n):
    a,b,c = map(int,input().split())
    for ai in range(i*10+11):
        for bi in range(i*10+11):
            if ai>=a and bi>=b:
                tmp = dp[i][ai-a][bi-b] + c
            else:
                tmp = INF
            dp[i+1][ai][bi] = min(dp[i][ai][bi], tmp)

ans = min(dp[n][ma*i][mb*i] for i in range(1,n*10//max(ma,mb)+1) )
if ans == INF: ans = -1
    
print(ans)
### BUGGY CODE ###

inp = int(input())
lst = map(int,input().split())
sum = 1
for i in lst:
  sum *= i
  
if sum <= 1e18:
  print(sum)
else:
  print(-1)

### FIXED CODE ###

import sys
inp = int(input())
lst = list(map(int,input().split()))
sum = 1
if 0 in lst:
    print(0)
    sys.exit(0)
else:
    num = 1;
    for i in range(inp):
        num *= lst[i]
        if num > 10 ** 18:
            print("-1")
            sys.exit()
    print(num)
### BUGGY CODE ###

K = int(input())
if K%2==0 or K%5==0:
  print(-1)
else:
  n = 1
  while True:
    if 7*(10**n-1)/9%K==0:
      print(n)
      break

### FIXED CODE ###

K = int(input())
if K%2==0 or K%5==0:
  print(-1)
else:
  n = 1
  Rem = 7%K
  while Rem!=0:
    Rem = (Rem*10+7)%K
    n+=1
  print(n)
### BUGGY CODE ###

N =int(input())
strings =[]
for i in range(N):
  strings.append(input())
strs=[]
for i in range(N):
  str1 =strings[i][0:1]
  str2 =strings[i][1:2]
  str3 =strings[i][2:3]
  str4 =strings[i][3:4]
  str5 =strings[i][4:5]
  str6 =strings[i][5:6]
  str7 =strings[i][6:7]
  str8 =strings[i][7:8]
  str9 =strings[i][8:9]
  str10 =strings[i][9:10]
  letters=[str1,str2,str3,str4,str5,str6,str7,str8,str9,str10]
  newstrlet =sorted(letters)
  newstr=newstrlet[0]+newstrlet[1]+newstrlet[2]+newstrlet[3]+newstrlet[4]+newstrlet[5]+newstrlet[6]+newstrlet[7]+newstrlet[8]+newstrlet[9]
  strs.append(newstr)
k=0
for i in range(N):
  for j in range(N):
    if strs[i]==strs[j]:
      k=k+1
ans=(k-N)/2
print(int(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
strs=[]
for i in range(n):
    line=sorted(input().rstrip())
    STR=""
    for j in line:
        STR=STR+j
    strs.append(STR)
#print(strs)
x=collections.Counter(strs)
#print(x)
sm=0
for j in x:
    sm+=x[j]*(x[j]-1)//2
print(sm)
### BUGGY CODE ###

S = list(input())
N = len(S)
count = 0
change=True
while change:
  change = False
  for i in range(N-1):
    if S[i] == 'B' and S[i+1] == 'W':
      S[i] = 'W'
      S[i+1] = 'B'
      count+=1
      change = True
      break
print(count)

### FIXED CODE ###

S = list(input())
N = len(S)
ans = 0
count = 0
for i in range(N):
  if S[i] == 'B':
    count+=1
  if S[i] == 'W':
    ans+=count
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
# coding=utf-8

import itertools
import sys

import numpy as np

n, k = map(int, sys.stdin.readline().strip().split(" "))
xyc = [l.strip().split(" ") for l in sys.stdin.readlines()]
xyc = [tuple((int(_x), int(_y), _c == "W")) for (_x, _y, _c) in xyc]
xyc = [
    tuple((_x % k, _y % k, _c if (_x // k + _y // k) % 2 == 0 else not _c)) for (_x, _y, _c) in xyc
]


def checker(base, condition):
    i, j, f = base
    x, y, c = condition
    if not ((x <= i and y <= j) or (i < x and j < y)):
        f = not f
    return f == c


xs = {_x for (_x, _y, _c) in xyc}
ys = {_y for (_x, _y, _c) in xyc}

ans = 0
for i, j, f in itertools.product(xs, ys, {True, False}):
    checks = [checker((i, j, f), _xyc) for _xyc in xyc]
    ans = max(ans, sum(checks))
    if ans == n:
        break
print(ans)

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]
ADD = {"B": 0, "W": K}


def create_bound(p, K, ub):
    if p - K + 1 >= 0:
        return [(p - K + 1, p + 1)]
    else:
        return [(0, p + 1), ((p - K + 1) % ub, ub)]


for i in range(N):
    x, y, c = input().split()
    nx = int(x) % ub
    ny = (int(y) + ADD[c]) % ub
    for add in [0, K]:
        for xlb, xub in create_bound((nx + add) % ub, K, ub):
            for ylb, yub in create_bound((ny + add) % ub, K, ub):
                b[xlb][ylb] += 1
                b[xlb][yub] -= 1
                b[xub][ylb] -= 1
                b[xub][yub] += 1

b_arr = np.array(b)
for i in range(ub):
    b_arr[i + 1, :] += b_arr[i, :]
for j in range(ub):
    b_arr[:, j + 1] += b_arr[:, j]
print(b_arr.max())
### BUGGY CODE ###

n,m=map(int, input().split())
ab=[list(map(int,input().split())) for i in range(m)]

from pprint import pprint

l=[[False for _ in range(n)] for _ in range(n)]
v=[True for _ in range(n)]
for a,b in ab:
    l[b-1][a-1], l[a-1][b-1]=True,True

def dfs(x,t,v,j,m,n):
    j+=1
    if j<n+m:
        v[x]=False
        for i in range(1,n):
            if t[x][i]:
                dfs(i,t,v,j,m,n)
import copy

ans=0
for i in range(m):
    j=0
    t=copy.deepcopy(l)
    t[ab[i][1]-1][ab[i][0]-1],t[ab[i][0]-1][ab[i][1]-1]=False,False
    v=[True for _ in range(n)]
    if i!=0:
        dfs(ab[0][0]-1, t, v, j, m,n)
    else:
        dfs(ab[1][0]-1, t, v, j, m,n)
        
    z=False
    for x in v:
        if x:
            z=True
    if z:
        ans+=1
print(ans)

### FIXED CODE ###

n,m=map(int, input().split())
ab=[list(map(int,input().split())) for i in range(m)]

from pprint import pprint

l=[[False for _ in range(n)] for _ in range(n)]
v=[True for _ in range(n)]
for a,b in ab:
    l[b-1][a-1], l[a-1][b-1]=True,True
def dfs(x,t,v,j,m,n):
    j+=1
    if j<n+m:
        v[x]=False
        for i in range(1,n):
            if v[i]:
                if t[x][i]:
                    dfs(i,t,v,j,m,n)
import copy

ans=0
for i in range(m):
    j=0
    t=copy.deepcopy(l)
    t[ab[i][1]-1][ab[i][0]-1],t[ab[i][0]-1][ab[i][1]-1]=False,False
    v=[True for _ in range(n)]
    dfs(0, t, v, j, m,n)
        
    z=False
    for x in v:
        if x:
            z=True
    if z:
        ans+=1
print(ans)