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 <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;
map<ll, ll> dem;
ll mod = 10000;
ll dp[101][4][2];

void eat(ll day, ll kind) {
    dp[day + 1][kind][1] = dp[day][kind][0];
    FOR(j, 1, 4) {
        if(j != kind) {
            dp[day + 1][kind][0] += dp[day][j][0] % mod;
            dp[day + 1][kind][0] += dp[day][j][1] % mod;
            dp[day + 1][kind][0] %= mod;
        }
    }
}

int main() {
    cin >> N >> K;
    REP(i, K) {
        CINT(A, B);
        dem[A] = B;
    }
    if(dem[1]) {
        dp[1][dem[1]][0] = 1;
    } else {
        dp[1][1][0] = 1;
        dp[1][2][0] = 1;
        dp[1][3][0] = 1;
    }
    FOR(i, 1, N) {
        if(dem[i + 1]) {
            eat(i, dem[i + 1]);
        } else {
            FOR(j, 1, 4) { eat(i, j); }
        }
        // REP(i, N + 1) {
        //     cout << "\n";
        //     FOR(j, 1, 4) {
        //         REP(k, 2) { cout << dp[i][j][k] << " "; }
        //         cout << "   ";
        //     }
        // }
    }
    ll ans = 0;
    FOR(i, 1, 4) REP(j, 2)(ans += dp[N][i][j] % mod) %= mod;
    cout << ans << "\n";
}

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

typedef pair<int, int> P;

int d1[101], d2[101], d3[101], s1[101], s2[101], s3[101], sta[101];
int N, K;

void search(int n){
	
	if(n == N) return;
	
	if(n == 0){
		if(sta[0] == 1) s1[0] = 1;
		if(sta[0] == 2) s2[0] = 1;
		if(sta[0] == 3) s3[0] = 1;
		if(sta[0] == 0)s1[0] = s2[0] = s3[0] = 1;
		//cout << d1[0] << d2[0] << d3[0] << s1[0] << s2[0] << s3[0] << endl;
		search(1);
		return;
	}
	
	if(sta[n] == 1){
		d1[n] = s1[n - 1];
		s1[n] = d2[n - 1] + d3[n - 1] + s2[n - 1] + s3[n - 1];
		
	}
	if(sta[n] == 2){
		d2[n] = s2[n - 1];
		s2[n] = d1[n - 1] + d3[n - 1] + s1[n - 1] + s3[n - 1];
		
	}
	if(sta[n] == 3){
		d3[n] = s3[n - 1];
		s3[n] = d1[n - 1] + d2[n - 1] + s1[n - 1] + s2[n - 1];
		
	}
	if(sta[n] == 0){
		d1[n] = s1[n - 1];
		d2[n] = s2[n - 1];
		d3[n] = s3[n - 1];
		s1[n] = d2[n - 1] + d3[n - 1] + s2[n - 1]  + s3[n - 1];
		s2[n] = d1[n - 1] + d3[n - 1] + s1[n - 1]  + s3[n - 1];
		s3[n] = d1[n - 1] + d2[n - 1] + s1[n - 1]  + s2[n - 1];
	}
	
	if(sta[n + 1] != 0){
	
		if(sta[n + 1] == sta[n + 2]){
			if(sta[n + 1] == 1) s1[n] = 0; 
			if(sta[n + 1] == 2) s2[n] = 0;
			if(sta[n + 1] == 3) s3[n] = 0;
		}
	}
	//cout << d1[n] << d2[n] << d3[n] << s1[n] << s2[n] << s3[n] << endl;
	search(n + 1);
	return;
}

int main(){
	for(int i = 0;i < 101;i ++)sta[i] = 0;
	d1[0] = d2[0] = d3[0] = s1[0] = s2[0] = s3[0] = 0;
	
	cin >> N >> K;
	int Ai, Bi;
	for(int i = 0;i < K;i ++){
		cin >> Ai >> Bi;
		sta[Ai - 1] = Bi;
	}
	search(0);
	cout << (d1[N - 1] + d2[N - 1] + d3[N - 1] + s1[N - 1] + s2[N - 1] + s3[N - 1]) % 10000 << endl;
	
	return 0;
}