output_description: Print the number of possible ways to write integers, modulo 998244353.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      a_1 b_1 c_1
      :
      a_M b_M c_M
attempt: from collections import defaultdict
  
  Q = 998244353
  D = defaultdict(int)
  N, M = map(int, input().split())
  L = (N**2 - N) // 2
  Ld = N
  ans = 1
  diag = [-1] * (N + 1)
  A = [(0, 0, 0)] * M
  for _ in range(M):
      a, b, c = map(int, input().split())
      if a == b:
          D[(a, b)] = c + 2
          Ld -= 1
      else:
          L -= 1
          D[(a, b)] = c + 2
  for i in range(N - 1):
      if (
          D[(i, i)] >= 2
          and D[(i, i + 1)] >= 2
          and D[(i + 1, i)] >= 2
          and D[(i + 1, i + 1)] >= 2
      ):
          if not (D[(i, i)] + D[(i, i + 1)] + D[(i + 1, i)] + D[(i + 1, i + 1)]) % 2 == 0:
              ans = 0
  print(ans * pow(2, L + Ld, Q))
  
problem_description: Statement
  
  Takahashi has an N \times N grid. The square at the i-th row and the j-th
  column of the grid is denoted by (i,j). Particularly, the top-left square of
  the grid is (1,1), and the bottom-right square is (N,N).
  
  An integer, 0 or 1, is written on M of the squares in the Takahashi's grid.
  Three integers a_i,b_i and c_i describe the i-th of those squares with
  integers written on them: the integer c_i is written on the square (a_i,b_i).
  
  Takahashi decides to write an integer, 0 or 1, on each of the remaining
  squares so that the condition below is satisfied. Find the number of such ways
  to write integers, modulo 998244353.
  
    * For all 1\leq i < j\leq N, there are even number of 1s in the square region whose top-left square is (i,i) and whose bottom-right square is (j,j).
samples: [{"input": "3 3\n    1 1 1\n    3 1 0\n    2 3 1", "output": "8\n    \n\nFor example, the following ways to write integers satisfy the condition:\n\n    \n    \n    101   111\n    011   111\n    000   011\n    \n\n* * *"}, {"input": "4 5\n    1 3 1\n    2 4 0\n    2 3 1\n    4 2 1\n    4 4 1", "output": "32\n    \n\n* * *"}, {"input": "3 5\n    1 3 1\n    3 3 0\n    3 1 0\n    2 3 1\n    3 2 1", "output": "0\n    \n\n* * *"}, {"input": "4 8\n    1 1 1\n    1 2 0\n    3 2 1\n    1 4 0\n    2 1 1\n    1 3 0\n    3 4 1\n    4 4 1", "output": "4\n    \n\n* * *"}, {"input": "100000 0", "output": "342016343"}]