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>
using namespace std;

long long int dp[101][3];

int main() {

    int n,k;

    cin >> n >> k;

    int day,s;

    bool a[101] = {false};
    int b[101] = {0};

    for(int i=0;i<k;i++){
        cin >> day >> s;
        a[day] = true;
        b[day] = s-1;
    }

    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    for(int k=0;k<3;k++){
        if(a[1] && b[1]!=k){
            dp[1][k] = 0;
        }
        else{
            dp[1][k] = 1;
        }
    }

    for(int i=2;i<=n;i++){

        for(int j=0;j<3;j++){
            if(a[i] && (b[i]!=j)){
                dp[i][j] = 0;
            }
            else {

                int sum = 0;
                for (int k = 0; k < 3; k++) {
                    /*if(i>2 && dp[i-1][k] != 0 && dp[i-2][k] != 0 && k!=j){
                        dp[i][j] += dp[i-1][k] - dp[i-2][k];
                    }
                    else {
                        dp[i][j] += dp[i-1][k];
                    }*/
                    sum += dp[i-1][k];
                }

                if(i>2) {

                    long long int sub = 0;

                    if(dp[i-1][j] != 0) {

                        sub = dp[i - 1][j] + 20000;
                        for (int k = 0; k < 3; k++) {
                            if (k != j) {
                                sub -= dp[i - 2][k];
                            }
                        }
                        sub %= 10000;
                        dp[i][j] = -sub;
                    }
                }

                dp[i][j] += sum + 10000;
            }

            dp[i][j] %= 10000;
            /*if(i>3 && dp[i-1][j] != 0 && dp[i-2][j] != 0){
                dp[i][j] = 0;
            }*/
        }

    }
/*
    ofstream ofs("output.txt");

    for(int i=0;i<=n;i++){

        for(int j=0;j<3;j++){

            ofs << dp[i][j] << " ";
        }

        ofs << endl;

    }
*/
    cout << (dp[n][0] + dp[n][1] + dp[n][2]) % 10000 << endl;

    return 0;
}

C++: #include <iostream>
using namespace std;
int unco[101][4][4];
int deta[101];
int main() {
	int n, k,unchi = 0;
	cin >> n >> k;
	for (int i = 0; i < k; i++){
		int x, y;
		cin >> x >> y;
		deta[x] = y;
	}
	unco[0][0][0] = 1;
	for(int hi = 0; hi <= n; hi++) {
		for(int one = 0; one <= 3; one++){
			for(int two = 0; two <= 3; two++) {
				if(deta[hi]) {
					if(!(deta[hi] == one && one == two)) {
						unco[hi][deta[hi]][one] += unco [hi - 1][one][two];
						unco[hi][deta[hi]][one] %= 10000;
					}
				}
				else {
					for(int l = 1; l <= 3; l++) {
						if(!(l == one && one == two)) {
							unco[hi][l][one] += unco[hi - 1][one][two];
							unco[hi][l][one] %= 10000;
						}
					}
				}
			}
		}
	}
	for(int i = 1; i<=3; i++){
		for(int j = 1; j<=3; j++){
			unchi += unco[n][i][j];
			unchi %= 10000;
		}
	}
	cout << unchi % 10000<<endl;
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define INF (1<<29)
#define EPS (1e-10)
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
int const MOD = 10000;

int main(){
	int N, K;
	cin >> N >> K;
	vii dp(N+1, vi(3, 1));
	for (int k=0; k<K; k++) {
		int A, B;
		cin >> A >> B;
		for (int b=0; b<3; b++) {
			if (b == B-1) continue;
			dp[A][b] = 0;
		}
	}

	for (int d=2; d<=N; d++) {
		for (int i=0; i<3; i++) {
			if (dp[d][i] == 0) continue;
			int sum = 0;
			for (int j=0; j<3; j++) {
				if (dp[d-1][j] == 0) continue;
				if (j == i && d != 2) {
					for (int k=0; k<3; k++) {
						if (k == j) continue;
						sum += dp[d-2][k];
					}
				} else {
					sum += dp[d-1][j];
				}
			}
			dp[d][i] = sum%MOD;
		}
	}
	int ans = dp[N][0]+dp[N][1]+dp[N][2];
	cout << ans%MOD << endl;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n, k;

int sche[100];

int dp[100][4][4];

int rec(int day, int a, int b) // a = i - 2 ??\???, b = i - 1 ??\???
{
    if (day == n) return 1;

    if (dp[day][a][b] >= 0) return dp[day][a][b];
    
    int res = 0;
    
    if (sche[day]) {
        if (sche[day] != a || sche[day] != b) {
            res += rec(day + 1, b, sche[day]);
            res %= 10000;
        }
    } else {
        for (int i = 1; i <= 3; ++i) {
            if (a == b && b == i) continue;
            res += rec(day + 1, b, i);
            res %= 10000;
        }
    }

    return dp[day][a][b] = res;
}

int main()
{
    cin >> n >> k;

    for (int i = 0; i < k; ++i) {
        int day; cin >> day; --day;
        cin >> sche[day];
    }

    memset(dp, -1, sizeof(dp));

    printf("%d\n", rec(0, 0, 0));
}