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++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int total_days,total_predetermined_pastas;
int predetermined_pastas[101];
int dp[101][4][4];

int dfs(int day,int pasta,int successive){
  if(successive == 3) return 0;
  if(predetermined_pastas[day] != -1
     && predetermined_pastas[day] != pasta){
    return 0;
  }
  if(dp[day][pasta][successive] != -1){
    return dp[day][pasta][successive];
  }

  if(day >= total_days){
    return 1;
  }

  int res = 0;

  if(predetermined_pastas[day+1] != -1){
    if(predetermined_pastas[day+1] == pasta){
      res = dfs(day+1,predetermined_pastas[day+1],successive+1);
    }
    else{
      res = dfs(day+1,predetermined_pastas[day+1],1);
    }
  }
  else{
    for(int next = 1; next<=3; next++){
      if(next == pasta){
	res += dfs(day+1,next,successive+1);
      }
      else{
	res += dfs(day+1,next,1);
      }
    }
  }
  return dp[day][pasta][successive] = (res % 10000);
}

int main(){

  while(~scanf("%d %d",&total_days,&total_predetermined_pastas)){
    memset(predetermined_pastas,-1,sizeof(predetermined_pastas));
    for(int pasta_idx = 0; pasta_idx < total_predetermined_pastas; pasta_idx++){
      int day,type;
      scanf("%d %d",&day,&type);
      predetermined_pastas[day] = type;
    }

    memset(dp,-1,sizeof(dp));

    if(predetermined_pastas[1] == -1){
      printf("%d\n",dfs(1,1,1)+dfs(1,2,1)+dfs(1,3,1));
    }
    else{
      printf("%d\n",dfs(1,predetermined_pastas[1],1));
    }
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[101] = { 0 };
	int n;
	int i;
	cin >> n >> i;
	for (int v = 0; v < i; v++){
		int y, x;
		cin >> y >> x;
		a[y] = { x };

	}
	n = n / 3;
	int f;
	if (a[1] = a[2] != a[3]){
		if (a[1] != 0){
			f = 2;
		}
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[1] = a[3] != a[2]){
		if (a[1] != 0)
			f = 2;
		if (a[1] = 0){
			f = 8;
		}
	}
	if (a[3] = a[2] != a[1]){
		if (a[2] != 0)
			f = 2;
		if (a[2] = 0){
			f = 8;
		}
	}
	if (a[1] = a[2] = a[3]){
		if (a[1] = 0){
			f = 24;
		}
		if (a[1] != 0){
			f = 1;
		}

	}

	for (int v = 1; v < n; v++){
		if (a[v * 3 + 1] = a[v * 3 + 2] != a[v * 3 + 3]){
			if (a[1] != 0){
				f = f * 2;
			}
			if (a[v * 3 + 1] = 0){
				f = f * 8;
			}
		}
		if (a[v * 3 + 1] = a[v*3+3] != a[v*3+2]){
			if (a[v*3+1] != 0)
				f = f*2;
			if (a[v * 3 + 1] = 0){
				f = f*8;
			}
		}
		if (a[v * 3 + 3] = a[v * 3 + 2] != a[v * 3 + 1]){
			if (a[v * 3 + 2] != 0)
				f = f*2;
			if (a[v * 3 + 2] = 0){
				f = f*8;
			}
		}
		if (a[v * 3 + 1] = a[v * 3 + 2] = a[v * 3 + 3]){
			if (a[v * 3 + 1] = 0){
				f = f*24;
			}
			if (a[v * 3 + 1] != 0){
				f = f*1;
			}

		}
		
	}
	        cout << f%10000 << endl;
        	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

int main(void){
	int i,n,k,a,b,p,q,r,ans=0,dp[110][3][3],ls[110];
	cin >> n >> k;
	fill(ls,ls+110,-1);
	fill(dp[0][0],dp[110][0],0);
	for(i=0; i<k; i++){
		cin >> a >> b;
		a--;
		b--;
		ls[a] = b;
	}

	for(p=0; p<3; p++){
		if((ls[0]==-1) || (ls[0]==p)){

			for(q=0; q<3; q++){
				if((ls[1]==-1) || (ls[1]==q)){
					dp[1][p][q] = 1;
				}
			}

		}
	}

	for(i=2; i<n; i++){

		for(p=0; p<3; p++){
			if((ls[i-2]==-1) || (ls[i-2]==p)){

				for(q=0; q<3; q++){
					if((ls[i-1]==-1) || (ls[i-1]==q)){

						for(r=0; r<3; r++){
							if((ls[i]==-1) || (ls[i]==r)){
								dp[i][q][r] += (p==q && q == r)?0:dp[i-1][p][q];
								dp[i][q][r] %= 10000;
							}
						}

					}
				}

			}
		}

	}
	for(p=0; p<3; p++){
		for(q=0; q<3; q++){
			ans += dp[n-1][p][q];
			ans %= 10000;
		}
	}
	cout << ans << endl;
	return 0;
}

C++: #include<cstdio>
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cctype>
#include<queue>
#define MM
#define rep(i,a) for(int i=0;i<a;i++)
#define rep2(i,a) for(int i=1;i<=a;i++)
#define rep3(i,a) for(int i=1;i<a;i++)
#define rep4(i,a) for(int i=0;i<=a;i++)
using namespace std;
int dp[101][4][4];
long long int sum;
int main(void)
{
	int x,y;
	int day,al,sosu[101]={MM};
	cin>>day>>al;
	rep(i,al) {cin>>x>>y;sosu[x]=y;}
	dp[MM][MM][MM]=1;
	rep2(i,day)rep(j,4)rep(k,4)rep3(kk,4) {
		if((j!=k||k!=kk)&&(sosu[i]==MM||sosu[i]==kk)) {
            dp[i][k][kk]+=dp[i-1][j][k];
            dp[i][k][kk]%=10000;
		}
	}
	sum=0;
	rep2(i,3)rep4(j,3) sum+=dp[day][i][j];
	cout<<sum%10000<<endl;
	return 0;
}