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<stdio.h>
#include<string.h>
#define MOD 10000
using namespace std;

int main() {
	int n, k, d[100], dp[100][3][3];
	scanf("%d%d", &n, &k);
	memset(d, -1, sizeof(d));
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < k; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		d[a - 1] = b - 1;
	}
	if (~d[0]) dp[0][d[0]][1] = 1;
	else { dp[0][0][1] = dp[0][1][1] = dp[0][2][1] = 1; }
	for (int i = 1; i < n; i++) {//day
		for (int j = 0; j < 3; j++){//pasta(today)
			for (int t = 0; t < 3; t++){//pasta(yesterday)
				for (int p = 0; p < 3; p++){//count(yesterday)
					if (~d[i] && d[i] != j)continue;
					int cnt = 1;
					if (j == t)cnt = p + 1;
					if (cnt >= 3)continue;
					dp[i][j][cnt] = (dp[i][j][cnt] + dp[i - 1][t][p]) % MOD;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			sum = (sum + dp[n - 1][i][j]) % MOD;
		}
	}
	printf("%d\n", sum);
	return 0;
}

C++: #include<iostream>
using namespace std;
int n,k,total,a,b;
int menu[101];
long long t[101][4][3],ans[101];
int ot(int a){
  if(a>3)a-=3;
  return a;
}
int main(){
  cin>>n>>k;
  for(int i=0;i<=100;i++){
    menu[i]=0;
    for(int j=0;j<4;j++){
      for(int k=0;k<3;k++){
	t[i][j][k]=0;
      }
    }
  }

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

  if(menu[1]==0){
    ans[1]=3;
    t[1][1][1]=t[1][2][1]=t[1][3][1]=1;
    t[1][1][0]=t[1][2][0]=t[1][3][0]=2;
  }else{
    t[1][menu[1]][1]=1;
    t[1][ot(menu[1]+1)][0]=1;
    t[1][ot(menu[1]+2)][0]=1;
    ans[1]=1;
  }
  for(int i=2;i<=n;i++){
    if(menu[i]==0){
      ans[i]=ans[i-1]*3;
      ans[i]-=t[i-1][1][2]+t[i-1][2][2]+t[i-1][3][2];
      t[i][1][2]=t[i-1][1][1];
      t[i][1][1]=t[i-1][1][0];
      t[i][1][0]=ans[i]-t[i][1][2]-t[i][1][1];

      t[i][2][2]=t[i-1][2][1];
      t[i][2][1]=t[i-1][2][0];
      t[i][2][0]=ans[i]-t[i][2][2]-t[i][2][1];

      t[i][3][2]=t[i-1][3][1];
      t[i][3][1]=t[i-1][3][0];
      t[i][3][0]=ans[i]-t[i][3][2]-t[i][3][1];

    }else{
      ans[i]=ans[i-1]-t[i-1][menu[i]][2];
      t[i][menu[i]][2]=t[i-1][menu[i]][1];
      t[i][menu[i]][1]=t[i-1][menu[i]][0];
      t[i][menu[i]][0]=0;
      t[i][ot(menu[i]+1)][0]=ans[i];
      t[i][ot(menu[i]+2)][0]=ans[i];
      t[i][ot(menu[i]+1)][1]=0;
      t[i][ot(menu[i]+2)][1]=0;
      t[i][ot(menu[i]+1)][2]=0;
      t[i][ot(menu[i]+2)][2]=0;
    }
    ans[i]%=10000;
    for(int j=1;j<=3;j++){
      for(int k=0;k<=2;k++){
	t[i][j][k]%=10000;
      }
    }
  }
  cout<<ans[n]%10000<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int a[101];

int dp[101][4][4];

int n, k;

int rec(int day, int pp, int p)
{
	if (day > n) return 1;

	if (dp[day][pp][p] >= 0) return dp[day][pp][p];

	int res = 0;

	if (a[day]) {
		if (a[day] != pp || a[day] != p) {
			res = rec(day + 1, p, a[day]);
			res %= 10000;
		}
	} else {
		for (int i = 1; i <= 3; ++i) {
			if (pp == p && p == i) continue;
			res += rec(day + 1, p, i);
			res %= 10000;
		}
	}

	return dp[day][pp][p] = res;
}

int main()
{
	cin >> n >> k;

	for (int i = 0; i < k; ++i) {
		int day; cin >> day;
		cin >> a[day];
	}
	
	memset(dp, -1, sizeof(dp));

	printf("%d\n", rec(1, 0, 0));
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int T[100];
int dp[110][3][3];

signed main(){
    cin>>N>>K;
    memset(T,-1,sizeof(T));
    rep(i,K){
        int a,b;
        cin>>a>>b;
        a--;b--;
        T[a]=b;
    }

    rep(i,3)rep(j,3){
        if(T[0]>=0&&T[0]!=i)continue;
        if(T[1]>=0&&T[1]!=j)continue;
        dp[2][i][j]=1;
    }

    for(int i=2;i<N;i++){
        rep(j,3)rep(k,3)rep(l,3){
            if(T[i]>=0&&T[i]!=l)continue;
            if(j==k&&k==l)continue;
            dp[i+1][k][l]=(dp[i+1][k][l]+dp[i][j][k])%10000;
        }
    }

    int ans=0;
    rep(i,3)rep(j,3)ans=(ans+dp[N][i][j])%10000;
    cout<<ans<<endl;
    return 0;
}