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

Fixed submission:
import itertools
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

Buggy submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

ans = 0
for i,j,k in itertools.combinations(range(n),m):
    u = 0
    for l in range(3):
        u += abs(a[i][l] + a[j][l] + a[k][l])
    ans = max(ans,u)

print(ans)

Buggy submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

ans = 0
for i,j,k in itertools.combinations(range(n),m):
    u = 0
    for l in range(3):
        u += abs(a[i][l] + a[j][l] + a[k][l])
    ans = max(ans,u)

print(ans)
Problem p02550 (python)

Fixed submission:
n, x, mod = map(int, input().split())
lst = [0, x]
num_set = set([x])
num_lst = [0, x]
flag = False

for i in range(mod - 1):
  x = (x * x) % mod
  s = x + lst[-1]
  if x == 0:
    lst.append(s)
    break
  if x in num_set:
    flag = True
    break
  lst.append(s)
  num_set.add(x)
  num_lst.append(x)
  if i + 2 == n:
    break

#print(lst)
if flag:
  for i, ele in enumerate(num_lst):
    if x == ele:
      loop_s = i
      break

l = len(lst)
if lst[l - 1] == lst[l - 2]:
  print(lst[l - 1])
else:
  if not flag:
    print(lst[-1])
  else:
    loop = len(lst) - loop_s
    n -= loop_s - 1
    c = n // loop
    r = n % loop
    ans = lst[l - 1] + (c - 1) * (lst[l - 1] - lst[loop_s - 1]) + lst[loop_s + r - 1] - lst[loop_s - 1]
    print(ans)

Buggy submission (verdict: Runtime Error):
n, x, mod = map(int, input().split())
lst = [0, x]
num_set = set([x])
num_lst = [0, x]
flag = False

for i in range(mod - 1):
  x = (x * x) % mod
  s = x + lst[-1]
  if x == 0:
    lst.append(s)
    break
  if x in num_set:
    flag = True
    break
  lst.append(s)
  num_set.add(x)
  num_lst.append(x)
  if i + 2 == n:
    break

#print(lst)
if flag:
  for i, ele in enumerate(num_lst):
    if x == ele:
      loop_s = i
      break

l = len(lst)
if lst[l - 1] == lst[l - 2]:
  print(lst[l - 1])
else:
  if not flag:
    print(lst[-1])
  else:
    loop = len(lst) - loop_s
    n -= loop_s - 1
    c = n // loop
    r = n % loop
    ans = 0
    if c == 0:
      ans += lst[n + loop_s + 1]
    else:
      ans += lst[l - 1] + (c - 1) * (lst[l - 1] - lst[loop_s - 1]) + lst[loop_s + r - 1] - lst[loop_s - 1]
    print(ans)

Buggy submission (verdict: Runtime Error):
n, x, mod = map(int, input().split())
lst = [0, x]
num_set = set([x])
num_lst = [0, x]
flag = False

for i in range(mod - 1):
  x = (x * x) % mod
  s = x + lst[-1]
  if x == 0:
    lst.append(s)
    break
  if x in num_set:
    flag = True
    break
  lst.append(s)
  num_set.add(x)
  num_lst.append(x)
  if i == n:
    break

#print(lst)
if flag:
  for i, ele in enumerate(num_lst):
    if x == ele:
      loop_s = i
      break

l = len(lst)
if lst[l - 1] == lst[l - 2]:
  print(lst[l - 1])
else:
  if not flag:
    print(lst[l - 1])
  else:
    loop = len(lst) - loop_s
    n -= loop_s - 1
    c = n // loop
    r = n % loop
    ans = 0
    if c == 0:
      ans += lst[n + loop_s + 1]
    else:
      if r == 0:
        ans += lst[l - 1] + (c - 1) * (lst[l - 1] - lst[loop_s - 1])
      else:
        ans += lst[l - 1] + (c - 1) * (lst[l - 1] - lst[loop_s - 1]) + lst[loop_s + r - 1] - lst[loop_s - 1]
    print(ans)
Problem p02557 (python)

Fixed submission:
n = int(input())
lst_a = [int(i) for i in input().split()]
lst_b = [int(i) for i in input().split()]
j = 0
flag = True
for i in range(n):
  if i > 0:
    if lst_a[i] != lst_a[i - 1]:
      j = 0
  if lst_a[i] != lst_b[i]:
    continue
  else:
    flag = False
    while j != n:
      if lst_a[i] != lst_b[j] and lst_a[j] != lst_b[i]:
        lst_b[i], lst_b[j] = lst_b[j], lst_b[i]
        flag = True
        break
      j += 1
    if not flag:
      break
if not flag:
  print('No')
else:
  print('Yes')
  lst_b = [str(i) for i in lst_b]
  print(' '.join(lst_b))

Buggy submission (verdict: Runtime Error):
n = int(input())
lst_a = [int(i) for i in input().split()]
lst_b = [int(i) for i in input().split()]
j = 0
for i in range(n):
  if lst_a[i] != lst_b[i]:
    continue
  else:
    flag = False
    while j != n:
      if lst_a[i] != lst_b[j]:
        lst_b[i], lst_b[j] = lst_b[j], lst_b[i]
        flag = True
        break
      j += 1
    if not flag:
      break
if not flag:
  print('No')
else:
  print('Yes')
  lst_b = [str(i) for i in lst_b]
  print(' '.join(lst_b))
Problem p02676 (python)

Fixed submission:
k = int(input())
s = input()

if k >= len(s):
    print(s)
else:
    print(s[0:k]+"...")

Buggy submission (verdict: Runtime Error):
k = int(input())
s = raw_input()

if k >= len(s):
    print(s)
else:
    print(s[0:k]+"...")
Problem p02759 (python)

Fixed submission:
# coding: utf-8

n = input()

if n % 2 == 1:
    print(n/2 + 1)
else:
    print(n/2)

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

n = input()

if n % 2 == 1:
    print(n/2 + 1)
else:
    print(n/2)

Buggy submission (verdict: Runtime Error):
n = input()

if n % 2 == 1:
    print(n/2 + 1)
else:
    print(n/2)

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

n = input()

if n % 2 == 1:
    print(n/2 + 1)
else:
    print(n/2)
Problem p02598 (python)

Fixed submission:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())

A = list(map(int, input().split()))


def ok(X):
    cnt = 0
    for a in A:
        cnt += (a - 1) // X

    return cnt <= K


def solve():
    l, r = 0, 1000000000

    while l + 1 < r:
        c = (l + r) // 2
        if ok(c):
            r = c
        else:
            l = c

    return r


print(solve())

Buggy submission (verdict: Runtime Error):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())

A = list(map(int, input().split()))


def ok(X):
    cnt = 0
    for a in A:
        cnt += (a - 1) // X

    return cnt <= K


def solve():
    l, r = -1, 1000000000

    while l + 1 < r:
        c = (l + r) // 2
        if ok(c):
            r = c
        else:
            l = c

    return r

print(solve())
Problem p02549 (python)

Fixed submission:
from sys import stdin
input = stdin.readline
mod = 998244353
from collections import defaultdict

def solve():
    n,K = map(int,input().split())
    step = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()]
    dp=defaultdict(int)

    f=0
    dp[1]=1
    for i in range(1,1+n):
        for r,l in step:
            f=(f+-dp[i-1-l]+dp[i-r])%mod
        dp[i]=(dp[i]+f)%mod
    print(dp[n])



if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
from sys import stdin

input = stdin.readline
from functools import lru_cache

MOD = 998244353


def solve():
    N,K = map(int,input().split())
    step = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()]\


    @lru_cache(None)
    def dp(n):
        if n == 1:
            return 1
        res = 0
        for a,b in step:
            if n <= a:
                continue
            for i in range(a,b+1):
                if n > i:
                    res += dp(n-i)
        return res % MOD

    print(dp(N))


if __name__ == '__main__':
    solve()
Problem p02580 (python)

Fixed submission:
from sys import stdin
import collections

input = stdin.readline

Y, X, M = map(int, input().split())
bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()])
cx = collections.defaultdict(int)
cy = collections.defaultdict(int)
for y,x in bomb:
    cx[x] += 1
    cy[y] += 1
mx = max(cx.values())
my = max(cy.values())
candidateX = [x for (x,v) in cx.items() if v == mx]
candidateY = [y for (y,v) in cy.items() if v == my]
res = mx + my -1
for x in candidateX:
    for y in candidateY:
        if (y,x) not in bomb:
            res += 1
            break
    else:
        continue
    break
print(res)

Buggy submission (verdict: Runtime Error):
from sys import stdin,exit
import collections

input = stdin.readline

Y, X, M = map(int, input().split())
bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()])
cx = collections.defaultdict(int)
cy = collections.defaultdict(int)
for y,x in bomb:
    cx[x] += 1
    cy[y] += 1
mx = max(cx.values())
my = max(cy.values())
candidateX = [x for (x,v) in cx.items() if v == mx]
candidateY = [y for (y,v) in cy.items() if v == my]
res = mx + my -1
for x in candidateX:
    for y in candidateY:
        if (y,x) not in bomb:
            print(res + 1)
            exit(1)

print(res)
Problem p02598 (python)

Fixed submission:
from sys import stdin

input = stdin.readline
import math
import heapq


def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    left = 1
    right = max(a)

    def ok(l):
        s = sum([(i-1) // l for i in a])
        return s <= k
    while left < right:
        mid = (left + right) // 2
        if ok(mid):
            right = mid
        else:
            left = mid + 1
    print(left)


if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
from sys import stdin

input = stdin.readline



def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    left = 0
    right = max(a)

    def ok(l):
        s = sum([i // l for i in a])
        return s <= k

    while left < right:
        mid = (left + right) // 2
        if ok(mid):
            right = mid
        else:
            left = mid + 1
    print(left)


if __name__ == '__main__':
    solve()
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
step_patern = [0,1]
for i in range(n):
         step_patern.append(step_patern[i] + step_patern[i+1])
kankaku = []
tmp = 0
for i in range(len(a)):
         kankaku.append(a[i] - tmp)
         tmp = a[i] +1
kankaku.append(n + 1 - tmp)
ans = 1
for i in kankaku:
         ans *= step_patern[i]
         ans %= (10 ** 9) +7
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(int(input()) for hoge in range(m))
dan = [a[0]]
ans = 1
for i in range(m-1):
         if (a[i+1]-(a[i]+1)) == 0:
                  print(0)
                  exit()
         dan.append(a[i+1]-(a[i]+1))
dan.append(n-(a[m-1]))
for j in range (len(dan)):
         ans *= ((2 ** (dan[j] //2)))
print(ans%((10 ** 9) +7))
Problem p03053 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    dx = [0, 0, -1, 1]
    dy = [1, -1, 0, 0]
    dist = [[-1 for __ in range(w)] for _ in range(h)]
    blacks = deque()

    # See:
    # http://drken1215.hatenablog.com/entry/2019/05/05/223200?_ga=2.177845805.987014750.1556545680-1855989383.1556545680
    # https://blog.kichi2004.jp/2019/05/agc033/
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                dist[i][j] = 0
                blacks.append((i, j))

    while blacks:
        current = blacks.popleft()
        cur_x = current[1]
        cur_y = current[0]

        for i in range(4):
            next_x = cur_x + dx[i]
            next_y = cur_y + dy[i]

            if next_x < 0 or next_x >= w or next_y < 0 or next_y >= h:
                continue

            if dist[next_y][next_x] == -1:
                dist[next_y][next_x] = dist[cur_y][cur_x] + 1
                blacks.append((next_y, next_x))

    ans = 0

    for i in range(h):
        for j in range(w):
            ans = max(ans, dist[i][j])

    print(ans)


if __name__ == '__main__':
    main()

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


def main():
    from collections import deque

    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    dx = [0, 0, -1, 1]
    dy = [1, -1, 0, 0]
    dist = [[float('inf') for __ in range(w)] for _ in range(h)]
    blacks = deque()

    # See:
    # http://drken1215.hatenablog.com/entry/2019/05/05/223200?_ga=2.177845805.987014750.1556545680-1855989383.1556545680
    # https://blog.kichi2004.jp/2019/05/agc033/
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                dist[i][j] = 0
                blacks.append((i, j))

    while blacks:
        current = blacks.popleft()
        cur_x = current[0]
        cur_y = current[1]

        for i in range(len(dx)):
            next_x = cur_x + dx[i]
            next_y = cur_y + dy[i]

            if next_x < 0 or next_x >= w or next_y < 0 or next_y >= h:
                continue

            if dist[next_x][next_y] == float('inf'):
                dist[next_x][next_y] = dist[cur_x][cur_y] + 1
                blacks.append((next_x, next_y))

    ans = 0

    for i in range(h):
        for j in range(w):
            ans = max(ans, dist[i][j])

    print(ans)


if __name__ == '__main__':
    main()
Problem p03127 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    mod_a = a
    mod = min(a)
    index = 0

    while True:
        for idx, ai in enumerate(a):
            if idx != index:
                mod_a[idx] %= mod

                if 0 < mod_a[idx] < mod:
                    mod = mod_a[idx]
                    index = idx

        if mod_a.count(0) >= n - 1:
            break

    print(max(min(a), max(mod_a)))


if __name__ == '__main__':
    main()

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


def main():
    from heapq import heappush, heappop

    n = int(input())
    a = list(map(int, input().split()))
    elements = list()

    for ai in a:
        heappush(elements, ai)

    while len(elements) >= 2:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()

    print(min(a_min, elements))


if __name__ == '__main__':
    main()
Problem p03631 (python)

Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    number = input()

    if number[0] == number[2]:
        print('Yes')
    else:
        print('No')

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


def main():
    from collections import defaultdict
    from collections import deque

    n = int(input())
    graph = [defaultdict(int) for _ in range(n)]
    visited = [False for _ in range(n)]
    dist = [float('inf') for _ in range(n)]

    for i in range(n - 1):
        ai, bi, ci = map(int, input().split())
        ai -= 1
        bi -= 1
        graph[ai][bi] = ci
        graph[bi][ai] = ci

    q, k = map(int, input().split())
    k -= 1
    dist[k] = 0
    d = deque()
    d.append(k)

    while d:
        di = d.popleft()
        visited[di] = True

        for bi, ci in graph[di].items():
            if visited[bi]:
                continue

            dist[bi] = dist[di] + ci
            d.append(bi)

    ans = [0 for _ in range(q)]

    for j in range(q):
        xi, yi = map(int, input().split())
        xi -= 1
        yi -= 1
        ans[j] = dist[xi] + dist[yi]

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()

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


def main():
    from collections import defaultdict
    from collections import deque

    n = int(input())
    graph = [defaultdict(int) for _ in range(n)]
    visited = [False for _ in range(n)]
    dist = [0 for _ in range(n)]

    for i in range(n - 1):
        ai, bi, ci = map(int, input().split())
        ai -= 1
        bi -= 1
        graph[ai][bi] = ci
        graph[bi][ai] = ci

    q, k = map(int, input().split())
    k -= 1
    dist[k] = 0
    d = deque()
    d.append(k)

    while d:
        di = d.popleft()
        visited[di] = True

        for bi, ci in graph[di].items():
            if visited[bi]:
                continue

            dist[bi] = dist[di] + ci
            d.append(bi)

    for j in range(q):
        xi, yi = map(int, input().split())
        xi -= 1
        yi -= 1
        print(dist[xi] + dist[yi])


if __name__ == '__main__':
    main()
Problem p02595 (python)

Fixed submission:
import numpy
N,D = map(int,input().split())
cnt = 0
for n in range(N):
  p,q = map(int,input().split())
  if numpy.sqrt(p ** 2 + q ** 2) <= D:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import numpy
N,D = map(int,input().split())
cnt = 0
for n in range(N):
  p,q = map(int,input().split())
  if numpy.sqrt(p ** 2 + q ** 2) <= D:
    cnt += 1
print(cnt)
Problem p02597 (python)

Fixed submission:
N = int(input())
C = []
for c in list(input()):
  a = 0
  if c == "R":
    a = 1
  C.append(a)
L = -1
R = N
cnt = 0
while L < R:
#  print(str(L) + " " + str(R))
  L += 1
  if L >= R:
    break
  if C[L] != 0:
    continue
  while L < R:
    R -= 1
    if L >= R:
      break
    if C[R] != 1:
      continue
    cnt += 1
    break     
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
C = []
for c in list(input()):
  a = 0
  if c == "R":
    a = 1
  C.append(a)
L = -1
R = N
cnt = 0
while L < R:
  L += 1
  if C[L] != 0:
    continue
  while L < R:
    R -= 1
    if C[R] != 1:
      continue
    cnt += 1
    break     
print(cnt)
Problem p02757 (python)

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N,P = LMIIS()
    S = input()[::-1]
    R = [0]*P
    R[0] = 1
    b = 1
    r = 0


    if P == 2 or P == 5:
        ans = 0
        for i,c in enumerate(S):
            if int(c) % P == 0:
                ans += N-i
        print(ans)
        return

    for c in S:
        r += b * int(c)
        r %= P
        R[r] += 1
        b *= 10
        b %= P
    ans = 0

    for r in R:
        ans += r*(r-1)//2
    print(ans)
        

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N,P = LMIIS()
    S = input()[::-1]
    R = [0]*P
    R[0] = 1
    b = 1
    r = 0


    if P == 2 or P == 5:
        ans = 0:
        for i,c in enumerate(S):
            if int(c) % P == 0:
                ans += N-i
        print(ans)
        return
    for c in S:
        r += b * int(c)
        r %= P
        R[r] += 1
        b *= 10
        b %= P
    ans = 0

    for r in R:
        ans += r*(r-1)//2
    print(ans)
        

if __name__ == '__main__':
    main()
Problem p02834 (python)

Fixed submission:
def main():
    from collections import defaultdict,deque
    from math import ceil
    from sys import setrecursionlimit
    setrecursionlimit(10**6)
    f = lambda :map(int,input().split())
    n,u,v = f() # u:高橋
    edge = defaultdict(list)
    for i in range(n-1):
        a,b = f()
        edge[a].append(b)
        edge[b].append(a)
    
    distance = [[-1]*2 for _ in range(n+1)]
    distance[u][0] = 0
    distance[v][1] = 0
    def dfs(node,start):
        targets = deque([node])
        while targets:
            parent = targets.popleft()
            distance_parent = distance[parent][start]
            for child in edge[parent]:
                if distance[child][start] == -1:
                    distance[child][start] = distance_parent + 1
                    targets.append(child)
    dfs(u,0)
    dfs(v,1)
    ans = 0
    for u_d, v_d in distance:
        if u_d < v_d:
            ans = max(ans,v_d)
    print(ans-1)


        


main()

Buggy submission (verdict: Runtime Error):
def main():
    from collections import defaultdict,deque
    from math import ceil
    INF = 10**20
    f = lambda :map(int,input().split())
    n,u,v = f() # u:高橋
    edge = defaultdict(list)
    for i in range(n-1):
        a,b = f()
        edge[a].append(b)
        edge[b].append(a)
    
    distance = [[-1]*2 for _ in range(n+1)]
    distance[u][0] = 0
    distance[v][1] = 0
    def dfs(parent, start):
        distance_parent = distance[parent][start]
        for child in edge[parent]:
            if distance[child][start] == -1:
                distance[child][start] = distance_parent + 1
                dfs(child, start)
    dfs(u,0)
    dfs(v,1)
    ans = 0
    for u_d, v_d in distance:
        if u_d < v_d:
            ans = max(ans,v_d)
    print(ans-1)


        


main()
Problem p02933 (python)

Fixed submission:
print('red') if int(input()) < 3200 else print(input())

Buggy submission (verdict: Runtime Error):
print('Yes) if int(input()) >= 3200 else print(input())
Problem p02987 (python)

Fixed submission:
S = input()
C = [0] * 26
for s in S:
    C[ord(s)-ord('A')] += 1
v = 0
for  c in C:
    if c == 2:
        v += 1
    elif c != 0:
        print('No')
        break
if v == 2:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S = input()
C = [0] * 26
for s in S:
    C[ord(s)-ord('A')] += 1
v = 0
for  c in C:
    if c != 0 and c!= 2:
        print('No')
        import sys
        sys.exit(1)

print('Yes')