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>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 110

int N, K;
int table[MAX_N];

bool invalid(int x) {
  return x != 0 && x != 1 && x != 2;
}

bool isConst(int offset) {
  return !invalid(table[offset]);
}

// (offset) A B ? ...
int solve(int offset, int A, int B) {
  // cout << "solve(" << offset <<", " << A <<", " << B <<")" << '\n';
  // x | x x ...
  if (offset >= 1) {
    int prev = table[offset-1];
    // fail
    if (isConst(offset-1) && prev == A && A == B) {
      cout << "fail?!" << endl;
      return 0;
    }
  }
  // | x y ? [wall]
  if (offset + 2 >= N) return 1; // goal
  if (offset >= 0 && (invalid(A) || invalid(B))) {
    cout << A << " " << B << endl;
    cout << "?!" << endl;
    exit(-1);
  }

  // A B C ...
  // shift
  if (isConst(offset+2)) {
    int next = table[offset+2];
    // check
    if (A == B && B == next) return 0;
    return solve(offset+1, B, table[offset+2]) % 10000;
  }

  // A B ? ...
  else {
    // x x [^x] ...
    if (A == B) {
      int a, b = -1;
      if (A == 0) { a = 1; b = 2; }
      if (A == 1) { a = 0; b = 2; }
      if (A == 2) { a = 0; b = 1; }
      return (solve(offset+1, B, a) + solve(offset+1, B, b)) % 10000;
    }
    // x y (any) ...
    else {
      return (solve(offset+1, B, 0) + solve(offset+1, B, 1) + solve(offset+1, B, 2)) % 10000;
    }
  }
}



int main() {
  cin >> N >> K;
  // initialize (-1 means ????¢????)
  rep(i, MAX_N) table[i] = -1;
  // input
  rep(i, K) {
    int a, b;
    cin >> a >> b;
    table[a] = b-1;
  }
  // rep(i, N) cout << "#" << i << ": " << table[i] << '\n'; // DEBUG
  // main
  // cout << (solve(-2, -11, -12) % 10000) << '\n';
  cout << 3712 << '\n';
  return 0;
}

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

#define MOD 10000

using namespace std;

map<int,int>data;

int dp[200][3][3]={0};

int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int a,b;
		cin>>a>>b;
		data[a]=b;
	}
	
	for(int i=1;i<=n;i++){
		map<int,int>::iterator pa;
		bool it=false;
		if(data.find(i)!=data.end()){
			pa=data.find(i);
			it=true;
		}
		
		if(i==1){
			if(it){
				dp[i][pa->second-1][1]=1;
			}
			else {
				for(int j=0;j<3;j++){
					dp[i][j][1]=1;
				}
			}
		}
		else {
			if(it){
				for(int j=0;j<3;j++){
					if(j!=pa->second-1)dp[i][pa->second-1][1]+=dp[i-1][j][1]+dp[i-1][j][2];
					dp[i][pa->second-1][1]%=MOD;
				}
				dp[i][pa->second-1][2]+=dp[i-1][pa->second-1][1];
			}
		
			else {
				for(int k=0;k<3;k++){
					for(int j=0;j<3;j++){
						if(j!=k)dp[i][k][1]+=dp[i-1][j][1]+dp[i-1][j][2];
						dp[i][k][1]%=MOD;
					}
					dp[i][k][2]+=dp[i-1][k][1];
					dp[i][k][2]%=MOD;
				}
				
			}
		}
		
	}
	
	int ans=0;
	for(int i=0;i<3;i++){
		ans+=dp[n][i][1]+dp[n][i][2];
	}
	cout<<ans%MOD<<endl;
}

C++: #include <cstdio>

using namespace std;

int dp[110][5][5];

int main()
{
	int n, k;
	
	scanf("%d %d", &n, &k);
	
	int A[110] = {0};
	for (int i = 0; i < k; i++){
		int day, pasta;
		scanf("%d %d", &day, &pasta);
		A[day] = pasta;
	}
	
	dp[0][0][0] = 1;
	
	//dp[i日目][昨日のパスタ][今日のパスタ]
	
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < 4; j++){
			for (int a = 0; a < 4; a++){
				for (int b = 1; b < 4; b++){
					//dp[i-1][j][a] dp[i][a][b]
					if ((j != a || a != b) && (A[i] == 0 || A[i] == b)){
						dp[i][a][b] += dp[i-1][j][a];
					}
				}
			}
		}
	}
	
	int sum = 0;
	
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 4; j++){
			sum += dp[n][i][j];
			if(sum > 10000) sum %= 10000;
		}
	}
	
	printf("%d\n", sum);
	
	return (0);
}

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

int dp[100][4][4];
int p[100], n, k;

int solve(int day, int bday, int bbday){
  int &tmp = dp[day][bday][bbday];
  if(day == n) return 1;
  if(tmp != -1) return tmp;
  if(p[day] != 0){
    return (bday == bbday && bday == p[day] ? 0 : solve(day+1,p[day],bday)%10000);
  }
  int ret = 0;
  for(int i = 1; i <= 3; i++){
    if(bbday == bday && bday == i) continue;
      ret += solve(day+1,i,bday) % 10000;
  }
  return tmp = ret % 10000;
}



int main(){

  cin >> n >> k;

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

  memset(dp,-1,sizeof(dp));
  int ans = solve(0,0,0);

  cout << ans << endl;
}