import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
//import java.lang.Math;

public class Exercise {
    public static void main(String[] args) {

        // А - покупка воды

        Scanner input = new Scanner(System.in);
        int q = input.nextInt();
        ArrayList<Long> sums = new ArrayList<>();
        for (int i = 0; i < q; ++i) {
            long sum;
            long n = input.nextLong();
            int a = input.nextInt();
            int b = input.nextInt();
            if (b / 2 < a) {
                sum = (n - (n % 2)) / 2 * b + (n % 2) * a;
            } else {
                sum = n * a;
            }
            sums.add(sum);
        }
        for (long i : sums) {
            System.out.println(i);
        }

        // B - эмоции

//        Scanner input = new Scanner(System.in);
//        int n = input.nextInt();
//        int m = input.nextInt();
//        int k = input.nextInt();
//        ArrayList<Integer> arr = new ArrayList<>();
//        for (int i = 0; i < n; ++i) {
//            arr.add(input.nextInt());
//        }
//        Collections.sort(arr);
//        long happiness;
//        long max = arr.get(arr.size() - 1);
//        long premax = arr.get(arr.size() - 2);
//        happiness = m / (k + 1) * (k * max + premax) + (m % (k + 1)) * max;
//        System.out.println(happiness);

        // А - лучший подотрезок

//        Scanner input = new Scanner(System.in);
//        int n = input.nextInt();
//        ArrayList<Integer> arr = new ArrayList<>();
//        for (int i = 0; i < n; ++i) {
//            arr.add(input.nextInt());
//        }
//        int maxEl = -1;
//        for (int i : arr) {
//            if (i > maxEl) maxEl = i;
//        }
//        int max = 1;
//        int j;
//        for (int i = 0; i < arr.size(); i += j) {
//            j = 1;
//            if (arr.get(i) == maxEl) {
//                while (i + j < arr.size() && arr.get(i + j) == maxEl) {
//                    if (++j > max) max = j;
//                }
//            }
//        }
//        System.out.println(max);

        //  ЗАДАЧА С ПОИСКОМ ПО МАССИВУ

//        Scanner input = new Scanner(System.in);
//        int n = input.nextInt();
//        ArrayList<Integer> arr = new ArrayList<>();
//        for (int i = 0; i < n; ++i) {
//            arr.add(input.nextInt());
//        }
//        Collections.sort(arr);
//        //System.out.println(arr);
//        int k = input.nextInt();
//        ArrayList<Integer> res = new ArrayList<>();
//        for (int i = 0; i < k; ++i) {
//            int min = input.nextInt();
//            int max = input.nextInt();
//            int lBound = -1;
//            int rBound = arr.size();
//            while (rBound - lBound > 1) {
//                int middle = (rBound + lBound) / 2;
//                if (arr.get(middle) >= min) {
//                    rBound = middle;
//                    if (middle != 0 && arr.get(middle - 1) < min) {
//                        lBound = middle - 1;
//                        break;
//                    }
//                } else {
//                    lBound = middle;
//                }
//            }
//            int minI = lBound;
//            lBound = -1;
//            rBound = arr.size();
//            while (rBound - lBound > 1) {
//                int middle = (rBound + lBound) / 2;
//                if (arr.get(middle) <= max) {
//                    lBound = middle;
//                    if (middle != arr.size() - 1 && arr.get(middle + 1) > max) {
//                        rBound = middle + 1;
//                        break;
//                    }
//                } else {
//                    rBound = middle;
//                }
//            }
//            int maxI = rBound;
//            res.add(maxI - minI - 1);
//        }
//        for (int i : res) {
//            System.out.print(i + " ");
//        }

        // ЗАДАЧА С КРОТОМ

//        Scanner input = new Scanner(System.in);
//        int n = input.nextInt();
//        ArrayList worms = new ArrayList();
//        worms.add(input.nextInt());
//        for (int i = 1; i < n; ++i) {
//            int a = input.nextInt();
//            worms.add((int)worms.get(i - 1) + a);
//        }
//        //System.out.println(worms);
//        int k = input.nextInt();
//        ArrayList res = new ArrayList();
//        for(int i = 0; i < k; ++i) {
//            int delic = input.nextInt();
//            int lBound = 0;
//            int rBound = worms.size();
//            while(rBound - lBound > 1) {
//                int middle = (rBound + lBound) / 2;
//                if ((int)worms.get(middle) >= delic) {
//                    if ((int)worms.get(middle - 1) < delic) {
//                        lBound = middle;
//                        break;
//                    } else {
//                        rBound = middle;
//                    }
//                } else {
//                    lBound = middle;
//                }
//            }
//            res.add(lBound + 1);
//        }
//        for (int i = 0; i < res.size(); ++i) {
//            System.out.print(res.get(i) + " ");
//        }

        //ЗАДАЧА С Х А И В

//        Scanner input = new Scanner(System.in);
//        int x = input.nextInt();
//        boolean found = false;
//        for (int b = 1; b <= x; b++) {
//            for(int a = 1; a <= x; a++) {
//                if(a % b == 0 && a * b > x && a / b < x) {
//                    found = true;
//                    System.out.println(a + " " + b);
//                    break;
//                }
//                if(found) break;
//            }
//        }
//        if (!found) {
//            System.out.println(-1);
//        }

        // ЗАДАЧА ПРО ОТРЕЗКИ

//        Scanner input = new Scanner(System.in);
//        int q = input.nextInt();
//        ArrayList first = new ArrayList();
//        ArrayList sec = new ArrayList();
//        for (int i = 0; i < q; ++i) {
//            int l1 = input.nextInt();
//            int r1 = input.nextInt();
//            int l2 = input.nextInt();
//            int r2 = input.nextInt();
//            if (l1 != l2) {
//                first.add(l1);
//                sec.add(l2);
//            } else if (r1 != r2) {
//                first.add(r1);
//                sec.add(r2);
//            } else {
//                first.add(l1);
//                sec.add(r1);
//            }
//        }
//        for (int i = 0; i < q; ++i) {
//            System.out.println(first.get(i) + " " + sec.get(i));
//        }

        //ЗАДАЧА ПРО ЧЕТНОСТЬ

//        Scanner input = new Scanner(System.in);
//        int b = input.nextInt();
//        int k = input.nextInt();
//        int sum = 0;
//        for (int i = 0; i < k; ++i) {
//            int a = input.nextInt();
//            if (i == k - 1) {
//                if (a % 2 != 0) {
//                    sum += 1;
//                }
//            } else {
//                if (b % 2 != 0 && a % 2 != 0) {
//                    sum += 1;
//                }
//            }
//        }
//        if (sum % 2 == 0) {
//            System.out.println("even");
//        } else {
//            System.out.println("odd");
//        }

//        ЗАДАЧА ПРО ТРАНСФОРМАЦИЮ СУПЕРГЕРОЕВ))0

//        Scanner input = new Scanner(System.in);
//        String hero1 = input.nextLine();
//        String hero2 = input.nextLine();
//
//        if (hero1.length() != hero2.length()) {
//            System.out.println("No");
//        } else {
//            boolean check = true;
//            for(int i = 0; i < hero1.length(); i++) {
//                boolean a1 = false;
//                boolean a2 = false;
//                if (hero1.charAt(i) == 'a' || hero1.charAt(i) == 'i' || hero1.charAt(i) == 'o' ||
//                hero1.charAt(i) == 'u' || hero1.charAt(i) == 'e') {
//                    a1 = true;
//                }
//                if (hero2.charAt(i) == 'a' || hero2.charAt(i) == 'i' || hero2.charAt(i) == 'o' ||
//                        hero2.charAt(i) == 'u' || hero2.charAt(i) == 'e') {
//                    a2 = true;
//                }
//                if (a1 != a2) {
//                    System.out.println("No");
//                    check = false;
//                    break;
//                }
//            }
//            if (check) {
//                System.out.println("Yes");
//            }
//        }

//        ArrayList array = new ArrayList();
//        for (int i = 0; i < 5; i++) {
//            array.add(sth.split(" ")[i]);
//        }
//        System.out.println(array);
    }
}

// List<Integer> x = new ArrayList();

q=int(input())
for i in range(q):
    n,a,b=map(int,input().split())
    b=min(b,2*a)
    if(n%2==1):
        print(((n//2)*b)+a)
    else:
        print((n//2)*b)


import java.util.*;

public class helloWorld
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		String ans = "YES";
		int h = 1000000000;
		for(int i = 0; i < n; i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			if(a > b) {
				int temp = a;
				a = b;
				b = temp;
			}
			if(b <= h)
				h = b;
			else if(a <= h)
				h = a;
			else {
				ans = "NO";
				break;
			}
		}

		System.out.println(ans);

		in.close();
	}
}

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

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const double PI = 3.14159;
vector<int> v;
long long n, m, k, t, sum, r, l, d, a, b, c;
long long ans;
map<int, int> mp;
string s;
bool f;
set<long long> st;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  int prv = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (!i)
      prv = max(x, y);
    else {
      if (prv >= x && prv >= y)
        prv = max(x, y);
      else if (prv >= x)
        prv = x;
      else if (prv >= y)
        prv = y;
      else {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}


n, k, x = map(int, input().split())
a = [int(x) for x in input().split()]
res = k*x
n-=k
res+=sum(a[:n])
print(res)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, time = 0, element;
  cin >> n >> k >> x;
  for (int i = 0; i < (n - k); i++) {
    cin >> element;
    time += element;
  }
  for (int i = 0; i < k; i++) {
    cin >> element;
  }
  time = time + (x * k);
  cout << time << endl;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] ch = new char[10000001];
            Arrays.fill(ch, 'a');
            int maxIndex = 0;
            for (int i = 0; i < n; i++) {
                String s = in.next();
                int l = s.length();
                int lastIndex = 0;
                int sn = in.nextInt();
                for (int j = 0; j < sn; j++) {
                    int p = in.nextInt();
                    for (int k = Math.max(lastIndex, p) - p; k < l; k++) {//out.println("here "+j);
                        ch[k + p] = s.charAt(k);
                    }
                    lastIndex = p + l;
                    maxIndex = Math.max(maxIndex, p + l);
                }
            }
            out.println(new String(ch, 1, maxIndex - 1));
        }

    }
}

10
dabacabafa 1 24
bacabadab 1 18
dabaca 1 8
bacabaea 1 42
bacaba 1 34
abadabaca 1 5
badabacaba 1 54
bacabaeaba 1 10
abacabaeab 1 9
adabacaba 1 23

6
ba 2 16 18
a 1 12
b 3 4 13 20
bb 2 6 8
ababbbbbaab 1 3
abababbbbb 1 1

17
a 4 2 7 8 9
bbaa 1 5
ba 2 1 6
aa 2 7 8
b 6 1 3 4 5 6 10
bbbaa 1 4
bbba 1 4
bab 1 1
bba 1 5
bbb 2 3 4
bb 3 3 4 5
ab 1 2
abbb 1 2
bbbb 1 3
abb 1 2
abbbba 1 2
bbbbaaa 1 3

9
fab 1 32
b 2 38 54
badab 1 38
ba 1 62
a 1 25
ab 1 37
bacaba 1 26
cabaeab 1 12
acab 1 3

#include <bits/stdc++.h>
using namespace std;
char c[2000100];
int p[2000100];
int get(int a) {
  if (p[a] == a) return a;
  return p[a] = get(p[a]);
}
void unite(int a, int b) { p[a] = b; }
void add(string &s, int a) {
  int k = get(a);
  while (true) {
    if (k - a + 1 > s.size()) break;
    c[k] = s[k - a];
    unite(k, k + 1);
    k = get(a);
  }
}
int main() {
  int n, i, k, a, j, m = 0;
  string s;
  cin >> n;
  for (i = 1; i <= 2000000; ++i) {
    c[i] = '#';
    p[i] = i;
  }
  for (i = 0; i < n; ++i) {
    cin >> s >> k;
    for (j = 0; j < k; ++j) {
      cin >> a;
      m = max(m, (int)s.size() + a - 1);
      add(s, a);
    }
  }
  for (i = 1; i <= m; ++i) {
    if (c[i] == '#') c[i] = 'a';
    cout << c[i];
  }
  return 0;
}


NumOfSocks = int(input())
Socks = [int(x) for x in input().split()]
OnTable, maxSocks, tmpMaxSocks = [0] * (NumOfSocks+1), 0, 0
for i in Socks:
    if not OnTable[i]:
        OnTable[i] = 1
        tmpMaxSocks += 1
    else:
        OnTable[i] = 0
        tmpMaxSocks -= 1
    if tmpMaxSocks > maxSocks: maxSocks = tmpMaxSocks
print(maxSocks)

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Andryusha_and_Socks {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt()*2;

        Set<Integer> set = new HashSet<>();

        int maxSize = set.size();
        while(n-- >= 1)
        {
            int x = sc.nextInt();
            if( set.contains(x) )
            {
                set.remove(x);
            }
            else
            {
                set.add(x);
            }

            if( set.size() > maxSize )
                maxSize = set.size();
        }
        System.out.println( maxSize );
    }

}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

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

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

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

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


#include <bits/stdc++.h>
int sx, sy, tx, ty, ans;
int main() {
  scanf("%d%d\n%d%d", &sx, &sy, &tx, &ty);
  ans = std::max(abs(sx - tx), abs(sy - ty));
  printf("%d\n", ans);
}

x2,y2=map(int,input().split())
x1,y1=map(int,input().split())

m=min(abs(x1-x2),abs(y2-y1) )
d=max(abs(x1-x2),abs(y2-y1) )
ans = m+d-m
print(ans )


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main1 {
    public static void main(String args[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int m=Integer.parseInt(st.nextToken());
        st=new StringTokenizer(br.readLine());
        StringTokenizer st1=new StringTokenizer(br.readLine());
        int f[]=new int[n+1];
        boolean amb=false,emp=false;
        for(int i=1;i<=n;i++)
        {
            int t=Integer.parseInt(st.nextToken());
            if(f[t]!=0)
            {
                f[t]=-1;
            }
            else f[t]=i;
        }
        int b[]=new int[m];
        for(int i=0;i<m;i++)
            b[i]=Integer.parseInt(st1.nextToken());
        int a[]=new int[m];
        for(int i=0;i<m;i++)
        {
            if(f[b[i]]==0)
            {
                emp=true;
            }
            else if(f[b[i]]==-1)
                amb=true;
            else a[i]=f[b[i]];
        }
        if(emp)
        {
            System.out.print("Impossible");
            return;
        }
        else if(amb)
        {
            System.out.print("Ambiguity");
            return;
        }
        System.out.println("Possible");
        for(int i=0;i<m;i++)
            System.out.print(a[i]+" ");
    }
}

read = lambda: map(int, input().split())
n, m = read()
f = list(read())
b = list(read())
c = [list() for i in range(n + 1)]
for i in range(n):
    c[f[i]].append(i + 1)
a = [0] * m
ans = 'Possible'
for i in range(m):
    if len(c[b[i]]) == 0:
        print('Impossible')
        exit()
    if len(c[b[i]]) > 1:
        ans = 'Ambiguity'
    if len(c[b[i]]) == 1:
        a[i] = c[b[i]][0]
print(ans)
if ans != 'Ambiguity':
    print(*a)


#include <bits/stdc++.h>
using namespace std;
int n, q, k, a[60005], p, P;
bool u[20000005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    u[a[i]] = 1;
  }
  scanf("%d", &q);
  while (q--) {
    int c, ans = 100;
    scanf("%d", &c);
    for (int x = 0; x <= k; ++x) {
      for (int y = 0; y <= k - x; ++y) {
        for (int i = 1; i <= n; ++i) {
          p = c - a[i] * x;
          if (p < 0) continue;
          if (p == 0)
            ans = min(ans, x + y);
          else {
            if (y != 0 && p % y == 0) {
              P = p / y;
              if (P <= a[n] && u[P]) ans = min(ans, x + y);
            }
          }
        }
      }
    }
    if (ans == 100)
      puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}

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

public class Main implements Runnable {
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    static void solve() throws Exception {
        int n = nextInt();
        int k = nextInt();
        int[] a = new int[n];
        boolean[] used = new boolean[(int)1e7 + 1];
        for (int i = 0; i < n; ++i) {
            a[i] = nextInt();
            used[a[i]] = true;
        }
        int q = nextInt();
        for (int qq = 0; qq < q; ++qq) {
            int x = nextInt();
            int res = Integer.MAX_VALUE;
            for (int i = 0; i < n; ++i) {
                int sum = 0;
                for (int j = 1; j <= k; ++j) {
                    sum += a[i];
                    if (sum == x) {
                        res = Math.min(j, res);
                    }
                    if (sum < x) {
                        for (int d = 1; d <= k - j; ++d) {
                            if ((x - sum) % d == 0) {
                                if ((x - sum) / d <= (int)1e7 && used[(x - sum) / d]) {
                                    res = Math.min(j + d, res);
                                }
                            }
                        }
                    }
                }
            }
            out.println(res == Integer.MAX_VALUE ? "-1" : res);
        }
    }

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

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

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

    static BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

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

    static String nextLine() throws IOException {
        tok = new StringTokenizer("");
        return in.readLine();
    }

    static boolean hasNext() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null) {
                return false;
            }
            tok = new StringTokenizer(s);
        }
        return true;
    }

    public static void main(String args[]) {
        new Thread(null, new Main(), "Main", 1 << 28).start();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            //in = new BufferedReader(new FileReader("input.in"));
            //out = new PrintWriter(new FileWriter("output.out"));
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            java.lang.System.exit(1);
        }
    }
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author madis
 */
public class Rasstanovka {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if (n == 1) {
            System.out.println("1");
        } else if (n == 2) {
            System.out.println("2 1");
        } else {
            for (int i = 1; i < n; i++) {
                System.out.print(i + 1);
                System.out.print(" ");
            }
            System.out.print("1 ");
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  cout << n << " ";
  for (long long i = 2; i <= n; i++) cout << i - 1 << " ";
  cout << "\n";
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char arr[305][305], letter1, letter2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> arr[i][j];
    }
  }
  letter1 = arr[0][0];
  letter2 = arr[0][1];
  if (letter1 == letter2) {
    cout << "NO";
    return 0;
  }
  bool valid = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j || i + j == n - 1) {
        if (arr[i][j] != letter1) {
          valid = false;
          break;
        }
      } else {
        if (arr[i][j] != letter2) {
          valid = false;
          break;
        }
      }
    }
  }
  if (valid)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

15
rxeeeeeeeeeeeer
ereeeeeeeeeeere
eedeeeeeeeeeoee
eeereeeeeeeewee
eeeereeeeebeeee
qeeeereeejedyee
eeeeeerereeeeee
eeeeeeereeeeeee
eeeeeerereeeeze
eeeeereeereeeee
eeeereeeeegeeee
eeereeeeeeereee
eereeeeeeqeeved
creeeeeeceeeere
reeerneeeeeeeer

n = int(input())

data = []

ghotr = set()

other = set()

for i in range(n):
    text = input()

    for index in range(len(text)):
        if index == i:
            ghotr.add(text[index])

        elif index == n - i - 1:
            ghotr.add(text[n-1-i])

        else:
            other.add(text[index])

if len(ghotr) == len(other) == 1:
    if ghotr.pop() == other.pop():
        print("NO")
    else:
        print('YES')

else:
    print("NO")


#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000")
int a, b, c, d;
int gcd(int x, int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
int main() {
  cin >> a >> b >> c >> d;
  int d1 = gcd(a, b), d2 = gcd(c, d);
  a /= d1, b /= d1;
  c /= d2;
  d /= d2;
  int d3 = b * d / gcd(b, d);
  if ((a * d3 / b) >= (c * d3 / d)) {
    int aa = a * d3 / b - c * d3 / d, bb = a * d3 / b, dd = gcd(aa, bb);
    cout << aa / dd << "/" << bb / dd << endl;
    return 0;
  }
  int d4 = a * c / gcd(a, c);
  if ((b * d4 / a) > (d * d4 / c)) {
    int aa = b * d4 / a - d * d4 / c, bb = b * d4 / a, dd = gcd(aa, bb);
    cout << aa / dd << "/" << bb / dd << endl;
  }
}

import sys
from fractions import gcd
my_file = sys.stdin
#my_file = open("input.txt", "r")
line = [int(i) for i in my_file.readline().split()]
a, b, c, d = line[0], line[1], line[2], line[3]
if a/b < c/d:
    N = (b*c) - (a*d)
    D = b*c
else:
    N = (a*d)-(b*c)
    D = a*d

dec = gcd(N,D)

print(N//dec, end="/")
print(D//dec)


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

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

class TaskE {
    public void solve(int testNumber, FastScanner in, FastPrinter out) {
        in.next();
        char[] s = in.next().toCharArray();
        int n = s.length;
        if ((n & 1) == 1) {
            out.println(0);
            return;
        }
        int[] dp = new int[n / 2 + 1];
        int[] next = new int[n / 2 + 1];
        dp[0] = 1;
        int count = 0;
        for (int i1 = 0; i1 < n; i1++) {
            char e = s[i1];
            if (e == '?') {
                ++count;
                int left = i1 - n / 2;
                int right = i1 / 2;
                if (left < 0) left = 0;
                if ((i1 & 1) == 1) {
                    dp[(i1 + 1) / 2] += dp[(i1 + 1) / 2 - 1];
                }
                for (int i = right; i > left; i--) {
                    dp[i] += dp[i - 1];
                }
                if (i1 - n / 2 >= 0) {
                    dp[i1 - n / 2] = 0;
                }
            }
        }
        int ans = dp[n / 2];
        for (int i = 0; i < count - n / 2; i++) {
            ans *= 25;
        }
        out.println(Long.parseLong(Integer.toBinaryString(ans), 2));
    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    public String next() {
        StringBuilder sb = new StringBuilder();
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c < 0) {
            return null;
        }
        while (c >= 0 && !isWhiteSpace(c)) {
            sb.appendCodePoint(c);
            c = read();
        }
        return sb.toString();
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
char s[MAXN];
int n, q;
unsigned int dp[2][MAXN];
int main() {
  cin >> n;
  scanf("%s", s);
  for (int i = 0; s[i]; i++)
    if (s[i] == '?') q++;
  if ((n & 1) || (q < n / 2)) {
    printf("0\n");
    return 0;
  }
  memset(dp, 0, sizeof(dp));
  int cur = 0;
  dp[cur][0] = 1;
  int L = n >> 1;
  for (int i = 0; i < n; i++) {
    int l = max(0, i + 1 - L), r = (i + 1) / 2;
    cur ^= 1;
    int las = cur ^ 1;
    for (int j = l; j <= r; j++) dp[cur][j] = dp[las][j];
    for (int j = 0; j < l; j++) dp[cur][j] = 0;
    for (int j = r + 1; j <= L; j++) dp[cur][j] = 0;
    if (s[i] == '?')
      for (int j = max(1, l); j <= r; j++) dp[cur][j] += dp[las][j - 1];
    if (1 == 2) i++;
  }
  unsigned int ans = dp[cur][L];
  int t = (q - L);
  while (t) ans = ans * 25, t--;
  cout << ans << endl;
  return 0;
}


n = int(input())
a = input()
b = input()
ai = 0
alen = len(a)
bi = 0
blen = len(b)
nik = 0
pol = 0
if alen == blen: rnd = alen
else: rnd = alen*blen
numofrounds = 0
for i in range(n):
    #print(i,rnd)
    if i == rnd:
        numofrounds = n//rnd
        # print(numofrounds)
        nik *= numofrounds
        pol *= numofrounds
        break
        #print(a[ai%alen], b[bi%blen])
    if a[ai] == b[bi]: pass
    elif (a[ai] == 'R' and b[bi] == 'S') or (a[ai] == 'S'
        and b[bi] == 'P') or (a[ai] == 'P' and b[bi] == 'R'):
        pol += 1
    else: nik += 1
    ai = (ai+1)%alen
    bi = (bi+1)%blen
if n%rnd != 0 and numofrounds != 0:
    n -= rnd*numofrounds
    ai = 0
    bi = 0
    for i in range(n):
        if a[ai] == b[bi]: pass
        elif (a[ai] == 'R' and b[bi] == 'S') or (a[ai] == 'S'
        and b[bi] == 'P') or (a[ai] == 'P' and b[bi] == 'R'):
            pol += 1
        else: nik += 1
        ai = (ai+1)%alen
        bi = (bi+1)%blen
print(nik, pol)

import java.util.*;
import java.io.*;
public class RockPaperScissors
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		char[] nike = in.next().toCharArray();
		char[] poly = in.next().toCharArray();

		int m = nike.length;
		int k = poly.length;

		int lcm = m * (k / gcd(m, k));

		int nPinches = 0;
		int pPinches = 0;

		for(int x = 0; x < lcm; x++)
		{
			int winner = play(nike[x % nike.length], poly[x % poly.length]);

			if(winner == 1)
			{
				nPinches += n / lcm;

				if(x < n % lcm)
				{
					nPinches++;
				}
			}
			else if(winner == 0)
			{
				pPinches += n / lcm;

				if(x < n % lcm)
				{
					pPinches++;
				}
			}
		}

		System.out.println(nPinches + " " + pPinches);
	}

	public static int gcd(int a, int b)
	{
		if(b == 0)
		{
			return a;
		}
		else
		{
			return gcd(b, a % b);
		}
	}

	public static int play(char n, char p)
	{
		if(n == p)
		{
			return -1;
		}
		else if(n == 'R')
		{
			if(p == 'P')
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		else if(n == 'P')
		{
			if(p == 'S')
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		else
		{
			if(p == 'R')
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ss = 0, su = 0;
  string s;
  cin >> n >> s;
  int m = n / 2 - 1;
  for (int i = 0; i <= m; i++) {
    if (s[i] == '4' || s[i] == '7')
      ss += (s[i] - '0');
    else {
      cout << "NO";
      return 0;
    }
  }
  for (int i = m + 1; i < n; i++) {
    if (s[i] == '4' || s[i] == '7')
      su += (s[i] - '0');
    else {
      cout << "NO";
      return 0;
    }
  }
  if (ss == su)
    cout << "YES";
  else
    cout << "NO";
}

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

import java.util.Scanner;
public class code{
public static void main(String args[]){
Scanner sc  = new Scanner(System.in);
int n = sc.nextInt();
String a =sc.next();
boolean ok=true;

for(int i=0;i<a.length();i++){
	if(a.charAt(i)!='4' && a.charAt(i)!='7'){
		ok=false;
		break;
	}}

if(ok){
	int q=0;
	int w=0;
	for(int i=0;i<n/2;i++){
		q+=Integer.parseInt(a.charAt(i)+"");
	}
	for(int i=n/2;i<n;i++){
		w+=Integer.parseInt(a.charAt(i)+"");
	}
	if(q==w){
		System.out.println("YES");
	}
	else{
		System.out.println("NO");
	}}

else{
		System.out.println("NO");
}}}


from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
for _ in range(int(input())):
	n,k=map(int,input().split())
	if k>=n:
		print(1)
	else:
		l=[]
		s=int(sqrt(n))
		for i in range(2,s+2):
			if n%i==0 and i<=k:
				l.append(n//i)
				t=n//i
				if t<=k:
					l.append(n//t)
		if len(l)==0:
			print(n)
		else:
			print(min(l))

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ans = n;
    for (int i = 1; i * i <= n; i++) {
      if (i <= k && n % i == 0) {
        ans = min(ans, n / i);
        if (n / i <= k) ans = min(ans, i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


from sys import stdin, stdout
a, b, c = [int(a) for a in stdin.read().split()]
ZA = [1, 1]
for d in range(2, 31):
	ZA.append(d * ZA[d - 1])
e = 0
if c - b < 4:
	d = 4
else:
	d = c - b
while d <= a and d < c:
	e = e + ZA[a] // ZA[d] // ZA[a - d] * ZA[b] // ZA[c - d] // ZA[b - c + d]
	d = d + 1
stdout.write(str(e))

//package srms;

import java.util.Scanner;

public class theatre {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int t = sc.nextInt();
        long ans = 0;
        for (int man = t - 1; man >= 4; --man) {
            int woman = t - man;
            if (woman < 1) break;
            ans += C(n, man) * C(m, woman);
        }
        System.out.print(ans);
    }

    public static long C(int n, int k) {
        double res = 1;
        for (int i = 1; i <= k; ++i)
            res = res * (n - k + i) / i;
        return (long) (res + 0.01);
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{

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

	int[] starts;
	int[] ends;
	long[] downStarts;
	long[] downEnds;
	long[] intervalLengths;
	long[] suffixSum;
	long H;

	public void run() throws IOException
	{
		BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(file.readLine());
		//always start at beginning of up flow
		//find x coordinate where (non up flow) - upFlow = 0
		//altitude when reaching
		//end right after up flow
		//consider only intervals with no upflow
		int N = Integer.parseInt(st.nextToken());
		H = Long.parseLong(st.nextToken());
		starts = new int[N];
		ends = new int[N];
		for(int i = 0;i<N;i++)
		{
			st = new StringTokenizer(file.readLine());
			starts[i] = Integer.parseInt(st.nextToken());
			ends[i] = Integer.parseInt(st.nextToken());
		}
		downStarts = new long[N+1];
		downEnds = new long[N+1];
		downStarts[0] = -1000000001l;
		downEnds[0] = starts[0];
		for(int i = 0;i<starts.length - 1;i++)
		{
			downStarts[i+1] = ends[i];
			downEnds[i+1] = starts[i+1];
		}
		downStarts[N] = ends[N-1];
		downEnds[N] = downStarts[N] + 1000000001l;
		long[] intervalLengths = new long[N+1];
		for(int i = 0;i<intervalLengths.length;i++)
			intervalLengths[i] = downEnds[i] - downStarts[i];
		suffixSum = new long[intervalLengths.length+1];
		suffixSum[suffixSum.length - 1] = 0;
		for(int i = suffixSum.length - 2;i>=0;i--)
			suffixSum[i] = intervalLengths[i] + suffixSum[i+1];
		long maxDist = H;
		//System.out.println(Arrays.toString(downEnds));
		//System.out.println(Arrays.toString(intervalLengths));
		for(int i = 0;i<downEnds.length - 1;i++)
		{
			long initialPos = getInitialXPos(i);
			long distanceFlown = (downStarts[i+1] - initialPos + 1);
			//System.out.println("distace flown is "+ distanceFlown);
			maxDist = Math.max(maxDist,distanceFlown);
			//System.out.println();
		}
		System.out.println(maxDist);
	}

	public long intervalSum(int start, int end)
	{
		return suffixSum[start] - suffixSum[end+1];
	}

	public long getInitialXPos(int intervalEnd)
	{
		//1: find the interval the point is in
		//2:
		//System.out.println("ending point is " +(downStarts[intervalEnd+1]+1));
		int R = intervalEnd+1;
		int L = -1;
		int M = (L+R)/2;
		while(R-L > 1)
		{
			M = (L+R)/2;
			long sum = intervalSum(M, intervalEnd);
			//System.out.println(M+" "+sum);
			if(sum > H-1)
			{
				L = M;
			}
			else {
				R = M;
			}
		}
		int start = R;//maybe needs changing;
		//System.out.println("interval is "+start+" "+intervalEnd);
		long distBefore = Math.max(0,intervalSum(start,intervalEnd));
		long distLeft = H-1-distBefore;
		//System.out.println("distBefore is "+ distBefore);
		return downEnds[start-1] - distLeft;
	}

	public int getIntervalIntersecting(int X)
	{
		int index = Arrays.binarySearch(starts, X);
		if(index < 0)
			index = -index+1;
		return index;
	}

}

R = lambda: map(int, input().split())
n, h = R()
ps = []
for _ in range(n):
    l, r = R()
    ps.append([l, r])
l, c, res = 0, 0, 0
for r in range(n):
    c += (ps[r][0] - ps[r - 1][1]) if r > 0 else 0
    while c >= h:
        c -= (ps[l + 1][0] - ps[l][1])
        l += 1
    res = max(res, ps[r][1] - ps[l][0] + h - c)
print(res)


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll mod = 1000000007;
int n, k;
int a[200001];
int ok;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (k == 0) {
    if (a[0] == 1) {
      cout << "-1\n";
      return 0;
    } else {
      cout << (a[0] - 1) << '\n';
      return 0;
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (a[i] <= a[k - 1]) ok++;
  }
  if (ok == k) {
    cout << a[k - 1] << '\n';
  } else {
    cout << "-1\n";
  }
  return 0;
}

# import sys

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

t = 1
# t = int(input())

while t:
    t -= 1

    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    # s = input()
    a.sort()
    if k == 0:
        ans = a[0]-1
    else:
        ans = a[k-1]
    cnt = 0
    for el in a:
        if el <= ans:
            cnt += 1
        else:
            break
    if cnt == k and ans > 0:
        print(ans)
    else:
        print(-1)


//package C830;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class BCardSorting {

    int N = (int) 1e5 + 10;

    int n;

    long ans = 0;
    int[] bit = new int[N];

    void solve() {
        n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();

        int[] cnt = new int[N];
        for (int i = 0; i < n; i++) cnt[a[i]]++;
        int[][] g = new int[N][];
        for (int i = 0; i < N; i++) {
            g[i] = new int[cnt[i]];
            cnt[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            g[a[i]][cnt[a[i]]++] = i;
        }

        int prev = 0;
        for (int v = 0; v < N; v++) {
            if (cnt[v] == 0) continue;
            int p = lowerBound(g[v], prev);
            if (p == cnt[v]) p = 0;
            for (int i = 0; i < cnt[v]; i++) {
                move(prev, g[v][p]);
                if (i > 0) ans--;
                prev = g[v][p];
                p++;
                if (p >= cnt[v]) p -= cnt[v];
            }
            for (int i = 0; i < cnt[v]; i++) {
                add(g[v][i]);
            }
        }
        out.println(ans);
    }

    void move(int a, int b) {
        if (a <= b) {
            ans += (b - a + 1) - sum(a, b);
        } else {
            ans += (n - a) - sum(a, n - 1);
            ans += (b + 1) - sum(0, b);
        }
    }

    void add(int i) {
        for (int x = i; x < N; x = x | (x + 1)) {
            bit[x]++;
        }
    }

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

    int sum(int i) {
        int tot = 0;
        for (int x = i; x >= 0; x = (x & (x + 1)) - 1) {
            tot += bit[x];
        }
        return tot;
    }

    int lowerBound(int[] a, int k) {
        int lb = -1, ub = a.length;
        while (ub - lb > 1) {
            int m = (lb + ub) >> 1;
            if (a[m] >= k) ub = m;
            else lb = m;
        }
        return ub;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new BCardSorting().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

#include <bits/stdc++.h>
int n;
struct pos {
  int x, y;
} ps[100007];
bool operator<(pos a, pos b) { return a.y != b.y ? a.y < b.y : a.x < b.x; }
int bit[100007];
void inc(int w, int a) {
  for (; w <= n; w += w & -w) bit[w] += a;
}
int sum(int w) {
  int s = 0;
  for (; w; w -= w & -w) s += bit[w];
  return s;
}
int dis(int a, int b) {
  if (a > b) return dis(a, n) + dis(0, b);
  return b - sum(b) - a + sum(a);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &ps[i].y), ps[i].x = i;
  std::sort(ps + 1, ps + n + 1);
  int pw = 0;
  long long ans = 0;
  for (int i = 1, j = 1; j <= n; i = j) {
    for (; j <= n && ps[i].y == ps[j].y; ++j)
      ;
    int k = std::upper_bound(ps + i, ps + j, (pos){pw, ps[i].y}) - ps;
    int l = ps[k == i ? j - 1 : k - 1].x;
    int r = ps[k == j ? i : k].x;
    ans += dis(pw, r);
    ans += dis(r, l);
    pw = l;
    for (int a = i; a < j; ++a) inc(ps[a].x, 1);
  }
  printf("%I64d\n", ans);
  return 0;
}


def check(s):
	for i in range(len(s)//2):
		if s[i] != s[-(i+1)]:
			return(True)
	return(False)
n = int(input())

sub = "aabb"
ans = ""

mod = n //4
ans += sub*mod

for i in range(n%4):
	ans += sub[i]
print(ans)
# print(check(ans))

import java.util.Scanner;

public class Fuck {

	public static void main(String[] args) {

		Scanner Scan=new Scanner(System.in);
		long n;
		n=Scan.nextLong();
		Scan.close();
		if(n==1){
			System.out.print('a');
		}
		else if(n==2){
			System.out.print("aa");
		}
		else{
			StringBuilder s=new StringBuilder();
			s.append('a');
			s.append('a');
			System.out.print("aa");
			for(int i=2;i<n;i++){
				char ch=s.charAt(i-2);
				if(ch=='a'){
					s.append('b');
					ch='b';
				}
				else{
					s.append('a');
					ch='a';
				}
				System.out.print(ch);
			}
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
int n, a[20] = {0};
int main() {
  int n, ma = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    ma = max(ma, x);
    a[i] = x;
  }
  printf("%d\n", ma ^ a[n]);
  return 0;
}

input()
a = list(map(int, input().split()))
print(max(a) ^ a[-1])


string=input()
a,b=map(int,string.split(' '))
if a==0 and b==0:
    print('NO')
elif a-b==1 or b-a==1:
    print('YES')
elif a==b:
    print('YES')
else:
    print('NO')

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int even, odd;
  cin >> even >> odd;
  if (even == 0 && odd == 0) {
    cout << "NO";
    return 0;
  } else {
    if (odd == even || even + 1 == odd || odd + 1 == even) {
      cout << "YES";
    } else
      cout << "NO";
  }
  return 0;
}


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

public class Solution670C {
    public static void main(String... bob) throws Exception {
        FAST in = new FAST();
        WriteMe out = new WriteMe();
        int N = in.nextInt();
        final Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < N; i++) {
            int tmp = in.nextInt();
            int count = map.containsKey(tmp) ? map.get(tmp) : 0;
            map.put(tmp, count + 1);
        }
        int M = in.nextInt();
        int[] audio = new int[M];
        for (int i = 0; i < M; i++) {
            audio[i] = in.nextInt();
        }
        int[] subtitle = new int[M];
        for (int i = 0; i < M; i++) {
            subtitle[i] = in.nextInt();
        }
        List<int[]> data = new ArrayList<int[]>();
        for (int i = 0; i < M; i++) {
            data.add(new int[]{i, audio[i], subtitle[i]});
        }
//        System.out.println(map);
//        for (int[] ints : data) {
//            System.out.println(Arrays.toString(ints));
//        }
//        System.out.println();
        Collections.sort(data, new Comparator<int[]>() {
            @Override
            public int compare(int[] a, int[] b) {
                int aAudio = map.containsKey(a[1]) ? map.get(a[1]) : -1;
                int bAudio = map.containsKey(b[1]) ? map.get(b[1]) : -1;
                int aSubtitle = map.containsKey(a[2]) ? map.get(a[2]) : -1;
                int bSubtitle = map.containsKey(b[2]) ? map.get(b[2]) : -1;
                if (aAudio != -1 && bAudio != -1) {
                    if (aAudio == bAudio) {
                        return -(aSubtitle - bSubtitle);
                    } else {
                        return -(aAudio - bAudio);
                    }
                } else {
                    return bAudio;
                }
            }
        });
//        for (int[] ints : data) {
//            System.out.println(Arrays.toString(ints));
//        }
        System.out.println(data.get(0)[0] + 1);

        out.close();
    }

    static class WriteMe {
        private PrintWriter out;

        public WriteMe() {
            try {
                out = new PrintWriter(new BufferedWriter(new FileWriter("Solution670C.out")));
            } catch (Exception e) {

            }
        }

        public void caseInt(int num, int ans) {
            caseStr(num, String.valueOf(ans));
        }

        public void caseStr(int num, String ans) {
            out.printf("Case #%d: %s\n", num, ans);
        }

        public void writeln(String str) {
            out.println(str);
        }

        public void write(String str) {
            out.print(str);
        }

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

    static class FAST {
        private BufferedReader in;
        private StringTokenizer str;

        public FAST() {
            in = new BufferedReader(new InputStreamReader(System.in));
            // in = new BufferedReader(new FileReader("Solution670C.in"));
        }

        private String next() {
            while (str == null || !str.hasMoreElements()) {
                try {
                    str = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                }
            }
            return str.nextToken();
        }

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

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

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

n = int(input())
d = {}
for i in list(map(int, input().split())):
    if i in d: d[i] += 1
    else: d[i] = 1
m = int(input())
res = [(0, 0)] * m
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(m):
    if b[i] not in d: d[b[i]] = 0
    if c[i] not in d: d[c[i]] = 0
    res[i] = (d[b[i]], i)
res.sort()
idx = res[m-1][1]
for i in range(m-1, -1, -1):
    if res[i][0] == res[m-1][0] and d[c[res[i][1]]] > d[c[idx]]:
        idx = res[i][1]
print(idx+1)


import sys;

lines = [];
m = 0;

for s in sys.stdin:
  lines.append(s.rstrip());
for s in lines:
  m = max(m, len(s));

turn_is_left = 1;

sys.stdout.write('*' * (m + 2) + '\n');

for s in lines:
  l = len(s);
  p = q = (m - l) // 2;
  if ((m - l) % 2):
    if turn_is_left:
      q += 1;
    else:
      p += 1;
    turn_is_left ^= 1;

  sys.stdout.write('*' + p * ' ' + s + q * ' ' + '*\n');

sys.stdout.write('*' * (m + 2) + '\n');

welcome to the
Codeforces
Beta
Round 5

and
good luck

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

public class CenterAlignment {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        String[] a = new String[1000];
        int n = 0;
        String str = f.readLine();
        while (str != null) {
            a[n++] = str;
            str = f.readLine();
        }
        int max = 0;
        for (int i = 0; i < n; i++)
            max = Math.max(max,a[i].length());
        for (int i = 0; i < max+2; i++)
            System.out.print("*");
        System.out.println();
        int x = 0;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 1000; i++)
            sb.append(" ");
        String spaces = sb.toString();
        for (int i = 0; i < n; i++) {
            System.out.print("*");
            System.out.print(spaces.substring(0, (max-a[i].length()+x)/2));
            System.out.print(a[i]);
            System.out.print(spaces.substring(0, (max-a[i].length()+1-x)/2));
            if ((max-a[i].length()) % 2 != 0)
                x = 1-x;
            System.out.println("*");
        }
        for (int i = 0; i < max+2; i++)
            System.out.print("*");
        System.out.println();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class C551 {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = new int[n];

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

		long high = (long) 1e15;
		long low = 0;
		while(high>=low){
//			System.out.println(low+" "+high);
			long mid = (low+high)/2;
			if(canSolve(Arrays.copyOf(a, a.length),mid,m)){
				high = mid-1;
			}else{
				low = mid+1;
			}

		}

		System.out.println(""+low);
	}

	public static boolean canSolve(int[] a, long t, int m){
		int i = 0;
		for(int s=0;s<m;++s){
			long curT= t-(i+1);
			while(curT>0&&i<a.length){
				if(curT>=a[i]){
					curT-=a[i];
					a[i]=0;
					++i;
					curT--;
				}else{
					a[i]-=curT;
					curT = 0;
				}
			}
		}
		for(i=0;i<a.length;++i){
			if(a[i]!=0){
				return false;
			}
		}
//		System.out.println("can solve for "+t);
		return true;
	}

}

#include <bits/stdc++.h>
using namespace std;
int n, m;
long long pile[100002];
bool bisa(long long x) {
  int idx = n;
  long long now = pile[idx - 1];
  for (int i = 0; i < m; i++) {
    long long tmp = x - idx;
    while (tmp > 0) {
      long long ambil = min(now, tmp);
      tmp -= ambil;
      now -= ambil;
      while (now == 0) {
        idx--;
        if (idx == 0) return 1;
        now = pile[idx - 1];
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  long long l, r = l = 0;
  for (int i = 0; i < n; i++) scanf("%I64d", &pile[i]), r += pile[i];
  while (n > 0 && pile[n - 1] == 0) n--;
  r += n;
  while (l < r) {
    long long mid = l + r >> 1;
    if (bisa(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%I64d\n", l);
  return 0;
}


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

public class a {
  public static void main(String[] args) {
    InputReader in = new InputReader();
    in.init(System.in);

    Solver soal = new Solver();
    soal.solve(in);
  }
}

class Solver {
  private int[] dp;
  private int N, exp = -1, n;

  public void solve(InputReader in) {
    n = in.nextInt();
    N = (1 << (n + 1)) - 1;

    dp = new int[N * 2];
    Arrays.fill(dp, 0);
    for (int i = 2; i <= N; ++i) {
      dp[i] = in.nextInt() + dp[i / 2];
      if (dp[i] > exp) exp = dp[i];
    }

    dfs(1);

    int ans = 0;
    for (int i = 2; i <= N; ++i) {
      ans += dp[i];
    }
    System.out.println(ans);
  }

  private int dfs(int cur) {
    if (cur > N) return 0;
    int l = cur << 1, r = l | 1;
    if (cur > 1) {
      if (l >= N) {
        dp[cur] = exp - dp[cur];
      } else {
        dp[cur] = Math.min(dfs(l), dfs(r));
        dp[l] -= dp[cur];
        dp[r] -= dp[cur];
      }
    } else {
      dfs(l);
      dfs(r);
    }
    return dp[cur];
  }
}

class InputReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;

  public void init(InputStream input) {
    reader = new BufferedReader(
            new InputStreamReader(input),
            32768);
    tokenizer = null;
  }

  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

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

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

# print ("Enter n")
n = int(input())

alen = 2**(n+1)
a = [0 for i in range(alen)]

# print ("Enter all values on the same line")
inp = input().split()
for i in range(len(inp)):
    a[i+2] = int(inp[i])

answer = 0
while (n > 0):
    index = 2**n
    for i in range(index, index*2, 2):
        left = a[i]
        right = a[i+1]
        diff = abs(left-right)
        bigone = max(left, right)
        answer += diff
        a[i//2] += bigone
    n = n - 1

print (answer)


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

    public class Main {
	static InputReader scn = new InputReader(System.in);
	static OutputWriter out = new OutputWriter(System.out);
	public static void main(String[] HastaLaVistaLa) {
		// Running Number Of TestCases (t)
		int t = 1;
		while(t-- > 0)
			solve();
		out.close();
	}

	static long mod = 1000000007L;

	public static void dummy(){
		int n = scn.nextInt();
		out.println(n);
	}

	public static void solve() {
		// Main Solution (AC)
		long n = scn.nextLong(), m = scn.nextLong();
		long rem = n - m + 1;
		long max = (rem) * (rem - 1) / 2; // Good Job For Maximum Finding
		long quot = n / m;
		long reminder = n % m;
		long bigA = (reminder) * (quot) * (quot + 1) / 2;
		long shortA = (m-  reminder) * (quot) * (quot - 1) / 2;
		long min = bigA + shortA;
		out.println(min + " " + max);

	}

	public static HashMap<Integer, Integer> CountFrequencies(int[] arr) {
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i : arr) {
			if (map.containsKey(i)) map.put(i, map.get(i) + 1);
			else map.put(i, 1);
		}
		return map;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static long factorial(long number) {
		number %= mod;
	        long result = 1;
	        for (long factor = 2; factor <= number; factor++) {
	            result *= factor % mod;
	            result %= mod;
	        }
	        result %= mod;
        	return result;
    	}

	public static long sum(int[] arr) {
	    	long sum = 0;
	    	for(int i : arr) sum += i;
	    	return sum;
	}

	// Number of Divisor for Range [l, r]
	public static int[] NumberOFDivisors(int l, int r) {
		int[] arr = new int[l - r + 1];
		for(int i = l; i <= r; i++) {
			for(int j = i; j <= r; j += i)
				arr[j]++;
		}
		return arr;
	}

	public static int LowerBound(int a[], int x) { // x is the target value or key

		  int l = -1,r = a.length;
		  while(l + 1 < r) {

		    int m = (l + r) >>> 1;
		    if(a[m] >= x) r = m;
		    else l = m;

		  }
		  return r;
	}

	static boolean[] prime;
	public static void sieveOfEratosthenes(int n) {
        	prime = new boolean[n+1];
	        for(int i=0;i<n;i++)
	            prime[i] = true;

	        for(int p = 2; p*p <=n; p++) {

	            if(prime[p] == true) {

	                for(int i = p*p; i <= n; i += p)
	                    prime[i] = false;
	            }
	        }
    	}

	public static long binpow(long n, long m, long mod) {
	        long res = 1;
	        while (m > 0) {
	            if (m % 2 == 1) {
	                res *= n;
	                res %= mod;
	                m--;
	            }
	            n *= n;
	            n %= mod;
	            m /= 2;
	        }
	        return res;
    	}

	public static int UpperBound(long a[], long x) {// x is the key or target value

		    int l = -1,r = a.length;

		    while(l + 1 < r) {

		       int m = (l + r) >>> 1;
		       if(a[m] <= x) l = m;
		       else r = m;

		    }
		    return l + 1;
	}

    	public static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sort(int[] arr) {
		Random rand = new Random();
		int n = arr.length;
		for(int i = 0; i<n; i++) {
			swap(arr, i, rand.nextInt(n));
		}
		Arrays.sort(arr);
	}

	public static void swap(int[] arr, int i, int j) {
		if(i!=j) {
			arr[i] ^= arr[j];
			arr[j] ^= arr[i];
			arr[i] ^= arr[j];
		}
	}

	public static void sortbyColumn(int[][] arr, int col) {
		Arrays.sort(arr, new Comparator<int[]>() {
			public int compare(final int[] entry1, final int[] entry2) {
				if (entry1[col] > entry2[col])
					return 1;
				else
					return -1;
			}
		});
	}

	public static void ArraySort2D(double[][] arr, int xy) {
		// xy == 0, for sorting wrt X-Axis
		// xy == 1, for sorting wrt Y-Axis
		Arrays.sort(arr, Comparator.comparingDouble(o -> o[xy]));
	}

	public static int binarySearch(int arr[], int l, int r, int x) {
		if (r >= l) {
			int mid = l + (r - l) / 2;
			if (arr[mid] == x)
				return mid;
			if (arr[mid] > x)
				return binarySearch(arr, l, mid - 1, x);
			return binarySearch(arr, mid + 1, r, x);
		}
		return -1;
	}

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

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

		public int[] readIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = scn.nextInt();
			}
			return a;
		}

     		public long[] readLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = scn.nextLong();
			}
			return a;
		}

		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 long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long 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 String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return nextLine();
		}

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

	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(1);
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

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

#code
n,m = map(int,input().split())

k = n//m
z = n - m

print(m*k*(k-1)//2+k*(n%m),(z+1)*z//2)


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n];
  long long sum[n + 1];
  long long sorted_sum[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum[i + 1] = sum[i] + arr[i];
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    sorted_sum[i + 1] = sorted_sum[i] + arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int t, l, r;
    cin >> t >> l >> r;
    if (t == 1)
      cout << sum[r] - sum[l - 1] << endl;
    else
      cout << sorted_sum[r] - sorted_sum[l - 1] << endl;
  }
  return 0;
}

t = int(input())
lst = list(map(int,input().split()))
x = lst[:]
x.sort()
l_st = [0]
lst1 = [0]
k = 0
k1 = 0
for i in range(t):
    k += lst[i]
    l_st.append(k)
    k1 += x[i]
    lst1.append(k1)
n = int(input())
for i in range(n):
    t_pe , l , r = map(int,input().split())
    if(t_pe == 1):
        print(l_st[r] - l_st[l - 1])
    else:
        print(lst1[r] - lst1[l - 1])
#print(l_st)
#print(lst1)
#print(x)
#print(lst)

#Qalay (^-^)


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		int sum = 0;
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextIntArr();
			sum += a[i][i];
		}
		sum%=2;
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		while(q-->0)
		{
			int t = sc.nextInt();
			if(t<3)
			{
				sc.nextInt();
				sum ^=1;
			}
			else
				sb.append(sum);
		}
		System.out.println(sb);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public Scanner(String s) throws FileNotFoundException {br = new BufferedReader(new FileReader(s));}
		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		public char nextChar() throws IOException{return next().charAt(0);}
		public boolean ready() throws IOException {return br.ready();}
		public int[] nextIntArr() throws IOException{
			st = new StringTokenizer(br.readLine());
			int[] res = new int[st.countTokens()];
			for (int i = 0; i < res.length; i++)
				res[i] = nextInt();
			return res;
		}
		public char[] nextCharArr() throws IOException{
			st = new StringTokenizer(br.readLine());
			char[] res = new char[st.countTokens()];
			for (int i = 0; i < res.length; i++)
				res[i] = nextChar();
			return res;
		}
	}

}

from sys import stdin

n = int(stdin.readline())
dot = 0
j = 0
for i in range(n):
    line = stdin.readline()
    if line[j] == '1':
        dot ^= 1
    j += 2

out = []
stdin.readline()
for query in stdin:
    if len(query) < 3:
        out.append('1' if dot else '0')
    else:
        dot ^= 1

print(''.join(out))


#include <bits/stdc++.h>
using namespace std;
char getOtherValue(char val) {
  if (val == '.') return '0';
  if (val == '1') return '0';
  return '1';
}
int main() {
  int n, p;
  cin >> n >> p;
  string str;
  cin >> str;
  bool ok = false;
  for (int i = 0; i < n - p; ++i) {
    if (str[i] == '.' || str[i] != str[i + p]) {
      ok = true;
      if (str[i] == '.') {
        str[i] = getOtherValue(str[i + p]);
      }
      if (str[i + p] == '.') {
        str[i + p] = getOtherValue(str[i]);
      }
      break;
    }
  }
  if (ok) {
    for (int i = 0; i < n; ++i) {
      if (str[i] == '.') {
        str[i] = '0';
      }
    }
    cout << str;
    return 0;
  }
  cout << "NO";
  return 0;
}

n, p = [int(i) for i in input().split()]
s = list(input())
k = 0
for index in range(n - p):
    if k != 0:
        break
    if s[index] == s[index + p] and s[index] == ".":
        s[index] = str(0)
        s[index + p] = str(1)
        k += 1
    elif s[index] != s[index + p] and s[index] != "." and s[index + p] != ".":
        k += 1
    elif s[index] != s[index + p] and (s[index] == "." or s[index + p] == "."):
        if s[index] == ".":
            s[index] = str(int(not int(s[index + p])))
        else:
            s[index + p] = str(int(not int(s[index])))
        k += 1
s = "".join(s)
print("No" if k == 0 else s.replace(".", str(0)))


import itertools

n = int(input())
a = []
for i in range(4):
    a.append([input() for _ in range(n)])
    if i < 3:
        assert input() == ''

best = 4*n*n
for p in itertools.permutations(a):
    for s in range(2):
        count = 0
        for i in range(4):
            for r in range(n):
                for c in range(n):
                    if p[i][r][c] != str((s + (i//2 + r) + (i % 2 + c)) % 2):
                        count += 1
        best = min(best, count)
print(best)


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Try
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

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

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

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}
		static PrintWriter w = new PrintWriter(System.out);

    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

   int x = sc.ni();
   w.println(2*x-1 + " " + "2");
   w.println("1" + " " + "2");

      w.close();

    }

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n)
    {
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            sum = 1;
            //System.out.print(2 + " ");
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                n /= i;
            }
            sum++;
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            sum++;
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static boolean binarysearch(int []arr,int p,int n)
    {
        //ArrayList<Integer> as = new ArrayList<>();
        //as.addAll(0,at);
        //Collections.sort(as);
        boolean re = false;
        int st = 0;
        int end = n-1;

        while(st <= end)
        {
            int mid = st + (end-st)/2;

            if(p > as.get(mid))
            {
                st = mid+1;

            }
            else if(p < as.get(mid))
            {
                end = mid-1;

            }
            else if(p == as.get(mid))
            {

            re = true;
            break;
            }

        }
         return re;

    }

    static class Student
    {

        int position;
        int value;
        Student(int position,int value)
        {
            this.position = position;
            this.value = value;

        }

    }
    /* Java program for Merge Sort */
static class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */

}

    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  cout << (2 * n) - 1 << " " << 2 << endl;
  cout << 1 << " " << 2;
  return 0;
}


n,t,k,d=[int(i) for i in input().split()]
a = (n+k-1)//k*t
b=1000000000
for i in range(n//k+1):
    b=min(b,max(d+i*t,(n-i*k+k-1)//k*t))
if b<a:
    print('YES')
else:
    print('NO')

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

import java.util.Scanner;

public class Problem {

    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int t = cin.nextInt();
        int k = cin.nextInt();
        int d = cin.nextInt();

        if (n - (d / t)*k > k)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


n, c1, c2 = [int(x) for x in input().split(' ')]
s = input()

cnt = s.count('1')

def price(x):
    return c1 + c2 * (x - 1) ** 2

prices = []

for i in range(1, cnt + 1):
    bigGroupsPeople = n // i + 1
    numBigGroups = n % i
    smallGroupsPeople = n // i
    numSmallGroups = i - n % i
    totalPrice = numBigGroups * price(bigGroupsPeople) + numSmallGroups * price(smallGroupsPeople)
    prices.append(totalPrice)

print(min(prices))

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, c1, c2, p = 0, r;
  cin >> n >> c1 >> c2;
  char g;
  for (long long int i = 0; i < n; i++) {
    cin >> g;
    if (g == '1') p++;
  }
  long long int minr = -1;
  for (int i = 1; i <= p; i++) {
    r = i * c1 + c2 * ((n % i) * (n / i) * (n / i) +
                       (i - (n % i)) * (n / i - 1) * (n / i - 1));
    if (r < minr || minr == -1) minr = r;
  }
  cout << minr;
}


import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int inf=1<<30;
        int l=-inf;
        int r=inf;
        int pre=0;
        for(int i=0;i<n;i++)
        {
            int fi=sc.nextInt();
            int se=sc.nextInt();
            if(se==1)
                l=Math.max(l,1900-pre);
            else
                r=Math.min(r,1899-pre);
            pre+=fi;
        }
        if(l>r){
            out.println("Impossible");
        }
        else if(l<=r&&r==inf){
            out.println("Infinity");
        }
        else{
            out.println(r+pre);
        }

        out.flush();
    }
}

I = lambda: list(map(int, input().split()))
n = I()[0]
c, d = [[0] * n for _ in range(2)]
for i in range(n):
    _c, _d = I()
    c[i] = _c
    d[i] = _d
lb, ub, change = -1e100, 1e100, 0
for i in range(n)[::-1]:
    change -= c[i]
    if d[i] == 1:
        lb = max(lb, 1900 - change)
    else:
        ub = min(ub, 1899 - change)
    if lb > ub:
        print('Impossible')
        break
if ub == 1e100:
    print('Infinity')
elif lb <= ub:
    print(ub)


import java.util.Scanner;

public class p56b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] all  = new int[n];
        for (int i = 0; i < all.length; i++) {
            all[i] = in.nextInt();
        }

        int left = 0;
        int right = 0;
        for (int i = 0; i < all.length; i++) {
            if(all[i] != (i+1)) {
                left = i;
                right = all[i]-1;

                int[] temp = new int[right - left + 1];
                for (int j = 0; j < temp.length; j++) {
                    temp[j] = all[right - j];
                }
                for(int j = left ; j<=right ; j++) {
                    all[j] = temp[j-left];
                }

                for (int k = 0; k < all.length; k++) {
                    if(all[k] != (k+1)) {
                        System.out.println("0 0");
                        return;
                    }
                }
                System.out.println((left+1)+" "+(right+1));
                return;
            }
        }
        System.out.println("0 0");
    }
}

n = int(input())

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

v = l.copy()
v.sort()
i = 0
j = 0
l1 = []
l2 = []
ans = []
while i<n and j<n:
    if l[i] == v[j]:
        i+=1
        j+=1
    else:
        l1.append(v[j])
        l2.append(l[i])
        ans.append(j)
        j+=1
        i+=1
l2.reverse()
if l1 == l2 and len(ans)>=2:
    print(ans[0]+1,ans[-1]+1)
else:
    print(0,0)


#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1005;
int n, T;
pair<int, int> tq[Maxn];
vector<int> cur;
bool Less(const int &a, const int &b) { return a > b; }
void Next() {
  vector<int> nw;
  for (int i = 0; i < cur.size(); i += 2) {
    int val = cur[i] + (i + 1 < cur.size() ? cur[i + 1] : 0);
    nw.push_back(val);
  }
  cur = nw;
}
int main() {
  scanf("%d %d", &n, &T);
  for (int i = 0; i < n; i++) scanf("%d %d", &tq[i].first, &tq[i].second);
  sort(tq, tq + n);
  int j = 0;
  for (int i = 1; i <= T; i++) {
    Next();
    while (j < n && tq[j].first == i) {
      cur.push_back(tq[j].second);
      j++;
    }
    sort(cur.begin(), cur.end(), Less);
  }
  printf("%d\n", cur[0]);
  return 0;
}

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class F {

    static void solve() throws IOException {
        int n = in.nextInt();
        int t = in.nextInt();
        int[] time = new int[n];
        int[] q = new int[n];
        for ( int i = 0; i < n; i ++ ) {
            time[i] = in.nextInt();
            q[i] = in.nextInt();
        }
        ArrayList< Integer > list = new ArrayList<>();
        for ( int ct = 1; ct <= t; ct ++ ) {
            for ( int i = 0; i < n; i ++ ) {
                if ( time[i] == ct ) {
                    list.add( q[i] );
                }
            }
            Collections.sort( list );
            if ( ct == t ) {
                break;
            }
            ArrayList< Integer > tmp = new ArrayList<>();
            for ( int i = list.size() - 1; i >= 0; i -= 2 ) {
                if ( i > 0 ) {
                    tmp.add( list.get( i ) + list.get( i - 1 ) );
                } else {
                    tmp.add( list.get( 0 ) );
                }
            }
            list = tmp;
        }
        out.println( list.get( list.size() - 1 ) );
    }

    static Scanner in;
//    static StreamTokenizer in;
    static PrintWriter out;

//    static int nextInt() throws IOException {
//        in.nextToken();
//        return ( int ) in.nval;
//    }

    public static void main( String[] args ) throws IOException {
        in = new Scanner( System.in );
//        in = new StreamTokenizer( new InputStreamReader( System.in ) );
        out = new PrintWriter( System.out );
        solve();
        out.close();
    }
}


#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
const long long _ = 1e18;
signed main() {
  long long a = read(), q = (_ % a * 9 % a * 9 % a + 1) % a;
  printf("%lld %lld\n", a - q + 1, a - q + _);
  return 0;
}


n, a, b = map(int, input().split())
x = set(map(int, input().split()))
y = set(map(int, input().split()))
y -= x
s = ""
for i in range(1, n + 1, 1):
    if i in x:
        s += str(1) + " "
    else:
        s += str(2) + " "
print(s)

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int A;
  int B;
  int C;
  int APPLE;
  int ARTHUR;
  int ALEX;
  int ARLIKE[100] = {0};
  int ALLIKE[100] = {0};
  cin >> APPLE >> ARTHUR >> ALEX;
  for (A = 0; A < ARTHUR; A++) {
    cin >> ARLIKE[A];
  }
  for (A = 0; A < ALEX; A++) {
    cin >> ALLIKE[A];
  }
  for (A = 0; A < APPLE; A++) {
    for (B = 0; B < APPLE; B++) {
      if (A + 1 == ARLIKE[B]) {
        cout << 1 << " ";
        break;
      } else if (A + 1 == ALLIKE[B]) {
        cout << 2 << " ";
        break;
      }
    }
  }
  cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  if (x % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < x; i++) {
    cout << i << " ";
  }
  cout << "\n";
  for (int i = 0; i < x; i++) {
    cout << i << " ";
  }
  cout << "\n";
  for (int i = 0; i < x; i++) {
    cout << (i * 2) % x << " ";
  }
  cout << "\n";
}

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

public class TestGenerator {

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

        int n = sc.nextInt();
        if (n % 2 == 0){
            System.out.println(-1);
            return;
        }
        StringBuilder a = new StringBuilder(), b = new StringBuilder(), c = new StringBuilder();
        for (int i = 0; i < n; i++) {
            a.append(i + " ");
            b.append(i + " ");
            c.append((2*i) % n + " ");
        }
        out.println(a);
        out.println(b);
        out.println(c);

        out.close();
    }
}

class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

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

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

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

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}

}


#https://codeforces.com/problemset/problem/281/D

def empty(l):
    return len(l) == 0

def lucky_number(arr):
    st = []
    l = 0

    for d in arr:
        while not empty(st) and st[-1] < d:
            l = max(l, st.pop() ^ d)
        if not empty(st):
            l = max(l, st[-1] ^ d)
        st.append(d)
        # print(st)

    # print(l)
    # print(st)

    d = 0
    if not empty(st):
        d = st.pop()
    while not empty(st):
        l = max(l, d ^ st[-1])
        d = st.pop()
    return l

N = int(input())
arr = list(map(int, input().split()))
print(lucky_number(arr))

# for i in range(len(arr)):
#     for j in range(i + 1, len(arr)):
#         print(arr[i], arr[j], arr[i]^arr[j])

#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> v) {
  int res = v[0] ^ v[1], n = ((int)(v).size());
  vector<int> st;
  for (register int i = (0); i < (int)(n); ++i) {
    while (!st.empty() && st.back() < v[i]) st.pop_back();
    st.push_back(v[i]);
    if (((int)(st).size()) >= 2)
      res = max(res, st[((int)(st).size()) - 1] ^ st[((int)(st).size()) - 2]);
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (register int i = (0); i < (int)(n); ++i) cin >> v[i];
  int res = solve(v);
  reverse((v).begin(), (v).end());
  cout << max(res, solve(v)) << endl;
  return 0;
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    static int mod = (int)1e9+7;
    static int inf = (int)(2e9+1e8);
    static double eps = 1e-15;
    static int N = 1005;
    int[] a = new int[N];
    double[][] inv = new double[N][N], inv2 = new double[N][N];

    void work() throws Exception {
        int n = nextInt(), m = nextInt();
        for(int i = 0; i < n; i ++) {
            a[i] = nextInt();
        }
        for(int i = 0; i < n; i ++) {
            for(int j = i+1; j < n; j ++) {
                if(a[i] > a[j]) inv[i][j] = 1;
                else inv[i][j] = 0;
            }
        }

        for(int i = 0; i < m; i ++) {
            int a = nextInt(), b = nextInt();
            a --; b --;
            if(a > b) {
                int tmp = a;
                a = b;
                b = tmp;
            }

            for(int j = 0; j < a; j ++) {
                inv2[j][a] = (inv[j][a] + inv[j][b]) / 2.0;
                inv2[j][b] = (inv[j][a] + inv[j][b]) / 2.0;
            }
            for(int j = a+1; j < b; j ++) {
                inv2[a][j] = (inv[a][j] + 1-inv[j][b]) / 2.0;
                inv2[j][b] = (inv[j][b] + 1-inv[a][j]) / 2.0;
            }
            for(int j = b+1; j < n; j ++) {
                inv2[a][j] = (inv[a][j] + inv[b][j]) / 2.0;
                inv2[b][j] = (inv[a][j] + inv[b][j]) / 2.0;
            }

            for(int j = 0; j < a; j ++) {
                inv[j][a] = inv2[j][a];
                inv[j][b] = inv2[j][b];
            }
            for(int j = a+1; j < b; j ++) {
                inv[a][j] = inv2[a][j];
                inv[j][b] = inv2[j][b];
            }
            for(int j = b+1; j < n; j ++) {
                inv[a][j] = inv2[a][j];
                inv[b][j] = inv2[b][j];
            }

            inv[a][b] = 0.5;
        }
        double ans = 0;
        for(int i = 0; i < n; i ++) {
            for(int j = i+1; j < n; j ++) {
                ans += inv[i][j];
            }
        }

        out.println(df.format(ans));
    }
    static PrintWriter out = new PrintWriter(System.out);
    Scanner cin = new Scanner(System.in);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer str = null;
    private String next() throws Exception{
        while (str == null || !str.hasMoreElements())
            str = new StringTokenizer(in.readLine());
        return str.nextToken();
    }
    private int nextInt() throws Exception{
        return Integer.parseInt(next());
    }
    private long nextLong() throws Exception{
        return Long.parseLong(next());
    }
    static int dx[] = {1, 0, 0, -1};
    static int dy[] = {0, -1, 1, 0};
    class pair implements Comparable<pair>{
        int first, second;
        pair(int x, int y) {
            first = x;
            second = y;
        }
        public int compareTo(pair o) {
            // TODO auto-generated method stub
            if(first != o.first) return ((Integer)first).compareTo(o.first);
            else return ((Integer)second).compareTo(o.second);
        }
    }
    int upper_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;
        int pos = r;
        r--;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (A[mid] <= val) {
                l = mid + 1;
            } else {
                pos = mid;
                r = mid - 1;
            }
        }
        return pos;
    }
    int lower_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;
        int pos = r;
        r--;
        while (l <= r) {
            int mid = (l + r) >> 1;
            if (A[mid] < val) {
                l = mid + 1;
            } else {
                pos = mid;
                r = mid - 1;
            }
        }
        return pos;
    }
    DecimalFormat df=new DecimalFormat("0.000000");
    public static void main(String[] args) throws Exception{
        Main wo = new Main();
        wo.work();
        out.close();
    }
}

#include <bits/stdc++.h>
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
const int MOD = mod - 1;
const double eps = 1e-18;
const double PI = acos(-1.0);
using namespace std;
int p[N];
double f[N][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) f[i][j] = (p[i] > p[j]);
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    for (int i = 1; i <= n; i++) {
      if (i != a && i != b) {
        f[i][a] = f[i][b] = (f[i][a] + f[i][b]) / 2;
        f[a][i] = f[b][i] = (f[a][i] + f[b][i]) / 2;
      }
    }
    f[a][b] = f[b][a] = 0.5;
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans += f[i][j];
    }
  }
  printf("%f\n", ans);
  return 0;
}