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

#include <iostream>

using namespace std;

int main() {
  int n;

  while (true) {
    scanf("%d", &n);

    if (n == 0)
      break;

    int ret = 0;

    for (int i = 1; i < n; i++) {
      for (int j = 2; j <= n / i; j++) {
        int sum = 0;

        for (int k = i; k < i + j; k++) {
          sum += k;
        }

        if (sum == n)
          ret++;
      }
    }

    printf("%d\\n", ret);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;

  while (true) {
    scanf("%d", &n);

    int ret = 0;

    for (int i = 1; i < n; i++) {
      for (int j = 2; j <= n / i; j++) {
        int sum = 0;

        for (int k = i; k < i + j; k++) {
          sum += k;
        }

        if (sum == n)
          ret++;
      }
    }
  }

  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int sum1[100000], n, a;
  memset(sum1, 0, sizeof(sum1));
  for (int i = 2; i < 100; i++) {
    for (int j = 1; j < 1000; j++) {
      a = ((i - 1) + 2 * j) * i / 2;
      if (a < 10000) {
        sum1[a] += 1;
      }
    }
  }
  while (true) {
    cin >> n;
    if (n == 0) {
      goto Exit;
    } else {
      cout << sum1[n] << endl;
    }
  }
Exit:
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int sum1[10000], n;
  memset(sum1, 0, sizeof(sum1));
  for (int i = 2; i < 100; i++) {
    for (int j = 1; j < 1000; j++) {
      if (i * j + i * (i - 1) / 2 < 10000) {
        sum1[i * j + i * (i + 1) / 2] += 1;
      }
    }
  }
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    } else {
      cout << sum1[n] << endl;
    }
  }
  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n;

  while (cin >> n, n) {

    int ans = 0;

    for (int i = 1; i < n; ++i) {
      int sum = 0;
      for (int j = i; j < n; ++j) {
        sum += j;
        if (sum == n) {
          ++ans;
          break;
        } else if (sum > n) {
          break;
        }
      }
    }

    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int n;
int dp[1001][2000];

int solve(int num, int sum) {

  if (dp[num][sum] != -1)
    return 0;

  if (sum == n) {
    return 1;
  } else if (sum > n) {
    return 0;
  } else {
    int ret = 0;
    ret += solve(num + 1, sum + num + 1);
    ret += solve(num + 2, num + 2);
    return dp[num][sum] = ret;
  }
}

int main() {

  while (cin >> n, n) {

    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0) - 1 << endl;
  }
}
Problem p01314 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int n, x;
  while (true) {
    scanf("%d", &n);
    x = 0;
    if (n == 0)
      break;
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j < n; j++) {
        int count = 0;
        for (int k = j; k < j + i; k++)
          count += k;
        if (count == n)
          x++;
      }
    }
    printf("%d\\n", x);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int n, x;
  while (true) {
    scanf("%d", &n);
    x = 0;
    if (n == 0)
      break;
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j < n; j++) {
        int count = 0;
        for (int k = 0; k < i; k++)
          count += j + k;
        if (count == n)
          x++;
      }
    }
    printf("%d\\n", x);
  }
  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int sum = 0, dp[100001] = {0};
    for (int i = 1; i <= n; i++) {
      sum = i;
      for (int j = 1; sum < n; j++) {
        sum += (i + j);
        dp[sum] += 1;
      }
    }
    cout << dp[n] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int sum = 0, dp[1001] = {0};
    for (int i = 1; i <= n; i++) {
      sum = i;
      for (int j = 1; sum < n; j++) {
        sum += (i + j);
        dp[sum] += 1;
      }
    }
    cout << dp[n] << endl;
  }
  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>

int main() {
  int a;
  scanf("%d ", &a);
  while (a) {
    int count = 0;
    int b = 1;
    for (int n = 100; n >= 2; n--) {
      while (n * (2 * b + n - 1) / 2 < a) {
        b++;
      }
      if (n * (2 * b + n - 1) / 2 == a)
        count++;
    }
    printf("%d\\n", count);
    scanf("%d", &a);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

class Game {
private:
  int N, M;
  int m[7][7][7];

public:
  bool inRange(int x, int y, int z) {
    return 0 <= x && x < N && 0 <= y && y < N && 0 <= z && z < N;
  }
  int check(int x0, int y0, int z0, int dx, int dy, int dz) {
    int x = x0, y = y0, z = z0;
    int c = -1;
    int cnt = 0;
    while (inRange(x, y, z)) {
      if (m[z][y][x] == c) {
        ++cnt;
      } else {
        if (cnt >= M) {
          return c;
        }
        c = m[z][y][x];
        cnt = 1;
      }
      x += dx, y += dy, z += dz;
    }
    return cnt >= M ? c : 0;
  }
  int check(int X, int Y, int Z) {
    int c = 0;

    c = check(X, 0, Z, 0, 1, 0);
    if (c)
      return c;
    c = check(X, Y, 0, 0, 0, 1);
    if (c)
      return c;
    c = check(0, Y, Z, 1, 0, 0);
    if (c)
      return c;

    c = check(0, 0, Z, 1, 1, 0);
    if (c)
      return c;
    c = check(0, Y, 0, 1, 0, 1);
    if (c)
      return c;
    c = check(X, 0, 0, 0, 1, 1);
    if (c)
      return c;

    c = check(N - 1, 0, Z, -1, 1, 0);
    if (c)
      return c;
    c = check(0, Y, N - 1, 1, 0, -1);
    if (c)
      return c;
    c = check(X, N - 1, 0, 0, -1, 1);
    if (c)
      return c;

    c = check(0, 0, 0, 1, 1, 1);
    if (c)
      return c;
    c = check(N - 1, 0, 0, -1, 1, 1);
    if (c)
      return c;
    c = check(0, N - 1, 0, 1, -1, 1);
    if (c)
      return c;
    c = check(0, 0, N - 1, 1, 1, -1);
    if (c)
      return c;

    return 0;
  }
  int set(int X, int Y, int turn) {
    int Z;
    for (Z = 0; Z < N && m[Z][Y][X]; ++Z)
      ;
    //		cout << X << " " << Y << " " << Z << " " << M <<endl;
    assert(Z < N);
    m[Z][Y][X] = turn;
    return check(X, Y, Z);
  }
  Game(int N, int M) : N(N), M(M) {
    for (int z = 0; z < N; ++z) {
      for (int x = 0; x < N; ++x) {
        for (int y = 0; y < N; ++y) {
          m[z][y][x] = 0;
        }
      }
    }
  }
};

int main() {
  int N, M, P;
  while (cin >> N >> M >> P, N || M || P) {
    Game g(N, M);
    int turn = 1;
    int winner = 0, lastTurn = P;
    for (int i = 0; i < P; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      if (winner == 0) {
        winner = g.set(x, y, turn);
        turn = turn == 1 ? 2 : 1;
        lastTurn = i + 1;
      }
    }
    if (winner == 0) {
      cout << "Draw" << endl;
    } else if (winner == 1) {
      cout << "Black " << lastTurn << endl;
    } else {
      cout << "White " << lastTurn << endl;
    }
  }
}
Problem p01314 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int n;
  while (cin >> n && n != 0) {
    vector<int> v;
    for (int i = 1; i <= n; i++) {
      v.push_back(i);
    }
    int sum = 1;
    int begin = 0;
    int end = 0;

    int cnt = 0;
    while (1) {
      if (end == n - 1)
        break;
      else if (sum == n) {
        cnt++;
      }
      if (sum < n) {
        end++;
        sum += v[end];
      } else if (sum >= n) {
        sum -= v[begin];
        begin++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int n;
  while (cin >> n && n != 0) {
    vector<int> v;
    for (int i = 1; i <= n; i++) {
      v.push_back(i);
    }
    int sum = 1;
    int begin = 0;
    int end = 0;

    int cnt = 0;
    while (1) {
      if (sum < n) {
        end++;
        if (end == n - 1)
          break;
        sum += v[end];
      } else if (sum >= n) {
        sum -= v[begin];
        begin++;
      }
      if (sum == n) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Time Limit Exceeded

// 52
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    int ans = 0;
    for (int i = 1; i <= 1000; i++) {
      for (int j = 2; j <= 1000; j++) {
        ans += n == i * j + j * (j - 1) / 2;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// 52
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    int ans = 0;
    for (int i = 2; i <= 1000; i++) {
      for (int j = 1; j <= 1000; j++) {
        int s = 0;
        for (int k = 0; k < i; k++) {
          s += j + k;
        }
        ans += s == n;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  int n, sum, ans, left, right;
  while (cin >> n) {
    if (!n)
      break;
    left = 1;
    right = 2;
    ans = 0;
    sum = left + right;
    if (n < 3) {
      cout << 0 << endl;
      continue;
    }
    while (n - 1 > left) {
      if (n == sum)
        ans++;
      if (sum <= n && right < n) {
        right++;
        sum += right;
      } else if (right - left < 2 && right < n) {
        right++;
        sum += right;
      } else if (sum > n && right - left >= 2) {
        sum -= left;
        left++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  int n, sum, ans, left, right;
  while (cin >> n) {
    if (!n)
      break;
    left = 1;
    right = 2;
    ans = 0;
    sum = left + right;
    while (n - 1 != left) {
      if (n == sum)
        ans++;
      if (sum <= n && right < n) {
        right++;
        sum += right;
      } else if (right - left < 2 && right < n) {
        right++;
        sum += right;
      } else if (sum > n && right - left >= 2) {
        sum -= left;
        left++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01314 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; i * 2 < n; i++) {
      int sum = 2 * i + 1;
      for (int j = 2; sum <= n; j++) {
        if (sum == n) {
          ans++;
          break;
        } else
          sum += i + j;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 1; i * 2 < n; i++) {
      int sum = 2 * i + 1;
      for (int j = 2; sum <= n; j++) {
        if (sum == n)
          ans++;
        else
          sum += i + j;
      }
    }
    cout << ans << endl;
  }
}
Problem p01315 (C++) — buggy submission, verdict: Time Limit Exceeded

// c++11 ~
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef struct info {
  string name;
  double eff;

  info(string n, double e) : name(n), eff(e) {}
} info;

bool cmp(const info &a, const info &b) {
  return a.eff == b.eff ? a.name < b.name : a.eff > b.eff;
}

int main() {
  int N = 0;
  string L;
  int p, a, b, c, d, e, f, s, m;
  int t = 0, tprice = 0;
  double eff;
  vector<info> v;
  while (1) {
    v.clear();
    cin >> N;
    if (N == 0)
      break;

    for (size_t i = 0; i < N; i++) {
      cin >> L >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      t = (a + b + c + (d + e) * m);
      tprice = f * m * s - p;
      eff = (double)tprice / (double)t;
      v.push_back(info(L, eff));
    }

    sort(v.begin(), v.end(), cmp);

    for (size_t i = 0; i < v.size(); i++) {
      cout << v[i].name << endl;
    }
    cout << '#' << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int N;
    cin >> N;

    vector<tuple<ll, ll, string>> ans(N);
    for (int i = 0; i < N; i++) {
      string L;
      ll P, A, B, C, D, E, F, S, M;
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;

      ans[i] = make_tuple(S * M * F - P, A + B + C + (D + E) * M, L);
    }

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N - 1; j++) {
        if (get<0>(ans[j]) * get<1>(ans[j + 1]) ==
            get<0>(ans[j + 1]) * get<1>(ans[j])) {
          if (get<2>(ans[j]) < get<2>(ans[j + 1])) {
            swap(ans[j], ans[j + 1]);
          }
        } else if (get<0>(ans[j]) * get<1>(ans[j + 1]) >
                   get<0>(ans[j + 1]) * get<1>(ans[j])) {
          swap(ans[j], ans[j + 1]);
        }
      }
    }

    for (int i = N - 1; i >= 0; i--) {
      cout << get<2>(ans[i]) << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}
Problem p01315 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct cmp {
  bool operator()(const pair<double, string> &lhs,
                  const pair<double, string> &rhs) const {
    return lhs.first == rhs.first ? lhs.second < rhs.second
                                  : lhs.first > rhs.first;
  }
};

int main() {
  int N;
  while (cin >> N && N != 0) {
    vector<pair<double, string>> v(N);
    for (int i = 0; i < N; i++) {
      string L;
      int P, A, B, C, D, E, F, S, M;
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      int t = A + B + C + (D + E) * M;
      int c = F * S * M;
      double e = double(c - P) / t;
      v[i] = make_pair(e, L);
    }
    sort(v.begin(), v.end(), cmp());
    for (int i = 0; i < N; i++) {
      cout << v[i].second << endl;
    }
    cout << '#' << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct cmp {
  bool operator()(const pair<double, string> &lhs,
                  const pair<double, string> &rhs) const {
    return greater<double>()(lhs.first, rhs.first)
               ? true
               : less<string>()(lhs.second, rhs.second);
  }
};

int main() {
  int N;
  while (cin >> N && N != 0) {
    vector<pair<double, string>> v(N);
    for (int i = 0; i < N; i++) {
      string L;
      int P, A, B, C, D, E, F, S, M;
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      int t = A + B + C + (D + E) * M;
      int c = F * S * M;
      double e = double(c - P) / t;
      v[i] = make_pair(e, L);
    }
    sort(v.begin(), v.end(), cmp());
    for (int i = 0; i < N; i++) {
      cout << v[i].second << endl;
    }
    cout << '#' << endl;
  }
  return 0;
}
Problem p01315 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  int n;
  while (cin >> n, n) {
    vector<pair<string, double>> crops;
    loop(n, i) {
      string name;
      int p, a, b, c, d, e, f, s, m;
      cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int time = 0, gain = -p;
      time = a + b + c;
      loop(m, j) {
        time += d + e;
        gain += f * s;
      }
      crops.push_back(make_pair(name, (double)gain / time));
    }

    sort(all(crops),
         [](pair<string, double> p1, pair<string, double> p2) -> int {
           if (islessgreater(p1.second, p2.second)) {
             return isgreater(p1.second, p2.second);
           } else {
             return p1.first < p2.first;
           }
         });
    for (auto m : crops) {
      cout << m.first << endl;
    }

    cout << '#' << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  int n;
  while (cin >> n, n) {
    vector<pair<string, float>> crops;
    loop(n, i) {
      string name;
      int p, a, b, c, d, e, f, s, m;
      cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int time = 0, gain = -p;
      time = a + b + c;
      loop(m, j) {
        time += d + e;
        gain += f * s;
      }
      crops.push_back(make_pair(name, (float)gain / time));
    }

    sort(all(crops), [](pair<string, float> p1, pair<string, float> p2) -> int {
      if (islessgreater(p1.second, p2.second)) {
        return isgreater(p1.second, p2.second);
      } else {
        p1.first < p2.first;
      }
    });
    for (auto m : crops) {
      cout << m.first << endl;
    }

    cout << '#' << endl;
  }
}
Problem p01315 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#pragma warning(disable : 4996)
using namespace std;

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    vector<pair<string, long double>> pls;
    for (int i = 0; i < N; ++i) {
      string st;
      int p, a, b, c, d, e, f, s, m;
      cin >> st >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int initime = a + b + c;
      int rooptime = d + e;
      int money = m * s * f - p;
      long double eff = static_cast<long double>(money) /
                        static_cast<long double>(initime + rooptime * (m));
      pls.push_back(make_pair(st, eff));
    }
    sort(pls.begin(), pls.end(),
         [](const pair<string, long double> &l,
            const pair<string, long double> &r) {
           return abs(l.second - r.second) < 1e-12 ? l.first < r.first
                                                   : l.second > r.second;
         });
    for (int i = 0; i < pls.size(); ++i) {
      cout << pls[i].first << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#pragma warning(disable : 4996)
using namespace std;

int main() {
  while (1) {
    int N;
    cin >> N;
    vector<pair<string, long double>> pls;
    for (int i = 0; i < N; ++i) {
      string st;
      int p, a, b, c, d, e, f, s, m;
      cin >> st >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      int initime = a + b + c;
      int rooptime = d + e;
      int money = m * s * f - p;
      double eff = double(money) / double(initime + rooptime * (m - 1));
      pls.push_back(make_pair(st, eff));
    }
    sort(pls.begin(), pls.end(),
         [](const pair<string, long double> &l,
            const pair<string, long double> &r) {
           return abs(l.second - r.second) < 1e-9 ? l.first < r.first
                                                  : l.second > r.second;
         });
    for (int i = 0; i < pls.size(); ++i) {
      cout << pls[i].first << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}
Problem p01315 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

#define EPS 1e-10

typedef pair<string, double> PD;

bool compare(const PD &a, const PD &b) {
  if (fabs(a.second - b.second) < EPS)
    return a.first < b.first;
  return a.second > b.second;
}

int main() {
  int N;
  while (cin >> N, N) {
    vector<PD> fruits;
    fruits.clear();
    string L;
    int P, A, B, C, D, E, F, S, M;
    for (int cs = 0; cs < N; cs++) {
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      int ABC = A + B + C;
      int DE = D + E;
      int total_value = S * F * M - P;
      int total_time = ABC + (DE * M);
      double v = (double)((double)total_value / (double)total_time);
      fruits.push_back(PD(L, v));
    }
    sort(fruits.begin(), fruits.end(), compare);

    for (int i = 0; i < N; i++) {
      cout << fruits[i].first << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

#define EPS 1e-10

typedef pair<string, double> PD;

bool compare(const PD &a, const PD &b) {
  if (fabs(a.second - b.second < EPS))
    return a.first < b.first;
  return a.second > b.second;
}

int main() {
  int N;
  while (cin >> N, N) {
    vector<PD> fruits;
    string L;
    int P, A, B, C, D, E, F, S, M;
    for (int cs = 0; cs < N; cs++) {
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      int ABC = A + B + C;
      int DE = D + E;
      int total_value = S * F * M - P;
      int total_time = ABC + (DE * M);
      double v = (double)((double)total_value / (double)total_time);
      fruits.push_back(PD(L, v));
    }
    sort(fruits.begin(), fruits.end(), compare);

    for (int i = 0; i < N; i++) {
      cout << fruits[i].first << endl;
    }
    cout << "#" << endl;
  }
  return 0;
}