#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
int main() {
  long long x1, x2, y1, y2, dx, dy;
  long long top1, bot1, lef1, rig1, top2, bot2, lef2, rig2, top3, bot3, lef3,
      rig3, s1, s2, s3;
  cin >> t;
  while (t--) {
    cin >> n >> m >> x1 >> y1 >> x2 >> y2;
    dx = x2 - x1;
    dy = y2 - y1;
    top1 = max(0LL, -dx);
    bot1 = min(n - 1, n - 1 - dx);
    lef1 = max(0LL, -dy);
    rig1 = min(m - 1, m - 1 - dy);
    top2 = max(0LL, dx);
    bot2 = min(n - 1, n - 1 + dx);
    lef2 = max(0LL, dy);
    rig2 = min(m - 1, m - 1 + dy);
    top3 = max(top1, top2);
    bot3 = min(bot1, bot2);
    lef3 = max(lef1, lef2);
    rig3 = min(rig1, rig2);
    s1 = (bot1 - top1 + 1LL) * (rig1 - lef1 + 1LL);
    s2 = (bot2 - top2 + 1LL) * (rig2 - lef2 + 1LL);
    s3 = (bot3 - top3 + 1LL) * (rig3 - lef3 + 1LL);
    if (top3 <= bot3 && lef3 <= rig3)
      cout << m * n - (s1 + s2 - s3) << endl;
    else
      cout << m * n - s1 - s2 << endl;
  }
  return 0;
}

import java.util.*;
import static java.lang.Math.*;

public class Main{
  public static void main(String[] args){
    new Main().run();
  }

  void run(){
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    for(;t>0;t--){
      int n = sc.nextInt();
      int m = sc.nextInt();
      int x1 = sc.nextInt();
      int y1 = sc.nextInt();
      int x2 = sc.nextInt();
      int y2 = sc.nextInt();
      int dx = abs(x1-x2);
      int dy = abs(y1-y2);
      int mnx = min(x1, x2);
      int mxx = max(x1, x2);
      int mny = min(y1, y2);
      int mxy = max(y1, y2);
      int w = n - dx;
      int h = m - dy;
      long ans = 1l * n * m - (1l * w * h * 2 - calc(mnx, mny, w, h, mxx, mxy, w, h));
      System.out.println(ans);
      /*
      if(x1 == x2){
        int mn = min(y1, y2);
        int mx = max(y1, y2);
        int left = m - 1 - dy;
        int right = dy;
        if(left < right)System.out.println(1l * n * (right - left - 1));
        else System.out.println(0);
      }else if(y1 == y2){
        int mn = min(x1, x2);
        int mx = max(x1, x2);
        int left = n - 1 - dx;
        int right = dx;
        if(left < right)System.out.println(1l * m * (right - left - 1));
        else System.out.println(0);
      }else{
        int a1 = n - dx;
        int b1 = 0;
        int a2 = 0;
        int b2 = m - dy;
        long dif = calc(a1, b1, dx, dy, a2, b2, dx, dy);
        long ans = 2l * dx * dy - dif;
        System.out.println(ans);
      }
      */
    }
  }

  long calc(int a1, int b1, int w1, int h1, int a2, int b2, int w2, int h2){
    if(a1 + w1 > a2 && b1 + h1 > b2)
      return 1l*(a1+w1-a2)*(b1+h1-b2);
    return 0;
  }
}


#include <bits/stdc++.h>
using namespace std;
const long long maxn = 27;
int main() {
  int t;
  long long i, j, k, l, m, n, a, b;
  cin >> n;
  vector<pair<int, int>> pr;
  int y = 500000;
  int x = 0;
  pr.push_back({x, y});
  pr.push_back({x + 1, y});
  pr.push_back({x, y - 1});
  pr.push_back({x + 1, y - 1});
  x++, y--;
  while (n--) {
    pr.push_back({x + 1, y});
    pr.push_back({x, y - 1});
    pr.push_back({x + 1, y - 1});
    x++, y--;
  }
  cout << pr.size() << "\n";
  for (auto it : pr) {
    cout << it.first << " " << it.second << "\n";
  }
}

/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        PrintWriter out = new PrintWriter(System.out);
        long n = Long.parseLong(st.nextToken());
        if(n%2 == 0){
            out.println(n*6+8);
            for(int i = 0; i < 2*n+2; i++){
                out.println(i + " " + 0);
            }
            for(int i = 1; i < 4; i++){
                out.println((2*n+1) + " " + i);
            }
            for(int i = 1; i < 4; i++){
                out.println(0 + " " + i);
            }
            for(int i = 1; i < 2*n+1; i++){
                out.println(i + " " + 3);
            }
            for(int i = 2; i < 2*n+2; i+= 4){
                out.println(i + " " + 2);
                out.println(i + " " + 4);
                out.println(i+1 + " " + 2);
                out.println(i+1 + " " + 4);
            }
        }
        else{
            out.println(n*6+7);
            for(int i = 0; i < 2*n+1; i++){
                out.println(i + " " + 0);
            }
            for(int i = 1; i < 4; i++){
                out.println((2*n) + " " + i);
            }
            for(int i = 1; i < 5; i++){
                out.println(0 + " " + i);
            }
            out.println("-1 3");
            out.println("-1 4");
            for(int i = 1; i < 2*n; i++){
                out.println(i + " " + 3);
            }
            for(int i = 3; i < 2*n+1; i+= 4){
                out.println(i + " " + 2);
                out.println(i + " " + 4);
                out.println(i+1 + " " + 2);
                out.println(i+1 + " " + 4);
            }
        }
        out.close();
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<pair<int, int>> chips(k);
  vector<pair<int, int>> pos(k);
  int my = 0, mx = 0;
  for (auto &x : chips) {
    cin >> x.first >> x.second;
  }
  for (auto &x : pos) {
    cin >> x.first >> x.second;
  }
  cout << ((n - 1) + (m - 1) + n * (m - 1) + n - 1) << endl;
  for (int i = 0; i < n - 1; i++) {
    cout << 'U';
  }
  for (int j = 0; j < m - 1; j++) {
    cout << 'L';
  }
  int diry = -1;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (diry == -1) {
        cout << 'D';
      } else {
        cout << 'U';
      }
      if (j == n - 2) {
        if (diry == -1)
          diry = 1;
        else
          diry = -1;
      }
    }
    if (i < m - 1) cout << 'R';
  }
}

n,m,k=map(int, input().split())
for i in range(2*k):
    map(int, input().split())
ans = (m-1)*'L' + (n-1)*'U'
for i in range(n):
    if i%2==0:
        ans += 'R'*(m-1)
    else:
        ans += 'L'*(m-1)
    if i < n-1:
        ans+='D'
print(len(ans))
print(ans)


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {
    static long mod = 998244353;
    static long fact[];
    static long inv[];

    static long pow(long a, long n) {
        if (n == 0) return 1;
        if (n == 1) return a;
        if ((n & 1) == 0) {
            long np = pow(a, n / 2);
            return (np * np)%mod;
        }
        return a % mod * pow(a, n - 1) % mod;
    }

    static long c(int n, int k) {
        return ((fact[n] * inv[k]) % mod * inv[n - k]) % mod;
    }

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int k = in.nextInt();
//        if(n == 5 && k == 5){
//            out.println(1000);
//            out.close();
//            return;
//        }
        array a = new array(n);
        a.scan(in);
        long h[] = a.a;
        long _h[] = a.right_shift(1);
        int eq = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == _h[i]) ++eq;
        }
        inv = new long[n + 1];
        fact = new long[n + 1];
        fact[1] = inv[1] = fact[0] = inv[0] = 1;
        for (int i = 2; i < n + 1; i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
            inv[i] = pow(fact[i], mod - 2);
            inv[i] %= mod;
        }
        long f = max(1, pow(k, eq));
        int N = n - eq;
        long ans = 0;
        long sum = 1;
        for (int i = 1; i <= N; i++) {
            ans = (ans + sum * pow(k - 2, N - i) % mod * c(N, i)) % mod;
            sum = sum * 2 % mod;
            if (i % 2 != 0) {
                sum = (sum + mod - c(i, i / 2)) % mod;
            }
            else {
                sum = (sum + c(i, i / 2)) % mod;
            }
        }
        ans = ans * f % mod;
        out.println(ans);
        out.close();
    }
}

class RANDOMIZER {
    static Random rnd = new Random();

    static int randomize() {
        return rnd.nextInt();
    }
}

class array {
    long a[];

    array(long a[]) {
        this.a = a;
    }

    array(int n) {
        a = new long[n];
    }

    void shuffle() {
        for (int i = 0; i < a.length; i++) {
            int id1 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;
            int id2 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;
            long t = a[id1];
            a[id1] = a[id2];
            a[id2] = t;
        }
    }

    void reverse(int l, int r) {
        for (int i = l; i < l + (r - l + 1) >> 1; i++) {
            long t = a[i];
            a[i] = a[r - i];
            a[r - i] = t;
        }
    }

    long[] right_shift(int shift) {
        long aa[] = new long[a.length];
        for (int i = 0; i < a.length; i++) {
            aa[(i + shift) % a.length] = a[i];
        }
        return aa;
    }

    void add(int l, int r, long val) {
        for (int i = l; i <= r; i++) {
            a[i] += val;
        }
    }

    void print(PrintWriter out) {
        for (int i = 0; i < a.length; i++) {
            out.print(a[i] + " ");
        }
    }

    void copy(long t[]) {
        for (int i = 0; i < a.length; i++) {
            a[i] = t[i];
        }
    }

    void scan(FastScanner in) throws IOException {
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextLong();
        }
    }

    long getSum() {
        long sum = 0;
        long md = (long) 1e16;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
            sum %= md;
        }
        return sum;
    }

    long getMin() {
        long min = Long.MAX_VALUE;
        for (int i = 0; i < a.length; i++) {
            min = min(min, a[i]);
        }
        return min;
    }

    long getMax() {
        long max = Long.MIN_VALUE;
        for (int i = 0; i < a.length; i++) {
            max = max(max, a[i]);
        }
        return max;
    }

    int ceilingID(long val) {
        int l = 0;
        int r = a.length - 1;
        while (l + 1 != r) {
            int m = (l + r) >> 1;
            if (a[m] >= val) r = m;
            else l = m;
        }
        int pr = l;
        if (pr > 0 && a[pr - 1] >= val) pr--;
        if (a[pr] < val) pr++;
        if (pr < a.length && a[pr] < val) pr++;
        return pr;
    }
}

class dsu {
    int p[];
    int max[];

    dsu(int n) {
        p = new int[n];
        max = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = i;
            max[i] = i;
        }
    }

    int get(int a) {
        if (p[a] == a) return a;
        return p[a] = get(p[a]);
    }

    void merge(int a, int b) {
        a = get(a);
        b = get(b);
        if (a != b) {
            p[a] = b;
            max[b] = max(max[a], max[b]);
        }
    }
}

class vertex {
    int next[];
}

class trie {
    vertex t[];
    int sz = 1;
    int k;

    trie(int k) {
        this.k = k;
        t = new vertex[300000];
        for (int i = 0; i < t.length; i++) {
            t[i] = new vertex();
            t[i].next = new int[k];
            for (int j = 0; j < k; j++) {
                t[i].next[j] = -1;
            }
        }
    }

    void add(String s, int id) {
        int v = 0;
        for (int i = 0; i < s.length(); i++) {
            char rc = (char) (s.charAt(i) - 'a');
            if (t[v].next[rc] == -1) {
                t[v].next[rc] = sz++;
            }
            v = t[v].next[rc];
        }
    }
}

class StringHelper {
    char[] s;
    long hash[];
    long px[];
    long mod = (int) 1e9 + 7;
    long x = 255;
    int n;

    public StringHelper(String s) {
        this.s = s.toCharArray();
        n = s.length();
    }

    int[] pi() {
        int pi[] = new int[n];
        for (int i = 1; i < n; i++) {
            int j = pi[i - 1];
            while (j > 0 && s[i] != s[j]) j = pi[j - 1];
            pi[i] = s[i] == s[j] ? j + 1 : j;
        }
        return pi;
    }

    void calcHash() {
        hash = new long[n + 1];
        px = new long[n + 3];
        px[0] = 1;
        for (int i = 1; i < n + 3; i++) {
            px[i] = px[i - 1] * x % mod;
        }
        for (int i = 1; i < n + 1; i++) {
            hash[i] = (hash[i - 1] * x % mod + s[i - 1] + mod) % mod;
        }
    }

    long getHash(int l, int r) {
        return (hash[r + 1] - hash[l] * px[r - l + 1] % mod + mod) % mod;
    }
}

class IMPLICITDT {
    long val;
    int y;
    int sz;
    IMPLICITDT l, r;

    static int getSize(IMPLICITDT t) {
        return t == null ? 0 : t.sz;
    }

    private static void recalc(IMPLICITDT t) {
        if (t == null) return;
        int LSZ = t.l == null ? 0 : t.l.sz;
        int RSZ = t.r == null ? 0 : t.r.sz;
        t.sz = LSZ + RSZ + 1;
    }

    IMPLICITDT() {
    }

    IMPLICITDT(long cost, int y, IMPLICITDT l, IMPLICITDT r) {
        this.val = cost;
        this.y = y;
        this.l = l;
        this.r = r;
        recalc(this);
    }

    IMPLICITDT(long cost, int y) {
        this.val = cost;
        this.y = y;
        recalc(this);
    }

    static long get(IMPLICITDT t, int id) {
        int LSZ = getSize(t.l);
        if (LSZ == id) return t.val;
        if (LSZ < id) return get(t.r, id - LSZ - 1);
        return get(t.l, id);
    }

    static IMPLICITDT split(IMPLICITDT T, int x) {
        IMPLICITDT RES = new IMPLICITDT();
        if (T == null) {
            return RES;
        }
        if (getSize(T.l) > x) {
            IMPLICITDT lsplit = split(T.l, x);
            RES.l = lsplit.l;
            RES.r = T;
            T.l = lsplit.r;
        } else {
            IMPLICITDT rsplit = split(T.r, x - getSize(T.l) - 1);
            RES.r = rsplit.r;
            RES.l = T;
            T.r = rsplit.l;
        }
        recalc(RES);
        recalc(T);
        return RES;
    }

    static IMPLICITDT merge(IMPLICITDT L, IMPLICITDT R) {
        if (L == null) return R;
        if (R == null) return L;
        if (L.y > R.y) return new IMPLICITDT(L.val, L.y, L.l, merge(L.r, R));
        else return new IMPLICITDT(R.val, R.y, merge(L, R.l), R.r);
    }

    static IMPLICITDT insert(IMPLICITDT T, long val, int id) {
        if (T == null) return new IMPLICITDT(val, RANDOMIZER.randomize());
        IMPLICITDT _T = split(T, id);
        IMPLICITDT _TR = new IMPLICITDT(val, RANDOMIZER.randomize());
        IMPLICITDT NEWTREAP = merge(_T.l, _TR);
        IMPLICITDT TREAP = merge(NEWTREAP, _T.r);
        recalc(TREAP);
        return TREAP;
    }
}

class stSUM {
    int t[];
    int a[];

    stSUM(int a[]) {
        this.a = a;
        t = new int[a.length * 4];
    }

    void build(int v, int l, int r) {
        if (l == r) t[v] = a[l];
        else {
            int m = (l + r) >> 1;
            build(v * 2, l, m);
            build(v * 2 + 1, m + 1, r);
            t[v] = t[v * 2] + t[v * 2 + 1];
        }
    }

    void upd(int v, int l, int r, int pos, int x) {
        if (l == r) t[v] = x;
        else {
            int m = (l + r) >> 1;
            if (pos <= m) upd(v * 2, l, m, pos, x);
            else upd(v * 2 + 1, m + 1, r, pos, x);
            t[v] = t[v * 2] + t[v * 2 + 1];
        }
    }

    int query(int v, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return t[v];
        if (l > qr || ql > r) return 0;
        int m = (l + r) >> 1;
        return query(v * 2, l, m, ql, qr) + query(v * 2 + 1, m + 1, r, ql, qr);
    }
}

class stMIN {
    int t[];
    int a[];

    stMIN(int a[]) {
        this.a = a;
        t = new int[a.length * 4];
    }

    void build(int v, int l, int r) {
        if (l == r) t[v] = a[l];
        else {
            int m = (l + r) >> 1;
            build(v * 2, l, m);
            build(v * 2 + 1, m + 1, r);
            t[v] = min(t[v * 2], t[v * 2 + 1]);
        }
    }

    void upd(int v, int l, int r, int pos, int x) {
        if (l == r) t[v] = x;
        else {
            int m = (l + r) >> 1;
            if (pos <= m) upd(v * 2, l, m, pos, x);
            else upd(v * 2 + 1, m + 1, r, pos, x);
            t[v] = min(t[v * 2], t[v * 2 + 1]);
        }
    }

    int query(int v, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return t[v];
        if (l > qr || ql > r) return Integer.MAX_VALUE;
        int m = (l + r) >> 1;
        return min(query(v * 2, l, m, ql, qr), query(v * 2 + 1, m + 1, r, ql, qr));
    }
}

class DT {
    long val;
    int x, y;
    int sz;
    DT l, r;

    DT() {
        recalc(this);
    }

    DT(int x, int y, long val) {
        this.x = x;
        this.y = y;
        this.val = val;
        recalc(this);
    }

    DT(int x, int y, DT l, DT r, long val) {
        this.x = x;
        this.y = y;
        this.l = l;
        this.r = r;
        this.val = val;
        recalc(this);
    }

    static DT split(DT t, int x) {
        DT res = new DT();
        if (t == null) {
            res.l = null;
            res.r = null;
            return res;
        }
        if (x < t.x) {
            DT lsplit = split(t.l, x);
            res.l = lsplit.l;
            res.r = t;
            t.l = lsplit.r;
        } else {
            DT rsplit = split(t.r, x);
            res.r = rsplit.r;
            res.l = t;
            t.r = rsplit.l;
        }
        recalc(t);
        recalc(res);
        return res;
    }

    static DT merge(DT t1, DT t2) {
        if (t1 == null || t2 == null)
            return t1 == null ? t2 : t1;
        if (t1.y < t2.y) {
            t1.r = merge(t1.r, t2);
            recalc(t1);
            return t1;
        } else {
            t2.l = merge(t1, t2.l);
            recalc(t2);
            return t2;
        }
    }

    static void recalc(DT t) {
        if (t == null) return;
        int lsz = t.l == null ? 0 : t.l.sz;
        int rsz = t.r == null ? 0 : t.r.sz;
        t.sz = lsz + rsz + 1;
    }

    static DT insert(DT t, int x, long val) {
        try {
            if (t == null) {
                DT ret = new DT(x, RANDOMIZER.randomize(), val);
                recalc(ret);
                return ret;
            }
            DT split = split(t, x);
            DT prelast = merge(split.l, new DT(x, RANDOMIZER.randomize(), val));
            DT newtreap = merge(prelast, split.r);
            recalc(newtreap);
            return newtreap;
        } catch (Exception e) {
            System.exit(0);
            return new DT();
        }
    }

    static long find_kth(DT t, int k) {
        if (t.l == null && k == 1)
            return t.val;
        if (t.l != null && t.l.sz == k - 1)
            return t.val;
        if (t.l != null && t.l.sz >= k)
            return find_kth(t.l, k);
        else
            return find_kth(t.r, k - (t.l == null ? 0 : t.l.sz) - 1);
    }

}

class FT {
    private int[] a;
    private long[] t;

    FT(int[] a) {
        this.a = a;
        t = new long[a.length];
    }

    void inc(int i, int delta) {
        for (; i < a.length; i = (i | (i + 1)))
            t[i] += delta;
    }

    long sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    private long sum(int r) {
        long sum = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1) {
            sum += t[r];
        }
        return sum;
    }
}

class LAZY_ST {
    long min[], sum[], set[];
    int last;
    long not_set = Long.MAX_VALUE;

    LAZY_ST(long a[]) {
        int n = a.length;
        last = n - 1;
        min = new long[4 * n];
        sum = new long[4 * n];
        set = new long[4 * n];
        for (int i = 0; i < 4 * n; i++) {
            set[i] = not_set;
        }
        build(0, 0, last, a);
    }

    void build(int v, int l, int r, long a[]) {
        if (l == r) {
            min[v] = a[l];
            return;
        }
        int m = ((l + r) >> 1);
        build(v * 2 + 1, l, m, a);
        build(v * 2 + 2, m + 1, r, a);
        min[v] = Math.min(min[v * 2 + 1], min[v * 2 + 2]);
    }

    void push(int v) {
        if (set[v] != not_set) {
            min[v] = set[v];
            sum[v * 2 + 1] = sum[v * 2 + 2] = 0;
            set[v * 2 + 1] = set[v * 2 + 2] = set[v];
            set[v] = not_set;
        }

        min[v] += sum[v];
        sum[v * 2 + 1] += sum[v];
        sum[v * 2 + 2] += sum[v];
        sum[v] = 0;
    }

    void upd(int v) {
        min[v] = Math.min(get_el(v * 2 + 1), get_el(v * 2 + 2));
    }

    long get_el(int v) {
        return (set[v] == not_set ? min[v] : set[v]) + sum[v];
    }

    void set(int l, int r, long x) {
        set(0, 0, last, l, r, x);
    }

    void set(int v, int l, int r, int left, int right, long x) {
        if (l > right || r < left) return;
        if (l >= left && r <= right) {
            sum[v] = 0;
            set[v] = x;
            return;
        }
        push(v);
        int m = ((l + r) >> 1);

        set(v * 2 + 1, l, m, left, right, x);
        set(v * 2 + 2, m + 1, r, left, right, x);

        upd(v);
    }

    void add(int l, int r, long x) {
        add(0, 0, last, l, r, x);
    }

    void add(int v, int l, int r, int left, int right, long x) {
        if (l > right || r < left) return;
        if (l >= left && r <= right) {
            sum[v] += x;
            return;
        }
        push(v);
        int m = ((l + r) >> 1);

        add(v * 2 + 1, l, m, left, right, x);
        add(v * 2 + 2, m + 1, r, left, right, x);

        upd(v);
    }

    long get(int l, int r) {
        return get(0, 0, last, l, r);
    }

    long get(int v, int l, int r, int left, int right) {
        if (l > right || r < left) return (long) 1e17;

        if (l >= left && r <= right) {
            return get_el(v);
        }
        push(v);
        int m = ((l + r) >> 1);

        long ans = Math.min(get(v * 2 + 1, l, m, left, right), get(v * 2 + 2, m + 1, r, left, right));
        upd(v);
        return ans;
    }

}

class multiset {
    TreeMap<Long, Integer> t;

    void insert(long val) {
        t.put(val, t.getOrDefault(val, 0) + 1);
    }

    void erase(long val) {
        int nw = t.getOrDefault(val, 1);
        if (nw == 1) t.remove(val);
        else t.put(val, nw - 1);
    }

    long ceiling(long val) {
        return t.ceilingKey(val);
    }

    long floor(long val) {
        return t.floorKey(val);
    }

    long higher(long val) {
        return t.higherKey(val);
    }

    long lower(long val) {
        return t.lowerKey(val);
    }

    int count(long val) {
        return t.getOrDefault(val, 0);
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    FastScanner(File f) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(f));
    }

    FastScanner(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}

class tree {
    ArrayList<Integer> g[];
    int n;
    ArrayList<Integer> order;
    int first[];
    int h[];
    int t[];
    int rt;

    tree(ArrayList<Integer> g[]) {
        this.g = g;
        this.n = g.length;
        order = new ArrayList<>();
        first = new int[n];
        fill(first, -1);
        h = new int[n];
        rt = 0;
        dfs(rt, -1);
        prepare();
    }

    void dfs(int v, int p) {
        if (first[v] == -1) first[v] = order.size();
        order.add(v);
        for (int to : g[v]) {
            if (to == p) continue;
            h[to] = h[v] + 1;
            dfs(to, v);
            order.add(v);
        }
    }

    void prepare() {
        t = new int[order.size() * 4];
        build(1, 0, order.size() - 1);
    }

    void build(int v, int l, int r) {
        if (l == r) t[v] = order.get(l);
        else {
            int m = (l + r) >> 1;
            build(v * 2, l, m);
            build(v * 2 + 1, m + 1, r);
            t[v] = h[t[v * 2]] < h[t[v * 2 + 1]] ? t[v * 2] : t[v * 2 + 1];
        }
    }

    int query(int v, int l, int r, int ql, int qr) {
        if (l > qr || ql > r) return Integer.MAX_VALUE;
        if (ql <= l && r <= qr) return t[v];
        int m = (l + r) >> 1;
        int v1 = query(v * 2, l, m, ql, qr);
        int v2 = query(v * 2 + 1, m + 1, r, ql, qr);
        if (v1 == Integer.MAX_VALUE) return v2;
        if (v2 == Integer.MAX_VALUE) return v1;
        return h[v1] < h[v2] ? v1 : v2;
    }

    int lca(int a, int b) {
        int l = first[a];
        int r = first[b];
        return query(1, 0, order.size() - 1, min(l, r), max(l, r));
    }
}

#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAXN = 2001;
int add(int a, int b) {
  if (a + b < 0) return a + b + MOD;
  if (a + b >= MOD) return a + b - MOD;
  return a + b;
}
int mul(int a, int b) { return (long long)a * b % MOD; }
bool bio[MAXN][2 * MAXN];
int n, k;
int a[MAXN], memo[MAXN][2 * MAXN];
int dp(int i, int diff) {
  if (bio[i][diff + n]) return memo[i][diff + n];
  bio[i][diff + n] = true;
  if (i == n) return memo[i][diff + n] = diff > 0;
  int ret = 0;
  if (a[i] == a[(i + 1) % n]) {
    ret = add(ret, mul(k, dp(i + 1, diff)));
  } else {
    ret = add(ret, dp(i + 1, diff + 1));
    ret = add(ret, dp(i + 1, diff - 1));
    ret = add(ret, mul(k - 2, dp(i + 1, diff)));
  }
  return memo[i][diff + n] = ret;
}
int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  printf("%d\n", dp(0, 0));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  for (auto &t : a) {
    cin >> t;
  }
  vector<long long> ind;
  for (long long i = 0; i < n; i++) {
    ind.push_back(i);
  }
  sort(ind.rbegin(), ind.rend(),
       [&](long long i, long long j) { return a[i] < a[j]; });
  long long ans = 0;
  vector<long long> cut(m * k);
  for (long long i = 0; i < m * k; i++) {
    ans += a[ind[i]];
    cut[i] = ind[i];
  }
  sort(cut.begin(), cut.end());
  cout << ans << '\n';
  long long cnt = 0;
  long long uu = 0;
  for (long long i = 0; i < n; i++) {
    auto it = lower_bound(cut.begin(), cut.end(), i);
    bool fl = false;
    if (it != cut.end() && *(it) == i) {
      fl = true;
    }
    if (fl) {
      cnt++;
    }
    if (cnt == m && uu < k - 1) {
      uu++;
      cnt = 0;
      cout << i + 1 << ' ';
    }
  }
}

from operator import itemgetter
from itertools import accumulate
from sys import stdin, stdout
n, m, k = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
id = [x for x in range(n)]
b = list(zip(a, id))
a.sort(reverse = True)
b.sort(reverse = True)
c = [p[1] for p in b[:m*k]]
c.sort()
print(list(accumulate(a[:m*k]))[-1])
for x in [x + 1 for x in c][m-1::m][:k-1]:
    print(x, end = ' ')


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        if (s.chars().distinct().count() > 1) {
            s = s.replaceAll(".*(.)(?!\\1)(.).*", "$1$2");
            System.out.println("YES\n" + s);
        } else {
            System.out.println("NO");
        }
    }
}

length=int(input())
def AllSubsets(s) : # accepts a string , returns a list of all non empty subsets
	l=[]
	for i in range (len(s)) :
			if i <len(s)-1:
				for j in range (i+2,len(s)+1):
					l+=[s[i:j]]
			else :
				l+=[s[i]]
	return l

#print(AllSubsets("string"))

def diverse(st) : # accepts string , returns 1 if diverse else 0
	for z in range (len(st)) :
		if st.count(st[z])>len(st)//2 :
			return 0
		elif z==len(st)-1:
			return 1

#print(diverse("abc"))
def output(l):  # accepts a list , prints NO / YES(along with the diverse strings)
	for sub in l :
		if diverse(sub)==1 :
			print("YES")
			print(sub)
			break
	else:
		print("NO")

output(AllSubsets(input()))


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author SarvagyaAgarwal
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) {
                arr[i] = in.nextInt();
                if (arr[i] % 2 == 1) {
                } else arr[i] -= 1;
            }
            for (int i = 0; i < n; ++i) {
                out.print(arr[i]);
                if (i != n - 1) out.print(" ");
                else out.println();
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

if __name__ == "__main__":
    _ = int(input())
    arr = [int(num) for num in input().split()]
    for i in arr:
        if i % 2 == 0:
            print(i - 1, end=" ")
        else:
            print(i, end=" ")


#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10, OO = 1e9;
const long long MOD = 998244353;
int n;
void print(string s) {
  cout << s << endl;
  exit(0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  string t = s;
  sort(t.begin(), t.end());
  n = s.size();
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != t[i]) print("NO");
    if (s[i] == 'a') ++a;
    if (s[i] == 'b') ++b;
    if (s[i] == 'c') ++c;
  }
  if (a == 0 || b == 0) print("NO");
  if (c == a || c == b) print("YES");
  print("NO");
}

ab ccbcc b bbc bcccc baa bbacc ababc aa abab aaa aabbc ac aa aaaaaabc aaaaac aaabccc aabbbc ababbc aaaaa aabc baaa abbb aaaaabc abbabc abbbb a aac abb bccc bbbbc aaabc c ababbbbc baaaa aaaa aabbbbc babc aaaabc aaaac ba aabb bc bc aaac bcc aabc aab abbbbb abbbabc

YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO YES YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO


//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;

public class C {
    String fileName = "C";
    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public C() {
    }

    public void solve() throws IOException {
        int n = this.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> visitTime = new HashMap(n);
        Map<Integer, Integer> roomNumber = new HashMap(n);

        int roomId;
        for(roomId = 0; roomId < n; ++roomId) {
            a[roomId] = this.nextInt();
        }

        roomId = 0;
        int ans = 0;

        for(int i = 0; i < n; ++i) {
            if(!roomNumber.keySet().contains(Integer.valueOf(a[i]))) {
                ++roomId;
                visitTime.put(Integer.valueOf(roomId), Integer.valueOf(i + 1));
                roomNumber.put(Integer.valueOf(i + 1), Integer.valueOf(roomId));
                ++ans;
            } else {
                int roomIdCur = ((Integer)roomNumber.get(Integer.valueOf(a[i]))).intValue();
                roomNumber.remove(Integer.valueOf(a[i]));
                visitTime.put(Integer.valueOf(roomIdCur), Integer.valueOf(i + 1));
                roomNumber.put(Integer.valueOf(i + 1), Integer.valueOf(roomIdCur));
            }
        }

        this.out.print(ans);
    }

    public void run() {
        try {
            this.br = new BufferedReader(new InputStreamReader(System.in));
            this.out = new PrintWriter(System.out);
            this.solve();
            this.out.close();
        } catch (IOException var2) {
            var2.printStackTrace();
            System.exit(1);
        }

    }

    public String nextToken() throws IOException {
        while(this.in == null || !this.in.hasMoreTokens()) {
            this.in = new StringTokenizer(this.br.readLine());
        }

        return this.in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(this.nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(this.nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(this.nextToken());
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        (new C()).run();
    }
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t--) {
    long long n, i;
    cin >> n;
    map<long long, long long> mp;
    long long s = 0;
    for (i = 1; i <= n; i++) {
      long long x;
      cin >> x;
      mp[x]++;
    }
    for (auto i : mp) {
      if (i.first == 0)
        s += i.second;
      else
        s += i.second - 1;
    }
    cout << s << endl;
  }
  return 0;
}


n=int(input())
o1=[]
o2=[]
e1=[]
e2=[]
l=list(map(int,input().split()))
for i in range(n):
    if l[i]%2==0:
        if l[i]<0:
            e1.append(l[i])
        elif l[i]>0:
            e2.append(l[i])
    else:
        if l[i]>0:
            o2.append(l[i])
        elif l[i]<0:
            o1.append(l[i])
#print(o1,o2,e1,e2)
if len(o2)==0:
    print(max(o1)+sum(e2))
else:
    if len(o2)%2==0:
        a2=sum(o2)+sum(e2)-min(o2)
        if len(o1)>0:
            a1=sum(o2)+sum(e2)+max(o1)
            #a2=sum(o2)+sum(e2)-min(o2)
            print(max(a1,a2))
        else:
            print(a2)
    else:
        print(sum(o2)+sum(e2))

#include <bits/stdc++.h>
using namespace std;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const long long INF = 1e9 + 7;
void edit() { return; }
void solve() {
  int n, x, sum = 0, mx = -100000, mxo = 100000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x >= 0) {
      sum += x;
      if (x & 1) mxo = min(mxo, x);
    } else if (x & 1)
      mx = max(mx, x);
  }
  if (sum & 1)
    cout << sum;
  else {
    cout << max(sum + mx, sum - mxo);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}


#!/usr/bin/env python3

from decimal import Decimal

def dist(a, b):
    x1, y1 = a
    x2, y2 = b
    return Decimal((x1-x2)**2+(y1-y2)**2).sqrt()

def minh(a, b, c):
    m = dist(a, b)
    n = dist(b, c)
    k = dist(a, c)
    p = Decimal(m + n + k)/2
    sqp = (p*(p-m)*(p-n)*(p-k)).sqrt()
    hm = (Decimal(2)/m)*sqp
    hn = (Decimal(2)/n)*sqp
    hk = (Decimal(2)/k)*sqp
    return min([hm, hn, hk])

def solve():
    n = int(input())
    coords = []
    for i in range(n):
        coords.append(tuple(map(int, input().split())))
    coords += coords

    res = min(
        minh(coords[i], coords[i+1], coords[i+2])
        for i in range(n))

    print(res/2)

if __name__ == '__main__':
    solve()

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
struct Point {
  double x, y;
  Point(double _x = 0, double _y = 0) {
    x = _x;
    y = _y;
  }
} point[maxn];
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
Point operator+(const Point &a, const Point &b) {
  return Point(a.x + b.x, a.y + b.y);
}
double operator*(const Point &a, const Point &b) {
  return a.x * b.y - b.x * a.y;
}
double dis(const Point &a, const Point &b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lf %lf", &point[i].x, &point[i].y);
  for (int i = n; i < n * 2; i++) point[i] = point[i - n];
  double ans = 1e18;
  for (int i = 0; i < n; i++) {
    double tmp = (point[i + 2] - point[i]) * (point[i + 1] - point[i]) / 2;
    ans = min(ans, tmp / dis(point[i], point[i + 2]));
  }
  printf("%.10f\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;
int main() {
  double a, b, c;
  scanf("%lf%lf%lf", &a, &b, &c);
  printf("%.18lf\n", a * a * a * sqrt(2) / 12 + b * b * b / 3 / sqrt(2) +
                         c * c * c * 0.301502832395831588);
  return 0;
}

import java.util.*;
public class Q630 {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		double l3 = scan.nextDouble();
		double l4 = scan.nextDouble();
		double l5 = scan.nextDouble();
		double v1 = (1/3.0)*((Math.sqrt(3)/4)*(l3*l3)) *(Math.sqrt(l3*l3-(l3*l3)/3));
		double v2 = (1/3.0)*(l4*l4)*Math.sqrt(l4*l4-l4*l4/2);
		double t54 = Math.sqrt(1+2.0/Math.sqrt(5));
		double x = l5/(Math.sqrt(5.0/8.0+Math.sqrt(5.0)/8.0))*(Math.sqrt(5.0)+1.0)/4.0;
		double v3 = (5.0/12.0)*t54*(l5*l5)*Math.sqrt(l5*l5-x*x);
		System.out.printf("%.16f", v1+v2+v3);
	}
}


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

lis=list()
s=''
for i in range(1,69):
    s=s+'1'
    for j in range(1,len(s)):
        temp=s[:j]+'0'+s[j+1:]
        lis.append(int(temp,2))

c=0
for x in lis:
    if x>=a and x<=b:
        c+=1
print(c)

//package codeforces;

import java.util.Scanner;

/**
 * Created by nitin.s on 08/10/16.
 */
public class NewYearAndOldProperty {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        int res = 0;
        for(int len = 1; len <= 60; ++len) {
            for(int j = 0; j + 1 < len; ++j) {
                long cur = (1L << len) - 1 - (1L << j);
                if(cur >= a && cur <= b) {
                    ++res;
                }
            }
        }
        System.out.println(res);
    }
}


#41A
print("YES" if input()==input()[::-1] else "NO")

YES NO YES YES YES YES YES YES YES YES YES YES NO YES YES YES NO YES NO YES YES YES YES YES YES NO YES YES NO YES NO YES YES YES NO YES YES YES YES YES YES NO

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  cin >> s >> s1;
  reverse(s.begin(), s.end());
  if (s == s1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


import java.util.*;

public class B {

	private final static boolean autoflush = false;

	public B () {
		int N = sc.nextInt();

		Integer [] T = sc.nextInts();
		Integer [] S = sc.nextInts();
		for (int i = 0; i < N; ++i)
			--S[i];

		int [] cnt = new int [N];
		for (int i = 0; i < N; ++i)
			if (S[i] >= 0)
				++cnt[S[i]];

		for (int i = 0; i < N; ++i)
			if (S[i] >= 0 && cnt[S[i]] > 1)
				S[i] = -1;

		Deque<Integer> res = new LinkedList<Integer>();
		for (int i = 0; i < N; ++i)
			if (T[i] == 1) { // Hotel!
				Deque<Integer> x = new LinkedList<Integer>();
				int j = i;
				do {
					x.addFirst(j+1);
					j = S[j];
				} while (j != -1);
				if (x.size() > res.size())
					res = x;
			}

		print(res.size());
		exit(res);
	}

	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public String nextLine() { line = null; return readLine(); }
		public String [] nextStrings() { return nextLine().split(" "); }
		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit (Object o, Object... a) { print(o, a); exit(); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new B(); exit(); }
}

import sys
def Z(s):
    return int(s)-1

n=int(sys.stdin.readline())

Hotels=[False]*(n)

Rep=[0]*(n+1)
Chains=[]

Type=list(map(int,sys.stdin.readline().split()))
for i in range(n):
    if(Type[i]==1):
        Hotels[i]=True
A=list(map(Z,sys.stdin.readline().split()))

for item in A:
    Rep[item]+=1
for i in range(n):
    if(Hotels[i]):
        Chains.append([i])
        x=A[i]
        if(x==-1):
            continue
        while(A[x]!=-1 and Rep[x]<=1):
            Chains[-1].append(x)
            x=A[x]
        if(Rep[x]<=1):
            Chains[-1].append(x)

if(n==1):
    print(1)
    print(1)
else:

    X=max(Chains,key=len)

    sys.stdout.write(str(len(X))+"\n")
    sys.stdout.write(str(X[-1]+1))

    for i in range(len(X)-2,-1,-1):
        sys.stdout.write(" "+str(X[i]+1))


n = int(input())

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

c = list(map(abs, a))

if len(list(filter(lambda x: x < 0, a))) & 1 and n + 1 & 1:

  print(sum(c) - 2 * min(c))

else:

  print(sum(c))

# Made By Mostafa_Khaled

import java.io.StreamTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		TokenizerReader in = new TokenizerReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(@SuppressWarnings("UnusedParameters") int testNumber, TokenizerReader in, PrintWriter out) {
        int n = in.nextInt();
        int numNegative = 0, sum = 0, min = 1001;

        for (int i = 0; i < 2*n - 1; ++i) {
            int a = in.nextInt();
            if (a < 0)
                ++numNegative;
            int abs = Math.abs(a);
            sum += abs;
            if (abs < min)
                min = abs;
        }
        if (n % 2 == 0 && numNegative % 2 == 1)
            sum -= 2 * min;
        out.println(sum);
    }
}

class TokenizerReader extends StreamTokenizer {
    public TokenizerReader(InputStream in) {
        super(new BufferedReader(new InputStreamReader(in)));
        defaultConfig();
    }

    public String nextString() {
        try {
            nextToken();
        } catch (IOException e) {
            throw new RuntimeException("nextString: exception in line " + lineno(), e);
        }
        return sval;
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public void defaultConfig() {
        resetSyntax();
        wordChars(33, 126);
        whitespaceChars(0, ' ');
    }

    }


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class Main {
	public static void main(String[] args) throws IOException {
		(new Main()).solve();
	}

	public void Main() {
	}

	void solve() throws IOException {
		// BufferedReader in = new BufferedReader(new
		// InputStreamReader(System.in));
		// Scanner in = new Scanner(System.in);
		MyReader in = new MyReader();
		PrintWriter out = new PrintWriter(System.out);
		//Scanner in = new Scanner(new FileReader("lantern2.in"));
		//PrintWriter out = new PrintWriter("lantern2.out");

		long n = in.nextLong();
		long m = in.nextLong();
		long[] a = new long[(int)n + 1];

		for (int i = 0; i < m; i++) {
			a[in.nextInt()]++;
			a[in.nextInt()]++;
		}

		long s = 0;

		for (int i = 1; i < n + 1; i++) {
			s += a[i]*(a[i] - 1)/2;
		}

		s = n*(n - 1)*(n - 2)/6 - m * (n - 2) + s;

		out.println(s);

		out.close();
	}

};

class MyReader {
	private BufferedReader in;
	String[] parsed;
	int index = 0;

	public MyReader() {
		in = new BufferedReader(new InputStreamReader(System.in));
	}

	public int nextInt() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Integer.parseInt(parsed[index++]);
	}

	public long nextLong() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Long.parseLong(parsed[index++]);
	}

	public String nextString() throws IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return parsed[index++];
	}

	private void read() throws IOException {
		parsed = in.readLine().split(" ");
		index = 0;
	}

	public String readLine() throws IOException {
		return in.readLine();
	}
};

#include <bits/stdc++.h>
using namespace std;
long long deg[1000011];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long ans = n * (n - 1) * (n - 2) / 6;
  for (long long i = 0; i < n; i++) deg[i]++;
  while (m--) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    ans -= n - deg[u] - deg[v];
    deg[u]++;
    deg[v]++;
  }
  cout << ans << endl;
  return 0;
}


# import math
# import sys
n = int(input().strip())
s = input().strip()
a = 0
for i in range(n):
	if s[i]=='(':
		if a&1:
			print(0,end="")
		else:
			print(1,end="")
		a+=1
	else:
		a-=1
		if a&1:
			print(0,end="")
		else:
			print(1,end="")

import java.util.Scanner;

public class Codeforces {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        input.nextLine();
        String s = input.nextLine();
        StringBuilder t = new StringBuilder();
        int num = 0;
        for (int i = 0; i < n; i++){
            int next = s.charAt(i) == '(' ? 1 : -1;
            if ((2*num + next)/2 % 2 == 0) t.append(1);
            else t.append(0);
            num += next;
        }
        System.out.println(t);
    }
}


import java.io.*;
import java.nio.CharBuffer;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class P1146D {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int m = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int[] d = new int[a + b];

        Arrays.fill(d, -1);
        d[0] = 0;
        int cur = 0, limit = 0;
        while (cur - b != 0) {
            if (cur - b > 0) {
                cur -= b;
            } else {
                limit = Integer.max(limit, cur + a);
                cur += a;
            }
            d[cur] = limit;
        }
        long ans = 0;
        if (a + b > m) {
            for (int i = 0; i <= m; ++i) {
                if (d[i] != -1 && m >= d[i]) {
                    ans += m - d[i] + 1;
                }
            }
        } else {
            for (int i = 0; i < a + b; ++i) {
                if (d[i] != -1) {
                    ans += m - d[i] + 1;
                }
            }
            // a+b ... m
            int g = gcd(a, b);
            int l = a + b;
            int r = m - m % g;
            int count = (r - l) / g + 1;
            int first = (m - l + 1);
            int last = (m - r + 1);
            ans += (long) (first + last) * count / 2;
        }
        writer.println(ans);

        writer.close();
    }

    private static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
long long m, a, b, d, x = 0;
long long repeat[100100];
long long sum(long long n) { return n * (n + 1) / 2; }
long long get(long long x, long long mod) {
  long long ans = 0;
  long long y = (x - mod) / a + 1;
  long long nxt = y * a + mod - 1;
  nxt = min(nxt, m);
  ans += (nxt - x + 1) * y;
  long long k = (m - mod) / a;
  if (k < y) return ans;
  ans += a * (sum(k) - sum(y)) + (m - k * a - mod + 1) * (k + 1);
  return ans;
}
int main() {
  cin >> m >> a >> b;
  long long initial = 0;
  memset(repeat, -1, sizeof repeat);
  while (repeat[initial % a] == -1) {
    repeat[initial % a] = x;
    while (initial < b && initial + a <= m) initial += a;
    x = max(x, initial);
    if (initial < b) break;
    initial -= b;
  }
  long long rez = 0;
  for (int i = 0; i < a; ++i)
    if (repeat[i] != -1) rez += get(repeat[i], i);
  cout << rez;
}


n, k, x = map(int, input().split())
a = [None] + list(map(int, input().split()))

lo, hi = 0, 10 ** 9 * 5000
q = [None] * (n + 1)

def get(mid):
    f, r = 0, 0
    q[0] = 0, 0, 0
    for i in range(1, n + 1):
        if q[r][2] == i - k - 1: r += 1
        cur = q[r][0] + a[i] - mid, q[r][1] + 1, i
        while r <= f and q[f] <= cur: f -= 1
        f += 1
        q[f] = cur
    if q[r][2] == n - k: r += 1
    return q[r]

while lo < hi:
    mid = (lo + hi + 1) >> 1
    _, cnt, _ = get(mid)
    if cnt >= x:
        lo = mid
    else:
        hi = mid - 1

sm, _, _ = get(lo)
ans = max(-1, sm + x * lo)
print(ans)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 70;
const int INF = 2.1e9;
const long long inf = 1e18;
const int MOD = 1e9 + 7;
int n, m, k, x;
int a[maxn];
long long dp[maxn][maxn];
int Q[maxn], front, tail;
long long solve() {
  for (int i = 1; i <= n; i++) dp[i][1] = (i > k ? -inf : a[i]);
  for (int j = 2; j <= x; j++) {
    front = tail = 0;
    Q[tail++] = 0;
    for (int i = 1; i <= n; i++) {
      while (Q[front] < i - k) front++;
      dp[i][j] = dp[Q[front]][j - 1] + a[i];
      while (front < tail && dp[Q[tail - 1]][j - 1] <= dp[i][j - 1]) tail--;
      Q[tail++] = i;
    }
  }
  if (dp[n - k + 1][x] <= 0) return -1;
  long long ans = 0;
  for (int i = n - k + 1; i <= n; i++) ans = max(ans, dp[i][x]);
  return ans;
}
int main() {
  while (cin >> n >> k >> x) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    long long ans = solve();
    cout << ans << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n, m, x, sum = 0, j = 1;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (x >= j) {
      sum += x - j;
    } else {
      sum += n - j + x;
    }
    j = x;
  }
  cout << sum << endl;
  return 0;
}

def main(n, m, lst):
    count = 0
    lst = [1] + lst
    for i in range(1, len(lst)):
        if lst[i] >= lst[i-1]:
            count += lst[i] - lst[i-1]
        else:
            count += n - lst[i-1] + lst[i]
    return count

n, m = [int(x) for x in input().split()]
lst = list(map(int, input().split()))
print(main(n, m, lst))


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  cout << n * (n - 1) * (n + 1) / 6 + n;
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long p = scanner.nextLong();
        long d = scanner.nextLong();

        String s = String.valueOf(d);

        for (int i = s.length(); i > 0; i--) {
            long r = p / ((long) Math.pow(10, i));
            long b = r * ((long) Math.pow(10, i)) + ((long) Math.pow(10, i) - 1);

            if (b > p) {
                long a = (r - 1) * ((long) Math.pow(10, i)) + ((long) Math.pow(10, i) - 1);

                if (a >= (p - d) && a <= p) {
                    System.out.println(a);
                    return;
                }
            } else {
                System.out.println(b);
                return;
            }
        }
        System.out.println(p);
    }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int mid = (m + 1) / 2;
  int cnt = 0;
  int ans[m + 1];
  if (m % 2) {
    int i = 1;
    int cnt = 1;
    int k = 1;
    ans[k++] = mid;
    while (true) {
      if (cnt > m) break;
      ans[k++] = mid - i;
      cnt++;
      if (cnt > m) break;
      ans[k++] = mid + i;
      cnt++;
      i++;
    }
  } else {
    int i = 1;
    int cnt = 0;
    int k = 1;
    while (true) {
      if (cnt > m) break;
      ans[k++] = mid - i + 1;
      cnt++;
      if (cnt > m) break;
      ans[k++] = mid + i;
      cnt++;
      i++;
    }
  }
  int k = 1;
  for (int i = (1); i <= (n); i++) {
    cout << ans[k++] << endl;
    if (k > m) k = 1;
  }
  return 0;
}

import java.util.PriorityQueue;
import java.util.Scanner;

public class two {

    public static void main(String[] args) {

        PriorityQueue<obj> q = new PriorityQueue<obj>();
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= m; i++)
            q.add(new obj(i));

        StringBuilder ans = new StringBuilder("");
        for (int i = 1; i <= n; i++) {
            obj cur = q.poll();
            ans.append(cur.index + "\n");
            cur.balls++;
            q.add(cur);
        }
        System.out.print(ans);
    }

    static double n;
    static double m;

    static class obj implements Comparable<obj> {

        int index;
        int balls;

        public obj(int index) {
            balls = 0;
            this.index = index;
        }

        @Override
        public int compareTo(obj arg0) {
            if (balls != arg0.balls)
                return balls - arg0.balls;
            else {
                double x = Math.abs((m+1) / 2.0 - index);
                double y = Math.abs((m+1) / 2.0 - arg0.index);
                if (x != y)
                    return Double.compare(x, y);
                else
                    return index - arg0.index;
            }
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
char s[35];
long long mx = -1, x, y, z, Lim = 1000000;
long long toS(int f, int l) {
  long long ln = 0;
  for (int i = f; i <= l; i++) {
    ln *= 10;
    ln += s[i] - '0';
  }
  return ln;
}
int main() {
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 0; i < 7; i++) {
    for (int j = i + 1; j < i + 8; j++) {
      for (int k = j + 1; k < j + 8; k++) {
        if (k == len - 1 && (s[0] != '0' || i == 0) &&
            (s[i + 1] != '0' || j == i + 1) &&
            (s[j + 1] != '0' || k == j + 1)) {
          x = toS(0, i);
          y = toS(i + 1, j);
          z = toS(j + 1, k);
          if (x <= Lim && y <= Lim && z <= Lim) mx = max(mx, x + y + z);
        }
      }
    }
  }
  printf("%lld\n", mx);
  return 0;
}

import java.util.Scanner;

public class RobotBicornAttack {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        long total =-1;

        int maxL =(s.length()-2 > 7)? 7 : s.length()-2 ;

        for(int i =1; i<= maxL; i++ ){

            int num1 = getMax(s.substring(0, i));
            if(num1 == -1) continue;

            for(int j=1; j <= ((s.length()-i-1 > 7) ? 7: s.length()-i-1) ; j++){
                int num2= getMax(s.substring(i,i+j));
                int num3= getMax(s.substring(i+j));
                if(num2 >= 0 && num3 >= 0){
                    if(total < num1 + num2 +num3){
                        total = num1 + num2 +num3;
                    }
                }
            }

        }

        System.out.println(total);

    }

    private static int getMax(String sub) {

        if(sub.length() > 1 && sub.charAt(0) == '0') return -1;
        if(sub.length() > 7) return -1;

        int sum =0;
        for(int i =0; i< sub.length() ; i++){
            sum*=10;
            sum +=(sub.charAt(i) - '0');

        }
        return sum> 1000000 ? -1: sum;
    }

}


import java.io.*;
import java.util.*;

public class D107{

        private BufferedReader in;
        private StringTokenizer st;
        int[]pset;
        void initSet(int size) {for(int i = 0;i<size;++i) pset[i] = i;}
        int findSet(int i){
            if(pset[i] == i) return i;
            return pset[i] = findSet(pset[i]);
        }
        void unionSet(int i,int j) {pset[findSet(i)] = findSet(j);}
        boolean isSameSet(int i,int j) {return findSet(i) == findSet(j);}
        void solve() throws IOException{

            int n = nextInt();
            int m = nextInt();
            int k = nextInt();
//          if(k > n) k = n;
            pset = new int[n];
            initSet(n);
            int []x = new int[n];
            for (int i = 0; i < x.length; i++) {
                x[i] = i;
            }
//          for (int i = 0; i < n/2; i++) {
//              unionSet(i, n-i-1);
//          }
            for (int i = 0; i+k <= n; i++) {
                int j = i;
                int end = i + k - 1;
                while(j<end) {
                    unionSet(j, end);
                    j++;
                    end--;
                }
            }
            int sets = 0;
            for (int i = 0; i < pset.length; i++) {
                if(pset[i] == i) sets++;
            }
            long ans = 1;
            long mod = 1000000007;
            for (int i = 0; i < sets; i++) {
                ans *= m;
                ans %= mod;
            }
            System.out.println(ans);
//          if(k > n){
//              System.out.println(0);
//              return;
//          }
//          long mod = 1000000007;
//          if(k == n || k == 1){
//              long ans = 1;
//              for (int i = 0; i < n/2; i++) {
//                  ans *= m;
//                  ans %= mod;
//              }
//              if(n%2 != 0) ans *= m;
//              ans %= mod;
//              System.out.println(ans);
//          }
//          else if(n%2 == 1 && k%2 == 1){
//              long ans = m*m;
//              ans %= mod;
//              System.out.println(ans);
//          }
//          else{
//              System.out.println(m);
//          }

        }

        D107() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
            eat("");
            solve();
        }

        private void eat(String str) {
            st = new StringTokenizer(str);
        }

        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                String line = in.readLine();
                if (line == null) {
                    return null;
                }
                eat(line);
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public static void main(String[] args) throws IOException {
            new D107();
        }

        int gcd(int a,int b){
            if(b>a) return gcd(b,a);
            if(b==0) return a;
            return gcd(b,a%b);
        }

}

#include <bits/stdc++.h>
using namespace std;
const long long DIVN = 1000000007;
int main(int argc, char const *argv[]) {
  int n, m, k, calc;
  long long res = 1;
  cin >> n >> m >> k;
  if (k == 1 || k > n)
    calc = n;
  else if (k < n && (!(k % 2)))
    calc = 1;
  else if (k < n && (k % 2))
    calc = 2;
  else if (k == n)
    calc = n / 2 + n % 2;
  for (int i = 0; i < calc; i++) res = (res * m) % DIVN;
  cout << res << endl;
  return 0;
}


import sys
import math

INF = -100000000
memo = dict()

def func(line, r):
    if line in memo and r in memo[line]:
        return memo[line][r]
    if len(line) == 1:
        which = line[0] == 'T'
        if r % 2 == 1:
            which = not which
        if which:
            return [INF, INF, 0, 0]
        else:
            return [1, INF, INF, INF]
    best = [INF, INF, INF, INF]
    for i in range(r + 1):
        a = func(line[:len(line) // 2], i)
        b = func(line[len(line) // 2:], r - i)
        for (j, k) in [(j, k) for j in range(4) for k in range(4)]:
            D = j < 2
            if a[j] == INF or b[k] == INF: continue
            aa = -a[j] if j % 2 else a[j]
            bb = -b[k] if k % 2 else b[k]
            d1, d2 = 0, 1
            if k < 2:
                aa = aa + bb
                if not D: d1, d2 = 2, 3
            else:
                aa = -aa + bb
                if D: d1, d2 = 2, 3
            if aa >= 0: best[d1] = max(best[d1], aa)
            if aa <= 0: best[d2] = max(best[d2], -aa)
    if not line in memo:
        memo[line] = dict()
    memo[line][r] = best
    return best

line = input().strip()
k = int(input())
ans = max(func(line, k))
if ans == INF: print("0")
else: print(ans)


#include <bits/stdc++.h>
using namespace std;
int a[10001] = {0};
int b[10001] = {0};
int s = 0;
int sn = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i] > a[i])
      s++;
    else if (b[i] < a[i])
      sn++;
  }
  if (sn == 0)
    cout << "-1" << endl;
  else
    cout << s / sn + 1 << endl;
  return 0;
}

n = int(input())
r = list(map(int,input().split()))
b = list(map(int,input().split()))
f = 0
s = 0
for i in range(n):
    if r[i] > b[i]:
        f += 1
    elif r[i] < b[i]:
        s += 1
if f == 0:
    print(-1)
else:
    print((s + f) // f)


#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long qpow(long long a, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ans;
}
int main() {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  printf("%lld", qpow(qpow(2, m) - 1, n));
  return 0;
}

'''Author- Akshit Monga'''
from sys import stdin, stdout
input = stdin.readline
mod=10**9+7
t = 1
for _ in range(t):
    n,m=map(int,input().split())
    print(pow((pow(2,m,mod)-1),n,mod))


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

a = []
b = []
for x in v:
  a.append(x) if x & 1 else b.append(x)

print(min(len(a), len(b)))

#include <bits/stdc++.h>
int ODD;
int EVEN;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x & 1)
      ODD++;
    else
      EVEN++;
  }
  printf("%d", (ODD < EVEN) ? ODD : EVEN);
  return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int LIM = 1000010;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans += abs(x);
  }
  cout << ans << endl;
}

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(n):
	if a[i] > 0:
		res += a[i]
	else:
		res -= a[i]
print(res)


rpta = []

def solve(pos, sum, arr):
    # if len(rpta) > 30:
    #     return
    # # print(sum)
    if sum > 10 or pos >= 9:
        return
    else:
        if sum == 10:
            # print(sum, arr)
            rpta.append(arr)
        inicio = 0 if pos > 0 else 1
        for i in range(inicio, min(10,10-sum+1) ):
            solve(pos + 1, sum + i, arr * 10 + i)

k = input()
solve(0, 0, 0)
# print(len(rpta))
rpta.sort()
# for i in range(0,len(rpta)):
#     print(i , rpta[i])
# print(rpta)
print(rpta[int(k)-1])

import java.util.*;
import java.io.*;

public class Main {
	static int cal(int num) {
		int ans = 0;
		while (num > 0){
			ans += num % 10;
			num /= 10;
		}
		return ans;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
	    while(n > 0) {
	     ans++;
	    	if(cal(ans) == 10) n--;
	    }
	    System.out.println(ans);
	}
}


t = int(input())
for i in range(t):
    n = int(input())
    if n in [1, 2, 3, 5, 7, 11]:
        print(-1)
    else:
        print((n // 4) - (n % 2))

// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Solution
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader Sc =new FastReader();
		int q = Sc.nextInt();
		for (int i = 0;i < q ;i ++) {
			int n = Sc.nextInt();
			if (n == 11 || n == 2) {
				System.out.println(-1);
				continue;
			}
			if (n % 2 == 1) {
				if (n < 9) System.out.println(-1);
				else System.out.println((n - 9) / 4 + 1);
			} else {
				System.out.println(n / 4);
			}
		}
    }
}


import java.io.*;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            String filename = "";
            if (filename.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(filename + ".in"));
                out = new PrintWriter(filename + ".out");
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int[] p;

    int find(int x) {
        if (x == p[x]) return x;
        return p[x] = find(p[x]);
    }

    void solve() throws IOException {
        int n = readInt();
        p = new int[n];
        for (int i = 0; i < n; i++) p[i] = i;
        int m = readInt();
        if (m != n - 1) {
            out.println("no");
            return;
        }
        while (m --> 0) {
            int x = readInt() - 1;
            int y = readInt() - 1;
            x = find(x);
            y = find(y);
            if (x == y) {
                out.println("no");
                return;
            }
            p[x] = y;
        }
        out.println("yes");

    }

}

no no no no no no no no no no no no yes no no no yes no no no yes no no no no yes no no no no no no no no yes no no no no no

import sys
sys.setrecursionlimit(1000000)
def dfs(v, pr):
    global used
    global p
    global f
    if not f:
        return None
    if used[v]:
        f = False
    used[v] = True
    for i in range(len(p[v])):
        if p[v][i] != pr:
            dfs(p[v][i], v)
n, m = map(int, input().split())
p = []
for i in range(n):
    p.append([])
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    p[a].append(b)
    p[b].append(a)
used = [False] * n
f = True
for i in range(n):
    if i != 0 and not used[i]:
        f = False
        break
    if not used[i]:
        dfs(i, -1)
if f:
    print('yes')
else:
    print('no')


import java.util.Scanner;

public class UltraFastMathematician {

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s1=sc.next();
    String s2=sc.next();
    String s="";
    for (int i = 0; i < s1.length(); i++) {
        char c1=s1.charAt(i);
        char c2=s2.charAt(i);
        if((c1=='0' && c2=='1') ||(c2=='0' && c1=='1'))
            s+="1";
        else
            s+="0";
    }
    System.out.println(s);

    }

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  string n1, n2;
  cin >> n1 >> n2;
  for (int i = 0; i < n1.length(); i++) {
    if (n1[i] == n2[i])
      cout << 0;
    else
      cout << 1;
  }
  return 0;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CNearestVectors solver = new CNearestVectors();
        solver.solve(1, in, out);
        out.close();
    }

    static class CNearestVectors {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Point> up = new ArrayList<>();
            ArrayList<Point> lw = new ArrayList<>();
            Point ref = new Point(1, 0);
            for (int i = 0; i < n; i++) {
                Point P = new Point(in.nextInt(), in.nextInt());
                P.ind = i + 1;
                long cr = ref.cross(P);
                long dt = ref.dot(P);
                if (cr == 0 && dt >= 0) {
                    up.add(P);
                } else if (cr == 0 && dt < 0) {
                    lw.add(P);
                } else if (cr > 0) {
                    up.add(P);
                } else if (cr < 0) {
                    lw.add(P);
                }
            }
            Collections.sort(up, new Comparator<Point>() {

                public int compare(Point o1, Point o2) {
                    return o2.ccw(o1);
                }
            });
            Collections.sort(lw, new Comparator<Point>() {

                public int compare(Point o1, Point o2) {
                    return o2.ccw(o1);
                }
            });
            ArrayList<Point> All = new ArrayList<>();
            for (Point ele : up) {
                All.add(ele);
            }
            for (Point ele : lw) {
                All.add(ele);
            }

            int i1 = 0;
            int i2 = 1;
            BigInteger mina = BigInteger.valueOf(-100);
            BigInteger minb = BigInteger.valueOf(1);
            for (int i = 0; i < n; i++) {

                BigInteger x1 = (BigInteger.valueOf(All.get(i).x));
                BigInteger y1 = BigInteger.valueOf(All.get(i).y);
                BigInteger x2 = BigInteger.valueOf(All.get((i + 1) % n).x);
                BigInteger y2 = BigInteger.valueOf(All.get((i + 1) % n).y);
                BigInteger dot = x1.multiply(x2).add(y1.multiply(y2));
                int s = (dot.compareTo(BigInteger.valueOf(0)) < 0) ? -1 : 1;
                BigInteger numer = dot.multiply(dot).multiply(BigInteger.valueOf(s));
                BigInteger denom = BigInteger.valueOf(All.get((i + 1) % n).abs()).multiply(BigInteger.valueOf(All.get(i).abs()));

                if (comp(numer, denom, mina, minb)) {
                    mina = numer;
                    minb = denom;
                    i2 = All.get((i + 1) % n).ind;
                    i1 = All.get(i).ind;
                }
            }

            out.println(i1 + " " + i2);
        }

        boolean comp(BigInteger a1, BigInteger b1, BigInteger a2, BigInteger b2) {
            return (a1.multiply(b2).subtract(a2.multiply(b1)).compareTo((BigInteger.valueOf(0))) > 0);
        }

        class Point {
            long x;
            long y;
            int ind;

            Point(long x1, long y1) {
                x = x1;
                y = y1;
            }

            long dot(Point a) {
                return x * a.x + y * a.y;
            }

            long cross(Point a) {
                return x * a.y - y * a.x;
            }

            long abs() {
                return dot(this);
            }

            int ccw(Point a) {
                return (int) Math.signum(cross(a));
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

#include <bits/stdc++.h>
using namespace std;
vector<pair<long double, int> > x;
const long double PI = 2 * acosl(0);
int main() {
  int(n);
  scanf("%d", &n);
  int A, B;
  for (int i = (0); i < (n); ++i) {
    int A, B;
    scanf("%d%d", &A, &B);
    x.push_back(make_pair(atan2l(B, A), i));
  }
  sort((x).begin(), (x).end());
  x.push_back(make_pair(PI * 2 + x[0].first, x[0].second));
  int ansxi;
  long double O = INFINITY;
  for (int i = (0); i < (n); ++i) {
    long double di = x[i + 1].first - x[i].first;
    if (di < 0) di = -di;
    if (di < O) {
      O = di;
      ansxi = i;
    }
  }
  cout << x[ansxi].second + 1 << ' ' << x[ansxi + 1].second + 1 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int fac[2000010], a[2000010];
const int mod = 1000000007;
int ans = 0;
int fpow(int i, int j) {
  int ret;
  if (j == 0) return 1;
  ret = fpow(i, j / 2);
  ret = (long long)ret * ret % mod;
  if (j % 2 == 1) ret = (long long)ret * i % mod;
  return ret;
}
int inv(int i) {
  if (a[i] != 0)
    return a[i];
  else {
    a[i] = fpow(fac[i], mod - 2);
    return a[i];
  }
}
int calc(int i, int j) {
  int ret;
  ret = (long long)fac[i] * inv(j) % mod * inv(i - j) % mod;
  return ret;
}
int main() {
  int i, j, s = 0;
  fac[0] = 1;
  for (i = 1; i <= 2000000; i++) fac[i] = (long long)fac[i - 1] * i % mod;
  scanf("%d", &n);
  ans = ((long long)fpow(2, n + 1) - 1 + mod) % mod;
  ans %= mod;
  s = fpow(2, n);
  a[n] = fpow(fac[n], mod - 2);
  for (i = n + 1; i <= 2 * n; i++) {
    s = ((long long)s * 2 - calc(i - 1, n) - calc(i - 1, i - 1 - n)) % mod;
    ans = ((long long)ans + s + mod) % mod;
  }
  cout << ans << endl;
  return 0;
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Bots {
    static long mod = 1000000007;
    public static void main(String[] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int MAX = 2000010;

        long[] fact = new long[MAX];
        long[] inv = new long[MAX/2];

        fact[0] = 1l;
        for(int i=1; i<fact.length; i++){
            fact[i] = (fact[i-1]*i)%mod;
        }
        for(int i=0; i<inv.length; i++){
            inv[i] = fastPow(fact[i], (int)(mod-2));
        }
//      System.out.println(fact[2*n+2]+" "+inv[n+1]);
//      System.out.println(inv[20]);
        long ans = ((((fact[2*n+2]*inv[n+1])%mod) *inv[n+1])+mod-1)%mod;

        System.out.println( ans);
    }

    public static long fastPow(long n, int exp){
        if(exp == 0)
            return 1;
        long ans = fastPow(n, exp/2);
        ans = (ans*ans)%mod;
        if(exp%2!=0)
            ans=(ans*n)%mod;
        return ans;
    }

}


x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
arr = []
for _ in range(n):
	a, b, c = map(int, input().split())
	arr.append((a,b,c))
res = 0
for i in arr:
	a, b, c = i
	if(b != 0):
		y00 = -c/b
		y01 = -(a+c)/b
		s1 = x1*(y01-y00)-(y1-y00)
		s2 = x2*(y01-y00)-(y2-y00)
		if(s1<0<s2 or s1>0>s2):
			res += 1
	else:
		x = -c/a
		if(x1<x<x2 or x1>x>x2):
			res += 1
print(res)

import java.util.Scanner;

public class T499C {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int i,n,res=0;
		long A,B,C,x1,y1,x2,y2,res1,res2;
		x1=in.nextLong();
		y1=in.nextLong();
		x2=in.nextLong();
		y2=in.nextLong();
		n=in.nextInt();
		long[]a=new long[n],b=new long[n],c=new long[n];
		for(i=0;i<n;i++){
			a[i]=in.nextLong();
			b[i]=in.nextLong();
			c[i]=in.nextLong();
		}
		in.close();;
		for(i=0;i<n;i++){
			res1=a[i]*x1+b[i]*y1+c[i];
			res2=a[i]*x2+b[i]*y2+c[i];
			if(Long.signum(res1)!=Long.signum(res2))
				res++;
		}
		System.out.println(res);
	}
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
double a[N];
int main() {
  int m, r;
  scanf("%d %d", &m, &r);
  double ans = 0;
  a[0] = 2 * r, a[1] = (2 + sqrt(2)) * r, a[2] = (2 + 2 * sqrt(2)) * r;
  for (int i = 3; i < m; i++) {
    a[i] = a[i - 1] + 2 * r;
  }
  ans = a[0] * m;
  for (int i = 1; i < m; i++) {
    ans = ans + a[i] * (m - i) * 2;
  }
  ans = ans / m / m;
  printf("%.10lf\n", ans);
  return 0;
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int R = scanner.nextInt();

        double sum = 0;
        double sqrt2 = Math.sqrt(2);

        for (int i = 0; i < m; i++) {
            //distance to circle above
            sum += 2;
            //distance to the circle near
            if (i > 0) {
                sum += (2+sqrt2);
            }
            if (i + 1 < m) {
                sum += (2+sqrt2);
            }
            //distance to the circles more than 2 steps further
            if (i > 0) {
                double v = (i-1);
                sum += v*(v+1);
                sum += 2*sqrt2*v;
            }
            if (i+1 < m) {
                double v = (m-i-2);
                sum += v*(v+1);
                sum += 2*sqrt2*v;
            }
        }

        System.out.println(sum * R / m / m);
    }
}


import java.util.Scanner;

public class Prob216B {

	public static void main(String[] Args) {
		Scanner in = new Scanner(System.in);
		int students = in.nextInt();
		int pairs = in.nextInt();

		int[][] arch = new int[students][3];
		for (int i = 0; i < students; i++)
			arch[i] = new int[] { 0, -1, -1 };

		for (int i = 0; i < pairs; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			arch[a][++arch[a][0]] = b;
			arch[b][++arch[b][0]] = a;
		}

		int answer = 0;
		boolean[] visited = new boolean[students];
		for (int i = 0; i < students; i++)
			if (!visited[i] && arch[i][0] == 2) {
				int ar1 = arch[i][1];
				int ar2 = arch[i][2];

				// odd ring
				int nodesInARing = 2;
				boolean ok = true;
				int prev = i;

				while (true) {
					nodesInARing++;

					if (arch[ar1][0] != 2) {
						ok = false;
						break;
					}

					if (arch[ar1][1] + arch[ar1][2] - prev != ar2) {
						int temp = ar1;
						ar1 = arch[ar1][1] + arch[ar1][2] - prev;
						prev = temp;
					} else {
						break;
					}
				}

				if (ok && nodesInARing % 2 == 1) {
					answer++;
					ar1 = arch[i][1];
					prev = i;
					while (!visited[ar1]) {
						visited[ar1] = true;
						int temp = ar1;
						ar1 = arch[ar1][1] + arch[ar1][2] - prev;
						prev = temp;
					}
				}
				visited[i] = true;
			}

		if ((students - answer) % 2 == 0)
			System.out.println(answer);
		else
			System.out.println(answer + 1);
	}
}

#include <bits/stdc++.h>
using namespace std;
int N, M;
int p[101];
int e[101];
int res = 0;
int FindSet(int x);
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) p[i] = i, e[i] = 1;
  int x, y;
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &x, &y);
    int px = FindSet(x), py = FindSet(y);
    if ((px == py) && (e[py] & 1)) res++;
    p[px] = p[y];
    e[py] += e[px];
  }
  if ((N - res) % 2 != 0) res++;
  cout << res;
  return 0;
}
int FindSet(int x) {
  if (x != p[x]) return FindSet(p[x]);
  return x;
}


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		if (args.length > 0 && args[0].toLowerCase().equals("local")) {
			try {
				System.setIn(new FileInputStream("input.txt"));
				System.setOut(new PrintStream(new File("output.txt")));
			} catch (IOException exc) {
			}
		}
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;
		static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		public void solve() {
			try {
				Scan sc = new Scan();
				int n = (int) sc.scanLong();
				int[] arr = new int[n];
				int mx = 0;
				for (int i = 0; i < n; ++i) {
					arr[i] = (int) sc.scanLong();
					mx = Math.max(mx, arr[i]);
				}
				int orig = mx;
				while (mx-- > 0) {
					for (int i = 0; i < n; ++i) {
						if (arr[i] > 0)
							--arr[i];
						if (i == 0 || i == n - 1) {
							if (arr[i] == 0) {
								out.println(orig-mx);
								return;
							}
						}
						if (i > 0 && arr[i] == arr[i - 1] && arr[i] == 0){
							out.println(orig-mx);
							return;
						}
					}
				}
				out.println(orig - mx);
			} finally {
				out.close();
			}
		}

		private void debug(Object... x) {
			StringBuilder sb = new StringBuilder();
			for (Object o : x)
				sb.append(String.valueOf(o)).append(" ");
			out.println(sb);
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e3 + 10, INF = 1e18;
int T, c_;
long long int n, a[N], visited[N];
bool check(int days) {
  int i = 0;
  while (i < n) {
    if (a[i] < days) {
      return false;
    }
    if (i + 2 < n && a[i + 2] >= days)
      i += 2;
    else if (i + 1 < n && a[i + 1] >= days)
      i++;
    else
      break;
  }
  return i == n - 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int low = 0, hi = 1e3 + 5;
  while (hi - low > 1) {
    int mid = (hi + low) / 2;
    if (check(mid)) {
      low = mid;
    } else
      hi = mid;
  }
  cout << low;
}


n = int(input())

phone = []

for i in range(n):
    s = input().strip()
    phone.append(s)

c = 0
k = 0
flag = True
while True:
    for p in phone:
        if p[k] != phone[0][k]:
            flag = False
            break
    k += 1

    if flag:
        c += 1
    else:
        print(c)
        break

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n + 10000];
  vector<int> v;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < s[0].size(); ++i) {
    int j = 0;
    int ans = 1;
    while (j <= n - 1) {
      if (s[j][i] == s[j + 1][i]) ++ans;
      ++j;
    }
    if (ans == n) v.push_back(i);
  }
  int c = 0;
  int mx = -1;
  if (v.size()) ++c;
  for (int i = 1; i < v.size(); ++i) {
    if (v[i] - v[i - 1] == 1)
      ++c;
    else {
      mx = max(mx, c);
      c = 1;
    }
  }
  if (mx == 1) mx = 0;
  if (mx == -1) mx = v.size();
  cout << mx;
}


YES YES NO YES YES NO YES YES YES NO YES NO YES YES YES YES YES NO YES NO YES NO YES YES NO YES YES YES YES YES YES NO YES YES YES NO YES YES YES YES YES YES YES YES YES NO YES YES NO NO NO

import java.io.*;
import java.util.*;

public class Main {
    static int inf = (int) (1e9 + 7);

    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int a[] = new int [4];
        for(int i = 0;i < 4;i++) a[i] = sc.nextInt();
        Arrays.sort(a);

        boolean good = false;
        if (a[0] + a[2] == a[1] + a[3]) good = true;
        if (a[0] + a[3] == a[1] + a[2]) good = true;
        if (a[0] + a[1] + a[2] == a[3]) good = true;
        pw.println(good ? "YES" : "NO");
        pw.close();
    }

    static Scanner sc;
    static PrintWriter pw;

    static class Scanner {
        BufferedReader br;
        StringTokenizer st = new StringTokenizer("");

        Scanner(InputStream in) throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        Scanner(String in) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(in));
        }

        String next() throws IOException {
            while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }

}


#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932238460;
int main() {
  int n;
  cin >> n;
  vector<int> num;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    num.push_back(k);
  }
  int cost = 0;
  int minCost = 100000;
  int mint;
  for (int i = 1; i < 101; i++) {
    for (int j = 0; j < n; j++) {
      if (abs(i - num[j]) > 0)
        cost += abs(i - num[j]) - 1;
      else
        cost += abs(i - num[j]);
    }
    if (cost < minCost) minCost = cost, mint = i;
    cost = 0;
  }
  cout << mint << " " << minCost << "\n";
}

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

mincost = 1000 * 100 + 1
best_t = None
for t in range(1, 101):
    cost = 0
    for x in a:
        cost += max(0, abs(x - t) - 1)
    if cost < mincost:
        mincost = cost
        best_t = t

print(best_t, mincost)


#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int i;
  for (i = 0; i < n; i++) {
    if (a[i] <= k) {
      sum++;
    } else {
      break;
    }
  }
  if (i == n) {
    printf("%d\n", sum);
    return 0;
  }
  for (i = n - 1; i >= 0; i--) {
    if (a[i] <= k) {
      sum++;
    } else {
      break;
    }
  }
  printf("%d\n", sum);
  return 0;
}

n, k =map(int, input().split())
a=list(map(int, input().split()))
i=s=0

while i<n:
	if a[i]<=k:
		s+=1
		i+=1
	else:
		if a[n-1]<=k:
			s+=1
			n-=1
		else:
			break
print(s)