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<stdio.h>
int dp[101][4][4];
int main(void)
{
	int N,K,A,B,S[101],i,j,k,l,x=0;
	scanf("%d%d",&N,&K);
	for(i=1;i<=N;i++){
		S[i]=0;
	}
	for(i=1;i<=K;i++){
		scanf("%d%d",&A,&B);
		S[A]=B;
	}
	for(i=0;i<=N;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				dp[i][j][k]=0;
			}
		}
	}
	dp[0][1][2]=1;
	for(i=0;i<N;i++){
		if(S[i+1]!=0){
			for(j=1;j<=3;j++){
				for(k=1;k<=3;k++){
					if(dp[i][j][k]!=0){
						if(i==1||S[i+1]!=j||k!=j){
							dp[i+1][S[i+1]][j]+=dp[i][j][k];
							dp[i+1][S[i+1]][j]%=10000;
						}
					}
				}
			}
		}
		else{
			for(j=1;j<=3;j++){
				for(k=1;k<=3;k++){
					if(dp[i][j][k]!=0){
						for(l=1;l<=3;l++){
							if(i==1||j!=k||l!=k){
								dp[i+1][l][j]+=dp[i][j][k];
								dp[i+1][l][j]%=10000;
							}
						}
					}
				}
			}
		}
	}
	/*for(i=0;i<=N;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				printf("%d ",dp[i][j][k]);
			}
			printf(" | ");
		}
		printf("\n");
	}*/
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			x+=dp[N][i][j];
			x%=10000;
		}
	}
	printf("%d\n",x);
	return 0;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll dp[101][4][4];

int main() {
  int n, m;
  cin >> n >> m;
  int y[100] = {};
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    y[a - 1] = b;
  }

  rep(i, 1, 4) rep(j, 1, 4) {
    int a = y[0] ? y[0] : i, b = y[1] ? y[1] : j;
    dp[1][b][a] = 1;
  }

  rep(i, 2, n) rep(j, 1, 4) rep(k, 1, 4){
    if(y[i]) {
      if(!(y[i] == j && j == k)) dp[i][y[i]][j] += dp[i - 1][j][k];
      dp[i][y[i]][j] %= 10000;
      continue;
    }
    rep(l, 1, 4) if(!(j == k && k == l)) dp[i][j][k] += dp[i - 1][k][l];
    dp[i][j][k] %= 10000;
  }

  ll ans = 0;
  rep(i, 1, 4) rep(j, 1, 4) ans += dp[n - 1][i][j];
  cout << ans % 10000 << endl;
}

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

int main(){
	int n,m,d[1000],t[1000],type[4][100],c[4][100];
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>d[i]>>t[i];
	}
	for(int i=0;i<m;i++){
		if(d[i]==1){
			type[d[i]][1]=1;
			goto Exit1;
		}
	}
	type[1][1]=1;
	type[2][1]=1;
	type[3][1]=1;
	
Exit1:
	for(int i=1;i<=3;i++){
		if(type[i][1]!=1){
			type[i][1]=0;
		}
	}
	type[1][2]=0;
	type[2][2]=0;
	type[3][2]=0;
	for(int i=2;i<=n;i++){
		for(int j=0;j<m;j++){

			if(d[j]==i){
				type[t[j]][2]=type[t[j]][1];
				type[t[j]][1]=0;
				for(int k=1;k<=3;k++){
					if(t[j]!=k){
						for(int l=1;l<=2;l++){
						type[t[j]][1] += type[k][l];
						type[k][l]=0;
						}
					}
				}
				goto Exit2;
			}

		}
		memset(c,0,sizeof(c));
		for(int k=1;k<=3;k++){
			for(int l=1;l<=3;l++){
				if(k==l){
					c[l][2] += type[k][1];
				}
				else{
					c[l][1] += type[k][1]+type[k][2];
				}
			}
		}
		for(int k=1;k<=3;k++){
			type[k][1]=c[k][1];
			type[k][2]=c[k][2];
		}
Exit2:
		for(int j=1;j<=3;j++){
			for(int k=1;k<=2;k++){
				type[j][k]=type[j][k]%10000;
			}
		}
	}
	cout<<(type[1][1]+type[1][2]+type[2][1]+type[2][2]+type[3][1]+type[3][2])%10000<<endl;
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
using namespace std;
int N,K,f11[100],f12[100],f13[100],f21[100],f22[100],f23[100],f31[100],f32[100],f33[100];
int d[100]={};
int main()
{
	cin>>N>>K;
	for(int i=0;i<K;i++){
		int a,b;cin>>a>>b;
		d[a]=b;
	}
	f11[2]=f12[2]=f13[2]=f21[2]=f22[2]=f23[2]=f31[2]=f32[2]=f33[2]=0;
	if(d[1]==0){
		if(d[2]==0)f11[2]=f12[2]=f13[2]=f21[2]=f22[2]=f23[2]=f31[2]=f32[2]=f33[2]=1;
		else if(d[2]==1)f11[2]=f21[2]=f31[2]=1;
		else if(d[2]==2)f12[2]=f22[2]=f32[2]=1;
		else if(d[2]==3)f13[2]=f23[2]=f33[2]=1;
	}else if(d[1]=1){
		if(d[2]==0)f11[2]=f12[2]=f13[2]=1;
		else if(d[2]==1)f11[2]=1;
		else if(d[2]==2)f12[2]=1;
		else if(d[2]==3)f13[2]=1;
	}else if(d[1]=2){
		if(d[2]==0)f21[2]=f22[2]=f23[2]=1;
		else if(d[2]==1)f21[2]=1;
		else if(d[2]==2)f22[2]=1;
		else if(d[2]==3)f23[2]=1;
	}else if(d[1]=3){
		if(d[2]==0)f31[2]=f32[2]=f33[2]=1;
		else if(d[2]==1)f31[2]=1;
		else if(d[2]==2)f32[2]=1;
		else if(d[2]==3)f33[2]=1;
	}
	for(int i=3;i<=N;i++){
		f11[i]=(f21[i-1]+f31[i-1])%10000;
		f22[i]=(f12[i-1]+f32[i-1])%10000;
		f33[i]=(f13[i-1]+f23[i-1])%10000;
		f12[i]=(f11[i-1]+f21[i-1]+f31[i-1])%10000;
		f13[i]=(f11[i-1]+f21[i-1]+f31[i-1])%10000;
		f21[i]=(f12[i-1]+f22[i-1]+f32[i-1])%10000;
		f23[i]=(f12[i-1]+f22[i-1]+f32[i-1])%10000;
		f31[i]=(f13[i-1]+f23[i-1]+f33[i-1])%10000;
		f32[i]=(f13[i-1]+f23[i-1]+f33[i-1])%10000;
		if(d[i]==1)f12[i]=f13[i]=f22[i]=f23[i]=f32[i]=f33[i]=0;
		else if(d[i]==2)f11[i]=f13[i]=f21[i]=f23[i]=f31[i]=f33[i]=0;
		else if(d[i]==3)f11[i]=f12[i]=f21[i]=f22[i]=f31[i]=f32[i]=0;
	}
	cout<<(f11[N]+f12[N]+f13[N]+f21[N]+f22[N]+f23[N]+f31[N]+f32[N]+f33[N])%10000<<endl;
}