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 <algorithm>

#include <vector>
#include <cmath>

using namespace std;

#define int long long

int dp[101][3][2]={};

inline int che(int ret)
{
    return ret >= 0 ? ret : 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int ans = 0;
    int day=0,dec=0;
    cin >> day>>dec;
    
    int ind,ink;
    
    for(int i=0;i<3;++i)
        dp[0][i][0] = 1;
    
    for(int i=0;i<dec;++i)
    {
        cin >> ind >> ink;
        ink--;
        ind--;
        for(int k=0;k<3;++k)
        {
            if(k!=ink)
            {
                dp[ind][k][0] = dp[ind][k][1] = -1;
            }
        }
    }
    //dp
    for(int i=0;i<day;++i)
    {
        for(int k = 0;k<3;++k)
        {
        //    cout << i <<":" <<k << " "<<dp[i][k][0] << " " << dp[i][k][1] <<endl;
            if(dp[i][k][0]!=-1)
            {
                dp[i][k][0] %= 10000;
                dp[i][k][1] %= 10000;
                
                if(dp[i+1][(k+1)%3][0] >= 0) dp[i+1][(k+1)%3][0] += dp[i][k][0];
                if(dp[i+1][(k+2)%3][0] >= 0) dp[i+1][(k+2)%3][0] += dp[i][k][0];
                
                if(dp[i+1][k][1] >= 0) dp[i+1][k][1] += dp[i][k][0];
                
                if(dp[i+1][(k+1)%3][0] >= 0) dp[i+1][(k+1)%3][0] += dp[i][k][1];
                if(dp[i+1][(k+2)%3][0] >= 0) dp[i+1][(k+2)%3][0] += dp[i][k][1];

            }
        }
    }
    for(int i = 0;i< 3;++i)
    {
        for(int k = 0;k < 2;++k)
        {
            ans = (ans+che(dp[day-1][i][k]));
        }
    }
    cout << ans%10000 << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int dp[100][4][4];
int p[100], n, k;

int solve(int day, int bday, int bbday){
  int &tmp = dp[day][bday][bbday];
  if(day == n) return 1;
  if(tmp != -1) return tmp;
  if(p[day] != 0){
    return (bday == bbday && bday == p[day] ? 0 : solve(day+1,p[day],bday)%10000);
  }
  int ret = 0;
  for(int i = 1; i <= 3; i++){
    if(bbday == bday && day == i) continue;
      ret += solve(day+1,i,bday) % 10000;
  }
  return tmp = ret % 10000;
}



int main(){

  cin >> n >> k;

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

  memset(dp,-1,sizeof(dp));
  int ans = solve(0,0,0);

  cout << ans << endl;
}

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

using namespace std;

#define MOD 10000
#define MAX 100

int dp[MAX+1][4][4],p[MAX],N;

int solve(int pos,int a,int b){
  if(pos == N) return 1; 
  if(dp[pos][a][b] != -1) return dp[pos][a][b];

  if(p[pos] > 0){
    if(a == b && b == p[pos]){
      return 0;
    }else{
      return solve(pos+1,b,p[pos]) % MOD;
    }
  }else{
    int res = 0;
    for(int i = 0 ; i < 3 ; i++){
      if(a == b && b == i+1) continue;
      res += solve(pos+1,b,i+1) % MOD;
    }
    return dp[pos][a][b] = res % MOD;
  }
}

int main(){
  int K,A,B;

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

  cin >> N >> K;
  for(int i = 0 ; i < K ; i++){
    cin >> A >> B;
    p[A-1] = B;
  }
  cout << solve(0,0,0) << endl;

  return 0;
}

C++: #include <cstdio>

int main() {
  int N, K; scanf("%d%d", &N, &K);
  int plan[100];
  for(int i = 0; i < N; ++i) plan[i] = -1;
  for(int i = 0; i < K; ++i) {
    int A, B; scanf("%d%d", &A, &B); --A; --B;
    plan[A] = B;
  }
  int dp[2][3][3];
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      dp[0][i][j] = (i == 0 && j == 0);
  for(int day = 0; day < N; ++day) {
    for(int i = 0; i < 3; ++i) {
      for(int j = 0; j < 3; ++j) {
        int cnt = 0;
        for(int k = 0; k < 3; ++k) {
          if((plan[day] == j || plan[day] == -1) &&
             (day < 2 || i != k || j != k)) {
            cnt = (cnt + dp[day & 1][k][i]) % 10000;
          }
        }
        dp[(day + 1) & 1][i][j] = cnt;
      }
    }
  }
  int cnt = 0;
  for(int i = 0; i < 3; ++i) {
    for(int j = 0; j < 3; ++j) {
      cnt = (cnt + dp[N & 1][i][j]) % 10000;
    }
  }
  printf("%d\n", cnt);
  return 0;
}