Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func StrStdin() (stringReturned string) {
//	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	nk, _ := SplitIntStdin(" ")
	n, k := nk[0], nk[1]
	kind := make([]int, n)
	for i := 0; i < k; i++ {
		var tmp []int
		var err error
		if tmp, err = SplitIntStdin(" "); err != nil {
			panic(err)
		}
		kind[tmp[0]-1] = tmp[1]
	}
	dp := make([][3][3]int, n)
	if kind[0] > 0 {
		dp[0][0][kind[0]-1] = 1
	} else {
		for i := 0; i < 3; i++ {
			dp[0][0][i] = 1
		}
	}
	if kind[1] > 0 {
		for i := 0; i < 3; i++ {
			dp[1][i][kind[1]-1] = dp[0][0][i]
		}
	} else {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[1][i][j] = dp[0][0][i]
			}
		}
	}
	for i := 1; i < n-1; i++ {
		if kind[i+1] > 0 {
			for j := 0; j < 3; j++ {
				if j == kind[i+1]-1 {
					for k := 0; k < 3; k++ {
						if j != k {
							dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
							dp[i+1][j][kind[i+1]-1] %= 10000
						}
					}
				} else {
					for k := 0; k < 3; k++ {
						dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
						dp[i+1][j][kind[i+1]-1] %= 10000
					}
				}
			}
		} else {
			for j := 0; j < 3; j++ {
				for k := 0; k < 3; k++ {
					for l := 0; l < 3; l++ {
						if j != k || k != l {
							dp[i+1][k][j] += dp[i][l][k]
							dp[i+1][k][j] %= 10000
						}
					}
				}
			}
		}
	}
	result := 0
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			result += dp[n-1][i][j]
		}
	}
	// fmt.Println(dp)
	// fmt.Println(kind)
	fmt.Println(result % 10000)
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

const int MOD = 10000;

int menu[101];
int dp[101][4][4];

int main() {
	int n, k;
	cin >> n >> k;
	int a, b;
	for (int i = 0; i < n; i++) {
		menu[i] = -1;
	}
	for (int i = 0; i < k; i++) {
		cin >> a >> b;
		menu[a - 1] = b - 1;
	}
	for (int i = 0; i < 3; i++) {
		if (menu[0] == -1 || menu[0] == i)dp[0][i][0] = 1;
	}
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 2; k++) {
				if (dp[i][j][k] > 0) {
					for (int l = 0; l < 3; l++) {
						if (menu[i + 1] == -1 || menu[i + 1] == l) {
							if (l != j) {
								dp[i + 1][l][0] += dp[i][j][k];
								dp[i + 1][l][0] %= MOD;
							}
							if (l == j && k + 1 < 2) {
								dp[i + 1][l][k + 1] += dp[i][j][k];
								dp[i + 1][l][k + 1] %= MOD;
							}
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 2; j++) {
			ans += dp[n - 1][i][j];
			ans %= MOD;
		}
	}
	cout << ans << endl;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

//-----------------------
const int MOD = 1e4;
struct mint { int n; mint(int n = 0) : n(n) { } };
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint& a) { return is >> a.n; }
mint operator^(mint a, long long n) { mint r = 1;
    while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0;
    while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); }
    return mint(u); }
bool operator<(const mint &a, const mint &b) { return a.n < b.n; }
//-----------------------

int main() {
    int n, k; cin >> n >> k;
    map<int, int> ma;
    while (k--) {
        int i; cin >> i; cin >> ma[i], ma[i]--;
    }
    #define nxt(j) ((j + 1) % 3)
    vector<vector<mint>> dp(3, vector<mint>(3, 0));
    if (ma.count(1)) {
        dp[ma[1]][1] = 1;
    } else {
        dp[0][1] = dp[1][1] = dp[2][1] = 1;
    }
    for (int i = 2; i <= n; i++) {
        vector<vector<mint>> dp2(3, vector<mint>(3, 0));
        for (int j = 0; j < 3; j++) {
            for (int k: {1, 2}) dp2[j][1] += dp[nxt(j)][k] + dp[nxt(nxt(j))][k];
            dp2[j][2] = dp[j][1];
        }
        swap(dp, dp2);
        if (!ma.count(i)) continue;
        for (int j = 0; j < 3; j++) if (ma[i] != j) dp[j][1] = dp[j][2] = 0;
    }
    mint ans = 0;
    for (int j = 0; j < 3; j++) ans += dp[j][1] + dp[j][2];
    cout << ans << endl;
    return 0;
}

C++: #include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int dp[4][4][101];

int main(){
  int n = getInt();
  int k = getInt();
  vector<int> d(n, -1);
  REP(i,k){
    int a = getInt();
    int b = getInt();
    d[a - 1] = b;
  }
  dp[0][0][0] = 1;

  REP(k,n) REP(i,4) REP(j,4) if(dp[i][j][k]){
    if(d[k] != -1){
      if(i != j || i != d[k])
        dp[j][d[k]][k + 1] = (dp[j][d[k]][k + 1] + dp[i][j][k]) % 10000;
    }else{
      REP(t,3) if(i != j || i != t + 1)
        dp[j][t + 1][k + 1] = (dp[j][t + 1][k + 1] + dp[i][j][k]) % 10000;
    }
  }

  int ans = 0;
  REP(i,3) REP(j,3) ans = (ans + dp[i+1][j+1][n]) % 10000;

  printf("%d\n", ans);

  return 0;
}