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;

const int MOD = 10000;
int N, K, A, B;
int AB[101];
int dp[101][4][3];

int main() {

    fill(AB, AB + 101, 0);
    fill(dp[0][0], dp[100][3], 0);

    cin >> N >> K;

    for (int i = 1; i <= K; i++) {
        cin >> A >> B;
        AB[A] = B;
    }

    if (AB[1]) {
        dp[1][AB[1]][1] = 1;
    } else {
        dp[1][1][1] = 1;
        dp[1][2][1] = 1;
        dp[1][3][1] = 1;
    }

    for (int i = 2; i <= N; i++) {
        if (AB[i]) {
            for (int j = 1; j <= 3; j++) {
                if (j == AB[i]) {
                    dp[i][AB[i]][2] += dp[i - 1][j][1];
                } else {
                    dp[i][AB[i]][1] += dp[i - 1][j][1];
                    dp[i][AB[i]][1] += dp[i - 1][j][2];
                }
                dp[i][AB[i]][1] %= MOD;
                dp[i][AB[i]][2] %= MOD;
            }
        } else {
            for (int k = 1; k <= 3; k++) {
                for (int j = 1; j <= 3; j++) {
                    if (j == k) {
                        dp[i][k][2] += dp[i - 1][j][1];
                    } else {
                        dp[i][k][1] += dp[i - 1][j][1];
                        dp[i][k][1] += dp[i - 1][j][2];
                    }
                    dp[i][k][1] %= MOD;
                    dp[i][k][2] %= MOD;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 2; j++) {
            ans += dp[N][i][j];
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

C++: #include <iostream>
#include <cstring>

int decided[101];
int n;

int mem[101][4][2];
int solve(int day, int prevKind, int combo) {
	if (combo >= 3)
		return 0;
	if (day > n)
		return 1;
	
	auto& m = mem[day][prevKind][combo];
	if (m != -1)
		return m;

	if (decided[day] != 0) {
		return m = solve(
			day + 1,
			decided[day],
			(decided[day] == prevKind ? combo + 1 : 1)
		);
	}

	int sum = 0;
	for (int kind = 1; kind <= 3; ++kind) {
		sum += solve(
			day + 1,
			kind,
			(kind == prevKind ? combo + 1 : 1)
		);
	}

	return m = sum % 10000;
}

int main() {
	std::memset(mem, -1, sizeof(mem));
	int k;
	std::cin >> n >> k;
	
	for (int i = 0; i < k; ++i) {
		int day, kind;
		std::cin >> day >> kind;
		decided[day] = kind;
	}

	std::cout << solve(1, 0, 0) << std::endl;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	
	int N, K;
	
	int sum[4][4][200];
	
	int dic[200];
	
	cin >> N >> K;
	
	for(int i = 0; i <= N; i++){
		dic[i] = 0;
		for(int j = 0; j < 4; j++){
			for(int k = 0; k < 4; k++){
				sum[k][j][i] = 0;
			}
		}
	}
	
	int a, b;
	
	for(int i = 0; i < K; i++){
		cin >> a >> b;
		dic[a] = b;
	}
	
	if(dic[1] != 0){
		sum[0][dic[1]][1] = 1;
	}else{
		sum[0][1][1] = 1;
		sum[0][2][1] = 1;
		sum[0][3][1] = 1;
	}
	
	for(int i = 2; i <= N; i++){
		if(dic[i] != 0){
			for(int j = 0; j < 4; j++){
				for(int k = 1; k <= 3; k++){
					if(j != k || k != dic[i]){
						sum[k][dic[i]][i] += sum[j][k][i - 1];
						sum[k][dic[i]][i] = sum[k][dic[i]][i] % 10000;
					}
				}
			}
		}else{
			for(int j = 0; j < 4; j++){
				for(int k = 1; k <= 3; k++){
					for(int l = 1; l <= 3; l++){
						if(j != k || k != l){
							sum[k][l][i] += sum[j][k][i - 1];
							sum[k][l][i] = sum[k][l][i] % 10000;
						}
					}
				}
			}
		}
	}
	
	int ans = 0;
	
	for(int j = 0; j < 4; j++){
		for(int k = 0; k < 4; k++){
			ans += sum[j][k][N];
			ans = ans % 10000;
		}
	}
	
	/*
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < 4; j++){
			for(int k = 0; k < 4; k++){
				printf("%d ", sum[j][k][i]);
			}
			printf("\n");
		}
		printf("\n");
	}
	*/
	printf("%d\n", ans);
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int dp[101][4][4];
int yotei[101];
int N,K;

const int mod=10000;
int dfs(int pos,int o,int tw){
    if(pos==N)return 1;
    if(dp[pos][o][tw]!=-1)return dp[pos][o][tw];
    int res=0;
    if(yotei[pos]!=-1){
        int a=yotei[pos];
        if(a==o&&a==tw)return 0;
        res+=dfs(pos+1,a,o);
        res%=mod;
    }
    else{
        for(int a=0;a<3;a++){
            if(a==o&&a==tw)continue;
            res+=dfs(pos+1,a,o);
            res%=mod;
        }
    }
    return dp[pos][o][tw]=res%mod;
}

int main(){
    cin>>N>>K;
    memset(dp,-1,sizeof(dp));
    memset(yotei,-1,sizeof(yotei));
    for(int i=0;i<K;i++){
        int a,b;
        cin>>a>>b;
        yotei[a-1]=b-1;
    }
    int res=dfs(0,3,3)%mod;
    cout<<res<<endl;

    return 0;
}