Problem:


Score : 300 points

Problem Statement

When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.

You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.

Find B_i for each i = 1, 2, ..., N.

Constraints

2 \leq N \leq 200000

N is even.

1 \leq X_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print N lines.
The i-th line should contain B_i.

Sample Input 1

4
2 4 4 3

Sample Output 1

4
3
3
4

Since the median of X_2, X_3, X_4 is 4, B_1 = 4.

Since the median of X_1, X_3, X_4 is 3, B_2 = 3.

Since the median of X_1, X_2, X_4 is 3, B_3 = 3.

Since the median of X_1, X_2, X_3 is 4, B_4 = 4.

Sample Input 2

2
1 2

Sample Output 2

2
1

Sample Input 3

6
5 5 4 4 3 3

Sample Output 3

4
4
4
4
4
4



Sample input:
4
2 4 4 3


Sample output:
4
3
3
4

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    x = f.read_int_list()
    x0 = x[:]

    x.sort()
    med = x[n/2-1]
    ans = []
    for xi in x0:
        if xi > med:
            ans.append(med)
        else:
            ans.append(x[n/2])

    return "\n".join(map(str, ans))


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:


count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

default_median_index = int((len(sli) + 1) / 2)
default_median = sli[default_median_index]

for i in range(len(li)):
    r = li[i]
    if r < default_median:
        print(default_median)
    else:
        print(sli[default_median_index - 1])

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
if n != 2:
    med_1 = q[n//2-1]
    med_2 = q[n//2]
    
    for i in range(n):
        if p[i] == med_1:
            print(med_2)
        elif p[i] == med_2:
            print(med_1)
        elif p[i] < med_1:
            print(med_2)
        else:
            print(med_1)
else:
    print(p[1])
    print(p[0])

Submission status: Accepted

Solution code:
N = int(input())
Xs = list(map(int, input().split()))

M1, M2 = sorted(Xs)[N // 2 - 1: N // 2 + 1]

for X in Xs:
    if X < M2:
        print(M2)
    else:
        print(M1)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
x=i2()
z=[]
for i in range(n):
 z.append([x[i],i])
y=sorted(z)
s1=y[n//2-1]
s2=y[n//2]
yy=[0 for i in range(n)]
for i in range(n):
 if i<=n//2-1:
   yy[y[i][1]]=s2
 else:
   yy[y[i][1]]=s1
for i in yy:
 print(i[0])

Submission status: Accepted

Solution code:
n=int(input())

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

a_s=sorted(a)

bf=a_s[n//2-1]
bl=a_s[n//2]

for ele in a:
    if(ele>=bl):
        print(bf)
    else:
        print(bl)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))

y = list(sorted(x))
for xi in x:
    if xi <= y[n // 2 - 1]:
        print(y[n // 2])
    else:
        print(y[n // 2 - 1])

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
a = X.copy()
a.sort()
a_l = a[N // 2 - 1]
a_r = a[N // 2]
for i in range(N):
    if X[i] <= a_l:
        print(a_r)
    else:
        print(a_l)

Submission status: Accepted

Solution code:
def solve(n, nums):
    sorted_nums = sorted(nums)
    low = sorted_nums[n/2 - 1]
    high = sorted_nums[n/2]

    for i in xrange(n):
        if nums[i] <= low:
            print high
        else:
            print low
    return


n = int(raw_input())
nums = map(int, raw_input().split())
solve(n, nums)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
y=[x[i] for i in range(n)]
y.sort()
for i in range(n):
    if x[i]==y[n//2-1]:
        print(y[n//2])
    elif x[i]==y[n//2]:
        print(y[n//2-1])
    elif x[i] < y[n//2-1]:
        print(y[n//2])
    else:
        print(y[n//2-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(input())
X = inpl()
Y = [[x, i] for i, x in enumerate(X)]
Y = sorted(Y)
if (N-1)%2==1:
    l = Y[(N-1)//2][0]
    r = Y[(N-1)//2+1][0]
    for i in range(N):
        if X[i]<=l:
            print(r)
        else:
            print(l)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

a=sorted(A)
#print(a)
d=a[N//2]
c=a[N//2 -1]

for i in A:
    if i >= d:
        print(str(c))
    else:
        print(str(d))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
x = sorted(a)
m1 = x[n // 2]
m2 = x[n // 2 - 1]
for i in range(n):
    if a[i] < m1: print(m1)
    else: print(m2)

Submission status: Accepted

Solution code:
N = int(input())
M = N//2
x = list(map(int, input().split()))
y = sorted(x)

thre = y[M]

ans_b = y[M]
ans_s = y[M-1]

for x_ in x:
    if x_ >= thre:
        print(ans_s)
    else:
        print(ans_b)

Submission status: Accepted

Solution code:
N = int(input())
inline = list(map(int,input().split()))
so = inline.copy()
so.sort()


left = so[int(N/2)-1]
right = so[int(N/2)]


for i in range(N):
    if inline[i] <= left:
        print(right)
    else:
        print(left)

Submission status: Accepted

Solution code:
'''
def binsearch(x, t):
    low = 0
    high = len(x) - 1
    k = (low + high) // 2
    if x[low] == t:
        return low
    if x[high] == t:
        return high
    while (low <= high):
        if x[k] < t:
            low = k
        elif x[k] > t:
            high = k
        else:
            return k
        k = (low + high) // 2
'''
N=int(input())
X=[int(i) for i in input().split()]
Y=sorted(X)
M=N//2
L=Y[M-1]
R=Y[M]
for i in range(N):
    if X[i]<=L:
        print(R)
    else:
        print(L)

Submission status: Accepted

Solution code:
N = int(input(
))
X = list(map(int,input().split()))

X_sorted = sorted(X)

for i in range(N):
    x = X[i]
    if x < X_sorted[N//2]:
        print(X_sorted[N//2])
    else:
        print(X_sorted[N//2-1])

Submission status: Accepted

Solution code:
N = int(input())
src = list(map(int,input().split()))
ss = sorted(src)
m1 = ss[N//2 - 1]
m2 = ss[N//2]

for a in src:
    if a <= m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
Xs = list(map(int, input().split()))

Ys = Xs[:]
Ys.sort()

a = Ys[N//2 - 1]
b = Ys[N//2]

for x in Xs:
    if x <= a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(_) for _ in input().split()]

xs = sorted(X)

m1 = xs[N // 2 - 1]
m2 = xs[N // 2]

for i in range(N):
    if X[i] <= m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N=int(raw_input())
X=map(int, raw_input().split())
Y=sorted(X)
m1=Y[N/2-1]
for x in X:
    if x<=m1:
        print Y[N/2]
    else:
        print m1

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split(" ")))
X2 = X[:]
X2.sort()
mid = (N-1)//2
l = X2[mid]
r = X2[mid+1]
for i in range(N):
	if X[i] <= l:
		print(r)
	else:
		print(l)

Submission status: Accepted

Solution code:
n = int(input())
*x, = map(int, input().split())
y = sorted(x)
p, q = y[n//2-1:n//2+1]
ans = []
for i in range(n):
    if x[i] < q:
        ans.append(q)
    else:
        ans.append(p)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
# C
N = int(input())
X_list = list(map(int, input().split()))
X_list_s = sorted(X_list)
Right = X_list_s[N // 2]
Left = X_list_s[(N // 2) - 1]
for i in range(N):
    if X_list[i] >= Right:
        print(Left)
    else:
        print(Right)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr2 = sorted(arr)

mean1 = arr2[N//2-1]
mean2 = arr2[N//2]

for a in arr:
  if a <= mean1:
    print(mean2)
  else:
    print(mean1)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))

S = sorted(A)
x,y = S[len(A)//2-1], S[len(A)//2]

for a in A:
  if a <= x:
    print(y)
  else:
    print(x)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

    n = int(input())
    xs = [int(c) for c in input().split()]

    xs_sorted = sorted(xs)
    cand_s, cand_l = xs_sorted[n // 2 - 1], xs_sorted[n // 2]

    for x in xs:
        print(cand_l if x <= cand_s else cand_s)

Submission status: Accepted

Solution code:
n = int(input())
xxx = list(map(int, input().split()))
yyy = sorted(xxx)
h = n // 2
a, b = yyy[h - 1], yyy[h]
for x in xxx:
    if x <= a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
N = input()
X = map(int, raw_input().split())
Y = sorted(X)
c1,c2 = Y[N/2-1],Y[N/2]
for x in X:
  if x<=c1:
    print c2
  else:
    print c1

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> X(N);
    for (int i = 0; i < N; ++i) std::cin >> X[i];
    
    std::vector<std::pair<int, int>> Y(N);
    for (int i = 0; i < N; ++i) Y[i] = std::make_pair(X[i], i);
    sort(Y.begin(), Y.end());
    std::vector<int> Z(N);
    for (int i = 0; i < N; ++i) Z[Y[i].second] = i;
    
    for (int i = 0; i < N; ++i) {
        if (Z[i] < N / 2) std::cout << Y[N / 2].first << std::endl;
        else std::cout << Y[N / 2 - 1].first << std::endl;
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
  Y = X[:]
  Y.remove(X[i])
  Y.sort()
  print(Y[N // 2])

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
sorted_x = sorted(x)

if sorted_x[n // 2] == sorted_x[n // 2 - 1]:
    print(' '.join([sorted_x[n // 2] * n]))
else:
    ret = []
    for i in range(n):
        if x[i] >= sorted_x[n // 2]:
            ret.append(sorted_x[n // 2])
        else:
            ret.append(sorted_x[n // 2 - 1])
    print(' '.join(ret))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> pii;
typedef vector<pi> vpi;
typedef set<ll> si;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll INF = 1e18;
ll MOD = 1e9+7;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
int l,r,A[100100], B[100100], N;

int main(){
  cin>>N;
  for (int i=0;i<N;++i){cin>>A[i];B[i] = A[i];}
  sort(A,A+N);
  l = A[N/2-1];
  r = A[N/2];
  for (int i=0;i<N;++i){
    if (B[i] <= l)cout<<r<<'\n';
    else cout<<l<<'\n';
  }
}

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
cou = 0
if n != 0 and m != 0:
  if n / m < 0:
    cou += 1
    n *= (-1)
  elif n < 0 and m < 0:
    cou += 2
    n *= (-1)
    m *= (-1)
  else:
    continue
print(cou + abs(n-m))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[I] <= l:print(r)
    else:print(l)

Submission status: Runtime Error

Solution code:
n = list(map(int,input().split()))
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[i] <= l:print(r)
    else:print(l)

Submission status: Runtime Error

Solution code:
n = list(map(int,input().split()))
x = list(map(int,input().split()))
y = sorted(x)
l = y[n/2-2]
r = y[n/2-1]
for i in range(n):
    if x[I] <= l:print(r)
    else:print(l)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
int main(void){
  using namespace std;
  long long int n;
  cin >> n;
  vector<long long int> x(n),s(n-1);
  for (long long int i = 0; i < n; i++){
    cin >> x[i];
  }
  for (long long int i = 0; i<n;i++){
    long long int k = x[i];
    x.erase(x.begin()+i);
    copy(x.begin(), x.end(), s.begin());
    sort(s.begin(), s.end());
    cout << s[n/2-1] << endl;
    x.insert(x.begin()+i,k);
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
from numpy import median
from copy import deepcopy

n = int(input())
x = list(map(int,input().split()))

sx = x.sorted()
newl = deepcopy(sx)
del newl[0]
bigm = median(newl)
newl = deepcopy(sx)
del newl[-1]
minm = median(newl)

med = median(x)

for i in x:
    if i > med:
        print(minm)
    else:
        print(maxm)

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split())

for i in range(n/2):
    print(x[n/2])

for i in range(n/2):
    print(x[(n-1)//2])

Submission status: Runtime Error

Solution code:
print(r.text[:300] + '...')

Submission status: Runtime Error

Solution code:
A

Submission status: Runtime Error

Solution code:
CODE

Submission status: Runtime Error

Solution code:
N = int(input())
b = input().split(" ")

for i in range(N):
    X = b
    X.pop(i)
    X.sort()
    print(X[len(X)//2])

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split(' ')))
x1=x[:]
x1.sort()
x2=x1[:]
for i in range(n):
    l=x[i]
    print(x1)
    x1.remove(l)
    print (x1[int(n/2)-1])
    print(x1)
    x1=x2[:]

Submission status: Runtime Error

Solution code:
import copy

n = int(input())
s = [int(input()) for i in range(n)]

s.sort()

for i in range(n):
    #a = s

    a = copy.deepcopy(s)
    #print(a)
    del a[i]
    #print(a)
    #a.sort()
    #print(a)
    #print("check")

    #print(int((n - 1) / 2))

    if (n - 1) % 2 == 0:
        #print(int(n / 2))
        print(a[int(n / 2)])
    else:
        print(a[int(  (n - 1) / 2  )])

Submission status: Runtime Error

Solution code:
import copy

n = int(input())
s = [int(input()) for i in range(n)]

for i in range(n):
    #a = s

    a = copy.deepcopy(s)
    #print(a)
    del a[i]
    #print(a)
    a.sort()
    #print(a)
    #print("check")

    #print(int((n - 1) / 2))

    if (n - 1) % 2 == 0:
        #print(int(n / 2))
        print(a[int(n / 2)])
    else:
        print(a[int(  (n - 1) / 2  )])

Submission status: Runtime Error

Solution code:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma/2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    value = abs(ma/2-num)
    if minvalue > value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

h, w = map(int, input().split())
s = [None] * h
ss = [None] * h
for i in range(h):
    s[i] = input()
    ss[i] = sorted(s[i])

def c(x, y):
    l = len(y)
    if l == w: return True
    if l % 2 == 0:
        for i in range(w):
            if i not in y:
                y.append(i)
                if c(x, y): return True
                y.pop()
    else:
        for i in range(w):
            if i not in y:
                ok = True
                for j in range(0, h, 2):
                    if j + 1 == h: k = j
                    else: k = j + 1
                    a, b = x[j], x[k]
                    d, e = y[-1], i
                    if s[a][d] == s[b][e] and s[a][e] == s[b][d]:
                        continue
                    ok = False
                if ok:
                    y.append(i)
                    if c(x, y): return True
                    y.pop()
    return False
    
def r(x):
    l = len(x)
    if l == h:
        for i in range(w):
            if c(x, [i]): return True
    if l % 2 == 0:
        for i in range(h):
            if i not in x:
                x.append(i)
                if r(x): return True
                x.pop()
    else:
        for i in range(h):
            if i not in x and ss[x[-1]] == ss[i]:
                x.append(i)
                if r(x): return True
                x.pop()
    return False
            

ok = True
for i in range(h):
    ok = r([i])
    if ok: break
if ok: print('YES')
else: print('NO')

Submission status: Runtime Error

Solution code:
from collections import defaultdict
H, W = map(int, input().split())
s = [input() for _ in range(H)]
if H == 1 and W == 1:
    print('YES')
elif W==1:
    print('NO')
else:

    d_h = [[0 for i in range(28)] for _ in range(H)]
    d_w = [[0 for i in range(28)] for _ in range(W)]

    for i in range(H):
        for c in s[i]:
            d_h[i][ord(c) - ord("a")] += 1

    for i in range(H):
        for j in range(W):
            d_w[j][ord(s[i][j]) - ord("a")] += 1
    #
    # for i in range(H):
    #     d_h[i].sort()
    #     d_w[i].sort()

    check_h = []
    check_w = []

    for i in range(H):
        if i in check_h:
            continue
        for j in range(i + 1, H):
            if j in check_h:
                continue
            else:
                if d_h[i] == d_h[j]:
                    check_h.append(i)
                    check_h.append(j)
                    break

    for i in range(W):
        if i in check_w:
            continue
        for j in range(i + 1, W):
            if j in check_w:
                continue
            else:
                if d_w[i] == d_w[j]:
                    check_w.append(i)
                    check_w.append(j)
                    break

    c_w = 0
    c_h = 0

    for i in range(H):
        if i in check_h:
            c_h += 1
    for i in range(W):
        if i in check_w:
            c_w += 1

    if c_h >= H - 1 and c_w >= W - 1:

        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
from collections import defaultdict
H, W = map(int, input().split())
s = [input() for _ in range(H)]
if H == 1 and W == 1:
    print('YES')
elif H==1:
    print('NO')
else:

    d_h = [[0 for i in range(28)] for _ in range(H)]
    d_w = [[0 for i in range(28)] for _ in range(W)]

    for i in range(H):
        for c in s[i]:
            d_h[i][ord(c) - ord("a")] += 1

    for i in range(H):
        for j in range(W):
            d_w[j][ord(s[i][j]) - ord("a")] += 1
    #
    # for i in range(H):
    #     d_h[i].sort()
    #     d_w[i].sort()

    check_h = []
    check_w = []

    for i in range(H):
        if i in check_h:
            continue
        for j in range(i + 1, H):
            if j in check_h:
                continue
            else:
                if d_h[i] == d_h[j]:
                    check_h.append(i)
                    check_h.append(j)
                    break

    for i in range(W):
        if i in check_w:
            continue
        for j in range(i + 1, W):
            if j in check_w:
                continue
            else:
                if d_w[i] == d_w[j]:
                    check_w.append(i)
                    check_w.append(j)
                    break

    c_w = 0
    c_h = 0

    for i in range(H):
        if i in check_h:
            c_h += 1
    for i in range(W):
        if i in check_w:
            c_w += 1

    if c_h >= H - 1 and c_w >= W - 1:

        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
x=[]
for i in range(N):
    x.append([i,0])
y = list(map(int, input().split()))

for i in range(N):
    x[i][1]=y[i]



x.sort(key=lambda a:a[1])
tmp1=x[int(N/2)]
tmp2=x[int(N/2)+1]

print(x)
for i in range(N):
    if i <N/2-1 and i !=tmp2[0]:
        print(tmp2[1])
    if i <N/2-1 and i ==tmp2[0]:
        print(tmp1[1])
    if i >=N/2-1 and i !=tmp1[0]:
        print(tmp1[1])
    if i >=N/2-1 and i ==tmp1[0]:
        print(tmp2[1])

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
d = {i: {chr(i): 0 for i in range(ord('a'), ord('z')+1)} for i in range(n)}
d2 = {i: {chr(i): 0 for i in range(ord('a'), ord('z')+1)} for i in range(m)}
for i in range(n):
    s = input()
    for j in s:
        d[i][j] += 1
    for j in range(len(s)):
        d2[j][s[j]] += 1

k = [0 for i in range(n)]
k2 = [0 for i in range(m)]

f = True
for i in range(n):
    for j in range(n):
        if d[i] == d[j]:
            k[i] += 1


for i in range(m):
    for j in range(m):
        if d2[i] == d2[j]:
            k2[i] += 1

k2 = sorted(k2)
k = sorted(k)
if n % 2:
    if len(k) > 1:
        if k[1] < 2:
            f = False
else:
    if k[0] < 2:
        f = False

if m % 2:
    if len(k) > 1:
        if k2[1] < 2:
            f = False
else:
    if k2[0] < 2:
        f = False

if f:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
from collections import defaultdict


def main():
    h, w = map(int, input().split())
    s = []
    for _ in range(h):
        col = []
        s.append(col)
        for c in input().strip():
            col.append(ord(c))
    c_row = defaultdict(int)
    for col in s:
        c_row[tuple(sorted(col))] += 1
    if sum(c % 2 for c in c_row.values()) > h % 2:
        print('NO')
        return
    for row, c in c_row.items():
        if c % 2:
            count = defaultdict(int)
            for ch in row:
                count[ch] += 1
            if sum(cc % 2 for cc in count.values()) > w % 2:
                print('NO')
                return

    c_col = defaultdict(int)
    for col in zip(*s):
        c_col[tuple(sorted(col))] += 1
    if sum(c % 2 for c in c_col.values()) > w % 2:
        print('NO')
        return

    for col, c in c_col.items():
        if c % 2:
            count = defaultdict(int)
            for ch in col:
                count[ch] += 1
            if sum(cc % 2 for cc in count.values()) > h % 2:
                print('NO')
                return

    if s[0][0] == ord('b'):
        print('NO')
    else:
        print('YES')


main()

Submission status: Runtime Error

Solution code:
N = int(input())
x = list(map(int, input().split()))

for i in range(N):
    temp = x[0:i].append(x[i+1:N])
    sort(temp)
    print(temp[(i+1)/2])

Submission status: Runtime Error

Solution code:
from sys import exit
r, s = map(int, input().split())
a = [input() for i in range(r)]

def check(x):
    cnt = [0 for i in range(300)]
    for i in x:
        cnt[ord(i)] += 1
    odd = sum(i % 2 for i in cnt)
    if odd != len(x) % 2:
        print('NO')
        exit(0)

midr, mids = None, None

dr = dict()
for i in range(r):
    b = tuple(sorted(a[i]))
    if b not in dr:
        dr[b] = 1
    else:
        dr[b] += 1
odd = 0
for k in dr:
    if dr[k] % 2 == 1:
        odd += 1
        midr = k
if odd != r % 2:
    print('NO')
    exit(0)
if odd == 1:
    check(midr)

ds = dict()
for j in range(s):
    b = tuple(sorted([a[i][j] for i in range(r)]))
    if b not in ds:
        ds[b] = 1
    else:
        ds[b] += 1
odd = 0
for k in ds:
    if ds[k] % 2 == 1:
        odd += 1
        mids = k
if odd != s % 2:
    print('NO')
    exit(0)
if odd == 1:
    check(mids)

if mids:
    for k in dr:
        indeksi = [i for i in range(r) if tuple(sorted(a[i])) == k]
        check([mids[i] for i in indeksi])
if midr:
    for k in ds:
        indeksi = [j for j in range(s) if tuple(
            sorted([a[i][j] for i in range(r)])) == k]
        check([midr[j] for j in indeksi])

print('YES')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""

import numpy as np

N = int(input())
X = np.array(map(int, input().split(" ")))

for i in range(N):
    print(np.append(X[:i], X[i+1:]).median)