alexjercan/bugnet huggingface dataset:
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll b;
int main() {
  // freopen("slyar.in", "r", stdin);
  // freopen("slyar.out", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> b;
  while (b != 0) {
    b = 2 * b;
    int flag = 0;
    for (int n = sqrt(b); n >= 1; n--) {
      if (b % n == 0) {
        if ((b / n - n + 1) / 2 > 0 && (b / n - n + 1) % 2 == 0) {
          cout << (b / n - n + 1) / 2 << " " << n << endl;
          break;
        }
      }
    }
    cin >> b;
  }
  // fclose(stdin);
  // fclose(stdout);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
double b;
int main() {
  while (1) {
    scanf("%lf", &b);
    if (b == 0)
      break;
    int i = 1;
    while (1) {
      double x = (double)(i) * (double)(i);
      x = x + 8 * b;
      double y = sqrt(x);
      if (y - (int)y == 0) {
        int s = y;
        s = s - i;
        if (s > 0 && s % 2 == 0) {
          printf("%d %d\\n", (i + 1) / 2, s / 2);
          break;
        }
      }
      i += 2;
    }
  }
  return (0);
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int b;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    cin >> b;
    if (b == 0)
      return 0;
    int m = 1e9, n = 0;
    for (int i = 1; i * i <= 2 * b; ++i) {
      if (2 * b % i != 0)
        continue;
      int c = 2 * b / i;
      if (i % 2 != c % 2) {
        int s = (i + c - 1) / 2;
        int t = (i - c + 1) / 2;
        if (s > t)
          swap(s, t);
        if (s > 0 && s < m) {
          m = s;
          n = t;
        }
        s = (c + i - 1) / 2;
        t = (c - i + 1) / 2;
        if (s > t)
          swap(s, t);
        if (s > 0 && s < m) {
          m = s;
          n = t;
        }
      }
    }
    cout << m << " " << n - m + 1 << "\\n";
  }
}


Error: TLE

Fixed submission:

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

vector<long long> a;
long long b;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  a.resize(1e7);
  a[0] = 0;
  for (int i = 1; i < 1e7; ++i)
    a[i] = a[i - 1] + i;
  while (1) {
    cin >> b;
    if (b == 0)
      return 0;
    for (int i = 1; i < 1e7; ++i) {
      long long c = b + a[i - 1];
      int t = lower_bound(a.begin(), a.end(), c) - a.begin();
      if (a[t] == c) {
        cout << i << " " << t - i + 1 << "\\n";
        break;
      }
    }
  }
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1626
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int main(void) {
  ll b;
  while (cin >> b, b) {
    int n, m;
    for (ll i = 0;; ++i) {
      ll t = b - (i + 1) * i / 2;

      if (t <= 0)
        break;
      if (t % (i + 1) != 0)
        continue;
      n = t / (i + 1);
      m = i + 1;
    }
    cout << n << " " << m << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2706
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int main(void) {
  ll b;
  while (cin >> b, b) {
    bool f = false;
    pair<ll, ll> ans(0, 0);
    ll left = 0, right = 1;
    ll len = 1;
    for (left = 0; left < 20000000; ++left) {
      while (right < 20000000 &&
             right * (right + 1) / 2 - left * (left + 1) / 2 < b) {
        right++;
      }
      len = right - left;
      if (right * (right + 1) / 2 - left * (left + 1) / 2 == b) {
        if (len > ans.second) {
          ans.first = left + 1;
          ans.second = len;
        }
      }
      if (right == left)
        right++;
    }
    cout << ans.first << " " << ans.second << endl;
  }
  return 0;
}
Problem p01111 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main() {
  while (1) {
    double b;
    cin >> b;
    if (b == 0)
      break;
    double nmaxd = 2 * sqrt(b);
    double nmax = ceil(nmaxd);
    ll fir, num;
    for (ll n = nmax; n > 0; n--) {
      double f = (2 * b / n - n + 1) / 2;
      if (f - floor(f) == 0 && f > 0) {
        fir = f;
        num = n;
        break;
      }
    }
    cout << fir << ' ' << num << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long n, s[50000000];
int main() {
  for (long long i = 0; i < 50000000; i++)
    s[i] = i * (i + 1);
  cin >> n;
  while (n != 0) {
    for (long long j = sqrt(2 * n); j <= n; j++) {
      long long i = (j + 1) * j - 2 * n;
      long long sum = sqrt(i);
      if (s[sum] == i) {
        printf("%lld %lld\\n", sum + 1, j - sum);
        break;
      }
    }
    scanf("%lld", &n);
  }
  return 0;
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long n;
int main() {
  while (scanf("%lld", &n) && n != 0) {
    for (long long s = 50000; s >= 1; s--) {
      long long i = 2 * n + s - s * s;
      i /= 2 * s;
      if (s * (s - 1 + 2 * i) == 2 * n && s > 0 && i > 0) {
        printf("%lld %lld\\n", i, s);
        break;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long n;
int main() {
  while (scanf("%lld", &n) && n != 0) {
    for (long long m = sqrt(n * 2); m <= 2 * n; m++)
      if ((2 * n) % m == 0) {
        long long s = 2 * n / m;
        if (m % 2 == 0 && s % 2 == 0)
          ;
        else if (m > s) {
          printf("%d %d\\n", m / 2 - (s - 1) / 2, s);
          break;
        }
      }
  }
  return 0;
}
Problem p01111 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

vector<int> divisorEnum(long long n) {
  vector<int> ret;
  for (int i = 1; i <= sqrt(n) + 1; i++) {
    if (n % i == 0) {
      ret.push_back(i);
    }
  }
  sort(ret.begin(), ret.end(), greater<int>());
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    long long n;
    cin >> n;
    if (!n)
      break;

    vector<int> divisor = divisorEnum(2 * n);
    for (auto i : divisor) {
      int res = (n - i * (i - 1) / 2);
      if (res % i == 0 && res > 0) {
        cout << res / i << " " << i << endl;
        break;
      }
    }
  }
}


Error: MLE

Fixed submission:

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

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

  vector<long long> ruisekiBill(500000000, 0);
  ruisekiBill[0] = 0;
  for (int i = 1; i < ruisekiBill.size(); i++) {
    ruisekiBill[i] = i + ruisekiBill[i - 1];
  }

  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    auto Iter1 = lower_bound(ruisekiBill.begin(), ruisekiBill.end(), n);
    auto Iter2 =
        lower_bound(ruisekiBill.begin(), ruisekiBill.end(), *Iter1 - n);
    int left = Iter2 - ruisekiBill.begin();
    for (int right = Iter1 - ruisekiBill.begin(); right < ruisekiBill.size();
         right++) {
      while (left < ruisekiBill.size() &&
             ruisekiBill[right] - ruisekiBill[left] > n) {
        left++;
      }

      if (ruisekiBill[right] - ruisekiBill[left] == n) {
        cout << left + 1 << " " << right - left << endl;
        break;
      }
    }
  }
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
typedef long long ll;
using namespace std;

#define sum(l, r) (((r) * ((r)-1) - (l) * ((l)-1)) / 2)

int main(void) {
  ll B;
  while (cin >> B, B) {
    for (ll w = 65000; w >= 0; w--) {
      ll l = 0, h = B + 1;
      while (h - l > 1) {
        ll m = (l + h) / 2;
        if (sum(m, m + w) >= B)
          h = m;
        else
          l = m;
      }
      if (sum(h, h + w) == B) {
        cout << h << " " << w << endl;
        break;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
typedef long long ll;
using namespace std;

#define sum(l, r) (((r) * ((r)-1) - (l) * ((l)-1)) / 2)

int main(void) {
  ll B;
  while (cin >> B, B) {
    for (ll w = 100000; w >= 0; w--) {
      ll l = 0, h = B + 1;
      while (h - l > 1) {
        ll m = (l + h) / 2;
        if (sum(m, m + w) >= B)
          h = m;
        else
          l = m;
      }
      if (sum(h, h + w) == B) {
        cout << h << " " << w << endl;
        break;
      }
    }
  }
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T> int getFormer(const vector<T> &vec, T x) {
  return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T> int getLatter(const vector<T> &vec, T x) {
  return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

void solve(long long b) {
  for (int k = 1e5; k > -1; k--) {
    if (2 * b % k != 0)
      continue;
    long long n = 2 * b / k - (k - 1);
    if (n < 1 || n % 2 != 0) {
      continue;
    }
    cout << n / 2 << " " << k << endl;
    break;
  }
}

int main() {
  long long b;
  while (cin >> b && b) {
    solve(b);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define llMAX ((long long)1e18)
#define MAX ((int)1e9);

using namespace std;

int main() {
  long long b;

  while (cin >> b && b) {
    for (long long nb = 1; nb <= 10e8; nb++) {
      long long tmp = 2 * b + nb * (nb - 1);

      long long left = nb, right = nb + 1e10;

      while ((right - left) > 1) {
        long long mid = (right + left) / 2;
        if (tmp <= mid * (mid - 1)) {
          right = mid;
        } else {
          left = mid;
        }
      }

      if (right * (right - 1) == tmp) {
        cout << nb << " " << right - nb << endl;
        break;
      }
    }
  }
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main() {
  lint b;
  while (true) {
    cin >> b;
    if (b == 0) {
      break;
    }
    lint n, m;
    for (m = sqrt(b * 2) + 1; m > 0; m--) {
      n = (b - (m * (m - 1)) / 2) / m;
      if (n * m + (m * (m - 1)) / 2 == b && n > 0) {
        break;
      }
    }
    cout << n << " " << m << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main() {
  lint b;
  while (true) {
    cin >> b;
    if (b == 0) {
      break;
    }
    b *= 2;
    lint i = 1, j = 2; // [i, j)
    while (j <= b) {
      lint now = j * (j - 1) - i * (i - 1);
      if (now == b) {
        break;
      } else if (now < b) {
        j++;
      } else {
        i++;
      }
    }
    cout << i << " " << j - i << endl;
  }
  return 0;
}
Problem p01111 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while (cin >> n, n) {
    ll ans = 1, ans2 = n;
    for (ll i = 2; i <= 110000; i++) {
      ll nn = n - (i * (i + 1)) / 2;
      if (nn >= 0 && nn % i == 0) {
        ans = i;
        ans2 = nn / i + 1;
      }
    }
    cout << ans2 << " " << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9 + 7
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
  ll yosan;
  int now = 1;
  while (cin >> yosan, yosan) {

    ll bot = 1;
    ll hoge = 0;
    ll fl = ceil((-1 + sqrt(8 * yosan + 1)) / 2);
    ll hogehoge;
    while ((hogehoge = (fl * (fl + 1) / 2) - ((hoge) * (hoge + 1) / 2)) !=
           yosan) {
      if (hogehoge < yosan) {
        ll tmp = yosan - hogehoge;

        fl++;
      } else {
        hoge++;
      }
    }
    cout << hoge + 1 << " " << fl - hoge << endl;
  }
  return 0;
}
Problem p01112 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL long long

using namespace std;

int a[20][20], ans, n, m, judge;

void dfs(int x, int y) {
  if (x > n) {
    int sum = 0;
    for (int i = 1; i <= n; i++)
      sum += a[i][y];
    if (sum != judge)
      return;
    y++;
    x = y + 1;
  }
  if (y == n) {
    int sum = 0;
    for (int i = 1; i <= n; i++)
      sum += a[i][y];
    if (sum == judge)
      ans++;
    return;
  }

  if (a[x][y] == 0) {
    a[x][y] = 2;
    a[y][x] = -1;
    dfs(x + 1, y);
    a[x][y] = -1;
    a[y][x] = 2;
    dfs(x + 1, y);
    a[x][y] = a[y][x] = 0;
  } else
    dfs(x + 1, y);
}

int main() {
  std::ios::sync_with_stdio(false);
  while (cin >> n) {
    if (n == 0)
      break;
    cin >> m;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++)
      a[i][i] = 3;
    while (m--) {
      int x, y;
      cin >> x >> y;
      a[x][y] = 2;
      a[y][x] = -1;
    }

    ans = 0;
    judge = n / 2 + 3;
    dfs(2, 1);
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m;
int sum;
int x, y;
int a[100][100];
int cnt[100];
void show() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (a[i][j] == -1)
        cout << "* ";
      else
        cout << a[i][j] << " ";
    cout << endl;
  }
}
void dfs(int x, int next) {
  // show();
  // system("pause");
  if (x == n + 1)
    sum++;
  else {
    if (cnt[x] == n / 2)
      dfs(x + 1, 1);
    else
      for (int i = next; i <= n; i++) {
        if (a[x][i] == 0 && x != i) {
          a[x][i] = 1;
          a[i][x] = -1;
          cnt[x]++;
          if (cnt[x] == n / 2)
            dfs(x + 1, 1);
          else
            dfs(x, i + 1);
          a[x][i] = 0;
          a[i][x] = 0;
          cnt[x]--;
        }
      }
  }
}
int main() {
  while (true) {
    memset(cnt, 0, sizeof(cnt));
    memset(a, 0, sizeof(a));
    sum = 0;
    cin >> n;
    if (n == 0)
      return 0;
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> x >> y;
      a[x][y] = 1;
      a[y][x] = -1;
      cnt[x]++;
    }
    dfs(1, 1);
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p01112 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int n, m, ans, table[9][9];

int chack() {
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < n; j++)
      tmp += table[i][j];
    if (tmp)
      return 0;
  }
  return 1;
}

void dfs(int y, int x) {
  if (x < n - 1)
    x++;
  else if (y < n - 1) {
    x = 0;
    y++;
  } else {
    ans += chack();
    return;
  }

  if (x == 0 && 0 < y) {
    int tmp = 0;
    for (int i = 0; i < n; i++)
      tmp += table[y - 1][i];
    if (tmp)
      return;
  }

  if (table[y][x] == 0 && y != x) {
    table[y][x] = 1;
    table[x][y] = -1;
    dfs(y, x);

    table[y][x] = -1;
    table[x][y] = 1;
    dfs(y, x);

    table[y][x] = table[x][y] = 0;
  } else
    dfs(y, x);
}

int main(void) {
  while (1) {
    cin >> n;
    if (!n)
      break;
    fill(table[0], table[8], 0);
    cin >> m;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      table[x][y] = 1;
      table[y][x] = -1;
    }

    ans = 0;
    dfs(0, 0);
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, m, ans, table[9][9];

int check() {
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < n; j++)
      tmp += table[i][j];
    if (tmp)
      return 0;
  }
  return 1;
}

void dfs(int x, int y) {
  if (x < n - 1)
    x++;
  else if (y < n - 1) {
    x = 0;
    y++;
  } else {
    ans += check();
    return;
  }

  if (x == 0 && 0 < y) {
    int tmp = 0;
    for (int i = 0; i < n; i++)
      tmp += table[y - 1][i];
    if (tmp)
      return;
  }

  if (table[y][x] == 0 && y != x) {
    table[y][x] = 1;
    table[x][y] = -1;
    dfs(y, x);

    table[y][x] = -1;
    table[x][y] = 1;
    dfs(y, x);

    table[y][x] = table[x][y] = 0;
  } else
    dfs(x, y);
}

int main(void) {
  while (1) {
    cin >> n;
    if (!n)
      break;
    fill(table[0], table[8], 0);
    cin >> m;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      table[x][y] = 1;
      table[y][x] = -1;
    }

    ans = 0;
    dfs(0, 0);
    cout << ans << endl;
  }
  while (1)
    ;
  return 0;
}
Problem p01112 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  while (true) {
    int n;
    cin >> n;
    if (!n)
      break;
    int m;
    cin >> m;
    VV<> v(n);
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y, --x, --y;
      v[x].push_back(y);
    }
    V<bitset<9>> a(n);
    int res = 0;
    auto dfs = [&](const auto &dfs, int i) -> void {
      if (i == n) {
        ++res;
        return;
      }
      int s = 0;
      for (int j = 0; j < i; ++j) {
        s += a[i][j] = !a[j][i];
      }
      if (s > n / 2 or i - s > n / 2)
        return;
      V<> p(n / 2 - s, 1);
      while (p.size() < n + ~i)
        p.push_back(0);
      sort(begin(p), end(p));
      do {
        for (int j = 0; j < n + ~i; ++j) {
          a[i][i + 1 + j] = p[j];
        }
        bool b = true;
        for (int j : v[i])
          if (!a[i][j]) {
            b = false;
            break;
          }
        if (b)
          dfs(dfs, i + 1);
      } while (next_permutation(begin(p), end(p)));
    };
    dfs(dfs, 0);
    cout << res << '\\n';
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  while (true) {
    int n;
    cin >> n;
    if (!n)
      break;
    int m;
    cin >> m;
    V<> x(m), y(m);
    for (int i = 0; i < m; ++i)
      cin >> x[i] >> y[i], --x[i], --y[i];
    V<bitset<9>> a(n);
    int res = 0;
    auto dfs = [&](const auto &dfs, int i) -> void {
      if (i == n) {
        for (int j = 0; j < m; ++j) {
          if (!a[x[j]][y[j]])
            return;
        }
        ++res;
        return;
      }
      int s = 0;
      for (int j = 0; j < i; ++j) {
        s += a[i][j] = !a[j][i];
      }
      if (s > n / 2 or i - s > n / 2)
        return;
      V<> p(n / 2 - s, 1);
      while (p.size() < n + ~i)
        p.push_back(0);
      sort(begin(p), end(p));
      do {
        for (int j = 0; j < n + ~i; ++j) {
          a[i][i + 1 + j] = p[j];
        }
        dfs(dfs, i + 1);
      } while (next_permutation(begin(p), end(p)));
    };
    dfs(dfs, 0);
    cout << res << '\\n';
  }
}