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

using namespace std;

int n,k;
int dp[102][4][2];
int yt[102];

void debug(){
    for(int d=0;d<=n;d++){
        printf("%2d ",d);
        for(int i=1;i<=3;i++){
            printf("(%5d,%5d) ",d,dp[d][i][0],dp[d][i][1]);
        }
        cout << endl;
    }
}

int solve(){
    if(yt[1] == 0){
        dp[1][1][0] = dp[1][2][0] = dp[1][3][0] = 1;
    }else{
        dp[1][yt[1]][0] = 1;
    }
    for(int d=2;d<=n;d++){
        for(int i=1;i<=3;i++){
            if(yt[d] != 0 && yt[d] != i){ dp[d][i][0] = dp[d][i][1] = 0; continue; }
            dp[d][i][1] = dp[d-1][i][0] % 10000;
            dp[d][i][0] = 0;
            for(int j=1;j<=3;j++){
                if(i==j)continue;
                dp[d][i][0] += (dp[d-1][j][0] + dp[d-1][j][1]) % 10000;
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=3;i++){
        ans += (dp[n][i][0] + dp[n][i][1]) % 10000;
    }
    return ans % 10000;
}

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

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

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

int dp[101][3][2];
int sche[101];
const int MOD = 10000;

int main()
{
	int n, k; cin >> n >> k;
	n--;
	memset(sche, -1, sizeof(sche));
	rep(i, k)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		sche[a] = b;
	}

	if (~sche[0]) dp[0][sche[0]][0] = 1;
	else rep(i, 3) dp[0][i][0] = 1;

	rep(i, n)
	{
		if (~sche[i + 1]) rep(j, 3)
		{
			if (j == sche[i + 1]) dp[i + 1][sche[i + 1]][1] += dp[i][sche[i + 1]][0] % MOD;
			else dp[i + 1][sche[i + 1]][0] += (dp[i][j][0] + dp[i][j][1]) % MOD;
		}
		else rep(j, 3) rep(k, 3)
		{
			if (j == k) dp[i + 1][j][1] += dp[i][k][0] % MOD;
			else dp[i + 1][j][0] += (dp[i][k][0] + dp[i][k][1]) % MOD;
		}
	}

	int ans = 0;
	rep(i, 3) (ans += (dp[n][i][0] + dp[n][i][1])) %= MOD;
	cout << ans << endl;

	return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
int k;
int p[100];
long long memo[101][4][4];
int solve(int idx,int t1,int t2){
  if(idx==n) return 1;
  if(memo[idx][t1][t2]!=-1) return memo[idx][t1][t2];
  if(p[idx]>0){
    if(t1==t2 && t2==p[idx]){
      return 0;
    }else{
      return solve(idx+1,t2,p[idx])%10000;
    }
  }else{
    long long res=0;
    for(int i=1;i<=3;i++){
      if(t1==t2 && t2==i) continue;
      res+=solve(idx+1,t2,i)%10000;
    }
    return memo[idx][t1][t2]=res%10000;
  }
}
int main(){
  cin>>n>>k;
  memset(p,-1,sizeof(p));
  memset(memo,-1,sizeof(memo));
  for(int i=0;i<k;i++){
    int a,b;
    cin>>a>>b;
    p[a-1]=b;
  }
  cout<<solve(0,0,0)<<endl;
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int dp[5][5][110],p[110],N,K;

int main(void){
	int i,j,k;

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

	for(i=2;i<=N;i++){
		if(i==2){
			if(p[1]==0 && p[2]==0){
				for(j=1;j<=3;j++) for(k=1;k<=3;k++) dp[j][k][i]=1;
			}
			if(p[1]==0 && p[2]!=0){
				dp[1][p[2]][i]=dp[2][p[2]][i]=dp[3][p[2]][i]=1;
			}
			if(p[1]!=0 && p[2]==0){
				dp[p[1]][1][i]=dp[p[1]][2][i]=dp[p[1]][3][i]=1;
			}
			if(p[1]!=0 && p[2]!=0){
				dp[p[1]][p[2]][i]=1;
			}
		}

		if(i>=3){
			if(p[i]==1){
				dp[1][1][i]=(dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][1][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
				dp[3][1][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
			}
			if(p[i]==2){
				dp[2][2][i]=(dp[1][2][i-1]+dp[3][2][i-1])%10000;
				dp[1][2][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[3][2][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
			}
			if(p[i]==3){
				dp[3][3][i]=(dp[1][3][i-1]+dp[2][3][i-1])%10000;
				dp[1][3][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][3][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
			}
			if(p[i]==0){
				dp[1][1][i]=(dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][1][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
				dp[3][1][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
				dp[2][2][i]=(dp[1][2][i-1]+dp[3][2][i-1])%10000;
				dp[1][2][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[3][2][i]=(dp[1][3][i-1]+dp[2][3][i-1]+dp[3][3][i-1])%10000;
				dp[3][3][i]=(dp[1][3][i-1]+dp[2][3][i-1])%10000;
				dp[1][3][i]=(dp[1][1][i-1]+dp[2][1][i-1]+dp[3][1][i-1])%10000;
				dp[2][3][i]=(dp[1][2][i-1]+dp[2][2][i-1]+dp[3][2][i-1])%10000;
			}
		}
	}

	      int ans=0;
	      for(i=1;i<=3;i++) for(j=1;j<=3;j++){
		     ans+=dp[i][j][N];
		     ans%=10000;
	      }

		cout << ans << endl;

	return 0;
}