prithivMLmods/Coder-Stat huggingface dataset:
Problem p02702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 2019
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> t(n + 1), a(n);
  REP(i, n) a[i] = s[i] - '0';
  t[n] = 0;
  vector<ll> pow10_mod(n);
  pow10_mod[0] = 1;
  for (ll i = 1; i < n; i++)
    pow10_mod[i] = pow10_mod[i - 1] * 10 % MOD;
  REP(i, n)
  for (ll i = n - 1; i >= 0; i--) {
    t[i] = (t[i + 1] + a[i] * pow10_mod[10, n - i - 1]) % MOD;
  }
  vector<ll> cnt(2019, 0);
  REP(i, n + 1) cnt[t[i]]++;
  ll ans = 0;
  REP(i, 2019) ans += cnt[i] * (cnt[i] - 1) / 2;
  DEBUGS(t);
  DEBUGS(a);
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 2019
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> t(n + 1), a(n);
  REP(i, n) a[i] = s[i] - '0';
  t[n] = 0;
  vector<ll> pow10_mod(n);
  pow10_mod[0] = 1;
  for (ll i = 1; i < n; i++)
    pow10_mod[i] = pow10_mod[i - 1] * 10 % MOD;

  for (ll i = n - 1; i >= 0; i--) {
    t[i] = (t[i + 1] + a[i] * pow10_mod[10, n - i - 1]) % MOD;
  }
  vector<ll> cnt(2019, 0);
  REP(i, n + 1) cnt[t[i]]++;
  ll ans = 0;
  REP(i, 2019) ans += cnt[i] * (cnt[i] - 1) / 2;
  DEBUGS(t);
  DEBUGS(a);
  cout << ans << "\n";
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long n, len, dp[2][200002];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("test.inp","r",stdin);
  // freopen("test.out","w",stdout);
  cin >> s;
  len = s.length();
  long long res = 0;
  dp[0][(s[0] - '0') % 2019] = 1;
  for (int i = 1; i < len; i++) {
    // cout<<dp[1][0]<<endl;
    for (int j = 0; j < 2019; j++) {
      dp[1][(j * 10 + (s[i] - '0')) % 2019] += dp[0][j];
      // if (( j*10 + (s[i]-'0') ) % 2019==0) cout<<i<<" "<<j<<"
      // "<<dp[0][403]<<endl;
    }
    res += dp[1][0];
    // cout<<res<<endl;
    memcpy(dp[0], dp[1], sizeof(dp[1]));
    dp[0][(s[i] - '0') % 2019]++;
    memset(dp[1], 0, sizeof(dp[1]));
  }
  cout << res;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, len, dp[2][2020];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("test.inp","r",stdin);
  // freopen("test.out","w",stdout);
  cin >> s;
  len = s.length();
  long long res = 0;
  dp[0][(s[0] - '0') % 2019] = 1;
  for (int i = 1; i < len; i++) {
    // cout<<dp[1][0]<<endl;
    for (int j = 0; j < 2019; j++) {
      dp[1][(j * 10 + (s[i] - '0')) % 2019] += dp[0][j];
      // if (( j*10 + (s[i]-'0') ) % 2019==0) cout<<i<<" "<<j<<"
      // "<<dp[0][403]<<endl;
    }
    res += dp[1][0];
    // cout<<res<<endl;
    memcpy(dp[0], dp[1], sizeof(dp[1]));
    dp[0][(s[i] - '0') % 2019]++;
    memset(dp[1], 0, sizeof(dp[1]));
  }
  cout << res;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
char s[20010];
int c[2020], inv = 202;
int main() {
  int ans = 0, tt = 1, cur = 0;
  scanf("%s", s);
  c[0] = 1;
  for (int i = 0; s[i]; i++) {
    int x = s[i] - '0';
    cur = (cur * 10 + x) % 2019;
    tt = (tt * inv) % 2019;
    ans += c[(cur * tt) % 2019];
    c[(cur * tt) % 2019]++;
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <stdio.h>
char s[200010];
int c[2020], inv = 202;
int main() {
  int ans = 0, tt = 1, cur = 0;
  scanf("%s", s);
  c[0] = 1;
  for (int i = 0; s[i]; i++) {
    int x = s[i] - '0';
    cur = (cur * 10 + x) % 2019;
    tt = (tt * inv) % 2019;
    ans += c[(cur * tt) % 2019];
    c[(cur * tt) % 2019]++;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const int MOD = 2019;

ll modpow(int a, int n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a *= a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  string S;
  cin >> S;
  vi cnt(2019, 0);
  cnt[0]++;
  ll sum = 0;
  for (int i = S.size() - 1; i >= 0; i--) {
    sum = (sum + (S[i] - '0') * modpow(10, S.size() - 1 - i) % MOD) % MOD;
    cnt[sum]++;
  }
  ll res = 0;
  for (int i = 0; i < 2019; i++) {
    res += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const int MOD = 2019;

ll modpow(int a, int n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  string S;
  cin >> S;
  vi cnt(2019, 0);
  cnt[0]++;
  ll sum = 0;
  for (int i = S.size() - 1; i >= 0; i--) {
    sum = (sum + (S[i] - '0') * modpow(10, S.size() - 1 - i) % MOD) % MOD;
    cnt[sum]++;
  }
  ll res = 0;
  for (int i = 0; i < 2019; i++) {
    res += cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << res << endl;
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  string s;
  cin >> s;
  vector<ll> x(2019, 0);
  x[0] += 1;
  ll k = 0;
  ll p = 1;
  for (int i = 1; i <= s.size(); i++) {
    k += ((ll)(s[s.size() - i] - '0')) * p % 2019;
    k %= 2019;
    x[k % 2019] += 1;
    p *= 10;
  }
  ll ans = 0;
  for (auto iter = x.begin(); iter != x.end(); iter++) {
    if (*iter > 0) {
      ans += (*iter) * (*iter - 1) / 2;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  string s;
  cin >> s;
  vector<ll> x(2019, 0);
  x[0] += 1;
  ll k = 0;
  ll p = 1;
  for (int i = 1; i <= s.size(); i++) {
    k += ((ll)(s[s.size() - i] - '0')) * p % 2019;
    k %= 2019;
    x[k % 2019] += 1;
    p *= 10;
    p %= 2019;
  }
  ll ans = 0;
  for (auto iter = x.begin(); iter != x.end(); iter++) {
    if (*iter > 0) {
      ans += (*iter) * (*iter - 1) / 2;
    }
  }
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

int main() {
  string s;
  cin >> s;
  int n = s.size(), a = 0, b = 1, r[2019];
  rep(i, 2019) r[i] = 0;
  rep(i, n) {
    a = (a + (s[n - 1 - i] - '0') * b) % 2019;
    b = (b * 10) % 2019;
    r[a]++;
  }

  ll res = 0;
  rep(i, n) res += r[i] * (r[i] + 1) / 2;

  cout << res << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

int main() {
  string s;
  cin >> s;
  int n = s.size(), a = 0, b = 1, r[2019];
  rep(i, 2019) r[i] = 0;
  rep(i, n) {
    a = (a + (s[n - 1 - i] - '0') * b) % 2019;
    b = (b * 10) % 2019;
    r[a]++;
  }
  ll res = r[0];
  rep(i, 2019) res += r[i] * (r[i] - 1) / 2;
  cout << res << endl;
  return 0;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 2019;

ll nums[MOD + 5];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  nums[0] = 1;
  ll num = 0, t = 1;
  for (int i = n - 1; i >= 0; i--, t *= 10) {
    num = (num + (s[i] - '0') * t) % MOD;
    nums[num]++;
  }
  ll ans = 0;
  for (int i = 0; i < MOD; i++) {
    ans += nums[i] * (nums[i] - 1) / 2;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 2019;

ll nums[MOD + 5];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  nums[0] = 1;
  ll num = 0, t = 1;
  for (int i = n - 1; i >= 0; i--, t *= 10) {
    t %= MOD;
    num = (num + (s[i] - '0') * t) % MOD;
    nums[num]++;
  }
  ll ans = 0;
  for (int i = 0; i < MOD; i++) {
    ans += nums[i] * (nums[i] - 1) / 2;
  }
  cout << ans << endl;
}
Problem p02702 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll p[2019] = {};
  ll t = 0;
  ll d = 1;
  ll ans = 0;
  for (ll i = n - 1; i >= 0; i--) {
    p[t]++;
    t += ((s[i] - '0') * d + t) % 2019;
    d = (d * 10) % 2019;
    ans += p[t];
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll p[2019] = {};
  ll t = 0;
  ll d = 1;
  ll ans = 0;
  for (ll i = n - 1; i >= 0; i--) {
    p[t]++;
    t = ((s[i] - '0') * d + t) % 2019;
    d = (d * 10) % 2019;
    ans += p[t];
  }
  cout << ans << endl;
}
Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <queue>
#include <stdio.h>
#include <vector>
struct str {
  int x0;
  int cost;
  int time;
};
std::vector<str> V[60];
struct str2 {
  int x0;
  int coin;
  long long int dist;
};
bool operator<(str2 a, str2 b) { return a.dist > b.dist; }
std::priority_queue<str2> Q;
std::pair<int, int> x[60];
long long int check[60][3000];

long long int MAX = 1;
int main() {
  for (int i = 1; i <= 15; i++)
    MAX *= 10;

  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 1; i <= b; i++) {
    int d, e, f, g;
    scanf("%d%d%d%d", &d, &e, &f, &g);
    V[d].push_back({e, f, g});
    V[e].push_back({d, f, g});
  }
  for (int i = 1; i <= a; i++) {
    int d, e;
    scanf("%d%d", &d, &e);
    x[i] = std::make_pair(d, e);
  }

  if (c > 2500)
    c = 2500;
  Q.push({1, c, 1});
  while (!Q.empty()) {
    int x0 = Q.top().x0;
    int coin = Q.top().coin;
    long long int dist = Q.top().dist;
    Q.pop();

    if (check[x0][coin])
      continue;
    check[x0][coin] = dist;

    Q.push({x0, coin + x[x0].first, dist + x[x0].second});
    for (int i = 0; i < V[x0].size(); i++)
      if (V[x0][i].cost <= coin)
        Q.push({V[x0][i].x0, coin - V[x0][i].cost, dist + V[x0][i].time});
  }

  for (int i = 2; i <= a; i++) {
    long long int ans = MAX;
    for (int j = 0; j <= 2500; j++) {
      if (check[i][j] > 0)
        ans = ans < check[i][j] ? ans : check[i][j];
    }
    printf("%lld\n", ans - 1);
  }
}

Fixed submission:
#include <queue>
#include <stdio.h>
#include <vector>
struct str {
  int x0;
  int cost;
  int time;
};
std::vector<str> V[60];
struct str2 {
  int x0;
  int coin;
  long long int dist;
};
bool operator<(str2 a, str2 b) { return a.dist > b.dist; }
std::priority_queue<str2> Q;
std::pair<int, int> x[60];
long long int check[60][3000];

long long int MAX = 1;
int main() {
  for (int i = 1; i <= 15; i++)
    MAX *= 10;

  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 1; i <= b; i++) {
    int d, e, f, g;
    scanf("%d%d%d%d", &d, &e, &f, &g);
    V[d].push_back({e, f, g});
    V[e].push_back({d, f, g});
  }
  for (int i = 1; i <= a; i++) {
    int d, e;
    scanf("%d%d", &d, &e);
    x[i] = std::make_pair(d, e);
  }

  if (c > 2500)
    c = 2500;
  Q.push({1, c, 1});
  while (!Q.empty()) {
    int x0 = Q.top().x0;
    int coin = Q.top().coin;
    long long int dist = Q.top().dist;
    Q.pop();

    if (check[x0][coin])
      continue;
    check[x0][coin] = dist;

    if (coin + x[x0].first <= 2500)
      Q.push({x0, coin + x[x0].first, dist + x[x0].second});
    for (int i = 0; i < V[x0].size(); i++)
      if (V[x0][i].cost <= coin)
        Q.push({V[x0][i].x0, coin - V[x0][i].cost, dist + V[x0][i].time});
  }

  for (int i = 2; i <= a; i++) {
    long long int ans = MAX;
    for (int j = 0; j <= 2500; j++) {
      if (check[i][j] > 0)
        ans = ans < check[i][j] ? ans : check[i][j];
    }
    printf("%lld\n", ans - 1);
  }
}
Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N;
  cin >> N;
  ll M;
  cin >> M;
  ll S;
  cin >> S;
  vector<ll> C(N), D(N);

  vector<pair<ll, pair<ll, ll>>> G[N]; // to, coin, time

  for (ll i = 0; i < M; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u].push_back(make_pair(v, make_pair(a, b)));
    G[v].push_back(make_pair(u, make_pair(a, b)));
  }
  for (ll i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
  }

  ll INF = 1e18;
  vector<vector<ll>> dp(N, vector<ll>(2550, INF));
  queue<pair<ll, pair<ll, ll>>> q; // time, location, coin
  q.push(make_pair(0, make_pair(0, S)));
  while (!q.empty()) {
    pair<ll, pair<ll, ll>> c = q.front();
    q.pop();
    ll mins = c.first, loc = c.second.first, coin = c.second.second;
    if (dp[loc][coin] <= mins)
      continue;
    dp[loc][coin] = mins;

    for (auto n : G[loc]) {
      ll new_mins = mins + n.second.second;
      ll new_loc = n.first;
      ll new_coin = coin - n.second.first;
      if (new_coin < 0)
        continue;
      q.push(make_pair(new_mins, make_pair(new_loc, new_coin)));
    }

    ll new_mins = mins + D[loc];
    ll new_coin = coin + C[loc];
    if (new_coin > 2500)
      new_coin = 2500;
    q.push(make_pair(new_mins, make_pair(loc, new_coin)));
  }

  for (ll i = 1; i < N; i++) {
    ll ans = INF;
    for (ll j = 0; j < 2550; j++) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << '\n';
  }
  return 0;
}

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

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

  ll N;
  cin >> N;
  ll M;
  cin >> M;
  ll S;
  cin >> S;
  vector<ll> C(N), D(N);

  vector<pair<ll, pair<ll, ll>>> G[N]; // to, coin, time

  for (ll i = 0; i < M; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u].push_back(make_pair(v, make_pair(a, b)));
    G[v].push_back(make_pair(u, make_pair(a, b)));
  }
  for (ll i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
  }

  S = min(S, (ll)2500);
  ll INF = 1e18;
  vector<vector<ll>> dp(N, vector<ll>(2550, INF));
  queue<pair<ll, pair<ll, ll>>> q; // time, location, coin
  q.push(make_pair(0, make_pair(0, S)));
  while (!q.empty()) {
    pair<ll, pair<ll, ll>> c = q.front();
    q.pop();
    ll mins = c.first, loc = c.second.first, coin = c.second.second;
    if (dp[loc][coin] <= mins)
      continue;
    dp[loc][coin] = mins;

    for (auto n : G[loc]) {
      ll new_mins = mins + n.second.second;
      ll new_loc = n.first;
      ll new_coin = coin - n.second.first;
      if (new_coin < 0)
        continue;
      q.push(make_pair(new_mins, make_pair(new_loc, new_coin)));
    }

    ll new_mins = mins + D[loc];
    ll new_coin = coin + C[loc];
    if (new_coin > 2500)
      new_coin = 2500;
    q.push(make_pair(new_mins, make_pair(loc, new_coin)));
  }

  for (ll i = 1; i < N; i++) {
    ll ans = INF;
    for (ll j = 0; j < 2550; j++) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << '\n';
  }
  return 0;
}
Problem p02703 (Python)

Buggy submission (status: Time Limit Exceeded):
import heapq

N, M, S = map(int, input().split())

uvab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(M):
    uvab[i][0] -= 1
    uvab[i][1] -= 1

railways = [[] for _ in range(N)]
max_a = 0
for u, v, a, b in uvab:
    railways[u].append((v, a, b))
    railways[v].append((u, a, b))
    max_a = max(max_a, a)
del uvab

max_silver = max_a * (N - 1)

ans = [-1] * N
d = dict()
d[(S, 0)] = 0  # silver, station
Q = [(0, S, 0)]  # time, silver, station
sum_reached = 0
reached = [False] * N

while Q:
    t, sv, st = heapq.heappop(Q)
    if not reached[st]:
        ans[st] = t
        reached[st] = True
        sum_reached += 1
        if sum_reached == N:
            break

    new_key = (sv + cd[st][0], st)
    new_value = t + cd[st][1]
    if new_key not in d or d[new_key] > new_value:
        d[new_key] = t + cd[st][1]
        heapq.heappush(Q, (new_value, *new_key))

    for dist, a, b in railways[st]:
        if sv >= a:
            new_key = (sv - a, dist)
            new_value = t + b
            if new_key not in d or d[new_key] > new_value:
                d[new_key] = new_value
                heapq.heappush(Q, (new_value, *new_key))

print(*ans[1:], sep="\n")


Fixed submission:
import heapq

N, M, S = map(int, input().split())

uvab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(M):
    uvab[i][0] -= 1
    uvab[i][1] -= 1

railways = [[] for _ in range(N)]
max_a = 0
for u, v, a, b in uvab:
    railways[u].append((v, a, b))
    railways[v].append((u, a, b))
    max_a = max(max_a, a)
del uvab

max_silver = max_a * (N - 1)

ans = [-1] * N
d = dict()
d[(S, 0)] = 0  # silver, station
Q = [(0, S, 0)]  # time, silver, station
sum_reached = 0
reached = [False] * N

while Q:
    t, sv, st = heapq.heappop(Q)
    if not reached[st]:
        ans[st] = t
        reached[st] = True
        sum_reached += 1
        if sum_reached == N:
            break

    new_key = (min(max_silver, sv + cd[st][0]), st)
    new_value = t + cd[st][1]
    if new_key not in d or d[new_key] > new_value:
        d[new_key] = t + cd[st][1]
        heapq.heappush(Q, (new_value, *new_key))

    for dist, a, b in railways[st]:
        if sv >= a:
            new_key = (sv - a, dist)
            new_value = t + b
            if new_key not in d or d[new_key] > new_value:
                d[new_key] = new_value
                heapq.heappush(Q, (new_value, *new_key))

print(*ans[1:], sep="\n")
Problem p02703 (Python)

Buggy submission (status: Time Limit Exceeded):
import heapq
import os
from collections import defaultdict

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353


N, M, S = list(map(int, sys.stdin.buffer.readline().split()))
UVAB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
CD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
CD = [(0, 0)] + CD

graph = [[] for _ in range(N + 1)]
for u, v, a, b in UVAB:
    graph[u].append((a, b, v))
    graph[v].append((a, b, u))
for vs in graph:
    vs.sort()

mada = set(list(range(2, N + 1)))
heap = [(0, 1, S)]
ans = [INF] * (N + 1)
ans[1] = 0
# dp[v, s]: v にお金を s 持ってる状態で来たときの最小値
dp = defaultdict(lambda: INF)
dp[1, S] = 0
while heap and mada:
    d, v, s = heapq.heappop(heap)
    if d > dp[v, s]:
        continue
    if v in mada:
        mada.remove(v)

    ans[v] = min(ans[v], d)
    for a, b, u in graph[v]:
        if s - a < 0:
            break
        if d + b < dp[u, s - a]:
            dp[u, s - a] = d + b
            heapq.heappush(heap, (d + b, u, s - a))
    c, dd = CD[v]
    for _ in range(3):
        if d + dd < dp[v, s + c]:
            dp[v, s + c] = d + dd
            heapq.heappush(heap, (d + dd, v, s + c))

print(*ans[2:], sep="\n")


Fixed submission:
import heapq
import os
from collections import defaultdict

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353


N, M, S = list(map(int, sys.stdin.buffer.readline().split()))
UVAB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
CD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
CD = [(0, 0)] + CD

graph = [[] for _ in range(N + 1)]
for u, v, a, b in UVAB:
    graph[u].append((a, b, v))
    graph[v].append((a, b, u))
for vs in graph:
    vs.sort()

mada = set(list(range(2, N + 1)))
heap = [(0, 1, S)]
ans = [INF] * (N + 1)
ans[1] = 0
# dp[v, s]: v にお金を s 持ってる状態で来たときの最小値
dp = defaultdict(lambda: INF)
dp[1, S] = 0
while heap and mada:
    d, v, s = heapq.heappop(heap)
    if d > dp[v, s]:
        continue
    if v in mada:
        mada.remove(v)

    ans[v] = min(ans[v], d)
    for a, b, u in graph[v]:
        if s - a < 0:
            break
        if d + b < dp[u, s - a]:
            dp[u, s - a] = d + b
            heapq.heappush(heap, (d + b, u, s - a))
    c, dd = CD[v]
    sc = min(s + c, 50 * N + 10)
    if d + dd < dp[v, sc]:
        dp[v, sc] = d + dd
        heapq.heappush(heap, (d + dd, v, sc))

print(*ans[2:], sep="\n")
Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

struct Edge {
  long to, c, t;
};

const long inf = 1e18;
const long mx = 5000;
long n, m, s;
vector<Edge> g[50];
long ca[50];
long ti[50];

vector<long> sub() {
  using PP = pair<long, long>;
  using TT = pair<long, PP>;

  priority_queue<TT, vector<TT>, greater<TT>> q;
  q.push(TT(0, PP(0, min(s, mx))));

  vector<vector<long>> dist(n, vector<long>(mx + 1, inf));
  while (!q.empty()) {
    auto tt = q.top();
    q.pop();
    long d = tt.first;
    long from = tt.second.first;
    long mon = tt.second.second;
    if (dist[from][mon] != inf)
      continue;
    dist[from][mon] = d;
    for (auto e : g[from]) {
      long to = e.to;
      long c = e.c;
      long t = e.t;
      if (mon >= c) {
        q.push(TT(d + t, PP(to, mon - c)));
      }
    }
    q.push(TT(d + ti[from], PP(from, mon + ca[from])));
  }

  vector<long> ret(n);
  for (int i = 0; i < n; ++i) {
    long mn = inf;
    for (int j = 0; j <= mx; ++j) {
      mn = min(mn, dist[i][j]);
    }
    ret[i] = mn;
  }
  return ret;
}

int main() {
  cin >> n >> m >> s;
  for (int j = 0; j < m; ++j) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u;
    --v;
    g[u].push_back(Edge{v, a, b});
    g[v].push_back(Edge{u, a, b});
  }
  for (int i = 0; i < n; ++i) {
    cin >> ca[i] >> ti[i];
  }

  auto v = sub();
  for (int i = 1; i < n; ++i) {
    cout << v[i] << endl;
  }
}

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

struct Edge {
  long to, c, t;
};

const long inf = 1e18;
const long mx = 5000;
long n, m, s;
vector<Edge> g[50];
long ca[50];
long ti[50];

vector<long> sub() {
  using PP = pair<long, long>;
  using TT = pair<long, PP>;

  priority_queue<TT, vector<TT>, greater<TT>> q;
  q.push(TT(0, PP(0, min(s, mx))));

  vector<vector<long>> dist(n, vector<long>(mx + 1, inf));
  while (!q.empty()) {
    auto tt = q.top();
    q.pop();
    long d = tt.first;
    long from = tt.second.first;
    long mon = tt.second.second;
    if (dist[from][mon] != inf)
      continue;
    dist[from][mon] = d;
    for (auto e : g[from]) {
      long to = e.to;
      long c = e.c;
      long t = e.t;
      if (mon >= c) {
        q.push(TT(d + t, PP(to, mon - c)));
      }
    }
    q.push(TT(d + ti[from], PP(from, min(mon + ca[from], mx))));
  }

  vector<long> ret(n);
  for (int i = 0; i < n; ++i) {
    long mn = inf;
    for (int j = 0; j <= mx; ++j) {
      mn = min(mn, dist[i][j]);
    }
    ret[i] = mn;
  }
  return ret;
}

int main() {
  cin >> n >> m >> s;
  for (int j = 0; j < m; ++j) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u;
    --v;
    g[u].push_back(Edge{v, a, b});
    g[v].push_back(Edge{u, a, b});
  }
  for (int i = 0; i < n; ++i) {
    cin >> ca[i] >> ti[i];
  }

  auto v = sub();
  for (int i = 1; i < n; ++i) {
    cout << v[i] << endl;
  }
}
Problem p02703 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct E {
  int to, co, ti;
};
struct P {
  int tim, idx, res;
};
bool operator<(const P &a, const P &b) { return a.tim < b.tim; }
bool operator>(const P &a, const P &b) {
  if (a.tim != b.tim)
    return a.tim > b.tim;
  return a.res < b.res;
}
int ans[50][5001];
const long long LINF = 1e18;
template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

signed main() {
  memset(ans, -1, sizeof(ans));
  int n, m, s;
  cin >> n >> m >> s;
  chmin(s, 5000LL);
  vector<E> edge[n];
  while (m--) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge[u].push_back({v, a, b});
    edge[v].push_back({u, a, b});
  }
  vector<int> c(n), d(n);
  for (int i = 0; i < n; i++)
    cin >> c[i] >> d[i];
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, 0, s});
  vector<int> fans(n, -1);
  int cnt = 0;
  while (que.size()) {
    P p = que.top();
    que.pop(); // cout<<p.idx<<" "<<p.res<<" "<<p.tim<<" "<<cnt<<endl;
    if (~ans[p.idx][p.res])
      continue;
    ans[p.idx][p.res] = p.tim;
    if (fans[p.idx] < 0) {
      fans[p.idx] = p.tim;
      if (++cnt == n)
        break;
    }
    do {
      for (auto q : edge[p.idx]) {
        if (p.res < q.co || ~ans[q.to][p.res - q.co])
          continue;
        que.push({p.tim + q.ti, q.to, p.res - q.co});
      }
      p.res += c[p.idx];
      p.tim += d[p.idx];
    } while (p.res < 5000);
  }
  for (int i = 1; i < n; i++)
    cout << fans[i] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct E {
  int to, co, ti;
};
struct P {
  int tim, idx, res;
};
bool operator<(const P &a, const P &b) { return a.tim < b.tim; }
bool operator>(const P &a, const P &b) {
  if (a.tim != b.tim)
    return a.tim > b.tim;
  return a.res < b.res;
}
int ans[50][5001];
const long long LINF = 1e18;
template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

signed main() {
  memset(ans, -1, sizeof(ans));
  int n, m, s;
  cin >> n >> m >> s;
  chmin(s, 5000LL);
  vector<E> edge[n];
  while (m--) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edge[u].push_back({v, a, b});
    edge[v].push_back({u, a, b});
  }
  vector<int> c(n), d(n);
  for (int i = 0; i < n; i++)
    cin >> c[i] >> d[i];
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, 0, s});
  vector<int> fans(n, -1);
  int cnt = 0;
  while (que.size()) {
    P p = que.top();
    que.pop(); // cout<<p.idx<<" "<<p.res<<" "<<p.tim<<" "<<cnt<<endl;
    if (~ans[p.idx][p.res])
      continue;
    ans[p.idx][p.res] = p.tim;
    if (fans[p.idx] < 0) {
      fans[p.idx] = p.tim;
      if (++cnt == n)
        break;
    }
    for (auto q : edge[p.idx]) {
      if (p.res < q.co || ~ans[q.to][p.res - q.co])
        continue;
      que.push({p.tim + q.ti, q.to, p.res - q.co});
    }
    if (p.res + c[p.idx] < 5000)
      que.push({p.tim + d[p.idx], p.idx, p.res + c[p.idx]});
  }
  for (int i = 1; i < n; i++)
    cout << fans[i] << endl;
}
Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const LL inf = 0x3f3f3f3f3f3f3f3f;
const int N = 55, M = 110;
struct Edge {
  int to, next;
  LL a, b;
} e[M];
int head[N], idx;
LL c[N], d[N];
LL dis[N][2510];
int n, m, s;

void add(int u, int v, LL a, LL b) {
  e[++idx].to = v;
  e[idx].next = head[u];
  e[idx].a = a;
  e[idx].b = b;
  head[u] = idx;
}

void spfa() {
  queue<PII> q;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 2500; j++) {
      dis[i][j] = inf;
    }
  }
  dis[1][s] = 0;
  q.push({1, s});
  while (!q.empty()) {
    int u = q.front().first, w = q.front().second;
    q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      LL a = e[i].a, b = e[i].b;
      if (w >= a && dis[v][w - a] > dis[u][w] + b) {
        dis[v][w - a] = dis[u][w] + b;
        q.push({v, w - a});
      }
    }
    if (dis[u][min(w + c[u], (LL)2500)] > dis[u][w] + d[u]) {
      dis[u][min(w + c[u], (LL)2500)] = dis[u][w] + d[u];
      q.push({u, min(w + c[u], (LL)2500)});
    }
  }
}

int main() {
  scanf("%d%d%d", &n, &m, &s);
  s = min(s, 2500);
  while (m--) {
    int u, v;
    LL a, b;
    scanf("%d%d%lld%lld", &u, &v, &a, &b);
    add(u, v, a, b);
    add(v, u, a, b);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld", &c[i], &d[i]);
  }
  spfa();
  for (int i = 2; i <= n; i++) {
    LL res = inf;
    for (int j = 0; j <= 2500; j++)
      res = min(res, dis[i][j]);
    printf("%lld\n", res);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const LL inf = 0x3f3f3f3f3f3f3f3f;
const int N = 55, M = 110;
struct Edge {
  int to, next;
  LL a, b;
} e[M * 2];
int head[N], idx;
LL c[N], d[N];
LL dis[N][2510];
int n, m, s;

void add(int u, int v, LL a, LL b) {
  e[++idx].to = v;
  e[idx].next = head[u];
  e[idx].a = a;
  e[idx].b = b;
  head[u] = idx;
}

void spfa() {
  queue<PII> q;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 2500; j++) {
      dis[i][j] = inf;
    }
  }
  dis[1][s] = 0;
  q.push({1, s});
  while (!q.empty()) {
    int u = q.front().first, w = q.front().second;
    q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      LL a = e[i].a, b = e[i].b;
      if (w >= a && dis[v][w - a] > dis[u][w] + b) {
        dis[v][w - a] = dis[u][w] + b;
        q.push({v, w - a});
      }
    }
    if (dis[u][min(w + c[u], (LL)2500)] > dis[u][w] + d[u]) {
      dis[u][min(w + c[u], (LL)2500)] = dis[u][w] + d[u];
      q.push({u, min(w + c[u], (LL)2500)});
    }
  }
}

int main() {
  scanf("%d%d%d", &n, &m, &s);
  s = min(s, 2500);
  while (m--) {
    int u, v;
    LL a, b;
    scanf("%d%d%lld%lld", &u, &v, &a, &b);
    add(u, v, a, b);
    add(v, u, a, b);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld", &c[i], &d[i]);
  }
  spfa();
  for (int i = 2; i <= n; i++) {
    LL res = inf;
    for (int j = 0; j <= 2500; j++)
      res = min(res, dis[i][j]);
    printf("%lld\n", res);
  }
  return 0;
}
Problem p02703 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

using vec = vector<pair<int, int64_t>>;
using graph = vector<vec>;
constexpr int64_t inf = 1e18;

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  vector<int> u(m), v(m), a(m), b(m), c(n), d(n);
  for (int i = 0; i < m; i++) {
    cin >> u.at(i) >> v.at(i) >> a.at(i) >> b.at(i);
    u.at(i)--;
    v.at(i)--;
  }
  for (int i = 0; i < n; i++) {
    cin >> c.at(i) >> d.at(i);
  }
  graph to(50 * n * n);
  for (int i = 0; i < m; i++) {
    for (int j = a.at(i); j < 50 * n; j++) {
      to.at(50 * n * u.at(i) + j)
          .emplace_back(50 * n * v.at(i) + j - a.at(i), b.at(i));
      to.at(50 * n * v.at(i) + j)
          .emplace_back(50 * n * u.at(i) + j - a.at(i), b.at(i));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 50 * n; j++) {
      int next = min(50 * n - 1, j + c.at(i));
      to.at(50 * n * i + j).emplace_back(50 * n * i + next, d.at(i));
    }
  }
  vector<int64_t> cost(50 * n * n, inf);
  priority_queue<pair<int64_t, int>> q;
  q.emplace(0, min(s, 50 * n - 1));
  while (!q.empty()) {
    auto x = q.top();
    q.pop();
    cost.at(x.second) = min(cost.at(x.second), -x.first);
    for (auto next : to.at(x.second)) {
      if (cost.at(next.first) < inf)
        continue;
      q.emplace(x.first - next.second, next.first);
    }
  }
  for (int i = 1; i < n; i++) {
    int64_t ans = inf;
    for (int j = 0; j < 50 * n; j++) {
      ans = min(ans, cost.at(50 * n * i + j));
    }
    cout << ans << endl;
  }
}


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

using vec = vector<pair<int, int64_t>>;
using graph = vector<vec>;
constexpr int64_t inf = 1e18;

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  vector<int> u(m), v(m), a(m), b(m), c(n), d(n);
  for (int i = 0; i < m; i++) {
    cin >> u.at(i) >> v.at(i) >> a.at(i) >> b.at(i);
    u.at(i)--;
    v.at(i)--;
  }
  for (int i = 0; i < n; i++) {
    cin >> c.at(i) >> d.at(i);
  }
  graph to(50 * n * n);
  for (int i = 0; i < m; i++) {
    for (int j = a.at(i); j < 50 * n; j++) {
      to.at(50 * n * u.at(i) + j)
          .emplace_back(50 * n * v.at(i) + j - a.at(i), b.at(i));
      to.at(50 * n * v.at(i) + j)
          .emplace_back(50 * n * u.at(i) + j - a.at(i), b.at(i));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 50 * n; j++) {
      int next = min(50 * n - 1, j + c.at(i));
      to.at(50 * n * i + j).emplace_back(50 * n * i + next, d.at(i));
    }
  }
  vector<int64_t> cost(50 * n * n, inf);
  priority_queue<pair<int64_t, int>> q;
  q.emplace(0, min(s, 50 * n - 1));
  while (!q.empty()) {
    auto x = q.top();
    q.pop();
    if (cost.at(x.second) < inf)
      continue;
    cost.at(x.second) = -x.first;
    for (auto next : to.at(x.second)) {
      if (cost.at(next.first) < inf)
        continue;
      q.emplace(x.first - next.second, next.first);
    }
  }
  for (int i = 1; i < n; i++) {
    int64_t ans = inf;
    for (int j = 0; j < 50 * n; j++) {
      ans = min(ans, cost.at(50 * n * i + j));
    }
    cout << ans << endl;
  }
}
Problem p02703 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> pl3;

const ll max_n = 52;
const ll max_s = 2500;
vector<ll> c, d;
vector<pl3> g[max_n];

ll n, m;
ll s;

const ll INF = 1e15;
ll dp[max_n + 1][max_s + 1];

void dijkstra() {
  s = min(s, max_s);
  rep(i, n) rep(j, max_s + 1) dp[i][j] = INF;
  dp[0][s] = 0;

  priority_queue<pl3, vector<pl3>, greater<pl3>> que;
  que.push({0, {0, s}});

  while (!que.empty()) {
    pl3 p = que.top();
    que.pop();

    ll time = p.first;
    ll v = p.second.first;
    ll ns = p.second.second;

    if (dp[v][ns] < time)
      continue; // 後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる

    if (ns + c[v] <= max_s) {
      que.push({time + d[v], {v, ns + c[v]}});
    }

    for (pl3 x : g[v]) {
      ll w = x.first;
      ll a = x.second.first;
      ll b = x.second.second;

      if (ns < a || dp[w][ns - a] <= time + b)
        continue;
      dp[w][ns - a] = time + b;
      que.push({time + b, {w, ns - a}});
    }
  }
}

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

  cin >> n >> m >> s;
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }

  c.resize(n);
  d.resize(n);
  rep(i, n) cin >> c[i] >> d[i];

  dijkstra();

  rep(i, n - 1) {
    ll ans = INF;
    rep(j, max_s + 1) ans = min(ans, dp[i + 1][j]);
    cout << ans << "\n";
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> pl3;

const ll max_n = 52;
const ll max_s = 2500;
vector<ll> c, d;
vector<pl3> g[max_n];

ll n, m;
ll s;

const ll INF = 1e15;
ll dp[max_n + 1][max_s + 1];

void dijkstra() {
  s = min(s, max_s);
  rep(i, n) rep(j, max_s + 1) dp[i][j] = INF;
  dp[0][s] = 0;

  priority_queue<pl3, vector<pl3>, greater<pl3>> que;
  que.push({0, {0, s}});

  while (!que.empty()) {
    pl3 p = que.top();
    que.pop();

    ll time = p.first;
    ll v = p.second.first;
    ll ns = p.second.second;

    if (dp[v][ns] < time)
      continue; // 後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる

    if (ns + c[v] <= max_s && dp[v][ns + c[v]] > time + d[v]) {
      dp[v][ns + c[v]] = time + d[v];
      que.push({time + d[v], {v, ns + c[v]}});
    }

    for (pl3 x : g[v]) {
      ll w = x.first;
      ll a = x.second.first;
      ll b = x.second.second;

      if (ns < a || dp[w][ns - a] <= time + b)
        continue;
      dp[w][ns - a] = time + b;
      que.push({time + b, {w, ns - a}});
    }
  }
}

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

  cin >> n >> m >> s;
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g[u].push_back({v, {a, b}});
    g[v].push_back({u, {a, b}});
  }

  c.resize(n);
  d.resize(n);
  rep(i, n) cin >> c[i] >> d[i];

  dijkstra();

  rep(i, n - 1) {
    ll ans = INF;
    rep(j, max_s + 1) ans = min(ans, dp[i + 1][j]);
    cout << ans << "\n";
  }
}
Problem p02703 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

typedef pair<ll, pll> ppll;

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  vector<map<ll, pll>> G(n);
  for (ll i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u][v] = {a, b};
    G[v][u] = {a, b};
  }
  vec mai(n), mnu(n);
  for (ll i = 0; i < n; i++) {
    cin >> mai[i] >> mnu[i];
  }
  mat d(n, vec(50 * (n - 1) + 1, -1));
  vec ans(n, -1);
  vec mins(n, -1);
  priority_queue<ppll, vector<ppll>, greater<ppll>> q;
  s = min(s, 50 * (n - 1));
  q.push({0, {0, s}});
  while (q.size()) {
    ll td = q.top().first;
    ll f = q.top().second.first;
    ll s = q.top().second.second;
    q.pop();
    ll flag = 0;
    if (ans[f] < 0)
      ans[f] = td;
    if (d[f][s] > -1)
      continue;
    d[f][s] = td;
    mins[f] = s;
    for (auto p : G[f]) {
      ll t = p.first;
      ll co = p.second.first;
      ll v = p.second.second;
      if (s - co >= 0 && d[t][s - co] == -1) {
        q.push({td + v, {t, s - co}});
      }
    }
    for (ll i = 0; 1; i++) {
      ll ns = min(s + i * mai[f], 50 * (n - 1));
      ll nd = td + i * mnu[f];
      if (d[f][ns] == -1)
        q.push({nd, {f, ns}});
      if (ns == 50 * (n - 1))
        break;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

typedef pair<ll, pll> ppll;

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  vector<map<ll, pll>> G(n);
  for (ll i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u][v] = {a, b};
    G[v][u] = {a, b};
  }
  vec mai(n), mnu(n);
  for (ll i = 0; i < n; i++) {
    cin >> mai[i] >> mnu[i];
  }
  mat d(n, vec(50 * (n - 1) + 1, -1));
  vec ans(n, -1);
  vec mins(n, -1);
  priority_queue<ppll, vector<ppll>, greater<ppll>> q;
  s = min(s, 50 * (n - 1));
  q.push({0, {0, s}});
  while (q.size()) {
    ll td = q.top().first;
    ll f = q.top().second.first;
    ll s = q.top().second.second;
    q.pop();
    ll flag = 0;
    if (ans[f] < 0)
      ans[f] = td;
    if (d[f][s] > -1)
      continue;
    d[f][s] = td;
    mins[f] = s;
    for (auto p : G[f]) {
      ll t = p.first;
      ll co = p.second.first;
      ll v = p.second.second;
      if (s - co >= 0 && d[t][s - co] == -1) {
        q.push({td + v, {t, s - co}});
      }
    }
    ll ns = min(s + mai[f], 50 * (n - 1));
    ll nd = td + mnu[f];
    if (d[f][ns] == -1)
      q.push({nd, {f, ns}});
  }
  for (ll i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02703 (Python)

Buggy submission (status: Time Limit Exceeded):
import heapq

N, M, init_silver = map(int, input().split())
MAX_COST = 2500
init_silver = min(init_silver, MAX_COST)

G = [[] for _ in range(N)]
for i in range(M):
    u, v, silver_cost, time_cost = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append([v, silver_cost, time_cost])
    G[v].append([u, silver_cost, time_cost])

change_rate, change_cost = [], []
for i in range(N):
    rate, cost = map(int, input().split())
    change_rate.append(rate)
    change_cost.append(cost)


# dp[i][silver] := 頂点iにいて銀貨をsilver枚持っているような状況を作るために必要な最小時間
dp = [[float("inf")] * (MAX_COST + 1) for _ in range(N)]
dp[0][init_silver] = 0

# 優先度付きキュー: (time, node, silver)
hq = [(0, 0, init_silver)]
while hq:
    time, node, silver = heapq.heappop(hq)

    self_loop_silver = min(silver + change_rate[node], MAX_COST)
    self_loop_cost = time + change_cost[node]
    if self_loop_cost < dp[node][self_loop_silver]:
        dp[node][self_loop_silver] = self_loop_cost
        heapq.heappush(hq, (time + change_cost[node], node, self_loop_silver))

    for to, silver_cost, time_cost in G[node]:
        remain_silver = min(silver - silver_cost, MAX_COST)
        if remain_silver < 0:
            continue

        dp_next_value = time + time_cost
        if dp[to][remain_silver] < dp_next_value:
            continue

        dp[to][remain_silver] = dp_next_value
        heapq.heappush(hq, (dp_next_value, to, remain_silver))

print(*[min(d) for d in dp[1:]], sep="\n")


Fixed submission:
import heapq

N, M, init_silver = map(int, input().split())
MAX_COST = 2500
init_silver = min(init_silver, MAX_COST)

G = [[] for _ in range(N)]
for i in range(M):
    u, v, silver_cost, time_cost = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append([v, silver_cost, time_cost])
    G[v].append([u, silver_cost, time_cost])

change_rate, change_cost = [], []
for i in range(N):
    rate, cost = map(int, input().split())
    change_rate.append(rate)
    change_cost.append(cost)


# dp[i][silver] := 頂点iにいて銀貨をsilver枚持っているような状況を作るために必要な最小時間
dp = [[float("inf")] * (MAX_COST + 1) for _ in range(N)]
dp[0][init_silver] = 0

# 優先度付きキュー: (time, node, silver)
hq = [(0, 0, init_silver)]
while hq:
    time, node, silver = heapq.heappop(hq)

    self_loop_silver = min(silver + change_rate[node], MAX_COST)
    self_loop_cost = time + change_cost[node]
    if self_loop_cost < dp[node][self_loop_silver]:
        dp[node][self_loop_silver] = self_loop_cost
        heapq.heappush(hq, (time + change_cost[node], node, self_loop_silver))

    for to, silver_cost, time_cost in G[node]:
        remain_silver = min(silver - silver_cost, MAX_COST)
        if remain_silver < 0:
            continue

        dp_next_value = time + time_cost
        if dp[to][remain_silver] <= dp_next_value:
            continue

        dp[to][remain_silver] = dp_next_value
        heapq.heappush(hq, (dp_next_value, to, remain_silver))

print(*[min(d) for d in dp[1:]], sep="\n")
Problem p02705 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n - sum(a) >= 0:
    print(n - sum(a))
else:
    print(-1)


Fixed submission:
import math

r = int(input())
print(2 * r * math.pi)
Problem p02705 (Python)

Buggy submission (status: Runtime Error):
import math

print(int(input()) * 2 * math.pi())


Fixed submission:
import math

print(int(input()) * 2 * math.pi)
Problem p02705 (Python)

Buggy submission (status: Runtime Error):
# coding: utf-8


def main():
    R = input(int())
    return R * 2 * 3.1415


print(main())


Fixed submission:
# coding: utf-8


def main():
    R = int(input())

    return R * 2 * 3.1415


print(main())
Problem p02705 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <math.h>
#define PI acos(-1)

using namespace std;

int main() {
  int n;
  scanf("%lld", &n);
  printf("%lf", 2 * n * PI);
}

Fixed submission:
#include <cstdio>
#include <math.h>
#define PI acos(-1)

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  printf("%lf", 2 * n * PI);
}
Problem p02705 (Python)

Buggy submission (status: Runtime Error):
import math

r = input()
print(2 * math.pi * r)
quit()


Fixed submission:
import math

r = int(input())
print(2 * math.pi * r)
quit()
Problem p02705 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define all(ct) ct.begin(), ct.end()
#define endl "\n"
#define fr(i, a) for (auto i : a)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define in(d, v) d.find(v) != d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return modexp((x * x) % md, n / 2, md);
  return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main() {
  fastio;
  // clock_t tm = clock();
  ll n, m, s = 0;
  cin >> n >> m;
  vl a(m);
  f(i, 0, m) {
    cin >> a[i];
    s += a[i];
  }
  if (s > n)
    cout << -1 << endl;
  else
    cout << n - s << endl;
  // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define all(ct) ct.begin(), ct.end()
#define endl "\n"
#define fr(i, a) for (auto i : a)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define in(d, v) d.find(v) != d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return modexp((x * x) % md, n / 2, md);
  return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main() {
  fastio;
  // clock_t tm = clock();
  double r;
  cin >> r;
  double ans = 2 * PI * r;
  cout << setprecision(8) << ans << endl;
  // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}
Problem p02705 (C++)

Buggy submission (status: Runtime Error):
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define gcd(a, b) __gcd(a, b);
int main() {
  fastio;
  ll n, m, i, s = 0;
  cin >> n >> m;
  vector<ll> v(m);
  for (i = 0; i < m; i++) {
    cin >> v[i];
  }
  for (i = 0; i < m; i++) {
    s = s + v[i];
  }
  if (s > n)
    cout << "-1" << endl;
  else {
    cout << n - s << endl;
  }
}


Fixed submission:
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define gcd(a, b) __gcd(a, b);
int main() {
  fastio;
  double ans, r, p = 3.1416;
  cin >> r;
  ans = p * r * 2;
  cout << ans << endl;
}