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;
		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;
	}

	int ans;
	if (pasta->sauceary[1] == NOT_DETERMINED){
		ans = pasta->schedule(2, Tomato, DIFF) + pasta->schedule(2, Cream, DIFF) + pasta->schedule(2, Basil, DIFF);
	}
	else {
		ans = pasta->schedule(2, pasta->sauceary[1], DIFF);
	}

	cout << ans % divisor << endl;

	delete pasta;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
#define S second
#define F first
typedef pair<int,int> Pi;

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }


int N, K;
int data[105];
int memo[105][4][2];

int dfs(int it, int ch, int cnt)
{
  int ret = 0;
  if(it == N)return 1;
  if(~memo[it][ch][cnt])return memo[it][ch][cnt];
  if(data[it + 1] != INF) {
    int nc;
    if(data[it + 1] == ch) nc = cnt + 1;
    else nc = 0;
    if(nc < 2) (ret += dfs(it + 1,data[it + 1],nc)) %= 10000;
  }else {
    Rep(i,3) {
      int nc;
      if(ch == i) nc = cnt + 1;
      else nc = 0;
      if(nc < 2) (ret += dfs(it + 1,i,nc)) %= 10000;
    }
  }
  return memo[it][ch][cnt] = ret;
}

int main()
{
  memset(memo,-1,sizeof(memo));
  cin >> N >> K;
  int A, B;
  fill(data,data + 105,INF);
  Rep(i,K) {
    cin >> A >> B; --B;
    data[A] = B;
  }
  cout << dfs(0,3,0) << endl;
  return(0);
}

C++: #include<cstdio>

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

using namespace std;

int day[128];
int dp[128][3][2];

int main(void){
	
	int n,k;
	int a,b;
	const int X = 10000;
	
	scanf("%d %d", &n, &k);
	
	rep(i,k){
		scanf("%d %d", &a, &b);
		day[a] = b;
	}
	
	rep(i,3){
		dp[1][i][0] = 1;
	}
	
	for(int i = 1; i <= n; i++){
		rep(j,3){
			if(day[i] != 0 && day[i] != j+1){
				dp[i][j][0] = 0;
				dp[i][j][1] = 0;
			}
			else{
				rep(l,3){
					if(l!=j)dp[i][j][0] += dp[i-1][l][0] + dp[i-1][l][1];
				}
				dp[i][j][1] += dp[i-1][j][0];
				dp[i][j][0]%=X;
				dp[i][j][1]%=X;
			}
		}
	}
	int ans = 0;
	rep(i,3){
		rep(j,2){
			ans += dp[n][i][j];
		}
	}
	printf("%d\n", ans%X);
	return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int dp[101][4][4];
int data[101];

main(){
  dp[0][0][0] = 1;
  cin >> n >> k;
  for(int i=0;i<k;i++){
    int in;
    cin >> in;
    cin >> data[in];
  }
  for(int i=1;i<=n;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        if(data[i] != 0){
          if(j == k && j == data[i]){
          }else{
            dp[i][k][data[i]] += dp[i-1][j][k];
            dp[i][k][data[i]] %= 10000;
          }
        }else{
          for(int l=1;l<4;l++){
            if(j == k && j == l){
            }else{
              dp[i][k][l] += dp[i-1][j][k];
              dp[i][k][l] %= 10000;
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      ans += dp[n][i][j];
      ans %= 10000;
    }
  }
  cout << ans << endl;
  return 0;
}