Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02640 (python)

Fixed submission:
x,y = map(int,input().split())
#2a+4b = y
#x = a+b
#x-a = b
#2a+4(x-a) = y
#y = 4x-2a

for i in range(x+1):
  if y == 4*x - 2*i:
    print('Yes')
    break
else:
  print('No')

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
a = int(input())
ans = 2*a + 4(x-a)
if ans == y:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
a = int(input())
ans = 2*a + 4(x-a)
if ans == y:
  print('Yes')
else:
  print('No')
Problem p02658 (python)

Fixed submission:
n = int(input())
a = sorted(map(int, input().split()))

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    break

else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
  print(0)
  break

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    break

else:
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
  print(0)
  break

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    break

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if 0 in a:
  print(0)
  break

ans = 1
for i in a:
  ans *= a
  if ans > 10**18:
    print(-1)
    break

print(ans)
Problem p02675 (python)

Fixed submission:
n = input()
if n[-1] == '3':
  print('bon')
elif n[-1] in ['0', '1', '6', '8']:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
n = int(input())
if n[-1] == 3:
  print('bon')
elif n[-1] in ['0', '1', '6', '8']:
  print('pon')
else:
  print('hon')

Buggy submission (verdict: Runtime Error):
n = int(input())
if n[-1] == 3:
  print('bon')
elif n[-1] in [0, 1, 6, 8]:
  print('pon')
else:
  print('hon')
Problem p02755 (python)

Fixed submission:
A, B = map(int, input().split())
 
for i in range(10000):
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(i)
        break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
for i in range(10000):
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(i)
        break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
for i in range(10000):
    if int(i*0.08) == A and int(i*0.1) == B:
        print(i)
        break
else:
    print(-1)
Problem p02817 (python)

Fixed submission:
s,t=input().split()
print(t+s)

Buggy submission (verdict: Runtime Error):
s,t=input()
print(t+s)
Problem p02830 (python)

Fixed submission:
N=input()
S,T=input().split()
print(*[s+t for s,t in zip(S,T)],sep='')

Buggy submission (verdict: Runtime Error):
S,T=input().split()
print(*[s+t for s,t in zip(S,T)],sep='')
Problem p03068 (python)

Fixed submission:
N=int(input())
S=input()
K=int(input())
ans=''
for i in range(N):
    if S[i] != S[K-1]:
        ans += '*'
    else:
        ans += S[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
K=int(input())
ans=''
for i in range(N):
    if s[i]!=S[K-1]:
        ans+='*'
    else:
        ans+=S[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
K=int(input())
ans=''
for i in range(N):
    if s[i] != S[K-1]:
        ans += '*'
    else:
        ans += S[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
K=int(input())
ans=''
for i in range(N):
    if s[i] != s[K-1]:
        ans += '*'
    else:
        ans += s[i]
print(ans)
Problem p03280 (python)

Fixed submission:
a,b=map(int,input().split())
print(a*b-(a+b-1))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split)
print(a*b-(a+b-1))
Problem p03860 (python)

Fixed submission:
print('A'+input()[8]+'C')

Buggy submission (verdict: Runtime Error):
s=input()
print('A'+input()[8]+'C')
Problem p03795 (python)

Fixed submission:
N= int(input())
x= 800 * N
if N < 15:
    y = 0
if 15 <= N < 30:
    y = 200
if 30 <= N < 45:
    y = 400
if 45 <= N < 60:
    y = 600
if 60 <= N < 75:
    y = 800
if 75 <= N <90:
    y = 1000
if 90 <= N <=100:
    y = 1200
print(x-y)

Buggy submission (verdict: Runtime Error):
N= int(input())
x= 800 * N
if N < 15:
    y = 0
if 15 <= N < 30:
    y = 200
if 30 <= N < 45:
    y = 400
if 45 <= N < 60:
    y = 600
if 60 <= N < 75:
    y = 800
if 75 <= N < 100:
    y = 1000

print(x-y)
Problem p02742 (python)

Fixed submission:
def main():
    h, w = map(int, input().split())
    if h == 1 or w == 1:
        print(1)
        return 0
    ans = 0
    if w&1:
        ans += w * (h//2)
        if h % 2 == 1:
            ans += (w+1)//2
    else:
        ans += h*(w//2)

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
def main():
    h, w = map(int, input().split())

    ans = 0
    if h == 1:
        print(1)
        return 0
    if w&1:
    ans += w * (h//2)
    if h % 2 == 1:
        ans += (w+1)//2
    else:
    ans += h*(w//2)

    print(ans)

main()
Problem p02755 (python)

Fixed submission:
def main():
    a, b = map(int, input().split())
    for x in range(1, 100005):
        aa = x * 8 // 100
        bb = x // 10
        if aa == a and bb == b:
            print(x)
            return

    print(-1)

main()

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

using namespace std;

int main() {
  int a, b; cin >> a >> b;
  for (int i = 0; i <= 10000; i++) {
    if ( i*8/100 == a && i*10/100 == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02768 (python)

Fixed submission:
# return x^{-1} % mod
# it take O(log{mod})
def mod_inverse(x, mod):
    return pow(x, mod-2, mod)

# return nCk % mod
# it take O(k)
def mod_comb(n, k, mod):
    numer, denom = 1, 1
    for i in range(k):
        # numer: 分子, denom: 分母
        numer = numer * ((n-i) % mod) % mod
        denom = denom * ((i+1) % mod) % mod

    return numer * mod_inverse(denom, mod) % mod


n, a, b = map(int, input().split())
mod = 1000000007
ans = pow(2, n, mod) - 1
ans = (ans - mod_comb(n, a, mod)) % mod
ans = (ans - mod_comb(n, b, mod)) % mod
print( (ans + mod) % mod )

Buggy submission (verdict: Runtime Error):
# return x^{-1} % mod
# it take O(log{mod})
def mod_inverse(x, mod):
    return pow(x, mod-2, mod)

# return nCk % mod
# it take O(k)
def mod_comb(n, k, mod):
    numer, denom = 1, 1
    for i in range(k):
        # numer: 分子, denom: 分母
        numer = numer * ((n-i) % mod) % mod
        denom = denom * ((i+1) % mod) % mod

    return numer * mod_inverse(denom) % mod

n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1
ans = (ans - mod_comb(n, a, mod)) % mod
ans = (ans - mod_comb(n, b, mod)) % mod
print( (ans + mod) % mod )
Problem p02780 (python)

Fixed submission:
n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]
s = [ 0 ]

for key, v in enumerate(p):
    t = (v+1)*v//2/v
    s.append(s[key] + t)

ans = -1

for i in range(n-k+1):
    v = s[i+k]-s[i]
    ans = max(ans, v)

print(ans)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

template <class T>
struct BIT {
  std::vector<T> bit;
  BIT(int n) : bit(n+1, 0) {}
  void add(int x, const T &w) {
    for (int i = x; i < bit.size()-1; i |= (i+1)) {
      bit[i] += w;
    }
  }
  T sum(int r) {
    T ret = 0;
    for (int i = r-1; i >= 0; i = (i & (i+1)) - 1) {
      ret += bit[i];
    }
    return ret;
  }
  T sum(int l, int r) { return sum(r) - sum(l); }
};

int main() {
  int n, k; cin >> n >> k;
  BIT<double> tree(n);
  for (int i = 0; i < n; i++) {
    int p; cin >> p;
    tree.add(i, (1 + p) / 2.0);
  }
  double ans = 0.0;
  for (int i = 0; i + k <= n; i++) {
    ans = max(ans, tree.sum(i, i+k));
  }
  cout << ans << endl;
  return 0;
}
Problem p02900 (python)

Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1

    if n != 1: ret[n] = 1

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)

Buggy submission (verdict: Runtime Error):
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def prime_factor(n):
    ret, p = [], 2

    while p*p <= n:
        if n % p != 0:
            p += 1
            continue

        exp_v = 0
        while n%p == 0:
            exp += 1
            n //= p
        ret.append( [ret, exp_v] )

        p += 1

    if n != 1: ret.append( [n, 1] )

    return ret


a, b = map(int, input().split())
g = gcd(a, b)

print( len(prime_factor(g)) + 1)
Problem p02910 (python)

Fixed submission:
s = input()
is_ok = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == "L":
        is_ok = False
        break
    if i % 2 == 1 and s[i] == "R":
        is_ok = False
        break
print("Yes" if is_ok else "No")

Buggy submission (verdict: Runtime Error):
s = input()
is_ok = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == "L":
        is_ok = False
        break
    if i % 2 == 1 and s[i] == "R":
        is_ok = False
        break
print("Yes" is_ok else "No")
Problem p02975 (python)

Fixed submission:
def main(): 
    n = int(input())
    a = [ int(x) for x in input().split() ]

    d = {}
    for aa in a:
        d[aa] = d.get(aa, 0) + 1

    if d.get(0, 0) == n:
        print("Yes")
        return 0
    L = sorted(list(d.items()))
    if n % 3 == 0 and len(L) == 2 and (L[0][0] == 0 and L[0][1] == n//3) and L[1][1] == n//3*2:
        print("Yes")
        return 0
    
    if n % 3 == 0 and len(L) == 3 and L[0][1] == n//3 and L[1][1] == n//3 and L[2][1] == n//3 and L[0][0]^L[1][0]^L[2][0] == 0:
        print("Yes")
        return 0

    print("No")

main()

Buggy submission (verdict: Runtime Error):
def main(): 
    n = int(input())
    a = [ int(x) for x in input().split() ]

    d = {}
    for aa in a:
        d[aa] = d.get(aa, 0) + 1

    if d.get(0, 0) == n:
        print("Yes")
        return 0
    L = sorted(list(d.items()))
    if n % 3 == 0 and len(L) == 2 and (L[0][0] == 0 and L[0][1] == n//3) and L[1][1] == n//3*2:
        print("Yes")
        return 0
    
    if n % 3 == 0 and len(L) == 3 and L[0][1] == n//3 and L[1][1] == n//3 and :[2][1] == n//3 and L[0][0]^L[1][0]^L[2][0] == 0:
        print("Yes")
        return 0

    print("No")

main()
Problem p03049 (python)

Fixed submission:
n = int(input())
ans, ba, xa, bx = 0, 0, 0, 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    if s[0] == "B" and s[-1] != "A":
        bx += 1
    if s[0] != "B" and s[-1] == "A":
        xa += 1

if xa == 0 and bx == 0:
    ans += max(0, ba-1)
else:
    ans += ba
    ans += min(xa, bx)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ba, xa, bx = 0, 0, 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    if s[0] == "B" and s[-1] != "A":
        bx += 1
    if s[0] != "B" and s[-1] == "A":
        xa += 1

if xa == 0 and bx == 0:
    ans += max(0, ba-1)
else:
    ans += ba
    ans += min(xa, bx)

print(ans)
Problem p03194 (python)

Fixed submission:
def prime_factor(n):
    ret = {}
    p = 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret

n, p = map(int, input().split())

primes = prime_factor(p)
ans = 1

for p, e in primes.items():
    ans *= max(1, p**(e//n))

print(ans)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while True:
        t = g**n
        if t > p: break
        if p%t == 0:
            ans = max(ans, g)
        g += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while g**n <= p:
        if p % (g**n) == 0:
            ans = max(ans, g)
        g += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
n, p = map(int, input().split())

if n == 1:
    print(p)
else:
    ans = 1
    g = 1
    while pow(g, n) <= p:
        if p % pow(g, n) == 0:
            ans = max(ans, g)
        g += 1
    print(ans)
Problem p03200 (python)

Fixed submission:
S = input()
L = [0]
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L)-1 

print(sum(L))

Buggy submission (verdict: Runtime Error):
S = input()
L = []
for i in S[::-1]:
    if i == "W":
        L.append(0)
    if i == "B":
        L[-1] += len(L) 

print(sum(L))
Problem p03245 (python)

Fixed submission:
def solve(x, y, d, m):
    ret = ""
    for i in range(m):
        if x + y >= 0 and x - y >= 0:
            ret += "R"
            x -= d[i]
        elif x + y >= 0 and x - y < 0:
            ret += "U"
            y -= d[i];
        elif x + y < 0 and x - y >= 0:
            ret += "D"
            y += d[i];
        else:
            ret += "L"
            x += d[i]
    print (ret)


def main():
    m = 34
    X, Y, d = [], [], []

    for i in range(32, 0, -1):
        d += [2**i]
    d += [1]

    N = int(input())
    even, odd = 0, 0

    for i in range(N):
        x, y = map(int, input().split())
        X += [x]; Y += [y]
    
        if (abs(x) + abs(y)) % 2 == 0:
            even += 1
        else:
            odd += 1

    if even and odd:
        print(-1)
        return 0

    if odd:
        m -= 1
    else:
        d += [1]

    print(m)
    print(" ".join(map(str, d)))

    for i in range(N):
        solve(X[i], Y[i], d, m)

main()

Buggy submission (verdict: Runtime Error):
def solve(x, y, d, m):
    ret = ""
    for i in range(m):
        if x + y >= 0 and x - y >= 0:
            ret += "R"
            x -= d[i]
        elif x + y >= 0 and x - y < 0:
            ret += "U"
            y -= d[i];
        elif x + y < 0 and x - y >= 0:
            ret += "D"
            y += d[i];
        else:
            ret += "L"
            x += d[i]
    print (ret)


def main():
    m = 34
    X, Y, d = [], [], []

    for i in range(32, 0, -1):
        d += [2**i]
    d += [1]

    N = int(input())
    even, odd = 0, 0

    for i in range(N):
        x, y = map(int, input().split())
        X += [x]; Y += [y]
    
        if (abs(x) + abs(y)) % 2 == 0:
            even += 1
        else:
            odd += 1

    if even and odd:
        print(-1)
        return 0

    if odd:
        m -= 1

    print(m)
    print(" ".join(map(str, d)))

    for i in range(N):
        solve(X[i], Y[i], d, m)

main()
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

for i, s in enumerate(S):
    if s != '1':
        t = i
        break
    if i == len(S)-1:
        t = 0
print (1 if K <= t else S[t] )

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

for i, s in enumerate(S):
    if s != '1':
        f = i
        break

print (1 if K <= f+1 else S[f] )
Problem p03290 (python)

Fixed submission:
D, G = map(int, input().split())
P, C = [], []

for _ in range(D):
    p, c = map(int, input().split())
    P.append(p); C.append(c)

ans = float('inf')

for bit in range(2**D):
    is_solve = [ 0 for _ in range(D) ]
    score, solve_num = 0, 0
    # i 番目の bit が立っている => 100(i+1)点をつけられた p_i 問を全完する
    for i in range(D):
        if (bit >> i) & 1:
            score += (100 * (i+1) * P[i] + C[i])
            solve_num += P[i]
            is_solve[i] += P[i]

    for i in range(D-1, -1, -1):
        if score >= G:
            break

        while is_solve[i] < P[i]:
            score += 100*(i+1)
            solve_num += 1
            is_solve[i] += 1
            if score >= G:
                break

    ans = min(ans, solve_num)

print(ans)

Buggy submission (verdict: Runtime Error):
D, G = map(int, input().split())
P, C = [], []

for _ in range(D):
    p, c = map(int, input().split())
    P.append(p); C.append(c)

ans = float('inf')

for bit in range(2**D):
    score, solve_num = 0, 0
    for i in range(D):
        if (bit >> i) & 1:
            score += (100 * (i+1) * P[i] + C[i])
            solve_num += P[i]
            is_solve[i] += P[i]

    for i in range(D-1, -1, -1):
        if score >= G:
            break

        if (bit >> i) & 1:
            continue

        for j in range(P[i]):
            score += 100*(i+1)
            solve_num += 1

            if score >= G:
                break

    ans = min(ans, solve_num)

print(ans)

Buggy submission (verdict: Runtime Error):
D, G = map(int, input().split())
P, C = [], []

for _ in range(D):
    p, c = map(int, input().split())
    P.append(p); C.append(c)

ans = float('inf')

for bit in range(2**D):
    score, solve_num = 0, 0
    for i in range(D):
        if (bit >> i) & 1:
            score += (100 * (i+1) * P[i] + C[i])
            solve_num += P[i]
            is_solve[i] += P[i]

    for i in range(D-1, -1, -1):
        if score >= G:
            break

        if (bit >> i) & 1:
            continue

        for j in range(p[i]):
            score += 100*(i+1)
            solve_num += 1

            if score >= G:
                break

    ans = min(ans, solve_num)

print(ans)
Problem p03330 (python)

Fixed submission:
import itertools
 
 
def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    CC = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]
 
    cost = [[0 for _ in range(C)] for _ in range(3)]
    for c in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i + j) % 3][c] += D[CC[i][j]][c]
 
    res = float("inf")
    color = [i for i in range(C)]
    for i, c in enumerate(list(itertools.permutations(color, 3))):
        tmp = 0
        for it in range(3):
            tmp += cost[it][c[it]]
        res = min(res, tmp)
 
    print(res)
 
main()

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
 
D = [ [int(i) for i in input().split()] for _ in xrange(C) ]
c = [ [int(i) for i in input().split()] for _ in xrange(N) ]
 
costD = [ [0, 0, 0] for _ in xrange(C)]
 
for c0 in xrange(C):
    for i in xrange(N):
        for j in xrange(N):
            costD[c0][(i+j)%3] += D[c[i][j]-1][c0]
 
kohoD = []
 
for c1 in xrange(C):
    for c2 in xrange(C):
        if c1 == c2:
            continue
        for c3 in xrange(C):
            if c1 == c3 or c2 == c3:
                continue
            kohoD += [(costD[c1][0] + costD[c2][1] + costD[c3][2])]
 
print(min(kohoD))
Problem p03393 (python)

Fixed submission:
import string

alp = string.ascii_lowercase

def main():
    s = input()
    if len(s) < 26:
        for i in alp:
            if i not in s:
                print (s + i)
                return
    if s == alp[::-1]:
        print(-1)
        return
    L = len(s)
    tmp = []
    tt = ''
    for i, ss in enumerate( s ):
        tmp += [ s[L-i-1] ]
        if s[L-i-1] > s[L-i-2]:
            ans = s[:L-i-2]
            tt = s[L-i-2] 
            break
    tmp.sort()
    for i in tmp:
        if i > tt:
            print (ans + i)
            break
main()

Buggy submission (verdict: Runtime Error):
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s)-1, 0, -1):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Buggy submission (verdict: Runtime Error):
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), 0, -1):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Buggy submission (verdict: Runtime Error):
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), -1, 0):
                for y in range(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()

Buggy submission (verdict: Runtime Error):
import string
def main():
    s = input()
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    for i in "abcdefghijklmnopqrstuvwxyz@":
        if i == "@":
            t = 0
            for x in range(len(s), -1, 0):
                for y in rnage(x-1, -1, -1):
                    if x == y:
                        continue
                    if s[x] > s[y]:
                        print(s.translate(string.maketrans(s[x],x[y])))
                        return 
        if s.count(i) == 0:
            print (s + i)
            break

main()
Problem p03475 (python)

Fixed submission:
# coding: utf-8
import math

N = int(raw_input())
CSF = [map(float, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            n = int(math.ceil((ans - t) / u))
            ans = int(s + t + u * n)
        else:
            ans = s + t

    print int(ans)

print 0

Buggy submission (verdict: Runtime Error):
import math

N = int(raw_input())
CSF = [map(float, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        C, S, F = CSF[j][0], CSF[j][1], CSF[j][2]
        if S < ans:
            n = math.ceil((ans - S) / F)
            ans = C + S + u * n
        else:
            ans = C + S
 
    print int(ans)

print 0

Buggy submission (verdict: Runtime Error):
import math

N = int(raw_input())
CSF = [map(float, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        C, S, F = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            n = math.ceil((ans - S) / F)
            ans = C + S + u * n
        else:
            ans = C + S
 
    print int(ans)

print 0