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;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int mod = 10000;

	int n,k; cin >> n >> k;

	int s[101]; memset(s,0,sizeof(s));

	for (int i = 0;i < k;i++){
		int a,b; cin >> a >> b;
		s[a-1] = b;
	}

	int dp[200][4][2]; memset(dp,0,sizeof(dp));

	if(s[0] > 0) dp[0][s[0]][0] = 1;
	else{ dp[0][1][0] = 1; dp[0][2][0] = 1; dp[0][3][0] = 1;}

	for (int i = 0;i < n;i++){
		for (int j = 1;j <= 3;j++){
			for (int k = 0;k < 2;k++){
				if(dp[i][j][k] == 0) continue;
				//cout << dp[i][j][k] << endl;
				int ni = i+1;
				dp[i][j][k] %= mod;
				if(s[ni] > 0){
					if(j == s[ni]){
						if(k == 0) dp[i+1][j][1] += dp[i][j][k];
					}else{
						dp[i+1][s[ni]][0] += dp[i][j][k];
					}
				}else{
					if(k == 0){
						for (int l = 1;l <= 3;l++){
							if(l == j) dp[i+1][l][1] += dp[i][j][k];
							else dp[i+1][l][0] += dp[i][j][k];
						}
					}else{
						for (int l = 1;l <= 3;l++){
							if(l == j) continue;
							dp[i+1][l][0] += dp[i][j][k];
						}
					}
				}
			}
		}
	}

	int ans = 0;

	for (int i = 1;i <= 3;i++){
		for (int j = 0;j < 2;j++){
			//cout << dp[n][i][j] << endl;
			ans += dp[n-1][i][j];
			ans %= mod;
		}
	}

	cout << ans << endl;

	return 0;

}

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

constexpr int mod = 10000;
int n, k;
int memo[100][4][3];

unordered_map<int, int> determined;

int dfs(int day, int eated, int num) {
	if(num == 3) return 0;
	if(day == n) return 1;
	if(memo[day][eated][num] != -1) return memo[day][eated][num];

	if(determined.count(day)) {
		const int eating = determined[day];
		return memo[day][eated][num] = dfs(day + 1, eating, (eated == eating ? num + 1 : 1));
	}

	int res = 0;
	for(int i = 0; i < 3; ++i) {
		res += dfs(day + 1, i, (eated == i ? num + 1 : 1));
		res %= mod;
	}

	return memo[day][eated][num] = res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n >> k;

	for(int i = 0; i < k; ++i) {
		int a, b;
		cin >> a >> b;
		determined[a - 1] = b - 1;
	}

	memset(memo, -1, sizeof(memo));
	cout << dfs(0, 3, 0) << endl;

	return EXIT_SUCCESS;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
using namespace std;
long long int dp[101][4][4];
int main(void)
{
	int i,j,k,n,m,a,b[101],c;
	long long int sum,x;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			for(k=0;k<=3;k++) dp[i][j][k]=0;
		}
	}
	for(i=1;i<=n;i++) b[i]=0;
	for(i=1;i<=m;i++){
		cin>>a;
		cin>>b[a];
	}
//	for(i=1;i<=n;i++)	printf("b=%d\n",b[i]);
	if(b[1]>0) dp[1][b[1]][0]=1;
	else{
		for(i=1;i<=3;i++) dp[1][i][0]=1;
	}
	for(i=1;i<n;i++){
//		printf("i=%d\n",i);
		for(j=1;j<=3;j++){
			if(dp[i][j][0]+dp[i][j][1]+dp[i][j][2]+dp[i][j][3]>0){
				for(k=0;k<=3;k++){
					if(b[i+1]>0){
						if(b[i+1]!=k||b[i+1]!=j){
							dp[i+1][b[i+1]][j]+=dp[i][j][k];
							dp[i+1][b[i+1]][j]%=10000;
						}
					}
					else{
						if(k!=1||j!=1){
							dp[i+1][1][j]+=dp[i][j][k];
							dp[i+1][1][j]%=10000;
						}
						if(k!=2||j!=2){
							dp[i+1][2][j]+=dp[i][j][k];
							dp[i+1][2][j]%=10000;
						}
						if(k!=3||j!=3){
							dp[i+1][3][j]+=dp[i][j][k];
							dp[i+1][3][j]%=10000;
						}
					}
				}
			}
		}
/*		for(j=1;j<=3;j++)	{
			for(k=1;k<=3;k++)	{			
				printf("dp=%d ",dp[i][j][k]);
			}
			printf("\n");
		}*/
	}
/*	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			sum=0;
			for(k=0;k<=3;k++) sum+=dp[i][j][k];
			printf("%lld ",sum);
		}
		printf("\n");
	}*/
	sum=0;
	for(i=1;i<=3;i++){
		for(j=0;j<=3;j++) sum+=dp[n][i][j];
	}
	x=sum%10000;
	printf("%d\n",x);
	return 0;
}

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

int N, K;
vector<int> plan;
vector<vector<vector<int > > > dp;

int solve(int day, int today, int tommorow) {
	if (dp[day][today][tommorow] != -1) return dp[day][today][tommorow];
	if (day == N - 2)return 1;
	int tmp = 0;
	dp[day][today][tommorow] = 0;
	for (int i = 0; i < 3; i++) {
		if ((plan[day + 2] != -1 && plan[day + 2] != i) || (today == tommorow && tommorow == i))continue;
		dp[day][today][tommorow] += solve(day + 1, tommorow, i);
	}
	if (dp[day][today][tommorow] > 10000)dp[day][today][tommorow] %= 10000;
	return dp[day][today][tommorow];
}

int main() {
	cin >> N >> K;
	plan = vector<int>(N+2, -1);
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		plan[a - 1] = b - 1;
	}
	dp = vector<vector<vector<int > > >(N+2, vector<vector<int> >(3, vector<int>(3, -1)));

	int ans = 0;
	for (int i = 0; i < 3; i++){
		if (plan[0] != -1 && plan[0] != i)continue;
		for (int j = 0; j < 3; j++) {
			if (plan[1] != -1 && plan[1] != j)continue;
			ans += solve(0, i, j);
		}
	}

	if (ans > 10000)ans %= 10000;
	cout << ans << endl;
	return 0;
}