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>

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];
						dp[i][a][b] %= 10000;
						//printf("%d\n", dp[i][a][b]);
					}
				}
			}
		}
	}
	
	int sum = 0;
	
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 4; j++){
			sum += dp[n][i][j];
			sum %= 10000;
		}
	}
	
	printf("%d\n", sum);
	
	return (0);
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int a[100],b[100][4][4],n,m;
int fn(int p,int q,int r){
  int i;
  if(p==n)
    return 1;
  if(a[p]){
    if(q==r&&r==a[p])
      return 0;
    return fn(p+1,r,a[p]);
  }
  if(b[p][q][r]>=0)
    return b[p][q][r];
  int sm=0;
  for(i=1;i<=3;++i){
    if(q==r&&r==i)
      continue;
    sm=(sm+fn(p+1,r,i))%10000;
  }
  return b[p][q][r]=sm;
}
int main(){
  int i;
  cin>>n>>m;
  memset(a,0,sizeof(a));
  for(i=0;i<m;++i){
    int p,q;
    cin>>p>>q;
    --p;
    a[p]=q;
  }
  memset(b,-1,sizeof(b));
  cout<<fn(0,0,0)<<endl;
  return 0;
}

C++: #include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> it(3, 1);
	vector<int> zer(3, 0);
	vector<vector<int> > tek(n, it);
	for (int i = 0; i < k; i++) {
		int x, y;
		cin >> x >> y;
		tek[x - 1][(y + 1) % 3] = 0;
		tek[x - 1][(y + 2) % 3] = 0;
	}
	vector<vector<int> > ku(2, zer);
	ku[0] = tek[0];
	for (int i = 1; i < n; i++) {
		vector<vector<int> > yob(2, zer);
		yob = ku;
		ku[0] = zer;
		for (int j = 0; j < 3; j++) {
			ku[1][j] = tek[i][j]*yob[0][j];
			for (int k = (j + 1) % 3; k != j; k = (k + 1) % 3) {
				ku[0][j] =( ku[0][j]+(tek[i][j] * (yob[0][k]+yob[1][k])))%10000;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			ans = (ku[i][j] + ans) % 10000;
		}
	}
	cout << ans << endl;
}

C++: #include<stdio.h>
int dp[101][4][2];//day, type, ツづつづδつォツつゥツつス
int type[101];
int main(){
	int a,b;
	int MOD=10000;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int c,d;
		scanf("%d%d",&c,&d);
		type[c]=d;
	}
	dp[0][0][0]=1;
	for(int i=1;i<=a;i++){
		if(type[i]){
			dp[i][type[i]][0]=dp[i-1][0][0];
			if(type[i]==1)dp[i][type[i]][1]+=dp[i-1][1][0];
			else dp[i][type[i]][0]+=dp[i-1][1][1]+dp[i-1][1][0];
			if(type[i]==2)dp[i][type[i]][1]+=dp[i-1][2][0];
			else dp[i][type[i]][0]+=dp[i-1][2][1]+dp[i-1][2][0];
			if(type[i]==3)dp[i][type[i]][1]+=dp[i-1][3][0];
			else dp[i][type[i]][0]+=dp[i-1][3][1]+dp[i-1][3][0];
		}else{
			for(int j=1;j<=3;j++){
				dp[i][j][0]=dp[i-1][0][0];
				for(int k=1;k<=3;k++){
					if(k!=j){
						dp[i][j][0]+=dp[i-1][k][0]+dp[i-1][k][1];
					}else dp[i][j][1]+=dp[i-1][k][0];
				}
			}
		}
		dp[i][1][0]%=MOD;
		dp[i][1][1]%=MOD;
		dp[i][2][0]%=MOD;
		dp[i][2][1]%=MOD;
		dp[i][3][0]%=MOD;
		dp[i][3][1]%=MOD;
	}
	printf("%d\n",(dp[a][1][0]+dp[a][1][1]+dp[a][2][0]+dp[a][2][1]+dp[a][3][0]+dp[a][3][1])%MOD);
}

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

int f(int, int, int);
int N;
int yotei[100];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int k, date;
    std::cin >> N >> k;
    for (int i = 0; i < k; i++) {
        std::cin >> date;
        std::cin >> yotei[date];
    }

    std::cout << f(0, 0, 0) << "\n";
    return 0;
}

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

struct day
{
  int kind[4];
  int order;
  int sum;
};

int n, k;
int a[100], b[100];
day dp[101];

int main()
{
  cin >> n >> k;
  for(int i = 0; i < k; i++)
    cin >> a[i] >> b[i];

  for(int i = 0; i < k; i++)
    dp[a[i]].order = b[i];

  //day 1
  if(dp[1].order)
    dp[1].sum = dp[1].kind[dp[1].order] = 1;
  else
    for(int i = 1; i <= 3; i++)
      dp[1].sum += dp[1].kind[i] = 1;

  //day 2
  if(dp[2].order)
    dp[2].sum = dp[2].kind[dp[2].order] = dp[1].sum;
  else
    for(int i = 1; i <= 3; i++)
      dp[2].sum += dp[2].kind[i] = dp[1].sum;

  //day 3
  for(int i = 3; i <= n; i++){
    if(dp[i].order){
      if(!dp[i - 1].kind[dp[i].order])
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum;
      else
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum - dp[i - 1].kind[dp[i].order] + dp[i - 2].sum - dp[i - 2].kind[dp[i].order];
    }
    else{
      for(int j = 1; j <= 3; j++){
	
	if(!dp[i - 1].kind[j])
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum;
	else
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum - dp[i - 1].kind[j] + dp[i - 2].sum - dp[i - 2].kind[j];
      }

      dp[i].sum %= 100000;
      dp[i].sum += 100000;
    }
  }

  cout << dp[n].sum % 10000 << endl;
  return 0;
}