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<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int k;
int q[200]={0};
int a,b;
int ans=0;
int mem[110][5][5]={{{0}}};
int check(int x,int y,int z);//x日目,前日y,前々日z
int main(void){
    cin>>n>>k;

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



    cout<<check(0,0,0)<<endl;
	return 0;
}
int check(int x,int y,int z){
    if(mem[x][y][z]!=0)return mem[x][y][z];

    if(x==n){

        return 1;
    }
    if(q[x]!=0){
        if(q[x]==1){
            if(y!=1||z!=1){
            return check(x+1,1,y);
            }
            else return 0;
        }
        else if(q[x]==2){
            if(y!=2||z!=2){
            return check(x+1,2,y);
            }
            else return 0;
        }
        else if(q[x]==3){
            if(y!=3||z!=3){
            return check(x+1,3,y);
            }
            else return 0;
        }

    }
    else{

        if(y!=z||y==0){
            int a=check(x+1,1,y)+check(x+1,2,y)+check(x+1,3,y);
            a%=10000;
            mem[x][y][z]=a;
            return a;

        }
        else if(y==1){

            int a=check(x+1,2,y)+check(x+1,3,y);
            a%=10000;
            mem[x][y][z]=a;
            return a;
        }
        else if(y==2){

            int a=check(x+1,1,y)+check(x+1,3,y);
            a%=10000;
            return a;
        }
        else if(y==3){

            int a=check(x+1,1,y)+check(x+1,2,y);
            a%=10000;
            mem[x][y][z]=a;
            return a;

        }
    }

C++: #include <iostream>
#include <cstring>

using namespace std;
#define mod 10000
#define MAX_N (100+1)
int n, k;
int sche[MAX_N];

int cnt(int day, int one, int two) {
    if (day == n) return 1;
    if (sche[day] > 0) {
        if (one == two && two == sche[day]) return 0;
        return cnt(day+1, sche[day], one);
    }
    int ret = 0;
    for (int i = 1; i <= 3; i++) {
        if (one == two && two == i) continue;
        ret += cnt(day+1, i, one);
        ret %= mod;
    }
    return ret % mod;
}

int main() {
    cin >> n >> k;
    memset(sche, -1, sizeof(sche));
    for (int i = 0; i < k; i++) {
        int d, p; cin >> d >> p;
        d--;
        sche[d] = p;
    }
//    for (int i = 0; i < n; i++) cout << sche[i] << ' ';cout << endl;
    cout << cnt(0, -1, -1) << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;

typedef unsigned long long ull;

int main(){
    int N, K;
    std::cin >> N >> K;

    int dp[110][5][5];
    REP(i, 110){
        REP(j, 5){
            REP(k, 5){
                dp[i][j][k] = 0;
            }
        }
    }
    
    int P[110];
    std::fill(P, P+110, 0);

    REP(i, K){
        int a, b;
        std::cin >> a >> b;

        P[a] = b;
    }

    if(P[1] == 0){
        dp[1][1][1] = 1;
        dp[1][2][1] = 1;
        dp[1][3][1] = 1;
    }else{
        dp[1][P[1]][1] = 1;
    }

    FOR(i, 2, N+1){
        if(P[i] != 0){
            //printf("Call: Day %d\n", i);
            dp[i][P[i]][2] = dp[i-1][P[i]][1];
            //dp[i][P[i]][3] = dp[i-1][P[i]][2];
            FOR(j, 1, 4){
                if(j == P[i]){continue;}
                FOR(k, 1, 3){
                    dp[i][P[i]][1] = (dp[i][P[i]][1] + dp[i-1][j][k]) % 10000;
                }
            }
        }else{
            FOR(j, 1, 4){
                FOR(k, 1, 3){
                    if(k >= 2){
                        dp[i][j][k] = dp[i-1][j][k-1];
                    }else{
                        FOR(l, 1, 4){
                            if(j == l){continue;}

                            //printf("Call: Day %d, Pasta %d L %d\n", i, j, l);
                            
                            dp[i][j][k] = (dp[i][j][k] + dp[i-1][l][1] + dp[i-1][l][2]) % 10000;
                        }
                    }
                }
            }
        }
    }

    // FOR(i, 1, N+1){
    //     printf("Day %d:\n", i);
    //     FOR(j, 1, 4){
    //         FOR(k, 1, 3){
    //             printf("%d ", dp[i][j][k]);
    //         }
    //         puts("");
    //     }
    // }

    int res = 0;
    FOR(i, 1, 4){
        FOR(j, 1, 3){
            res = (res + dp[N][i][j]) % 10000;
        }
    }

    std::cout << res << std::endl;
}