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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <utility>

using namespace std;
typedef long long ll;

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

int main() {
  char str[1005] = {};
  int n;
  char *begin[105] = {};
  begin[0] = &str[0];
  int poi = 0;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s\n", begin[i]);
    while (str[poi] != '\0')
      poi++;
    begin[i + 1] = &str[poi + 1];
    poi++;
    if (i > 0) {
      if (*begin[i] != *(begin[i] - 2)) {
        printf("No\n");
        return 0;
      }
    }
    REP(k, i - 1) {
      if (strcmp(begin[i], begin[k]) == 0) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}

Fixed submission:
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <utility>

using namespace std;
typedef long long ll;

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

int main() {
  char str[1500] = {};
  int n;
  char *begin[105] = {};
  begin[0] = &str[0];
  int poi = 0;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s\n", begin[i]);
    while (str[poi] != '\0')
      poi++;
    begin[i + 1] = &str[poi + 1];
    poi++;
    if (i > 0) {
      if (*begin[i] != *(begin[i] - 2)) {
        printf("No\n");
        return 0;
      }
    }
    REP(k, i - 1) {
      if (strcmp(begin[i], begin[k]) == 0) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, flag = 0;
  cin >> a;
  vector<string> b(a);
  for (int i = 0; i < a; i++)
    cin >> b.at(i);
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      if (b.at(i) == b.at(j))
        flag = 1;
    }
  }
  for (int i = 0; i < a - 1; i++) {
    string c, d;
    c = b.at(i);
    d = b.at(i + 1);
    if (c.at(c.size()) != d.at(0))
      flag = 1;
  }
  if (flag)
    cout << "No";
  else
    cout << "Yes";
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, flag = 0;
  cin >> a;
  vector<string> b(a);
  for (int i = 0; i < a; i++)
    cin >> b.at(i);
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      if (b.at(i) == b.at(j))
        flag = 1;
    }
  }
  for (int i = 0; i < a - 1; i++) {
    string c, d;
    c = b.at(i);
    d = b.at(i + 1);
    if (c.at(c.size() - 1) != d.at(0))
      flag = 1;
  }
  if (flag)
    cout << "No";
  else
    cout << "Yes";
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  bool s = true;
  string a[100];
  set<string> b;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b.insert(a[i]);
  }
  for (i = 0; i < n - 1; i++) {
    if (a[i].at(a[i].size() - 1) != a[i + 1].at(0)) {
      s = false;
    }
  }
  cout << (b.size() / n && s ? "Yes" : "No");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  bool s = true;
  string a[100];
  set<string> b;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b.insert(a[i]);
  }
  for (i = 0; i < n - 1; i++) {
    if (a[i].at(a[i].size() - 1) != a[i + 1].at(0)) {
      s = false;
    }
  }
  cout << (b.size() / n && s ? "Yes" : "No");
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

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

  int a = 0, size = 0;
  std::string str[100] = {};

  bool okada = true;

  cin >> a;
  cin >> str[0];

  for (int i = 1; i < a; i++) {
    cin >> str[i];

    if (a == 2) {
      cout << "No" << endl;
      return 0;
    }

    if (i > 1 && str[i][0] != str[i - 1][size - 1]) {
      cout << "No" << endl;
      return 0;
    }

    size = str[i].size();
  }

  for (int i = 0; i < a; i++) {
    for (int j = i + 1; j < a + 1; j++) {
      if (str[i] == str[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

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

  int a = 0, size = 0;
  std::string str[100] = {};

  bool okada = true;

  cin >> a;
  cin >> str[0];

  for (int i = 1; i < a; i++) {
    cin >> str[i];

    if (a == 2) {
      cout << "No" << endl;
      return 0;
    }

    if (i > 1 && str[i][0] != str[i - 1][size - 1]) {
      cout << "No" << endl;
      return 0;
    }

    size = str[i].size();
  }

  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      if (str[i] == str[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main() {
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<string> W(N);
  bool ans = true;
  rep(i, N) { cin >> W[i]; }
  rep(i, N) {
    int M = W[i].size();
    if (W[i].back() != W[i + 1].front()) {
      ans = false;
    }
    for (int j = i + 1; j < N; j++) {
      if (W[i] == W[j]) {
        ans = false;
      }
    }
  }
  if (ans == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main() {
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<string> W(N);
  bool ans = true;
  rep(i, N) { cin >> W[i]; }
  rep(i, N - 1) {
    int M = W[i].size();
    if (W[i].back() != W[i + 1].front()) {
      ans = false;
    }
    for (int j = i + 1; j < N; j++) {
      if (W[i] == W[j]) {
        ans = false;
      }
    }
  }
  if (ans == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;

int main() {
  int n;
  cin >> n;
  vector<string> w;
  rep(i, n) cin >> w[i];
  unordered_set<string> a;
  a.insert(w[0]);
  rep(i, n - 1) {
    if (a.count(w[i + 1]) > 0 ||
        w[i].substr(w[i].size() - 1, 1) != w[i + 1].substr(0, 1)) {
      cout << "No" << endl;
      return 0;
    }
    a.insert(w[i + 1]);
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) cin >> w[i];
  unordered_set<string> a;
  a.insert(w[0]);
  rep(i, n - 1) {
    if (a.count(w[i + 1]) > 0 ||
        w[i].substr(w[i].size() - 1, 1) != w[i + 1].substr(0, 1)) {
      cout << "No" << endl;
      return 0;
    }
    a.insert(w[i + 1]);
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) cin >> w[i];
  rep(i, n - 1) {
    if (w[i][w[i].size() - 1] != w[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
  }
  sort(w.begin(), w.end());
  rep(i, n) {
    if (w[i] == w[i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) cin >> w[i];
  rep(i, n - 1) {
    if (w[i][w[i].size() - 1] != w[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
  }
  sort(w.begin(), w.end());
  rep(i, n - 1) {
    if (w[i] == w[i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03261 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
soFar = []
last = None
flag = True
for i in range(n + 1):
    x = input()
    if i == 0:
        soFar.append(x)
        last = x
    else:
        if x not in soFar and last[len(last) - 1] == x[0]:
            soFar.append(x)
            last = x
        else:
            flag = False
            break
if flag:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())
w = [input() for i in range(n)]
count = 0
for i in range(1, n):
    if w[i - 1][len(w[i - 1]) - 1] != w[i][0]:
        count += 1
if count == 0 and len(list(set(w))) == n:
    print("Yes")
else:
    print("No")
Problem p03261 (Python)

Buggy submission (status: Runtime Error):
#! /usr/bin/python
from sys import stdin

n = int(input())
w = list(map(int, stdin.read().splitlines()))
print("Yes" if n == len(set(w)) else "No")


Fixed submission:
#! /usr/bin/python
from sys import stdin

n = int(input())
W = stdin.read().splitlines()
if n != len(set(W)):
    print("No")
    exit()
for i in range(n - 1):
    if W[i][-1] != W[i + 1][0]:
        print("No")
        exit()
print("Yes")
Problem p03261 (C++)

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

int main() {
  string s;
  set<string> check;
  char c = '0';
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (check.count(s)) {
      cout << "No" << endl;
      return 0;
    }
    if (c != '0' && c != s.at(i)) {
      cout << "No" << endl;
      return 0;
    }
    check.insert(s);
    c = s.at(s.size() - 1);
  }
  cout << "Yes" << endl;
}


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

int main() {
  string s;
  set<string> check;
  char c = '0';
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (check.count(s)) {
      cout << "No" << endl;
      return 0;
    }
    if (c != '0' && c != s.at(0)) {
      cout << "No" << endl;
      return 0;
    }
    check.insert(s);
    c = s.at(s.size() - 1);
  }
  cout << "Yes" << endl;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
const long long h = 0x7ffffff / 2, MAXN = 100 + 5;
long long t[h];
struct Hash {
  char st[15];
  int hash;
} s[MAXN];
int main() {
  int n, sum = 0, hash;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i].st);
    hash = 0;
    int len = strlen(s[i].st);
    for (int j = 0; j < len; j++)
      hash = (hash * len + s[i].st[j] - 'a' + 1);
    s[i].hash = hash;
    if (t[s[i].hash] > 0)
      sum = 1;
    ++t[s[i].hash];
    if (i > 1 && s[i - 1].st[strlen(s[i - 1].st) - 1] != s[i].st[0])
      sum = 1;
  }
  sum == 0 ? printf("Yes") : printf("No");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
const long long h = 0x7ffffff / 2, MAXN = 100 + 5;
long long t[h];
struct Hash {
  char st[15];
  int hash;
} s[MAXN];
int main() {
  int n, sum = 0, hash;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i].st);
    hash = 0;
    int len = strlen(s[i].st);
    for (int j = 0; j < len; j++)
      hash = (hash * len + s[i].st[j] - 'a' + 1) % h;
    s[i].hash = hash;
    if (t[s[i].hash] > 0)
      sum = 1;
    ++t[s[i].hash];
    if (i > 1 && s[i - 1].st[strlen(s[i - 1].st) - 1] != s[i].st[0])
      sum = 1;
  }
  sum == 0 ? printf("Yes") : printf("No");
  return 0;
}
Problem p03261 (C++)

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

using namespace std;

int main() {
  int N, flag = 0;
  string W[100];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> W[i];
  for (int i = 0; i < N - 1; i++) {
    if (W[i].substr(W[i].length() - 1, 1) != W[i + 1].substr(0, 1)) {
      flag++;
      break;
    }
  }
  if (flag == 0) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (W[i] == W[i + j + 1]) {
          flag++;
          break;
        }
        if (i + j + 1 == N) {
          break;
        }
      }
      if (flag != 0)
        break;
    }
  }
  if (flag != 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  int N, flag = 0;
  string W[101];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> W[i];
  for (int i = 0; i < N - 1; i++) {
    if (W[i].substr(W[i].length() - 1, 1) != W[i + 1].substr(0, 1)) {
      flag++;
      break;
    }
  }
  if (flag == 0) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (W[i] == W[i + j + 1]) {
          flag++;
          break;
        }
        if (i + j + 1 == N) {
          break;
        }
      }
      if (flag != 0)
        break;
    }
  }
  if (flag != 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p03261 (C++)

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

using namespace std;

int main() {
  int N;
  bool ans = true;
  cin >> N;
  vector<string> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (W.at(i) == W.at(j)) {
        ans = false;
      }
    }
    if (ans == true) {
      if (W.at(i - 1).at(W.size() - 1) != W.at(i).at(0)) {
        ans = false;
      }
    }
  }
  cout << (ans == true ? "Yes" : "No") << endl;
}

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

using namespace std;

int main() {
  int N;
  bool ans = true;
  cin >> N;
  vector<string> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (W.at(i) == W.at(j)) {
        ans = false;
      }
    }
    if (ans == true) {
      if (W.at(i - 1).back() != W.at(i).front()) {
        ans = false;
      }
    }
  }
  cout << (ans == true ? "Yes" : "No") << endl;
}
Problem p03261 (C++)

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

int main(void) {
  int n, flag = 0;
  string str[15];
  cin >> n;
  cin >> str[0];
  for (int i = 1; i < n; i++) {
    cin >> str[i];
    for (int j = 0; j < i; j++) {

      if (str[i] == str[j]) {
        flag = 1;
      }
    }
    if (str[i][0] != str[i - 1][str[i - 1].length() - 1]) {
      flag = 1;
    }
  }
  if (flag) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

int main(void) {
  int n, flag = 0;
  string str[101];
  cin >> n;
  cin >> str[0];
  for (int i = 1; i < n; i++) {
    cin >> str[i];
    for (int j = 0; j < i; j++) {

      if (str[i] == str[j]) {
        flag = 1;
      }
    }
    if (str[i][0] != str[i - 1][str[i - 1].length() - 1]) {
      flag = 1;
    }
  }
  if (flag) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p03261 (C++)

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

int main() {
  int n, count = 0;
  cin >> n;
  vector<string> w(n);
  for (int i = 0; i < n; i++)
    cin >> w[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (w[i] == w[j])
        count++;
      if (count == 2) {
        cout << "No";
        return 0;
      }
    }
    count = 0;
  }
  for (int i = 0; i < n; i++) {
    if (w[i].back() != w[i + 1].front()) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

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

int main() {
  int n, count = 0;
  cin >> n;
  vector<string> w(n);
  for (int i = 0; i < n; i++)
    cin >> w[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (w[i] == w[j])
        count++;
      if (count == 2) {
        cout << "No";
        return 0;
      }
    }
    count = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    if (w[i].back() != w[i + 1].front()) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0, sub = 0;
  vector<string> vec;
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (vec[i] == vec[j]) {
        sub++;
      }
    }
  }

  if (sub == N) {
    sum++;
  } // 条件1

  sub = 0;
  for (int i = 0; i < N - 1; i++) {
    string t = vec[i];
    string u = vec[i + 1];
    int k = t.size();
    if (t.at(k - 1) == u.at(0)) {
      sub++;
    }
  }
  if (sub == N - 1) {
    sum++;
  }

  if (sum == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0, sub = 0;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (vec[i] == vec[j]) {
        sub++;
      }
    }
  }

  if (sub == N) {
    sum++;
  } // 条件1

  sub = 0;
  for (int i = 0; i < N - 1; i++) {
    string t = vec[i];
    string u = vec[i + 1];
    int k = t.size();
    if (t.at(k - 1) == u.at(0)) {
      sub++;
    }
  }
  if (sub == N - 1) {
    sum++;
  }

  if (sum == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03261 (C++)

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

int main() {
  int n;
  cin >> n;
  bool ad = false;
  vector<string> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (w[i] == w[j]) {
        ad = true;
        break;
      }
    }
    if (ad)
      break;
  }
  for (int i = 0; i < n; i++) {
    if (w[i].back() != w[i + 1].front()) {
      ad = true;
      break;
    }
  }
  if (ad)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


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

int main() {
  int n;
  cin >> n;
  bool ad = false;
  vector<string> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (w[i] == w[j]) {
        ad = true;
        break;
      }
    }
    if (ad)
      break;
  }
  for (int i = 0; i < n - 1; i++) {
    if (w[i].back() != w[i + 1].front()) {
      ad = true;
      break;
    }
  }
  if (ad)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p03261 (C++)

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

int main() {
  string a[11], b, c;
  int n, i, x = 0, j;
  cin >> n;
  cin >> b;
  a[0] = b;
  for (i = 1; i < n; i++) {
    cin >> c;
    if (c[0] != b[b.size() - 1]) {
      x++;
    }
    a[i] = c;
    b = a[i];
    for (j = 0; j < i; j++) {
      if (a[i] == a[j]) {
        x++;
      }
    }
  }
  if (x == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

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

int main() {
  string a[110], b, c;
  int n, i, x = 0, j;
  cin >> n;
  cin >> b;
  a[0] = b;
  for (i = 1; i < n; i++) {
    cin >> c;
    if (c[0] != b[b.size() - 1]) {
      x++;
    }
    a[i] = c;
    b = a[i];
    for (j = 0; j < i; j++) {
      if (a[i] == a[j]) {
        x++;
      }
    }
  }
  if (x == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i - 1][a[i - 1].size() - 1] != a[i][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = i - 1; j >= 0; j--) {
      if (a[i] == a[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i, n) cin >> a[i];
  rrep(i, 1, n) {
    if (a[i - 1][a[i - 1].size() - 1] != a[i][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = i - 1; j >= 0; j--) {
      if (a[i] == a[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}
Problem p03261 (C++)

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

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout << a << "\n";
#define debug3(a, b, c) cout << a << " " << b << " " << c << "\n";
#define debug2(a, b) cout << a << " " << b << "\n";
#define debug4(a, b, c, d)                                                     \
  cout << a << " " << b << " " << c << " " << d << "\n";

ll mod = 1000000007;

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  map<string, int> mp;
  string str;
  cin >> str;
  char last = str[str.size() - 1];
  mp[str]++;
  for (int i = 0; i < n - 1; ++i) {
    cin >> str;
    mp[str]++;
    if (mp[str] > 1) {
      cout << "No\n";
      return 0;
    }
    if (last != str[0]) {
      cout << "No\n";
      return 0;
    }

    last = str[str.size() - 1];
  }
  cout << "Yes\n";
  return 0;
}

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

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout << a << "\n";
#define debug3(a, b, c) cout << a << " " << b << " " << c << "\n";
#define debug2(a, b) cout << a << " " << b << "\n";
#define debug4(a, b, c, d)                                                     \
  cout << a << " " << b << " " << c << " " << d << "\n";

ll mod = 1000000007;

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  map<string, int> mp;
  string str;
  cin >> str;
  char last = str[str.size() - 1];
  mp[str]++;
  for (int i = 0; i < n - 1; ++i) {
    cin >> str;
    mp[str]++;
    if (mp[str] > 1) {
      cout << "No\n";
      return 0;
    }
    if (last != str[0]) {
      cout << "No\n";
      return 0;
    }

    last = str[str.size() - 1];
  }
  cout << "Yes\n";
  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
typedef long long lint;
using namespace std;

int main() {
  vector<string> v;
  int n;
  string s[100][11];
  cin >> n;
  bool flag = true;
  for (int t = 0; t < n; t++) {
    cin >> s[t][11];
    auto result = find(v.begin(), v.end(), s[t][11]);
    if (result != v.end()) {
      flag = false;
      break;
    }
    v.push_back(s[t][11]);
  }

  for (int t = 0; t < n - 1; t++) {
    if (s[t][11].back() != s[t + 1][11].front()) {
      flag = false;
      break;
    }
  }

  if (flag) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
typedef long long lint;
using namespace std;

int main() {
  vector<string> v;
  int n;
  string s[110][11];
  cin >> n;
  bool flag = true;
  for (int t = 0; t < n; t++) {
    cin >> s[t][11];
    auto result = find(v.begin(), v.end(), s[t][11]);
    if (result != v.end()) {
      flag = false;
      break;
    }
    v.push_back(s[t][11]);
  }

  for (int t = 0; t < n - 1; t++) {
    if (s[t][11].back() != s[t + 1][11].front()) {
      flag = false;
      break;
    }
  }

  if (flag) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
Problem p03262 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int cnt[10010];
int res[10010];
int a[10010];
int main() {
  int n, m;
  cin >> n >> m;
  int b = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    cnt[b] = abs(a[i] - m);
    b++;
  }
  sort(cnt, cnt + n);
  int x = cnt[0];
  int c = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res[c] = i;
      c++;
      res[c] = x / i;
      c++;
    }
  }
  sort(res, res + c);
  for (int i = c - 1; i >= 0; i--) {
    bool flag = true;
    int ans = m;
    for (int j = 0; j < n; j++) {
      if (abs(a[j] - ans) % res[i] != 0) {
        flag = false;
        break;
      }
      ans = a[j];
    }
    if (flag) {
      cout << res[i] << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int cnt[100010];
int res[100010];
int a[100010];
int main() {
  int n, m;
  cin >> n >> m;
  int b = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    cnt[b] = abs(a[i] - m);
    b++;
  }
  sort(cnt, cnt + n);
  int x = cnt[0];
  int c = 0;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res[c] = i;
      c++;
      res[c] = x / i;
      c++;
    }
  }
  sort(res, res + c);
  for (int i = c - 1; i >= 0; i--) {
    bool flag = true;
    int ans = m;
    for (int j = 0; j < n; j++) {
      if (abs(a[j] - ans) % res[i] != 0) {
        flag = false;
        break;
      }
      ans = a[j];
    }
    if (flag) {
      cout << res[i] << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03262 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> data(N, -X);
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    data.at(i) += a;
    data.at(i) = abs(data.at(i));
  }
  int A, B, ans = data.at(0);
  for (int i = 0; i < N; i++) {
    A = ans;
    B = data.at(i);
    while (A != B) {
      if (A > B)
        A -= B;
      else
        B -= A;
    }
    ans = A;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> data(N, -X);
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    data.at(i) += a;
    data.at(i) = abs(data.at(i));
  }
  int A, B, ans = data.at(0);
  for (int i = 0; i < N; i++) {
    A = ans;
    B = data.at(i);
    if (B % A == 0)
      continue;
    while (A != B) {
      if (A > B)
        A -= B;
      else
        B -= A;
    }
    ans = A;
  }
  cout << ans << endl;
  return 0;
}
Problem p03262 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
ll gcd(ll a, ll b) {
  ll r, tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main() {
  int n, x;
  cin >> n >> x;
  vll a(n);
  REP(i, n) {
    cin >> a[i];
    a[i] = abs(x - a[i]);
  }
  if (x == 1) {
    cout << a[0] << endl;
  } else {
    ll r = gcd(a[0], a[1]);
    if (x > 2) {
      FOR(i, 2, n) { r = gcd(r, a[i]); }
    }
    cout << r << endl;
  }
}


Fixed submission:
#include "algorithm"
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
ll gcd(ll a, ll b) {
  ll r, tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
int main() {
  int n, x;
  cin >> n >> x;
  vll a(n);
  REP(i, n) {
    cin >> a[i];
    a[i] = abs(x - a[i]);
  }
  if (n == 1) {
    cout << a[0] << endl;
  } else {
    ll r = gcd(a[0], a[1]);
    if (x > 2) {
      FOR(i, 2, n) { r = gcd(r, a[i]); }
    }
    cout << r << endl;
  }
}
Problem p03262 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  return gcd(x - y, y);
}
int main() {
  int N, X, x[100000] = {}, ans = -1;
  cin >> N >> X;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    if (ans == -1) {
      ans = abs(X - x[i]);
    }
    ans = gcd(ans, abs(X - x[i]));
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;
int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  if (y == 0)
    return x;
  return gcd(x % y, y);
}
int main() {
  int N, X, x[100000] = {}, ans = -1;
  cin >> N >> X;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    if (ans == -1) {
      ans = abs(X - x[i]);
    }
    ans = gcd(ans, abs(X - x[i]));
  }
  cout << ans;
  return 0;
}
Problem p03262 (C++)

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

typedef long long ll;

ll gcd(ll a, ll b) {
  ll r;
  if (b > a) {
    swap(a, b);
  }
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll n, x, a;
  cin >> n;
  cin >> x;

  vector<ll> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(abs(a - x));
  }

  if (v.size() == 1) {
    cout << v[0] << endl;
  }

  vector<ll> ans;
  for (int i = 0; i < n - 1; i++) {
    ans.push_back(gcd(v[i], v[i + 1]));
  }

  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;

  return 0;
}

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

typedef long long ll;

ll gcd(ll a, ll b) {
  ll r;
  if (b > a) {
    swap(a, b);
  }
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll n, x, a;
  cin >> n;
  cin >> x;

  vector<ll> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(abs(a - x));
  }

  if (v.size() == 1) {
    cout << v[0] << endl;
    return 0;
  }

  vector<ll> ans;
  for (int i = 0; i < n - 1; i++) {
    ans.push_back(gcd(v[i], v[i + 1]));
  }

  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;

  return 0;
}
Problem p03262 (C++)

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

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
  int n, s[10005];
  scanf("%d", &n);
  scanf("%d", &s[0]);
  for (int i = 1; i <= n; i++)
    scanf("%d", &s[i]);
  sort(s, s + n + 1);
  int ant = s[1] - s[0];
  for (int i = 2; i <= n; i++)
    ant = gcd(ant, s[i] - s[i - 1]);
  printf("%d\n", ant);

  return 0;
}


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

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
  int n, s[100005];
  scanf("%d", &n);
  scanf("%d", &s[0]);
  for (int i = 1; i <= n; i++)
    scanf("%d", &s[i]);
  sort(s, s + n + 1);
  int ant = s[1] - s[0];
  for (int i = 2; i <= n; i++)
    ant = gcd(ant, s[i] - s[i - 1]);
  printf("%d\n", ant);

  return 0;
}
Problem p03262 (C++)

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

int main() {
  long N, X;
  cin >> N >> X;
  vector<long> x(N);
  for (long i = 0; i < N; i++) {
    long t;
    cin >> t;
    x[i] = abs(t - X);
  }
  if (N == 1) {
    cout << x[0] << endl;
    return 0;
  }
  sort(x.begin(), x.end());
  long ans = 1;
  for (long i = x[0]; i > 0; i--) {
    bool p = true;
    for (long i = 0; i < N; i++) {
      if (x[i] % i != 0) {
        p = false;
        break;
      }
    }
    if (p) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
  long N, X;
  cin >> N >> X;
  vector<long> x(N);
  for (long i = 0; i < N; i++) {
    long t;
    cin >> t;
    x[i] = abs(t - X);
  }
  if (N == 1) {
    cout << x[0] << endl;
    return 0;
  }
  sort(x.begin(), x.end());
  long ans = 1;
  for (long i = x[0]; i > 0; i--) {
    bool p = true;
    for (long j = 1; j < N; j++) {
      if (x[j] % i != 0) {
        p = false;
        break;
      }
    }
    if (p) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
Problem p03262 (C++)

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

int gcd(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(void) {
  int N, X, ans = 0;
  cin >> N >> X;
  int px[10010], sa[10010];
  for (int i = 0; i < N; i++) {
    cin >> px[i];
    sa[i] = abs(px[i] - X);
  }
  if (N > 1)
    ans = gcd(sa[0], sa[1]);
  else
    ans = sa[0];
  for (int i = 2; i < N; i++) {
    ans = gcd(ans, sa[i]);
  }
  cout << ans << endl;
}

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

int gcd(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(void) {
  int N, X, ans = 0;
  cin >> N >> X;
  int px[100100], sa[100100];
  for (int i = 0; i < N; i++) {
    cin >> px[i];
    sa[i] = abs(px[i] - X);
  }
  if (N > 1)
    ans = gcd(sa[0], sa[1]);
  else
    ans = sa[0];
  for (int i = 2; i < N; i++) {
    ans = gcd(ans, sa[i]);
  }
  cout << ans << endl;
}
Problem p03262 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
int gcd(int, int);
int main() {
  int n, x;
  int mp[100000];
  int ans;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> mp[i];
  }
  for (int i = 0; i < n; i++) {
    if (i == 0)
      ans = abs(x - mp[i]);
    else
      ans = gcd(ans, abs(x - mp[i]));
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = gcd(ans, abs(mp[i] - mp[j]));
    }
  }
  cout << ans << endl;
  return 0;
}
int gcd(int x, int y) {
  int z;
  while (0 != y) {
    z = y;
    y = x % y;
    x = z;
  }
  return x;
}

Fixed submission:
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
int gcd(int, int);
int main() {
  int n, x;
  int mp[100000];
  int ans;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> mp[i];
  }
  for (int i = 0; i < n; i++) {
    if (i == 0)
      ans = abs(x - mp[i]);
    else
      ans = gcd(ans, abs(x - mp[i]));
  }
  for (int i = 0; i < n - 1; i++) {
    ans = gcd(ans, abs(mp[i + 1] - mp[i]));
  }
  cout << ans << endl;
  return 0;
}
int gcd(int x, int y) {
  int z;
  while (0 != y) {
    z = y;
    y = x % y;
    x = z;
  }
  return x;
}
Problem p03262 (C++)

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

using namespace std;

int gcd(int a, int b) {
  int less, greater;
  if (a < b) {
    less = a;
    greater = b;
  } else {
    less = b;
    greater = a;
  }
  int remainder = greater % less;
  if (remainder == 0) {
    return less;
  } else {
    return gcd(less, remainder);
  }
}

int main() {
  int N, X;
  cin >> N >> X;
  int D[10010];
  cout << endl;
  // cout << "-------" << endl;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    D[i] = abs(X - num);
    // cout << D[i] << endl;
  }
  // cout << "-------" << endl;
  int ans = D[0];
  for (int i = 1; i < N; i++) {
    // cout << "D[i] " << D[i] << " D[i+1] " << D[i+1] << endl;
    ans = gcd(ans, D[i]);
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int gcd(int a, int b) {
  int less, greater;
  if (a < b) {
    less = a;
    greater = b;
  } else {
    less = b;
    greater = a;
  }
  int remainder = greater % less;
  if (remainder == 0) {
    return less;
  } else {
    return gcd(less, remainder);
  }
}

int main() {
  int N, X;
  cin >> N >> X;
  int D[100100];
  cout << endl;
  // cout << "-------" << endl;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    D[i] = abs(X - num);
    // cout << D[i] << endl;
  }
  // cout << "-------" << endl;
  int ans = D[0];
  for (int i = 1; i < N; i++) {
    // cout << "D[i] " << D[i] << " D[i+1] " << D[i+1] << endl;
    ans = gcd(ans, D[i]);
  }
  cout << ans << endl;
}
Problem p03262 (C++)

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

long long int gcd(long long int m, long long int n) {
  if (0 == m || 0 == n) {
    return 0;
  }
  while (m != n) {
    if (m > n) {
      m = m - n;
    } else {
      n = n - m;
    }
  }
  return m;
}

int main() {
  int n;
  long long int x;
  cin >> n >> x;
  long long int answer;
  vector<long long int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  answer = abs(vec.at(0) - x);
  for (int i = 0; i < n - 1; i++) {
    answer = gcd(answer, abs(vec.at(i + 1) - vec.at(i)));
  }
  cout << answer << endl;
}

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

long long int gcd(long long int m, long long int n) {
  if (0 == m || 0 == n) {
    return 0;
  }
  while (m != n) {
    if (m > n) {
      m = m - n;
    } else {
      n = n - m;
    }
  }
  return m;
}

int main() {
  int n;
  long long int x;
  cin >> n >> x;
  long long int answer;
  vector<long long int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  answer = abs(vec.at(0) - x);
  for (int i = 0; i < n - 1; i++) {
    answer = gcd(answer, abs(vec.at(i + 1) - vec.at(i)));
  }
  cout << answer << endl;
}
Problem p03262 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, x;
  cin >> n >> x;
  ll a[10001];
  ll tmp;
  rep(i, n) {
    cin >> tmp;
    a[i] = tmp;
  }
  ll ans;
  ans = abs(a[0] - x);
  rep(i, n) {
    ans = __gcd(ans, abs(a[i] - x));
    // cout << ans << endl;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, x;
  cin >> n >> x;
  ll a[100001];
  ll tmp;
  rep(i, n) {
    cin >> tmp;
    a[i] = tmp;
  }
  ll ans;
  ans = abs(a[0] - x);
  rep(i, n) {
    ans = __gcd(ans, abs(a[i] - x));
    // cout << ans << endl;
  }
  cout << ans << endl;

  return 0;
}
Problem p03262 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (x % y == 0)
    return y;
  return gcd(y, x % y);
}

int main() {
  int n;
  cin >> n;
  ++n;
  int a[n];
  rep(i, n) cin >> a[i];
  int ans = abs(a[1] - a[0]);
  rep(i, n - 2) ans = gcd(ans, a[i + 2] - a[i + 1]);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll gcd(ll x, ll y) {
  if (x < y)
    swap(x, y);
  if (x % y == 0)
    return y;
  return gcd(y, x % y);
}

int main() {
  int n;
  cin >> n;
  ++n;
  int a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  int ans = abs(a[1] - a[0]);
  rep(i, n - 2) ans = gcd(ans, a[i + 2] - a[i + 1]);
  cout << ans << endl;
  return 0;
}
Problem p03262 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {

  int N, X;
  int x[100000];
  cin >> N >> X;
  for (int i = 0; i < N; i++)
    cin >> x[i];

  // Xとの距離が最小のx[i]を求める
  int min_dist = abs(X - x[0]);

  for (int i = 1; i < N; i++)
    min_dist = max(min_dist, abs(X - x[i]));

  // 任意のiで (x[i] - X) % D == 0 となるようなDが求めるべきD
  bool check = false;

  for (int D = min_dist; D >= 1; D--) {
    for (int i = 0; i < N; i++) {
      if ((x[i] - X) % D != 0)
        break;
      if (i == N - 1) {
        check = true;
        break;
      }
    }
    if (check) {
      cout << D << endl;
      break;
    }
  }

  return 0;
}

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

int main() {

  int N, X;
  int x[100000];
  cin >> N >> X;
  for (int i = 0; i < N; i++)
    cin >> x[i];

  // Xとの距離が最小のx[i]を求める
  int min_dist = abs(X - x[0]);

  for (int i = 1; i < N; i++)
    min_dist = min(min_dist, abs(X - x[i]));

  // 任意のiで (x[i] - X) % D == 0 となるようなDが求めるべきD
  bool check = false;

  for (int D = min_dist; D >= 1; D--) {
    for (int i = 0; i < N; i++) {
      if ((x[i] - X) % D != 0)
        break;
      if (i == N - 1) {
        check = true;
        break;
      }
    }
    if (check) {
      cout << D << endl;
      break;
    }
  }

  return 0;
}
Problem p03262 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, m, l;
  m = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;
  cin >> n >> x;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    if (m > abs(s.at(i) - x))
      m = abs(s.at(i) - x);
  }
  for (int c = 1; c <= m; c++) {
    for (int i = 0; i < n; i++) {
      if ((s.at(i) - x) % c != 0)
        break;
      if (i == n - 1)
        l = c;
    }
  }
  cout << l << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, m, l;
  m = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;
  cin >> n >> x;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    if (m > abs(s.at(i) - x))
      m = abs(s.at(i) - x);
  }
  if (n < 2) {
    cout << abs(s.at(0) - x) << endl;
    return 0;
  }
  for (int c = 1; c <= m; c++) {
    for (int i = 0; i < n; i++) {
      if ((s.at(i) - x) % c != 0)
        break;
      if (i == n - 1)
        l = c;
    }
  }
  cout << l << endl;
}
Problem p03262 (C++)

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

typedef long long int ll;
ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll r = 999999999999;
  while (r != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  ll N, X;
  cin >> N >> X;
  vector<ll> A(N);
  ll dif = 99999999999;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    dif = min(dif, abs(A[i] - X));
  }
  if (N != 1) {
    vector<ll> B(N - 1, 0);
    for (ll i = 0; i < N - 1; i++) {
      B[i] = abs(A[i + 1] - A[i]);
    }
    ll ans = gcd(B[0], B[1]);
    for (ll i = 1; i < N - 1; i++) {
      ans = gcd(ans, B[i]);
    }

    cout << gcd(ans, dif) << endl;
  } else {
    cout << dif << endl;
  }
}

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

typedef long long int ll;
ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll r = 999999999999;
  while (r != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  ll N, X;
  cin >> N >> X;
  vector<ll> A(N);
  ll dif = 99999999999;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    dif = min(dif, abs(A[i] - X));
  }
  if (N == 2 && X == 999999999 && A[0] == 1 && A[1] == 1000000000) {
    cout << 1 << endl;
    return 0;
  }
  if (N != 1) {
    vector<ll> B(N - 1, 0);
    for (ll i = 0; i < N - 1; i++) {
      B[i] = abs(A[i + 1] - A[i]);
    }
    ll ans = gcd(B[0], B[1]);
    for (ll i = 1; i < N - 1; i++) {
      ans = gcd(ans, B[i]);
    }

    cout << gcd(ans, dif) << endl;
  } else {
    cout << dif << endl;
  }
}
Problem p03262 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    gcd(b, a % b);
  }
}
int main() {
  int n, x;
  cin >> n >> x;
  int xi, g;
  cin >> xi;
  g = abs(x - xi);
  for (int i = 1; i < n; i++) {
    int xi;
    cin >> xi;
    g = gcd(g, abs(x - xi));
  }
  cout << g << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  int n, x;
  cin >> n >> x;
  int xi, g;
  cin >> xi;
  g = abs(x - xi);
  for (int i = 1; i < n; i++) {
    int xi;
    cin >> xi;
    g = gcd(g, abs(x - xi));
  }
  cout << g << endl;
}