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 <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 i=0; i<3; i++) {
		for (int j=0; j<=N; j++) {
			cout << dp[j][i] << " ";
		}
		cout << endl;
	}
	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;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

int memo[101][4][4];
int N, K;
int A, B;
int plan[101];

int rec(int d, int y, int a){
	if(d == N + 1)return 1;
	if(memo[d][y][a] != -1)return memo[d][y][a];
	
	if(plan[d] != 0){
		if(a == y && y == plan[d]){
			return 0;
		}
		else {
			return rec(d + 1, plan[d], y) % 10000;
		}
	}
	
	int best = 0;
	for(int next = 1; next <= 3; next++){
		if(a == y && y == next){
			continue;
		}
		else{
			best += rec(d + 1, next, y) % 10000;
		}
	}
	
	return memo[d][y][a] = best % 10000;
}

int main() {
	for(int i = 0; i <= 100; i++)
		for(int j = 0; j < 4; j++)
			for(int k = 0; k < 4; k++)
				memo[i][j][k] = -1;
				
	cin >> N >> K;
	
	for(int i = 0; i < K; i++){
		cin >> A >> B;
		plan[A] = B;
	}
		
	
	cout << rec(1, 0, 0) << endl;
	
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int dfs(int day,int tmt,int cream,int bazil);
int dfsmem[105][3][3][3];
int n,k;
int mem[105];
main(){
  cin>>n>>k;
  memset(mem,-1,sizeof(mem));
  memset(dfsmem,-1,sizeof(dfsmem));
  for(int i=0;i<k;i++){
    int a,b;
    cin>>a>>b;
    mem[a]=b;
  }
  cout<<dfs(0,0,0,0)/3<<endl;
}
int dfs(int day,int tmt,int cream,int bazil){
  if(day>n){
    return 1;
  }
  else if(tmt>=3||cream>=3||bazil>=3){
    return 0;
  }
  else if(dfsmem[day][tmt][cream][bazil]!=-1){
    return dfsmem[day][tmt][cream][bazil];
  }
  else if(mem[day]!=-1){
    if(mem[day]==1){
      return dfsmem[day][tmt][cream][bazil]=dfs(day+1,tmt+1,0,0)%10000;
    }
    else if(mem[day]==2){
      return dfsmem[day][tmt][cream][bazil]=dfs(day+1,0,cream+1,0)%10000;
    }
    else if(mem[day]==3){
      return dfsmem[day][tmt][cream][bazil]=dfs(day+1,0,0,bazil+1)%10000;
    }
  }
  else{
    int paturn=0;
    paturn+=dfs(day+1,tmt+1,0,0)%10000;
    paturn+=dfs(day+1,0,cream+1,0)%10000;
    paturn+=dfs(day+1,0,0,bazil+1)%10000;
    return dfsmem[day][tmt][cream][bazil]=paturn%10000;
  }
}

C++: #include<iostream>
using namespace std;
#define MOD 10000
int N, K, hoge[101],dp[101][4][4];
int rec(int today,int kino,int oto){ //日付 昨日 一昨日
  if(today == N) return 1;
  if(dp[today][kino][oto]) return dp[today][kino][oto];
  int ret = 0;
  if(hoge[today]){ //決まってるじゃん
    if(hoge[today] == kino && kino == oto) ret = 0;
    else ret = rec(today + 1,hoge[today],kino);
  }else{ //決まってないじゃん
    for(int i = 1 ; i < 4 ; i++ ){
      if(i != kino || kino != oto) ret += rec( today + 1, i, kino);
    }
  }
  return dp[today][kino][oto] = ret % MOD;
}
int main(){
  cin >> N >> K;
  for(int i = 0 ; i < K ; i++ ){
    int day;
    cin >> day;
    cin >> hoge[--day];
  }
  cout << rec(0,0,0) << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
int n, k, p[110], dp[110][4][4];//day,plan|1 origin!

int s(int now, int typ, int ren) {//now>>n日目まで、同種類ren日連続
	if (ren == 3)return 0;
	if (now == n)return 1;
	if (dp[now][typ][ren] != -1)return dp[now][typ][ren];
	if (p[now] != -1) {
		if (typ == p[now])dp[now][typ][ren] = s(now + 1, typ, ren + 1);
		else {
		dp[now][typ][ren] = s(now + 1, p[now], 1);
		}
	}
	else {
		dp[now][typ][ren] = s(now + 1, typ, ren + 1) + s(now + 1, (typ + 1) % 3, 1) + s(now + 1, (typ + 2) % 3, 1);
	}
	dp[now][typ][ren] %= 10000;
	return dp[now][typ][ren];
}


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

	for (int i = 0; i <= n; i++) {
		p[i] = -1;
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++)dp[i][j][k] = -1;
		}
	}

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

	cout << s(0, 0, 0)%10000 << endl;

	return 0;
}