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>

using namespace std;

const int type[3][2]={{1,2},{0,2},{0,1}};

void reset(int[][3][2],int,int);

int main(void){
	int N,K,B[100]={0},pst[100][3][2],sum=0;

	cin >> N >> K;

	for(int i=0;i<K;i++){
		int day;
		cin >> day;
		cin >> B[day-1];
	}

	for(int i=0;i<3;i++){
		pst[0][i][0]=1;
		pst[0][i][1]=0;
	}
	if(B[0])
		reset(pst,B[0],0);

	for(int i=1;i<N;i++){
		for(int j=0;j<3;j++){
			pst[i][j][0]=0;
			for(int k=0;k<2;k++)
				(pst[i][j][0]+=(pst[i-1][type[j][k]][0]+pst[i-1][type[j][k]][1]))%=10000;
			pst[i][j][1]=pst[i-1][j][0];
		}
		if(B[i])
			reset(pst,B[i],i);
	}

	for(int i=0;i<3;i++)
		sum+=(pst[N-1][i][0]+pst[N-1][i][1]);
	cout << sum%10000 << endl;

	return 0;
}

void reset(int pst[][3][2],int num,int i){
	for(int j=0;j<2;j++)
		for(int k=0;k<2;k++)
			pst[i][type[num-1][j]][k]=0;
}

C++: #include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int dp[101][3][3];
int can[100][3];

int main() {
  int n, k;
  cin >> n >> k;
  rep (i, k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    can[a][(b + 1) % 3] = -1;
    can[a][(b + 2) % 3] = -1;
  }
  rep (i, 3) if (can[0][i] != -1) dp[0][i][i] = 1;
  rep (i, 3) if (can[1][i] != -1) rep (j, 3) dp[1][i][j] = dp[0][j][j];
  rep (i, n - 2) {
    rep (j, 3) rep (k, 3) {
      if (can[i + 2][j] != -1) {
	rep (l, 3) {
	  if (j == k && j == l) continue;
	  dp[i + 2][j][k] += dp[i + 1][k][l];
	  dp[i + 2][j][k] %= 10000;
	}
      }
    }
  }
  int res = 0;
  rep (i, 3) rep (j, 3) res += dp[n - 1][i][j];
  cout << res % 10000 << endl;
  return 0;
}

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

#define int long long

int mod = 10000;
int n, k;
int p[111] = {0};

int dp[111][2][4];

int dfs(int i = 1, bool ff = false, int f = 0)
{
  int &ans = dp[i][ff][f];

  if (ans != -1) return ans;
  if (i == n + 1) {
    return 1;
  }
  
  if (p[i] != 0){
    if (ff && f == p[i]) return 0;
    ans = dfs(i + 1, f == p[i], p[i]);
    return ans %= mod;
  }

  ans = 0;
  for (int j = 1; j < 4; j++){
    if (ff && f == j) continue;
    ans += dfs(i + 1, f == j, j);
  }

  return ans %= mod;
}

main()
{
  memset(dp, -1, sizeof(dp));

  cin >> n >> k;
  for (int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    p[a] = b;
  }

  cout << dfs() << endl;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >>n;
int k;
cin >>k;
int a[n][3][3];//n+1個の最後から2番目-1,1番目-1
int b[n];
int c;
c=0;
while(c<n){
b[c]=-1;
c=c+1;}
int d;
int e;
c=0;
while(c<k){
cin >>d;
cin >>e;
b[d-1]=e-1;
c=c+1;}
int f;
int h;
c=0;
while(c<3){
f=0;
while(f<3){
h=0;
if(b[0]!=c){if(b[0]!=-1){h=1;}}
if(b[1]!=f){if(b[1]!=-1){h=1;}}
if(h==1){a[1][c][f]=0;}
if(h==0){a[1][c][f]=1;}
f=f+1;}
c=c+1;}
int g;
c=2;
while(c<n){
f=0;
while(f<3){
g=0;
while(g<3){
a[c][f][g]=a[c-1][0][f]+a[c-1][1][f]+a[c-1][2][f];
if(f==g){a[c][f][g]=a[c][f][g]-a[c-1][f][f];}
if(b[c]!=f){if(b[c]!=-1){a[c][f][g]=0;}
a[c][f][g]=a[c][f][g]%10000
g=g+1;}
f=f+1;}
c=c+1;}
cout << a[n-1][0][0]+a[n-1][0][1]+a[n-1][0][2]+a[n-1][1][0]+a[n-1][1][1]+a[n-1][1][2]+a[n-1][2][0]+a[n-1][2][1]+a[n-1][2][2]<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;


int main(){
    ll n, k;
    cin >> n >> k;
    vll a(k), b(k);
    REP(i, k){
        cin >> a[i] >> b[i];
        b[i]--;
    }

    ll p1 = 0, p2 = 0, q1 = -1, q2 = -1;
    REP(i, k){
        if(a[i] == 1){
            p1 = 1, q1 = b[i];
        }
        if(a[i] == 2){
            p2 = 1, q2 = b[i];
        }
    }
    
    vector<vector<vector<ll>>> dp(110, vvll(3, vll(3, 0)));
    //i = 2に対して初期化
    REP(s2, 3){
        REP(s1, 3){
            if((p1 && q1 != s2) || (p2 && q2 != s1)) dp[2][s2][s1] = 0;
            else dp[2][s2][s1] = 1;
        }
    }
    //i+1文字目の更新を考えるとき, [p2(i-1文字目)][p1(i文字目)][p0(i+1文字目)]
    for(int i = 2; i < n; i++){
        REP(p2, 3){
            REP(p1, 3){
                REP(p0, 3){
                    ll flg = 0;
                    REP(j, k){
                        if(i + 1 == a[j] && p0 != b[j]) flg = 1;
                    }
                    if(flg) dp[i + 1][p1][p0] = 0;
                    else if((p2 != p0) || (p1 != p0)){
                        dp[i + 1][p1][p0] += dp[i][p2][p1];
                        dp[i + 1][p1][p0] %= 10000;
                    }
                }
            }
        }
    }
    ll res = 0;
    REP(p2, 3){
        REP(p1, 3){
            res += dp[n][p2][p1];
            res %= 10000;
        }
    }
    cout << res << endl;
    return 0;
}