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 <cstdio>
#include <algorithm>
using namespace std;

const int MAX_N = 100;
int N, K;
int plan[MAX_N + 1];
int memo[MAX_N + 1][4][4];
int solve(int n, int b1, int b2) {
	if (n == N + 1) return 1;
	if (memo[n][b1][b2] != -1) return memo[n][b1][b2];
	if (plan[n] != 0) {
		if (b1 == b2 && b1 == plan[n])
			return 0;
		else
			return solve(n + 1, plan[n], b1) % 10000;
	}
	int t = 0;
	for (int i = 1; i <= 3; ++i) {
		if (b1 == b2 && b1 == i) continue;
		t += solve(n + 1, i, b1) % 10000;
	}
	return memo[n][b1][b2] = t % 10000;
}
int main() {
	scanf("%d %d", &N, &K);
	for (int i = 0; i < K; ++i) {
		int d, k;
		scanf("%d %d", &d, &k);
		plan[d] = k;
	}
	for (int i = 0; i <= N; ++i)
		for (int j = 0; j < 4; ++j)
			for (int k = 0; k < 4; ++k)
				memo[i][j][k] = -1;
	printf("%d\n", solve(1, 0, 0));
	return 0;
}

C++: #include<stdio.h>

#define MOD 10000

int N ,K ;
int plan[ 100 + 1 ][ 4 + 1 ][ 4 + 1 ] ;
int _now[ 100 + 1 ] ;

int Cnt( int day ,int prev ,int now )
{
	if( day == N )
	{
		return 1 ;
	}

	int &next = _now[ day ] ;
	if( next > 0 )
	{
		if( prev == now && now == next )
		{
			return 0 ;
		}
		
		return Cnt( day + 1 ,now ,next ) ;
	}

	int &value = plan[ day ][ prev ][ now ] ;
	if( value > 0 )
	{
		return value ;
	}

	int nex ,cnt = 0 ;
	for( nex = 1 ; nex <= 3 ; ++nex )
	{
		if( prev != now || now != nex )
		{
			cnt = (cnt + Cnt( day + 1 ,now ,nex )) % MOD ;
		}
	}

	return (value = cnt) ;
}


int main( void )
{
	scanf( "%d %d" ,&N ,&K ) ;

	++N ;

	int i ,day ,menu ;
	for( i = 0 ; i < K ; ++i )
	{
		scanf( "%d %d" ,&day ,&menu ) ;

		_now[ day ] = menu ;
	}

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

	return 0 ;
}

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

using namespace std;


int dfs(vector<int>& menu, int now) {
    int ans=0;

    if(now==(int)menu.size()) {
        return 1;
    }

    if(menu[now]==0){
        for(int c=1; c<=3; ++c) {
            if(now>=2 && menu[now-2]==c && menu[now-1]==c) continue;
            if(now>=1 && now<=(int)menu.size()-2 && menu[now-1]==c && menu[now+1]==c) continue;
            if(now<=(int)menu.size()-3 && menu[now+1]==c && menu[now+2]==c) continue;
            menu[now]=c;
            ans=(ans+dfs(menu,now+1))%10000;
            menu[now]=0;
        }
    } else {
        ans=(ans+dfs(menu,now+1))%10000;
    }

    return ans;
}

int main()
{
    int N,K;
    vector<int> menu;

    cin >> N >> K;

    menu.resize(N);

    fill(menu.begin(),menu.end(),0);

    for(int i=0; i<K; ++i) {
        int a,b;
        cin >> a >> b;
        menu[a-1]=b;
    }

    cout << dfs(menu,0) << endl;

    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int N,K;
int A[100],B[100];
int dp[110][4][4][4];
int mod=10000;
int main()
{
	scanf("%d%d",&N,&K);
	for(int i=0;i<K;i++){
		scanf("%d%d",&A[i],&B[i]);A[i]--;B[i]--;
	}
	
	for(int i=0;i<K;i++){
		for(int j=i+1;j<K;j++){
			if(A[i]>A[j]){
				swap(A[i],A[j]);swap(B[i],B[j]);
			}
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				//dp[3][i][j][k]
				if(A[0]==0&&i!=B[0])continue;
				if(A[0]==1&&j!=B[0])continue;
				if(A[1]==1&&j!=B[1])continue;
				if(A[0]==2&&k!=B[0])continue;
				if(A[1]==2&&k!=B[1])continue;
				if(A[2]==2&&k!=B[2])continue;
				if(i==j&&i==k)continue;
				//printf("%d %d %d\n",i,j,k);
				dp[2][i][j][k]++;
			}
		}
	}
	for(int i=3;i<N;i++){
		int X=-1;
		for(int j=0;j<K;j++){
			if(A[j]==i)X=B[j];
		}
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				for(int l=0;l<3;l++){
					if(j==k&&j==l)continue;
					if(X!=-1&&l!=X)continue;
					dp[i][j][k][l]+=dp[i-1][0][j][k];
					dp[i][j][k][l]+=dp[i-1][1][j][k];
					dp[i][j][k][l]+=dp[i-1][2][j][k];
					dp[i][j][k][l]%=mod;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<27;i++)ans+=dp[N-1][i/9][(i/3)%3][i%3];
	printf("%d\n",ans%mod);
	return 0;
}

C++: #include<iostream>
using namespace std;
#define MOD 10000
int N, K, hoge[101],dp[100][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 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 <bits/stdc++.h>
using namespace std;
const int MOD = 1e4;

int n;
int ng[101][4];
int dp[101][4][4];

int search(int i, int a, int b)
{
	int &res = dp[i][a][b];
	if (~res) return res;
	if (ng[i][b]) return res = 0;
	if (i == n) return res = 1;
	
	res = 0;
	for (int ne = 1; ne <= 3; ne++){
		if (a == b && b == ne) continue;
		res += search(i + 1, b, ne);
		res %= MOD;
	}
	return res;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	
	int k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < k; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		ng[a][(b + 1) % 3 + 1] = true;
		ng[a][b % 3 + 1] = true;
	}
	
	int res = search(0, 0, 0);
	
	printf("%d\n", res);
}