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;
typedef long long ll;

ll dp[101][3][3]{};
ll mod = 10000;

void init(int a, int b) {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (a == -1 && b == -1) {
                dp[1][i][j] = 1;
            } else if (a != -1 && b != -1) {
                dp[1][a][b] = 1;
                return;
            } else if (a == -1 && b != -1) {
                dp[1][i][b] = 1;
            } else if (a != -1 && b == -1) {
                dp[1][a][j] = 1;
            }
        }
    }
}

// d日目にa, d+1日目にb
void solve(int d, int a, int b) {
    if (a == -1 && b == -1) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (i == j && i == k) continue;
                    dp[d][i][j] += dp[d - 1][k][i];
                    dp[d][i][j] %= mod;
                }
            }
        }
    } else if (a != -1 && b != -1) {
        for (int i = 0; i < 3; i++) {
            if (i == a && a == b) continue;
            dp[d][a][b] += dp[d - 1][i][a];
            dp[d][a][b] %= mod;
        }
    } else if (a == -1 && b != -1) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (b == i && i == j) continue;
                dp[d][i][b] += dp[d - 1][j][i];
                dp[d][i][b] %= mod;
            }
        }
    } else if (a != -1 && b == -1) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a == i && i == j) continue;
                dp[d][a][i] += dp[d - 1][j][a];
                dp[d][a][i] %= mod;
            }
        }
    }
}

int main() {
    int N, K;
    cin >> N >> K;
    int A[N], B[N];
    int C[N + 1];
    fill(C, C + N + 1, -1);
    for (int i = 0; i < K; i++) {
        cin >> A[i] >> B[i];
        B[i]--;
        C[A[i]] = B[i];
    }
    
    // dp[i][j][k] i日目にj、i+1日目にkの個数
    init(C[1], C[2]);
    for (int i = 2; i < N; i++) {
        solve(i, C[i], C[i + 1]);
    }
    ll ans = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            ans += dp[N - 1][i][j];
        }
    }
    cout << ans % mod << "\n";
    return 0;
}

C++: #include <cstdio>
#include <cstring>
using namespace std;

bool comp(int a, int b, int c){
	if(a == b && b == c) return false;
	else return true;
}

int main(){
	const int MAX_K = 100;
	const int MAX_N = 100;
	int N, K;
	int A[MAX_K], B[MAX_K];
	int C[MAX_N + 1];
	int dp[MAX_N + 1][4][4][4];
	int ans;
	
	scanf("%d%d", &N, &K);
	for(int i = 0; i < K; i++){
		scanf("%d%d", &A[i], &B[i]);
	}
	
	memset(C, 0, sizeof(C));
	for(int i = 0; i < K; i++){
		C[A[i]] = B[i];
	}
	
	memset(dp, 0, sizeof(dp));
	for(int a = 1; a <= 3; a++){
		for(int b = 1; b <= 3; b++){
			for(int c = 1; c <= 3; c++){
				if((C[1] == 0 || C[1] == a) && (C[2] == 0 || C[2] == b) && (C[3] == 0 || C[3] == c)){
					if(comp(a, b, c)) dp[1][a][b][c] = 1;
				}
			}
		}
	}
	for(int a = 2; a <= N - 2; a++){
		for(int b = 1; b <= 3; b++){
			for(int c = 1; c <= 3; c++){
				for(int d = 1; d <= 3; d++){
					if(b == c && c == d) continue;
					
					if((C[a] == 0 || C[a] == b) && (C[a + 1] == 0 || C[a + 1] == c) && (C[a + 2] == 0 || C[a + 2] == d)){
						for(int x = 1; x <= 3; x++){
							if(C[a - 1] == 0 || C[a - 1] == x){
								if(comp(x, b, c)){
									dp[a][b][c][d] += dp[a - 1][x][b][c];
								}
							}
						}
					}
					
					dp[a][b][c][d] %= 10000;
				}
			}
		}
	}
	
	ans = 0;
	for(int a = 1; a <= 3; a++){
		for(int b = 1; b <= 3; b++){
			for(int c = 1; c <= 3; c++){
				ans = (ans + dp[N - 2][a][b][c]) % 10000;
			}
		}
	}
	
	printf("%d\n", ans);
	
	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]

const int MOD = 10000;

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];
      dp[i][1][tc] %= MOD;
      rep(k, 3) {
        if (k != tc) {
          dp[i][0][tc] += dp[i-1][0][k] + dp[i-1][1][k];
          dp[i][0][tc] %= MOD;
        }
      }
    }
    else {
      rep(x, 3) {
        dp[i][1][x] += dp[i-1][0][x];
        dp[i][1][x] %= MOD;
        rep(k, 3) {
          if (k != x) {
            dp[i][0][x] += dp[i-1][0][k] + dp[i-1][1][k];
            dp[i][0][x] %= MOD;
          }
        }
      }
    }
  }

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

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