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 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 = 1; j < 4; j++)
        for (int k = 1; 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<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int k;
int a,q[200]={0};
int b,w[200]={0};
int cnt1=0,cnt2=0,cnt3=0;
int cnt=0,ans=0,co=0;
void check (int x);
int main(void){
    cin>>n>>k;

	for(int i=0;i<k;i++){
        cin>>a;
        cin>>b;
        q[a-1]=b;
	}
	/*for(int i=1;i<=20;i++){
	n=i;*/
	check(0);

    cout<<ans<<endl;
    /*co=0;
    ans=0;
	}	*/
	return 0;
}
void check(int x){
    /*for(int i=0;i<x;i++){
        cout<<"-";
    }
    cout<<(co+1)/2<<endl;*/

    if(x==n){
        ans++;
        //if(ans>=10000)ans-=10000;
        //cout<<"+"<<co<<endl;
        return;
    }
    if(q[x]!=0){
        if(q[x]==1){
            if(co==2)return;
            else if(co==1)co++;
            else co=1;
            check(x+1);
        }
        else if(q[x]==2){
            if(co==4)return;
            else if(co==3)co++;
            else co=3;
            check(x+1);
        }
        else if(q[x]==3){
            if(co==6)return;
            else if(co==5)co++;
            else co=5;
            check(x+1);
        }

    }
    else{

        if(co!=2){
            int sub=co;
            if(co==1)co++;
            else co=1;
            check(x+1);
            co=sub;
        }
        if(co!=4){
            int sub=co;
            if(co==3)co++;
            else co=3;
            check(x+1);
            co=sub;
        }
        if(co!=6){
            int sub=co;
            if(co==5)co++;
            else co=5;
            check(x+1);
            co=sub;
        }
    }


}

C++: #include<iostream>

using namespace std;

int N, K;
const int MOD = 10000;

int order[100], dp[100][3][3];//[day][today][yesterday]

int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		order[a - 1] = b;
	}
	if (!order[0]) {
		dp[0][0][1] = 1;
		dp[0][1][0] = 1;
		dp[0][2][0] = 1;
	}
	else
		if (order[0] - 1)dp[0][order[0] - 1][0] = 1;
		else dp[0][order[0] - 1][1] = 1;
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (!order[i]) {
					for (int l = 0; l < 3; l++) {
						if (order[i + 1] - 1 == l || !order[i + 1]) {
							if (j != k) dp[i + 1][l][j] += dp[i][j][k], dp[i + 1][l][j] %= MOD;
							else {
								if (j != l)dp[i + 1][l][j] += dp[i][j][k],dp[i + 1][l][j] %= MOD;
							}
						}
					}
				}
				else {
					for (int l = 0; l < 3; l++) {
						if (order[i + 1] - 1 == l || !order[i + 1]) {
							if (j != k) dp[i + 1][l][j] += dp[i][j][k], dp[i + 1][l][j] %= MOD;
							else {
								if (j != l)dp[i + 1][l][j] += dp[i][j][k], dp[i + 1][l][j] %= MOD;
							}
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)ans += dp[N - 1][i][j];
	cout << ans % MOD<< endl;
	return 0;
}