def main():
    n = int(input())
    v = [int(x) for x in input().split()]
    ans = 0
    s = 0
    mp = {}

    for i in range(0, n):
        l = 0
        if (v[i] - 1) in mp:
            l = mp[v[i] - 1]

        r = 0
        if (v[i] + 1) in mp:
            r = mp[v[i] + 1]

        ans = ans + i * v[i] - s - l + r
        s = s + v[i]

        x = 0
        if v[i] in mp:
            x = mp[v[i]]
            del mp[v[i]]

        mp[v[i]] = x + 1

    print(ans)

main()


n = int(input())
ct = {}
sm = 0
ans = 0
arr = list(map(int, input().split()))

for i in range(0, n):
	ans += arr[i] * i - sm;
	ans -= ct.get(arr[i] - 1, 0)
	ans += ct.get(arr[i] + 1, 0)
	sm += arr[i]
	ct[arr[i]] = ct.get(arr[i], 0) + 1

print(ans)


n = int(input())
ct = {}
sm = 0
ans = 0
arr = list(map(int, input().split()))

for i in range(0, n):
	ans += a[i] * i - sm;
	ans -= ct.get(arr[i] - 1, 0)
	ans += ct.get(arr[i] + 1, 0)
	sm += arr[i]
	ct[arr[i]] = ct.get(arr[i], 0) + 1

print(ans)


N=int(input())
s=map(int,input().split())
M={}
ans=0
j=1-N
for i in s:
    M[i]=M.get(i,0)+1
    ans+=j*i
    j+=2
for i in s:
    ans+=M[i-1]
    ans-=M[i+1]
    M[i]=M.get(i,0)-1
print(ans)


N=int(input())
s=list( map(int, input().split()) )
M={}
ans=0
j=1-N
for i in s:
    M[i]=M.get(i,0)+1
    ans+=j*i
    j+=2
for i in s:
    ans+=M.get(i-1,0)
    ans-=M.get(i+1,0)
    M[i]=M.get(i,0)-1
print(ans)


import bisect
src=input()
n=int(src)

def consum(x):
    data=x[:]
    for i in range(1,len(data)):
        data[i]+=data[i-1]

    return data

src=input()
a=list([0])
a.extend(list( map(int,src.split() )))

pro=consum(a)

res=0
ma={}
for i in range(1,n+1):
    if(ma.get(a[i])):
        ma[a[i]]+=1
    else:
        ma[a[i]]=1

    res+=(i-1)*a[i]-pro[i-1]

    if(ma.get(a[i]-1)):
        res-=ma[a[i]-1]
    if(ma.get(a[i]+1)):
        res+=ma[a[i]+1]

print(res)


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

sm = 0
dc = {}
res = 0
for i in range(n):
    res += a[i] * i - sm
    if a[i] + 1 in dc:
        res += dc[a[i]+1]
    if a[i] - 1 in dc:
        res -= dc[a[i]-1]
    sm += a[i]
    if(a[i] in dc):
        dc[a[i]] += 1
    else :
        dc[a[i]] = 1
print(res)


n = int(input())
a = list(map(int, input().split()))
ans = 0
mus = 0
for i in range(n - 1, -1, -1):
    ans += mus - a[i] * (n - 1 - i)

    mus += a[i]

cnt = dict()
for i in range(n - 1, -1, -1):
    if (a[i] + 1) not in cnt:
        cnt[a[i] + 1] = 0
    ans -= cnt[a[i] + 1]
    if (a[i] - 1) not in cnt:
        cnt[a[i] - 1] = 0
    ans += cnt[a[i] - 1]

    if a[i] not in cnt:
        cnt[a[i]] = 0
    cnt[a[i]] += 1

print(ans)


n = int(input())
a = [int(i) for i in input().split()]

from collections import defaultdict
d = defaultdict(lambda : 0)

ans = 0
s = 0;
for i in range(n):
    e = a[i]
    prev = i - d[e] - d[e - 1] - d[e + 1]
    ans += e * prev - s + d[e] * e + d[e - 1] * (e - 1) + d[e + 1] * (e + 1)
    d[e] += 1
    s += e

print(ans)


def main():
    n = int(input())
    v = list(map(int, input().split()))
    m = dict()
    res = 0

    for i in v:
        if i not in m:
            m[i] = 0
        m[i] += 1
    k = v.copy()

    for i in range(n - 1, 0, -1):
        k[i - 1] = k[i] + k[i - 1]

    for i in range(0, n - 1):
        res += -(n - i - 1) * v[i] + k[i + 1]
        m[v[i]] -= 1
        if v[i] + 1 in m:
            res -= m[v[i] + 1]
        if v[i] - 1 in m:
            res += m[v[i] - 1]

    print(res)

if __name__ == '__main__':
    main()


n = int(input())
v = list(map(int, input().split()))
m={}
res=0

for i in v:
     if not i in m:
          m[i]=0
     m[i]+=1

k=v.copy()

for i in range(n-1,0,-1):
     k[i-1]=k[i]+k[i-1]

for i in range(0,n-1):
     res += -(n-i-1)*v[i]+k[i+1]
     m[v[i]]-=1
     if v[i]+1 in m:
          res-=m[v[i]+1]
     if v[i]-1 in m:
          res+=m[v[i]-1]

print(res)


#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0;i < n;i++)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    int d = 0;
    for (int i = 0; i < n - 1;i++)
        for (int j = i + 1; i < n;i++)
            if (abs(a[i] - a[j]) > 1)
                d += a[j] - a[i];
    cout << d;
    return 0;
}


n = int(input())
a = [int(x) for x in input().split()]
d = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if abs(a[i] - a[j]) > 1:
            d += a[j] - a[i]
print(d)


n = int(input())
a = [int(x) for x in input().split()]
d = 0
for i in range(n):
    d += -1 * a[i] * (n - i - 1)
    d += a[i] * i
di = {}
for i in range(n):
    if a[i] not in di:
        di[a[i]] = 0
    if a[i] - 1 in di:
        d -= di[a[i] - 1]
    if a[i] + 1 in di:
        d += di[a[i] + 1]
    di[a[i]] += 1
print(d)


from collections import Counter
def lInt(d = None): return map(int, input().split(d))

acc = 0; pre = 0
freq = Counter()
n, *_ = lInt()

for i, v in enumerate(lInt()):
  m = i-freq[v-1]-freq[v]-freq[v+1]
  a = pre+(v-1)*freq[v-1]+v*freq[v]+(v+1)*freq[v+1]
  acc += a+m*v
  pre -= v
  freq[v] += 1
print(acc)


from collections import Counter
def lInt(d = None): return map(int, input().split(d))

a = 0; p = 0
f = Counter()
n, *_ = lInt()

for i, v in enumerate(lInt()):
  x = f[v-1]
  y = f[v]
  z = f[v+1]
  m = i-x-y-z
  a = p+(v-1)*x+v*y+(v+1)*z
  a += a+m*v
  p -= v
  f[v] += 1
print(a)


from collections import Counter

class BIT:
  def __init__(self, n):

    self.n = n
    self.tree = Counter()

  def __setitem__(self, i, v):

    while i <= self.n:
      self.tree[i] += v
      i += i&-i

  def __getitem__(self, i):

    p = 0

    while i > 0:
      p += self.tree[i]
      i -= i&-i
    return p

def lInt(d = None): return map(int, input().split(d))

MAX = 1000000000
n, *_ = lInt()
b = BIT(MAX); c = BIT(MAX)
acc = 0

for v in lInt():
  l = b[v-2]
  r = b[MAX]-b[v+1]
  pl = c[v-2]
  pr = c[MAX]-c[v+1]
  acc += (l+r)*v-pl-pr
  b[v] = 1
  c[v] = v
print(acc)


from collections import Counter
def lInt(d = None): return map(int, input().split(d))

n, *_ = lInt()
acc = 0; pre = 0; i = 0
freq = Counter()

for v in lInt():
  m = i-freq[v-1]-freq[v]-freq[v+1]
  a = pre+(v-1)*freq[v-1]+v*freq[v]+(v+1)*freq[v+1]
  acc += a+m*v
  pre -= v
  freq[v] += 1
  i += 1
print(acc)


from collections import Counter
def lInt(d = None): return map(int, input().split(d))

t = 0; p = 0
f = Counter()
n, *_ = lInt()

for i, v in enumerate(lInt()):
  x = f[v-1]
  y = f[v]
  z = f[v+1]
  m = i-x-y-z
  a = p+(v-1)*x+v*y+(v+1)*z
  t += a+m*v
  p -= v
  f[v] += 1
print(t)


from collections import Counter

class BIT:
  def __init__(self, n):

    self.n = n
    self.tree = Counter()

  def __setitem__(self, i, v):

    while i <= self.n:
      self.tree[i] += v
      i += i&-i

  def __getitem__(self, i):

    p = 0

    while i > 0:
      p += self.tree[i]
      i -= i&-i
    return p

def lInt(d = None): return map(int, input().split(d))

MAXI = 1000000000
n, *_ = lInt()
a = list(lInt())
b = BIT(MAXI);
acc = 0

for i in range(n):
  n_lt = b[a[i]-2]
  n_gt = b[MAXI]-b[a[i]+1]
  acc += n_lt*2
  acc -= n_gt*2
  b[a[i]] = 1
print(acc)


n = int(input())
arr = list(map(int, input().split(' ')))
mp = {}
cum = 0
res = 0
mp[arr[0]] = 1
for i in range(1,n):
	res += arr[i] * i - cum
	if arr[i]+1 in mp:
		res += mp[arr[i]+1]
	if arr[i]-1 in mp:
		res -= mp[arr[i]-1]
	mp[arr[i]] += 1
print(res)


n = int(input())
arr = list(map(int, input().split(' ')))
mp = {}
cum = 0
res = 0
mp[arr[0]] = 1
for i in range(1,n):
	res += arr[i] * i - cum
	if arr[i]+1 in mp:
		res += mp[arr[i]+1]
	if arr[i]-1 in mp:
		res -= mp[arr[i]-1]
	cum += arr[i]
	if arr[i] not in mp:
		mp[arr[i]] = 0
	mp[arr[i]] += 1
print(res)


n = int(input())
arr = list(map(int, input().split(' ')))
mp = {}
cum = arr[0]
res = 0
mp[arr[0]] = 1
for i in range(1,n):
	res += arr[i] * i - cum
	if arr[i]+1 in mp:
		res += mp[arr[i]+1]
	if arr[i]-1 in mp:
		res -= mp[arr[i]-1]
	cum += arr[i]
	if arr[i] not in mp:
		mp[arr[i]] = 0
	mp[arr[i]] += 1
	#print(res)
print(res)


n=int(input())
dic={}
sl=list(map(int,input().split()))
summ=[0 for i in range(n)]
summ[n-1]=sl[n-1]
for i in range(n-2,-1,-1):
    summ[i]=summ[i+1]+sl[i]
for i in sl:
    if i in dic:
        dic[i]=dic[i]+1
    else:
        dic[i]=1
fuckdiff=0
for i in range(0,n-1):
    fuckdiff+=summ[i]-(n-i)*sl[i]
    if (sl[i]+1) in dic:
        fuckdiff-=dic[sl[i]+1]
    if (sl[i]-1) in dic:
        fuckdiff+=dic[sl[i]-1]
    dic[sl[i]]-=1
print(fuckdiff)


#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
//#define int long long
using namespace std;
typedef pair<int, int> ii;

signed main() {
    FAST_IO;
    //FILE_IO;

    string s;
    cin >> s;
    map<char, int> cnt, encountered;
    for (auto x:s) {
        cnt[x]++;
        encountered[x] = 1;
        if (x == 'b' && !encountered['a']) {
            cout << "NO";
            return 0;
        }
    }
    if ((cnt['c'] == cnt['a']) || (cnt['c'] == cnt['b'])) cout << "YES";
    else cout << "NO";
    return 0;
}


#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
//#define int long long
using namespace std;
typedef pair<int, int> ii;

signed main() {
    FAST_IO;
    //FILE_IO;

    string s;
    cin >> s;
    map<char, int> cnt;
    string val;
    val += s[0];
    for (int i = 1; i < s.length(); i++) {
        cnt[s[i]]++;
        if (s[i] != s[i - 1]) val += s[i];
    }
    if (val != "abc") {
        cout << "NO";
        return 0;
    }
    if ((cnt['c'] == cnt['a']) || (cnt['c'] == cnt['b'])) cout << "YES";
    else cout << "NO";
    return 0;
}


#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
//#define int long long
using namespace std;
typedef pair<int, int> ii;

signed main() {
    FAST_IO;
    //FILE_IO;

    string s;
    cin >> s;
    map<char, int> cnt;
    string val;
    val += s[0];
    cnt[s[0]]++;
    for (int i = 1; i < s.length(); i++) {
        cnt[s[i]]++;
        if (s[i] != s[i - 1]) val += s[i];
    }
    if (val != "abc") {
        cout << "NO";
        return 0;
    }
    if ((cnt['c'] == cnt['a']) || (cnt['c'] == cnt['b'])) cout << "YES";
    else cout << "NO";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0;
	bool ok = true;
	char pr = 'z';
	for(int i = 0; i < s.size(); i++){
		if(pr == 'z'){
			pr = s[i];
		}else{
			if(pr == s[i]){
				continue;
			}else{
				if(s[i] - pr == 1){
					pr = s[i];
				}else{
					ok = false;
				}
			}
		}
		if(s[i] == 'a') a++;
		if(s[i] == 'b') b++;
		if(s[i] == 'c') c++;
	}
	if(c == a || c == b){
		if(ok){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}else{
		cout << "NO";
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0;
	bool ok = true;
	char pr = 'z';
	for(int i = 0; i < s.size(); i++){
		if(pr == 'z'){
			pr = 'a';
		}else{
			if(pr == s[i]){
				continue;
			}else{
				if(s[i] - pr == 1){
					pr = s[i];
				}else{
					ok = false;
				}
			}
		}
		if(s[i] == 'a') a++;
		if(s[i] == 'b') b++;
		if(s[i] == 'c') c++;
	}
	if(c == a || c == b){
		if(ok){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}else{
		cout << "NO";
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0;
	bool ok = true;
	char pr = 'z';
	for(int i = 0; i < s.size(); i++){
		if(pr == 'z'){
			pr = s[i];
		}else{
			if(pr == s[i]){
				continue;
			}else{
				if(s[i] - pr == 1){
					pr = s[i];
				}else{
					ok = false;
				}
			}
		}
		if(s[i] == 'a') a++;
		if(s[i] == 'b') b++;
		if(s[i] == 'c') c++;
	}
	if((c == a || c == b) && b && c){
		if(ok){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}else{
		cout << "NO";
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0;
	bool ok = true;
	char pr = 'z';
	for(int i = 0; i < s.size(); i++){
		if(pr == 'z'){
			pr = s[i];
		}else{
			if(pr == s[i]){
				continue;
			}else{
				if(s[i] - pr == 1){
					pr = s[i];
				}else{
					ok = false;
				}
			}
		}
		if(s[i] == 'a') a++;
		if(s[i] == 'b') b++;
		if(s[i] == 'c') c++;
	}
	if((c == a || c == b) && a && b && c){
		if(ok){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}else{
		cout << "NO";
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	int a = 0, b = 0, c = 0;
	cin >> s; int ok = 0;
	if(s[0] == 'a') ok++;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'a') a++;
		if(s[i] == 'b') b++;
		if(s[i] == 'c') c++;
	}
	if(b == 0) ok--;
	if(c == a || c == b){
		if(ok){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}else{
		cout << "NO";
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0;
	bool ok = true; char pr = 'z';
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'a') a++;
		if(s[i] == 'b') b++;
		if(s[i] == 'c') c++;
		if(pr == 'z'){
			pr = s[i];
		}else{
			if(pr == s[i]){
				continue;
			}else{
				if((s[i] - pr) == 1){
					pr = s[i];
				}else{
					ok = false;
				}
			}
		}
	}
	if((c == a || c == b) && a && b && c){
		if(ok){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}else{
		cout << "NO";
	}
}


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) begin(a), end(a)
#define pb push_back
#define ins insert
#define si size
#define fi first
#define se second
#define ll long long

int main() {
    string s;
    cin >> s;
    string s1 = s;
    sort(all(s1));
    int i = 0, a = 0, b = 0, c = 0;
    while (i < s.size()) {
        if (s1[i] != s[i]) {
            cout << "NO" << endl;
            return 0;
        }
        if (s[i] == 'a') ++a;
        else if (s[i] == 'b') ++b;
        else ++c;
        ++i;
    }
    if (a == c && b == c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) begin(a), end(a)
#define pb push_back
#define ins insert
#define si size
#define fi first
#define se second
#define ll long long

int main() {
    string s;
    cin >> s;
    string s1 = s;
    sort(all(s1));
    int i = 0;
    while (i < s.size()) {
        if (s1[i] != s[i]) {
            cout << "NO" << endl;
            return 0;
        }
        ++i;
    }
    cout << "YES" << endl;
    return 0;
}

/*
  5 6
4 2
3 4
8 11
6 5
17 2
 */


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) begin(a), end(a)
#define pb push_back
#define ins insert
#define si size
#define fi first
#define se second
#define ll long long

int main() {
    string s;
    cin >> s;
    string s1 = s;
    sort(all(s1));
    int i = 0;
    while (i < s.size()) {
        if (s1[i] != s[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

/*
  5 6
4 2
3 4
8 11
6 5
17 2
 */


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) begin(a), end(a)
#define pb push_back
#define ins insert
#define si size
#define fi first
#define se second
#define ll long long

int main() {
    string s;
    cin >> s;
    string s1 = s;
    sort(all(s1));
    long long  i = 0, a = 0, b = 0, c = 0;
    while (i < s.size()) {
        if (s1[i] != s[i]) {
            cout << "NO" << endl;
            return 0;
        }
        if (s[i] == 'a') ++a;
        else if (s[i] == 'b') ++b;
        else ++c;
        ++i;
    }
    if ((a == c || b == c) && a > 0 && b > 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) begin(a), end(a)
#define pb push_back
#define ins insert
#define si size
#define fi first
#define se second
#define ll long long

int main() {
    string s;
    cin >> s;
    string s1 = s;
    sort(all(s1));
    int i = 0, a = 0, b = 0, c = 0;
    while (i < s.size()) {
        if (s1[i] != s[i]) {
            cout << "NO" << endl;
            return 0;
        }
        if (s[i] == 'a') ++a;
        else if (s[i] == 'b') ++b;
        else ++c;
        ++i;
    }
    if (a == c || b == c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;

int main()
{
	string n;
	cin>>n;
	int as=0, bs=0, cs= 0;

	for(auto &c:n){
		if (c=='a'){
			as++;
		}
		if(c=='c' ){
			if(bs==0){
				cout<<"NO";
				return 0;
			}

			cs++;

		}
		else if(c=='b'){
			if(as==0){
				cout<<"NO";
				return 0;
			}
			bs++;
		}

	}
	if(bs==0){
		cout<<"NO";
		return 0;
	}
	if(cs!=bs && cs!=as){
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;

}


#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;

int main()
{
	string n;
	cin>>n;
	int as=0, bs=0, cs= 0;

	for(auto &c:n){
		if (c=='a'){
			as++;
		}
		if(c=='c' ){
			if(bs==0){
				cout<<"NO";
				return 0;
			}

			cs++;

		}
		else if(c=='b'){
			if(as==0){
				cout<<"NO";
				return 0;
			}
			bs++;
		}

	}

	if(cs!=bs && cs!=as){
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;

}


#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	cin>>s;
	int as=0, bs=0, cs= 0;
	int n = s.size();
	int idx=0;

	while(idx<n){

		while(idx<n && s[idx]=='a'){
			as++;
			//cout<<s[idx]<<endl;
			idx++;
		}

		if(s[idx]!='b'){

			cout<<"NO";
		    return 0;
		}
		while(idx<n && s[idx]=='b'){
			if (as==0){
				cout<<"NO";
				return 0;
			}
			bs++;
			idx++;
		}

		while(idx<n && s[idx]=='c'){
			cs++;
			idx++;
		}

		if(idx<n){
			cout<<"NO";
			return 0;
		}
	}

	if(cs!=bs && cs!=as){
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;

}


#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	cin>>s;
	int as=0, bs=0, cs= 0;
	int n = s.size();
	int idx=0;

	while(idx<n){

		while(idx<n && s[idx]=='a'){
			as++;
			//cout<<s[idx]<<endl;
			idx++;
		}

		if(s[idx]!='b'){

			cout<<"NO";
		    return 0;
		}
		while(idx<n && s[idx]=='b'){
			if (as==0){
				cout<<"NO";
				return 0;
			}
			bs++;
			idx++;
		}

		while(idx<n && s[idx]=='c'){
			cs++;
			idx++;
		}
	}

	if(cs!=bs && cs!=as){
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;

}


#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	cin>>s;
	int as=0, bs=0, cs= 0;
	int n = s.size();
	int idx=0;
	while(idx<n){

		while(idx<n && s[idx]=='a'){
			as++;
			//cout<<s[idx]<<endl;
			idx++;
		}

		if(s[idx]!='b'){

			cout<<"NO";
		    return 0;
		}
		while(idx<n && s[idx]=='b'){
			bs++;
			idx++;
		}

		while(idx<n && s[idx]=='c'){
			cs++;
			idx++;
		}
	}

	if(cs!=bs && cs!=as){
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;

}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    int vis[5];
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag=0;
        memset(vis,0,sizeof(vis));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                vis[0]++;
            }
            else if(s[i]=='b')
            {
                vis[1]++;
            }
            else if(s[i]=='c')
            {
                vis[2]++;
            }
            if(i>=1&&s[i-1]>s[i])
                flag=1;
        }
        if(flag)
            printf("NO\n");
        else
        {
            if(vis[2]==vis[1]||vis[2]==vis[0])
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    int vis[5];
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag=0;
        memset(vis,0,sizeof(vis));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                vis[0]++;
            }
            else if(s[i]=='b')
            {
                vis[1]++;
            }
            else if(s[i]=='c')
            {
                vis[2]++;
            }
            if(i>=1&&s[i-1]>s[i])
                flag=1;
        }
        if(flag)
            printf("NO\n");
        else
        {
            if(vis[2]==vis[1]||vis[2]==vis[0]&&(vis[0]!=0&&vis[1]!=0)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    int vis[5];
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag=0;
        memset(vis,0,sizeof(vis));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                vis[0]++;
            }
            else if(s[i]=='b')
            {
                vis[1]++;
            }
            else if(s[i]=='c')
            {
                vis[2]++;
            }
            if(i>=1&&s[i-1]>s[i])
                flag=1;
        }
        if(flag)
            printf("NO\n");
        else
        {
            if(（vis[2]==vis[1]||vis[2]==vis[0]）&&(vis[0]!=0&&vis[1]!=0))
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    int vis[5];
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag=0;
        memset(vis,0,sizeof(vis));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                vis[0]++;
            }
            else if(s[i]=='b')
            {
                vis[1]++;
            }
            else if(s[i]=='c')
            {
                vis[2]++;
            }
            if(i>=1&&s[i-1]>s[i])
                flag=1;
        }
        if(flag)
            printf("NO\n");
        else
        {
            if((vis[2]==vis[1]||vis[2]==vis[0])&&(vis[0]!=0&&vis[1]!=0))
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    while(~scanf("%s",s))
    {
        int flag1=0,flag2=0,flag3=0;
        int cnt1=0,cnt2=0,cnt3=0;
        int len=strlen(s);
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                flag1=1;
                cnt1++;
            }
            else if(s[i]=='b')
            {
                if(flag1==0)
                {
                    printf("NO\n");
                    return 0;
                }
                else
                {
                    flag2=1;
                    cnt2++;
                }
            }
            else
            {
                if(flag2==0||flag1==0)
                {
                    printf("NO\n");
                    return 0;
                }
                else if(flag2&&flag1)
                {
                    flag3=1;
                    cnt3++;
                }
            }
        }
        if(cnt3==cnt2||cnt3==cnt1)
        {
            if(flag1&&flag2&&flag3)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag=0,a=0,b=0,c=0;
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                a++;
            }
            else if(s[i]=='b')
            {
                b++;
            }
            else if(s[i]=='c')
            {
                c++;
            }
            if(i>=1&&s[i-1]>s[i])
                flag=1;
        }
        if(flag)
            printf("NO\n");
        else
        {
            if((c==a||c==b)&&(b!=0&&a!=0))
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    int vis[5];
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag1=0,flag2=0,flag3=0,flag=0;
        memset(vis,0,sizeof(vis));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                vis[0]++;
                flag1=1;
                if(flag2||flag3)
                    flag=1;
            }
            else if(s[i]=='b')
            {
                vis[1]++;
                flag2=1;
                if(!flag1||flag3)
                    flag=1;
            }
            else
            {
                vis[2]++;
                flag3=1;
                if(!flag1||!flag2)
                    flag=1;

            }
        }
        if(flag)
            printf("NO\n");
        else
        {
            if(vis[2]==vis[1]||vis[2]==vis[0])
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
char s[5010];
int main()
{
    int vis[5];
    while(~scanf("%s",s))
    {
        int len=strlen(s);
        int flag=0;
        memset(vis,0,sizeof(vis));
        for(int i=0; i<len; i++)
        {
            if(s[i]=='a')
            {
                vis[0]++;
            }
            else if(s[i]=='b')
            {
                vis[1]++;
            }
            else if(s[i]=='c')
            {
                vis[2]++;
            }
            if(i>=1&&s[i-1]>s[i])
                flag=1;
        }
        if(flag)
            printf("NO\n");
        else
        {
            if(vis[2]==vis[1]||vis[2]==vis[0]&&(vis[0]!=0&&vis[1]!=0))
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        if(i!=(len-1))
        {
            if(str[i]>str[i+1])
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }

        if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;

    }

      if(c==a||c==b)
            cout<<"YES"<<endl;
      else
        cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        if(i!=(len-1))
        {
            if(str[i]>str[i+1])
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }

       else if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;

    }

      if(c==a||c==b&&a>1&&b>1)
            cout<<"YES"<<endl;
      else
        cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int length=str.length();
    for(int i=0;i<length;i++)
    {
        if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;
    }

    if(a>b)
    {
        if(c==a||c==b)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    }
       else
        cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int length=str.length();
    for(int i=0;i<length;i++)
    {
        if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;
    }

    if(a>=b)
    {
        if(c==a||c==b)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    }
       else
        cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        if(i!=(len-1))
        {
            if(str[i]>str[i+1])
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }

       else if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;

    }
      if((c==a||c==b)&&a>=1&&b>=1)
            cout<<"YES"<<endl;
      else
        cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int length=str.length();
    for(int i=0;i<length;i++)
    {
        if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;
    }
    cout<<a<<b<<c<<endl;
    if(a>b)
    {
        if(c==a||c==b)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    }
       else
        cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int a=0,b=0,c=0;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        if(i!=(len-1))
        {
            if(str[i]>str[i+1])
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }

       if(str[i]=='a')
            a++;
        else if(str[i]=='b')
            b++;
        else if(str[i]='c')
            c++;

    }
      if((c==a||c==b)&&a>=1&&b>=1)
            cout<<"YES"<<endl;
      else
        cout<<"NO"<<endl;

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string x;
	cin >> x;
	int arr[3] = {};
	bool first_a = false, first_b = false;
	if (x[0] == 'a') first_a = true;
	for (int i = 0; i < x.length() && first_a; i++)
	{
		if (x[i] = 'c') break;
		else if (x[i] = 'b') { first_b = true;  break; }
	}

	for (int i = 0; i < x.length(); i++)
		arr[x[i] - 97]++;
	if (arr[2] == arr[1] && first_a && first_b || arr[2] == arr[0] && first_a && first_b) cout << "YES";
	else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string x;
	cin >> x;
	int arr[3] = {};
	bool first_a = false, first_b = false;
	if (x[0] == 'a') first_a = true;
	for (int i = 0; i < x.length() && first_a; i++)
	{
		if (x[i] == 'c') break;
		else if (x[i] == 'b') { first_b = true;  break; }
	}

	int z=x.find_first_of('c');   // returns 10
	bool more_c = true;
	for (int k = z; k < x.length(); k++) if (x[k] != 'c') more_c = false;
	bool more_b = true;
	 z = x.find_first_of('b');
	for (int k = z; k < x.length(); k++) if (x[k] != 'b') more_b = false;

	for (int i = 0; i < x.length(); i++)
		arr[x[i] - 97]++;
	if (arr[2] == arr[1] && first_a && first_b && more_b && more_c || arr[2] == arr[0] && first_a && first_b && more_b && more_c) cout << "YES";
	else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string x;
	cin >> x;
	int arr[3] = {};
	bool first_a = false, first_b = false;
	if (x[0] == 'a') first_a = true;
	for (int i = 0; i < x.length() && first_a; i++)
		if (x[i] = 'b') first_b = true;

	for (int i = 0; i < x.length(); i++)
		arr[x[i] - 97]++;
	if (arr[2] == arr[1] && first_a && first_b || arr[2] == arr[0] && first_a && first_b) cout << "YES";
	else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string x;
	cin >> x;
	int arr[3] = {};
	bool first_a = false, first_b = false;
	if (x[0] == 'a') first_a = true;
	for (int i = 0; i < x.length() && first_a; i++)
	{
		if (x[i] == 'c') break;
		else if (x[i] == 'b') { first_b = true;  break; }
	}

	int z=x.find_first_of('c');   // returns 10
	bool more = true;
	for (int k = z; k < x.length(); k++) if (x[k] != 'c') more = false;

	for (int i = 0; i < x.length(); i++)
		arr[x[i] - 97]++;
	if (arr[2] == arr[1] && first_a && first_b && more || arr[2] == arr[0] && first_a && first_b && more) cout << "YES";
	else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string x;
	cin >> x;
	int arr[3] = {};
	bool first_a = false, first_b = false;
	if (x[0] == 'a') first_a = true;
	for (int i = 0; i < x.length() && first_a; i++)
	{
		if (x[i] == 'c') break;
		else if (x[i] == 'b') { first_b = true;  break; }
	}

	int z=x.find_first_of('c');   // returns 10
	bool more_c = true;
	for (int k = z; k < x.length(); k++) if (x[k] != 'c') more_c = false;
	bool more_a = true;
	 z = x.find_first_of('b');
	for (int k = z; k < x.length(); k++) if (x[k] == 'a') more_a = false;

	for (int i = 0; i < x.length(); i++)
		arr[x[i] - 97]++;
	if (arr[2] == arr[1] && first_a && first_b && more_a && more_c || arr[2] == arr[0] && first_a && first_b && more_a && more_c) cout << "YES";
	else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string x;
	cin >> x;
	int arr[3] = {};
	bool first_a = false, first_b = false;
	if (x[0] == 'a') first_a = true;
	for (int i = 0; i < x.length() && first_a; i++)
	{
		if (x[i] == 'c') break;
		else if (x[i] == 'b') { first_b = true;  break; }
	}

	for (int i = 0; i < x.length(); i++)
		arr[x[i] - 97]++;
	if (arr[2] == arr[1] && first_a && first_b || arr[2] == arr[0] && first_a && first_b) cout << "YES";
	else cout << "NO";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        {
          cb++;
        }
      else if(s[i]=='c' )
        {
          cc++;

        }

    }
    if(ca==0 || cb==0)
      cout<<"NO";
    else if(cb==cc)
      cout<<"YES";
    else if(ca==cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        {
          cb++;
        }
      else if(s[i]=='c' )
        {
          cc++;

        }

    }
    if(ca==0 || cb==0)
      cout<<"NO";
    else if(cb>=cc)
      cout<<"YES";
    else if(ca>=cc)
      cour<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        {
          cb++;
        }
      else if(s[i]=='c' )
        {
          cc++;

        }

    }
    if(ca==0 || cb==0 || cc==0)
      cout<<"NO";
    else if(cb>=cc || ca>=cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        { a=1;
          cb++;
        }
      else if(s[i]=='c' )
        { b=1;
          cc++;

        }

    }
    if(cb>=cc || ca>=cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        {
          cb++;
        }
      else if(s[i]=='c' )
        {
          cc++;

        }

    }
    if(ca==0 || cb==0)
      cout<<"NO";
    else if(cb>=cc)
      cout<<"YES";
    else if(ca>=cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        {
          cb++;
        }
      else if(s[i]=='c' )
        {
          cc++;

        }

    }
    if(ca==0 || cb==0)
      cout<<"NO";
    else if(cb>=cc || ca>=cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    string k=s;
    sort(k.begin(),k.end());
    if(s!=k)
    {
      cout<<"NO";
        return 0;
    }
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' )
        ca++;
      else if(s[i]=='b' )
        {
          cb++;
        }
      else if(s[i]=='c' )
        {
          cc++;

        }

    }
    if(ca==0 || cb==0 || cc==0)
      cout<<"NO";
    else if(cb>cc || ca>cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{   string s;
    cin>>s;
    int a=0,b=0,c=0,ca=0,cb=0,cc=0;

    for(int i=0;i<s.size();i++)
    {
      if(s[i]=='a' && a==0 && b==0 && c==0)
        ca++;
      if(s[i]=='b' && a==1  && b==0 && c==0 )
        { a=1;
          cb++;
        }
      if(s[i]=='c' &&  a==1  && b==1 && c==0)
        { b=1;
          cc++;

        }
      else
      {
        cout<<"NO";
        return 0;
      }

    }
    if(cb>=cc || ca>=cc)
      cout<<"YES";
    else
      cout<<"NO";

}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "as."
using namespace std;
const int N=1e5+3;
string s;
bool ok[5];
int sl[5] ;
int main()
{

    cin >> s;
    for(int i = 0 ; i < s.size() ;i++)
    {
        sl[s[i]-'a'] ++;
        ok[s[i] - 'a'] = 1;
        if(ok[0] <ok[1] || ok[1] <ok[2] || ok[0] <ok[2])
        {
            cout <<"No" ;  return 0;
        }
    }
    if( (sl[2] ==sl[1] || sl[2] == sl[0] || sl[2] == sl[0] +sl[1]) && (sl[1] >0 ||sl[2]>0) )cout<<"Yes";
    else cout <<"No" ;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "as."
using namespace std;
const int N=1e5+3;
string s;
bool ok[5];
int sl[5] ;
int main()
{
    cin >> s;
    for(int i = 0 ; i < s.size() ;i++)
    {
        sl[s[i]-'a'] ++;
        ok[s[i] - 'a'] = 1;
        if(ok[0] <ok[1] || ok[1] <ok[2] || ok[0] <ok[2])
        {
            cout <<"No" ;  return 0;
        }
    }
    if(sl[2] ==sl[1] || sl[2] == sl[0] || sl[2] == sl[0] +sl[1]) cout<<"Yes";
    else cout <<"No" ;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "as."
using namespace std;
const int N=1e5+3;
string s;
bool ok[5];
int sl[5] ;
int main()
{

    cin >> s;
    for(int i = 0 ; i < s.size() ;i++)
    {
        sl[s[i]-'a'] ++;
        ok[s[i] - 'a'] = 1;
        if(ok[0] <ok[1] || ok[1] <ok[2] || ok[0] <ok[2])
        {
            cout <<"No" ;  return 0;
        }
    }
    if(sl[2] ==sl[1] || sl[2] == sl[0] || sl[2] == sl[0] +sl[1]) cout<<"Yes";
    else cout <<"No" ;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
using namespace std;
const int N=5000+3;
string s;
bool ok[5];
int sl[5],dp[N][4] ;
char a[]={'a','b','c'} ;
int main()
{

    cin >> s;
    int sz = s.size() ;
    for(int i = 0 ; i < s.size() ;i++) sl[s[i]-'a'] ++;

    FOR(i,1,sz) FOR(j,1,3) dp[i][j] = max(dp[i][j-1] , dp[i-1][j] + (s[i-1]==a[j-1]) ) ;

  //  cerr<< dp[sz][3];
    if(dp[sz][3] !=sz){
        cout << "No" ;return 0;
    }

    if( (sl[2] ==sl[1] || sl[2] == sl[0] || sl[2] == sl[0] +sl[1]) && (sl[1] >0 ||sl[2]>0) )cout<<"Yes";
    else cout <<"No" ;
}


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool ccc(int x,int y)
{
	if(x==y&&x)
	  {
	 return true;}
	return false;
}
bool zzz(int x,int y,int z)
{
	if(x<y||x<z)
	 return false;
	 if(y<z)
	 return false;
	 return true;
}
int main()
{
  char str[5005];
  char str1[5005];
  int a=0,b=0,c=0;
  cin>>str;
  strcpy(str1,str);
  int tt=strlen(str);
   sort(str1,str1+tt);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
if(strcmp(str,str1)==0&&(ccc(a,b)||ccc(a,c)||ccc(b,c)))
 cout<<"YES";
 else
  cout<<"NO";
  return 0;
 }


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool ccc(int x,int y)
{
	if(x==y&&x)
	  {
	 return true;}
	return false;
}
bool zzz(int x,int y,int z)
{
	if(x<y||x<z)
	 return false;
	 if(y<z)
	 return false;
	 return true;
}
int main()
{
  char str[5005];
  char str1[5005];
  int a=0,b=0,c=0;
  cin>>str;
  strcpy(str1,str);
  int tt=strlen(str);
   sort(str1,str1+tt);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
if(a>0&&b>0&&c>0&&strcmp(str,str1)==0&&(ccc(a,b)||ccc(a,c)||ccc(b,c)))
 cout<<"YES";
 else
  cout<<"NO";
  return 0;
 }


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool ccc(int x,int y)
{
	if(x==y)
	  {
	 return true;}
	return false;
}
bool zzz(int x,int y,int z)
{
	if(x<y||x<z)
	 return false;
	 if(y<z)
	 return false;
	 return true;
}
int main()
{
  char str[5005];
  char str1[5005];
  int a=0,b=0,c=0;
  cin>>str;
  strcpy(str1,str);
  int tt=strlen(str);
   sort(str1,str1+tt);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
if(strcmp(str,str1)==0&&(ccc(a,b)||ccc(a,c)||ccc(b,c)))
 cout<<"YES";
 else
  cout<<"NO";
  return 0;
 }


#include<iostream>
#include<cstring>
using namespace std;
bool ccc(int x,int y)
{
	if(x==y)
	  {
	 return true;}
	return false;
}
bool zzz(int x,int y,int z)
{
	if(x<y||x<z)
	 return false;
	 if(y<z)
	 return false;
	 return true;
}
int main()
{
  char str[5005];
  int a=0,b=0,c=0;
  cin>>str;
  int tt=strlen(str);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
if(zzz(cc,bb,aa)&&(ccc(a,b)||ccc(a,c)||ccc(b,c)))
 cout<<"YES";
 else
  cout<<"NO";
  return 0;
 }


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool ccc(int x,int y)
{
	if(x==y&&x)
	  {
	 return true;}
	return false;
}
bool zzz(int x,int y,int z)
{
	if(x<y||x<z)
	 return false;
	 if(y<z)
	 return false;
	 return true;
}
int main()
{
  char str[5005];
  char str1[5005];
  int a=0,b=0,c=0;
  cin>>str;
  strcpy(str1,str);
  int tt=strlen(str);
   sort(str1,str1+tt);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
if(a>0&&b>0&&c>0strcmp(str,str1)==0&&(ccc(a,b)||ccc(a,c)||ccc(b,c)))
 cout<<"YES";
 else
  cout<<"NO";
  return 0;
 }


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool ccc(int x,int y)
{
	if(x==y&&x)
	  {
	 return true;}
	return false;
}
bool zzz(int x,int y,int z)
{
	if(x<y||x<z)
	 return false;
	 if(y<z)
	 return false;
	 return true;
}
int main()
{
  char str[5005];
  char str1[5005];
  int a=0,b=0,c=0;
  cin>>str;
  strcpy(str1,str);
  int tt=strlen(str);
   sort(str1,str1+tt);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
if(a>0&&b>0&&c>0&&strcmp(str,str1)==0&&(ccc(a,c)||ccc(b,c)))
 cout<<"YES";
 else
  cout<<"NO";
  return 0;
 }


#include<iostream>
#include<cstring>
using namespace std;
bool ccc(int x,int y,int xx,int yy)
{
	if(x==y&&yy>xx)
	 return true;
}
int main()
{
  char str[5005];
  int a,b,c;
  cin>>str;
  int tt=strlen(str);
  int aa,bb,cc;
  for(int i=0;i<tt;i++)
  {
  	if(str[i]=='a')
  	a++,aa=i;
  	if(str[i]=='b')
  	b++,bb=i;
  	if(str[i]=='c')
  	c++,cc=i;
  }
  if(ccc(a,b,aa,bb)||ccc(a,c,aa,cc)||(b,c,bb,cc))
     cout<<"YES";
     else
     cout<<"NO";
     return 0;
 }


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
string s;
int main(int argc, char ** argv)
{
    cin>>s;
    if(s.size()<2)
        pure=false;
    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(pure&&mp['a']==mp['b']||pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
string s;
int main(int argc, char ** argv)
{
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(mp['a']!=0||mp['c']!=0||mp['b']!=0)
        pure=false;
    if(pure&&mp['a']==mp['b']||pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
string s;
int main(int argc, char ** argv)
{
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(mp['a']==0||mp['c']==0||mp['b']==0||s[0]!='a'||s[s.size()-1]!='c')
        pure=false;
    if(pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
string s;
int main(int argc, char ** argv)
{
    cin>>s;

    for(int i=0;i<s.size();i++)
    {//abca
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(mp['a']==0||mp['c']==0||mp['b']==0||s[0]!='a'||s[s.size()-1]!='c')
        pure=false;
    if(pure&&mp['a']==mp['b']||pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
string s;
int main(int argc, char ** argv)
{
    cin>>s;
    if(s.size()<2)
        pure=falsel;
    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(pure&&mp['a']==mp['b']||pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
string s;
int main(int argc, char ** argv)
{
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(mp['a']==0||mp['c']==0||mp['b']==0)
        pure=false;
    if(pure&&mp['a']==mp['b']||pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7;
#define clr(x,val) memset(x,val,sizeof(a));//fill array with 0s. clr(array,0);
typedef long long ll;
map<char,int>mp;
bool pure=true;
char c;
string s;
int main(int argc, char ** argv)
{
    cin>>s;
    c=s[0];
    for(int i=0;i<s.size();i++)
    {
        mp[s[i]]++;
        if (s[i]=='a'&&s[i+1]=='c'&&i!=s.size()-1||s[i]=='b'&&s[i+1]=='a'&&i!=s.size()-1||s[i]=='c'&&s[i+1]=='b'&&i!=s.size()-1)
            pure=false;
    }
    if(pure&&mp['a']==mp['b']||pure&&mp['a']==mp['c']||pure&&mp['c']==mp['b'])
        cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <stack>
#include <set>
#include <climits>
using namespace std;

int main(int argc,char **argv)
{
  string s{};
  cin>>s;
  int ac{0};
  int bc{0};
  int cc{0};
  if(s[0]!='a'){
    cout<<"NO"<<endl;
  }else{
    for(int i=0;i<s.length();i++){
      if(s[i]=='a'){
        if(s[i-1]!='a' and i>=1){
           cout<<"NO"<<endl;
           return 0;
        }
        ac+=1;
      }else if(s[i]=='b'){
        if(bc==0){
          if(s[i-1]!='a'){
            cout<<"NO"<<endl;
            return 0;
          }else{

            bc+=1;
          }
        }else{
           if(s[i-1]!='b'){
             cout<<"NO"<<endl;
            return 0;
          }
          bc+=1;
        }
      }else if(s[i]=='c'){
        if(cc==0){
          if(s[i-1]!='b'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            cc+=1;
          }
        }else{
          if(s[i-1]!='c'){
             cout<<"NO"<<endl;
            return 0;
          }
          cc+=1;
        }
      }
    }
      cout<<(((ac==cc || bc==cc) and ac>0 and bc>0)? "YES":"NO")<<endl;
  }

  /*
  int n{0};
  cin>>n;
  int minind{0};
  int maxind{0};
  for(int i=0;i<n;i++){
    int r;
    cin>>r;
    if(r==1){
      minind=i;
    }if(r==n){
      maxind=i;
    }
  }
  */

  return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <stack>
#include <set>
#include <climits>
using namespace std;

int main(int argc,char **argv)
{
  string s{};
  cin>>s;
  int ac{0};
  int bc{0};
  int cc{0};
  if(s[0]!='a'){
    cout<<"NO"<<endl;
  }else{
    for(int i=0;i<s.length();i++){
      if(s[i]=='a'){
        ac+=1;
      }else if(s[i]=='b'){
        if(bc==0){
          if(s[i-1]!='a'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            bc+=1;
          }
        }else{
          bc+=1;
        }
      }else if(s[i]=='c'){
        if(cc==0){
          if(s[i-1]!='b'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            cc+=1;
          }
        }else{
          cc+=1;
        }
      }
    }
      cout<<((ac==cc || bc==cc)? "YES":"NO")<<endl;
  }

  /*
  int n{0};
  cin>>n;
  int minind{0};
  int maxind{0};
  for(int i=0;i<n;i++){
    int r;
    cin>>r;
    if(r==1){
      minind=i;
    }if(r==n){
      maxind=i;
    }
  }
  */

  return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <stack>
#include <set>
#include <climits>
using namespace std;

int main(int argc,char **argv)
{
  string s{};
  cin>>s;
  int ac{0};
  int bc{0};
  int cc{0};
  if(s[0]!='a'){
    cout<<"NO"<<endl;
  }else{
    for(int i=0;i<s.length();i++){
      if(s[i]=='a'){
        ac+=1;
      }else if(s[i]=='b'){
        if(bc==0){
          if(s[i-1]!='a'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            bc+=1;
          }
        }else{
          bc+=1;
        }
      }else if(s[i]=='c'){
        if(cc==0){
          if(s[i-1]!='b'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            cc+=1;
          }
        }else{
          cc+=1;
        }
      }
    }
      cout<<(((ac==cc || bc==cc) and ac>0 and bc>0)? "YES":"NO")<<endl;
  }

  /*
  int n{0};
  cin>>n;
  int minind{0};
  int maxind{0};
  for(int i=0;i<n;i++){
    int r;
    cin>>r;
    if(r==1){
      minind=i;
    }if(r==n){
      maxind=i;
    }
  }
  */

  return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <stack>
#include <set>
#include <climits>
using namespace std;

int main(int argc,char **argv)
{
  string s{};
  cin>>s;
  int ac{0};
  int bc{0};
  int cc{0};
  if(s[0]!='a'){
    cout<<"NO"<<endl;
  }else{
    for(int i=0;i<s.length();i++){
      if(s[i]=='a'){
        ac+=1;
      }else if(s[i]=='b'){
        if(bc==0){
          if(s[i-1]!='a'){
            cout<<"NO"<<endl;
            return 0;
          }else{
             if(s[i-1]!='b'){
             cout<<"NO"<<endl;
            return 0;
          }
            bc+=1;
          }
        }else{
          bc+=1;
        }
      }else if(s[i]=='c'){
        if(cc==0){
          if(s[i-1]!='b'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            cc+=1;
          }
        }else{
          if(s[i-1]!='c'){
             cout<<"NO"<<endl;
            return 0;
          }
          cc+=1;
        }
      }
    }
      cout<<(((ac==cc || bc==cc) and ac>0 and bc>0)? "YES":"NO")<<endl;
  }

  /*
  int n{0};
  cin>>n;
  int minind{0};
  int maxind{0};
  for(int i=0;i<n;i++){
    int r;
    cin>>r;
    if(r==1){
      minind=i;
    }if(r==n){
      maxind=i;
    }
  }
  */

  return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <stack>
#include <set>
#include <climits>
using namespace std;

int main(int argc,char **argv)
{
  string s{};
  cin>>s;
  int ac{0};
  int bc{0};
  int cc{0};
  if(s[0]!='a'){
    cout<<"NO"<<endl;
  }else{
    for(int i=0;i<s.length();i++){
      if(s[i]=='a'){
        if(s[i-1]!='a' and i>=1){
           cout<<"NO"<<endl;
           return 0;
        }
        ac+=1;
      }else if(s[i]=='b'){
        if(bc==0){
          if(s[i-1]!='a'){
            cout<<"NO"<<endl;
            return 0;
          }else{

            bc+=1;
          }
        }else{
          bc+=1;
        }
      }else if(s[i]=='c'){
        if(cc==0){
          if(s[i-1]!='b'){
            cout<<"NO"<<endl;
            return 0;
          }else{
            cc+=1;
          }
        }else{
          if(s[i-1]!='c'){
             cout<<"NO"<<endl;
            return 0;
          }
          cc+=1;
        }
      }
    }
      cout<<(((ac==cc || bc==cc) and ac>0 and bc>0)? "YES":"NO")<<endl;
  }

  /*
  int n{0};
  cin>>n;
  int minind{0};
  int maxind{0};
  for(int i=0;i<n;i++){
    int r;
    cin>>r;
    if(r==1){
      minind=i;
    }if(r==n){
      maxind=i;
    }
  }
  */

  return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    string s;
    vector<char>t;
    int a=0,b=0,c=0,ck=0;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]!=s[i+1])
            t.push_back(s[i]);

    }
     for(int i=0; i<t.size(); i++){
        if(t[i]=='a'&&t[i+1]=='b'&&t[i+2]=='c')
            ck=1;
        }

    if(ck==1){
        for(int i=0; i<s.size(); i++){
            if(s[i]=='a') a++;
            else if(s[i]=='b') b++;
            else if(s[i]=='c') c++;
        }
        if(c==a || c==b) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    string s;
    vector<char>t;
    int a=0,b=0,c=0,ck=0;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]!=s[i+1])
            t.push_back(s[i]);

    }

    if(t[0]=='a'&&t[1]=='b'&&t[2]=='c') ck=1;

    if(ck==1){
        for(int i=0; i<s.size(); i++){
            if(s[i]=='a') a++;
            else if(s[i]=='b') b++;
            else if(s[i]=='c') c++;
        }
        if(c==a || c==b) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    string s;
    vector<char>t;
    int a=0,b=0,c=0,ck=0;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]!=s[i+1])
            t.push_back(s[i]);

    }
    if(t.size()<=3){
        if(t[0]=='a'&&t[1]=='b'&&t[2]=='c')ck=1;
    }
    else{
     for(int i=0; i<t.size(); i++){
      if(t[0]=='a'&&t[1]=='b'&&t[2]=='c')ck=1;
      if(t[i+3]!='c'){
         ck=0;
         break;
      }
    }
    }
    if(ck==1){
        for(int i=0; i<s.size(); i++){
            if(s[i]=='a') a++;
            else if(s[i]=='b') b++;
            else if(s[i]=='c') c++;
        }
        if(c==a || c==b) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    string s;
    vector<char>t;
    int a=0,b=0,c=0,ck=0;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]!=s[i+1])
            t.push_back(s[i]);

    }
     for(int i=0; i<t.size(); i++){
        if(t[i]=='a'&&t[i+1]=='b'&&t[i+2]=='c')
            ck=1;
            else{
                ck=0;
                break;
            }
        }

    if(ck==1){
        for(int i=0; i<s.size(); i++){
            if(s[i]=='a') a++;
            else if(s[i]=='b') b++;
            else if(s[i]=='c') c++;
        }
        if(c==a || c==b) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string s;
    int a=0,b=0,c=0;
    cin>>s;

    if(s[0]!='a') cout<<"NO"<<endl;
    else{
        for(int i=0; i<s.size(); i++){
            if(s[i]=='a') a++;
            else if(s[i]=='b') b++;
            else if(s[i]=='c') c++;
        }
        if(c==a || c==b) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
    string s;
    vector<char>t;
    int a=0,b=0,c=0,ck=0;
    cin>>s;

    for(int i=0; i<s.size(); i++){
        if(s[i]!=s[i+1])
            t.push_back(s[i]);

    }

    if(t[0]=='a'&&t[1]=='b'&&t[2]=='c')ck=1;
    if(t[t.size()-1]!='c'&&t[t.size()-2]=='c') ck=0;

    if(ck==1){
        for(int i=0; i<s.size(); i++){
            if(s[i]=='a') a++;
            else if(s[i]=='b') b++;
            else if(s[i]=='c') c++;
        }
        if(c==a || c==b) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    else cout<<"NO"<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
enum { };

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string s; cin >> s;
	int n = (int) s.length();
	unordered_map<char,int> f;
	bool flag = true;
	++f[s[0]];
	for (int i = 1; i < n; ++i) {
		flag &= (s[i] >= s[i-1]);
		++f[s[i]];
	}
	flag &= ((f['a'] == f['c']) || (f['b'] == f['c']));
	string ans = "NO";
	if (flag) {
		ans = "YES";
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
enum { };

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string s; cin >> s;
	int n = (int) s.length();
	unordered_map<char,int> f;
	bool flag = true;
	++f[s[0]];
	for (int i = 1; i < n; ++i) {
		flag &= (s[i] >= s[i-1]);
		++f[s[i]];
	}
	flag &= ((f['a'] == f['c']) || (f['b'] == f['c']));
	flag &= (f['a'] != 0);
	flag &= (f['b'] != 0);
	flag &= (f['c'] != 0);
	string ans = "NO";
	if (flag) {
		ans = "YES";
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int count=0,count1=0,count2=0;
    string s,s1;
    cin>>s;
    s1 = s;
    sort(s1.begin(),s1.end());
    if(s == s1)
    {
        for(int i=0;i<s.length();++i)
        {
            if(s[i] == 'a')
                count++;
            else if(s[i] == 'b')
                count1++;
            else
                count2++;
        }
        if((count == count2 || count1 == count2) && (count1>=1 && count>=1))
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
        cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int count=1,count1=0,count2=1,count3=1;
    string s;
    cin>>s;
    int n = s.length();
    if(s[0]=='a' && s[n-1]=='c')
    {
        for(int i=1;i<n-1;++i)
        {
           if(s[i]=='a')
           {
            count++;
            count3++;
           }
            else if(s[i]=='b')
            {
                count1++;
                count3=0;
            }
            else if(count3==0 && count1>=1)
                count2++;
        }
        if(count3!=0)
            cout<<"NO";
        else if(count2 == count || count2 == count1)
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
    {
        cout<<"NO";
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int count=0,count1=0,count2=0;
    string s,s1;
    cin>>s;
    s1 = s;
    sort(s1.begin(),s1.end());
    if(s == s1)
    {
        for(int i=0;i<s.length();++i)
        {
            if(s[i] == 'a')
                count++;
            else if(s[i] == 'b')
                count1++;
            else
                count2++;
        }
        if(count == count2 || count1 == count2 && count1>=1 && count>=1)
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
        cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int count=1,count1=0,count2=1;
    string s;
    cin>>s;
    int n = s.length();
    if(s[0]=='a' && s[n-1]=='c')
    {
        for(int i=1;i<n-1;++i)
        {
           if(s[i]=='a')
            count++;
            else if(s[i]=='b')
                count1++;
            else if(count>=1 && count1>=1)
                count2++;

        }
        if(count2 == count || count2 == count1)
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
    {
        cout<<"NO";
        return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int count=0,count1=0,count2=0;
    string s,s1;
    cin>>s;
    s1=s;
    sort(s1.begin(),s1.end());
    if(s == s1)
    {
        for(int i=0;i<s.length();++i)
        {
            if(s[i]=='a')
                count++;
            else if(s[i]=='b')
                count1++;
            else if(s[i]=='c')
                count2++;
        }
        if(count == count2 || count1 == count2)
            cout<<"YES";
        else
            cout<<"NO";
    }
    else
        cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a[200];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; int n;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'b' && !a[97])
        {
            cout << "NO";
            return 0;
        }
        if (s[i] == 'c' && !a[97] || !a[98])
        {
            cout << "NO";
            return 0;
        }
        a[int(s[i])]++;
    }

    if (a[99] == a[97] || a[99] == a[98])
    {
        cout << "YES";
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>

using namespace std;
int a[200];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; int n;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++)
    {
        if ((s[i] == 'b' && !a[97])||(s[i] == 'c' && (!a[97]||!a[98])))
        {
            cout << "NO";
            return 0;
        }
        a[int(s[i])]++;
    }
    if ((a[99] == a[98] || a[99] == a[97]) && a[99])
        cout << "YES";
    else
        cout << "NO";

}


#include <bits/stdc++.h>

using namespace std;
int a[200];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; int n;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'b' && !a[97])
        {
            cout << "NO";
            return 0;
        }
        if (s[i] == 'c' && !a[97] && !a[98])
        {
            cout << "NO";
            return 0;
        }
        a[int(s[i])]++;
    }
    if (a[99] == a[97] || a[99] == a[98])
    {
        cout << "YES";
        return 0;
    }
    cout << "NO";
}


#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[5001];
	int a=0,b=0,c=0,len,x=0,y=0,i;
	cin>>s;
	len=strlen(s);
	if(s[0]!='a')
	{
		cout<<"NO"<<endl;
		return 0;
	}
	else if(s[0]=='a')
	{
		a=1;
		for(i=1;i<len;i++)
		{
			if(s[i]=='a'&&b==0)
				a++;
			else if(s[i]=='b'&&a>0&&c==0)
				b++;
			else if(s[i]=='c')
				c++;
		}
		if(a+b+c==len&&(a==c||b==c)&&a!=0&&b!=0)
		{
			cout<<"YES"<<endl;
		}
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[5001];
	int a=0,b=0,c=0,len,x=0,y=0,i;
	cin>>s;
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		if(s[i]=='a')
		{
			if(x<1)
				x++;
			a++;
		}
		else if(x==1||x==2&&s[i]=='b')
		{
			if(x<2)
				x++;
			b++;
		}
		else if(x==2||x==3&&s[i]=='c')
		{
			if(x<3)
				x++;
			c++;
		}
		else
			y=1;
	}
	if(c!=a&&c!=b)
		y=1;
	if(y==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[5001];
	int a=0,b=0,c=0,len,x=0,y=0,i;
	cin>>s;
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		if(s[i]=='a')
		{
			if(x<1)
				x++;
			a++;
		}
		else if(x==1||x==2&&s[i]=='b')
		{
			if(x<2)
				x++;
			b++;
		}
		else if(x==2||x==3&&s[i]=='c')
		{
			if(x<3)
				x++;
			c++;
		}
		else
			y=1;
	}
	if(c!=a&&c!=b||b==0||c==0||a==0)
		y=1;
	if(y==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[5001];
	int a=0,b=0,c=0,len,x=0,y=0,i;
	cin>>s;
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		if((x==0||x==1)&&s[i]=='a')
		{
			if(x<1)
				x++;
			a++;
		}
		else if((x==1||x==2)&&s[i]=='b')
		{
			if(x<2)
				x++;
			b++;
		}
		else if((x==2||x==3)&&s[i]=='c')
		{
			if(x<3)
				x++;
			c++;
		}
		else
		{
			y=1;
			break;
		}
	}
	if(c!=a&&c!=b||b==0||c==0||a==0)
		y=1;
	cout<<a<<b<<c;
	if(y==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include <iostream>
using namespace std;
#include <string>

int main() {
	string x;
	string a, b, c;
	cin >> x;

	bool k = true;
	int i = 0;
	while (i < x.length() && k) {
		while (k && i < x.length()) {
			if (x[i] == 'a') {
				a += 'a';
			}
			else if (x[i] == 'b') {
				if (a.length() == 0) {
					k = false;
					break;
				}
				else break;
			}
			else {
				k = false;
				break;
			}
			i++;
		}
		while (k && i < x.length()) {
			if (x[i] == 'b') {
				b += 'b';
			}
			else if (x[i] == 'a') {
				k = false;
				break;
			}
			else {
				if (b.length() == 0) {
					k = false;
					break;
				}
				else break;
			}
			i++;
		}
		while (k && i < x.length()) {
			if (x[i] == 'c') {
				c += 'c';
			}
			else {
				k = false;
				break;
			}
			i++;
		}

	}

	/*for (int i = 0; i < x.length(); i++) {
		if (x[i] == 'a')
			a += 'a';
		else if (x[i] == 'b')
			b += 'b';
		else
			c += 'c';
	}*/

	if (k && (c.length() == a.length() || c.length() == b.length()))
		cout << "YES";
	else
		cout << "NO";

	cin >> x;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define int long long
#define F first
#define S second
#define pi pair <int, int>
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define watch(x) cout << (#x) << " = " << (x) << "\n"
#define PI 3.14159265359
#define MOD 1000000007
#define INF 1000000000000000005

using namespace std;

void swap(int &a, int &b){
	int temp = a;
	a = b;
	b = temp;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T = 1;
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		int a[n + 1], i;
		map <int, int> mp;
		for(i = 1; i <= n; i++){
			cin >> a[i];
			mp[a[i]] = i;
		}
		int moves = n-1;
		for(i = 1; i <= n; i++){
			int p = mp[i];
			while(moves && p != i){
				mp[a[p - 1]] = p;
				swap(a[p], a[p - 1]);
				p--;
				moves--;
			}
			if(moves == 0){
				break;
			}
		}
		for(i = 1; i <= n; i++){
			cout << a[i] << ' ';
		}
		cout << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define int long long
#define F first
#define S second
#define pi pair <int, int>
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define watch(x) cout << (#x) << " = " << (x) << "\n"
#define PI 3.14159265359
#define MOD 1000000007
#define INF 1000000000000000005

using namespace std;

void swap(int &a, int &b){
	int temp = a;
	a = b;
	b = temp;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T = 1;
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		int a[n + 1], i;
		map <int, int> mp;
		for(i = 1; i <= n; i++){
			cin >> a[i];
			mp[a[i]] = i;
		}
		int moves = n-1;
		for(i = 1; i <= n; i++){
			int p = mp[i];
			while(moves && p != i){
				mp[a[p-1]] = p;
				mp[i] = p-1;
				swap(a[p], a[p - 1]);
				p--;
				moves--;
			}
			if(moves == 0){
				break;
			}
		}
		for(i = 1; i <= n; i++){
			cout << a[i] << ' ';
		}
		cout << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {

    ll n,cnt=0,val=0;
    cin>>n;
    vector<ll> v(n),s(n);
    for(auto &in:v) cin>>in;
    iota(s.begin(),s.end(),1);
    for(int i=0;i<n && cnt!=n-1;i++)
        {
           if(s==v) {for(auto i: v) cout<<i<<" ";cout<<endl;break;}
           if(v[i]==s[i]) {continue;}
           for(int j=find(v.begin(),v.end(),s[i])-v.begin();j>i;j--)
            {
                if(cnt==n-1) break;
                swap(v[j],v[j-1]);
                cnt++;
            }
        }
        if(cnt==n-1) {for(auto i: v) cout<<i<<" ";cout<<endl;}
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {

    ll n,cnt=0,val=0;
    cin>>n;
    vector<ll> v(n),s(n);
    for(auto &in:v) cin>>in;
    iota(s.begin(),s.end(),1);
    for(int i=0;i<n && cnt!=n-1;i++)
        {
           if(s==v) {for(auto i: v) cout<<i<<" ";cout<<endl; cnt=0;break;}
           if(v[i]==s[i]) {continue;}
           for(int j=find(v.begin(),v.end(),s[i])-v.begin();j>i;j--)
            {
                if(cnt==n-1) break;
                swap(v[j],v[j-1]);
                cnt++;
            }
        }
        if(cnt==n-1) {for(auto i: v) cout<<i<<" ";cout<<endl;}
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll> v(n);
        for(int i=0;i<n;i++) cin>>v[i];

        ll ind;
        for(int k=0;k<n-1;k++)
        {
          ll  mn=9;

        for(int i=k;i<n;i++) if(mn>=v[i]) {mn=v[i];ind=i;}

        for(int i=ind;i>k;i--) swap(v[i],v[i-1]);
        if(k<ind) k=ind-1;
        }
        for(auto out: v) cout<<out<<" ";cout<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll> v(n),st(n);
        for(int i=0;i<n;i++) cin>>v[i];
        st=v;
        sort(st.begin(),st.end());
        ll mn,ind;
        for(int k=0;k<n;k++)
        {
            mn=9;
        if(st[k]==v[k]) continue;
        for(int i=k;i<n;i++) if(mn>=v[i]) {mn=v[i];ind=i;}

        for(int i=ind;i>k;i--) swap(v[i],v[i-1]);
        if(k<ind) k=ind-1;
        }
        for(auto out: v) cout<<out<<" ";cout<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll> v(n);
        for(int i=0;i<n;i++) cin>>v[i];

        ll ind;
        for(int k=0;k<n-1;k++)
        {
          ll  mn=n;

        for(int i=k;i<n;i++) if(mn>=v[i]) {mn=v[i];ind=i;}

        for(int i=ind;i>k;i--) swap(v[i],v[i-1]);
        if(k<ind) k=ind-1;

        }
        for(auto out: v) cout<<out<<" ";cout<<endl;

    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {

    ll n,cnt=0,val=0,mx;
    cin>>n;
    vector<ll> v(n),s(n);
    for(auto &in:v) cin>>in;
    iota(s.begin(),s.end(),1);
    for(int i=0;i<n && cnt!=n-1;i++)
        {
           if(s==v) {for(auto i: v) cout<<i<<" ";cout<<endl; cnt=0;break;}
           if(v[i]==s[i]) {continue;}
           if(cnt==0)
           {
               mx=find(v.begin(),v.end(),s[i])-v.begin();

           for(int j=find(v.begin(),v.end(),s[i])-v.begin();j>i;j--)
            {
                if(cnt==n-1) break;
                swap(v[j],v[j-1]);
                cnt++;
            }
           }
           else{
                vector<ll> vt;
            for(int k=mx;k<=mx+n-1-cnt;k++) vt.push_back(v[k]);

            mx=find(v.begin(),v.end(),*min_element(vt.begin(),vt.end()))-vt.begin();

           for(int j=find(v.begin(),v.end(),*min_element(vt.begin(),vt.end()))-v.begin();j>i;j--)
            {
                if(cnt==n-1) break;
                if(j<=v.size()-1) {swap(v[j],v[j-1]);cnt++;}
                else break;

            }
           }
        }
        if(cnt==n-1) {for(auto i: v) cout<<i<<" ";cout<<endl;}
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {

    ll n;
    cin>>n;
    ll cnt=n-1;
    vector<ll> v(n);
    string str,st;
    ll ct=0;
    for(int i=0;i<n;i++) {cin>>v[i]; str.push_back(v[i]+48); }

    for(int i=1;i<=n;i++) st.push_back(i+48);

    for(int i=0;i<n;i++)
    {

      if(st==str && ct==0) {for(int i=0;i<n;i++) cout<<str[i]<<" ";ct=1;break;}
      if(str[i]==st[i]) continue;
          char mn='9';
          ll ind=i;

          for(int j=i;j<(str.size()<=i+cnt+1?str.size():i+cnt+1);j++)if(mn>=str[j]) {mn=str[j];ind=j;}
          if(ind>i)
          {

            if(cnt<=0) break;
            str.erase(ind,1);
            str.insert(str.begin()+i,mn);
            cnt-=(ind-i);
             i=ind-1;

          }
    }
    if(ct==0) { for(int i=0;i<n;i++) cout<<str[i]<<" ";cout<<endl;}
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {

    ll n;
    cin>>n;
    ll cnt=n-1;
    vector<ll> v(n);
    string str,st;
    ll ct=0;
    for(int i=0;i<n;i++) {cin>>v[i]; str.push_back(v[i]+48); }

    for(int i=1;i<=n;i++) st.push_back(i+48);
    ll i2=0;
    for(int i=0;i<n;i++)
    {

      if(st==str && ct==0) {for(int i=0;i<n;i++) cout<<str[i]<<" ";ct=1;break;}
      if(str[i]==st[i]) continue;
          char mn='9';
          ll ind=i;
          if(cnt==n-1)  i2=i;
          for(int j=i2;j<(str.size()<=i2+cnt+1?str.size():i2+cnt+1);j++)if(mn>=str[j]) {mn=str[j];ind=j;}
          if(ind!=i2)
          {

            if(cnt<=0) break;
            str.erase(ind,1);
            str.insert(str.begin()+i2,mn);
            cnt-=(ind-i2);
             i2=ind;

          }
    }
    if(ct==0) { for(int i=0;i<n;i++) cout<<str[i]<<" ";cout<<endl;}
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {

    ll n;
    cin>>n;
    ll cnt=n-1;
    vector<ll> v(n);
    string str,st;
    for(int i=0;i<n;i++) {cin>>v[i]; str.push_back(v[i]+48); }

    for(int i=1;i<=n;i++) st.push_back(i+48);

    for(int i=0;i<n;i++)
    {

      if(st==str) {break;}
      if(str[i]==st[i]) continue;
          char mn;
          mn='9';
          ll ind=i;
          if(cnt<=0) break;
          for(int j=i;j<(str.size()<=i+cnt+1?str.size():i+cnt+1);j++)if(mn>=str[j]) {mn=str[j];ind=j;}
          if(ind>i)
          {
            str.erase(ind,1);
            str.insert(str.begin()+i,mn);
            cnt-=(ind-i);
             i=ind-1;
          }
    }
     for(int i=0;i<n;i++) cout<<str[i]<<" ";cout<<endl;
    }

}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],mp[MAX],used[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v;
        for(int i=1; i<=n; i++)
            cin>>arr[i],mp[arr[i]]=i,used[i]=0;
        for(int i=1; i<=n; i++)
        {
            int j=mp[i];
            while(j>i && used[j-1]==0)
            {

                swap(arr[j],arr[j-1]);
                mp[arr[j-1]]=j;
                j--;
                used[j]=1;

            }
        }
        for(int i=1;i<=n;i++)
            cout<<arr[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v,ans;
        for(int i=0; i<n; i++)
        {
            cin>>a;
            v.push_back(a);
        }
        int turn=n-1,mn=1;
        map<int,int>mp;
        for(int i=0; i<n; i++)
        {
            if(v[i]==mn)
            {
                mp[mn]=1;
            }
            else
            {
                int pos;
                for(int j=i; j<n; j++)
                {
                    if(v[j]==mn)
                    {
                        pos=j;
                        break;
                    }
                }
                ans.push_back(mn);
                mp[mn]=1;
                for(int j=pos-1; j>=i; j--)
                {
                    mp[v[j]]=1;
                    swap(v[j],v[j+1]);
                }
                i=pos-1;
            }
            while(mp[mn])
                mn++;
            if(mn>n)
                break;
        }
        for(auto i:v)
            cout<<i<<" ";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v;
        for(int i=0; i<n; i++)
        {
            cin>>a;
            v.push_back(a);
        }
        int turn=n-1;
        for(int i=1; i<=n; i++)
        {
            if(v[i-1]==i)
                continue;
            int pos;
            for(int j=i-1; j<n; j++)
            {
                if(v[j]==i)
                {
                    pos=j;
                    break;
                }
            }
            while(turn && v[i-1]!=i)
            {
                turn--;
                swap(v[pos],v[pos-1]);
                pos--;
            }
        }
        for(auto i:v)
            cout<<i<<" ";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v,ans;
        for(int i=0; i<n; i++)
        {
            cin>>a;
            v.push_back(a);
        }
        int turn=n-1,mn=1;
        map<int,int>mp;
        for(int i=0; i<n; i++)
        {
            if(v[i]==mn)
            {
                mp[mn]=1;
                ans.push_back(v[i]);
            }
            else
            {
                int pos;
                for(int j=i; j<n; j++)
                {
                    if(v[j]==mn)
                    {
                        pos=j;
                        break;
                    }
                }
                ans.push_back(mn);
                mp[mn]=1;
                for(int j=i; j<pos; j++)
                {
                    mp[v[j]]=1;
                    ans.push_back(v[j]);
                }
                i=pos;
            }
            while(mp[mn])
                mn++;
        }
        for(auto i:ans)
            cout<<i<<" ";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],mp[MAX],used[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v;
        for(int i=1; i<=n; i++)
            cin>>arr[i],mp[arr[i]]=i,used[i]=0;
        for(int i=1; i<=n; i++)
        {
            int j=mp[i];
            while(j>i && used[j-1]==0 && arr[j-1]>arr[j])
            {
                mp[arr[j-1]]=j;
                swap(arr[j],arr[j-1]);
                j--;
                used[j]=1;
            }
        }
        for(int i=1;i<=n;i++)
            cout<<arr[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],mp[MAX],used[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v;
        for(int i=1; i<=n; i++)
            cin>>arr[i],mp[arr[i]]=i,used[i]=0;
        for(int i=1; i<=n; i++)
        {
            int j=mp[i];
            while(j>i && used[j-1]==0)
            {
                mp[arr[j-1]]=j;
                swap(arr[j],arr[j-1]);
                j--;
                used[j]=1;
            }
        }
        for(int i=1;i<=n;i++)
            cout<<arr[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],mp[MAX],used[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--)
    {
        int n,a;
        cin>>n;
        vector<int>v;
        for(int i=1; i<=n; i++)
            cin>>arr[i],mp[arr[i]]=i,used[i]=0;
        for(int i=1; i<=n; i++)
        {
            int j=mp[i];
            while(j>i && used[j-1]==0)
            {

                swap(arr[j],arr[j-1]);
                j--;
                used[j]=1;
            }
        }
        for(int i=1;i<=n;i++)
            cout<<arr[i]<<" ";
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1024;

int main() {
	int tc;
	ri(tc);
	while (tc--){
		int n;
		ri(n);
		int a[n];
		forn(i, n) ri(a[i]);
		int swaps = n-1;
		for(int i = 0; i<n; i++){
			int p = find(a, a+n, i+1) -a;
			while (swaps>0 and p>i){
				if (a[p-1]>a[p]) {
					swap(a[p], a[p-1]); swaps--;
					p--;
				}
				else break;
			}
		}
		forn(i, n) printf("%d ", a[i]);
		puts("");
	}

	return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1024;

int main() {
	int tc;
	ri(tc);
	while (tc--){
		int n;
		ri(n);
		int a[n];
		forn(i, n) ri(a[i]);
		int swaps = n-1;
		int lim = 0;
		for(int i = 1; i<=n; i++){
			int p = find(a, a+n, i) -a;
			//printf("%d,", p);
			int aux = p-1;
			while (swaps>0 and p>lim){
				swap(a[p], a[p-1]); swaps--;
				p--;
			}
			lim = max(i,aux);
		}
		forn(i, n) printf("%d ", a[i]);
		puts("");
	}

	return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1024;

int main() {
	int tc;
	ri(tc);
	while (tc--){
		int n;
		ri(n);
		int a[n];
		forn(i, n) {
			ri(a[i]);
			a[i]--;
		}
		int lim = 0;
		for(int i = 0; i<n; i++){
			int p = find(a, a+n, i) - a;
		//	printf("%d %d, ", p, lim);
			if (p< lim) continue;
			for(int j = p; j>lim; j--){
				a[j] = a[j-1];
			}
			a[lim] = i;
			lim = max(p, lim+1);
		}
	//	puts("");
		forn(i, n) printf("%d ", a[i]+1);
		puts("");

	}

	return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1024;

int main() {
	int tc;
	ri(tc);
	while (tc--){
		int n;
		ri(n);
		int a[n];
		forn(i, n) ri(a[i]);
		int swaps = n-1;
		int lim = 0;
		for(int i = 1; i<=n; i++){
			int p = find(a, a+n, i) -a;
			//printf("%d,", p);
			int aux = p-2;
			while (swaps>0 and p>lim){
				swap(a[p], a[p-1]); swaps--;
				p--;
			}
			lim = max(i,aux);
		}
		forn(i, n) printf("%d ", a[i]);
		puts("");
	}

	return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1024;

int main() {
	int tc;
	ri(tc);
	while (tc--){
		int n;
		ri(n);
		int a[n];
		forn(i, n) ri(a[i]);
		int swaps = n-1;
		for(int i = 0; i<n; i++){
			int p = find(a, a+n, i+1) -a;
			while (swaps>0 and p>i){
				swap(a[p], a[p-1]); swaps--;
				p--;
			}
		}
		forn(i, n) printf("%d ", a[i]);
		puts("");
	}

	return 0;
}