Problem p03244 (python)

Fixed submission:
import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    #偶数列 奇数列
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    #頻値を取り出す
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    #print(even_c)
    #print(odd_c)
    #print(len(even_c))
    
    #最頻値の比較
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    #偶数列と奇数列の最頻値の数字が同じかつ、全て同じ数字じゃない
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 1:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    #全て同じ
    else:
        ans = even_c[0][1]
        
    #出力
    print(ans)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    #偶数列 奇数列
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    #頻値を取り出す
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    #print(even_c)
    #print(odd_c)
    
    #最頻値の比較
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    #偶数列と奇数列の最頻値の数字が同じかつ、全て同じ数字じゃない
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 0:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    #全て同じ
    else:
        ans = even_c[0][1]
        
    #出力
    print(ans)
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return 0, 0

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    x = 0 if x < 0 else x
    y = 0 if y < 0 else y
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    if n == 0 : return 0
    
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    if n == 0 : return 0
    
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    if n == 0 : return 0
    
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if(even_c[e][1] + odd_c[o][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(int(len(m) / 2) )
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        y -= 1
        return x , y
        
    if l1[x][1] < l2[y][1]:
        x -= 1
        return x , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if(even_c[e][1] + odd_c[o][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(int(len(m) / 2) )
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        y -= 1
        return x , y
        
    if l1[x][1] < l2[y][1]:
        x -= 1
        return x , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if(even_c[e][1] + odd_c[o][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        y -= 1
        return x , y
        
    if l1[x][1] < l2[y][1]:
        x -= 1
        return x , y
    
    return 0, 0

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if(even_c[e][1] + odd_c[o][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print(x)
    #print(y)
    
    #それぞれの出現値が同じ場合
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
        
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
            
    #出現回数を比較し、少ない方を2番目の出現値で返す
    if l1[x][1] > l2[y][1]:
        y -= 1
    else:
        x -= 1
    
    return x, y
    

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    
    x, y = selection(even_c, odd_c, 0 ,0)
    
    #全部ばらばら
    if(even_c[x][1] + odd_c[y][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[x][1] == odd_c[y][1] and even_c[x][0] == odd_c[y][0]:
        print(len(m) - even_c[x][1])
        return
    
    print( len(m) - (even_c[x][1] + odd_c[y][1]) )
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print(x)
    #print(y)
    
    #それぞれの出現値が同じ場合
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
        
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
            
    #出現回数を比較し、少ない方を2番目の出現値で返す
    if l1[x][1] > l2[y][1]:
        y -= 1
    else:
        x -= 1
    
    return x, y
    

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    
    x, y = selection(even_c, odd_c, 0 ,0)
    
    #全部ばらばら
    if(even_c[x][1] + odd_c[y][1] == 2):
        print(len(m) - 1)
        return
    
    #全部一緒
    if even_c[x][1] == odd_c[y][1] and even_c[x][0] == odd_c[y][0]:
        print(len(m) - even_c[x][1])
        return
    
    print( len(m) - (even_c[x][1] + odd_c[y][1]) )
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print(x)
    #print(y)
    
    #それぞれの出現値が同じ場合
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
        
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
            
    #出現回数を比較し、少ない方を2番目の出現値で返す
    if l1[x][1] > l2[y][1]:
        y -= 1
    else:
        x -= 1
    
    return x, y
    

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    
    x, y = selection(even_c, odd_c, 0 ,0)
    
    #全部ばらばら
    if(even_c[x][1] + odd_c[y][1] == 2):
        print(len(m) - 1)
        return
    
    #全部一緒
    if even_c[x][1] == odd_c[y][1]:
        print(len(m) - even_c[x][1])
        return
    
    print( len(m) - (even_c[x][1] + odd_c[y][1]) )
    
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

def defs(c1, c2):
    
    if c1[0][1] > c2[0][1]:
        return c1[0], c2[1]
    else:
        return c1[1], c2[0]

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    if even_c[0] == odd_c[0]:
        print(len(m) / 2)
        return
    
#    print(even_c)
#    print(odd_c)
    
    even_c, odd_c = defs(even_c, odd_c)
    
    if even_c[1] == odd_c[1]:
        ans = len(odd) - min(even_c[1], odd_c[1])
        
    else:
        ans = len(m) - (even_c[1] + odd_c[1])
    
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

def defs(c1, c2):
    if c1[0][0] > c2[0][0]:
        return c1[1], c2[0]
    else:
        return c1[0], c2[1]

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    if even_c[0] == odd_c[0]:
        print(len(m) / 2)
        return
    
#    print(even_c)
#    print(odd_c)
    
    even_c, odd_c = defs(even_c, odd_c)
    
    if even_c[1] == odd_c[1]:
        ans = len(odd) - min(even_c[1], odd_c[1])
        
    else:
        ans = len(m) - (even_c[1] + odd_c[1])
    
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common(1)
    odd_c = Counter(odd).most_common(1)
    
    if even_c[0][0] == odd_c[0][0]:
        print(even_c[0][1])
    else:
        print(len(m) - (even_c + odd_c))

if __name__ == '__main__':
    main()