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 <vector>
#include <array>
#include <numeric>

int f(int, int, int);
int N;
int yotei[100];
int dp[111][4][4];

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

    int k, date;
    std::cin >> N >> k;
    for (int i = 0; i < k; i++) {
        std::cin >> date;
        std::cin >> yotei[date - 1];
    }

    for (int i = 0; i < 111; i++)
        for (int j = 0; j < 4; j++)
            for (int k = 0; k < 4; k++)
                dp[i][j][k] = -1;

    std::cout << f(0, 0, 0) << "\n";
    return 0;
}

int f(int day, int kinou, int ototui) {
    if (day == N) return 1;
    if (dp[day][kinou][ototui] >= 0) return dp[day][kinou][ototui];
    int ans = 0;

    for (int i = 1; i <= 3; i++) {
        if ((i == kinou && i == ototui) || (yotei[day] != 0 && i != yotei[day])) continue;

        ans += f(day + 1, i, kinou);
    }

    dp[day][kinou][ototui] = ans % 10000;
    return ans % 10000;
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> p(n, -1);
    rep (i, k) {
        int a, b;
        cin >> a >> b;
        p[--a] = --b;
    }
    vector <vector <vector <int>>> dp(n, vector <vector <int>> (3, vector <int> (3, 0)));
    rep (i, 3) rep (j, 3) {
        dp[0][p[0] == -1 ? i : p[0]][p[1] == -1 ? j : p[1]] = 1;
    }

    rep (i, n - 1) {
        if (i < n - 2 && p[i + 2] != -1) {
            rep (j, 3) rep (k, 3) if (j != k || k != p[i + 2]) {
                (dp[i + 1][j][p[i + 2]] += dp[i][k][j]) %= 10000;
            }
        }
        else {
            rep (j, 3) rep (k, 3) rep (l, 3) if (j != k || k != l) {
                (dp[i + 1][j][k] += dp[i][l][j]) %= 10000;
            }
        }
    }

    int cnt = 0;
    rep (i, 3) rep (j, 3) (cnt += dp[n - 2][i][j]) %= 10000;
    cout << cnt << endl;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
using namespace std;

const int UNEXPLORED = 0;
const int UNDEFINED = -1;
int n;

int main(void){
    int k; cin >> n >> k;
    int dp[n][3][3];
    int fixedPasta[n];
    rep(day, n) fixedPasta[day] = UNDEFINED;
    rep(i, n) rep(j, 3) rep(l, 3) dp[i][j][l] = UNEXPLORED;

    while(k --){
        int a, b; cin >> a >> b;
        fixedPasta[a - 1] = b - 1;
    }

    rep(day, n){
        if(fixedPasta[day] != UNDEFINED){
            if(day == 0){ dp[day][fixedPasta[day]][1] = 1; continue; }
            rep(p, 3)
                if(p != fixedPasta[day])
                    for(int d = 1; d <= 2; d ++)
                        (dp[day][fixedPasta[day]][1] += dp[day - 1][p][d]) %= 10000;
            dp[day][fixedPasta[day]][2] = dp[day - 1][fixedPasta[day]][1];
        }

        else{
            if(day == 0){ rep(p, 3) dp[day][p][1] = 1; continue; }
            rep(p, 3){
                rep(pd, 3)
                    if(p != pd)
                        for(int d = 1; d <= 2; d ++)
                            (dp[day][p][1] += dp[day - 1][pd][d]) %= 10000;
                dp[day][p][2] = dp[day - 1][p][1];
            }
        }
    }

    int result = 0;

    rep(p, 3)
        for(int d = 1; d <= 2; d ++)
            (result += dp[n - 1][p][d]) %= 10000;

    cout << result << endl;

    return 0;
}

C++: #include<iostream>
//#include<windows.h>
//#include<errno.h>
 
#define Iset int i,j,l
#define man 10000
#define cn continue
 
int pas[101], dt[101][4][4];
 
using namespace std;
 
int main() {
    int n, k;
    Iset;
    int ans = 0;
    cin >> n >> k;
    for (i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        pas[a] = b;
    }
    dt[0][0][0] = 1;
    for (i = 1; i <= n; i++) {
        if (pas[i] == 0) {
            for (j = 1; j <= 3; j++) {
                for (k = 0; k <= 3; k++) {
                    for (l = 0; l <= 3; l++) {
                        if (j == k && l == k) cn;
                        dt[i][j][k] += dt[i - 1][k][l];
                        dt[i][j][k] %= man;
                    }
                }
            }
        }
        else {
            for (k = 0; k <= 3; k++) {
                for (l = 0; l <= 3; l++) {
                    if (pas[i] == k && l == k)cn;
                    dt[i][pas[i]][k] += dt[i - 1][k][l];
                    dt[i][pas[i]][k] %= man;
                }
            }
        }
    }
    for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 3; j++) {
            ans += dt[n][i][j];
            ans %= man;
        }
    }
    cout << ans << endl;
    return 0;
}