import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.StringTokenizer;

public class A {
	static InputReader in = new InputReader(System.in);
	static OutputWriter out = new OutputWriter(System.out);

	public static void main(String[] args) {

		int n = in.nextInt(), m = in.nextInt(), mm = m;
		boolean[] b = new boolean[n];

		for (int i = 0; i < n && m > 0; i += 2, m--)
			b[i] = true;
		for (int i = n-1; i >= 0 && m > 0; i--) {
			if (b[i])
				continue;
			b[i] = true;
			m--;
		}
		int ans = 0;
		for (int i = 1; i < n; i++)
			if (b[i-1] && !b[i])
				ans++;
		if (mm == n-1 || mm == 0 || mm == 1)
			ans = 1;
		if (mm == n)
			ans = 0;

		out.println(ans);

		out.flush();
	}

	static class Pair<E extends Comparable, F extends Comparable> implements Comparable {
		E first;
		F second;

		public Pair(E first, F second) {
			this.first = first;
			this.second = second;
		}

		public int compareTo(Object o) {
			Pair p = (Pair) o;
			if (first.compareTo(p.first) == 0)
				return second.compareTo(p.second);
			return first.compareTo(p.first);
		}

		public int hashCode() {
			return Objects.hash(first, second);
		}

		public boolean equals(Object o) {
			Pair p = (Pair) o;
			return first.compareTo(p.first) == 0 && second.compareTo(p.second) == 0;
		}

		public String toString() {
			return String.format("(%s,%s)", first.toString(), second.toString());
		}

	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (Exception e) {
				return tokenizer.nextToken();
			}
		}

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

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

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

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

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

		public double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

	}

	static class OutputWriter {
		private PrintWriter writer;

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

		public void print(Object o) {
			writer.print(o.toString());
		}

		public void println(Object o) {
			writer.print(o.toString());
			writer.print('\n');
		}

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

	}
}

#include <bits/stdc++.h>
using namespace std;
int mini(int a, int b, int c) {
  int minm = min(a, b);
  minm = min(c, minm);
  return minm;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0)
    cout << "1\n";
  else
    cout << mini(n / 2, n - m, m) << endl;
}


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

public class Main {

    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);
    long mod = (long)1e9+7;
    int ma = (int)1e5;

    // main code
    void solve(){
        int n = in.ni(), cnt = 0, x = 0;
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.ni();
            if(x!=a[i]){
                a[cnt++] = a[i];
                x = a[i];
            }
        }
        n = cnt;
        int[][] dp = new int[n][n];
        for(int l = 2;l<=n;l++){
            for(int i=0,j = l-1;j<n;i++,j++){
                if(a[i]==a[j])dp[i][j] = j-i>1?dp[i+1][j-1] + 1:0;
                else dp[i][j]=Math.min(dp[i+1][j],dp[i][j-1])+1;
            }
        }
        out.println(dp[0][n-1]);
    }

    void run(){
        solve();
        // out.flush();
        out.close();
    }
    public static void main(String[] args) {
        new Main().run();
    }
    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
        int nextInt(){return Integer.parseInt(in.next());}
        long nextLong(){return Long.parseLong(in.next());}
        double nextDouble(){return Double.parseDouble(in.next());}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}
    }
    class Edges{
        int u,v,w;
        public Edges(int u,int v,int w){
            this.u = u;
            this.v = v;
            this.w = w;
        }
    }
    void pn(Object o){out.println(o);out.flush();}
    long inv(long a, long b){return 1<a ? b - inv(b%a,a)*b/a : 1;}//a^(-1)%b
    long fe(long a,long b){
        long ans = 1L;
        while(b>0){
            if((b&1)>0)ans=ans*a%mod;
            a = a%mod*a%mod;
            b>>=1;
        }
        // pn("ans = "+ans);
        return ans;
    }
    long gcd(long a,long b){
        if(a==0)return b;
        return gcd(b%a,a);
    }
    class pair{
        int f,s;
        public pair(int f,int s){
            this.f = f;
            this.s = s;
        }
    }
}

def run_length_compress(string):
    string = string + ["."]
    n = len(string)

    begin = 0
    end = 1
    cnt = 1
    ans = []
    while True:
        if end >= n:
            break
        if string[begin] == string[end]:
            end += 1
            cnt += 1
        else:
            ans.append(string[begin])
            begin = end
            end = begin + 1
            cnt = 1

    return ans

def lps(string):
    n = len(string)
    dp = [[0]*n for _ in range(n)]

    for i in range(n):
        dp[i][i] = 1

    for cl in range(2, n+1):
        for i in range(n-cl+1):
            j = i + cl - 1

            if string[i] == string[j] and cl == 2:
                dp[i][j] = 2
            elif string[i] == string[j]:
                dp[i][j] = dp[i+1][j-1] + 2
            else:
                dp[i][j] = max(dp[i][j-1], dp[i+1][j])

    return dp[0][n-1]

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

a = run_length_compress(a)
len_pal = lps(a)
print(len(a) - 1 - len_pal//2)


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.Math.max;
import static java.lang.Math.sqrt;
import static java.lang.Integer.signum;

@SuppressWarnings("unchecked")
public class P1095C {

  public void run() throws Exception {
    int n = nextInt(), k = nextInt();

    if ((Integer.bitCount(n) > k) || (n < k)) {
      println("NO");
      return;
    }

    PriorityQueue<Integer> pq = new PriorityQueue(k, Comparator.reverseOrder());

    for (int b = 1 << 30; b != 0; b >>= 1) {
      if ((n & b) != 0) {
        pq.add(b);
      }
    }

    while (pq.size() < k) {
      int b = pq.element() >> 1;
      pq.remove();
      pq.add(b);
      pq.add(b);
    }

    println("YES");
    pq.forEach(this::println);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P1095C().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

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

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  long gcd(long a, long b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  void shuffle(int [] a) {
    Random r = new Random();
    for (int i = a.length - 1; i >= 0; i--) {
      int j = r.nextInt(a.length);
      int t = a[i]; a[i] = a[j]; a[j] = t;
    }
  }

  void shuffle(long [] a) {
    Random r = new Random();
    for (int i = a.length - 1; i >= 0; i--) {
      int j = r.nextInt(a.length);
      long t = a[i]; a[i] = a[j]; a[j] = t;
    }
  }

  void shuffle(Object [] a) {
    Random r = new Random();
    for (int i = a.length - 1; i >= 0; i--) {
      int j = r.nextInt(a.length);
      Object t = a[i]; a[i] = a[j]; a[j] = t;
    }
  }

  void flush() {
    pw.flush();
  }

  void pause() {
    flush();
    System.console().readLine();
  }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l, r;
  cin >> l >> r;
  cout << "YES\n";
  long long i;
  for (i = l; i <= r; i += 2) cout << i << ' ' << i + 1 << endl;
}

l,r=map(int,input().split())
print('YES')
for i in range((r-l+1)//2):
    print(l+i*2,l+i*2+1)


/**
 *
 */
//package codeforces;
import java.util.*;
/**
 * @author Shivansh Singh
 *
 */
public class Cf102B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int i,j,c=0,l,n;
		String str=sc.next();
		while(str.length()!=1) {
			c++;
			n=0;
			for (i=0;i<str.length();i++)
				n+=(int)str.charAt(i)-48;
			str=Integer.toString(n);
		}
		System.out.println(c);
		sc.close();
	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int c = 0;
  cin >> s;
  long long int n = 0, t;
  if (s.size() == 1) {
    cout << c;
    exit(0);
  }
  for (int i = 0; i < s.size(); ++i) {
    n += s[i] - '0';
  }
  c++;
  t = n;
  while (n / 10) {
    n = 0;
    while (t > 0) {
      n += t % 10;
      t /= 10;
    }
    c++;
    t = n;
  }
  cout << c << "\n";
}


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

import java.util.Scanner;

public class A72 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(3 * n / 2);
    }
}


#include <bits/stdc++.h>
using namespace std;
int a[200005], ans[200005];
queue<int> q;
const int sb = 1e5;
int main() {
  int n;
  cin >> n;
  q.push(-1000000);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) q.push(i);
  }
  q.push(1000000);
  int x = q.front();
  q.pop();
  int y = q.front();
  for (int i = 1; i <= n; i++) {
    if (i <= y) {
      ans[i] = min(i - x, y - i);
    } else {
      x = y;
      q.pop();
      y = q.front();
      ans[i] = min(i - x, y - i);
    }
    cout << ans[i] << " ";
  }
}

/**
 * Created by Martin on 4/28/2017.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.PrintWriter;

public class Main {

    public static void main(String[]args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }
        int[] d = new int[N];
        int lz = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            if (a[i]==0)lz = i;
            d[i] = (lz == Integer.MAX_VALUE) ? lz : Math.abs(i - lz);
        }
        lz = Integer.MAX_VALUE;
        for (int i = N-1; i >= 0; i--) {
            if (a[i]==0)lz = i;
            d[i] = Math.min(d[i], (lz == Integer.MAX_VALUE) ? lz : Math.abs(i - lz));
        }
        for (int i = 0; i < N; i++) {
            pw.print(d[i] + " ");
        }
        pw.println();
        pw.flush();
    }

    public static void debug(Object...args) {
        System.out.println(Arrays.deepToString(args));
    }
}


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

public class Main {

    static int counter;

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        long [] array = new long[n];

        long type1 = -1,type2 = -1,type3=-1;
        boolean can = true;
        for(int i =0;i<n;++i){
            long input = in.nextLong();
            if(!can)continue;
            if(type1 == -1 || type1 == input){
                type1 = input;
                continue;
            }
            if(type2 == -1|| type2 == input){
                type2 = input;
                continue;
            }
            if(type3 == -1|| type3 == input){
                type3 = input;
                continue;
            }
            can = false;
        }

        if(can){
            if(type1 == -1 || type2 == -1||type3 == -1){
                System.out.println("YES");
                return;
            }
            if(max(type1,type2,type3) - midle(type1,type2,type3) == midle(type1,type2,type3) - min(type1,type2,type3)){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

    static long midle(long l1,long l2,long l3){
       if(l1>min(l1,l2,l3)&&l1<max(l1,l2,l3))return l1;
        if(l2>min(l1,l2,l3)&&l2<max(l1,l2,l3))return l2;
       return l3;
    }
    static long max(long l1,long l2,long l3){
        if(l1<l2&&l2>l3) return l2;
        if(l2<l1&&l1>l3)return l1;
        return l3;
    }
    static long min(long l1,long l2,long l3){
        if(l1>l2&&l2<l3) return l2;
        if (l2>l1&&l1<l3)return l1;
        return l3;
    }

}

n=int(input())
s=set()
L=[ int(x) for x in input().split() ]
for i in L :
    s.add(i)
if ( len(s) > 3 ) :
    print("NO")
elif (len(s) == 1 or len(s) == 2 ) :
    print("YES")
else :
    L=[]
    for i in s :
        L.append(i)
    L.sort()
    a,b,c = L[0], L[1], L[2]
    if ( b-a == c-b ):
        print("YES")
    else :
        print("NO")


"""
Oh, Grantors of Dark Disgrace,
Do Not Wake Me Again.
"""

from collections import Counter

n, k = map(int, input().split())
cc = Counter(map(int, input().split()))
coins = 0

while cc[k] != n:
    t = 0
    for i in range(1, k):
        if t+1 <= cc[i]:
            cc[i] -= 1
            cc[i+1] += 1
            t = 1
        else:
            t = 0
    coins += 1

print(coins)

#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 6, nBits = 2e8 + 5, M = (1 << 16), MAX = 1111,
          OO = 0x3f3f3f3f, MOD = 1e9 + 7, inf = 1 << 30;
const long long INF = (long long)1e18;
long long GCD(long long a, long long b) { return !b ? a : GCD(b, a % b); }
long long LCM(long long x, long long y) { return (x * y / GCD(x, y)); }
long long fact(long long z) { return (z <= 1) ? 1 : z * fact(z - 1); }
int n, k, x, A[N], freq[111], ans, last;
bool f;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", A + i);
  while (A[0] < k) {
    ++ans;
    last = k;
    for (int i = n - 1; ~i; --i)
      if (A[i] != last) last = A[i]++;
  }
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  long double n;
  int m;
  cin >> n >> m;
  long sum = n;
  long double newsum = 0.0;
  for (int i = 0; i < n; i++) {
    newsum += pow((long double)i / (long double)n, m);
  }
  cout << sum - newsum;
}

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

public class Main{

	static int mod=(int)1e9+7;

	public static void main(String[] args) throws IOException {
		PrintWriter out=new PrintWriter(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
//		ts=in.nextInt();
		outer: while(ts-->0) {

			//let us say she gets max x dots in n
			//then choose 1 toss in which x came and in all the other
			//tosses anything from 1 to x-1 could come

			int m=in.nextInt();
			int n=in.nextInt();

			double ans=0;

			for(double i=1; i<=m; ++i) {
				double tmp=(ppow(i/m, n)-ppow((i-1)/m,n));
				tmp*=i;
				ans+=tmp;
			}

			out.println(ans);

		}
		out.close();
	}

	static double ppow(double a, int b){
	    if(b==0) return 1;
	    double tmp=ppow(a,b/2);
	    if(b%2==0) return tmp*tmp;
	    else return tmp*tmp*a;

	}

	static void sort(int [] a) {
		List<Integer> l=new ArrayList<>();
		for(int i: a) l.add(i);
		Collections.sort(l);
		for(int i=0; i<a.length; i++) a[i]=l.get(i);
	}

	static class Reader{
		BufferedReader br;
		StringTokenizer to;
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());
				}catch(IOException e) {}

			}
			return to.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}

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

}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import sun.misc.Queue;

/**
 *
 * @author Mojtaba
 */
public class Main {

    static ArrayList<Edge>[] graph;
    static Stack<Integer> stack;
    static boolean[] visited;
    static int time;
    static int[] lowlink;
    private static List<List<Integer>> components;

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        StringBuilder sb = new StringBuilder();
        //String str = reader.readLine();
        PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int n = Integer.parseInt(reader.readLine());
        graph = new ArrayList[n];
        for (int i = 0; i < graph.length; i++) {
            graph[i] = new ArrayList<>();
            StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
            for (int j = 0; j < n; j++) {
                int temp = Integer.parseInt(tokenizer.nextToken());
                if (temp > 0) {
                    graph[i].add(new Edge(j));
                }
            }
        }
        sb.append(scc().size() == 1 ? "YES" : "NO");

        writer.println(sb.toString().trim());
        writer.close();
        reader.close();
    }

    static List<List<Integer>> scc() {
        int n = graph.length;
        visited = new boolean[n];
        stack = new Stack<>();
        time = 0;
        lowlink = new int[n];
        components = new ArrayList<>();

        for (int u = 0; u < n; u++) {
            if (!visited[u]) {
                dfs(u);
            }
        }

        return components;
    }

    static void dfs(int u) {
        lowlink[u] = time++;
        visited[u] = true;
        stack.add(u);
        boolean isComponentRoot = true;

        for (Edge edge : graph[u]) {
            int v = edge.to;
            if (!visited[v]) {
                dfs(v);
            }
            if (lowlink[u] > lowlink[v]) {
                lowlink[u] = lowlink[v];
                isComponentRoot = false;
            }
        }

        if (isComponentRoot) {
            List<Integer> component = new ArrayList<>();
            while (true) {
                int x = stack.pop();
                component.add(x);
                lowlink[x] = Integer.MAX_VALUE;
                if (x == u) {
                    break;
                }
            }
            components.add(component);
        }
    }

    static int log(long a, long b) {
        if (a == 0 || a == 1) {
            return 0;
        }
        if (a == b) {
            return 1;
        }
        int log = 0;
        while (a > 0) {
            a /= b;
            log++;
        }
        return log;
    }

    static long pow(long a, long b) {
        if (a == 0) {
            return 0;
        }
        if (a == 1) {
            return 1;
        }
        long answer = 1;
        for (long i = 0; i < b; i++) {
            answer *= a;
        }
        return answer;
    }
}

class Edge {

    int to;

    public Edge(int to) {
        this.to = to;
    }
}

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

#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> adj[2005];
int num[2005], low[2005], cnt;
void dfs(int u) {
  low[u] = num[u] = ++cnt;
  for (int i = (0), _b = ((int)adj[u].size() - 1); i <= _b; i++) {
    int v = adj[u][i];
    if (num[v])
      low[u] = min(low[u], num[v]);
    else {
      dfs(v);
      low[u] = min(low[u], low[v]);
    }
  }
  if (u != 1 && num[u] == low[u]) {
    cout << "NO" << endl;
    exit(0);
  }
}
int main(void) {
  scanf("%d", &N);
  char x = getchar();
  for (int i = (1), _b = (N); i <= _b; i++)
    for (int j = (1), _b = (N); j <= _b; j++) {
      while ('0' <= x && x <= '9') x = getchar();
      x = getchar();
      if (x != '0') adj[i].push_back(j);
    }
  dfs(1);
  for (int i = (1), _b = (N); i <= _b; i++)
    if (!num[i]) return cout << "NO" << endl, 0;
  cout << "YES" << endl;
  return 0;
}


n,m,d=map(int,input().split())
x=[]
y=[]
for i in range(n):
    a=list(map(int,input().split()))
    y+=a
    x.append(a)
y.sort()
e=y[(0+n*m-1)//2]
a=x[0][0]%d
count=0
ans=0
for i in x:
    for j in range(len(i)):
        if(i[j]%d!=a):
            pass
        else:
            count+=1
            ans+=(max(i[j],e)-min(i[j],e))//d
if(count==n*m):
    print(ans)
else:
    print(-1)

import java.util.*;
import java.io.*;
public class PoloPenguinAndMatrix {
    public static void main(String[] args) throws Exception {
        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());
        int d = Integer.parseInt(st.nextToken());
        List<Integer> arr = new ArrayList<>();
        for(int i=0; i<n; i++){
            st = new StringTokenizer(br.readLine());
            for(int j=0; j<m; j++){
                arr.add(Integer.parseInt(st.nextToken()));
            }
        }
        Object[] myarr = arr.toArray();
        Arrays.sort(myarr);
        int count = 0;
        for(int i=0; i<myarr.length; i++){
            if(((int)myarr[i] - (int)myarr[myarr.length/2])%d != 0){
                count = -1;
                break;
            }
            else{
                count += Math.abs(((int)myarr[i] - (int)myarr[myarr.length/2])/d);
                // System.out.println(myarr[i] + " - " + myarr[myarr.length/2] + " \\/ " + d);
            }
        }
        System.out.println(count);
    }
}


from collections import defaultdict
n, m = map(int, input().split())
r, p = [0] * n, defaultdict(list)
i = d = 0
while i < n - m:
    for j in range(i, i + m):
        t, x = map(int, input().split())
        p[x].append(j)
    d = max(t, d)
    y = sorted(p.keys())
    for x in y:
        for j in p[x]: r[j] = d + x
        d += 1 + len(p[x]) // 2
    d += 2 * y[-1]
    p.clear()
    i += m
for j in range(i, n):
    t, x = map(int, input().split())
    p[x].append(j)
if p:
    d = max(t, d)
    y = sorted(p.keys())
    for x in y:
        for j in p[x]: r[j] = d + x
        d += 1 + len(p[x]) // 2
print(' '.join(map(str, r)))

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > A(n);
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i].first >> A[i].second;
    ans[i] = A[i].first;
  }
  int count = 0, ololo = 0, lastx;
  int i = 0, j;
  while (i < n) {
    j = i;
    map<int, int> B;
    map<int, vector<int> > C;
    while (j < n && count < m) {
      B[A[j].second]++;
      C[A[j].second].push_back(j);
      count++, j++;
    }
    int time = max(ololo, A[j - 1].first), prev = 0;
    for (map<int, int>::iterator z = B.begin(); z != B.end(); z++) {
      time += z->first - prev;
      prev = z->first;
      for (int p = 0; p < C[z->first].size(); p++) ans[C[z->first][p]] = time;
      time += 1 + z->second / 2;
    }
    count = 0;
    ololo = time + prev;
    i = j;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int n, flg = 1, tot;
basic_string<int> v[1 << 17];
void dfs(int p, int f = 0, int dep = 1) {
  int fs = 1;
  for (int i : v[p])
    if (i != f) {
      if (v[i].size() == 1) {
        if (fs) fs = 0, tot += dep != 2;
      } else
        tot++;
      if (v[i].size() == 1 && (dep & 1)) flg = 0;
      dfs(i, p, dep + 1);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x] += y, v[y] += x;
  }
  for (int i = 1; i <= n; i++)
    if (v[i].size() == 1) {
      dfs(i);
      printf("%d %d\n", flg ? 1 : 3, tot);
      break;
    }
  return 0;
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskB {
        ArrayList<Integer>[] tree;
        boolean[] leaf;
        int[] cntLeaves;
        boolean odd = false;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            tree = new ArrayList[N];
            leaf = new boolean[N];
            cntLeaves = new int[N];
            for (int i = 0; i < N; i++) {
                tree[i] = new ArrayList<>();
            }
            for (int i = 0; i < N - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                tree[a].add(b);
                tree[b].add(a);
            }
            for (int i = 0; i < N; i++) {
                if (tree[i].size() == 1) {
                    leaf[i] = true;
                    for (int ch : tree[i]) {
                        cntLeaves[ch]++;
                    }
                }
            }
            int max = N - 1;
            for (int i = 0; i < N; i++) {
                if (cntLeaves[i] >= 2) {
                    max -= cntLeaves[i] - 1;
                }
            }
            for (int i = 0; i < N; i++) {
                if (!leaf[i]) {
                    dfs(i, i);
                    break;
                }
            }
            int min = 1;
            if (odd) {
                min = 3;
            }
            out.println(min);
            out.println(max);
        }

        int[] dfs(int n, int p) {
            if (leaf[n]) {
                return new int[]{1, 0};
            }
            int[] a = new int[]{0, 0};
            for (int ch : tree[n]) {
                if (ch != p) {
                    int[] b = dfs(ch, n);
                    a[0] += b[1];
                    a[1] += b[0];
                }
            }
            if (a[1] > 0 && a[0] > 0) {
                odd = true;
            }
            return a;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}


def main():
    n, m = map(int, input().split())
    l = list(list(map(int, input().split()))[::-1] for _ in range(n))[::-1]
    for r0, r1 in zip(l, l[1:-1]):
        for i, a in enumerate(r1[1:-1], 1):
            if not a:
                r1[i] = min(r1[i - 1], r0[i]) - 1
    print(sum(map(sum, l)) if all(r1[i - 1] > a < r0[i] for r0, r1 in zip(l, l[1:]) for i, a in enumerate(r1[1:], 1))
                              and all(a < b for a, b in zip(l[0][1:], l[0])) and all(
        r1[0] < r0[0] for r0, r1 in zip(l, l[1:])) else -1)

if __name__ == '__main__':
    main()


import sys, os, re, datetime
from collections import *
from bisect import *
def mat(v, *dims):
    def submat(i):
        if i == len(dims)-1: return [v for _ in range(dims[-1])]
        return [submat(i+1) for _ in range(dims[i])]
    return submat(0)
__cin__ = None
def cin():
    global __cin__
    if __cin__ is None: __cin__ = iter(input().split(" "))
    try: return next(__cin__)
    except StopIteration:
        __cin__ = iter(input().split(" "))
        return next(__cin__)
def iarr(n): return [int(cin()) for _ in range(n)]
def farr(n): return [float(cin()) for _ in range(n)]
def sarr(n): return [cin() for _ in range(n)]
def carr(n): return input()
def imat(n, m): return [iarr(m) for _ in range(n)]
def fmat(n, m): return [farr(m) for _ in range(n)]
def smat(n, m): return [sarr(m) for _ in range(n)]
def cmat(n, m): return [input() for _ in range(n)]

n = int(cin())
m = int(cin())
h = int(cin())
mv = iarr(m)
nv = iarr(n)
tv = imat(n, m)
ans = mat(0, n, m)

for i in range(n):
    for j in range(m):
        if tv[i][j] == 1: ans[i][j] = nv[i]
for j in range(m):
    for i in range(n):
        if tv[i][j] == 1: ans[i][j] = min(ans[i][j], mv[j])
for _r in ans:
    for v in _r:
        sys.stdout.write(str(v)+" ")
    print()

import java.util.Scanner;

/**
 *
 * @author hossam
 */
public class Ps {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),m=in.nextInt(),h=in.nextInt();
        int[] a=new int[m],b=new int[n];
        for(int i =0;i<m;i++)
        {
            a[i]=in.nextInt();
        }
        for(int i =0;i<n;i++)
        {
            b[i]=in.nextInt();
        }
        int y;
        int[][] x=new int[n][m];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                y=in.nextInt();
                if(y==1)
                {
                    x[i][j]=Math.min(a[j], b[i]);
                }
                else
                {x[i][j]=0;}
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                System.out.print(x[i][j]+" ");
            }
            System.out.println("");
        }
    }}


def heist(n,a):
    return max(a)-min(a)-n+1

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

import java.util.*;
import java.math.*;
public class Hie
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long a[]=new long[n];
for(int i=0;i<n;i++)
a[i]=sc.nextLong();
Arrays.sort(a);
long s=0;
for(int i=0;i<n-1;i++)
{
if(a[i+1]-a[i]>1)
s=s+(a[i+1]-a[i]-1);
}
System.out.print(s);

}
}


import java.util.*;
import java.math.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class a{
     static int[] count,count1,count2;
     static int[] arr;
     static char[] ch,ch1;
     static int[] darr,farr;
     static Character[][] mat,mat1;
     static long x,h;
     static long maxl;
     static double dec;
     static String s;
     static long minl;
     static int mx = (int)1e9+5;
     static long mod = 998244353l;
     // static int minl = -1;
     // static long n;
     static int n,n1,n2;
     static long a;
     static long b;
     static long c;
     static long d;
     static long y,z;
     static int m;
     static long k;
     static String[] str,str1;
     static Set<Character> set,set1,set2;
     static List<Integer> list,list1,list2;
     static LinkedList<Character> ll;
     static Map<Integer,Integer> map;
     static StringBuilder sb,sb1,sb2;

     // public static boolean solve(){

     //    FastScanner sc = new FastScanner();
     //    int n = sc.nextInt();
     //    for(int i = 0 ; i <  n ; i++){
     //        int a = sc.nextInt();
     //        int b = sc.nextInt();
     //    }

     // }

     public static void solve(){

        sb = new StringBuilder();
        sb1 = new StringBuilder();

        for(int i = 1 ; i <= n;  i++){
            sb1.append(ch[i-1]);
            if(n%i == 0){
                sb1 = sb1.reverse();
                for(int j = 0 ; j < i ; j++){
                    ch[j] = sb1.charAt(j);
                }
                // System.out.println(sb1);
            }
        }

        for(int i = 0; i < n ; i++)
            sb.append(ch[i]);
        System.out.println(sb);

     }

     public static void main(String[] args) {

            FastScanner sc = new FastScanner();
            // Scanner sc = new Scanner(System.in);
            // int t = sc.nextInt();
            int t = 1;
            // int l = 1;
            while(t > 0){

                // a = sc.nextLong();
                // b = sc.nextLong();
                // c = sc.nextLong();
                // d = sc.nextLong();

                // x = sc.nextLong();
                // y = sc.nextLong();

                // n = sc.nextLong();
                n = sc.nextInt();
                // n1 = sc.nextInt();

                // m = sc.nextInt();

                // k = sc.nextLong();

                ch = sc.next().toCharArray();
                // ch1 = sc.next().toCharArray();

                // arr = new int[n];
                // for(int i = 0 ; i < n ; i++){
                //     arr[i] = sc.nextInt();
                // }

                // darr = new int[n];
                // for(int i = 0; i < n ; i++){
                //     darr[i] = sc.nextInt();
                // }

                // farr = new int[n];
                // for(int i = 0; i < n ; i++){
                //     farr[i] = sc.nextInt();
                // }

                // mat = new Character[n][m];
                // for(int i = 0 ; i < n ; i++){
                //     String s = sc.next();
                //     for(int j = 0 ; j < m ; j++){
                //         mat[i][j] = s.charAt(j);
                //     }
                // }
                // str = new String[n];
                // for(int i = 0 ; i < n ; i++)
                //     str[i] = sc.next();

                // System.out.println(solve()?"YES":"NO");
                 solve();
                 // System.out.println(solve());
                 t -= 1;
            }

     }

    public static int log(long n){

         if(n == 0 || n == 1)
             return 0;

         if(n == 2)
             return 1;

         double num = Math.log(n);
         double den = Math.log(2);

         if(den == 0)
             return 0;

         return (int)(num/den);
     }

    public static boolean isPrime(long n) {
    // Corner cases
        if (n <= 1)
            return false;

        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n%2 == 0 || n%3 == 0)
            return false;

        for (int i=5; i*i<=n; i=i+6)
            if (n%i == 0 || n%(i+2) == 0)
               return false;

        return true;
    }

     public static long gcd(long a,long b){

        if(b%a == 0)
            return a;

        return gcd(b%a,a);

     }

     // public static void swap(int i,int j){
     //     long temp = arr[j];
     //     arr[j] = arr[i];
     //     arr[i] = temp;
     // }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n);
            long temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }

    static class Node{
        int first;
        int second;
        Node(int f,int s){
            this.first = f;
            this.second = s;
        }
    }

     static class FastScanner {

                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st=new StringTokenizer("");
                String next() {
                        while (!st.hasMoreTokens())
                                try {
                                        st=new StringTokenizer(br.readLine());
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        return st.nextToken();
                }

                int nextInt() {
                        return Integer.parseInt(next());
                }
                int[] readArray(int n) {
                        int[] a=new int[n];
                        for (int i=0; i<n; i++) a[i]=nextInt();
                        return a;
                }
                long nextLong() {
                        return Long.parseLong(next());
                }
        }

}

#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> v;
int main() {
  int n;
  cin >> n >> s;
  for (int i = 2; i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
    }
  }
  int len = s.size();
  for (int x = 0; x < (int)v.size(); x++) {
    int i = v[x];
    string s1 = s.substr(0, i);
    string s2 = s.substr(i, len - i);
    reverse(s1.begin(), s1.end());
    s = s1 + s2;
  }
  cout << s << endl;
}


n = int(input()) + 1
if n == 1:
	print(0)
	exit()

if n % 2 == 0:
	print(n //2)
else:
	print(n)

42
I hope this helps. Let me know if you have any further questions or need additional assistance.

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

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

            long n = sc.nextLong();

            if(n == 0)
            {
                  System.out.println("0");
            }
            else if(n%2 == 0)
            {
                  System.out.println(n+1);
            }
            else
            {
                  System.out.println((n+1)/2);
            }
      }
}


#include <bits/stdc++.h>
using namespace std;
long long N, P;
double M;
int main() {
  scanf("%lld", &N);
  if (N < 10) {
    printf("1\n");
    return 0;
  }
  long long k = 10;
  while (k * 10 <= N) k *= 10;
  M = N;
  M /= k;
  P = (long long)ceil(M) * k;
  if (P == N) P += k;
  cout << P - N << endl;
}

import math

a = int(input())
#print(math.log(a))
b = int(10 ** ((math.log(a+1) // math.log(10))))
#print(b)
total = b
while total <= a:
  total += b
print(str(total-a))


#include <bits/stdc++.h>
using namespace std;
long long fact[200001];
long long invFact[200001];
long long mod = 1000 * 1000 * 1000 + 7;
long long binpow(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n & 1)
    return (binpow(x, n - 1) * x) % mod;
  else
    return binpow((x * x) % mod, n >> 1);
}
long long inv(long long x) { return binpow(x, mod - 2); }
long long calcC(int n, int k) {
  long long ans = (fact[n] * invFact[k]) % mod;
  return (ans * invFact[n - k]) % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  fact[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  invFact[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    invFact[i] = (invFact[i - 1] * inv(i)) % mod;
  }
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans = (ans + calcC(n - 2 + i, i) * 2 * (n - i)) % mod;
  }
  cout << (ans + n) % mod;
  return 0;
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

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

	long N;
	long MOD = 1000000007L;
	BigInteger BMOD = BigInteger.valueOf(MOD);
	long ans = 1L;

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		N = nextInt();

		for (long x = 1L; x <= N; x++) {
			ans = (ans * ((N + x) % MOD)) % MOD;
			long inv = BigInteger.valueOf(x).modInverse(BMOD).longValue();
			ans = (ans * inv) % MOD;
		}

		ans = (ans + MOD - N) % MOD;
		out.println(ans);
		out.close();
	}

//	void rec(int pos, int last) {
//		if (pos == N) {
//			ans++;
//			return;
//		}
//		for (int i = last; i <= N; i++)
//			rec(pos + 1, i);
//	}

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

		return st.nextToken();
	}

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

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

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

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

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();

			if (s == null) {
				return true;
			}

			st = new StringTokenizer(s);
		}

		return false;
	}
}


n = int(input())
a_list = list(map(int, list(str(input()).split(" "))))

out = [' '*(sum(a_list))]*2000
cur,pref_size = 1000, 0
cur_max, cur_min = 1000,1000
for k in range(n):
    for i in range(a_list[k]):
        ind = pref_size + i
        if k % 2 == 0:
            out[cur] = out[cur][:ind] + '/' + out[cur][ind+1:]
            cur += 1
        else:
            out[cur] = out[cur][:ind] + '\\' + out[cur][ind+1:]
            cur -= 1

    if k % 2 == 1:
        cur += 1
        cur_min = min(cur_min, cur)
    else:
        cur -= 1
        cur_max = max(cur_max, cur)

    pref_size += a_list[k]

for i in range(cur_max,cur_min-1,-1):
    print(out[i])

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

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

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int median = 1002;
        byte b[][] = new byte[2014][1012];
        int x = 0;
        int y = median;
        int newX = x;
        int newY = median;
        int minY = median;
        int maxY = median;

        for (int i = 0; i < n; i++) {
            x = newX;
            y = newY;
            newX = newX + a[i];
            newY = newY - (a[i]-1) * (i%2==0?1:-1);
            minY = Math.min(minY, newY);
            maxY = Math.max(maxY, newY);
            boolean up = i%2==0;
            for (; x < newX; x++) {
                if(up) {
                    b[y][x] = 1;
                    y--;
                } else  {
                    b[y][x] = -1;
                    y++;
                }
            }

        }
        int maxX = x;
        StringBuilder sb = new StringBuilder();
        for (int i = minY; i <=maxY; i++) {
            for (int j = 0; j < maxX; j++) {
                switch(b[i][j]) {
                    case 0:
                        sb.append(' ');
                        break;
                    case 1:
                        sb.append('/');
                        break;
                    case -1:
                        sb.append('\\');

                        break;
                }
            }
            sb.append('\n');
        }
        out.println(sb);

    }
}

class InputReader  extends BufferedReader {
    public InputReader(InputStream st) {
        super(new InputStreamReader(st));
    }

    public int nextInt() {
        try {
            int c = read();

            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new RuntimeException();
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

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

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

}


#!/usr/bin/python
import re
import inspect
from sys import argv, exit

def rstr():
    return input()

def rstrs(splitchar=' '):
    return [i for i in input().split(splitchar)]

def rint():
    return int(input())

def rints(splitchar=' '):
    return [int(i) for i in rstrs(splitchar)]

def varnames(obj, namespace=globals()):
    return [name for name in namespace if namespace[name] is obj]

def pvar(var, override=False):
    prnt(varnames(var), var)

def prnt(*args, override=False):
    if '-v' in argv or override:
        print(*args)

# Faster IO
pq = []
def penq(s):
    if not isinstance(s, str):
        s = str(s)
    pq.append(s)

def pdump():
    s = ('\n'.join(pq)).encode()
    os.write(1, s)

if __name__ == '__main__':
    s1 = [c for c in rstr()]
    s2 = [c for c in rstr()]

    counts1 = [len([c for c in s1 if ord(c)==ch]) for ch in range(ord('a'), ord('z')+1)]
    counts2 = [len([c for c in s2 if ord(c)==ch]) for ch in range(ord('a'), ord('z')+1)]

    total = 0
    for c1, c2 in zip(counts1, counts2):
        if c2 != 0 and c1 == 0:
            print('-1')
            exit(0)
        if c2 > c1:
            ans = c1
        else:
            ans = c2
        total += ans

    print(total)

/**
 * File              : B.java
 * Author            : Bao To Hoai
 * Date              : 02.11.2020 13:56:25 UTC+7
 * Last Modified Date: 02.11.2020 14:04:25 UTC+7
 * Last Modified By  : Bao To Hoai
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        String s1 = fs.next();
        String s2 = fs.next();
        int[] cnt1 = new int[26];
        int[] cnt2 = new int[26];
        for (char c : s1.toCharArray()) {
            cnt1[c - 'a']++;
        }
        for (char c : s2.toCharArray()) {
            cnt2[c - 'a']++;
        }
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            if (cnt2[i] > 0 && cnt1[i] == 0) {
                System.out.println("-1");
                return;
            }
            if (cnt2[i] > 0 && cnt1[i] > 0) {
                ans += Math.min(cnt1[i], cnt2[i]);
            }
        }
        System.out.println(ans);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

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

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


#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  long long c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
int main() {
  long long n;
  cin >> n;
  long long arr[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    sum = sum + arr[i];
  }
  sort(arr, arr + n);
  for (long long i = 0; i < n; i++) {
    sum = sum + 2 * (i * arr[i] - (n - i - 1) * arr[i]);
  }
  long long z = GCD(sum, n);
  cout << sum / z << " " << n / z << endl;
  return 0;
}

import math
n = int(input())
l = [int(x) for x in input().split()]
a1 = sum(l)
a2 = n
a3 = 0
temp = 0
l.sort()
for i in range(n):
    temp += l[n-i-1]
    a3-=(a1-temp)
    a3+=(n-i-1)*(l[n-i-1])

a1 = a1+a3+a3
a4 = math.gcd(a1, a2)
print(a1//a4, a2//a4)


import java.util.Scanner;

public class CF197C {

    public static void main(String[] args) {
        new CF197C().solve();
    }

    private void solve() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder sb = new StringBuilder(s.length());
        char curMax = 'a';
        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            if (c >= curMax) {
                curMax = c;
                sb.append(c);
            }
        }
        for (int i = sb.length() - 1; i >= 0; i--) {
            System.out.print(sb.charAt(i));
        }
        System.out.println();
    }
}

b aa cc cb cc cbaa ccb cbba caa cbbaa cc c cb yttt cc cb aa ed cc c bbba ccbaa cccccbba ccccb cca cbb ca zzzyyxxwddddccbba cb ccc ccc ccb ccb bbb ccb c bb ccba cccccbba cb ccc ca cc ccb cc ttttsrom

#include <bits/stdc++.h>
int main() {
  char str[100005];
  int pos = 0;
  scanf("%s", str);
  for (int i = 25; i >= 0; i--) {
    for (int j = pos; str[j]; j++) {
      if (str[j] == i + 'a') {
        printf("%c", str[j]);
        pos = j;
      }
    }
  }
}


n = int(input())

gh = [0 for _ in range(n)]
arr = [gh[:] for _ in range(n) ]
visited = [gh[:] for _ in range(n)]

for i in range(n):
    a = input()
    a1 = a.split()
    for j in range(n):
        arr[i][j] = int(a1[j])

if n == 1:
    print( a)
else:
    middleR = (n - 1) // 2
    middleC = (n - 1 ) // 2
    total = 0
    for i in range(n):
        if visited[middleR][i] == 0:
            visited[middleR][i] = 1
            total += arr[middleR][i]
    #print(visited)
    for i in range(n):
        if visited[i][middleC] == 0:
            visited[i][middleC] = 1
            total += arr[i][middleC]
    #print(visited)

    for i in range(n):
        if visited[i][i] == 0:
            visited[i][i] = 1
            total += arr[i][i]
    #print(visited)
    ku = 0
    for i in range(n):
        kkt = n - 1 - i
        if visited[ku][kkt] == 0:
            visited[ku][kkt] = 1
            total += arr[ku][kkt]
        ku += 1

    #print(visited)
    print(total)

#include <bits/stdc++.h>
using namespace std;
int a[200][200];
int main() {
  int n;
  cin >> n;
  int res = 0;
  for (register int i = (1); i < (int)(n + 1); i++)
    for (register int j = (1); j < (int)(n + 1); j++) {
      cin >> a[i][j];
      if (i == j || j + i == n + 1 || j == (n + 1) / 2 || i == (n + 1) / 2) {
        res += a[i][j];
      }
    }
  cout << res << endl;
}


import java.util.*;

public class _144C_Anagram_Search {
    static int ns;
    static int np;

    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	String s = in.nextLine();
	String p = in.nextLine();
	ns = s.length();
	np = p.length();
	int[] cp = countLetters(p);
	int[] cs = countLetters(s);
	int r = 0;

	for (int i = 0; i < ns - np + 1; i++) {
	    if (isGood(cs, cp))
		r++;
	    // System.out.println(s.substring(i, i + np));
	    removeChar(cs, s.charAt(i));
	    if (i + np < ns)
		addChar(cs, s.charAt(i + np));
	}
	System.out.println(r);
    }

    private static void removeChar(int[] cs, char c) {
	if (c != '?')
	    cs[c - 'a']--;
	else
	    cs[26]--;
    }

    private static void addChar(int[] cs, char c) {
	if (c != '?')
	    cs[c - 'a']++;
	else
	    cs[26]++;
    }

    private static boolean isGood(int[] cs, int[] cp) {
	boolean ans = true;
	int q = cs[26];
	for (int i = 0; i < 27; i++)
	    if (cs[i] < cp[i])
		if (q >= cp[i] - cs[i])
		    q -= cp[i] - cs[i];
		else {
		    ans = false;
		    break;
		}
	return ans;
    }

    static int[] countLetters(String str) {
	char[] s = str.toCharArray();
	int[] c = new int[27];

	for (int i = 0; i < np && i < ns; i++)
	    if (s[i] == '?')
		c[26]++;
	    else
		c[s[i] - 'a']++;
	return c;
    }
}

s = input()
p = input()
fit = 0
cnts = {}
cntp = {}
for c in s:
    cnts[c] = cntp[c] = 0
for c in p:
    cnts[c] = cntp[c] = 0
for c in p:
    cntp[c] += 1

def extend(c):
    if c == '?':
        return
    global fit
    if cnts[c] == cntp[c]:
        fit += 1
    cnts[c] += 1

def remove(c):
    if c == '?':
        return
    global fit
    if cnts[c] == cntp[c] + 1:
        fit -= 1
    cnts[c] -= 1

if len(s) < len(p):
    print(0)
    exit(0)

ans = 0
for i in range(0, len(p)):
    extend(s[i])
if fit == 0:
    ans = 1
for i in range(0, len(s) - len(p)):
    remove(s[i])
    extend(s[i + len(p)])
    if fit == 0:
        ans += 1
print(ans)


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

public class CFD {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "YES";
    private static final String no = "NO";

    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        char[][] mat = new char[n][m];
        for (int i = 0; i < n; i++) {
            mat[i] = nextString().toCharArray();
        }

        int[][] days = new int[n][1 + m];
        for (int i = 0; i < n; i++) {
            Arrays.fill(days[i], Integer.MAX_VALUE);
            List<Integer> ls = new ArrayList<>();
            for (int j = 0; j < m; j++) {
                if (mat[i][j] == '1') {
                    ls.add(j);
                }
            }

            for (int j = ls.size(); j <= m; j++) {
                days[i][j] = 0;
            }

            int sz = ls.size();
            if (ls.size() != 0) {
                days[i][0] = ls.get(sz - 1) - ls.get(0) + 1;
                for (int j = 0; j < sz; j++) {
                    for (int k1 = j; k1 < sz; k1++) {
                        int skip = j + sz - k1 - 1;
                        int attend = ls.get(k1) - ls.get(j) + 1;
                        days[i][skip] = Math.min(days[i][skip], attend);
                    }
                }
            }
        }

//        for (int i = 0; i < n; i++) {
//            outln(Arrays.toString(days[i]));
//        }
//        outln("----");

        int[] dp = new int[1 + k];
        for (int i = 0; i < n; i++) {
            int[] dp1 = new int[1 + k];
            Arrays.fill(dp1, Integer.MAX_VALUE);
            //attend day i
            for (int j = 0; j <= k; j++) {
                for (int add = 0; add <= m; add++) {
                    if (add + j <= k) {
                        dp1[add + j] = Math.min(dp1[add + j], dp[j] + days[i][add]);
                    }
                }
            }

            dp = dp1;
        }

        int res = Integer.MAX_VALUE;
        for (int i = 0; i <= k; i++) {
            res = Math.min(res, dp[i]);
        }

        outln(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFD() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFD();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

n, m, k = map(int, input().split())
DATA = [input() for i in range(n)]

#dp[n_day][used_cost]
#ans = min(dp[n_day][used_cost] for used_cost in range(k + 1))
#dp[n_day][used_cost] := min(dp[n_day - 1][prev_cost] + cost(pay used_cost - prev_cost in n_day) for prev_cost in range(used_cost + 1))
INF = 1 << 60
dp = [[INF]*(k + 10) for i in range(n + 10)]
dp[0][0] = 0

COST = [[INF]*(k + 10) for i in range(n + 10)]
for i, string in enumerate(DATA):
    #COST[i + 1]
    stack = []
    for j in range(m):
        if string[j] == "1":
            stack.append(j)
    L = len(stack)
    for j in range(k + 10):
        if j >= L:
            COST[i + 1][j] = 0
            continue
        else:
            for pos in range(j + 1):
                l = pos
                r = pos + L - 1 - j
                COST[i+1][j] = min(COST[i+1][j], stack[r] - stack[l] + 1)
for day in range(1, n + 1):
    for used_cost in range(k + 1):
        dp[day][used_cost] = min(dp[day - 1][prev_cost] + COST[day]
                                 [used_cost - prev_cost] for prev_cost in range(used_cost + 1))

ans = min(dp[n][used_cost] for used_cost in range(k + 1))
print(ans)


import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')

def inp():
    return sys.stdin.readline().rstrip()

def mpint():
    return map(int, inp().split(' '))

def itg():
    return int(inp())

# ############################## import
# ############################## main
def main():
    a, b, p, x = mpint()
    ans = 0
    for j in range(p - 1):
        y = pow(a, p - 1 - j, p)
        by = b * y
        i = (j - by) % p  # smallest i s.t. the equation
        if i > (x - j) // (p - 1):
            continue
        ans += 1 + ((x - j) // (p - 1) - i) // p
    print(ans)

DEBUG = 0
URL = 'https://codeforces.com/contest/919/problem/E'

if __name__ == '__main__':
    # 0: normal, 1: runner, 2: interactive, 3: debug
    if DEBUG == 1:
        import requests
        from ACgenerator.Y_Test_Case_Runner import TestCaseRunner

        runner = TestCaseRunner(main, URL)
        inp = runner.input_stream
        print = runner.output_stream
        runner.checking()
    else:
        if DEBUG != 3:
            sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
        if DEBUG:
            _print = print

            def print(*args, **kwargs):
                _print(*args, **kwargs)
                sys.stdout.flush()
        main()
# Please check!

#include <bits/stdc++.h>
long long k[1005555];
long long Pow(long long a, long long b, long long p) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % p;
    a = a * a % p;
    b /= 2;
  }
  return ans;
}
int main(void) {
  long long a, b, p, x, i, xh, last, c, n, ans;
  scanf("%lld%lld%lld%lld", &a, &b, &p, &x);
  ans = 0, xh = p - 1;
  long long inv = Pow(p - 1, p - 2, p);
  for (i = 0; i <= p - 2; i++) {
    k[i] = Pow(a, i, p);
    c = Pow(k[i], p - 2, p) * b % p;
    n = (inv * ((c - i) % p) % p + p) % p;
    n = n * (p - 1) + i;
    ans += (x - n + p * (p - 1)) / (p * (p - 1));
  }
  printf("%lld\n", ans);
  return 0;
}


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

public class B {

    static BufferedReader in;
    static StringTokenizer st;

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

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

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        int[] a = new int[n + 2];
        for (int i = 1; i <= n; i++) {
            a[i] = nextInt();
        }
        a[n + 1] = Integer.MAX_VALUE;
        long ans = 0;
        long cnt = 1;
        for (int i = 2; i <= n + 1; i++) {
            if (a[i] == a[i - 1]) {
                cnt++;
            } else {
                ans += cnt * (cnt + 1) / 2;
                cnt = 1;
            }
        }
        System.out.println(ans);
    }
}

from sys import stdin, stdout
from math import factorial

n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
ans = 0

cnt = 1
for i in range(1, n):
    if values[i] != values[i - 1]:
        ans += cnt * (cnt + 1) // 2
        cnt = 1
    else:
        cnt += 1

ans += cnt * (cnt + 1) // 2

stdout.write(str(ans))


import java.util.Scanner;

/**
 * Created by prasad on 7/19/17.
 */
public class Restaurent {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int g = Integer.parseInt(in.next());
        int o = Integer.parseInt(in.next());
        int t = Integer.parseInt(in.next());
        int ocount = o;
        int tcount = t;
        int oneInTwo = 0;
        int deniedCount = 0;

        for (int i = 0; i < g; ++i) {
            int c = Integer.parseInt(in.next());
            if (c == 1) {
                if (ocount != 0) {
                    ocount--;
                } else if (tcount != 0) {
                    tcount--;
                    oneInTwo++;
                }else if(oneInTwo != 0){
                    oneInTwo--;
                } else{
                    deniedCount+=1;
                }
            } else {
                if (tcount != 0) {
                    tcount--;
                } else {
                    deniedCount+=2;
                }
            }
        }
        System.out.println(deniedCount);
    }

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, ans = 0, t;
  string s;
  cin >> n >> a >> b;
  int x, y, z;
  x = a, y = b, z = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    if (t == 1) {
      if (x > 0) {
        x--;
      } else if (y > 0) {
        y--, z++;
      } else if (z > 0)
        z--;
      else
        ans++;
    } else {
      if (y > 0)
        y--;
      else
        ans += 2;
    }
  }
  cout << ans;
  return 0;
}


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

public class MaximalGCD {

	public static FastScanner in = new FastScanner(System.in);

	public static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner(InputStream i) {
			reader = new BufferedReader(new InputStreamReader(i));
			tokenizer = new StringTokenizer("");
		}

		public String next() throws IOException {
			while (!tokenizer.hasMoreTokens())
				tokenizer = new StringTokenizer(reader.readLine());
			return tokenizer.nextToken();
		}

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

		public void close() throws IOException {
			reader.close();
		}
	}

	// variables

	public static long n, k;

	// onReads

	public static void main(String[] args) {
		try {
			n = in.nextLong();
			k = in.nextLong();
			// readValues
			// useFunctions
			// printResult
			long sumK = sum(k);
			if (k >= 141421 || n < sumK)
				System.out.println(-1);
			else {
				long ratio = n / sumK;
				if (n % ratio != 0)
					ratio = getNewRatio(n, ratio);
				for (int i = 1; i <= k - 1; i++) {
					System.out.print(ratio * i + " ");
					n -= ratio * i;
				}
				System.out.println(n);
			}
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// functions

	public static long sum(long k) {
		return k * (k + 1) / 2;
	}

	public static long getNewRatio(long n, long maxRatio) {
		long result = 1;
		for (Long i = 1l; i * i <= n; i++)
			if (n % i == 0) {
				if (n / i <= maxRatio)
					return n / i;
				else if (i <= maxRatio && i > result)
					result = i;
			}
		return result;
	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, gcd = 0;
  cin >> n >> k;
  if (k > 141420) {
    cout << "-1" << endl;
    return 0;
  }
  long long temp = sqrt(n);
  long long summ = k * (k + 1) / 2;
  for (long long i = 1; i <= temp; i++)
    if (n % i == 0) {
      if (i >= summ) {
        gcd = n / i;
        break;
      } else if (n / i >= summ)
        gcd = i;
    }
  if (!gcd) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long i = 1; i < k; i++) cout << i * gcd << " ";
  cout << gcd * (n / gcd - k * (k - 1) / 2) << endl;
}


print((2*int(input())+1)//3)

# Made By Mostafa_Khaled

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

public class VKR2A1 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(br.readLine());
		int time = 1;
		int count = 0;
		while(n > 0){
			if(n - 6 >= 0){
				n -= 6;
				count += 4;
				time += 4;
			}
			else if(time % 2 == 0){
				n--;
				count++;
				time++;
			}
			else if(n-2 >= 0){
				n-=2;;
				count++;
				time++;
			}
			else{
				n--;
				count++;
				time++;
			}
		}
		out.println(count);
		out.close();
	}
}


#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b, w;
};
vector<vector<edge> > es;
long long dfs(int u, int p) {
  long long ret = 0;
  for (int v = 0; v < es[u].size(); v++) {
    edge e = es[u][v];
    if (e.b == p) {
      ret = max(0LL, ret);
    } else {
      ret = max(ret, dfs(e.b, u) + (long long)e.w);
    }
  }
  return ret;
}
int main() {
  int n;
  long long sum;
  cin >> n;
  es.clear();
  es.resize(n + 1);
  sum = 0;
  for (int i = 0; i < n - 1; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    x;
    y;
    es[x].push_back((edge){x, y, w});
    es[y].push_back((edge){y, x, w});
    sum += w;
  }
  cout << (sum * 2 - dfs(1, -1)) << endl;
}

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

public class EternalVictory {

	static ArrayList<Pair>[]adjList;
	static boolean[]visited;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		adjList = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			adjList[i] = new ArrayList<>();
		}
		visited = new boolean[n];
		long sum = 0;
		for (int i = 0; i <n-1; i++) {
			int from = sc.nextInt()-1;
			int to = sc.nextInt()-1;
			int weight = sc.nextInt();
			adjList[from].add(new Pair(to, weight));
			adjList[to].add(new Pair(from, weight));
			sum+= 2*weight;
		}
		long max = dfs(0);
		System.out.println(sum-max);

	}
	public static long dfs(int u) {
		visited[u] = true;

		long maxWeight=0;

		for(Pair p: adjList[u]) {
			long weight = 0;
			if(!visited[p.node]) {
			weight += dfs(p.node);
			weight+= p.weight;
			}
			maxWeight= Math.max(weight, maxWeight);
		}
		return maxWeight;
	}

	static class Pair {

		int node,weight;

		Pair(int node, int weight) {
		this.node=node;
		this.weight=weight;
		}
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

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

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

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

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

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

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

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

		public void waitForInput(long time) {
			long ct = System.currentTimeMillis();
			while(System.currentTimeMillis() - ct < time) {};
		}

	}
}


#include <bits/stdc++.h>
int main() {
  int n, k, i, j;
  int hols, arr[1000];
  int temp, loop, flag = 0;
  scanf("%d%d", &n, &k);
  scanf("%d", &hols);
  for (i = 0; i <= n; i++) {
    arr[i] = 0;
  }
  for (i = 0; i < hols; i++) {
    scanf("%d", &temp);
    arr[temp] = 2;
  }
  for (i = 0; i <= n;) {
    for (j = i; j < i + k; j++) {
      if (arr[j] == 2) {
        flag = 1;
        loop = j;
      }
    }
    if (flag == 1) {
      flag = 0;
      i = loop;
    } else {
      i = i + k;
    }
    arr[i] = 1;
  }
  int min = 0;
  for (i = 1; i <= n; i++) {
    if (arr[i] == 1 || arr[i] == 2) min++;
  }
  printf("%d", min);
  return 0;
}

def searchInRange(arr: list, start: int, end: int) -> int:
    for i in range(start, end + 1):
        if i in arr:
            return i
    return -1

n, k = [int(item) for item in input().split(' ')]
holidays = [int(item) for item in input().split(' ')]
del holidays[:1]
ans, start, end = 0, 1, k

while start <= n:
    day = searchInRange(holidays, start, end)
    if day == -1 and start + k - 1 > n:
        break
    if day == -1:
        start = end + 1
    else:
        start = day + 1

    end = start + k - 1 if start + k - 1 <= n else n
    ans += 1

print(ans)


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

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

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

	private void run() throws IOException {
		if (new File("input.txt").exists())
			in = new BufferedReader(new FileReader("input.txt"));
		else
			in = new BufferedReader(new InputStreamReader(System.in));
		if (new File("output.txt").exists())
			out = new PrintWriter("output.txt");
		else
			out = new PrintWriter(System.out);

		solve();

		in.close();
		out.close();
	}

	char s[], t[];
	int n, m;

	void solve() throws IOException {
		s = nextToken().toCharArray();
		t = nextToken().toCharArray();
		n = s.length;
		m = t.length;

		int addCnt = 0;
		int iMin = 0;
		for (int i = 0; i < n && iMin < m; ++i) {
			while (iMin < m && t[iMin] != s[i])
				++iMin;
			if (iMin < m && t[iMin] == s[i]) {
				++iMin;
				++addCnt;
			}
		}
		--iMin;

		int iMax = m - 1;
		for (int i = n - 1; i >= 0 && iMax >= 0; --i) {
			while (iMax >= 0 && t[iMax] != s[i])
				--iMax;
			if (iMax >= 0 && t[iMax] == s[i]) {
				--iMax;
				++addCnt;
			}
		}
		++iMax;

		int ans = iMax - iMin;
		out.println((addCnt == 2 * n && iMin < iMax) ? ans : "0");
	}

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

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

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

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

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

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String str = in.readLine();
			if (str == null)
				return true;
			st = new StringTokenizer(str);
		}
		return false;
	}

}

#include <bits/stdc++.h>
using namespace std;
int n, fst, lst, l1, l2;
char s1[1005], s2[1000005];
int solve() {
  int pos1 = 0, ans = -1;
  for (int i = 0; i <= l2; i++) {
    if (s1[pos1] == s2[i]) pos1++;
    if (pos1 == l1) {
      ans = i;
      break;
    }
  }
  return ans;
}
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  l1 = strlen(s1);
  l2 = strlen(s2);
  fst = solve();
  if (fst == -1) {
    puts("0");
    return 0;
  }
  for (int i = 0; i < l1 >> 1; i++) swap(s1[i], s1[l1 - 1 - i]);
  for (int i = 0; i < l2 >> 1; i++) swap(s2[i], s2[l2 - 1 - i]);
  lst = solve();
  if (l2 - lst - 1 - fst < 0)
    cout << 0 << endl;
  else
    cout << l2 - lst - fst - 1 << endl;
}


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

public class R245qCGuessTheTree {

	static int n;
	static int c[];
	static int cnt[];
	static int subtree[];
	static int leafs,inter;
	static boolean dp[][],done[][];

	public static void main(String args[]) {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		n = in.nextInt();

		c = new int[n];
		for(int i=0;i<n;i++)
			c[i] = in.nextInt();

		cnt = new int[n + 1];

		for(int x : c)
			cnt[x]++;

		int minLeafs = (n + 1) >> 1;
		if(cnt[1] < minLeafs || cnt[n] != 1){
			System.out.println("NO");
			return;
		}
		else{
			leafs = cnt[1];
			inter = n - cnt[1];
			subtree = new int[inter];
			inter = 0;
			for(int x : c)
				if(x != 1)
					subtree[inter++] = x;
			Arrays.sort(subtree);
			//System.out.println(Arrays.toString(subtree));
			dp = new boolean[leafs + 1][1<<inter];
			done = new boolean[leafs + 1][1<<inter];
			w.println(go(leafs,0) ? "YES" : "NO");
		}

		w.close();
	}

	public static boolean go(int leafsLeft,int mask){
		//System.out.println(leafsLeft + " " + Integer.toBinaryString(mask));
		if(!done[leafsLeft][mask]){
			int curr = -1;
			boolean ans = false;
			for(int i=0;i<inter;i++)
				if(get(i,mask))
					curr = i;
			curr++;
			if(curr == inter)
				ans = true;

			else{
				//System.out.println("here " + curr + " " + (1<<curr));
				for(int newMask=0;newMask<(1<<curr);newMask++){
					int tot = 0;
					boolean valid = true;
					int goMask = mask | (1<<curr);
					//System.out.println(Integer.toBinaryString(newMask) + " " + Integer.toBinaryString(goMask));
					int cnt = 0;
					for(int j=0;j<curr;j++){
						if(get(j,newMask)){
							if(get(j,mask)){
								tot += subtree[j];
								goMask ^= 1 << j;
								cnt++;
							}
							else{
								valid = false;
								break;
							}
						}
					}
					//System.out.println(Integer.toBinaryString(goMask) + " " + valid + " " + cnt);
					valid &= tot < subtree[curr];
					if(valid){
						int leafsNeeded = subtree[curr] - 1 - tot;
						cnt += leafsNeeded;
						if(leafsNeeded <= leafsLeft && cnt >= 2){
							ans |= go(leafsLeft - leafsNeeded,goMask);
							if(ans)
								break;
						}
					}
				}
			}

			done[leafsLeft][mask] = true;
			dp[leafsLeft][mask] = ans;
		}
		return dp[leafsLeft][mask];
	}

	public static boolean get(int bit,int mask){
		return (mask & (1<<bit)) != 0;
	}

	public static int set(int bit,int mask){
		return mask | (1<<bit);
	}

	public static void p(int x){
		for(int i=inter-1;i>=0;i--){
			if((x & (1<<i)) != 0)
				System.out.print('1');
			else
				System.out.print('0');
		}
		System.out.println();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int snumChars;
		private SpaceCharFilter filter;

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

		public int snext() {
			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 nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			int res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

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

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

def DFS(x):

    for i in range(x):

        if(Seen[i][x]):

            continue

        if(Rem[i]>=C[x]):

            if(Rem[i]==C[x] and len(Children[i])==0):

                continue

            Rem[i]-=C[x]

            Parent[x]=i

            Children[i].append(x)

            return True

    for i in range(x):

        if(Seen[i][x]):

            continue

        Y=[]

        for j in range(len(Children[i])):

            child=Children[i][j]

            if(Seen[i][child]):

                continue

            Parent[child]=-1

            Rem[i]+=C[child]

            Seen[i][child]=True

            Seen[child][i]=True

            if(DFS(child)):

                Seen[i][child]=False

                Seen[child][i]=False

                continue

            Seen[i][child]=False

            Seen[child][i]=False

            Parent[child]=i

            Rem[i]-=C[child]

            Y.append(child)

        Children[i]=list(Y)

        if(Rem[i]>=C[x]):

            if(Rem[i]==C[x] and len(Children[i])==0):

                continue

            Rem[i]-=C[x]

            Children[i].append(x)

            Parent[x]=i

            return True

    return False

n=int(input())

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

Rem=[-1]*n

Parent=[-1]*n

Children=[]

Seen=[]

for i in range(n):

    Seen.append([False]*n)

C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):

    print("NO")

else:

    for i in range(n):

        Rem[i]=C[i]-1

        Children.append([])

    Parent[0]=0

    Ans="YES"

    for i in range(1,n):

        if(DFS(i)==False):

            Ans="NO"

            break

    for i in range(n):

        if(Rem[i]!=0 and C[i]!=1):

            Ans="NO"

            break

    print(Ans)

# Made By Mostafa_Khaled


#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  string s;
  cin >> s;
  int i;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == 'r') {
      printf("%d\n", i + 1);
    } else {
      v.push_back(i + 1);
    }
  }
  for (i = v.size() - 1; i >= 0; i--) {
    printf("%d\n", v[i]);
  }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class C {
	static BufferedReader stdin = new BufferedReader(new
			InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer("");
	public static void main(String[] args) throws Exception {
		char[] cc = readString().toCharArray();
		int N = cc.length;
		LinkedList<Integer> r = new LinkedList<Integer>(),
						    l = new LinkedList<Integer>();
		for (int i = 0; i < N; i++){
			char c = cc[i];
			if (c == 'r')
				l.addLast(i+1);
			else
				r.addFirst(i+1);
		}
		StringBuilder sb = new StringBuilder();
		for (int i : l){
			sb.append(i);
			sb.append("\n");
		}
		for (int i : r){
			sb.append(i);
			sb.append("\n");
		}
		System.out.println(sb);
	}

	static String readString() throws Exception {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(stdin.readLine());
		}
		return st.nextToken();
	}

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

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

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


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;

public class E
{
	BufferedReader in;
	PrintStream out;
	StringTokenizer tok;
	public E() throws NumberFormatException, IOException
	{
		in = new BufferedReader(new InputStreamReader(System.in));
		//in = new BufferedReader(new FileReader("in.txt"));
		out = System.out;
		run();
	}
	int bs(List<Integer> a, int x)
	{
		int l = 0;
		int h = a.size()-1;
		while(l<=h)
		{
			int m = (l+h)/2;
			if(a.get(m) < x)l = m+1;
			else h = m-1;
		}
		return l;
	}
	void run() throws NumberFormatException, IOException
	{
		long k = nextLong();
		long b = nextLong();
		int n = nextInt();

		long[] dig = new long[n];
		long[] s = new long[n+1];
		TreeMap<Long,List<Integer>> r = new TreeMap<Long,List<Integer>>();
		long c = 0;
		for(int i = 0; i < n; i++)
		{
			dig[i] = nextLong();
			c+=dig[i];
			c%=(k-1);
			if(r.containsKey(c))
			{
				List<Integer> l = r.get(c);
				l.add(i);
			}
			else
			{
				List<Integer> l = new ArrayList<Integer>();
				l.add(i);
				r.put(c, l);
			}
			s[i+1] = c;
		}
		long ans = 0;
		long zeros = 0;
		for(int i =0; i < n; i++)
		{
			List<Integer> l = r.get((b+s[i])%(k-1));
			if(l==null) continue;
			int p = bs(l,i);
			if(p < l.size()) ans+= l.size()-p;
		}
		for(int i = 0; i <n; i++)
		{
			long t = 0;
			while(i < n && dig[i]==0)
			{
				i++;
				t++;
			}
			if(t>0)
			{
				zeros += (t+1)*t/2;
				i--;
			}
		}
		if(b==0) out.println(zeros);
		else if(b==k-1) out.println(ans-zeros);
		else out.println(ans);
	}
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		new E();
	}
	String nextToken() throws IOException
	{
		if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
		return tok.nextToken();
	}
	int nextInt() throws NumberFormatException, IOException
	{
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws NumberFormatException, IOException
	{
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws NumberFormatException, IOException
	{
		return Double.parseDouble(nextToken());
	}
}

#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int n, k, b;
int main() {
  scanf("%d%d%d", &k, &b, &n);
  int k1 = k - 1;
  mp[0] = 1;
  int temp, sum = 0;
  long long ans = 0, zero = 0, tz = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &temp);
    sum = (sum + temp) % k1;
    int t = (sum - b + k1) % k1;
    ans += mp[t];
    mp[sum]++;
    if (temp == 0) {
      zero += ++tz;
    } else
      tz = 0;
  }
  long long ret = 0;
  if (b == 0)
    ret = zero;
  else if (b == k1)
    ret = ans - zero;
  else
    ret = ans;
  printf("%I64d\n", ret);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a, n, vv[10000001];
int main() {
  cin >> a >> n;
  for (int i = a; i < a + n; i++) vv[i] = i;
  for (int i = 2; i * i < (a + n); i++) {
    for (int j = 1; j * i * i < (a + n); j++) vv[j * i * i] = j;
  }
  long long sum = 0;
  for (int i = a; i < a + n; i++) sum += vv[i];
  cout << sum;
  return 0;
}


#include <bits/stdc++.h>
int main() {
  int n, i, j, m, sum, len;
  char a[101];
  while (scanf("%s", a) != EOF) {
    len = strlen(a);
    for (i = 1; i < len; i++) {
      if (a[i] < 'a')
        ;
      else
        break;
    }
    if (i != len)
      printf("%s\n", a);
    else {
      for (i = 0; i < len; i++)
        printf("%c", a[i] >= 'a' ? a[i] - 32 : a[i] + 32);
      printf("\n");
    }
  }
}

Input: aAbBcCdd
XweAR
Input: hello
Input: helloWORLD
Input: Appl
Input: heLLO
A
Input: abCd
Input: ABC
Input: ABCD
Input: ABc
Input: AABBcc
Input: Z
Zz
Input: aAbBcC
Input: HELLO
Lock
Input: AABBCCdd
Input: AbCd
Input: aBc
Input: AAbbCC
Input: HELLOworld
Input: http
Input: AaBbCcDd
Input: Http
Input: Https
Input: A
Input: z
Input: HTTP
Input: APPL
Input: HelloWorld
Input: AAbbCCdd
OOPS
Input: aBcD
Input: hELLOWorld
Input: AbC
Input: AABBccDd
zA
Input: AaBbCc
Input: ZZ
Input: HeLlO
Input: AABBCC
F
Input: aPPL
Input: Zz
Input: appl
cAPS
Input: abc
Input: https
Input: HTTPs

Input: AAbbCC
a
Input: ZZ
Input: abCd
Input: Https
Input: Appl
Input: AbCd
Input: Http
Input: ABCD
Input: hELLOWorld
Input: AABBCC
Input: HELLO
Input: abc
Input: HTTPs
Zz
Input: HTTP
Input: APPL
Input: z
Input: AABBccDd
XweAR
Input: aAbBcC
Input: HELLOworld
Lock
Input: AAbbCCdd
Caps
Input: AaBbCc
Input: aBcD
Input: hello
Input: AbC
oops
Input: HeLlO
Input: https
Input: ABC
Input: aAbBcCdd
Input: helloWORLD
Za
Input: aBc
Input: appl
Input: AABBcc
Input: AABBCCdd
Input: ABc
Input: A
Input: HelloWorld
Input: AaBbCcDd
Input: Zz
Input: heLLO
Input: http
Input: aPPL
Input: Z
f

import java.util.*;
public class CapsLock {
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		String sCap = s.substring(0,1).toUpperCase() + s.substring(1, s.length()).toLowerCase();
		String sAnti = s.substring(0,1).toLowerCase() + s.substring(1, s.length()).toUpperCase();

		if(s == s.toUpperCase())
			System.out.println(s.toLowerCase());
		else if(s.compareTo(sAnti) == 0)
			System.out.println(sCap);
		else if(s == s.toLowerCase())
			System.out.println(s);
		else
			System.out.println(s);

	}
}


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

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

    static int pow(int a, int b) {
        int ans = 1;
        for(int i = 0;i < b;i++) ans *= a;
        return ans;
    }

    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int v1[] = new int [m], v2[] = new int [m];
        for(int i = 0;i < m;i++) {
            v1[i] = sc.nextInt() - 1;
            v2[i] = sc.nextInt() - 1;
        }

        int ans = 0;
        for(int mask = 0;mask < pow(6, n);mask++) {
            int num[] = new int [n];
            for(int i = 0;i < n;i++) {
                num[i] = mask / pow(6, i) % 6;
            }

            boolean used[][] = new boolean[6][6];
            int new_ans = 0;
            for(int i = 0;i < m;i++) {
                int q1 = num[v1[i]];
                int q2 = num[v2[i]];
                if (!used[q1][q2]) {
                    new_ans++;
                    used[q1][q2] = true;
                    used[q2][q1] = true;
                }
            }
            ans = Math.max(ans, new_ans);
        }

        pw.println(ans);

        pw.close();
    }

    static Scanner sc;
    static PrintWriter pw;

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

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

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

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

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

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

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

}

#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void gen(vector<int> &A, vector<vector<int>> &G, int i) {
  if (i < G.size()) {
    for (int j = 0; j < 6; ++j) {
      A[i] = j;
      gen(A, G, i + 1);
    }
  } else {
    bool was[6][6];
    for (int a = 0; a < 6; ++a) {
      for (int b = 0; b < 6; ++b) was[a][b] = false;
    }
    for (int a = 0; a < G.size(); ++a) {
      for (int b : G[a]) {
        was[A[a]][A[b]] = true;
        was[A[b]][A[a]] = true;
      }
    }
    int res = 0;
    for (int a = 0; a < 6; ++a) {
      for (int b = 0; b <= a; ++b) res += was[a][b];
    }
    ans = max(ans, res);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> A(n);
  gen(A, G, 0);
  cout << ans;
  return 0;
}