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

int n, k;
int a[100];
int dp[100][3][3];

int main(){
	scanf("%d %d", &n, &k);
	for(int i=0; i<k; i++){
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		a[t1-1] = t2;
	}

	if(a[0] == 0){
		for(int i=0; i<3; i++){
			dp[0][i][0] = 1;
		}
	}else{
		dp[0][a[0]-1][0] = 1;
	}

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

	for(int i=2; i<n; i++){
		if(a[i] == 0){
			for(int p=0; p<3; p++){
				for(int q=0; q<3; q++){
					for(int r=0; r<3; r++){
						if(p == q && q == r) continue;
						else{
							dp[i][p][q] += dp[i-1][q][r];
							dp[i][p][q] %= 10000;
						}
					}
				}
			}
		}else{
			for(int p=0; p<3; p++){
				for(int q=0; q<3; q++){
					if(a[i] - 1 == p && p == q) continue;
					else{
						dp[i][a[i] - 1][p] += dp[i-1][p][q];
						dp[i][a[i] - 1][p] %= 10000;
					}
				}
			}
		}
	}
/*
	for(int i=0; i<n; i++)
		printf("%d\t", a[i]);
*/

/*	for(int i=0; i<n; i++){
		for(int j=0; j<3; j++){
			printf("%d\t", dp[i][j][0] + dp[i][j][1] + dp[i][j][2]);
		}
		printf("\n");
	}
*/
	int ans=0;
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			ans += dp[n-1][i][j];
			ans %= 10000;
		}
	}
	printf("%d\n", ans);
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,K,a,b;
	cin>>N>>K;
	int dp[110][4]={};
	for(int i=0;i<K;i++){
		cin>>a>>b;
		dp[a][b]=1;
	}
	if(dp[1][1]==0 && dp[1][2]==0 && dp[1][3]==0){
		for(int i=1;i<=3;i++){
			dp[1][i]=1;
		}
	}

	for(int i=1;i<=N;i++){
		if(dp[i+1][1]==0 && dp[i+1][2]==0 && dp[i+1][3]==0){
			for(int j=1;j<=3;j++){
				
				if(dp[i][j]>0 && dp[i+2][j]>0){
					dp[i+1][j]=dp[i][1]+dp[i][2]+dp[i][3]-dp[i][j];


				}
				else if(dp[i+2][j]>0 && dp[i+3][j]>0){
					dp[i+1][j]=0;


				}
				else if(dp[i-1][j]>0  && dp[i][j]>0){
					dp[i+1][j]=dp[i][1]+dp[i][2]+dp[i][3]-dp[i][j]+(dp[i-1][1]+dp[i-1][2]+dp[i-1][3]-dp[i-1][j]);

				}

				else{
					dp[i+1][j]=dp[i][1]+dp[i][2]+dp[i][3];
				}
			}
		}
		else{
			for(int j=1;j<=3;j++){
				if(dp[i+1][j]==1){
					dp[i+1][j]=dp[i][1]+dp[i][2]+dp[i][3];
				}
			}
		}
	}
	cout<<(dp[N][1]+dp[N][2]+dp[N][3])%10000<<endl;
	return 0;
	

	}

C++: #include<iostream>
using namespace std;

struct day
{
  int kind[4];
  int order;
  int sum;
};

int n, k;
int a[100], b[100];
day dp[101];

int main()
{
  cin >> n >> k;
  for(int i = 0; i < k; i++)
    cin >> a[i] >> b[i];

  for(int i = 0; i < k; i++)
    dp[a[i]].order = b[i];

  //day 1
  if(dp[1].order)
    dp[1].sum = dp[1].kind[dp[1].order] = 1;
  else
    for(int i = 1; i <= 3; i++)
      dp[1].sum += dp[1].kind[i] = 1;

  //day 2
  if(dp[2].order)
    dp[2].sum = dp[2].kind[dp[2].order] = dp[1].sum;
  else
    for(int i = 1; i <= 3; i++)
      dp[2].sum += dp[2].kind[i] = dp[1].sum;

  //day 3
  for(int i = 3; i <= n; i++){
    if(dp[i].order){
      if(!dp[i - 1].kind[dp[i].order])
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum;
      else
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum - dp[i - 1].kind[dp[i].order] + dp[i - 2].sum - dp[i - 2].kind[dp[i].order];
    }
    else{
      for(int j = 1; j <= 3; j++){
	
	if(!dp[i - 1].kind[j])
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum;
	else
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum - dp[i - 1].kind[j] + dp[i - 2].sum - dp[i - 2].kind[j];
      }

      dp[i].sum %= 10000;
    }
  }

  cout << dp[n].sum % 10000 << endl;
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e4;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

vector<int> meal;
int dp[110][4][2];
int N, K;

int dfs(int i, int j, bool k)
{
    if (dp[i][j][k] != -1)
        return dp[i][j][k];

    if (i == N + 1)
        return 1;

    int res = 0;

    if (meal[i] != 0)
    {
        if (k && j == meal[i])
            return 0;

        res = dfs(i + 1, meal[i], meal[i] == j);

        return dp[i][j][k] = res % MOD;
    }

    FOR(n, 1, 4)
    {
        if (k && j == n) continue;

        res += dfs(i + 1, n, n == j);
    }

    return dp[i][j][k] = res % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K;

    meal.resize(N + 1, 0);

    REP(i, K)
    {
        int a, b;
        cin >> a >> b;
        meal[a] = b;
    }

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

    Cout(dfs(1, 0, 0));

    return 0;
}