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 <algorithm>
using namespace std;

int memo[101][4][4];
int N, K;
int A, B;
int plan[101];

int rec(int d, int y, int a){
	if(memo[d][y][a] != -1)return memo[d][y][a];
	if(d == N + 1)return 1;
	
	if(plan[d] != 0){
		if(a == y && y == plan[d]){
			return 0;
		}
		else {
			return rec(d + 1, plan[d], y) % 10000;
		}
	}
	
	
	int best = 0;
	for(int next = 1; next <= 3; next++){
		if(a == y && y == next){
			continue;
		}
		else{
			best += rec(d + 1, next, y) % 10000;
		}
	}
	
	return memo[d][y][a] = best % 10000;
}

int main() {
	for(int i = 0; i <= 100; i++)
		for(int j = 0; j < 4; j++)
			for(int k = 0; k < 4; k++)
				memo[i][j][k] = -1;
				
	cin >> N >> K;
	
	for(int i = 0; i < K; i++){
		cin >> A >> B;
		plan[A] = B;
	}
		
	
	cout << rec(1, 0, 0) << endl;
	
	return 0;
}

C++: #include<stdio.h>
int dp[101][4][4];
int main(void)
{
	int n,d;
	int a,b;
	int pa[101];
	int s=0;
	int i,j,k,l;
	
	scanf("%d %d",&n,&d);
	for(i=1;i<=n;i++){
		pa[i]=0;
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				dp[i][j][k]=0;
			}
		}
	}
	for(i=1;i<=d;i++){
		scanf("%d %d",&a,&b);
		pa[a]=b;
	}
	if(pa[1]==0){
		for(i=1;i<=3;i++){
			dp[1][i][1]=1;
		}
	}
	else {
		dp[1][pa[1]][1]=1;
	}
	for(i=1;i<=3;i++){
		if(pa[1]==i || pa[1]==0){
			for(j=1;j<=3;j++){
				if(pa[2]==j || pa[2]==0){
					dp[2][j][i]+=1;
				}
			}
		}
	}
	for(i=2;i<n;i++){
		for(j=1;j<=3;j++){
			if(pa[i]==j || pa[i]==0){
				for(k=1;k<=3;k++){
					for(l=1;l<=3;l++){
						if(pa[i+1]==l || pa[i+1]==0){
							if(!(j==k && l==j)){
								dp[i+1][l][j]+=dp[i][j][k];
								dp[i+1][l][j]=dp[i+1][l][j]%10000;
							}
						}
					}
				}
			}
		}
	}
	
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				printf(" %d",dp[i][j][k]);
			}
			printf(" |");
		}
		printf("\n");
	}
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			s+=dp[n][i][j];
			s=s%10000;
		}
	}
	printf("%d\n",s);
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
const ll mod=10000;
ll n,k;
ll p[100];
bool rsv[100];
ll dp[100][6];//day:i  pasta:j 0 1 2 00 11 22
int main()
{
	scanf("%lld%lld",&n,&k);
	for(ll i=0;i<k;i++){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		a--;
		b--;
		rsv[a]=1;
		p[a]=b;
	}
	if(rsv[0]) dp[0][p[0]]=1;
	else{
		dp[0][0]=dp[0][1]=dp[0][2]=1;
	}
	for(ll i=1;i<n;i++){
		if(rsv[i]){
			for(ll j=0;j<6;j++){
				if(j!=p[i]&&j!=p[i]+3) dp[i][p[i]]=(dp[i][p[i]]+dp[i-1][j])%mod;
			}
			dp[i][p[i]+3]=dp[i-1][p[i]];
		}
		else{
			for(ll s=0;s<3;s++){
				for(ll j=0;j<6;j++){
					if(j!=s&&j!=s+3) dp[i][s]=(dp[i][s]+dp[i-1][j])%mod;
				}
				dp[i][s+3]=dp[i-1][s];
			}
		}
	}
	
	printf("%lld\n",(dp[n-1][0]+dp[n-1][1]+dp[n-1][2]+dp[n-1][3]+dp[n-1][4]+dp[n-1][5])%mod);
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int dp[111][4][4];
int C[111];
int N, K;

int const MOD = 10000;

int solve(int idx = 0, int p = 0, int pp = 0) {
  int& ret = dp[idx][p][pp];
  if(ret + 1) return ret;
  if(C[idx] && (C[idx] != p || C[idx] != pp)) return ret = solve(idx + 1, C[idx], p);
  if(C[idx]) return ret = 0;
  if(idx == N) return ret = 1;
  ret = 0;
  REP(i, 1, 4) {
    if(i == p && i == pp) continue;
    ret += solve(idx + 1, i, p);
    ret %= MOD;
  }
  return ret % MOD;
}

int main() {

  cin >> N >> K;
  rep(i, K) {
    int A, B; cin >> A >> B;
    C[A-1] = B;
  }

  minus(dp);
  cout << solve() << endl;
  
  return 0;
}