Problem p03244 (python)

Fixed submission:
from collections import Counter
n = int(input())
v = [int(_) for _ in input().split()]
v1 = []
v2 = []
for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v_count = Counter(v)
v1_count = Counter(v1)
v2_count = Counter(v2)
# print("v1_count", v1_count)
# print("v2_count", v2_count)
v1_comm = v1_count.most_common(1)
v2_comm = v2_count.most_common(1)
sols = []
# print("v1_comm", v1_comm)
# print("v2_comm", v2_comm)
if len(v_count) == 1:
    print(n//2)
else:
    key1 = v1_comm[0][1]
    # print("v1_comm[0][0]", v1_comm[0][0])
    # print("v2_comm[0][0]", v2_comm[0][0])
    if v1_comm[0][0] == v2_comm[0][0]:
        # print("hoge")
        v2_comm = v2_count.most_common(2)
        key2 = v2_comm[1][1]
    else:
        key2 = v2_comm[0][1]
    sols.append(n-key1-key2)
    key1 = v2_comm[0][1]
    if v1_comm[0][0] == v2_comm[0][0]:
        v1_comm = v1_count.most_common(2)
        key2 = v1_comm[1][1]
    else:
        key2 = v1_comm[0][1]
    sols.append(n-key1-key2)
    print(min(sols))

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

n = int(input())
v = [int(_) for _ in input().split()]

# 最終的な2値をx, yとしたとき書き換える要素が最小の場合は、
# xは、書き換えが最も少ない数。つまり、もともと最も多い数
# yも同様。
# ただ、xとyがかぶる場合があるので、それに対処。
if len(Counter(v)) > 1:
    v1 = v[0:n+1:2]
    # print(v)
    # print(v1)
    v2 = v[1:n+2:2]
    # print(v2)
    v1_count = Counter(v1)
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v2_1st_common = v2_count.most_common(1)
    sols = []
    # print(v1_1st_common[0][1], v2_1st_common[0][1])
    # v1を基準として多い方を考える場合。
    n1 = v1_1st_common[0][1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
        if len(v2_count >= 2):
            v2_2nd_common = v2_count.most_common(2)
            n2 = v2_2nd_common[0][1]
        else:
            print(n//2)
    else:
        n2 = v2_1st_common[0][1]
    sols.append(n-n1-n2)

    # v2を基準として多い方を考える場合。
    n2 = v2_1st_common[0][1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
         if len(v1_count >= 2):
            v1_2nd_common = v1_count.most_common(2)
            n1 = v1_2nd_common[0][1]
         else:
            print(n//2)
    else:
        n1 = v1_1st_common[0][1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)

Buggy submission (verdict: Runtime Error):

























-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined
30.py                                  col_m.txt
31.png                                 del_list.txt
31.py                                  enwiki-20150112-400-r10-105752.txt.bz2
32.png                                 features.txt
32.py                                  hightemp.txt
33.png                                 jawiki-country.json.gz
33.py                                  json_write.py
34.png                                 jsonkun.txt
34.py                                  l005.py
35.png                                 lambda.py
35.py                                  nako.txt.tmp
36.png                                 neko.txt
36.py                                  neko.txt.cabocha
36a.py                                 neko.txt.cabocha.tmp
37.png                                 neko.txt.mecab
37.py                                  neko.txt.tmp
38.png                                 nlp.txt
38.py                                  nlp.txt.xml
39.png                                 parse.out
39.py                                  predicate.txt
4.png                                  predicate_Particle.txt
40.png                                 result.png
40.py                                  result.txt
41.png                                 result49.txt
41.py                                  rt-polarity.neg
42.png                                 rt-polarity.pos
42.py                                  rt-polaritydata
43.png                                 rt-polaritydata.tar.gz
43.py                                  sentiment.txt
44.png                                 stanford-corenlp-full-2018-02-27
44.py                                  stanford-corenlp-full-2018-02-27.zip
45.png                                 start_server.sh
45.py                                  test.sh
46.png                                 test.sh~
46.py                                  test47.sh
47.png                                 test47.sh~
47.py                                  test_db
48.png                                 する.txt
48.py                                  見る.txt
49.png                                 与える.txt
49.py                                  すべて.txt
5.png
➜  lang_process_100 git:(master) ✗ git add 90.py
➜  lang_process_100 git:(master) ✗ git commit -m "20180930 wrote need check"
[master 8821b56] 20180930 wrote need check
 1 file changed, 13 insertions(+), 4 deletions(-)
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 709 bytes | 709.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:higher68/lang_process.git
   5a0fa42..8821b56  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
➜  lang_process_100 git:(master) ✗ e question-words.txt
➜  lang_process_100 git:(master) ✗ e question-words.txt
➜  lang_process_100 git:(master) ✗ git add 91.py
➜  lang_process_100 git:(master) ✗ git commit -m "20180930 wrote need check"
[master bdc97a1] 20180930 wrote need check
 1 file changed, 21 insertions(+)
 create mode 100644 91.py
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 617 bytes | 617.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:higher68/lang_process.git
   8821b56..bdc97a1  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
➜  lang_process_100 git:(master) ✗ git add 92.py
➜  lang_process_100 git:(master) ✗ git commit -m "20180930 wrote need check"
[master 8d2cb0c] 20180930 wrote need check
 1 file changed, 62 insertions(+)
 create mode 100644 92.py
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.06 KiB | 542.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:higher68/lang_process.git
   bdc97a1..8d2cb0c  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
➜  lang_process_100 git:(master) ✗ git add 92.py
➜  lang_process_100 git:(master) ✗ git commit -m "20181001 wrote need check"
[master e8eed9e] 20181001 wrote need check
 1 file changed, 1 deletion(-)
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 294 bytes | 147.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:higher68/lang_process.git
   8d2cb0c..e8eed9e  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
➜  lang_process_100 git:(master) ✗ git add 93.py
➜  lang_process_100 git:(master) ✗ git commit -m "20181001 wrote need check"
[master 37076e6] 20181001 wrote need check
 1 file changed, 18 insertions(+)
 create mode 100644 93.py
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 642 bytes | 642.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:higher68/lang_process.git
   e8eed9e..37076e6  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
➜  lang_process_100 git:(master) ✗ ls
#64.py#                                51.py
000.py                                 51_ans.py
001.py                                 52.py
002.py                                 53.py
003.py                                 54.py
003_B.py                               55.py
004.py                                 56.py
006.py                                 56_test.py
007.py                                 57.py
008.py                                 58.py
009.py                                 59.py
00e0.py                                6.png
010.py                                 60.py
011.py                                 61.py
012.py                                 62.py
013.py                                 63.py
014.py                                 64.py
015.py                                 65.py
016.py                                 67.py
017.py                                 68.py
018.py                                 69.py
019.py                                 7.png
020.py                                 70.py
021.py                                 71.py
022.py                                 72.py
023.py                                 73.py
024.py                                 74.py
025.py                                 75.py
026.py                                 76.py
026_a.py                               77.py
027.py                                 78.py
028.py                                 79.py
029.py                                 8.png
1.png                                  80.py
10.png                                 81.py
11.png                                 82.py
12.png                                 83.py
13.png                                 84.py
14.png                                 85.py
15.png                                 86.py
16.png                                 87.py
17.png                                 88.py
18.png                                 89.py
19.png                                 9.png
2.png                                  90.py
20.png                                 91.py
21.png                                 92.py
22.png                                 93.py
23.png                                 94.py
24.png                                 Country_list.csv
25.png                                 Country_list.numbers
26.png                                 README.md
27.png                                 __pycache__
28.png                                 artist.json.gz
29.png                                 cgi-bin
3.png                                  col1.txt
30.png                                 col2.txt
30.py                                  col_m.txt
31.png                                 del_list.txt
31.py                                  enwiki-20150112-400-r10-105752.txt.bz2
32.png                                 features.txt
32.py                                  hightemp.txt
33.png                                 jawiki-country.json.gz
33.py                                  json_write.py
34.png                                 jsonkun.txt
34.py                                  l005.py
35.png                                 lambda.py
35.py                                  nako.txt.tmp
36.png                                 neko.txt
36.py                                  neko.txt.cabocha
36a.py                                 neko.txt.cabocha.tmp
37.png                                 neko.txt.mecab
37.py                                  neko.txt.tmp
38.png                                 nlp.txt
38.py                                  nlp.txt.xml
39.png                                 parse.out
39.py                                  predicate.txt
4.png                                  predicate_Particle.txt
40.png                                 question-words.txt
40.py                                  result.png
41.png                                 result.txt
41.py                                  result49.txt
42.png                                 rt-polarity.neg
42.py                                  rt-polarity.pos
43.png                                 rt-polaritydata
43.py                                  rt-polaritydata.tar.gz
44.png                                 sentiment.txt
44.py                                  stanford-corenlp-full-2018-02-27
45.png                                 stanford-corenlp-full-2018-02-27.zip
45.py                                  start_server.sh
46.png                                 test.sh
46.py                                  test.sh~
47.png                                 test47.sh
47.py                                  test47.sh~
48.png                                 test_db
48.py                                  wordsim353
49.png                                 wordsim353.zip
49.py                                  する.txt
5.png                                  見る.txt
50.png                                 与える.txt
50.py                                  すべて.txt
50_sub.py
➜  lang_process_100 git:(master) ✗ git add 94.py
➜  lang_process_100 git:(master) ✗ git commit -m "20181001 writing"
[master 256b14d] 20181001 writing
 1 file changed, 20 insertions(+)
 create mode 100644 94.py
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 652 bytes | 652.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:higher68/lang_process.git
   37076e6..256b14d  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
➜  lang_process_100 git:(master) ✗ cd
➜  ~
➜  ~ cd git/atcoder/Beginner111
➜  Beginner111 git:(master) ✗ ls
a.py        b2.py       c.py        c3.py       d.py
b.py        b_review.py c2.py       cpy
➜  Beginner111 git:(master) ✗ p b_review.py
111
111
222
333
444
555
666
777
888
999
➜  Beginner111 git:(master) ✗
➜  Beginner111 git:(master) ✗
➜  Beginner111 git:(master) ✗ p b_review.py
111
111
➜  Beginner111 git:(master) ✗ p b_review.py
112
222
➜  Beginner111 git:(master) ✗ p b_review.py
750
777
➜  Beginner111 git:(master) ✗ git add 94.py
fatal: pathspec '94.py' did not match any files
➜  Beginner111 git:(master) ✗ cd
➜  ~ cd git/lang_process_100
➜  lang_process_100 git:(master) ✗ git add 94.py
➜  lang_process_100 git:(master) ✗ git commit -m "20181001 writing"
[master 6080a32] 20181001 writing
 1 file changed, 13 insertions(+), 1 deletion(-)
➜  lang_process_100 git:(master) ✗ git push -u origin master
ssh: Could not resolve hostname github.com: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

File Edit Options Buffers Tools Help

























































-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined
Please make sure you have the correct access rights
and the repository exists.
➜  lang_process_100 git:(master) ✗ git push -u origin master
Enter passphrase for key '/Users/junya/.ssh/github_id_rsa':
File Edit Options Buffers Tools Help

























































-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 477 bytes | 477.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:higher68/lang_process.git
   256b14d..6080a32  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v1_2nd_common = v1_count.most_common(2)
    print("v1", v1_1st_common, v1_2nd_common)
    v2_1st_common = v2_count.most_common(1)
    v2_2nd_common = v2_count.most_common(2)
    print("v2", v2_1st_common, v2_2nd_common)
    sols = []

    # v1を基準として多い方を考える場合。
    n1 = v1_1st_common[1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0] == v2_1st_common[0]:
        n2 = v2_2nd_common[1]
    else:
        n2 = v2_1st_common[1]
    sols.append(n-n1-n2)

    # v2を基準として多い方を考える場合。
    n2 = v2_1st_common[1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0] == v2_1st_common[0]:
        n1 = v1_2nd_common[1]
    else:
        n1 = v1_1st_common[1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)
















-UUU(LF)----F1  c_review.py    All L43    (Python AC ElDoc) --------------------------------------------
Wrote /Users/junya/git/atcoder/Beginner111/c_review.py
from collections import Counter

n = int(input())
v = [int(_) for _ in input().split()]

# 最終的な2値をx, yとしたとき書き換える要素が最小\\
の場合は、
# xは、書き換えが最も少ない数。つまり、もともと最\\
も多い数
# yも同様。
# ただ、xとyがかぶる場合があるので、それに対処。
if len(Counter(v)) > 1:
    v1 = v[0:n-2:2]
    v2 = v[1:n-1:2]
    v1_count = Counter(v1)
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v1_2nd_common = v1_count.most_common(2)
    print("v1", v1_1st_common, v1_2nd_common)
    v2_1st_common = v2_count.most_common(1)
    v2_2nd_common = v2_count.most_common(2)
    print("v2", v2_1st_common, v2_2nd_common)
    sols = []

    # v1を基準として多い方を考える場合。
    n1 = v1_1st_common[1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0] == v2_1st_common[0]:
        n2 = v2_2nd_common[1]
    else:
        n2 = v2_1st_common[1]
    sols.append(n-n1-n2)

    # v2を基準として多い方を考える場合。
    n2 = v2_1st_common[1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0] == v2_1st_common[0]:
        n1 = v1_2nd_common[1]
    else:
        n1 = v1_1st_common[1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)











File Edit Options Buffers Tools Help

























































-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined

File Edit Options Buffers Tools Help

























































-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined

File Edit Options Buffers Tools Help

























































-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined
-UUU(LF)----F1  c_review.py    All L43    (Python A
Wrote /Users/junya/git/atcoder/Beginner111/c_revie\
➜  lang_process_100 git:(master) ✗ cd
➜  ~ cd git/atcoder/Beginner111
➜  Beginner111 git:(master) ✗ p c.py
4
3 1 3 2
1
File Edit Options Buffers Tools Help

























































-UUU:----F1  *scratch*      All L1     (Fundamental Fill) ----------------------------------------------
ad-handle-definition: ‘pdb’ got redefined
➜  Beginner111 git:(master) ✗

➜  Beginner111 git:(master) ✗
➜  Beginner111 git:(master) ✗ p c.py
6
105 119 105 119 105 119
0
➜  Beginner111 git:(master) ✗
File Edit Options Buffers Tools Help






















































-UUU:----F1  *scratch*      All L1     (Fundamental
ad-handle-definition: ‘pdb’ got redefined
from collections import Counter

n = int(input())
v = [int(_) for _ in input().split()]

# 最終的な2値をx, yとしたとき書き換える要素が最小\\
の場合は、
# xは、書き換えが最も少ない数。つまり、もともと最\\
も多い数
# yも同様。
# ただ、xとyがかぶる場合があるので、それに対処。
if len(Counter(v)) > 1:
    v1 = v[0:n+1:2]
    # print(v)
    # print(v1)
    v2 = v[1:n+2:2]
    # print(v2)
    v1_count = Counter(v1)
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v2_1st_common = v2_count.most_common(1)
    sols = []
    # print(v1_1st_common[0][1], v2_1st_common[0][\
1])
    # v1を基準として多い方を考える場合。
    n1 = v1_1st_common[0][1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
        if len(v2_count >= 2):
            v2_2nd_common = v2_count.most_common(2\
)
            n2 = v2_2nd_common[0][1]
        else:
            print(n//2)
    else:
        n2 = v2_1st_common[0][1]
    sols.append(n-n1-n2)

    # v2を基準として多い方を考える場合。
    n2 = v2_1st_common[0][1]
    # v1の1位とv2の1位がかぶる場合
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
         if len(v1_count >= 2):
            v1_2nd_common = v1_count.most_common(2\
)
            n1 = v1_2nd_common[0][1]
         else:
            print(n//2)
    else:
        n1 = v1_1st_common[0][1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)

-UUU(LF)----F1  c_review.py    All L22    (Python A
Wrote /Users/junya/git/atcoder/Beginner111/c_revie\
w.py

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

n = int(input())
v = [int(_) for _ in input().split()]

# 最終的な2値をx, yとしたとき書き換える要素が最小の場合は、
# xは、書き換えが最も少ない数。つまり、もともと最も多い数
# yも同様。
# ただ、xとyがかぶる場合があるので、それに対処。
v1 = v[0:n-2:2]
v2 = v[1:n-1:2]
v1_count = Counter(v1)
v2_count = Counter(v2)

v1_1st_common = v1_count.most_common(1)
v1_2nd_common = v1_count.most_common(2)

v2_1st_common = v2_count.most_common(1)
v2_2nd_common = v2_count.most_common(2)
sols = []

# v1を基準として多い方を考える場合。
n1 = v1_1st_common[1]
# v1の1位とv2の1位がかぶる場合
if v1_1st_common[0] == v2_1st_common[0]:
    n2 = v2_2nd_common[1]
else:
    n2 = v2_1st_common[1]
sols.append(n-n1-n2)

# v2を基準として多い方を考える場合。
n2 = v2_1st_common[1]
# v1の1位とv2の1位がかぶる場合
if v1_1st_common[0] == v2_1st_common[0]:
    n1 = v1_2nd_common[1]
else:
    n1 = v1_1st_common[1]
sols.append(n-n1-n2)
print(min(sols))