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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define M 10000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, K, p[100];
int dp[128][4][4];

int check(){
  int c = 0;
  int n = p[0];
  rep(i, N){
    if(n == p[i]) c++;
    else{ c = 1; n = p[i]; }
    if(c >= 3) return 0;
  }
  if(c >= 3) return 0;
  rep(i, N) printf("%d ", p[i]); puts("");
  return 1;
}

int dfs(int n, int p2, int p1){
  if(N == n) return 1;
  if(dp[n][p2][p1]) return dp[n][p2][p1];

  if(p[n]){
    if(p2 == p1 && p1 == p[n]) return 0;
    return dfs(n+1, p1, p[n]);
  } else {
    int res = 0;
    REP(i, 1, 4){
      if(p2 == p1 && p1 == i) continue;
      p[n] = i;
      res += dfs(n+1, p1, i);
      res = res % M;
      p[n] = 0;
    }
    return dp[n][p2][p1] = res;
  }
  return 1;
}
int main(){
  scanf("%d%d", &N, &K);
  int A, B;
  rep(i, K){
    scanf("%d%d", &A, &B); A--;
    p[A] = B;
  }
  printf("%d\n", dfs(0, 0, 0));
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	const int mod = 10000;
	int n, k, pasta[128];
	cin >> n >> k;
	CLEAR(pasta, -1);
	while (k--)
	{
		int a, b;
		cin >> a >> b;
		--a, --b;
		pasta[a] = b;
	}

	int dp[128][3][3];
	CLEAR(dp, 0);
	for (int i = 0; i < 3; ++i)
		dp[0][i][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		if (pasta[i] != -1)
			for (int j = 0; j < 3; ++j)
				if (pasta[i] != j)
					dp[i][j][0] = dp[i][j][1] = 0;

		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 2; ++k)
				for (int l = 0; l < 3; ++l)
					(dp[i + 1][l][j == l ? k + 1 : 0] += dp[i][j][k]) %= mod;
	}

	int res = 0;
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 2; ++j)
			(res += dp[n - 1][i][j]) %= mod;
	cout << res << endl;
}

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

int dp[105][5][5];
int mod = 10000;

int N,K;
int day[105];

signed main(){
    cin>>N>>K;
    for(int i=0;i<K;++i){
        int d,p;
        cin>>d>>p;
        day[d]=p;
    }
    dp[0][0][0]=1;
    for(int i=1;i<=N;++i){
        for(int j=0;j<=3;++j){
            for(int k=0;k<=3;++k){
                if(day[i]==0){
                    for(int p=1;p<=3;++p){
                        if(j==p&&k==p)continue;
                        dp[i][p][j]+=dp[i-1][j][k]%mod;
                    }
                }
                else{
                    if(j==day[i]&&k==day[i])continue;
                    dp[i][day[i]][j]+=dp[i-1][j][k]%mod;
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=3;++i)for(int j=1;j<=3;++j)ans+=dp[N][i][j]%mod;
    cout<<ans%mod<<endl;
}