Problem: p04031
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
_ = input()
a = list(map(int, input().split()))
ans = 10 ** 18
for val in range(-200, 200):
  curr = 0
  for it in a:
    curr += (it - val) ** 2
    ans = min(ans, curr)
    print(ans)

Failing test case input:
3
-1 0 14

Expected output:
141


Actual output:
39601
39601
39601
39204
39204
39204
38809
38809
38809
38416
38416
38416
38025
38025
38025
37636
37636
37636
37249
37249
37249
36864
36864
36864
36481
36481
36481
36100
36100
36100
35721
35721
35721
35344
35344
35344
34969
34969
34969
34596
34596
34596
34225
34225
34225
33856
33856
33856
33489
33489
33489
33124
33124
33124
32761
32761
32761
32400
32400
32400
32041
32041
32041
31684
31684
31684
31329
31329
31329
30976
30976
30976
30625
30625
30625
30276
30276
30276
29929
29929
29929
29584
29584
29584
29241
29241
29241
28900
28900
28900
28561
28561
28561
28224
28224
28224
27889
27889
27889
27556
27556
27556
27225
27225
27225
26896
26896
26896
26569
26569
26569
26244
26244
26244
25921
25921
25921
25600
25600
25600
25281
25281
25281
24964
24964
24964
24649
24649
24649
24336
24336
24336
24025
24025
24025
23716
23716
23716
23409
23409
23409
23104
23104
23104
22801
22801
22801
22500
22500
22500
22201
22201
22201
21904
21904
21904
21609
21609
21609
21316
21316
21316
21025
21025
21025
20736
20736
20736
20449
20449
20449
20164
20164
20164
19881
19881
19881
19600
19600
19600
19321
19321
19321
19044
19044
19044
18769
18769
18769
18496
18496
18496
18225
18225
18225
17956
17956
17956
17689
17689
17689
17424
17424
17424
17161
17161
17161
16900
16900
16900
16641
16641
16641
16384
16384
16384
16129
16129
16129
15876
15876
15876
15625
15625
15625
15376
15376
15376
15129
15129
15129
14884
14884
14884
14641
14641
14641
14400
14400
14400
14161
14161
14161
13924
13924
13924
13689
13689
13689
13456
13456
13456
13225
13225
13225
12996
12996
12996
12769
12769
12769
12544
12544
12544
12321
12321
12321
12100
12100
12100
11881
11881
11881
11664
11664
11664
11449
11449
11449
11236
11236
11236
11025
11025
11025
10816
10816
10816
10609
10609
10609
10404
10404
10404
10201
10201
10201
10000
10000
10000
9801
9801
9801
9604
9604
9604
9409
9409
9409
9216
9216
9216
9025
9025
9025
8836
8836
8836
8649
8649
8649
8464
8464
8464
8281
8281
8281
8100
8100
8100
7921
7921
7921
7744
7744
7744
7569
7569
7569
7396
7396
7396
7225
7225
7225
7056
7056
7056
6889
6889
6889
6724
6724
6724
6561
6561
6561
6400
6400
6400
6241
6241
6241
6084
6084
6084
5929
5929
5929
5776
5776
5776
5625
5625
5625
5476
5476
5476
5329
5329
5329
5184
5184
5184
5041
5041
5041
4900
4900
4900
4761
4761
4761
4624
4624
4624
4489
4489
4489
4356
4356
4356
4225
4225
4225
4096
4096
4096
3969
3969
3969
3844
3844
3844
3721
3721
3721
3600
3600
3600
3481
3481
3481
3364
3364
3364
3249
3249
3249
3136
3136
3136
3025
3025
3025
2916
2916
2916
2809
2809
2809
2704
2704
2704
2601
2601
2601
2500
2500
2500
2401
2401
2401
2304
2304
2304
2209
2209
2209
2116
2116
2116
2025
2025
2025
1936
1936
1936
1849
1849
1849
1764
1764
1764
1681
1681
1681
1600
1600
1600
1521
1521
1521
1444
1444
1444
1369
1369
1369
1296
1296
1296
1225
1225
1225
1156
1156
1156
1089
1089
1089
1024
1024
1024
961
961
961
900
900
900
841
841
841
784
784
784
729
729
729
676
676
676
625
625
625
576
576
576
529
529
529
484
484
484
441
441
441
400
400
400
361
361
361
324
324
324
289
289
289
256
256
256
225
225
225
196
196
196
169
169
169
144
144
144
121
121
121
100
100
100
81
81
81
64
64
64
49
49
49
36
36
36
25
25
25
16
16
16
9
9
9
4
4
4
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0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ict: Accepted):
_ = input()
a = list(map(int, input().split()))
ans = 10 ** 18
for val in range(-200, 200):
    curr = 0
    for it in a:
        curr += (it - val) ** 2
    ans = min(ans, curr)
print(ans)