import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main() {
    int cases = to!int(strip(readln()));

    // per testcase
    for (int t = 0; t < cases; t++) {
        int n;
        readf!"%d\n"(n);

        string s;
        readf!"%s\n"(s);

        /*int best_left = 0;
        int best_right = 0;
        int best_value = int.max;
        int left = 0;
        int right = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'a') {
                left = right;
                right = i;

                int value = right - left - 1;
                if ((value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) || (value == best_value && value == 2 && s[left+1] != s[left+2])) {
                    best_left = left;
                    best_right = right;
                    best_value = value;
                }
            }
        }

        // output cases
        if (best_value > 2) {
            writeln(-1);
        }
        else if (best_value == 2) {
            if (s[best_left+1] != s[best_left+2]) {
                writeln(4);
            } else writeln(-1);
        }
        else if (best_value == 1 || best_value == 0) {
            writeln(best_value+2);
        }
        else {
            writeln(-1);
        }*/
        int best = -1;

        for (int i = 0; i < n-1; i++) {
            if (s[i] == 'a' && s[i+1] == 'a') {
                best = 2;
            }
        }

        if (best == 2) {
            writeln(best);
            continue;
        }

        for (int i = 0; i < n-2; i++) {
            if (s[i] == 'a' && s[i+1] != 'a' && s[i+2] == 'a') {
                best = 3;
            }
        }

        if (best == 3) {
            writeln(best);
            continue;
        }

        for (int i = 0; i < n-3; i++) {
            if (s[i] == 'a' && s[i+1] != s[i+2] && s[i+3] == 'a') {
                best = 4;
            }
        }

        if (best == 4) {
            writeln(best);
            continue;
        }

        for (int i = 0; i < n-6; i++) {
            if (s[i] == 'a' && s[i+1] == s[i+2] && s[i+3] == 'a' && s[i+4] == s[i+5] && s[i+6] == 'a' && s[i+1] != s[i+4]) {
                best = 7;
            }
        }

        writeln(best);
    }
}

/*
cabbabbcbbcbcbababcbcbababbabcbcaaa

abcbbcbcbababbcbcbcbbbabbcbcbbabbcbcbcbabaabcbcbababca

abba 2
abbcbbcbcba vs abba -> abba 2
aba vs abba -> aba 1
abba vs aba -> aba 1
abcbca vs aba -> aba 1
aa vs aba -> aa 0 -> return

"aa" -> that
"aba"/"aca" -> ye
"abca"/"acba" -> ye*/

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto w = scan!(dchar[]);
    auto check = new long[n];
    int st = -1;
    for(int i = 0; i < n; ++i){
        if(w[i] == 'a'){
            st = i;
            break;
        }
    }
    if(st == -1){
        writeln(-1);
        return;
    }
    long cntb = 0, cntc = 0;
    ll res = 10;
    for(int i = st+1; i < n; ++i){
        if(w[i] == 'b'){
            ++cntb;
        }else if(w[i] == 'c'){
            ++cntc;
        }else{
            if(cntb <= 1 && cntc <= 1){
                res = min(2 + cntc + cntb, res);
            }
            if(cntb == 2 && !cntc){
                if(check[i-3] == 2){
                    res = min(7, res);
                }
                check[i] = 1;
            }else if(cntc == 2 && !cntb){
                if(check[i-3] == 1){
                    res = min(7, res);
                }
                check[i] = 2;
            }
            cntb = 0;
            cntc = 0;
        }
    }

    if(res > 9){
        writeln(-1);
    }else{
        writeln(res);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto w = scan!(dchar[]);
    auto check = new long[n];
    int st = -1;
    for(int i = 0; i < n; ++i){
        if(w[i] == 'a'){
            st = i;
            break;
        }
    }
    if(st == -1){
        writeln(-1);
        return;
    }
    long cntb = 0, cntc = 0;
    ll res = 10;
    for(int i = st+1; i < n; ++i){
        if(w[i] == 'b'){
            ++cntb;
        }else if(w[i] == 'c'){
            ++cntc;
        }else{
            if(cntb <= 1 && cntc <= 1){
                res = min(2 + cntc + cntb, res);
            }
            if(cntb == 2){
                if(check[i-3] == 2){
                    res = min(7, res);
                }
                check[i] = 1;
            }else if(cntc == 2){
                if(check[i-3] == 1){
                    res = min(7, res);
                }
                check[i] = 2;
            }
            cntb = 0;
            cntc = 0;
        }
    }

    if(res > 9){
        writeln(-1);
    }else{
        writeln(res);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto w = scan!(dchar[]);
    auto check = new long[n];
    int st = -1;
    for(int i = 0; i < n; ++i){
        if(w[i] == 'a'){
            st = i;
            break;
        }
    }
    if(st == -1){
        writeln(-1);
        return;
    }
    long cntb = 0, cntc = 0;
    ll res = 10;
    for(int i = st+1; i < n; ++i){
        if(w[i] == 'b'){
            ++cntb;
        }else if(w[i] == 'c'){
            ++cntc;
        }else{
            if(cntb <= 1 && cntc <= 1){
                res = min(2 + cntc + cntb, res);
            }
            if(cntb == 2){
                if(check[i-3] == 2){
                    res = min(7, res);
                }
                check[i] = 1;
            }else if(cntc == 2){
                if(check[i-3] == 1){
                    res = min(7, res);
                }
                check[i] = 2;
            }
            cntb = 0;
            cntc = 0;
        }
    }

    if(res > 4){
        writeln(-1);
    }else{
        writeln(res);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto w = scan!(dchar[]);
    int st = -1;
    for(int i = 0; i < n; ++i){
        if(w[i] == 'a'){
            st = i;
            break;
        }
    }
    if(st == -1){
        writeln(-1);
        return;
    }
    long cntb = 0, cntc = 0;
    ll res = 10;
    for(int i = st+1; i < n; ++i){
        if(w[i] == 'b'){
            ++cntb;
        }else if(w[i] == 'c'){
            ++cntc;
        }else{
            if(cntb <= 1 && cntc <= 1){
                res = min(2 + cntc + cntb, res);
            }
            cntb = 0;
            cntc = 0;
        }
    }
    if(res > 4){
        writeln(-1);
    }else{
        writeln(res);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main() {
    int cases = to!int(strip(readln()));

    // per testcase
    for (int t = 0; t < cases; t++) {
        int n;
        readf!"%d\n"(n);

        string s;
        readf!"%s\n"(s);

        /*int best_left = 0;
        int best_right = 0;
        int best_value = int.max;
        int left = 0;
        int right = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'a') {
                left = right;
                right = i;

                int value = right - left - 1;
                if ((value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) || (value == best_value && value == 2 && s[left+1] != s[left+2])) {
                    best_left = left;
                    best_right = right;
                    best_value = value;
                }
            }
        }

        // output cases
        if (best_value > 2) {
            writeln(-1);
        }
        else if (best_value == 2) {
            if (s[best_left+1] != s[best_left+2]) {
                writeln(4);
            } else writeln(-1);
        }
        else if (best_value == 1 || best_value == 0) {
            writeln(best_value+2);
        }
        else {
            writeln(-1);
        }*/
        int best = -1;

        for (int i = 0; i < n-1; i++) {
            if (s[i] == 'a' && s[i+1] == 'a') {
                best = 2;
            }
        }

        if (best == 2) {
            writeln(best);
            continue;
        }

        for (int i = 0; i < n-2; i++) {
            if (s[i] == 'a' && s[i+1] != 'a' && s[i+2] == 'a') {
                best = 3;
            }
        }

        if (best == 3) {
            writeln(best);
            continue;
        }

        for (int i = 0; i < n-3; i++) {
            if (s[i] == 'a' && s[i+1] != s[i+2] && s[i+3] == 'a') {
                best = 4;
            }
        }

        writeln(best);
    }
}

/*
cabbabbcbbcbcbababcbcbababbabcbcaaa

abcbbcbcbababbcbcbcbbbabbcbcbbabbcbcbcbabaabcbcbababca

abba 2
abbcbbcbcba vs abba -> abba 2
aba vs abba -> aba 1
abba vs aba -> aba 1
abcbca vs aba -> aba 1
aa vs aba -> aa 0 -> return

"aa" -> that
"aba"/"aca" -> ye
"abca"/"acba" -> ye*/

import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main() {
    int cases = to!int(strip(readln()));

    // per testcase
    for (int t = 0; t < cases; t++) {
        int n;
        readf!"%d\n"(n);

        string s;
        readf!"%s\n"(s);

        int best_left = 0;
        int best_right = 0;
        int best_value = int.max;
        int left = 0;
        int right = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'a') {
                left = right;
                right = i;

                int value = right - left - 1;
                if ((value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) || (value == best_value && value == 2 && s[left+1] != s[left+2])) {
                    best_left = left;
                    best_right = right;
                    best_value = value;
                }
            }
        }

        // output cases
        if (best_value > 2) {
            writeln(-1);
        }
        else if (best_value == 2) {
            if (s[best_left+1] != s[best_left+2]) {
                writeln(4);
            } else writeln(-1);
        }
        else if (best_value == 1 || best_value == 0) {
            writeln(best_value+2);
        }
        else {
            writeln("something went terribly wrong...");
        }
    }
}

/*
cabbabbcbbcbcbababcbcbababbabcbcaaa

abba 2
abbcbbcbcba vs abba -> abba 2
aba vs abba -> aba 1
abba vs aba -> aba 1
abcbca vs aba -> aba 1
aa vs aba -> aa 0 -> return

"aa" -> that
"aba"/"aca" -> ye
"abca"/"acba" -> ye*/

import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main() {
    int cases = to!int(strip(readln()));

    // per testcase
    for (int t = 0; t < cases; t++) {
        int n;
        readf!"%d\n"(n);

        string s;
        readf!"%s\n"(s);

        int best_left = 0;
        int best_right = 0;
        int best_value = int.max;
        int left = 0;
        int right = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'a') {
                left = right;
                right = i;

                int value = right - left - 1;
                if (value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) {
                    best_left = left;
                    best_right = right;
                    best_value = value;
                }
            }
        }

        // output cases
        if (best_value > 2) {
            writeln(-1);
        }
        else if (best_value == 2) {
            if (s[best_left+1] != s[best_left+2]) {
                writeln(4);
            } else writeln(-1);
        }
        else if (best_value == 1 || best_value == 0) {
            writeln(best_value+2);
        }
        else {
            writeln("something went terribly wrong...");
        }
    }
}

/*
cabbabbcbbcbcbababcbcbababbabcbcaaa

abba 2
abbcbbcbcba vs abba -> abba 2
aba vs abba -> aba 1
abba vs aba -> aba 1
abcbca vs aba -> aba 1
aa vs aba -> aa 0 -> return

"aa" -> that
"aba"/"aca" -> ye
"abca"/"acba" -> ye*/


import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int limit = 1 << 10;

void main ()
{
	int n, k, x;
	while (readf (" %s %s %s", &n, &k, &x) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		int [limit] [2] c;
		int b = 0;
		foreach (v; a)
		{
			c[b][v] += 1;
		}

		foreach (step; 0..k)
		{
			b ^= 1;
			c[b][] = 0;
			int p = 0;
			foreach (v; 0..limit)
			{
				int d = c[!b][v] >> 1;
				c[b][v] += d;
				c[b][v ^ x] += d;
				if (c[!b][v] & 1)
				{
					c[b][v ^ (p ? 0 : x)] += 1;
					p ^= 1;
				}
			}
		}

		int lo = int.max;
		int hi = int.min;
		foreach (v; 0..limit)
		{
			if (c[b][v])
			{
				lo = min (lo, v);
				hi = max (hi, v);
			}
		}
		writeln (hi, " ", lo);
	}
}

import core.bitop, std.bitmanip;
import std.algorithm, std.functional;
import std.array, std.container;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int INF = 10L ^^ 9 + 23;

void main()
{
    int n, k, x;
    readf("%s %s %s", &n, &k, &x);
    readln;

    int [1 << 11][2] vals;

    readln.chomp.split.map!(to!int).each!(v => vals[0][v] += 1);

    debug { vals[0][0 .. 20].writeln; }

    foreach (i; 0 .. k) {
        int step = i & 1;
        vals[step ^ 1][] = 0;
        bool oddstart = true;
        foreach (v; 0 .. 1 << 11) {
            int cnt = vals[step][v];
            int modif = 0;
            if (cnt % 2 == 0) { modif = cnt / 2; }
            else {
                modif = cnt / 2 + (oddstart ? 1 : 0);
                oddstart ^= 1;
            }

            vals[step ^ 1][v ^ x] += modif;
            vals[step ^ 1][v] += cnt - modif;
        }
    }

    debug { vals[k & 1][1 .. 20].writeln; }

    int a, b;
    foreach (v; 0 .. 1 << 11) {
        if (vals[k & 1][v] > 0) { a = v; }
    }

    foreach_reverse (v; 0 .. 1 << 11) {
        if (vals[k & 1][v] > 0) { b = v; }
    }

    writeln(a, ' ', b);
}

import core.bitop, std.bitmanip;
import std.algorithm, std.functional;
import std.array, std.container;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int INF = 10L ^^ 9 + 23;

void main()
{
    int n, k, x;
    readf("%s %s %s", &n, &k, &x);
    readln;

    int [1 << 11][2] vals;

    readln.chomp.split.map!(to!int).each!(v => vals[0][v] += 1);

    debug { vals[0][1 .. 20].writeln; }

    foreach (i; 0 .. k) {
        int step = i & 1;
        vals[step ^ 1][] = 0;
        bool oddstart = true;
        foreach (v; 1 .. 1 << 11) {
            int cnt = vals[step][v];
            int modif = 0;
            if (cnt % 2 == 0) { modif = cnt / 2; }
            else {
                modif = cnt / 2 + (oddstart ? 1 : 0);
                oddstart ^= 1;
            }

            vals[step ^ 1][v ^ x] += modif;
            vals[step ^ 1][v] += cnt - modif;
        }
    }

    debug { vals[k & 1][1 .. 20].writeln; }

    int a, b;
    foreach (v; 1 .. 1 << 11) {
        if (vals[k & 1][v] > 0) { a = v; }
    }

    foreach_reverse (v; 1 .. 1 << 11) {
        if (vals[k & 1][v] > 0) { b = v; }
    }

    writeln(a, ' ', b);
}

import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int limit = 1 << 10;

void main ()
{
	int n, k, x;
	while (readf (" %s %s %s", &n, &k, &x) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		int [limit] [2] c;
		int b = 0;
		foreach (v; a)
		{
			c[b][v] += 1;
		}

		foreach (step; 0..k)
		{
			b ^= 1;
			c[b][] = 0;
			int p = 0;
			foreach (v; 0..limit)
			{
				int d = c[!b][v] >> 1;
				c[b][v] += d;
				c[!b][v ^ x] += d;
				if (c[!b][v] & 1)
				{
					c[b][v ^ (p ? 0 : x)] += 1;
					p ^= 1;
				}
			}
		}

		int lo = int.max;
		int hi = int.min;
		foreach (v; 0..limit)
		{
			if (c[b][v])
			{
				lo = min (lo, v);
				hi = max (hi, v);
			}
		}
		writeln (hi, " ", lo);
	}
}


import std.stdio, std.string;

bool ok(bool[long] c, long s, long ps)
{
    if (ps >= s - ps && ((ps - (s - ps)) & 1) == 0)
    {
        auto v = (ps - (s - ps)) >> 1;
        if (v in c)
        {
            return true;
        }
    }
    return false;
}

void solve(int[] a)
{
    auto n = cast(int)a.length;
    long s = 0;
    foreach (i; 0 .. n)
    {
        s += a[i];
    }
    long ps = a[0];
    for (int i = 1; i < n; ++ i)
    {
        if (ps == s - ps)
        {
            writeln("YES");
            return;
        }
        ps += a[i];
    }
    foreach (i; 0 .. n)
    {
        if (a[i] == s - a[i])
        {
            writeln("YES");
            return;
        }
    }
    bool[long] c;
    c[a[0]] = true;
    ps = a[0];
    for (int i = 1; i < n - 1; ++ i)
    {
        c[a[i]] = true;
        ps += a[i];
        if (ok(c, s, ps))
        {
            writeln("YES");
            return;
        }
    }
    c.clear();
    c[a[n - 1]] = true;
    ps = a[n - 1];
    for (int i = n - 2; i > 0; -- i)
    {
        c[a[i]] = true;
        ps += a[i];
        if (ok(c, s, ps))
        {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a);
    }
    return 0;
}

import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    ll summ = 0;
    foreach(el; arr){
        summ += el;
    }
    if(summ % 2){
        writeln("NO");
        return;
    }
    bool[long] seen;
    seen[0] = 1;
    long req = (summ/2);
    ll cursum = 0;
    foreach(el; arr){
        cursum += el;
        if(cursum >= req && seen.get(cursum - req, 0) == 1){
            writeln("YES");
            return;
        }
        seen[el] = 1;
    }
    seen.clear;
    cursum = 0;
    foreach_reverse(el; arr){
        cursum += el;
        if(cursum >= req && seen.get(cursum - req, 0) == 1){
            writeln("YES");
            return;
        }
        seen[el] = 1;
    }
    writeln("NO");
}

int main(){
    long t = 1;
    while(t--) solve();
    stdout.flush;
    return 0;
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;
import std.traits;

void main(string[] args)
{
  auto n = next!int;
  auto a = next!long(n);
  long rightSum = cast(long) a.sum;
  auto rightSet = redBlackTree!(true, long)(a);
  long leftSum = 0;
  auto leftSet = redBlackTree!(true, long)();
  foreach(i, ai; a)
    {
      rightSum -= ai;
      rightSet.removeKey(ai);
      leftSum += ai;
      leftSet.insert(ai);
      if (leftSum < rightSum)
	{
	  if ((rightSum - leftSum) % 2 == 0 &&
	      ((rightSum - leftSum) / 2) in rightSet)
	    return writeln("YES");
	}
      else if (leftSum > rightSum)
	{
	  if ((leftSum - rightSum) % 2 == 0 &&
	      ((leftSum - rightSum) / 2) in leftSet)
	    return writeln("YES");
	}
      else
	{
	  return writeln("YES");
	}
    }
  return writeln("NO");
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.bitmanip,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,
	std.meta,core.stdc.stdio : freopen;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;const int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' ') if(isInputRange!X)
{foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a) if(isInputRange!X && isInputRange!(typeof(a.front)))
{
	foreach(ref const i;a)
	{
		foreach(ref const j;i)write(j,' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		auto a=arread!lint;
		RedBlackTree!lint q=new RedBlackTree!lint;
		q.insert(a[0]);
		long s=a[0];
		long sm=a.sum;
		if(sm&1){writeln("NO");continue loop;}
		sm/=2;
		foreach(i;1..n)
		{
			q.insert(a[i]);
			s+=a[i];
			if(!q.equalRange(s-sm).empty){writeln("YES");continue loop;}
		}
		s=0;
		q.clear;
		a.reverse;
		s=a[0];
		q.insert(a[0]);
		foreach(i;1..n)
		{
			q.insert(a[i]);
			s+=a[i];
			if(!q.equalRange(s-sm).empty){writeln("YES");continue loop;}
		}
		writeln("NO");

	}
}

import std.stdio, std.string;

bool ok(bool[long] c, long s, long ps)
{
    if (ps >= s - ps && ((ps - (s - ps)) & 1) == 0)
    {
        auto v = (ps - (s - ps)) >> 1;
        if (v in c)
        {
            return true;
        }
    }
    return false;
}

void solve(int[] a)
{
    auto n = cast(int)a.length;
    long s = 0;
    foreach (i; 0 .. n)
    {
        s += a[i];
    }
    long ps = a[0];
    for (int i = 1; i < n; ++ i)
    {
        if (ps == s - ps)
        {
            writeln("YES");
            return;
        }
        ps += a[i];
    }
    bool[long] c;
    c[a[0]] = true;
    ps = a[0];
    for (int i = 1; i < n - 1; ++ i)
    {
        c[a[i]] = true;
        ps += a[i];
        if (ok(c, s, ps))
        {
            writeln("YES");
            return;
        }
    }
    c.clear();
    c[a[n - 1]] = true;
    ps = a[n - 1];
    for (int i = n - 2; i > 0; -- i)
    {
        c[a[i]] = true;
        ps += a[i];
        if (ok(c, s, ps))
        {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a);
    }
    return 0;
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  int n;
  @Dim("n") int[] a;

  void solve(long tc = -1)
  {
    auto prefix_set = redBlackTree!(true, int)();
    auto suffix_set = redBlackTree!(true, int)(a);
    int prefix_sum = 0;
    int suffix_sum = a.sum;
    foreach(i, ai; a)
      {
        prefix_set.insert(ai);
        suffix_set.removeKey(ai);
        prefix_sum += ai;
        suffix_sum -= ai;
        if (suffix_sum == prefix_sum)
          return writeln("YES");
        if ((suffix_sum - prefix_sum) % 2 == 0 &&
            (suffix_sum - prefix_sum) / 2 in suffix_set)
          return writeln("YES");
        if ((prefix_sum - suffix_sum) % 2 == 0 &&
            (prefix_sum - suffix_sum) / 2 in prefix_set)
          return writeln("YES");
      }
    writeln("NO");
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  int n;
  @Dim("n") int[] a;

  void solve(long tc = -1)
  {
    auto prefix_set = redBlackTree!(true, int)();
    auto suffix_set = redBlackTree!(true, int)(a);
    long prefix_sum = 0;
    long suffix_sum = a.sum;
    foreach(i, ai; a)
      {
        prefix_set.insert(ai);
        suffix_set.removeKey(ai);
        prefix_sum += ai;
        suffix_sum -= ai;
        if (suffix_sum == prefix_sum)
          return writeln("YES");
        if ((suffix_sum - prefix_sum) % 2 == 0 &&
            cast(int)((suffix_sum - prefix_sum) / 2) in suffix_set)
          return writeln("YES");
        if ((prefix_sum - suffix_sum) % 2 == 0 &&
            cast(int)((prefix_sum - suffix_sum) / 2) in prefix_set)
          return writeln("YES");
      }
    writeln("NO");
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  int n;
  @Dim("n") int[] a;

  void solve(long tc = -1)
  {
    auto prefix_set = redBlackTree!(true, int)();
    auto suffix_set = redBlackTree!(true, int)(a);
    long prefix_sum = 0;
    long suffix_sum = a.map!(ai => cast(long) ai).sum;
    foreach(i, ai; a)
      {
        prefix_set.insert(ai);
        suffix_set.removeKey(ai);
        prefix_sum += ai;
        suffix_sum -= ai;
        if (suffix_sum == prefix_sum)
          return writeln("YES");
        if ((suffix_sum - prefix_sum) % 2 == 0 &&
            cast(int)((suffix_sum - prefix_sum) / 2) in suffix_set)
          return writeln("YES");
        if ((prefix_sum - suffix_sum) % 2 == 0 &&
            cast(int)((prefix_sum - suffix_sum) / 2) in prefix_set)
          return writeln("YES");
      }
    writeln("NO");
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto q = RD!int;
	auto ans = new bool[](q);
	foreach (i; 0..q)
	{
		auto n = RD!int;
		auto s = RDA;
		//s.sort!"a > b"();
		auto heap = heapify!"a > b"(s);
		bool ok;
		long[] stack;
		while (!heap.empty)
		{
			auto x = heap.front; heap.removeFront;
			if (x == 2048)
			{
				ok = true;
				break;
			}
			if (stack.length != 2)
			{
				stack ~= x;
			}
			debug writeln(stack);
			if (stack.length == 2)
			{
				if (stack[0] == stack[1])
				{
					heap.insert(stack[0] * 2);
					stack = [];
				}
				else
				{
					stack = stack[1..$];
				}
			}
		}
		ans[i] = ok;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush();
	debug readln();
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int q = rint;
	foreach(_; 0 .. q){
		int n = rint;
		long[] as = rlong(n);
		long s;
		foreach(a; as) if(a <= 2048) s += a;

		if(s >= 2048) "Yes".writeln;
		else "No".writeln;
	}
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;
    auto C = new Tuple!(int, int)[](N);
    auto D = new int[](N);

    A.sort!"a > b"();
    foreach (i; 0..N) C[i] = tuple(B[i], i);
    C.sort!"a[0] < b[0]"();

    foreach (i; 0..N) {
        D[C[i][1]] = A[i];
    }

    D.map!(d => d.to!string).join(" ").writeln;
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      auto A = new long[M];
      foreach (i; 0 .. M) {
        A[i] = readLong();
      }
      auto B = new long[M];
      foreach (i; 0 .. M) {
        B[i] = readLong();
      }

      auto as = new Tuple!(long, int)[M];
      auto bs = new Tuple!(long, int)[M];
      foreach (i; 0 .. M) {
        as[i] = tuple(A[i], i);
        bs[i] = tuple(B[i], i);
      }
      as.sort;
      bs.sort;

      auto ans = new long[M];
      foreach (i; 0 .. M) {
        ans[bs[i][1]] = as[M - 1 - i][0];
      }

      foreach (i; 0 .. M) {
        if (i > 0) write(" ");
        write(ans[i]);
      }
      writeln;
    }
  } catch (EOFException e) {
  }
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.array, std.conv, std.string, std.algorithm;

auto gets() { return readln().chomp(); }
auto getV(T)() { return to!T(readln().chomp()); }
auto getVals(T)() { return to!(T[])(readln().chomp().split(" ")); }

auto isOdd(int p) { return p % 2 != 0; }

void main() {
    int n = getV!int();
    auto xs = getVals!int();
    auto ys = getVals!int();
    auto ix = new int[n];
    auto iy = new int[n];
    makeIndex!("a > b")(xs, ix);
    makeIndex!("a < b")(ys, iy);
    // writeln(ix.map!(a => xs[a]));
    // writeln(iy.map!(a => ys[a]));
    auto zs = new int[n];
    for (int i = 0; i < n; i++) {
        zs[iy[i]] = xs[ix[i]];
    }
    writeln(to!(string[])(zs).join(" "));
}


import std.stdio, std.algorithm;

immutable MOD = 95542721, P = 48;

int cb(int x) {
    return 1L * x * x % MOD * x % MOD;
}

class T {
    int[P] d;
    int l, r, sh, lz;
    T lt, rt;

    this(int L, int R, int[] a) {
        l = L; r = R;
        if (l + 1 == r) {
            d[0] = a[l];
            foreach (i; 1..P) d[i] = cb(d[i - 1]);
            return;
        }
        int m = l + (r - l >> 1);
        lt = new T(l, m, a); rt = new T(m, r, a);
        pu;
    }

    void pd() {
        if (lz) {
            (sh += lz) %= P;
            if (lt !is null) {
                (lt.lz += lz) %= P;
                (rt.lz += lz) %= P;
            }
            lz = 0;
        }
    }

    void pu() {
        sh = 0;
        foreach (i; 0..P)
            d[i] = (lt.d[(i + lt.sh) % P] + rt.d[(i + rt.sh) % P]) % MOD;
    }

    int q(int L, int R) {
        if (R <= l || r <= L) return 0;
        pd;
        if (L <= l && r <= R) return d[sh];
        return (lt.q(L, R) + rt.q(L, R)) % MOD;
    }

    void u(int L, int R) {
        if (L <= l && r <= R) {
            (lz += 1) %= P;
            pd;
            return;
        }
        pd;
        if (R <= l || r <= L) return;
        lt.u(L, R); rt.u(L, R);
        pu;
    }
}

void main() {
    int n;
    readf(" %d", &n);

    auto a = new int[n];
    foreach (i; 0..n) scanf(" %d", &a[i]);

    T tr = new T(0, n, a);

    int q;
    readf(" %d", &q);
    foreach (i; 0..q) {
        int t, l, r;
        scanf(" %d %d %d", &t, &l, &r);
        --l;
        if (t == 1) printf("%d\n", tr.q(l, r));
        else tr.u(l, r);
    }
}

import std.stdio, std.algorithm;

immutable M = 95542721, P = 48;

int cb(int x) {
    return 1L * x * x % M * x % M;
}

class T {
    int[P] d;
    int l, r, sh, lz;
    T lt, rt;

    this(int L, int R, int[] a) {
        l = L; r = R;
        if (l + 1 == r) {
            d[0] = a[l];
            foreach (i; 1..P) d[i] = cb(d[i - 1]);
            return;
        }
        int m = l + (r - l >> 1);
        lt = new T(l, m, a); rt = new T(m, r, a);
        pu;
    }

    void pu() {
        foreach (i; 0..P)
            d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % M;
    }

    int q(int L, int R, int LZ = 0) {
        if (R <= l || r <= L) return 0;
        if (L <= l && r <= R) return d[(LZ + lz) % P];
        return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % M;
    }

    void u(int L, int R) {
        if (L <= l && r <= R) {
            (lz += 1) %= P;
            return;
        }
        if (R <= l || r <= L) return;
        lt.u(L, R); rt.u(L, R);
        pu;
    }
}

void main() {
    int n;
    readf(" %d", &n);

    auto a = new int[n];
    foreach (i; 0..n) scanf(" %d", &a[i]);

    T tr = new T(0, n, a);

    int q;
    readf(" %d", &q);
    foreach (i; 0..q) {
        int t, l, r;
        scanf(" %d %d %d", &t, &l, &r);
        --l;
        if (t == 1) printf("%d\n", tr.q(l, r));
        else tr.u(l, r);
    }
}

import std.stdio, std.algorithm;

immutable M = 95542721, P = 48;

int cb(int x) {
    return 1L * x * x % M * x % M;
}

class T {
    int[P] d;
    int l, r, lz;
    T lt, rt;

    this(int L, int R, int[] a) {
        l = L; r = R;
        if (l + 1 == r) {
            d[0] = a[l];
            foreach (i; 1..P) d[i] = cb(d[i - 1]);
            return;
        }
        int m = l + (r - l >> 1);
        lt = new T(l, m, a); rt = new T(m, r, a);
        pu;
    }

    void pu() {
        foreach (i; 0..P)
            d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % M;
    }

    int q(int L, int R, int LZ = 0) {
        if (R <= l || r <= L) return 0;
        if (L <= l && r <= R) return d[(LZ + lz) % P];
        return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % M;
    }

    void u(int L, int R) {
        if (L <= l && r <= R) {
            (lz += 1) %= P;
            return;
        }
        if (R <= l || r <= L) return;
        lt.u(L, R); rt.u(L, R);
        pu;
    }
}

void main() {
    int n;
    readf(" %d", &n);

    auto a = new int[n];
    foreach (i; 0..n) scanf(" %d", &a[i]);

    T tr = new T(0, n, a);

    int q;
    readf(" %d", &q);
    foreach (i; 0..q) {
        int t, l, r;
        scanf(" %d %d %d", &t, &l, &r);
        --l;
        if (t == 1) printf("%d\n", tr.q(l, r));
        else tr.u(l, r);
    }
}

import std.stdio;

immutable M = 95542721, P = 48;

int cb(int x) {
    return 1L * x * x % M * x % M;
}

class T {
    int[P] d;
    int l, r, lz;
    T lt, rt;

    this(int L, int R, int[] a) {
        l = L; r = R;
        if (l + 1 == r) {
            d[0] = a[l];
            foreach (i; 1..P) d[i] = cb(d[i - 1]);
            return;
        }
        int m = l + (r - l >> 1);
        lt = new T(l, m, a); rt = new T(m, r, a);
        pu;
    }

    void pu() {
        foreach (i; 0..P)
            d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % M;
    }

    int q(int L, int R, int LZ = 0) {
        if (R <= l || r <= L) return 0;
        if (L <= l && r <= R) return d[(LZ + lz) % P];
        return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % M;
    }

    void u(int L, int R) {
        if (R <= l || r <= L) return;
        if (L <= l && r <= R) { (lz += 1) %= P; return; }
        lt.u(L, R); rt.u(L, R);
        pu;
    }
}

void main() {
    int n;
    readf(" %d", &n);

    auto a = new int[n];
    foreach (i; 0..n) scanf(" %d", &a[i]);

    T tr = new T(0, n, a);

    int q;
    readf(" %d", &q);
    foreach (i; 0..q) {
        int t, l, r;
        scanf(" %d %d %d", &t, &l, &r);
        --l;
        if (t == 1) printf("%d\n", tr.q(l, r));
        else tr.u(l, r);
    }
}

import std.stdio, std.algorithm;

immutable MOD = 95542721, P = 48;

int cb(int x) {
    return 1L * x * x % MOD * x % MOD;
}

class T {
    int[P] d;
    int l, r, lz;
    T lt, rt;

    this(int L, int R, int[] a) {
        l = L; r = R;
        if (l + 1 == r) {
            d[0] = a[l];
            foreach (i; 1..P) d[i] = cb(d[i - 1]);
            return;
        }
        int m = l + (r - l >> 1);
        lt = new T(l, m, a); rt = new T(m, r, a);
        pu;
    }

    void pu() {
        lz = 0;
        foreach (i; 0..P) d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % MOD;
    }

    int q(int L, int R, int LZ = 0) {
        if (R <= l || r <= L) return 0;
        if (L <= l && r <= R) return d[(LZ + lz) % P];
        return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % MOD;
    }

    void u(int L, int R, int LZ = 1) {
        if (L <= l && r <= R) {
            (lz += LZ) %= P;
            return;
        }
        if (R <= l || r <= L) return;
        lt.u(L, R, LZ + lz); rt.u(L, R, LZ + lz);
        pu;
    }
}

void main() {
    int n;
    readf(" %d", &n);

    auto a = new int[n];
    foreach (i; 0..n) scanf(" %d", &a[i]);

    T tr = new T(0, n, a);

    int q;
    readf(" %d", &q);
    foreach (i; 0..q) {
        int t, l, r;
        scanf(" %d %d %d", &t, &l, &r);
        --l;
        if (t == 1) printf("%d\n", tr.q(l, r));
        else tr.u(l, r);
    }
}