Problem:
C: Digital Clock / デジタル時計
物語
あいずにゃんは最近，風邪を引いてしまった．あまりのだるさにベットから出られない．辛そうにしている姿もまたかわいい．
しかし暇で暇で仕方がないあいずにゃんは，枕下にあるデジタル時計で遊ぶ方法を考えついた．下の図のようなデジタル時計の光っている棒の本数を毎秒毎秒，ただひたすらに数えるのである．
何時間かこの遊びを続けた頃，あいずにゃんは時間が違っていても光っている棒の本数が等しい場合があることに気づいた．光っている棒の本数が等しい時間が何通りあるのか気になったあいずにゃんは，看病中のあなたに数えてくれるようお願いしてきた．
ベッドから出られないあいずにゃんのために，あなたはプログラムを書いて求めることにした．
問題
年月日，および時分秒を表示する上図のようなデジタル時計がある．光っている棒の本数がちょうど
N
本になる年月日時分秒が何通りあるか答えよ．ただし，デジタル時計は一部壊れているため，絶対光らない棒が何箇所かある．光らない棒によって同じ表示に見える場合でも，表示しようとした年月日時分秒が異なる場合は別に数えることに注意せよ．
各数字の光る箇所は次の図に示す通りである．
デジタル時計は西暦を0詰め4桁（0000年〜9999年），月，日，時，分，秒をそれぞれ0詰め2桁で表示する．
月は1日から始まり，4, 6, 9, 11月は30日まで，1, 3, 5, 7, 8, 10, 12月は31日までである．2月は通常28日までだが，閏年には29日までとなる．ここで閏年とは，次のような年である．
西暦が400で割り切れる年は閏年である．
西暦が400で割り切れないが，100で割り切れる年は閏年ではない．
西暦が100で割り切れないが，4で割り切れる年は閏年である．
西暦が4で割り切れない年は閏年ではない．
時間は0時から23時まで，分は0分から59分まで，秒は0秒から59秒までである．閏秒に関しては考えなくてよい．
入力形式
1行目に光っている棒の本数
N
(
0 ≤ N ≤ 98
) が与えられる．
2行目に壊れて光らない箇所の個数
K
(
0 ≤ K ≤ 98
) が与えられ，続いて
K
行に壊れている箇所の情報が与えられる．
K
行のうち
i
行目には，
i
番目の壊れている棒の桁
p_i
(
0 ≤ p_i ≤ 13
) と位置
q_i
(
0 ≤ q_i ≤ 6
) が空白区切りで与えられる．
桁とは，次の図のようなデジタル時計の各数字に割り当てられたIDであり，上位の数字から順に0から13までを割り当てた番号のことである．
また，棒の位置とは次の図のような各数字中における棒のIDであり，上の棒から順に0から6までの数字を割り当てた番号のことである．
出力形式
光っている棒の本数がちょうど
N
本になる年月日時分秒の総数を1行に出力せよ．
入力例1
28
0
出力例1
1
1111年11月11日11時11分11秒の1通りである．
入力例2
28
1
2 0
出力例2
2
1171年11月11日11時11分11秒 と 1111年11月11日11時11分11秒 の2通りである．
入力例3
98
1
3 0
出力例3
0
入力例4
60
1
3 0
出力例4
13362470370

Submitted solutions:

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

vector<int> bar[10] = {{0, 1, 2, 4, 5, 6}, {2, 5},    {0, 2, 3, 4, 6},       {0, 2, 3, 5, 6},   {1, 2, 3, 5}, {0, 1, 3, 5, 6},
                       {0, 1, 3, 4, 5, 6}, {0, 2, 5}, {0, 1, 2, 3, 4, 5, 6}, {0, 1, 2, 3, 5, 6}};

int digit[10];
int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    for (int i = 0; i < 10; ++i) {
        for (int j : bar[i]) {
            digit[i] |= (1 << j);
        }
    }
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> u(14);
    for (int i = 0; i < k; ++i) {
        int p, q;
        cin >> p >> q;
        u[p] |= (1 << q);
    }
    map<int, ll> mp1, mp2;
    for (int i = 0; i <= 9999; ++i) {
        auto is_uruu = [&](int y) -> bool { return (y % 400 == 0) or (y % 100 and y % 4 == 0); };
        for (int j = 1; j <= 12; ++j) {
            for (int l = 1; l <= day[j - 1] + (is_uruu(i) and j == 2); ++l) {
                string y = to_string(i);
                while (y.size() < 4) {
                    y = "0" + y;
                }
                string m = to_string(j);
                if (m.size() == 1) m = "0" + m;
                string d = to_string(l);
                if (d.size() == 1) d = "0" + d;
                string g = y + m + d;

                int cnt = 0;
                for (int p = 0; p < g.size(); ++p) {
                    int uo = digit[g[p] - '0'] - (digit[g[p] - '0'] & u[p]);
                    cnt += __builtin_popcount(uo);
                }
                mp1[cnt] += 1;
            }
        }
    }
    for (int i = 0; i < 24; ++i) {
        for (int j = 0; j < 60; ++j) {
            for (int l = 0; l < 60; ++l) {
                string y = to_string(i);
                if (y.size() == 1) y = "0" + y;
                string m = to_string(j);
                if (m.size() == 1) m = "0" + m;
                string d = to_string(l);
                if (d.size() == 1) d = "0" + d;
                string g = y + m + d;
                int cnt = 0;
                for (int p = 0; p < g.size(); ++p) {
                    int uo = digit[g[p] - '0'] - (digit[g[p] - '0'] & u[p + 8]);
                    cnt += __builtin_popcount(uo);
                }
                mp2[cnt] += 1;
            }
        }
    }
    ll res = 0;
    for (int i = 0; i <= n; ++i) {
        res += mp1[i] * mp2[n - i];
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 740
memory_kb: 3572
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

bool uruu(int year){
    if(year % 4 == 0) {
        if (year % 100 == 0) {
            return year % 400 == 0;
        }else{
            return true;
        }
    }else{
        return false;
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> month = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    vector<vector<int>> G(14, vector<int> (10));
    vector<int> t = {6,2,5,5,4,5,6,3,7,6};
    for(int i=0; i<14; i++){
        G[i] = t;
    }
    vector<vector<int>> _(7);
    _[0] = {0,2,3,5,6,7,8,9};
    _[1] = {0,4,5,6,8,9};
    _[2] = {0,1,2,3,4,7,8,9};
    _[3] = {2,3,4,5,6,8,9};
    _[4] = {0,2,6,8};
    _[5] = {0,1,3,4,5,6,7,8,9};
    _[6] = {0,2,3,5,6,8,9};
    int N;
    cin >> N;
    int K;
    cin >> K;
    set<pair<int,int>> se;
    for(int i=0; i<K; i++){
        int a,b;
        cin >> a >> b;
        if(se.count(P(a,b))) continue;
        for(int j=0; j<_[b].size(); j++){
            G[a][_[b][j]]--;
        }
        se.insert(P(a,b));
    }
    vector<ll> time_num(50,0);
    for(int i=0; i<24; i++){
        for(int j=0; j<60; j++){
            for(int k=0; k<60; k++){                
                int sum = 0;
                sum += G[8][i/10];
                sum += G[9][i%10];
                sum += G[10][j/10];
                sum += G[11][j%10];
                sum += G[12][k/10];
                sum += G[13][k%10];
                time_num[sum]++;
            }
        }
    }
    // for(int i=0; i<50; i++){
    //     cout << time_num[i] << "\n";
    // }
    ll ans = 0;
    for(int y=0; y<10000; y++){
        for(int m=1; m<=12; m++){
            bool uru = (m==2 and uruu(y));
            for(int d=1; d<=month[m]+uru; d++){
                int sum = 0;
                int year = y;
                sum += G[0][year/1000];
                year %= 1000;
                sum += G[1][year/100];
                year %= 100;
                sum += G[2][year/10];
                sum += G[3][year%10];
                sum += G[4][m/10];
                sum += G[5][m%10];
                sum += G[6][d/10];
                sum += G[7][d%10];
                if(sum > N) continue;
                if(N-sum > 50) continue;
                ans += time_num[N-sum];
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3224
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

bool uruu(int year){
 if (year % 4 == 0) {
   if (year % 100 == 0) {
     if (year % 400 == 0) {
         return true;
     } else {
         return false;
     }
   } else {
       return true;
   }
 } else {
     return false;
 }   
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> month = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    vector<vector<int>> G(14, vector<int> (10));
    vector<int> t = {6,2,5,5,4,5,6,3,7,6};
    for(int i=0; i<14; i++){
        G[i] = t;
    }
    vector<vector<int>> _(7);
    _[0] = {0,2,3,5,6,7,8,9};
    _[1] = {0,4,5,6,8,9};
    _[2] = {0,1,2,3,4,7,8,9};
    _[3] = {2,3,4,5,6,8,9};
    _[4] = {0,2,6,8};
    _[5] = {0,1,3,4,5,6,7,8,9};
    _[6] = {0,2,3,5,6,8,9};
    int N;
    cin >> N;
    int K;
    cin >> K;
    set<pair<int,int>> se;
    for(int i=0; i<K; i++){
        int a,b;
        cin >> a >> b;
        if(se.count(P(a,b))) continue;
        for(int j=0; j<_[b].size(); j++){
            G[a][_[b][j]]--;
        }
        se.insert(P(a,b));
    }
    vector<ll> time_num(50,0);
    for(int i=0; i<24; i++){
        for(int j=0; j<60; j++){
            for(int k=0; k<60; k++){                
                int sum = 0;
                sum += G[8][i/10];
                sum += G[9][i%10];
                sum += G[10][j/10];
                sum += G[11][j%10];
                sum += G[12][k/10];
                sum += G[13][k%10];
                time_num[sum]++;
            }
        }
    }
    // for(int i=0; i<50; i++){
    //     cout << time_num[i] << "\n";
    // }
    ll ans = 0;
    for(int y=0; y<10000; y++){
        for(int m=1; m<=12; m++){
            bool uru = (m==2 and uruu(y));
            for(int d=1; d<=month[m]+uru; d++){
                int sum = 0;
                int year = y;
                sum += G[0][year/1000];
                year %= 1000;
                sum += G[1][year/100];
                year %= 100;
                sum += G[2][year/10];
                sum += G[3][year%10];
                sum += G[4][m/10];
                sum += G[5][m%10];
                sum += G[6][d/10];
                sum += G[7][d%10];
                if(sum > N) continue;
                if(N-sum > 50) continue;
                ans += time_num[N-sum];
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3224
final_rank: 7

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}
int bit[10][7] = {{0,1,2,4,5,6},
                      {2,5},
                      {0,2,3,4,6},
                      {0,2,3,5,6},
                      {1,2,3,5},
                      {0,1,3,5,6},
                      {0,1,3,4,5,6},
                      {0,2,5},
                      {0,1,2,3,4,5,6},
                      {0,1,2,3,5,6}};
/*int bit[10][7]={
                {1,1,1,0,1,1,1},//0
                {0,0,1,0,0,1,0},//1
                {1,0,1,1,1,0,1},//2
                {1,0,1,1,0,1,1},//3
                {0,1,1,1,0,1,0},//4
                {1,1,0,1,0,1,1},//5
                {1,1,0,1,1,1,1},//6
                {1,0,1,0,0,1,0},//7
                {1,1,1,1,1,1,1},//8
                {1,1,1,1,0,1,1},//9
              };*/
int num_use[10]={6,2,5,5,4,5,6,3,7,6};
int shine_num[14][10];
bool flag[14][7];
long long int num_hms[43];
long long int num_ymd[57];

int main(){
  int n,K;
  cin >> n >> K;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=6; j++) flag[i][j]=true;
  }
  int digit,pos;
  for(int i=0; i<K; i++){
    cin >> digit >> pos;
    flag[digit][pos] = false;
  }
  int count;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=9; j++){
      count=0;
      for(int k=0; k<num_use[j]; k++){
        if(flag[i][bit[j][k]]) count++;
      }
      shine_num[i][j] = count;
    }
  }
  //時分秒
  int work[14];
  for(int i=0; i<=42; i++) num_hms[i] = 0;
  for(int h=0; h<=23; h++){
    for(int m=0; m<=59; m++){
      for(int s=0; s<=59; s++){
        work[8] = shine_num[8][h/10];
        work[9] = shine_num[9][h%10];
        work[10] = shine_num[10][m/10];
        work[11] = shine_num[11][m%10];
        work[12] = shine_num[12][s/10];
        work[13] = shine_num[13][s%10];
        int tmp_sum=0;
        for(int i=8; i<=13; i++) tmp_sum += work[i];
        num_hms[tmp_sum]++;
      }
    }
  }
  //年月日
  for(int i=0; i<=56; i++) num_ymd[i]=0;
  for(int y=0; y<=9999; y++){
    for(int m=1; m<=12; m++){
      int last;
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      else if(m==2) last = check(y);
      else last = 31;
      for(int d=1; d<=last; d++){
        work[0] = shine_num[0][y/1000];
        work[1] = shine_num[1][y/100%10];
        work[2] = shine_num[2][y/10%10];
        work[3] = shine_num[3][y%10];
        work[4] = shine_num[4][m/10];
        work[5] = shine_num[5][m%10];
        work[6] = shine_num[6][d/10];
        work[7] = shine_num[7][d%10];
        int tmp_sum = 0;
        for(int i=0; i<=7; i++) tmp_sum += work[i];
        num_ymd[tmp_sum]++;
      }
    }
  }
  long long int ans = 0;
  for(int i=0; i<=min(42,n); i++){
    if(n-i > 56) continue;
    ans += num_hms[i]*num_ymd[n-i];
  }
  cout << ans << endl;
  return 0;
}



/*
int bit(int p, int n){
  int sum=0;
    for(int i=0; i<7; i++){
    if(flag[p][i]==false) sum += bit[n][i];
    }
    return sum;
}
vector<long long int> a;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}

int search(int res,int n){
  int left = 0;
  int right = a.size();
  int mid;
  int x = n-res;
  while(left<right){
    mid = (left + right)/2;
    if(x==a[mid]) return a[mid];
    if(x>a[mid]) left = mid+1;
    else if(x<a[mid]) right = mid;
  }
  return 0;
}
int main(){
  int n,k;
  cin >> n >> k;
  int p,q;
  int A[14][10]
  int bit[14][10]={};
  for(int i=0; i<k; i++) cin >> p >> q;
  rep(i,14) rep(j,10) A[i][j]=1;
  A[p][q]=0;

  for(int i=0;i<14;i++){
    bit[i][0]=A[i][0]+A[i][1]+A[i][2]+A[i][4]+A[i][5]+A[i][6];
    bit[i][1]=A[i][2]+A[i][5];
    bit[i][2]=A[i][0]+A[i][2]+A[i][3]+A[i][4]+A[i][6];
    bit[i][3]=A[i][0]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
    bit[i][4]=A[i][1]+A[i][2]+A[i][3]+A[i][5];
    bit[i][5]=A[i][0]+A[i][1]+A[i][3]+A[i][5]+A[i][6];
    bit[i][6]=A[i][0]+A[i][1]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][7]=A[i][0]+A[i][2]+A[i][5];
    bit[i][8]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][9]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
  }

  for(int i=1; i<=24; i++){
    for(int j=1; j<=59; j++){
      for(int k=1; k<=59; k++){
          int sum=0;
          sum+=bit[8][i/10];
          sum+=bit[9][i%10];
          sum+=bit[10][j/10];
          sum+=bit[11][j%10];
          sum+=bit[12][k/10];
          sum+=bit[13][k%10];
          a.push_back(sum);
        }
      }
  }
  int y,m,d,count=0,last;
  for(y=1; y<=9999; y++){
    int sum = 0;
    sum+=bit[0][y/1000];
    sum+=bit[1][y/100%10];
    sum+=bit[2][y/10%10];
    sum+=bit[3][y%10];

    for(m=1; m<=12; m++){
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      if(m==2) last = check(y);
      else last = 31;
      sum+=bit[4][m/10];
      sum+=bit[5][m%10];

      for(d=1; d<=last; d++){
        sum+=bit[6][d/10];
        sum+=bit[7][d%10];
        if(sum+search(sum,n)==n) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
*/
accuracy: 1
time_ms: 20
memory_kb: 3096
final_rank: 3

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}
int bit[10][7] = {{0,1,2,4,5,6},
                      {2,5},
                      {0,2,3,4,6},
                      {0,2,3,5,6},
                      {1,2,3,5},
                      {0,1,3,5,6},
                      {0,1,3,4,5,6},
                      {0,2,5},
                      {0,1,2,3,4,5,6},
                      {0,1,2,3,5,6}};
/*int bit[10][7]={
                {1,1,1,0,1,1,1},//0
                {0,0,1,0,0,1,0},//1
                {1,0,1,1,1,0,1},//2
                {1,0,1,1,0,1,1},//3
                {0,1,1,1,0,1,0},//4
                {1,1,0,1,0,1,1},//5
                {1,1,0,1,1,1,1},//6
                {1,0,1,0,0,1,0},//7
                {1,1,1,1,1,1,1},//8
                {1,1,1,1,0,1,1},//9
              };*/
int num_use[10]={6,2,5,5,4,5,6,3,7,6};
int shine_num[14][10];
bool flag[14][7];
long long int num_hms[43];
long long int num_ymd[57];

int main(){
  int n,K;
  cin >> n >> K;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=6; j++) flag[i][j]=true;
  }
  int digit,pos;
  for(int i=0; i<K; i++){
    cin >> digit >> pos;
    flag[digit][pos] = false;
  }
  int count;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=9; j++){
      count=0;
      for(int k=0; k<num_use[j]; k++){
        if(flag[i][bit[j][k]]) count++;
      }
      shine_num[i][j] = count;
    }
  }
  //時分秒
  int work[14];
  for(int i=0; i<=42; i++) num_hms[i] = 0;
  for(int h=0; h<=23; h++){
    for(int m=0; m<=59; m++){
      for(int s=0; s<=59; s++){
        work[8] = shine_num[8][h/10];
        work[9] = shine_num[9][h%10];
        work[10] = shine_num[10][m/10];
        work[11] = shine_num[11][m%10];
        work[12] = shine_num[12][s/10];
        work[13] = shine_num[13][s%10];
        int tmp_sum=0;
        for(int i=8; i<=13; i++) tmp_sum += work[i];
        num_hms[tmp_sum]++;
      }
    }
  }
  //年月日
  for(int i=0; i<=56; i++) num_ymd[i]=0;
  for(int y=0; y<=9999; y++){
    for(int m=1; m<=12; m++){
      int last;
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      else if(m==2) last = check(y);
      else last = 31;
      for(int d=1; d<=last; d++){
        work[0] = shine_num[0][y/1000];
        work[1] = shine_num[1][y/100%10];
        work[2] = shine_num[2][y/10%10];
        work[3] = shine_num[3][y%10];
        work[4] = shine_num[4][m/10];
        work[5] = shine_num[5][m%10];
        work[6] = shine_num[6][d/10];
        work[7] = shine_num[7][d%10];
        int tmp_sum = 0;
        for(int i=0; i<=7; i++) tmp_sum += work[i];
        num_ymd[tmp_sum]++;
      }
    }
  }
  long long int ans = 0;
  for(int i=0; i<=min(42,n); i++){
    if(n-i > 56) continue;
    ans += num_hms[i]*num_ymd[n-i];
  }
  cout << ans << endl;
  return 0;
}


/*
int bit(int p, int n){
  int sum=0;
    for(int i=0; i<7; i++){
    if(flag[p][i]==false) sum += bit[n][i];
    }
    return sum;
}
vector<long long int> a;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}

int search(int res,int n){
  int left = 0;
  int right = a.size();
  int mid;
  int x = n-res;
  while(left<right){
    mid = (left + right)/2;
    if(x==a[mid]) return a[mid];
    if(x>a[mid]) left = mid+1;
    else if(x<a[mid]) right = mid;
  }
  return 0;
}
int main(){
  int n,k;
  cin >> n >> k;
  int p,q;
  int A[14][10]
  int bit[14][10]={};
  for(int i=0; i<k; i++) cin >> p >> q;
  rep(i,14) rep(j,10) A[i][j]=1;
  A[p][q]=0;

  for(int i=0;i<14;i++){
    bit[i][0]=A[i][0]+A[i][1]+A[i][2]+A[i][4]+A[i][5]+A[i][6];
    bit[i][1]=A[i][2]+A[i][5];
    bit[i][2]=A[i][0]+A[i][2]+A[i][3]+A[i][4]+A[i][6];
    bit[i][3]=A[i][0]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
    bit[i][4]=A[i][1]+A[i][2]+A[i][3]+A[i][5];
    bit[i][5]=A[i][0]+A[i][1]+A[i][3]+A[i][5]+A[i][6];
    bit[i][6]=A[i][0]+A[i][1]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][7]=A[i][0]+A[i][2]+A[i][5];
    bit[i][8]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][9]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
  }

  for(int i=1; i<=24; i++){
    for(int j=1; j<=59; j++){
      for(int k=1; k<=59; k++){
          int sum=0;
          sum+=bit[8][i/10];
          sum+=bit[9][i%10];
          sum+=bit[10][j/10];
          sum+=bit[11][j%10];
          sum+=bit[12][k/10];
          sum+=bit[13][k%10];
          a.push_back(sum);
        }
      }
  }
  int y,m,d,count=0,last;
  for(y=1; y<=9999; y++){
    int sum = 0;
    sum+=bit[0][y/1000];
    sum+=bit[1][y/100%10];
    sum+=bit[2][y/10%10];
    sum+=bit[3][y%10];

    for(m=1; m<=12; m++){
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      if(m==2) last = check(y);
      else last = 31;
      sum+=bit[4][m/10];
      sum+=bit[5][m%10];

      for(d=1; d<=last; d++){
        sum+=bit[6][d/10];
        sum+=bit[7][d%10];
        if(sum+search(sum,n)==n) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
*/
accuracy: 1
time_ms: 20
memory_kb: 3096
final_rank: 3

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}
int bit[10][7] = {{0,1,2,4,5,6},
                      {2,5},
                      {0,2,3,4,6},
                      {0,2,3,5,6},
                      {1,2,3,5},
                      {0,1,3,5,6},
                      {0,1,3,4,5,6},
                      {0,2,5},
                      {0,1,2,3,4,5,6},
                      {0,1,2,3,5,6}};
/*int bit[10][7]={
                {1,1,1,0,1,1,1},//0
                {0,0,1,0,0,1,0},//1
                {1,0,1,1,1,0,1},//2
                {1,0,1,1,0,1,1},//3
                {0,1,1,1,0,1,0},//4
                {1,1,0,1,0,1,1},//5
                {1,1,0,1,1,1,1},//6
                {1,0,1,0,0,1,0},//7
                {1,1,1,1,1,1,1},//8
                {1,1,1,1,0,1,1},//9
              };*/
int num_use[10]={6,2,5,5,4,5,6,3,7,6};
int shine_num[14][10];
bool flag[14][7];
int num_hms[43];
int num_ymd[57];

int main(){
  int n,K;
  cin >> n >> K;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=6; j++) flag[i][j]=true;
  }
  int digit,pos;
  for(int i=0; i<K; i++){
    cin >> digit >> pos;
    flag[digit][pos] = false;
  }
  int count;
  for(int i=0; i<=13; i++){
    for(int j=0; j<=9; j++){
      count=0;
      for(int k=0; k<num_use[j]; k++){
        if(flag[i][bit[j][k]]) count++;
      }
      shine_num[i][j] = count;
    }
  }
  //時分秒
  int work[14];
  for(int i=0; i<=42; i++) num_hms[i] = 0;
  for(int h=0; h<=23; h++){
    for(int m=0; m<=59; m++){
      for(int s=0; s<=59; s++){
        work[8] = shine_num[8][h/10];
        work[9] = shine_num[9][h%10];
        work[10] = shine_num[10][m/10];
        work[11] = shine_num[11][m%10];
        work[12] = shine_num[12][s/10];
        work[13] = shine_num[13][s%10];
        int tmp_sum=0;
        for(int i=8; i<=13; i++) tmp_sum += work[i];
        num_hms[tmp_sum]++;
      }
    }
  }
  //年月日
  for(int i=0; i<=56; i++) num_ymd[i]=0;
  for(int y=0; y<=9999; y++){
    for(int m=1; m<=12; m++){
      int last;
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      else if(m==2) last = check(y);
      else last = 31;
      for(int d=1; d<=last; d++){
        work[0] = shine_num[0][y/1000];
        work[1] = shine_num[1][y/100%10];
        work[2] = shine_num[2][y/10%10];
        work[3] = shine_num[3][y%10];
        work[4] = shine_num[4][m/10];
        work[5] = shine_num[5][m%10];
        work[6] = shine_num[6][d/10];
        work[7] = shine_num[7][d%10];
        int tmp_sum = 0;
        for(int i=0; i<=7; i++) tmp_sum += work[i];
        num_ymd[tmp_sum]++;
      }
    }
  }
  long long int ans = 0;
  for(int i=0; i<=min(42,n); i++){
    if(n-i > 56) continue;
    ans += num_hms[i]*num_ymd[n-i];
  }
  cout << ans << endl;
  return 0;
}












/*
int bit(int p, int n){
  int sum=0;
    for(int i=0; i<7; i++){
    if(flag[p][i]==false) sum += bit[n][i];
    }
    return sum;
}
vector<long long int> a;
int check(int year){
  if(year % 400 == 0) return 29;
  if(year % 400 != 0 && year % 100 == 0) return 28;
  if(year % 100 !=0 && year % 4 == 0) return 29;
  if(year % 4 != 0) return 28;
  return 0;
}

int search(int res,int n){
  int left = 0;
  int right = a.size();
  int mid;
  int x = n-res;
  while(left<right){
    mid = (left + right)/2;
    if(x==a[mid]) return a[mid];
    if(x>a[mid]) left = mid+1;
    else if(x<a[mid]) right = mid;
  }
  return 0;
}
int main(){
  int n,k;
  cin >> n >> k;
  int p,q;
  int A[14][10]
  int bit[14][10]={};
  for(int i=0; i<k; i++) cin >> p >> q;
  rep(i,14) rep(j,10) A[i][j]=1;
  A[p][q]=0;

  for(int i=0;i<14;i++){
    bit[i][0]=A[i][0]+A[i][1]+A[i][2]+A[i][4]+A[i][5]+A[i][6];
    bit[i][1]=A[i][2]+A[i][5];
    bit[i][2]=A[i][0]+A[i][2]+A[i][3]+A[i][4]+A[i][6];
    bit[i][3]=A[i][0]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
    bit[i][4]=A[i][1]+A[i][2]+A[i][3]+A[i][5];
    bit[i][5]=A[i][0]+A[i][1]+A[i][3]+A[i][5]+A[i][6];
    bit[i][6]=A[i][0]+A[i][1]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][7]=A[i][0]+A[i][2]+A[i][5];
    bit[i][8]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
    bit[i][9]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
  }

  for(int i=1; i<=24; i++){
    for(int j=1; j<=59; j++){
      for(int k=1; k<=59; k++){
          int sum=0;
          sum+=bit[8][i/10];
          sum+=bit[9][i%10];
          sum+=bit[10][j/10];
          sum+=bit[11][j%10];
          sum+=bit[12][k/10];
          sum+=bit[13][k%10];
          a.push_back(sum);
        }
      }
  }
  int y,m,d,count=0,last;
  for(y=1; y<=9999; y++){
    int sum = 0;
    sum+=bit[0][y/1000];
    sum+=bit[1][y/100%10];
    sum+=bit[2][y/10%10];
    sum+=bit[3][y%10];

    for(m=1; m<=12; m++){
      if(m==4 || m==6 || m==9 || m==11) last = 30;
      if(m==2) last = check(y);
      else last = 31;
      sum+=bit[4][m/10];
      sum+=bit[5][m%10];

      for(d=1; d<=last; d++){
        sum+=bit[6][d/10];
        sum+=bit[7][d%10];
        if(sum+search(sum,n)==n) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
*/
accuracy: 0.5344827586206896
time_ms: 30
memory_kb: 3092
final_rank: 19

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

int main(){
  long long int N, K, temp[2][110], uru = 0, xx, sum, ans = 0, y = 0;
  long long int hon, bou[16][10][10], temp3[100] = {};
  long long  int temp2[10][10] =
    {{1, 1, 1, 0, 1, 1, 1},//0
     {0, 0, 1, 0, 0, 1, 0},//1
     {1, 0, 1, 1, 1, 0, 1},
     {1, 0, 1, 1, 0, 1, 1},//3
     {0, 1, 1, 1, 0, 1, 0},
     {1, 1, 0, 1, 0, 1, 1},//5

     {1, 1, 0, 1, 1, 1, 1},
     {1, 0, 1, 0, 0, 1, 0},//7
     {1, 1, 1, 1, 1, 1, 1},
     {1, 1, 1, 1, 0, 1, 1},
    };

  int sugi[20][16] = {};
  int a, b;

  for(int i = 0; i <= 13; i++){
    for(int j = 0; j <= 9; j++){
      for(int k = 0; k <= 6; k++){
	bou[i][j][k] = temp2[j][k];
      }
    }
  }

  cin>>N;

  cin>>K;

  for(int i = 0; i < K; i++){
    cin>>a>>b;
    for(int k = 0; k <= 9; k++){
      bou[a][k][b] = 0;
    }
  }
  for(int i = 0; i<= 13; i++){
    for(int j = 0; j <= 9; j++){
      sum = 0;
       for(int k = 0; k <= 6; k++){
	 sum += bou[i][j][k];//cout<<bou[i][j][k]<<endl;
	
       }//cout<<sum<<endl<<endl;
        sugi[i][j] = sum;
    }
  }
  
  for(int l = 0; l <= 23; l++){
    for(int m = 0; m <= 59; m++){
      for(int n = 0; n <= 59; n++){
	temp3[sugi[8][l/10] +sugi[9][l%10] + sugi[10][m/10] + sugi[11][m%10] + sugi[12][n/10] + sugi[13][n%10]]++;
      }
    }
  }
  
  

  for(int i = 0; i < 10000; i++){
    uru = 0;
    if(i%4 == 0 && i%100 != 0) uru = 1;
    if(i%400 == 0) uru = 1;
    
    for(int j = 1; j <= 12; j++){
      
      if(j == 2){
	if(uru == 1) xx = 29;
	else xx = 28;
      }else if(j == 4 || j == 6 || j == 9 || j == 11){
	xx = 30;
      } else xx = 31;
      
      for(int k = 1; k <= xx; k++){
	hon = sugi[0][i/1000] + sugi[1][(i/100)%10] + sugi[2][(i/10)%10] + sugi[3][i%10]
	  + sugi[4][j/10] + sugi[5][j%10] + sugi[6][k/10] + sugi[7][k%10];
		
	if(hon <= N){
	  ans += temp3[N - hon];
	}
	       
      }
    }
  }

  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3120
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
vector<int> v[20];

int pin[10][7]={
  {1,1,1,0,1,1,1},
  {0,0,1,0,0,1,0},
  {1,0,1,1,1,0,1},
  {1,0,1,1,0,1,1},
  {0,1,1,1,0,1,0},
  {1,1,0,1,0,1,1},
  {1,1,0,1,1,1,1},
  {1,0,1,0,0,1,0},
  {1,1,1,1,1,1,1},
  {1,1,1,1,0,1,1},
};

int pic[10]={6,2,5,5,4,5,6,3,7,6};

int he(int x,int p){
  int ans=pic[x];
  for(int i=0;i<v[p].size();i++){
    ans-=pin[x][v[p][i]];
  }
  return ans;
}

signed main(){
  cin>>n>>k;
  for(int i=0;i<k;i++){
    int p,q;
    cin>>p>>q;
    v[p].push_back(q);
  }
  int time[50]={};
  for(int i=0;i<=23;i++){
    for(int j=0;j<=59;j++){
      for(int k=0;k<=59;k++){
	int cnt=0;
	cnt+=he(i/10,8);
	cnt+=he(i%10,9);
	cnt+=he(j/10,10);
	cnt+=he(j%10,11);
	cnt+=he(k/10,12);
	cnt+=he(k%10,13);
	time[cnt]++;
      }
    }
  }
  int ans=0;
  for(int i=0;i<10000;i++){
    int f=0;
    if(i%400==0)f=1;
    if(i%100&&i%4==0)f=1;
    for(int j=1;j<=12;j++){
      for(int k=1;k<=31;k++){
	if(j==4||j==6||j==9||j==11)
	  if(k==31)break;
	if(j==2){
	  if(!f&&k==29)break;
	  if(k==30)break;
	}
	int cnt=0;
	int ti=i,tj=j,tk=k;
	for(int x=0;x<4;x++){
	  if(x<2){
	    cnt+=he(tj%10,5-x);
	    cnt+=he(tk%10,7-x);
	  }
	  cnt+=he(ti%10,3-x);
	  ti/=10,tj/=10,tk/=10;
	}
	int tmp=n-cnt;
	if(0<=tmp&&tmp<50){
	  ans+=time[tmp];
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3168
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
vector<int> v[20];

int pin[10][7]={
  {1,1,1,0,1,1,1},
  {0,0,1,0,0,1,0},
  {1,0,1,1,1,0,1},
  {1,0,1,1,0,1,1},
  {0,1,1,1,0,1,0},
  {1,1,0,1,0,1,1},
  {1,1,0,1,1,1,1},
  {1,0,1,0,0,1,0},
  {1,1,1,1,1,1,1},
  {1,1,1,1,0,1,1},
};

int pic[10]={6,2,5,5,4,5,6,3,7,6};

int he(int x,int p){
  int ans=pic[x];
  for(int i=0;i<v[p].size();i++){
    ans-=pin[x][v[p][i]];
  }
  return ans;
}

signed main(){
  cin>>n>>k;
  for(int i=0;i<k;i++){
    int p,q;
    cin>>p>>q;
    v[p].push_back(q);
  }
  int time[50]={};
  for(int i=0;i<=23;i++){
    for(int j=0;j<=59;j++){
      for(int k=0;k<=59;k++){
	int cnt=0;
	cnt+=he(i/10,8);
	cnt+=he(i%10,9);
	cnt+=he(j/10,10);
	cnt+=he(j%10,11);
	cnt+=he(k/10,12);
	cnt+=he(k%10,13);
	time[cnt]++;
      }
    }
  }
  int ans=0;
  for(int i=0;i<10000;i++){
    int f=0;
    if(i%400==0)f=1;
    if(i%100&&i%4==0)f=1;
    for(int j=1;j<=12;j++){
      for(int k=1;k<=31;k++){
	if(j==4||j==6||j==9||j==11)
	  if(k==31)break;
	if(j==2){
	  if(!f&&k==29)break;
	  if(k==30)break;
	}
	int cnt=0;
	int ti=i,tj=j,tk=k;
	for(int x=0;x<4;x++){
	  if(x<2){
	    cnt+=he(tj%10,5-x);
	    cnt+=he(tk%10,7-x);
	  }
	  cnt+=he(ti%10,3-x);
	  ti/=10,tj/=10,tk/=10;
	}
	int tmp=n-cnt;
	if(0<tmp&&tmp<50){
	  ans+=time[tmp];
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.9310344827586207
time_ms: 150
memory_kb: 3164
final_rank: 18

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int num_use[10] = {6,2,5,5,4,5,6,3,7,6};
int use_pos[10][7] = {{0,1,2,4,5,6},{2,5},{0,2,3,4,6},{0,2,3,5,6},{1,2,3,5},{0,1,3,5,6},{0,1,3,4,5,6},{0,2,5},{0,1,2,3,4,5,6},{0,1,2,3,5,6}};
int shine_num[14][10];
int num_day[13] = {0,31,0,31,30,31,30,31,31,30,31,30,31};
ll num_HMS[43],num_YMD[57];
bool is_ok[14][7];

bool is_leap_year(int year){

	if(year%400 == 0)return true;
	if(year%100 == 0)return false;
	return year%4 == 0;
}

int main(){

	int N;
	scanf("%d",&N);

	int K;
	scanf("%d",&K);

	for(int i = 0; i <= 13; i++){
		for(int k = 0; k <= 6; k++)is_ok[i][k] = true; //各桁の各棒が光るか
	}

	int digit,pos;
	for(int loop = 0; loop < K; loop++){
		scanf("%d %d",&digit,&pos);
		is_ok[digit][pos] = false;
	}

	//各桁の各数字が、実際に何文字棒を光らせるか計算
	int count;
	for(int i = 0; i <= 13; i++){
		for(int k = 0; k <= 9; k++){
			count = 0;
			for(int a = 0; a < num_use[k]; a++){
				if(is_ok[i][use_pos[k][a]]){
					count++;
				}
			}
			shine_num[i][k] = count;
		}
	}

	int work[14];
	int tmp_sum;

	for(int i = 0; i <= 42; i++)num_HMS[i] = 0;

	//時分秒を全探索
	for(int hour = 0; hour <= 23; hour++){

		work[8] = shine_num[8][hour/10];
		work[9] = shine_num[9][hour%10];

		for(int minute = 0; minute <= 59; minute++){

			work[10] = shine_num[10][minute/10];
			work[11] = shine_num[11][minute%10];

			for(int second = 0; second <= 59; second++){

				work[12] = shine_num[12][second/10];
				work[13] = shine_num[13][second%10];

				tmp_sum = 0;

				for(int a = 8; a <= 13; a++)tmp_sum += work[a];

				num_HMS[tmp_sum]++;
			}
		}
	}

	int tmp,limit;
	for(int i = 0; i <= 56; i++)num_YMD[i] = 0;

	//年月日を全探索
	for(int year = 0; year <= 9999; year++){

		tmp = year;

		work[0] = shine_num[0][tmp/1000];
		tmp %= 1000;
		work[1] = shine_num[1][tmp/100];
		tmp %= 100;
		work[2] = shine_num[2][tmp/10];
		work[3] = shine_num[3][tmp%10];

		for(int month = 1; month <= 12; month++){

			work[4] = shine_num[4][month/10];
			work[5] = shine_num[5][month%10];

			if(month != 2){
				limit = num_day[month];
			}else{
				if(is_leap_year(year)){
					limit = 29;
				}else{
					limit = 28;
				}
			}

			for(int day = 1; day <= limit; day++){

				work[6] = shine_num[6][day/10];
				work[7] = shine_num[7][day%10];

				tmp_sum = 0;

				for(int a = 0; a <= 7; a++)tmp_sum += work[a];

				num_YMD[tmp_sum]++;
			}
		}
	}

	ll ans = 0;
	for(int i = 0; i <= min(42,N); i++){
		if(N-i > 56)continue;
		ans += num_HMS[i]*num_YMD[N-i];
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3200
final_rank: 6

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int num_use[10] = {6,2,5,5,4,5,6,3,7,6};
int use_pos[10][7] = {{0,1,2,4,5,6},{2,5},{0,2,3,4,6},{0,2,3,5,6},{1,2,3,5},{0,1,3,5,6},{0,1,3,4,5,6},{0,2,5},{0,1,2,3,4,5,6},{0,1,2,3,5,6}};
int shine_num[14][10];
int num_day[13] = {0,31,0,31,30,31,30,31,31,30,31,30,31};
ll num_HMS[43],num_YMD[57];
bool is_ok[14][7];

bool is_leap_year(int year){

	if(year%400 == 0)return true;
	if(year%100 == 0)return false;
	return year%4 == 0;
}

int main(){

	int N;
	scanf("%d",&N);

	int K;
	scanf("%d",&K);

	for(int i = 0; i <= 13; i++){
		for(int k = 0; k <= 6; k++)is_ok[i][k] = true; //各桁の各棒が光るか
	}

	int digit,pos;
	for(int loop = 0; loop < K; loop++){
		scanf("%d %d",&digit,&pos);
		is_ok[digit][pos] = false;
	}

	//各桁の各数字が、実際に何文字棒を光らせるか計算
	int count;
	for(int i = 0; i <= 13; i++){
		for(int k = 0; k <= 9; k++){
			count = 0;
			for(int a = 0; a < num_use[k]; a++){
				if(is_ok[i][use_pos[k][a]]){
					count++;
				}
			}
			shine_num[i][k] = count;
		}
	}

	int work[14];
	int tmp_sum;

	for(int i = 0; i <= 42; i++)num_HMS[i] = 0;

	//時分秒を全探索
	for(int hour = 0; hour <= 23; hour++){

		work[8] = shine_num[8][hour/10];
		work[9] = shine_num[9][hour%10];

		for(int minute = 0; minute <= 59; minute++){

			work[10] = shine_num[10][minute/10];
			work[11] = shine_num[11][minute%10];

			for(int second = 0; second <= 59; second++){

				work[12] = shine_num[12][second/10];
				work[13] = shine_num[13][second%10];

				tmp_sum = 0;

				for(int a = 8; a <= 13; a++)tmp_sum += work[a];

				num_HMS[tmp_sum]++;
			}
		}
	}

	int tmp,limit;
	for(int i = 0; i <= 56; i++)num_YMD[i] = 0;

	//年月日を全探索
	for(int year = 0; year <= 9999; year++){

		tmp = year;

		work[0] = shine_num[0][tmp/1000];
		tmp %= 1000;
		work[1] = shine_num[1][tmp/100];
		tmp %= 100;
		work[2] = shine_num[2][tmp/10];
		work[3] = shine_num[3][tmp%10];

		for(int month = 1; month <= 12; month++){

			work[4] = shine_num[4][month/10];
			work[5] = shine_num[5][month%10];

			if(month != 2){
				limit = num_day[month];
			}else{
				if(is_leap_year(year)){
					limit = 29;
				}else{
					limit = 28;
				}
			}

			for(int day = 1; day <= limit; day++){

				work[6] = shine_num[6][day/10];
				work[7] = shine_num[7][day%10];

				tmp_sum = 0;

				for(int a = 0; a <= 7; a++)tmp_sum += work[a];

				num_YMD[tmp_sum]++;
			}
		}
	}

	ll ans = 0;
	for(int i = 0; i <= min(42,N); i++){
		ans += num_HMS[i]*num_YMD[N-i];
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 0.034482758620689655
time_ms: 20
memory_kb: 3176
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define int long long
using namespace std;

int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool isLeap(int year){return (year%4 == 0 && (year%100 != 0 || year%400 == 0));}

int n, b[14][7], C[100], num[10]={6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int check(char c, int idx){
  
  int d=c-'0', res=0;
  
  if(b[idx][0]){
    
    if(d==0||d==2||d==3||d==5||d==6||d==7||d==8||d==9) res++;
      
  }
  if(b[idx][1]){

    if(d==0||d==4||d==5||d==6||d==8||d==9) res++;
    
  }
  if(b[idx][2]){
    
    if(d==0||d==1||d==2||d==3||d==4||d==7||d==8||d==9) res++;
    
  }
  if(b[idx][3]){
    
    if(d==2||d==3||d==4||d==5||d==6||d==8||d==9) res++;
    
  }
  if(b[idx][4]){
    
    if(d==0||d==2||d==6||d==8) res++;
    
  }
  if(b[idx][5]){
    
    if(d==0||d==1||d==3||d==4||d==5||d==6||d==7||d==8||d==9) res++;
    
  }
  if(b[idx][6]){
    
    if(d==0||d==2||d==3||d==5||d==6||d==8||d==9) res++;
    
  }

  return res;
}

int cal(int h, int m, int s){
  
  string H=to_string(h);
  string M=to_string(m);
  string S=to_string(s);
  
  if(H.size()==1) H='0'+H;
  if(M.size()==1) M='0'+M;
  if(S.size()==1) S='0'+S;
  
  int res=0;
  
  for(int i=0;i<2;i++) res+=num[H[i]-'0'];
  for(int i=0;i<2;i++) res+=num[M[i]-'0'];
  for(int i=0;i<2;i++) res+=num[S[i]-'0'];
  
  res-=check(H[0], 8);
  res-=check(H[1], 9);
  res-=check(M[0], 10);
  res-=check(M[1], 11);
  res-=check(S[0], 12);
  res-=check(S[1], 13);
  
  return res;
}

int cal2(int y, int m, int d){
  
  string Y=to_string(y);
  string M=to_string(m);
  string D=to_string(d);
  
  while(Y.size()!=4) Y='0'+Y;
  if(M.size()==1) M='0'+M;
  if(D.size()==1) D='0'+D;
  
  int res=0;
  
  for(int i=0;i<4;i++) res+=num[Y[i]-'0'];
  for(int i=0;i<2;i++) res+=num[M[i]-'0'];
  for(int i=0;i<2;i++) res+=num[D[i]-'0'];
  
  res-=check(Y[0], 0);
  res-=check(Y[1], 1);
  res-=check(Y[2], 2);
  res-=check(Y[3], 3);
  res-=check(M[0], 4);
  res-=check(M[1], 5);
  res-=check(D[0], 6);
  res-=check(D[1], 7);
  
  return res;
}

void solve(){
  
  for(int h=0;h<=23;h++)
    
    for(int m=0;m<=59;m++)
      
      for(int s=0;s<=59;s++){
	
	int cnt = cal(h, m, s);
	
	C[cnt]++;
	
      }
  
  int ans = 0;
  
  int y=0, m=1, d=1;
  
  while(y<=9999){
    
    while(m<=12){
      
      while(d<=days[m]+(m==2&&isLeap(y))){
	
	int cnt = cal2(y, m, d);
	
	if(n-cnt>=0) ans+=C[n-cnt];
	
	d++;
      }
      
      d=1;
      
      m++;
    }
    
    m=1;
    
    y++;    
  }
  
  cout<<ans<<endl;
}

signed main(){
  
  cin>>n;
  
  int k;
  cin>>k;
  
  for(int i=0;i<k;i++){
    int p, q;
    cin>>p>>q;
    b[p][q]=1;
  }
  
  solve();
  
  return 0;
}
accuracy: 1
time_ms: 1930
memory_kb: 3308
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

using int64 = long long;


int digit[] = {
    0b1110111,
    0b0010010,
    0b1011101,
    0b1011011,
    0b0111010,
    0b1101011,
    0b1101111,
    0b1010010,
    0b1111111,
    0b1111011
};

int main() {

  for(int i = 0; i < 10; i++) {
    int rev = 0;
    for(int j = 0; j < 7; j++) {
      rev |= ((digit[i] >> (6 - j) & 1)) << j;
    }
    digit[i] = rev;
  }


  int N, K;
  int mask[1333] = {};
  for(int i = 0; i < 1333; i++) {
    mask[i] = (1 << 8) - 1;
  }


  cin >> N >> K;
  for(int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    mask[13 - p] ^= 1 << q;
  }

  const int m[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

  int latte[100] = {}, malta[100] = {};

  for(int i = 0; i < 10000; i++) {
    for(int j = 1; j <= 12; j++) {
      int x = m[j - 1];
      if(j == 2 && (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0))) {
        ++x;
      }
      for(int k = 1; k <= x; k++) {
        int bit = i * 10000 + j * 100 + k, add = 0;
        for(int l = 6; l <= 13; l++) {
          add += __builtin_popcount(digit[bit % 10] & mask[l]);
          bit /= 10;
        }
        latte[add]++;
      }
    }
  }

  for(int i = 0; i < 24; i++) {
    for(int j = 0; j < 60; j++) {
      for(int k = 0; k < 60; k++) {
        int bit = i * 10000 + j * 100 + k, add = 0;
        for(int l = 0; l <= 5; l++) {
          add += __builtin_popcount(digit[bit % 10] & mask[l]);
          bit /= 10;
        }
        malta[add]++;
      }
    }
  }

  int64 ret = 0;
  for(int i = 0; i <= N; i++) {
    ret += 1LL * latte[i] * malta[N - i];
  }
  cout << ret << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 3140
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;

bool d[14][7];
Int a[10][7];


Int cal(Int p,Int n){
  Int res=0;
  for(Int i=0;i<7;i++)
    if(!d[p][i])res+=a[n][i];
  return res;
}

Int uru(Int n){
  if(n%400==0)return 1;
  if(n%100==0)return 0;
  if(n%4==0)return 1;
  return 0;
}

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,K,p,q;

  a[0][0]=1;
  a[0][1]=1;
  a[0][2]=1;
  a[0][3]=0;
  a[0][4]=1;
  a[0][5]=1;
  a[0][6]=1;

  a[1][0]=0;
  a[1][1]=0;
  a[1][2]=1;
  a[1][3]=0;
  a[1][4]=0;
  a[1][5]=1;
  a[1][6]=0;

  a[2][0]=1;
  a[2][1]=0;
  a[2][2]=1;
  a[2][3]=1;
  a[2][4]=1;
  a[2][5]=0;
  a[2][6]=1;


  a[3][0]=1;
  a[3][1]=0;
  a[3][2]=1;
  a[3][3]=1;
  a[3][4]=0;
  a[3][5]=1;
  a[3][6]=1;

  
  a[4][0]=0;
  a[4][1]=1;
  a[4][2]=1;
  a[4][3]=1;
  a[4][4]=0;
  a[4][5]=1;
  a[4][6]=0;


  a[5][0]=1;
  a[5][1]=1;
  a[5][2]=0;
  a[5][3]=1;
  a[5][4]=0;
  a[5][5]=1;
  a[5][6]=1;

  a[6][0]=1;
  a[6][1]=1;
  a[6][2]=0;
  a[6][3]=1;
  a[6][4]=1;
  a[6][5]=1;
  a[6][6]=1;

  a[7][0]=1;
  a[7][1]=0;
  a[7][2]=1;
  a[7][3]=0;
  a[7][4]=0;
  a[7][5]=1;
  a[7][6]=0;

  a[8][0]=1;
  a[8][1]=1;
  a[8][2]=1;
  a[8][3]=1;
  a[8][4]=1;
  a[8][5]=1;
  a[8][6]=1;

  a[9][0]=1;
  a[9][1]=1;
  a[9][2]=1;
  a[9][3]=1;
  a[9][4]=0;
  a[9][5]=1;
  a[9][6]=1;
  

  cin>>n>>K;
  while(K--)cin>>p>>q,d[p][q]=1;

  Int c[13],cnt[100][2]={};
  c[4]=c[6]=c[9]=c[11]=30;
  c[1]=c[3]=c[5]=c[7]=c[8]=c[10]=c[12]=31;
  c[2]=28;
  
  for(Int i=1;i<=12;i++)
    for(Int j=1;j<=c[i];j++)
      for(Int k=0;k<=23;k++)
	for(Int l=0;l<=59;l++)
	  for(Int m=0;m<=59;m++){
	    Int res=0;
	    res+=cal(4,i/10);
	    res+=cal(5,i%10);
	    res+=cal(6,j/10);
	    res+=cal(7,j%10);
	    res+=cal(8,k/10);
	    res+=cal(9,k%10);
	    res+=cal(10,l/10);
	    res+=cal(11,l%10);
	    res+=cal(12,m/10);
	    res+=cal(13,m%10);
	    cnt[res][0]++;
	  }

  c[2]=29;
  for(Int i=1;i<=12;i++)
    for(Int j=1;j<=c[i];j++)
      for(Int k=0;k<=23;k++)
	for(Int l=0;l<=59;l++)
	  for(Int m=0;m<=59;m++){
	    Int res=0;
	    res+=cal(4,i/10);
	    res+=cal(5,i%10);
	    res+=cal(6,j/10);
	    res+=cal(7,j%10);
	    res+=cal(8,k/10);
	    res+=cal(9,k%10);
	    res+=cal(10,l/10);
	    res+=cal(11,l%10);
	    res+=cal(12,m/10);
	    res+=cal(13,m%10);
	    cnt[res][1]++;
	  }
  Int ans=0;
  for(Int i=0;i<=9999;i++){
    Int res =0;
    res+=cal(0,i/1000);
    res+=cal(1,i/100%10);
    res+=cal(2,i/10%10);
    res+=cal(3,i%10);
    if(res<=n)ans+=cnt[n-res][uru(i)];
  }
  cout<<ans<<endl;  
  return 0;
}
accuracy: 1
time_ms: 3580
memory_kb: 3196
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int ND[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int f(int n, vector<bool> m) {
	int r = 0;
	switch (n) {
	case 0:return m[0] + m[1] + m[2] + m[4] + m[5] + m[6];
	case 1:return m[2] + m[5];
	case 2:return m[0] + m[2] + m[3] + m[4] + m[6];
	case 3:return m[0] + m[2] + m[3] + m[5] + m[6];
	case 4:return m[1] + m[2] + m[3] + m[5];
	case 5:return m[0] + m[1] + m[3] + m[5] + m[6];
	case 6:return m[0] + m[1] + m[3] + m[4] + m[5] + m[6];
	case 7:return m[0] + m[2] + m[5];
	case 8:return m[0] + m[1] + m[2] + m[3] + m[4] + m[5] + m[6];
	case 9:return m[0] + m[1] + m[2] + m[3] + m[5] + m[6];
	default: throw 1;
	}
	return r;
}
int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<bool>> PQ(14, vector<bool>(7, true));
	for (int i = 0; i < K; ++i) {
		int p, q;
		cin >> p >> q;
		PQ[p][q] = false;
	}
	map<int, int> yy;
	map<int, int> y229;
	for (int y = 0; y < 10000; ++y) {
		int n = f(y / 1000, PQ[0]) + f(y / 100 % 10, PQ[1]) + f(y / 10 % 10, PQ[2]) + f(y % 10, PQ[3]);
		++yy[n];
		if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
			++y229[n];
		}
	}
	map<int, int> ymd;
	for (int m = 1; m <= 12; ++m) {
		int nd = ND[m-1];
		for (int d = 1; d <= nd; ++d) {
			int n = f(m / 10, PQ[4]) + f(m % 10, PQ[5]) + f(d / 10, PQ[6]) + f(d % 10, PQ[7]);
			if (m == 2 && d == 29) {
				for (auto p : y229) {
					ymd[p.first + n] += p.second;
				}
			} else {
				for (auto p : yy) {
					ymd[p.first + n] += p.second;
				}
			}
		}
	}
	map<int, int> hms;
	for (int h = 0; h < 24; ++h) for (int m = 0; m < 60; ++m) for (int s = 0; s < 60; ++s) {
		++hms[f(h / 10, PQ[8]) + f(h % 10, PQ[9]) + f(m / 10, PQ[10]) + f(m % 10, PQ[11]) +
			f(s / 10, PQ[12]) + f(s % 10, PQ[13])];
	}
	long long r = 0;
	for (auto p : ymd) {
		int m = N - p.first;
		if (hms.count(m)) {
			r += (long long)p.second * hms[m];
		}
	}
	cout << r << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3132
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool digit[10][7]={
  {1,1,1,0,1,1,1},
  {0,0,1,0,0,1,0},
  {1,0,1,1,1,0,1},
  {1,0,1,1,0,1,1},
  {0,1,1,1,0,1,0},
  {1,1,0,1,0,1,1},
  {1,1,0,1,1,1,1},
  {1,0,1,0,0,1,0},
  {1,1,1,1,1,1,1},
  {1,1,1,1,0,1,1}
};
bool use[14][7];
ll n,k,a,b,cnt1[57],cnt2[43];
int D[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool check(int y){
  if(!(y%400)||((y%100)&&!(y%4)))return true;
  return false;
}

void Cnt1(int y,int m,int d){
  ll c=0,idx=3;
  for(int i=0;i<4;i++){
    for(int j=0;j<7;j++)
      if(digit[y%10][j]&&!use[idx][j])c++;
    y/=10;
    idx--;
  }
  idx=5;
  for(int i=0;i<2;i++){
    for(int j=0;j<7;j++)
      if(digit[m%10][j]&&!use[idx][j])c++;
    m/=10;
    idx--;
  }
  idx=7;
  for(int i=0;i<2;i++){
    for(int j=0;j<7;j++)
      if(digit[d%10][j]&&!use[idx][j])c++;
    d/=10;
    idx--;
  }
  cnt1[c]++;
}

void Cal(){
  int y=0,m=1,d=1;
  while(y<=9999){
    while(m<=12){
      while(d<=D[m]+(m==2&&check(y))){
	Cnt1(y,m,d);
	d++;
      }
      d=1;
      m++;
    }
    m=1;
    y++;
  }
}

void Cnt2(int h,int m,int s){
  ll c=0,idx=9;
  for(int i=0;i<2;i++){
    for(int j=0;j<7;j++)
      if(digit[h%10][j]&&!use[idx][j])c++;
    h/=10;
    idx--;
  }
  idx=11;
  for(int i=0;i<2;i++){
    for(int j=0;j<7;j++)
      if(digit[m%10][j]&&!use[idx][j])c++;
    m/=10;
    idx--;
  }
  idx=13;
  for(int i=0;i<2;i++){
    for(int j=0;j<7;j++)
      if(digit[s%10][j]&&!use[idx][j])c++;
    s/=10;
    idx--;
  }
  cnt2[c]++;
}

void Cal2(){
  int h=0,m=0,s=0;
  while(h<=23){
    while(m<=59){
      while(s<=59){
	Cnt2(h,m,s);
	s++;
      }
      s=0;
      m++;
    }
    m=0;
    h++;
  }
}

int main(){
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>a>>b;
    use[a][b]=1;
  }
  Cal();
  Cal2();
  ll ans=0;
  for(int i=0;i<=56;i++){
    for(int j=0;j<=42;j++)
      if(i+j==n)ans+=cnt1[i]*cnt2[j];
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 380
memory_kb: 3088
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
ll n,K[14][10],A[1000];
ll M[13];

void mkK(vector<int>zero,int idx){
  int cnt[10][7]={};
  cnt[0][0]=cnt[0][1]=cnt[0][2]=cnt[0][4]=cnt[0][5]=cnt[0][6]=1;
  cnt[1][2]=cnt[1][5]=1;
  cnt[2][0]=cnt[2][2]=cnt[2][3]=cnt[2][4]=cnt[2][6]=1;
  cnt[3][0]=cnt[3][2]=cnt[3][3]=cnt[3][5]=cnt[3][6]=1;
  cnt[4][1]=cnt[4][2]=cnt[4][3]=cnt[4][5]=1;
  cnt[5][0]=cnt[5][1]=cnt[5][3]=cnt[5][5]=cnt[5][6]=1;
  cnt[6][0]=cnt[6][1]=cnt[6][3]=cnt[6][4]=cnt[6][5]=cnt[6][6]=1;
  cnt[7][0]=cnt[7][2]=cnt[7][5]=1;
  cnt[8][0]=cnt[8][1]=cnt[8][2]=cnt[8][3]=cnt[8][4]=cnt[8][5]=cnt[8][6]=1;
  cnt[9][0]=cnt[9][1]=cnt[9][2]=cnt[9][3]=cnt[9][5]=cnt[9][6]=1;

  for(int i=0;i<10;i++)
    for(int j=0;j<=6;j++) cnt[i][j]*=zero[j];
  
  for(int i=0;i<10;i++)
    for(int j=0;j<=6;j++)K[idx][i]+=cnt[i][j];
}


int count(int num,int idx,int t){
  vector<int> B(t,0);
  while(num) B[--t]=num%10,num/=10;

  int res=0;  
  for(int i=0;i<(int)B.size();i++)res+=K[idx+i][B[i]];
  return res;
}

void mkA(){
  for(int i=0;i<24;i++)//h
    for(int j=0;j<60;j++)//m
      for(int k=0;k<60;k++)//s
	A[count(i,8,2)+count(j,10,2)+count(k,12,2)]++;
}

void mkM(){
  M[1] = M[3] = M[5] =M[7] =M[8] = M[10] = M[12] = 31;
  M[4] = M[6] = M[9] =M[11] = 30;
  M[2] = 28;
}

int uru(int n,int k){
  if(k!=2) return 0;
  if(n%400==0) return 1;
  if(n%100==0) return 0;
  if(n%4==0) return 1;
  return 0;
}


ll solve(){
  ll res=0;
  for(int i=0;i<10000;i++) //y
    for(int j=1;j<=12;j++) //m
      for(int k=1;k<=M[j]+uru(i,j);k++){//d
	ll sum=count(i,0,4)+count(j,4,2)+count(k,6,2);
	if(n-sum>=0)res+=A[n-sum];
      }
  return res;
}


main(){
  int m;
  cin>>n>>m;
  vector<int>A[14];
  for(int i=0;i<14;i++) A[i].resize(10,1);
  for(int i=0,id,pos;i<m;i++)cin>>id>>pos,A[id][pos] = 0;
  for(int i=0;i<14;i++) mkK(A[i],i);
  mkA();
  mkM();
  cout<<solve()<<endl;
  
}
accuracy: 1
time_ms: 460
memory_kb: 3160
final_rank: 13

code_snippet: #include <iostream>
using namespace std;
const int bit[10] = { 119, 36, 93, 109, 46, 107, 123, 37, 127, 111, };
inline bool is_leap(int yy) {
	return yy % 400 == 0 || (yy % 4 == 0 && yy % 100 != 0);
}
inline int day(int yy, int mm) {
	if (mm == 2) return is_leap(yy) ? 29 : 28;
	if (mm == 4 || mm == 6 || mm == 9 || mm == 11) return 30;
	return 31;
}
int N, K, a, b, dame[14][7], c1[100], c2[100];
inline int count(int x, int n) {
	int ret = 0;
	for (int i = 0; i < 7; i++) {
		if (((bit[n] >> i) & 1) && !dame[x][i]) ret++;
	}
	return ret;
}
int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) cin >> a >> b, dame[a][b] = 1;
	for (int i = 0; i <= 9999; i++) {
		for (int j = 1; j <= 12; j++) {
			int r = day(i, j);
			for (int k = 1; k <= r; k++) {
				int z[8] = { i / 1000, i / 100 % 10, i / 10 % 10, i % 10, j / 10, j % 10, k / 10, k % 10 };
				int res = 0;
				for (int l = 0; l < 8; l++) res += count(l, z[l]);
				c1[res]++;
			}
		}
	}
	for (int i = 0; i <= 23; i++) {
		for (int j = 0; j <= 59; j++) {
			for (int k = 0; k <= 59; k++) {
				int z[6] = { i / 10, i % 10, j / 10, j % 10, k / 10, k % 10 };
				int res = 0;
				for (int l = 0; l < 6; l++) res += count(l + 8, z[l]);
				c2[res]++;
			}
		}
	}
	long long ret = 0;
	for (int i = 0; i <= N; i++) ret += 1LL * c1[i] * c2[N - i];
	cout << ret << endl;
	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 3092
final_rank: 11

code_snippet: #include <iostream>
#include <cstdio>
using namespace std;

//Const
const int seg[10] = {0x77, 0x24, 0x5d, 0x6d, 0x2e, 0x6b, 0x7b, 0x25, 0x7f, 0x6f};

//Input
int N;
int K;
int p[99], q[99];

//Data
int dispFlag[14][10];
int dispNum[14][10];

//Data2
int hms[99];

//function
bool isUruu( int year ){
	if( year % 400 == 0 || (year % 4 == 0 && year % 100 != 0) )
		return true;
	return false;
}

bool nextDay( int &day, int &month, int &year ){
	int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if( isUruu(year) )
		days[2]++;
	day++;
	if( day > days[month] ){
		day = 1;
		month++;
	}
	if( month > 12 ){
		month = 1;
		year++;
	}
	if( year >= 10000 )
		return false;
	return true;
}

void solve(){
	int day = 1, month = 1, year = 0;
	long long ans = 0;
	do{
		int x = 0;
		x += dispNum[0][year/1000];
		x += dispNum[1][(year%1000)/100];
		x += dispNum[2][(year%100)/10];
		x += dispNum[3][year%10];
		x += dispNum[4][month/10];
		x += dispNum[5][month%10];
		x += dispNum[6][day/10];
		x += dispNum[7][day%10];
		if( x <= N ){
			ans += hms[N - x];
		}
	}while( nextDay(day, month, year) );
	cout << ans << endl;
}

void preSolve(){
	for( int i = 0; i <= N; i++ ){
		hms[i] = 0;
	}
	for( int i = 0; i < 86400; i++ ){
		int h = i / 3600;
		int m = (i % 3600) / 60;
		int s = i % 60;
		int x = 0;
		x += dispNum[8][h/10];
		x += dispNum[9][h%10];
		x += dispNum[10][m/10];
		x += dispNum[11][m%10];
		x += dispNum[12][s/10];
		x += dispNum[13][s%10];
		hms[x]++;
	}
}

void input(){
	int i, j;
	
	for( i = 0; i < 14; i++ ){
		for( j = 0; j < 10; j++ ){
			dispFlag[i][j] = seg[j];
		}
	}
	
	cin >> N >> K;
	for( i = 0; i < K; i++ ){
		cin >> p[i] >> q[i];
		for( j = 0; j < 10; j++ ){
			dispFlag[p[i]][j] &= ~(1 << q[i]);
		}
	}
	
	for( i = 0; i < 14; i++ ){
		for( j = 0; j < 10; j++ ){
			dispNum[i][j] = 0;
			for( int k = 7; k >= 0; k-- ){
				if( (dispFlag[i][j] >> k) & 1 )
					dispNum[i][j]++;
			}
			//printf("%4d", dispNum[i][j]);
		}
		//printf("\n");
	}
}

int main()
{
	//cout << "C";
	input();
	//cout << "K";
	preSolve();
	//cout << "P";
	solve();
	//cout << "??????";
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 1164
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<tuple>
using namespace std;

#define YEAR 10000
#define MAX_IDS 100
#define MAX_DIGIT 14
#define MAX_ID 7
#define HOUR 24
#define MINUTE 60
#define SECOND 60
#define MONTH 12
#define MAX_NUM 10
#define DAY_ID 2
#define MONTH_ID 2
#define YEAR_ID 4
#define ELSE_ID 2
#define TYPES 4

int day1[MONTH + 1] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int day2[MONTH + 1] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };

vector<tuple<int, int, int>>days;

bool Uruu(int a) {
	if (a % 400 == 0) { return true; }
	if (a % 100 == 0) { return false; }
	if (a % 4 == 0) { return true; }
	return false;
}

void calc() {
	for (int i = 0; i < YEAR; i++) {
		if (Uruu(i) == true) {
			for (int j = 1; j <= MONTH; j++) {
				for (int k = 1; k <= day2[j]; k++) {
					days.push_back(make_tuple(i, j, k));
				}
			}
		}
		else {
			for (int j = 1; j <= MONTH; j++) {
				for (int k = 1; k <= day1[j]; k++) {
					days.push_back(make_tuple(i, j, k));
				}
			}
		}
	}
}

int y[MAX_NUM][MAX_ID] =
{
	{1,1,1,0,1,1,1},
	{0,0,1,0,0,1,0},
	{1,0,1,1,1,0,1},
	{1,0,1,1,0,1,1},
	{0,1,1,1,0,1,0},
	{1,1,0,1,0,1,1},
	{1,1,0,1,1,1,1},
	{1,0,1,0,0,1,0},
	{1,1,1,1,1,1,1},
	{1,1,1,1,0,1,1}
};
int z[MAX_DIGIT][MAX_NUM][MAX_ID];
int power[5] = { 1,10,100,1000,10000 };

int calc2(int a, int b, int c) {
	int p[DAY_ID+MONTH_ID+YEAR_ID];
	for (int i = 0; i < YEAR_ID; i++) {
		p[YEAR_ID - 1 - i] = (a / power[i]) % MAX_NUM;
	}
	for (int i = 0; i < MONTH_ID; i++) {
		p[YEAR_ID + MONTH_ID - 1 - i] = (b / power[i]) % MAX_NUM;
	}
	for (int i = 0; i < DAY_ID; i++) {
		p[YEAR_ID + MONTH_ID + DAY_ID - 1 - i] = (c / power[i]) % MAX_NUM;
	}
	int sum = 0;
	for (int i = 0; i < DAY_ID + MONTH_ID + YEAR_ID; i++) {
		for (int j = 0; j < MAX_ID; j++) {
			sum += z[i][p[i]][j];
		}
	}
	return sum;
}

int calc3(int a, int b) {
	int r[ELSE_ID];
	r[0] = a / 10; r[1] = a % 10;
	int sum = 0;
	for (int i = 0; i < ELSE_ID; i++) {
		for (int j = 0; j < MAX_ID; j++) {
			sum += z[i + b][r[i]][j];
		}
	}
	return sum;
}

int n, q, a, b;
int x[MAX_DIGIT][MAX_ID];
long long dp[MAX_IDS][TYPES];
long long h[MAX_IDS], m[MAX_IDS], s[MAX_IDS];

int main() {
	calc();
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		x[a][b] = 1;
	}
	for (int i = 0; i < MAX_DIGIT; i++) {
		for (int j = 0; j < MAX_ID; j++) {
			if (x[i][j] == 1) {
				for (int k = 0; k < MAX_NUM; k++) {
					z[i][k][j] = 0;
				}
			}
			else {
				for (int k = 0; k < MAX_NUM; k++) {
					z[i][k][j] = y[k][j];
				}
			}
		}
	}
	for (int i = 0; i < days.size(); i++) {
		int a1 = get<0>(days[i]);
		int a2 = get<1>(days[i]);
		int a3 = get<2>(days[i]);
		dp[calc2(a1, a2, a3)][0]++;
	}
	for (int i = 0; i < HOUR; i++) {
		h[calc3(i, 8)]++;
	}
	for (int i = 0; i < MINUTE; i++) {
		m[calc3(i, 10)]++;
	}
	for (int i = 0; i < SECOND; i++) {
		s[calc3(i, 12)]++;
	}
	for (int i = 0; i < MAX_IDS; i++) {
		if (dp[i][0] >= 1) {
			for (int j = 0; j <= MAX_ID*ELSE_ID; j++) {
				dp[i + j][1] += dp[i][0] * h[j];
			}
		}
	}
	for (int i = 0; i < MAX_IDS; i++) {
		if (dp[i][1] >= 1) {
			for (int j = 0; j <= MAX_ID*ELSE_ID; j++) {
				dp[i + j][2] += dp[i][1] * m[j];
			}
		}
	}
	for (int i = 0; i < MAX_IDS; i++) {
		if (dp[i][2] >= 1) {
			for (int j = 0; j <= MAX_ID*ELSE_ID; j++) {
				dp[i + j][3] += dp[i][2] * s[j];
			}
		}
	}
	cout << dp[n][3] << endl;
	return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 51888
final_rank: 17