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;

int N, K;
int C[101];
int dp[101][3][3];

int solve(int n, int b1, int b2)
{
  if(n == N) return 1;
  int &ret = dp[n][b1][b2];
  if(~ret) return ret;
  if(~C[n] && (b1 != C[n] || b2 != C[n])) return ret = solve(n + 1, C[n], b1) % 10000;
  else if(~C[n]) return ret = 0;
  ret = 0;
  for(int i = 0; i < 3; i++){
    if(b1 == i && b2 == i) continue;
    ret = (ret + solve(n + 1, i, b1)) % 10000;
  }
  return ret;
}

int main()
{
  cin >> N >> K;
  memset(C, -1, sizeof(C));
  for(int i = 0; i < K; i++){
    int A, B;
    cin >> A >> B;
    A--, B--;
    C[A] = B;
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(0, -1, -1) % 10000 << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100000001
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[101], dp[101][3][3];
int main(){
	int n, k,t1,t2;
	scanf("%d%d", &n, &k);
	rep(i,k){
		scanf("%d%d", &t1, &t2);
		a[t1] = t2;
	}
	rep(i,3)if(!a[1] || a[1] == i+1)dp[1][i][(i+1)%3] = 1;
	for(int i = 1;i <= n;i++){
		if(a[i] == 0 || a[i] == 1){
			dp[i][0][0] = dp[i-1][0][1]+dp[i-1][0][2];
			rep(j,3)rep(k,2)dp[i][0][k+1] += dp[i-1][k+1][j];
		}
		if(a[i] == 0 || a[i] == 2){
			dp[i][1][1] = dp[i-1][1][0]+dp[i-1][1][2];
			rep(j,3)rep(k,2)dp[i][1][(k+2)%3] += dp[i-1][(k+2)%3][j];
		}
		if(a[i] == 0 || a[i] == 3){
			dp[i][2][2] = dp[i-1][2][0]+dp[i-1][2][1];
			rep(j,3)rep(k,2)dp[i][2][k] += dp[i-1][k][j];
		}
		rep(j,3)rep(k,3)dp[i][j][k] = dp[i][j][k]%10000;
	}
	int ans = 0;
	rep(i,3)rep(j,3)ans += dp[n][i][j];
	printf("%d\n", ans%10000);
	return 0;
}

C++: #include<iostream>
using namespace std;
int N,K,day,sosu;
int plan[101];
int memo[101][4][4];

int solve(int n,int b1,int b2){
  if(n==N+1) return 1;
  if(memo[n][b1][b2]!=-1) return memo[n][b1][b2];

  if(plan[n]!=0){
    if(b1==b2&&b1==plan[n])
      return 0;
      else
       return solve(n+1,plan[n],b1)%10000;
    }
    int t=0;
    for(int i=1;i<=3;++i){
      if(b1==b2&&b1==i)continue;
      t+=solve(n+1,i,b1)%10000;
    }
    return memo[n][b1][b2]=t%10000;
}

int main(){
  cin>>N>>K;

  for(int i=0;i<K;i++){
    cin>>day>>sosu;
    plan[day]=sosu;
  }
  for(int i=0;i<=N;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
	memo[i][j][k]=-1;
      }
    }
  }
  cout<<solve(1,0,0)<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
int k;
int p[102];
int memo[102][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]);
    }
  }else{
    int res=0;
    for(int i=1;i<=3;i++){
      if(t1==t2 && t2==i) continue;
      res+=solve(idx+1,t2,i);
    }
    return memo[idx][t1][t2]=res;
  }
}
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)%10000<<endl;
}

C++: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define INF (1<<29)
#define EPS (1e-10)
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
int const MOD = 10000;

int main(){
	int N, K;
	cin >> N >> K;
	vii dp(N+1, vi(3, 1));
	for (int k=0; k<K; k++) {
		int A, B;
		cin >> A >> B;
		for (int b=0; b<3; b++) {
			if (b == B-1) continue;
			dp[A][b] = 0;
		}
	}

	for (int d=2; d<=N; d++) {
		for (int i=0; i<3; i++) {
			if (dp[d][i] == 0) continue;
			int sum = 0;
			for (int j=0; j<3; j++) {
				if (dp[d-1][j] == 0) continue;
				if (j == i && d != 2) {
					for (int k=0; k<3; k++) {
						if (k == j) continue;
						sum += dp[d-2][k];
					}
				} else {
					sum += dp[d-1][j];
				}
			}
			dp[d][i] = sum;
		}
	}
	int ans = dp[N][0]+dp[N][1]+dp[N][2];
	cout << ans%MOD << endl;
}