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 pasuta(int d2, int d1, int dd1, int dd2,int date){
    if(date>day)return 1;
    else if(almost[date]!=0){
        return pasuta(d1,almost[date],kaburi1(date+1),kaburi2(date+1),date+1)%10000;
    }else if((d2==d1||d1==dd1)&&d1!=0){
       return (pasuta(d1,pasu(d1),kaburi1(date+1),kaburi2(date+1),date+1)+pasuta(d1,pasu2(d1),kaburi1(date+1),kaburi2(date+1),date+1))%10000;
    }else if(dd1==dd2&&dd1!=0){
        return (pasuta(d1,pasu(dd1),kaburi1(date+1),kaburi2(date+1),date+1)+pasuta(d1,pasu2(dd1),kaburi1(date+1),kaburi2(date+1),date+1))%10000;
    }else{
        return (pasuta(d1,1,kaburi1(date+1),kaburi2(date+1),date+1)+
        pasuta(d1,2,kaburi1(date+1),kaburi2(date+1),date+1)+
        pasuta(d1,3,kaburi1(date+1),kaburi2(date+1),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[2],almost[3],1);
    cout << ans%10000 << endl;
return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, k;
int c[100];
int dp[101][16];

int main(){
	cin >> n >> k;
	rep(i, k){
		int a, b;
		cin >> a >> b;
		c[a - 1] = b;
	}

	dp[0][0] = 1;
	rep(i, n){
		rep(j, 16){
			if(c[i]){
				if(j % 4 != c[i] || j / 4 != c[i]){
					dp[i + 1][(j % 4) * 4 + c[i]] = (dp[i][j] + dp[i + 1][(j % 4) * 4 + c[i]]) % 10000;
				}
			}
			else{
				for(k = 1; k < 4; ++k){
					if(j % 4 != k || j / 4 != k){
						dp[i + 1][(j % 4) * 4 + k] = (dp[i][j] + dp[i + 1][(j % 4) * 4 + k]) % 10000;
					}
				}
			}
		}
	}

	int ans = 0;
	rep(j, 16){
		 ans = (dp[n][j] + ans) % 10000;
	}
	cout << ans << endl;;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int dfs(int day,int tmt,int cream,int bazil);
int dfsmem[105][3][3][3];
int n,k;
int mem[105];
main(){
  cin>>n>>k;
  memset(mem,-1,sizeof(mem));
  memset(dfsmem,-1,sizeof(dfsmem));
  for(int i=0;i<k;i++){
    int a,b;
    cin>>a>>b;
    mem[a]=b;
  }
  cout<<dfs(1,0,0,0)<<endl;
}
int dfs(int day,int tmt,int cream,int bazil){
  if(tmt>=3||cream>=3||bazil>=3){
    return 0;
  }
  else if(day>n){
    return 1;
  }
  else if(dfsmem[day][tmt][cream][bazil]!=-1){
    return dfsmem[day][tmt][cream][bazil];
  }
  else if(mem[day]!=-1){
    if(mem[day]==1){
      return dfsmem[day][tmt][cream][bazil]=dfs(day+1,tmt+1,0,0)%10000;
    }
    else if(mem[day]==2){
      return dfsmem[day][tmt][cream][bazil]=dfs(day+1,0,cream+1,0)%10000;
    }
    else if(mem[day]==3){
      return dfsmem[day][tmt][cream][bazil]=dfs(day+1,0,0,bazil+1)%10000;
    }
  }
  else{
    int paturn=0;
    paturn+=dfs(day+1,tmt+1,0,0)%10000;
    paturn+=dfs(day+1,0,cream+1,0)%10000;
    paturn+=dfs(day+1,0,0,bazil+1)%10000;
    return dfsmem[day][tmt][cream][bazil]=paturn%10000;
  }
}

C++: #include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

std::vector<size_t> make_vector(size_t n, size_t x) {
  return std::vector<size_t>(n, x);
}

template <class Tp>
std::vector<Tp> make_vector(size_t n, const Tp& x) {
  return std::vector<Tp>(n, x);
}

template <class... Ts>
auto make_vector(size_t n, size_t m, const Ts&... x) {
  return std::vector<decltype(make_vector(m, x...))>(n, make_vector(m, x...));
}

int main() {
  size_t N, K;
  scanf("%zu %zu", &N, &K);

  std::vector<size_t> S(N+1);
  for (size_t i = 0; i < K; ++i){
    size_t A, B;
    scanf("%zu %zu", &A, &B);
    S[A] = B;
  }

  constexpr intmax_t mod = 1e4;
  auto dp = make_vector(N+1, 3, 3, size_t(0));

  {
    size_t i = 1;
    for (size_t k = 0; k < 3; ++k)
      if (S[i] == 0 || S[i]-1 == k)
        dp[i][0][k] = 1;
  }

  {
    size_t i = 2;
    for (size_t j = 0; j < 3; ++j)
      for (size_t k = 0; k < 3; ++k)
        if (S[i] == 0 || S[i]-1 == k)
          dp[i][j][k] += dp[i-1][0][j];
  }

  {
    for (size_t i = 3; i <= N; ++i)
      for (size_t j0 = 0; j0 < 3; ++j0)
        for (size_t j = 0; j < 3; ++j)
          for (size_t k = 0; k < 3; ++k)
            if ((S[i] == 0 || S[i]-1 == k) && !(j0 == k && j == k))
              (dp[i][j][k] += dp[i-1][j0][j]) %= mod;
  }

  intmax_t res = 0;
  for (size_t j = 0; j < 3; ++j)
    for (size_t k = 0; k < 3; ++k)
      (res += dp[N][j][k]) %= mod;

  printf("%jd\n", res);
}