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>

using namespace std;

int main() {
	const int mod = 10000;
	int n,k;
	cin >> n >> k;
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> a;
	int in1, in2;
	for (int i = 1; i <= k; i++) {
		cin >> in1 >> in2;
		a.push(make_pair( in1,in2 ));
	}

	vector<vector<long long>> dp(n + 1,vector<long long>(4));

	if (a.top().first != 1) {
		dp[1][1] = 1;
		dp[1][2] = 1;
		dp[1][3] = 1;
	}
	else{
		dp[1][a.top().second] = 1;
		a.pop();
	}

	if (a.top().first != 2) {
		dp[2][1] = dp[1][1]+dp[1][2]+dp[1][3];
		dp[2][2] = dp[1][1] + dp[1][2] + dp[1][3];
		dp[2][3] = dp[1][1] + dp[1][2] + dp[1][3];
	}
	else {
		for (int j = 1; j <= 3; j++) {
			if (a.top().second == j) {
				dp[2][j] = dp[1][1]	+ dp[ 1][2] + dp[1][3] ;
			}
			else {
				dp[2][j] = 0;
			}
		}
		a.pop();
	}

	for (int i = 3; i <= n; i++) {		

		if (a.empty()==true || i != a.top().first) {
			dp[i][1] = (dp[i-1][1]!=0)*(dp[i - 2][2] + dp[i - 2][3])
				+ dp[i - 1][2] + dp[i - 1][3];
			dp[i][2] = (dp[i - 1][2] != 0)*(dp[i - 2][1] + dp[i - 2][3])
				+ dp[i - 1][1] + dp[i - 1][3];
			dp[i][3] = (dp[i - 1][3] != 0)*(dp[i - 2][1] + dp[i - 2][2])
				+ dp[i - 1][1] + dp[i - 1][2];
		}
		else {
			for (int j = 1; j <= 3; j++) {
				if (a.top().second == j) {
					if (dp[i - 1][j] != 0) {
						dp[i][j] = dp[i - 1][1]//+dp[i-2][1]
							+ dp[i - 1][2]//+dp[i-2][2]
							+ dp[i - 1][3]//+dp[i-2][3]
							-dp[i - 1][j]
							+dp[i-2][1]
							+dp[i-2][2]
							+dp[i-2][3]
							- dp[i - 2][j];
					}
					else {
						dp[i][j] = dp[i - 1][1]//+dp[i-2][1]
							+ dp[i - 1][2]//+dp[i-2][2]
							+ dp[i - 1][3];//+dp[i-2][3]
					}
				}
				else {
					dp[i][j] = 0;
				}
			}
			a.pop();
		}
		for (int j = 1; j <= 3; j++) {
			dp[i][j] = dp[i][j] % mod;
		}
	}

	cout << (dp[n][1]+dp[n][2]+dp[n][3])%10000 << endl;
	return 0;

}

C++: #include<iostream>
using namespace std;
int dp[105][3][2],a[105],n,m,p,q;
int main(){
	cin>>n>>m;for(int i=0;i<m;i++){cin>>p>>q;a[p]=q;}
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++){
		if(a[i]==0 || a[i]==1){
			dp[i][0][0]+=(dp[i-1][1][0]+dp[i-1][1][1]+dp[i-1][2][0]+dp[i-1][2][1]);dp[i][0][0]%=10000;
			dp[i][0][1]+=dp[i-1][0][0];dp[i][0][1]%=10000;
		}
		if(a[i]==0 || a[i]==2){
			dp[i][1][0]+=(dp[i-1][0][0]+dp[i-1][0][1]+dp[i-1][2][0]+dp[i-1][2][1]);dp[i][1][0]%=10000;
			dp[i][1][1]+=dp[i-1][1][0];dp[i][1][1]%=10000;
		}
		if(a[i]==0 || a[i]==3){
			dp[i][2][0]+=(dp[i-1][0][0]+dp[i-1][0][1]+dp[i-1][1][0]+dp[i-1][1][1]);dp[i][2][0]%=10000;
			dp[i][2][1]+=dp[i-1][2][0];dp[i][2][1]%=10000;
		}
	}
	cout<<(dp[n][0][0]+dp[n][0][1]+dp[n][1][0]+dp[n][1][1]+dp[n][2][0]+dp[n][2][1])%10000<<endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 110
int N, K;
//int A[MAX_N];
//int B[3];
int timeline[MAX_N];
int dp[MAX_N][3][3]; // dp[day][cons][last_choice]

int main() {
  cin >> N >> K;
  rep(i, N) timeline[i] = -1;
  rep(i, K) {
    int a, b;
    cin >> a >> b;
    timeline[a-1] = b-1;
  }

  if (timeline[0] != -1) {
    dp[0][0][timeline[0]] = 1;
  }
  else {
    dp[0][0][0] = 1;
    dp[0][0][1] = 1;
    dp[0][0][2] = 1;
  }
  for (int i=1; i<N; i++) {
    int tc = timeline[i];
    if (tc != -1) {
      dp[i][1][tc] += dp[i-1][0][tc];
      rep(k, 3) {
        if (k != tc) {
          dp[i][0][tc] += dp[i-1][0][k] + dp[i-1][1][k];
        }
      }
    }
    else {
      rep(x, 3) {
        dp[i][1][x] += dp[i-1][0][x];
        rep(k, 3) {
          if (k != x) {
            dp[i][0][x] += dp[i-1][0][k] + dp[i-1][1][k];
          }
        }
      }
    }
  }

  int ans = 0;
  rep(i, 2) rep(j, 3) ans = (ans + dp[N-1][i][j]) % 10000;

  cout << ans << '\n';
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  memset(a, -1, sizeof(a));
  REP(i, k) {
    int b, c;
    cin >> b >> c;
    b--;c--;
    a[b] = c;
  }
  const int MOD = 10000;
  int dp[101][3][3];
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  REP(i, n) {
    REP(j, 3) {
      REP(k, 3) {
        REP(l, 3) {
          if (i>=2 && j==k&&k==l) continue;
          if (a[i] != -1 && a[i] != l) continue;
          dp[i+1][k][l] = (dp[i+1][k][l] + dp[i][j][k]) % MOD;
        }
      }
    }
    // REP(j,3) {
    //   REP(k,3) cout << dp[i+1][j][k] << " ";
    //   cout << endl;
    // }cout << endl;
  }
  int ans = 0;
  REP(i,3)REP(j,3)
    ans = (ans + dp[n][i][j]) % MOD;
  cout << ans << endl;
}