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;

enum Sauce{ NOT_DETERMINED = 0, Tomato = 1, Cream = 2, Basil = 3 };
enum Seq{ SAME, DIFF };

const int divisor = 10000;

class Pasta{
public:
	Pasta(int _N);
	~Pasta();

	Sauce* sauceary;
	int schedule(int i, Sauce yesterday, Seq seq);

private:
	int N;
	int*** memo;
};

Pasta::Pasta(int _N){
	N = _N;
	sauceary = new Sauce[N + 1];
	memo = new int**[N + 1];

	for (int i = 0; i <= N; i++) sauceary[i] = NOT_DETERMINED;

	for (int i = 0; i <= N; i++){
		memo[i] = new int*[4];
		for (int j = 0; j < 4; j++){
			memo[i][j] = new int[2];
			memo[i][j][SAME] = -1;
			memo[i][j][DIFF] = -1;
		}
	}
}

Pasta::~Pasta(){
	delete[] sauceary;
	delete[] memo;
}

int Pasta::schedule(int i, Sauce yesterday, Seq seq){
	if (i == N + 1) return 1;
	if (memo[i][yesterday][seq] >= 0) return memo[i][yesterday][seq];

	if (seq == SAME && yesterday == sauceary[i]){
		memo[i][yesterday][SAME] = 0;
		return 0;
	}

	if (sauceary[i] == NOT_DETERMINED){
		int tmpmemo = 0;

		for (int si = 1; si <= 3; si++){
			if ((Sauce)si == yesterday && seq == SAME) continue;
			else if ((Sauce)si == yesterday && seq == DIFF) tmpmemo += schedule(i + 1, (Sauce)si, SAME) % divisor;
			else tmpmemo += schedule(i + 1, (Sauce)si, DIFF) % divisor;
		}

		memo[i][yesterday][seq] = tmpmemo % divisor;
		return tmpmemo;
	}
	else {
		if (yesterday == sauceary[i]) memo[i][yesterday][seq] = schedule(i + 1, sauceary[i], SAME) % divisor;
		else memo[i][yesterday][seq] = schedule(i + 1, sauceary[i], DIFF) % divisor;
			
		return memo[i][yesterday][seq];
	}
}

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

	Pasta* pasta = new Pasta(N);

	for (int i = 0; i < K; i++){
		int A, B;
		cin >> A >> B;
		pasta->sauceary[A] = (Sauce)B;
	}

	cout << pasta->schedule(1, NOT_DETERMINED, DIFF) % divisor << endl;

	delete pasta;
	return 0;
}

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

int dp[114][5][14];//day yesterday today
int pa[114];//pasta

int main(){
	int n,ka;
	cin>>n>>ka;
	for(int i=0;i<ka;i++){
		int a,b;
		cin>>a>>b;
		pa[a]=b;
		}
		
	if(pa[1]){
		for(int i=0;i<3;i++)dp[1][i][pa[1]-1]++;
		}
	else{
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)dp[1][i][j]++;
		}	
		
	for(int x=2;x<=n;x++){
		if(pa[x]==1){
			for(int i=0;i<3;i++){
				for(int j=0;j<3;j++){
					if(i==j&&j==0)continue;
					dp[x][i][0]+=dp[x-1][j][i];
					dp[x][i][0]%=modulo;
					}
				}
			}
		else if(pa[x]==2){
			for(int i=0;i<3;i++){
				for(int j=0;j<3;j++){
					if(i==j&&j==1)continue;
					dp[x][i][1]+=dp[x-1][j][i];
					dp[x][i][1]%=modulo;
					}
				}
			}
		else if(pa[x]==3){
			for(int i=0;i<3;i++){
				for(int j=0;j<3;j++){
					if(i==j&&j==2)continue;
					dp[x][i][2]+=dp[x-1][j][i];
					dp[x][i][2]%=modulo;
					}
				}
			}
		else{
			for(int i=0;i<3;i++){
				for(int j=0;j<3;j++){
					for(int k=0;k<3;k++){
						if(x!=2){
						if(i==j&&j==k)continue;}
						dp[x][i][j]+=dp[x-1][k][i];
						dp[x][i][j]%=modulo;
						}
					}
				}
			}
		}	
		int ans=0;
		for(int i=0;i<3;i++)ans+=dp[n][i][0];
		ans%=modulo;
		cout<<ans<<endl;
		return 0;
	}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int M = 10000;
static const int NMAX = 100;

main(){
  int N, K, A, B;
  int dp[NMAX+1][3][2], T[NMAX+1];

  cin >> N >> K;

  rep(i, N+1) rep(j, 3) rep(k, 2) dp[i][j][k] = 0;
  rep(i, N+1) T[i] = -1;

  rep(i, K){
    cin >> A >> B;
    B--; // 0, 1, 2
    T[A] = B;
  }
  
  // init
  if ( T[1] >= 0 ){
    dp[1][T[1]][1] = 1;
  } else {
    rep(j, 3) dp[1][j][0] = 1;
  }

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

  int sum = 0;
  rep(j, 3) rep(k, 2) sum = (sum + dp[N][j][k])%M;

  cout << sum << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int dp[205][5][5];
int main() {
	int a, b, n, m, ans = 0;
	cin >> n >> m;
	vector<int>v(n + 1, 4);
	for (int i = 0; i<m; ++i) {
		cin >> a >> b;
		v[a] = b - 1;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j<3; ++j) {
			if (v[i] != 4 && v[i] != j) continue;
			if (i == 1) {
				dp[i][0][j] = 1; continue;
			}
			a = 0;
			for (int k = 0; k<3; ++k) {
				if (k == j) continue;
				a += dp[i - 1][0][k] + dp[i - 1][1][k];
			}
			dp[i][0][j] = a;
			dp[i][1][j] = dp[i - 1][0][j];
			dp[i][0][j] %= 10000, dp[i][1][j] %= 10000;
		}
	}
	for (int i = 0; i<2; ++i) {
		for (int j = 0; j<3; ++j) {
			ans += dp[n][i][j];
			ans %= 10000;
		}
	}
	cout << ans << endl;
}