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>

int n;
int dec[105]={};
int dp[105][4][4]={};

void modadd(int &p,int q){
	p=(p+q)%10000;
}

int rec(int d,int p1,int p2){
	if(dp[d][p1][p2]!=-1)return dp[d][p1][p2];
	int r=0;
	if(d==2){
		if((dec[d]!=0 && dec[d]!=p2) || (dec[d-1]!=0 && dec[d-1]!=p1))goto re;
		r=1;
		goto re;
	}
	else{
		if((dec[d]!=0 && dec[d]!=p2) || (dec[d-1]!=0 && dec[d-1]!=p1))goto re;
		for(int i=1;i<=3;i++){
			if( !(i==p1 && p1==p2) ) modadd(r,rec(d-1,i,p1));
		}
	}
re:;
	dp[d][p1][p2]=r;
	return r;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	int k,a,b;
	scanf("%d%d", &n, &k);
	for(int i=0;i<k;i++){
		scanf("%d%d", &a, &b);
		dec[a]=b;
	}
	int r=0;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			modadd(r,rec(n,i,j));
		}
	}
	printf("%d\n",r);
	return 0;
}

C++: #include<iostream>
using namespace std;

int N, K, mem[100][4][4], decided[100];

int dp(int n, int b1, int b2)
{
  if(n == N)
    return 1;
  if(mem[n][b1][b2] != -1)
    return mem[n][b1][b2];
  int ans = 0;
  if(decided[n] != 0)
  {
    if(b1 == b2 && decided[n] == b1)
      return 0;
    mem[n][b1][b2] = dp(n + 1, decided[n], b1);
    return mem[n][b1][b2];
  }
  for(int i = 1; i <= 3; i++)
  {
    if(b1 == b2 && b1 == i)
      continue;
    ans += dp(n + 1, i, b1);
  }
  mem[n][b1][b2] = ans % 10000;
  return ans % 10000;
}

int main()
{
  cin >> N >> K;
  for(int i = 0; i < 100; i++)
    for(int j = 0; j < 4; j++)
      for(int k = 0; k < 4; k++)
        mem[i][j][k] = -1;
  for(int i = 0; i < K; i++)
  {
    int a, b;
    cin >> a >> b;
    decided[a - 1] = b;
  }
  cout << dp(0, 0, 0) << endl;
}

C++: #include<cstdio>
int n, p[128];
int memo[128][8][8];
int solve(int d, int p1, int p2){
  if(memo[d][p1][p2]) return memo[d][p1][p2];
  if(p[d] == p1 && p1 == p2) return memo[d][p1][p2] = 0;
  if(d == n + 1) return memo[d][p1][p2] = 1;
  if(p[d]) return memo[d][p1][p2] = solve(d + 1, p[d], p1);
  int ret = 0;
  if(!(p1 == p2 && p1 == 1))
    ret += solve(d + 1, 1, p1);
  if(!(p1 == p2 && p1 == 2))
    ret += solve(d + 1, 2, p1);
  if(!(p1 == p2 && p1 == 3))
    ret += solve(d + 1, 3, p1);
  return memo[d][p1][p2] = ret % 10000;
}
int main(void){
  int k, a, b;
  scanf("%d %d", &n, &k);
  for(int i = 0;i < k; i++){
    scanf("%d %d", &a, &b);
    p[a] = b;
  }
  printf("%d\n", solve(1, 5, 5));
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,K,a[200],b[200],dc[200];
int dp[200][3][2];
int main(){
    scanf("%d%d",&n,&K);
    REP(i,n + 1)
        dc[i] = -1;
    REP(i,K){
        scanf("%d%d",a + i,b + i);
        b[i]--;
        dc[a[i]] = b[i];
    }

    REP(j,3){
        REP(k,2){
            dp[1][j][k] = (k == 0 && (dc[1] == -1 || dc[1] == j));
        }
    }

    FOR(i,2,n + 1){
        REP(j,3){
            REP(k,2){
                if(dc[i] != j && dc[i] >= 0)
                    dp[i][j][k] = 0;
                else{
                    if(k == 0){
                        int s = 0;
                        REP(jj,3){
                            REP(kk,2){
                                s += dp[i - 1][jj][kk] * (j != jj);
                            }
                        }
                        dp[i][j][k] = s;
                    }else{
                        dp[i][j][k] = dp[i - 1][j][k - 1];
                    }
                }
                dp[i][j][k] %= 10000;
            }
        }
    }

    int ans = 0;
    REP(j,3)
        REP(k,2){
            ans += dp[n][j][k];
            ans %= 10000;
        }
    printf("%d\n", ans);
    return 0;
}

C++: #include <cstdio>
#include <cstring>

#define MOD (10000)

using namespace std;

int check[101];
int memo[101][4][3];
int n, k;

int getWay(int day, int menu, int cont)
{
	if (cont > 2){
		return (0);
	}
	
	if (memo[day][menu][cont] >= 0){
		return (memo[day][menu][cont]);
	}
	
	if (day == n){
		return (1);
	}
	
	int ans = 0;
	if (check[day + 1]){
		ans = getWay(day + 1, check[day + 1], (menu == check[day + 1] ? cont + 1 : 1));
		ans %= MOD;
	}
	else {
		for (int i = 1; i <= 3; i++){
			ans += getWay(day + 1, i, (menu == i ? cont + 1 : 1));
			ans %= MOD;
		}
	}
	
	return (memo[day][menu][cont] = ans);
}

int main()
{
	
	scanf("%d %d", &n, &k);
	
	for (int i = 0; i < k; i++){
		int day, menu;
		scanf("%d %d", &day, &menu);
		check[day] = menu;
	}
	
	memset(memo, -1, sizeof(memo));
	
	printf("%d\n", getWay(0, 0, 0));
}