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>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int main()
{
	for(int N,K;cin>>N>>K && N|K;){
		vi as(K),bs(K);
		for(int i=0;i<K;i++){
			cin>>as[i]>>bs[i];
			as[i]--; bs[i]--;
		}
		
		for(int i=0;i<K;i++)
			for(int j=K-1;j--;)
				if(as[j]>as[j+1]){
					swap(as[j],as[j+1]);
					swap(bs[j],bs[j+1]);
				}
		
		int si=0;
		vector<vvi> ps(N,vvi(3,vi(3)));
		
		int i=0;
		if(i<N){
			for(int j=0;j<3;j++)
				ps[i][j][0]=1;
			if(si<K && as[si]==i){
				for(int j=0;j<3;j++)
					if(j!=bs[si])
						ps[i][j][0]=0;
				si++;
			}
			i++;
		}
		if(i<N){
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					for(int l=0;l<3;l++)
						ps[i][j][k]+=ps[i-1][k][l];
			if(si<K && as[si]==i){
				for(int j=0;j<3;j++)
					if(j!=bs[si])
						for(int k=0;k<3;k++)
							ps[i][j][k]=0;
				si++;
			}
			i++;
		}
		for(;i<N;i++){
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					for(int l=0;l<3;l++){
						if(j==k && k==l)
							continue;
						ps[i][j][k]=(ps[i][j][k]+ps[i-1][k][l])%10000;
					}
			if(si<K && as[si]==i){
				for(int j=0;j<3;j++)
					if(j!=bs[si])
						for(int k=0;k<3;k++)
							ps[i][j][k]=0;
				si++;
			}
		}
		
		int res=0;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				res+=ps[N-1][i][j];
		cout<<res%10000<<endl;
	}
	return 0;
}

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 <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

int N, K;
int pasta[110];

int dp[110][10][10];
const int MOD = 10000;

void solve() {
	minit(dp, 0);
	if (pasta[0] != -1) dp[1][pasta[0]][1] = 1;
	else for_(j,0,3) dp[1][j][1] = 1;
	
	for_(i,1,N) for_(j,0,3) for_(k,1,3) {
		if (pasta[i] == -1) {
			for_(jj,0,3) {
				if (j == jj) {
					dp[i + 1][jj][k + 1] += dp[i][j][k];
					dp[i + 1][jj][k + 1] %= MOD;
				}
				else {
					dp[i + 1][jj][1] += dp[i][j][k];
					dp[i + 1][jj][1] %= MOD;
				}
			}
		} else {
			if (j == pasta[i]) {
				dp[i + 1][j][k + 1] += dp[i][j][k];
				dp[i + 1][j][k + 1] %= MOD;
			}
			else {
				dp[i + 1][pasta[i]][1] += dp[i][j][k];
				dp[i + 1][pasta[i]][1] %= MOD;
			}
		}
	}
	
	int ans = 0;
	for_(j,0,3) for_(k,1,3) {
		ans += dp[N][j][k];
		ans %= MOD;
	}
	
	cout << ans << endl;
}

int main() {
	cin >> N >> K;
	
	minit(pasta, -1);
	for_(i,0,K) {
		int a, b; cin >> a >> b;
		--a; --b;
		pasta[a] = b;
	}
	
	solve();
	return 0;
}