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>
#define rep(a,b) for(int a=0;a<b;a++)
#define int long long int

using namespace std;

const int INF = 1000000009;

int day,al;
int almost[200];
int ans=1;
int used[200];

int pasu(int p){
    if(p==3)return 1;
    else if(p==2)return 3;
    else if(p==1)return 2;
}

int pasu2(int p){
    if(p==3)return 2;
    else if(p==2)return 1;
    else if(p==1)return 3;
}

int kaburi1(int date){
    if(almost[date+1]!=0){
        return almost[date+1];
    }else return 0;
}

int kaburi2(int date){
    if(almost[date+2]!=0){
        return almost[date+2];
    }else return 0;
}

int memo[200][200][200];

int pasuta(int d2, int d1, int dd1, int dd2,int date){
    if(date==day)return 1;
    else if(memo[d2][d1][date]>0&&dd2!=dd1)return memo[d2][d1][date];
    else if(almost[date]>0){
            ///?±??????£?????????
        return memo[d2][d1][date]=pasuta(d1,almost[date],almost[date+2],almost[date+3],date+1)%10000;
    }else if(d2==d1&&d1!=0){
        ///?????\??¨?????????????????¨???
       return memo[d2][d1][date]=(pasuta(d1,pasu(d1),almost[date+2],almost[date+3],date+1)+pasuta(d1,pasu2(d1),almost[date+2],almost[date+3],date+1))%10000;
    }else if(d1==dd1&&d1!=0){
        ///?????\??¨?????????????????¨???
       return memo[d2][d1][date]=(pasuta(d1,pasu(d1),almost[date+2],almost[date+3],date+1)+pasuta(d1,pasu2(d1),almost[date+2],almost[date+3],date+1))%10000;
    }else if(dd1==dd2&&dd1!=0){
        ///?????¨?????¨?????????
       return memo[d2][d1][date]=(pasuta(dd1,dd2,almost[date+5],almost[date+6],date+3)+pasuta(dd1,dd2,almost[date+5],almost[date+6],date+3))%10000;
    }else{
        return memo[d2][d1][date]=(pasuta(d1,1,almost[date+2],almost[date+3],date+1)+
        pasuta(d1,2,almost[date+2],almost[date+3],date+1)+
        pasuta(d1,3,almost[date+2],almost[date+3],date+1))%10000;
    }
}

signed main(){
    fill(almost,almost+200,0);
    fill(used,used+200,0);
    cin >> day >> al;
    rep(a,al){
        int da,pa;
        cin >> da >> pa;
        almost[da]=pa;
    }
    ans = pasuta(0,0,almost[1],almost[2],0);
    cout << ans%10000 << endl;
return 0;
}

C++: #include <bits/stdc++.h>
#define ll unsigned long long

using namespace std;

int main() {
    ll N,K;
    cin >>N>>K;
    vector<ll> yotei(N+1,0);
    for(ll i=0;i<K;i++) {
        ll a,b;
        cin >>a>>b;
        yotei[a] = b;
    }
    vector<vector<ll>> dp(N+1,vector<ll>(7,0));
    if(yotei[1]==0){
        dp[1][1] = 1;
        dp[1][2] = 1;
        dp[1][3] = 1;
    }else if(yotei[1]==1){
        dp[1][1] = 1;
    }else if(yotei[1]==2){
        dp[1][2] = 1;
    }else if(yotei[1]==3){
        dp[1][3] = 1;
    }
    for(ll i=1;i<N;i++) {
        for(ll j=1;j<=6;j++) {
            if(dp[i][j] >= 10000)dp[i][j]%=10000;
        }
        if(yotei[i+1]==0) {
            dp[i+1][1] = dp[i][2] + dp[i][3] + dp[i][5] + dp[i][6];
            dp[i+1][2] = dp[i][1] + dp[i][3] + dp[i][4] + dp[i][6];
            dp[i+1][3] = dp[i][1] + dp[i][2] + dp[i][4] + dp[i][5];
            dp[i+1][4] = dp[i][1];
            dp[i+1][5] = dp[i][2];
            dp[i+1][6] = dp[i][3];
        }else if(yotei[i+1]==1) {
            dp[i+1][1] = dp[i][2] + dp[i][3] + dp[i][5] + dp[i][6];
            dp[i+1][2] = 0;
            dp[i+1][3] = 0;
            dp[i+1][4] = dp[i][1];
            dp[i+1][5] = 0;
            dp[i+1][6] = 0;
        }else if(yotei[i+1]==2) {
            dp[i+1][1] = 0;
            dp[i+1][2] = dp[i][1] + dp[i][3] + dp[i][4] + dp[i][6];
            dp[i+1][3] = 0;
            dp[i+1][4] = 0;
            dp[i+1][5] = dp[i][2];
            dp[i+1][6] = 0;
        }else if(yotei[i+1]==3) {
            dp[i+1][1] = 0;
            dp[i+1][2] = 0;
            dp[i+1][3] = dp[i][1] + dp[i][2] + dp[i][4] + dp[i][5];
            dp[i+1][4] = 0;
            dp[i+1][5] = 0;
            dp[i+1][6] = dp[i][3];
        }
    }
    ll sum = 0;
    for(ll i=1;i<=6;i++) {
        sum+=(dp[N][i]);
    }
    cout << ((sum % 10000)+10000)%10000 << endl;
}

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

int main(){
	int n,k,a,b,t[102]={0},dp[102][5][5]={0};
	scanf("%d%d",&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d%d",&a,&b);
		t[a]=b;
	}
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			if((t[1]==0||t[1]==i)&&(t[2]==0||t[2]==j))dp[2][j][i]++;
		}
	}
	for(int m=3;m<=n;m++){
		int sum=0;
		for(int i=1;i<=3;i++)for(int j=1;j<=3;j++)sum+=dp[m-1][i][j];
		for(int i=1;i<=3;i++){
			for(int j=1;j<=3;j++){
				if(t[m]==0||t[m]==i){
					dp[m][i][j]=dp[m-1][j][1]+dp[m-1][j][2]+dp[m-1][j][3];
					if(i==j)dp[m][i][j]-=dp[m-1][i][i];
				}
				dp[m][i][j]%=10000;
			}
		}
	}

				
	int sum=0;
	for(int i=1;i<=3;i++)for(int j=1;j<=3;j++)sum+=dp[n][i][j];
	printf("%d\n",sum%10000);
}