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<cstdio>
#include<cstring>
#define rep(i,a) for(int i=0;i<(a);++i)
#define clr(a,v) memset((a),(v),sizeof(a))

const int mod = 10000;

int N, K, P[100];
int dp[101][3][2];

int main()
{
	clr( P, -1 );

	scanf( "%d%d", &N, &K );
	rep( i, K )
	{
		int A, B;
		scanf( "%d%d", &A, &B );
		P[A-1] = B-1;
	}

	if( ~P[0] )
		dp[0][P[0]][0] = 1;
	else rep( j, 3 )
		dp[0][j][0] = 1;
	
	rep( i, N-1 )
	{
		if( !~P[i+1] ) rep( j, 3 )
		{
			rep( k, 3 ) if( j != k )
				dp[i+1][j][0] = (dp[i+1][j][0]+dp[i][k][0]+dp[i][k][1]) % mod;

			dp[i+1][j][1] = (dp[i+1][j][1]+dp[i][j][0]) % mod;
		}
		else
		{
			rep( j, 3 ) if( j != P[i+1] )
				dp[i+1][P[i+1]][0] = (dp[i+1][P[i+1]][0]+dp[i][j][0]+dp[i][j][1]) % mod;

			dp[i+1][P[i+1]][1] = (dp[i+1][P[i+1]][1]+dp[i][P[i+1]][0]) % mod; 
		}
	}

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

	printf( "%d\n", ans );

	return 0;
}

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

const int mod=10000;
int N,K;
int order[100];

int memo[100][4][4];
int calc(int day=0,int prev=0,int cur=0){
    if(day==N)return 1;
    if(~memo[day][prev][cur])return memo[day][prev][cur];

    int ret=0;
    for(int i=1;i<=3;i++){
        if(order[day]&&order[day]!=i)continue;
        if(prev==cur&&cur==i)continue;
        ret=(ret+calc(day+1,cur,i))%mod;
    }
    return memo[day][prev][cur]=ret;
}

int main(){
    cin>>N>>K;
    for(int i=0;i<K;i++){
        int a,b;
        cin>>a>>b;
        order[--a]=b;
    }

    memset(memo,-1,sizeof(memo));
    cout<<calc()<<endl;
    return 0;
}

C++: 	cin>>n>>k;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		if(b==1)dp[a][2]=INF,dp[a][3]=INF;
		if(b==2)dp[a][1]=INF,dp[a][3]=INF;
		if(b==3)dp[a][1]=INF,dp[a][2]=INF;
	}
	for(int i=1;i<=3;i++)if(dp[1][i]!=INF)dp[1][i]=1;
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=3;j++){
			if(dp[i+1][j]!=INF){
				for(int k=1;k<=3;k++){
					if(dp[i][k]!=INF){
						if(j==k&&i+1>=3&&dp[i-1][k]!=INF){
						dp[i+1][j]=(dp[i+1][k]+dp[i][k]-dp[i-1][k])%10000;
						}
						else dp[i+1][j]+=(dp[i][k])%10000;
					}
				}
			}
		}
	}
	
//	REP(i,n+1){
	//for(int j=1;j<=3;j++)cout<<dp[i][j]<<" ";
//	cout<<endl;
//	}
	int ans=0;
	for(int i=1;i<=3;i++)ans+=dp[n][i];
	cout<<ans%10000<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7
 
__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
 
ll dp[101][4][4];
 
int main() {
  int n, m;
  cin >> n >> m;
  int y[100] = {};
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    y[a - 1] = b;
  }
 
  rep(i, 1, 4) rep(j, 1, 4) {
    int a = y[0] ? y[0] : i, b = y[1] ? y[1] : j;
    dp[1][b][a] = 1;
  }
 
  rep(i, 2, n) rep(j, 1, 4) rep(k, 1, 4){
    if(y[i]) {
      if(!(y[i] == j && j == k)) dp[i][y[i]][j] += dp[i - 1][j][k];
      dp[i][y[i]][j] %= 10000;
      continue;
    }
    rep(l, 1, 4) if(!(j == k && k == l)) dp[i][j][k] += dp[i - 1][k][l];
    dp[i][j][k] %= 10000;
  }
 
  ll ans = 0;
  rep(i, 1, 4) rep(j, 1, 4) ans += dp[n - 1][i][j];
  cout << ans % 10000 << endl;
}