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 <stdio.h>
#include <string.h>
int main(){
	int N,K;//N日分のシミュレーション
	scanf("%d %d",&N,&K);
	long long int dp[N][3];
	long long int delete[3];
	int i,j,k;
	memset(dp,0,sizeof(dp));//初期化
	memset(delete,0,sizeof(delete));
	int a,b;
	for(i=0;i<K;i++){
		scanf("%d %d",&a,&b);
		dp[a-1][b-1]=1;
	}
	if(dp[0][0]==0&&dp[0][1]==0&&dp[0][2]==0){//予約がなければ全てあり得る
		dp[0][0]++;
		dp[0][1]++;
		dp[0][2]++;
	}
	int flag;
	long long int temp=0;
	for(i=1;i<N;i++){
		flag=0;
		temp=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
		for(j=0;j<3;j++){
			if(dp[i][j]==1){
				dp[i][j]=temp-delete[j];
				for(k=0;k<3;k++){
					if(k==j){
						delete[j]=dp[i-1][j]-delete[j];//2日連チャンで食べている通り
					}
					else{
						delete[k]=0;
					}
				}
				flag=1;
				break;
			}
		}
		if(flag==0){
			for(j=0;j<3;j++){
				dp[i][j]=temp-delete[j];
				delete[j]=dp[i-1][j]-delete[j];
			}
		}
		if(delete[0]>10000&&delete[1]>10000&&delete[2]>10000){
			delete[0]%=10000;
			delete[1]%=10000;
			delete[2]%=10000;
			dp[i][0]=(dp[i][0]%10000)+10000;
			dp[i][1]=(dp[i][1]%10000)+10000;
			dp[i][2]=(dp[i][2]%10000)+10000;
			
		}
	}
	printf("%lld\n",(dp[N-1][0]+dp[N-1][1]+dp[N-1][2])%10000);
	return 0;
}

C++: #include<bits/stdc++.h>
#define N 101
using namespace std;
int dp[N][4][4],n,k,d[N];

int solve(int x,int d1,int d2){
   if(x==0) return 1;
   if(dp[x][d1][d2]>0) return dp[x][d1][d2];
  if(d[x]>0){
    if(d1!=d[x] || d2!=d[x]) dp[x][d1][d2]=(dp[x][d1][d2]+solve(x-1,d[x],d1))%10000;
  }
  else {
    for(int i=1;i<4;i++){
      if(d1==i && d2==i)continue;
      else dp[x][d1][d2]=(dp[x][d1][d2]+solve(x-1,i,d1))%10000;
    }
  }
  return dp[x][d1][d2];
}

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

  for(int i=0;i<k;i++)cin>>a>>b,d[a]=b;
  cout<<solve(n,0,0)<<endl;
  return 0;
}

C++: # include <iostream>

# define MAX_N 100
# define MOD 10000

int n, K;

int plan[MAX_N+1];
int memo[MAX_N+1][4][4];

int solve(int day,int t,int y){
	if (day == n + 1)
		return 1;
	if (memo[day][t][y] != -1)
		return memo[day][t][y];
	if (plan[day + 1] != 0){
		if (t == y&&t == plan[n + 1])
			return 0;
		else
			return solve(day + 1, plan[day + 1], t)%MOD;
	}

	int result = 0;
	for (int i = 1; i <= 3; ++i){
		if (t == y&&t == i)
			continue;
		else
			result+=solve(day + 1, i, t)%MOD;
	}
	return memo[day][t][y] = result%MOD;
}

int main(){
	int d, k;
	std::cin >> n >> K;

	for (int i = 0; i < K; ++i){
		std::cin >> d >> k;
		plan[d] = k;
	}

	for (int i = 1; i <= n; ++i){
		for (int j = 1; j < 4; ++j){
			for (int k = 0; k < 4; ++k){
				memo[i][j][k] = -1;
			}
		}
	}

	std::cout << solve(1, 0, 0) << std::endl;

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define rep(X, Y) for( int (X) = 0; (X) < (Y); ++(X) )
#define rept(X, Y, Z) for( int (X) = (Y); (X) < (Z); ++(X) )
#define MOD 10000

int N, K, tmp[2];
int memo[101][4][4];
int def[101];

int func(int d, int op, int tp){
	if( memo[d][op][tp] != -1 ) return memo[d][op][tp];

	int sum = 0;

	if( d == N ) return 1;

	rept( i, 1, 4 ){
		if( def[d] != 0 && def[d] != i || op == tp && i == op ) continue;

		sum += func( d + 1, i, op ) % MOD;
	}

	return memo[d][op][tp] = sum % MOD;
}

int main(){
	memset( memo, -1, sizeof(memo) );

	scanf( "%d%d", &N, &K );

	rep( i, K ){
		scanf("%d%d", tmp, tmp + 1);

		def[tmp[0] - 1] = tmp[1];
	}

	std::cout << func(0, 0, 0) % MOD << std::endl;

	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n, k ,a;
	int  b[101];
	int dp[101][4][4];
	for (int i = 0; i <= 100; i++)
	{
		b[i] = 0;
		for (int j = 0; j <= 3; j++)
		{
			for (int l = 0; l <= 3; l++)
			{
				dp[i][j][l] = 0;
			}
		}
	}
	cin >> n >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> a;
		cin >> b[a-1];
	}
	if (b[0] == 0)
	{
		dp[0][1][0] = 1; dp[0][2][0] = 1; dp[0][3][0] = 1;
	}
	else
	{
		dp[0][b[0]][0] = 1;
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j <= 3; j++)
		{
			if (b[i] == 0 || b[i] == j)
			{
				for (int l = 1; l <= 3; l++)
				{
					dp[i][j][l] += (dp[i - 1][l][0] + dp[i - 1][l][1] + dp[i - 1][l][2] + dp[i - 1][l][3]);
					if (j == l)
					{
						dp[i][j][l] -= dp[i - 1][l][l];
					}
					dp[i][j][l] = dp[i][j][l] % 10000;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= 3; i++)
	{
		for (int j = 1; j <= 3; j++)
		{
			ans += dp[n - 1][i][j];
		}
	}
	cout << ans%10000 << endl;
	return 0;
}