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>
using namespace std;
int N, K, a, b, x[109], dp[109][3][2];
int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> a >> b; a--;
		x[a] = b;
	}
	if (x[0] == 0) {
		dp[0][0][0] = 1;
		dp[0][1][0] = 1;
		dp[0][2][0] = 1;
	}
	else dp[0][x[0] - 1][0] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			if (x[i] != 0 && x[i] != j + 1) continue;
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < 2; l++) {
					if (j == k && l == 1) continue;
					if (j == k) dp[i][j][1] += dp[i - 1][k][l];
					else dp[i][j][0] += dp[i - 1][k][l];
				}
			}
			dp[i][j][0] %= 10000;
			dp[i][j][1] %= 10000;
		}
	}
	int ret = 0;
	for (int i = 0; i < 3; i++) ret += dp[N - 1][i][0] + dp[N - 1][i][1];
	cout << ret % 10000 << endl;
	return 0;
}

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

map< pair< int , deque<int> > , int > memo;
int scheduled[100];
int n , m;

int f(int pos,deque<int> prev){
	deque<int> current = prev;
	if( memo.count(make_pair(pos,prev)) ) return memo[make_pair(pos,prev)];
	
	if(prev.size() == 3 && count(prev.begin(),prev.end(),prev[0]) == 3 ) return 0;
	
	if(pos == n) return 1;
	
	if(prev.size() == 3) prev.pop_front();
	
	int ans = 0;
	if(scheduled[pos] == -1){
		for(int i = 1 ; i <= 3 ; i++){
			prev.push_back(i);
			ans = ( ans + f(pos+1,prev) ) % 10000;
			prev.pop_back();
		}
	}else{
		prev.push_back(scheduled[pos]);
		ans = ( ans + f(pos+1,prev) ) % 10000;
	}
	return memo[make_pair(pos,current)] = ans;
}

int main(){
	memset(scheduled,-1,sizeof(scheduled));
	
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++){
		int a,b;
		cin >> a >> b;
		a--;
		scheduled[a] = b;
	}
	cout << f(0,deque<int>()) << endl;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#define int long long
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	map<int, int>c;
	for (int d = 0; d < b; d++) {
		int e;
		cin >> e; e--;
		cin >> c[e];
	}
	int dp[100][3][2]{};
	if (c[0])dp[0][c[0]-1][0] = 1;
	else dp[0][0][0] = dp[0][1][0] = dp[0][2][0] = 1;
	for (int f = 1; f < a; f++) {
		dp[f][0][0] = dp[f - 1][1][0] + dp[f - 1][1][1] + dp[f - 1][2][0] + dp[f - 1][2][1];
		dp[f][1][0] = dp[f - 1][0][0] + dp[f - 1][0][1] + dp[f - 1][2][0] + dp[f - 1][2][1];
		dp[f][2][0] = dp[f - 1][0][0] + dp[f - 1][0][1] + dp[f - 1][1][0] + dp[f - 1][1][1];
		dp[f][0][1] = dp[f - 1][0][0];
		dp[f][1][1] = dp[f - 1][1][0];
		dp[f][2][1] = dp[f - 1][2][0];
		switch (c[f]) {
		case 1:dp[f][1][0] = dp[f][1][1] = dp[f][2][0] = dp[f][2][1] = 0; break;
		case 2:dp[f][0][0] = dp[f][0][1] = dp[f][2][0] = dp[f][2][1] = 0; break;
		case 3:dp[f][0][0] = dp[f][0][1] = dp[f][1][0] = dp[f][1][1] = 0; break;
		}
	}
	int s = 0;
	for (int x = a-1; x < a; x++) {
		for (int y = 0; y < 3; y++) {
			s += dp[x][y][0] + dp[x][y][1];
		}
	}
	cout << s % 10000 << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;

const int MOD = 10000;
int dp[101][4][4];
int pasta[101];
int main(){
	int n, k;
	cin >> n >> k;
	rep(i, k){
		int d, p;
		cin >> d >> p;
		pasta[d] = p;
	}
	
	dp[0][0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int l = 1; l < 4; l++){
			if(pasta[i] && pasta[i] != l) continue;
			for(int j = 0; j < 4; j++){
				for(int k = 0; k < 4; k++){
					if(l == j && j == k) continue;
					dp[i][l][j] += dp[i-1][j][k];
					dp[i][l][j] %= MOD;
				}
			}
		}
	}
	int ans = 0;
	rep(i, 4) rep(j, 4) ans += dp[n][i][j];
	cout << ans%MOD << endl;

	return 0;
}