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 <algorithm>
using namespace std;
int main(){
    int n;
    int k;
    cin>>n>>k;
    int dp[100][3];
    for(int i=0;i<n;i++){
        for(int ii =0;ii<3;ii++){
            dp[i][ii] = 0;
        }
    }
    for(int i=0;i<k;i++){
        int a;
        int b;
        cin>>a>>b;
        dp[a-1][0] = -1;
        dp[a-1][1] = -1;
        dp[a-1][2] = -1;
        dp[a-1][b-1] = 0;
    }
    for(int i= 0; i<n;i++){
        for(int ii= 0;ii<3;ii++){
             
            if(dp[i][ii] == -1){
                dp[i][ii] = 0;
            }else{
                if(i==0)dp[i][ii]=1; 
                if(i!=0)dp[i][ii]=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
    if(i>=2){
        if(dp[i-1][ii]>0)
        dp[i][ii] = dp[i-2][0]+dp[i-2][1]+dp[i-2][2]-dp[i-2][ii]+dp[i-1][0]+dp[i-1][1]+dp[i-1][2]-dp[i-1][ii];
    }
            }
            dp[i][ii]= dp[i][ii]%10000;
        }
    }
    int res = dp[n-1][0]+dp[n-1][1]+dp[n-1][2];
    res = res%10000;
    cout<<res<<endl;
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <numeric>

int N;
int yotei[100], 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;

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


    for (int i = N - 1; i >= 0; --i)
        for (int j = 1; j < 4; j++)
            for (int k = 1; k < 4; k++) {
                for (int m = 1; m < 4; m++) {
                    if ((m == j && m == k) || (yotei[i] != 0 && m == yotei[i]))
                        continue;
                    dp[i][j][k] += dp[i + 1][m][j];
                }
                dp[i][j][k] %= 10000;
            }
    int ans = 0;

    for (int j = 1; j < 4; j++)
        for (int k = 1; k < 4; k++) {
            if (dp[0][j][k] != -1) ans += dp[0][j][k];
            ans %= 10000;
        }

    std::cout << ans << "\n";
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define A first
#define B second

using namespace std;

typedef pair<int,int> P;

int main(void){
	
	int n,k,dp[102][4][3];
	
	cin >> n >> k;
	
	vector<P>v(k);
	
	for(int i=0;i<k;i++)
		cin >> v[i].A >> v[i].B;
	
	sort(v.begin(),v.end());
	
	for(int i=0;i<101;i++)
		for(int j=0;j<4;j++)
			for(int k=0;k<3;k++)
				dp[i][j][k]=0;
	
		for(int i=1;i<4;i++)dp[1][i][1]=1;
	
	int p=0;
	
	for(int i=1;i<=n;i++){
		for(int k=1;k<4;k++){
			for(int l=1;l<3;l++){
					
				if(i==v[p].A){
					if(v[p].B==k && l<2)dp[i+1][k][l+1]+=dp[i][v[p].B][l]%10000;
					else if(v[p].B!=k)dp[i+1][k][1]+=dp[i][v[p].B][l]%10000;
					continue;
				}
					
				for(int j=1;j<4;j++){
					if(j==k && l<2)dp[i+1][k][l+1]+=dp[i][j][l]%10000;
					else if(j!=k)dp[i+1][k][1]+=dp[i][j][l]%10000;
				}
			}
		}
		if(v[p].A==i)p++;
	}
	
	int ans=0;
	

		for(int i=1;i<4;i++){
			for(int j=1;j<3;j++){
				ans+=dp[n][i][j];
				ans%=10000;
			}
		}

	
	cout << ans << endl;
	
return 0;
}