import java.io.*;
import java.util.*;
public class __Solution {
 static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
 public static void main(String[] args) {
  new __Solution().run();
 }
 BufferedReader in ;
 PrintWriter out;
 StringTokenizer tok;
 void init() throws FileNotFoundException {
  if (ONLINE_JUDGE) { in = new BufferedReader(new InputStreamReader(System.in));
   out = new PrintWriter(System.out);
  } else { in = new BufferedReader(new FileReader("input.txt"));
   out = new PrintWriter("output.txt");
  }
  tok = new StringTokenizer("");
 }
 void run() {
  try {
   long timeStart = System.currentTimeMillis();
   init();
   solve();
   out.close();
   long timeEnd = System.currentTimeMillis();
   System.err.println("Time = " + (timeEnd - timeStart));
  } catch (Exception e) {
   e.printStackTrace();
   System.exit(-1);
  }
 }
 String readLine() throws IOException {
  return in.readLine();
 }
 String delimiter = " ";
 String readString() throws IOException {
  while (!tok.hasMoreTokens()) {
   String nextLine = readLine();
   if (null == nextLine) return null;
   tok = new StringTokenizer(nextLine);
  }
  return tok.nextToken(delimiter);
 }
 int readInt() throws IOException {
  return Integer.parseInt(readString());
 }
 long readLong() throws IOException {
  return Long.parseLong(readString());
 }
 void solve() throws IOException {
  int a[] = new int[6];
  int sum = 0;
  for (int i = 0; i < 6; i++) {
   a[i] = readInt();
   sum += a[i];
  }
  for (int i = 0; i < 6; i++)
   for (int j = i + 1; j < 6; j++)
    for (int k = j + 1; k < 6; k++) {
     if ((a[i] + a[j] + a[k])×2 == sum) {
      out.println("YES");
      return;
     }
    }
  out.println("NO");
 }
}


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

public class Main {

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

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(System.in), 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());
		}

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

	public static void main(String[] args) {
		// InputStream inputStream = System.in; // Useful when taking input other than
		// console eg file handling // check ctor of inputReader
		InputReader scn = new InputReader();

		int[] arr = new int[6];
		for(int i = 0; i < 6; i++) {
			arr[i] = scn.nextInt();
			sum += arr[i];
		}

		if(func(arr, 0, 0, 0)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	public static boolean func(int[] arr, int si, int y, int x) {
		if(si == arr.length) {
			if(x == y) {
				return true;
			}
			return false;
		}

		boolean a = func(arr, si + 1, y, x + arr[si]);
		boolean b = func(arr, si + 1, y + arr[si], x);
		return a || b;
	}
}


import com.sun.xml.internal.bind.v2.runtime.unmarshaller.IntArrayData;

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

public class PA {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer st1 = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st1.nextToken()) , k = Integer.parseInt(st1.nextToken());

        int min = Integer.MAX_VALUE;

        for(int i = 1 ; i <= k-1 ; i++)
        {
            if(n % i == 0)
            {
                min = Math.min(min , (n/i)*k + i);
            }
        }

        out.println(min);

        out.flush();
        out.close();

    }

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n, k;
		n = scanner.nextInt();
		k = scanner.nextInt();
		ArrayList<Long> possibleXs = new ArrayList<>();
		for (int i = 1; 2 * i <= k; i++) {
			if (k % i != 0) continue;
			for (int j = 0; j * k + i <= n * k; j++) {
				possibleXs.add(j * k + i);
			}
		}
		long minimum = Long.MAX_LONG;
		for (Long x : possibleXs) {
			if ((x / k) * (x % k) == n) {
				minimum = Math.min(minimum, x);
			}
		}
		System.out.println(minimum);
	}
}


import java.util.Scanner;
import java.util.stream.IntStream;

public class Solution {

	public static int[] toIntArray(String s) {
		String[] nums = s.split("\\s");
		return IntStream.range(0, nums.length)
			.map(index -> Integer.parseInt(nums[index]))
			.toArray();
	}

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int result = -1;

		int[] nk = Util.toIntArray(scanner.nextLine());

		int n = nk[0], k = nk[1];

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

			int xLow = (int) n * k / i;
			int x = xLow + i;
			if (x % k == i && ((x / k) * (x % k)) == n) {
				if (result == -1)
					result = x;
				else
					result = Math.min(result, x);
			}

		}

		System.out.println(result);

	}

}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays;

public class   technocupp2
{
  BufferedReader in;
  StringTokenizer as;
  int nums[],nums2[];
  ArrayList < Integer > [] ar;

  public static void main (String[] args)
  {
    new technocupp2  ();
  }

  public int GCD(int a, int b) {
    if (b==0) return a;
    return GCD(b,a%b);
  }

  public long stuff(int n, int k)
  {
    return (n/k) * (n % k);
  }

  public technocupp2  ()
  {
    try
    {

      in = new BufferedReader (new InputStreamReader (System.in));
      long a = nextInt();
      long b = nextInt();
      for(long x = 1;x<1000000000;x++)
      {
        if(stuff(x,b) == a)
        {
          System.out.println(x);
          break;
        }
      }
    }

    catch(IOException e)
    {

    }
  }

  String next () throws IOException
  {
    while (as == null || !as.hasMoreTokens ())
    {
      as = new StringTokenizer (in.readLine ().trim ());
    }

    return as.nextToken ();
  }

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

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

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

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


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = 2020;
    static int inf = (int)1e9;
    static int n,k,s,leftSize, rightSize,ans;
    static int f[] = new int[maxn];
    static int a[] = new int[maxn];
    static HashMap<Long, Integer> map[] = new HashMap[maxn];

    private static void solve() throws Exception {
        n = in.nextInt();
        k = in.nextInt();
        s = in.nextInt();

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

        for (int i=0; i<=k; i++) {
            map[i] = new HashMap<>();
        }

        f[0]=1;
        for (int i=1; i<=22; i++) {
            f[i] = f[i-1]*i;
        }

        leftSize = n/2;
        calc1(1,0,0);
        calc2(leftSize + 1, 0,0);
        out.println(ans);

    }

    private static void calc1(int pos, int q, long sum) {
        if (q>k) return;
        if (pos==leftSize+1) {
            if (!map[q].containsKey(sum))
                map[q].put(sum, 0);
            map[q].put(sum, map[q].get(sum)+1);
            return;
        }

        calc1(pos+1,q,sum);
        calc1(pos+1,q,sum+a[pos]);
        if (a[pos]<=18)
            calc1(pos+1,q+1, sum + f[a[pos]]);
    }

    private static void calc2(int pos, int q, long sum) {
        if (q>k) return;
        if (pos == n+1){
            for (int i=0; i<=k-q; i++)
                if (map[i].containsKey(s-sum)) {
                    ans+=map[i].get(s-sum);
                }
            return;
        }
        calc2(pos+1,q,sum);
        calc2(pos+1,q,sum+a[pos]);
        if (a[pos]<=18)
            calc2(pos+1,q+1, sum + f[a[pos]]);
    }

    public static void main (String [] args) throws Exception {

        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }

        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }
    @Override
    public int hashCode() {
        // TODO Auto-generated method stub
        return x;
    }
    @Override
    public int compareTo(Pair p) {
        if (x<p.x)return 1;
        else if (x==p.x) return 0;
        else return -1;
    }

}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

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

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

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


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

public class B {

	static ArrayList<Integer> cubes;
	static int[] cnt;
	static long[] a, comb[];

	static long bt1(int idx, int k, long S)
	{
		if(idx == 36)
			return bt2(0, S);
		long ret = 0;
		for(int i = 0; i <= cnt[idx] && i * a[idx] <= S; ++i)
		{
			if(idx < 18)
				cnt[idx + 18] -= i;
			else if(k < i)
				break;
			ret += comb[cnt[idx]][i] * bt1(idx + 1, k - (idx >= 18 ? i : 0), S - i * a[idx]);
			if(idx < 18)
				cnt[idx + 18] += i;
		}
		return ret;
	}

	static long bt2(int idx, long S)
	{
		if(S < 0)
			return 0;
		if(cubes.size() == idx)
			return S == 0 ? 1 : 0;
		return bt2(idx + 1, S) + bt2(idx + 1, S - cubes.get(idx));
	}

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

		comb = new long[26][26];
		comb[0][0] = 1;
		for(int i = 1; i <= 25; ++i)
		{
			comb[i][0] = 1;
			for(int j = 1; j <= i; ++j)
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
		}
		int n = sc.nextInt(), k = sc.nextInt(), S = sc.nextInt();
		a = new long[36];
		for(int i = 0; i < 18; ++i)
			a[i] = i + 1;
		a[18] = 1;
		for(int i = 19; i < 36; ++i)
			a[i] = a[i - 1] * (i - 17);
		cnt = new int[36];
		cubes = new ArrayList<>();
		while(n-->0)
		{
			int x = sc.nextInt();
			if(x <= 18)
			{
				cnt[x - 1]++;
				cnt[x + 17]++;
			}
			else
				cubes.add(x);
		}
		out.println(bt1(0, k, S));
		out.flush();
		out.close();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class E_Round_297_Div2 {

	public static long MOD = 1000000007;
	static HashMap<State, Long> map = new HashMap();

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		int k = in.nextInt();
		long s = in.nextLong();
		int[]data = new int[n];
		for(int i = 0; i < n;i++){
			data[i] = in.nextInt();
		}
		out.println(cal(0,k,s, data));
		out.close();
	}

	public static long cal(int index, int left, long cur, int[] data) {
		if (index == data.length) {
			if (cur == 0) {
				return 1;
			}
			return 0;
		}
		if (cur == 0) {
			return 1;
		}
		State s = new State(index, left, cur);
		if (map.containsKey(s)) {
			return map.get(s);
		}
		long result = cal(index + 1, left, cur, data);
		if (data[index] <= cur) {
			result += cal(index + 1, left, cur - data[index], data);
		}
		if (left > 0 && data[index] <= 19) {
			long v = 1;
			for (long i = 1; i <= data[index]; i++) {
				v *= i;
			}
			if (v <= cur) {
				result += cal(index + 1, left - 1, cur - v, data);
			}
		}
		map.put(s, result);
		return result;
	}

	public static class State {
		int index, left;
		long cur;

		public State(int index, int left, long cur) {
			this.index = index;
			this.left = left;
			this.cur = cur;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + (int) (cur ^ (cur >>> 32));
			result = prime * result + index;
			result = prime * result + left;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			State other = (State) obj;
			if (cur != other.cur)
				return false;
			if (index != other.index)
				return false;
			if (left != other.left)
				return false;
			return true;
		}

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

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

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

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

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

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

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskE {
	//	int[][][] mem = new int[100][100][100]; //change to hashmap with array of 25 elements each later
	HashMap<Long, long[][]> hm = new HashMap<>();
	int[] a;
	int ncubes;
	int kstickers;
	long dp(long sumwant, int curindex, int exclamationsleft){
		if (sumwant < 0) return 0;
		if (curindex == a.length && sumwant == 0) return 1;
		if (curindex == a.length) return 0;
//		O curobject = new O(sumwant, curindex, exclamationsleft);
//		if (tm.containsKey(curobject)){
//			return tm.get(curobject);
//		}
//		long dontchoose = 0, choosenormal = 0, choosefact = 0;
//		dontchoose = dp(sumwant, curindex + 1, exclamationsleft);
//		choosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);
//		if (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);
//		long res = dontchoose + choosenormal + choosefact;
//		tm.put(curobject, res);
//		return res;
		//		return pointer[curindex][exclamationsleft] = res;

				if (hm.containsKey(sumwant)){
					long[][] pointer = hm.get(sumwant);
					if (pointer[curindex][exclamationsleft] != -1) return pointer[curindex][exclamationsleft];
					long dontchoose = 0, choosenormal = 0, choosefact = 0;
					dontchoose = dp(sumwant, curindex + 1, exclamationsleft);
					choosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);
					if (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);
					long res = dontchoose + choosenormal + choosefact;
					return pointer[curindex][exclamationsleft] = res;
				}
				long dontchoose = 0, choosenormal = 0, choosefact = 0;
				dontchoose = dp(sumwant, curindex + 1, exclamationsleft);
				choosenormal = dp(sumwant - a[curindex], curindex + 1, exclamationsleft);
				if (a[curindex] <= 18 && exclamationsleft > 0) choosefact = dp(sumwant - IntegerUtils.factorial(a[curindex]), curindex + 1, exclamationsleft - 1);
				long[][] temp = new long[ncubes + 1][kstickers + 1];
				ArrayUtils.fill(temp, -1);
				hm.put(sumwant, temp);
				long res = dontchoose + choosenormal + choosefact;
				return temp[curindex][exclamationsleft] = res;
	}
	public void solve(int testNumber, InputReader in, OutputWriter out){
		ncubes = in.ri();
		kstickers = in.ri();
		long SumWant = in.readLong();
		int[] a = IOUtils.readIntArray(in, ncubes);
		this.a = a;
		long res = dp(SumWant, 0, kstickers);
		out.print(res);
	}
}

class IntegerUtils {
	public static long factorial(int n) {
		long result = 1;
		for (int i = 2; i <= n; i++)
			result *= i;
		return result;
	}
}

class ArrayUtils {
	public static void fill(long[][] array, long value) {
		for (long[] row : array)
			Arrays.fill(row, value);
	}
}

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

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

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}
	public void close() {
		writer.close();
	}
	public void print(long i) {
		writer.print(i);
	}
}

class IOUtils {
	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}
}


import java.io.OutputStream;
import java.io.IOException;
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;
        StdIn in = new StdIn(inputStream);
        StdOut out = new StdOut(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, StdIn in, StdOut out) {
            int n = StdIn.readInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = StdIn.readInt();
            int p = 0;
            int nn = 0;
            for (int i = 0; i < n; i++) {
                if (ar[i] > 0)
                    p++;
                if (ar[i] < 0)
                    nn++;
            }
            double dd = (1.0 * n) / 2;
            int d = (int) dd;
            if (d != dd)
                d += 1;
            if (p >= d)
                StdOut.println(1);
            else if (nn >= d)
                StdOut.println(-1);
            else
                StdOut.println(0);
        }

    }

    static class StdOut {
        StdOut();

        void close();

        void println();

    }

    static class StdIn {
        StdIn();

        int readInt();

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.BufferedInputStream;
import java.util.Locale;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.io.UnsupportedEncodingException;

/**
 * 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;
        StdIn in = new StdIn(inputStream);
        StdOut out = new StdOut(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, StdIn in, StdOut out) {
            int n = StdIn.in.readInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = StdIn.in.readInt();
            int p = 0;
            int neg = 0;
            for (int i : ar) {
                if (i > 0)
                    p++;
                if (i < 0)
                    neg++;
            }
            double dd = (1.0 * n) / 2;
            int d = (int) dd;
            if (dd != d)
                d++;
            if (p >= d)
                StdOut.out.println(1);
            else if (neg >= d)
                StdOut.out.println(-1);
            else
                StdOut.out.println(0);
        }

    }

    static final class StdIn {
        private static final String CHARSET_NAME = "UTF-8";
        private static final Locale LOCALE = Locale.US;
        private static Scanner scanner;

        // do this once when StdIn is initialized
        static {
            resync();
        }

        private StdIn() {
        }

        public static int readInt() {
            try {
                return scanner.nextInt();
            } catch (InputMismatchException e) {
                String token = scanner.next();
                throw new InputMismatchException("attempts to read an 'int' value from standard input, "
                        + "but the next token is \"" + token + "\"");
            } catch (NoSuchElementException e) {
                throw new NoSuchElementException("attemps to read an 'int' value from standard input, "
                        + "but no more tokens are available");
            }

        }

        private static void resync() {
            setScanner(new Scanner(new java.io.BufferedInputStream(System.in), CHARSET_NAME));
        }

        private static void setScanner(Scanner scanner) {
            StdIn.scanner = scanner;
            StdIn.scanner.useLocale(LOCALE);
        }

    }

    static final class StdOut {
        private static final String CHARSET_NAME = "UTF-8";
        private static PrintWriter out;

        // this is called before invoking any methods
        static {
            try {
                out = new PrintWriter(new OutputStreamWriter(System.out, CHARSET_NAME), true);
            } catch (UnsupportedEncodingException e) {
                System.out.println(e);
            }
        }

        private StdOut() {
        }

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

        public static void println(int x) {
            out.println(x);
        }

    }
}


package text1;

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

public class Text1 {

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

        int n=Integer.parseInt(l.nextToken());

        StringTokenizer l1=new StringTokenizer(L.readLine());
        int []a=new int[n];

        int x=0,For=0; int n_2=(int)(Math.ceil(n/2.0));
        for (int i = 0; i < n; i++) {
            a[i]=Integer.parseInt(l1.nextToken());
        }
        for (int d =-1; d <= 1 ; d++) {
            int count=0;
            if(d!=0){
                for (int i = 0; i < n; i++) {
                    double Dividing=a[i]/((double)d);
                    if (Dividing>0) {
                        count++;
                    }
                }
                if ((Math.max(For,count))==count&&count>=n_2) {
                    For=count;
                    x=d;
                }
            }
        }
        if(x>0)
            System.out.println(x);
        else
            System.out.println("0");
    }
}


import java.io.OutputStream;
import java.io.IOException;
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;
        StdIn in = new StdIn(inputStream);
        StdOut out = new StdOut(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, StdIn in, StdOut out) {
            int n = StdIn.readInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = StdIn.readInt();
            int p = 0;
            int nn = 0;
            for (int i = 0; i < n; i++) {
                if (ar[i] > 0)
                    p++;
                if (ar[i] < 0)
                    nn++;
            }
            double dd = (1.0 * n) / 2;
            int d = (int) dd;
            if (d != dd)
                d += 1;
            if (p >= d)
                StdOut.println(1);
            else if (nn >= d)
                StdOut.println(-1);
            else
                StdOut.println(0);
        }

    }

    static class StdOut {
        StdOut();

        void close();

        void println;

    }

    static class StdIn {
        StdIn();

        int readInt();

    }
}


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

public class C507C {
	private StringTokenizer st;
	private BufferedReader bf;
	private int m;
	private int goal;
	private int cnt;
	private int skip;
	private boolean[] a;

	public C507C() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());

			int h = nextInt();
			int n = nextInt();

			m = 0;
			for (int i=0;i<=h;i++) {
				m += (int)Math.pow(2, i);
			}
			int k = 0;
			goal = 0;
			for (int i=0;i<h;i++) {
				k += (int)Math.pow(2, i);
			}
			goal = k + n;
			a = new boolean[m+1];

			search(1, false);

			System.out.println(cnt);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private boolean search(int ci, boolean f) {
		int nexti;

		if (ci == goal)
			return true;

		cnt++;
		a[ci] = true;

		if ((ci * 2) > m)
			return false;

		for (int i=0;i<2;i++) {
			if (f) {
				//right
				nexti = ci * 2 + 1;
			} else {
				//left
				nexti = ci * 2;
			}

			if ((ci * 2) > m)
				return false;

			if (a[nexti]) {
				skip++;
				if (skip==2) {
					skip = 0;
					return false;
				}
			} else {
				f = !f;
				if (search(nexti, f))
					return true;
			}
		}
		return false;
	}

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

	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		C507C c = new C507C();
	}

}


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

public class Trees
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int t,h,n;
		Scanner sc = new Scanner(System.in);
		//t=sc.nextInt();
		//while(t!=0)
		//{
			t--;
			h=sc.nextInt();
			n=sc.nextInt();
			long leaf = 1<<(h);
			long up,low,ans=0;
			boolean dir = true; // true = left, false = right
			up = leaf;
			low = 1;
			while(up>low && h>0)
			{
				long mid = (up+low)/2;
				long uc=up,lc=low;
				if(dir)
					uc=mid;
				else
					lc=mid+1;
				if(n<=uc && n>=lc)
				{
					up=uc;
					low=lc;
					dir=!dir;
					ans++;
				}
				else
				{
					long nodes = (1<<(h));
					ans+=nodes;
					if(dir)
						low=mid+1;
					else
						up=mid;

				}
				h--;
			}
			System.out.println(ans);
		//}
	}
}


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        double n=sc.nextDouble();
        System.out.printf("%.0f",1+caso1(h, n));
        System.out.println("");
    }
    public static double caso1(int h, double n){
        if(h==1){
            return n%2==0?1:0;
        }
        double canNodosVis=(Math.pow(2, h+1)/2);
        double canHojas=Math.pow(2, h);
        if(n>canHojas/2){
            n=n-canHojas/2;
            return canNodosVis+caso1(h-1,n);
        }
        return 1+caso2(h-1,n);
    }
    public static double caso2(int h,double n){
        if(h==1){
            return n%2;
        }
        double canNodosVis=(Math.pow(2, h+1)/2);
        double canHojas=Math.pow(2, h);
        if(n<=canHojas/2){
            return canNodosVis+caso2(h-1,n);

        }
        n=n-canHojas/2;
        return 1+caso1(h-1,n);
    }
}


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

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(in, out);
        out.close();
    }
}

class TaskC {
    long foo(long v, long h, boolean f) {
        if (h == 0) return 0;
        if (f) {
            if (1L<<(h-1) >= v) return 1+foo(v, h-1, !f);
            else return ((1L<<h)) + foo(v - (1L<<(h-1)), h-1, f);
        }
        else {
            if (1L<<(h-1) < v) return 1+foo(v - (1L<<(h-1)), h-1, !f);
            else return ((1L<<h)) + foo(v, h-1, f);
        }
    }
    public void solve(InputReader in, PrintWriter out) {
        long h = in.nextLong();
        long v = in.nextLong();
        out.println(foo(v, h, true));
    }
}


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

public class BEAR {
    public static int[][] mul(int[][] a, int[][] b, int mod){
        int n  = a.length;
        int m = a[0].length;
        int l = b[0].length;
        int[][] ret = new int[n][l];
        for(int i = 0;i<n;i++)
            for(int j = 0;j<l;j++)
                for(int k = 0;k<m;k++){
                    ret[i][j] = (int) ((ret[i][j] + 1L * a[i][k] * b[k][j])%mod);
                }
        return ret;
    }
    public static int[][] pow(int[][] a, long t, int mod){
        int[][] ret = new int[a.length][a.length];
        for(int i = 0;i<ret.length;i++)ret[i][i]=1;
        while(t>0){
            if((t & 1)!=0){
                ret = mul(ret, a, mod);
            }
            a = mul(a, a, mod);
            t>>=1;
        }
        return ret;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x0 = in.nextInt()-1;
        int y0 = in.nextInt()-1;
        int dx0 =(in.nextInt()%n+n)%n;
        int dy0 =( in.nextInt()%n+n)%n;
        long t = in.nextLong();

        int[][] m = {
                { 2, 1, 1, 0, 1, 2 },
                { 1, 2, 0, 1, 1, 2 },
                { 1, 1, 1, 0, 1, 2 },
                { 1, 1, 0, 1, 1, 2 },
                { 0, 0, 0, 0, 1, 1 },
                { 0, 0, 0, 0, 0, 1 }};
        int[][] original = {{x0},
                            {y0},
                            {dx0},
                            {dy0},
                            {0},
                            {1}};
        m = pow(m, t,n);
        int[][] res = mul(m , original, n);
//      System.out.println(Arrays.deepToString(original));
//      System.out.println(Arrays.deepToString(res));
        System.out.println((1+res[0][0])+" "+(1+res[1][0]));
    }
}
/*
3 4
1 2 = 3

4 1

*/


public class E {

	private final static boolean autoflush = false;

	long [][] A = {
			{ 1, 0, 0, 0, 0, 0 },
			{ 1, 1, 0, 0, 0, 0 },
			{ 2, 1, 2, 1, 1, 0 },
			{ 2, 1, 1, 2, 0, 1 },
			{ 2, 1, 1, 1, 1, 0 },
			{ 2, 1, 1, 1, 0, 1 }
	};

	public E () {
		int N = sc.nextInt();
		int X = sc.nextInt() - 1;
		int Y = sc.nextInt() - 1;
		int VX = sc.nextInt();
		int VY = sc.nextInt();
		long T = sc.nextLong();

		long [] V = { 1, 0, X, Y, VX, VY };
		long [] W = prod(pow(A, T, N), V, N);
		exit(W[2] + 1, W[3] + 1);
	}

	long [] prod(long [][] A, long [] V, long mod) {
		long [][] W = new long [V.length][1];
		for (int i : rep(V.length))
			W[i][0] = V[i];
		long [][] X = prod(A, W, mod);
		long [] res = new long [X.length];
		for (int i : rep(X.length))
			res[i] = X[i][0];
		return res;
	}

	long [][] sum (long [][] A, long [][] B, long mod) {
		int M = A.length, K = A[0].length, N = B[0].length;
		assert(K == B.length);
		long [][] res = new long [M][N];

		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				res[i][j] = mod(A[i][j] + B[i][j], mod);
		return res;
	}

	long [][] prod (long [][] A, long [][] B, long mod) {
		int M = A.length, K = A[0].length, N = B[0].length;
		assert(K == B.length);
		long [][] res = new long [M][N];

		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				for (int k = 0; k < K; ++k)
					res[i][j] = mod(res[i][j] + A[i][k] * B[k][j], mod);
		return res;
	}

	long [][] pow (long [][] A, long e, long mod) {
		long [][] res = id(A.length);
		if (e > 0) {
			int M = 1 + Long.numberOfTrailingZeros(Long.highestOneBit(e));
			long [][][] P = new long[M][][]; P[0] = A;
			for (int i : rep(1, M))
				P[i] = prod(P[i-1], P[i-1], mod);
			for (int i : rep(M))
				if ((e & (1L << i)) != 0)
					res = prod(res, P[i], mod);
		}
		return res;
	}

	long [][] id (int N) {
		long [][] res = new long [N][N];
		for (int i : rep(N))
			res[i][i] = 1;
		return res;
	}

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


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sheep
 */
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);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        // [x y dx dy 1]
        long n = in.nextLong();

        long sx = ((in.nextLong() - 1) % n + n) % n;
        long sy = ((in.nextLong() - 1) % n + n) % n;
        long dx = (in.nextLong() % n + n) % n;
        long dy = (in.nextLong() % n + n) % n;

        long t = in.nextLong();

        Matrix move = Matrix.getUnitMatrix(6);
        long[][] mat = move.arr;
        mat[0][2] = 1;
        mat[1][2] = 1;
        mat[0][3] = 1;
        mat[1][3] = 1;

        mat[2][0] = 1;
        mat[3][1] = 1;

        mat[0][0] = 2;
        mat[1][0] = 1;
        mat[0][1] = 1;
        mat[1][1] = 2;

        mat[4][2] = 1;
        mat[4][3] = 1;
        mat[4][0] = 1;
        mat[4][1] = 1;

        mat[5][4] = 1;

        Matrix result = NumberUtils.powMod(move, t, n);

        // [sx sy dx dy 1]
        mat = result.arr;
        long x = (sx * mat[0][0] + sy * mat[1][0] + dx * mat[2][0] + dy * mat[3][0] + 2 * mat[4][0] + mat[5][0]) % n;
        long y = (sx * mat[0][1] + sy * mat[1][1] + dx * mat[2][1] + dy * mat[3][1] + 2 * mat[4][1] + mat[5][1]) % n;

        out.println((x + 1) + " " + (y + 1));
    }
}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

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

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

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

    }

class Matrix {

    public long[][] arr;

    public Matrix(int size) {
        arr = new long[size][size];
    }

    public Matrix(long[][] arr) {
        if (arr.length != arr[0].length) {
            throw new IllegalArgumentException();
        }
        this.arr = new long[arr.length][arr.length];
        for (int i = 0; i < arr.length; ++i) {
            System.arraycopy(arr[i], 0, this.arr[i], 0, arr.length);
        }
    }

    public Matrix(int[][] arr) {
        if (arr.length != arr[0].length) {
            throw new IllegalArgumentException();
        }
        this.arr = new long[arr.length][arr.length];
        for (int i = 0; i < arr.length; ++i) {
            for (int j = 0; j < arr.length; ++j) {
                this.arr[i][j] = arr[i][j];
            }
        }
    }

    public Matrix multiply(Matrix to, Long mod) {
        if (arr.length != to.arr.length) {
            throw new IllegalArgumentException();
        }

        Matrix res = new Matrix(arr.length);
        for (int k = 0; k < arr.length; ++k) {
            for (int i = 0; i < arr.length; ++i) {
                if (arr[i][k] == 0) continue;
                for (int j = 0; j < arr.length; ++j) {
                    res.arr[i][j] += arr[i][k] * to.arr[k][j];
                    if (mod != null && res.arr[i][j] >= mod) {
                        res.arr[i][j] %= mod;
                    }
                }
            }
        }

        return res;
    }

    public int size() {
        return arr.length;
    }

    public static Matrix getUnitMatrix(int size) {
        Matrix matrix = new Matrix(size);
        for (int i = 0; i < size; ++i) {
            matrix.arr[i][i] = 1;
        }
        return matrix;
    }

    public String toString() {
        return Arrays.deepToString(arr);
    }
}

class NumberUtils {

    public static Matrix powMod(Matrix mat, long p, long mod) {

        if (p == 0) {
            return Matrix.getUnitMatrix(mat.size());
        }

        if (p == 1) {
            return mat;
        }

        if (p % 2 == 0) {
            Matrix res = powMod(mat, p / 2, mod);
            return res.multiply(res, mod);
        }

        return powMod(mat, p - 1, mod).multiply(mat, mod);
    }

    }


public class E {

	private final static boolean autoflush = false;

	long [][] A = {
			{ 1, 0, 0, 0, 0, 0 },
			{ 1, 1, 0, 0, 0, 0 },
			{ 2, 1, 2, 1, 1, 0 },
			{ 2, 1, 1, 2, 0, 1 },
			{ 2, 1, 1, 1, 1, 0 },
			{ 2, 1, 1, 1, 0, 1 }
	};

	public E () {
		int N = sc.nextInt();
		int X = sc.nextInt() - 1;
		int Y = sc.nextInt() - 1;
		int VX = sc.nextInt();
		int VY = sc.nextInt();
		long T = sc.nextLong();

		long [] V = { 1, 0, X, Y, VX, VY };
		long [] W = prod(pow(A, T, N), V, N);
		exit(W[2] + 1, W[3] + 1);
	}

	long [] prod(long [][] A, long [] V, long mod) {
		long [][] W = new long [V.length][1];
		for (int i : rep(V.length))
			W[i][0] = V[i];
		long [][] X = prod(A, W, mod);
		long [] res = new long [X.length];
		for (int i : rep(X.length))
			res[i] = X[i][0];
		return res;
	}

	long [][] sum (long [][] A, long [][] B, long mod) {
		int M = A.length, K = A[0].length, N = B[0].length;
		assert(K == B.length);
		long [][] res = new long [M][N];

		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				res[i][j] = mod(A[i][j] + B[i][j], mod);
		return res;
	}

	long [][] prod (long [][] A, long [][] B, long mod) {
		int M = A.length, K = A[0].length, N = B[0].length;
		assert(K == B.length);
		long [][] res = new long [M][N];

		for (int i = 0; i < M; ++i)
			for (int j = 0; j < N; ++j)
				for (int k = 0; k < K; ++k)
					res[i][j] = mod(res[i][j] + A[i][k] * B[k][j], mod);
		return res;
	}

	long [][] pow (long [][] A, long e, long mod) {
		long [][] res = id(A.length);
		if (e > 0) {
			int M = 1 + Long.numberOfTrailingZeros(Long.highestOneBit(e));
			long [][][] P = new long[M][][]; P[0] = A;
			for (int i : rep(1, M))
				P[i] = prod(P[i-1], P[i-1], mod);
			for (int i : rep(M))
				if ((e & (1 << i)) != 0)
					res = prod(res, P[i], mod);
		}
		return res;
	}

	long [][] id (int N) {
		long [][] res = new long [N][N];
		for (int i : rep(N))
			res[i][i] = 1;
		return res;
	}

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


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

public class Main {

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int m = in.nextInt();

        boolean[] arr = new boolean[m];
        List<Integer> positions = new ArrayList<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            int v = in.nextInt() % m;
            if (v == m - 1) {
                System.out.println(m - 1);
                return;
            }
            max = Math.max(v, max);
            List<Integer> toAdd = new ArrayList<>();
            for (Integer pos : positions) {
                int v2 = (pos + v) % m;
                max = Math.max(v2, max);
                if (!arr[v2]) {
                    toAdd.add(v2);
                    arr[v2] = true;
                }
            }

            positions.addAll(toAdd);
            if (!arr[v]) {
                positions.add(v);
                arr[v] = true;
            }
        }

        System.out.println(max);
    }

    public static int gcd(int a, int b) {
        int t;
        while (b != 0) {
            t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    public static void pa(List<Object> objs) {
        String str = "";
        for (Object obj : objs) {
            str += obj.toString() + " ";
        }
        p(str);
    }

    public static void pa(int[] objs) {
        String str = "";
        for (int i = 0; i < objs.length; i++) {
            str += objs[i] + " ";
        }
        p(str);
    }

    static void p(Object str) {
        System.out.println(str);
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.io.InputStream;
import java.util.ArrayList;

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

    static class cf {
        long mod;
        int n;
        List<Long> li = new ArrayList<>();
        int[] ar;
        TreeSet<Long> li2 = new TreeSet<>();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            mod = in.nextInt();
            ar = in.nextIntArray(n);
            subset(0, 0, n / 2);
            subset(n / 2, 0, n);
            long max = 0;
            //out.print();
            // System.out.println(li);
            for (int i = 0; i < li.size(); i++) {
                long val1 = mod - li.get(i) - 1;
                //System.out.println(val1);
                if (val1 <= li2.first()) {
                    long val2 = li2.floor(val1);
                    if (val2 != 1) {
                        max = Math.max(max, val1 + val2);
                    }
                }
                max = Math.max(max, li.get(i));
            }
            max = Math.max(max, li2.last());
            out.println(max);

        }

        void subset(int pos, long sum, int last) {
            if (pos == n) {
                li2.add(sum);
                return;
            }
            if (pos >= last) {
                li.add(sum);
                return;
            }
            subset(pos + 1, sum, last);
            subset(pos + 1, (sum + ar[pos]) % mod, last);

        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;

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

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

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

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

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

    }
}


import java.util.*;
import java.io.*;
public class Main
{
	static class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException
		{
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException
		{
			byte[] buf = new byte[201]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1)
			{
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
		}
	}
        static ArrayList<Integer> al;
        static int bs(int l,int r,int v){
         if(r<l)return 0;
         int rs=0;
         while(l<r){
          int m=(l+r)>>1;
          if(al.get(m)==v){rs=m;break;}
          if(al.get(m)<v)l=m+1;else r=m;
         }if(l==r)rs=l;
         if(al.get(rs)>v)rs--;return (rs>=0)?al.get(rs):0;
        }
        public static void main(String[] args) throws IOException
	{
		Reader in=new Reader();PrintWriter out=new PrintWriter(System.out);
                int n=in.nextInt(),m=in.nextInt();
                int a[]=new int[n];
                for(int i=0;i<n;i++)a[i]=in.nextInt()%m;
                int h=n/2;al=new ArrayList<>();
                for(int i=1;i<(1<<h);i++){
                 int v=0;
                 for(int j=0;j<h;j++){
                  if(((i>>j)&1)==1)v=(v+a[j])%m;
                 }al.add(v);
                }Collections.sort(al);int l=al.size();
                h=n-n/2;int ans=0;
                for(int i=1;i<(1<<h);i++){
                 int v=0;
                 for(int j=0;j<h;j++){
                  if(((i>>j)&1)==1)v=(v+a[n/2+j])%m;
                 }int v1=bs(0,l-1,m-v-1);
                 int t1=(v+v1)%m,t2=(v+((l==0)?0:al.get(l-1)))%m;
                 ans=Math.max(ans,Math.max(t1,t2));
                }out.print(ans);
                out.flush();out.close();
	}
}


import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class MaxSubSeq {
public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
	int m = s.nextInt();
	int x = 0;
	if(n%2!=0) {
		x=1;
	}
	int[] a = new int[n/2];
	int[] b = new int[n/2+x];
	for (int i = 0; i < a.length; i++) {
		a[i] = s.nextInt();
	}
	for (int i = 0; i < b.length; i++) {
		b[i] = s.nextInt();
	}
	s.close();
	TreeSet<Integer> posA = getSums(a,m);
	TreeSet<Integer> posB = getSums(b,m);
	Iterator<Integer> it = posA.iterator();
	Iterator<Integer> bit = posB.descendingIterator();
	int max = 0;
	int bEl = bit.next();
	while(it.hasNext()) {
		int aEl = it.next();
		while(aEl+bEl>m) {
			bEl = bit.next();
		}
		max = Math.max((aEl+bEl)%m, max);
	}
	System.out.println(max);

}

private static TreeSet<Integer> getSums(int[] a, int m) {
	TreeSet<Integer> obtained = new TreeSet<>();
	obtained.add(0);
	for (int i = 0; i<a.length; i++) {
		Integer[] copy = obtained.toArray(new Integer[0]);
		for(int j:copy) {
			obtained.add((j+a[i])%m);
		}
	}
	return obtained;
}
}


import java.util.Scanner;

public class Main {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int p = scanner.nextInt();
    if(p == 1 || p == n) {
        System.out.println(n * 3);
    } else {
         System.out.println(((n-1)*3) + 5);
    }
    scanner.close();
}


import java.io.*;

public class Middle{
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nk = br.readLine().split(" ");
        int N = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);
        total = (k-1<N-k)? 3*N+k-1:4*N-k;
        System.out.println(total);

    }
}


import java.util.*;
public class A{
    public static void main(String[]args)
    Scanner sc= new Scanner (System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    System.out.println(3*x+Math.max(y-1,x-y);
}


public class BB {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();int k=scan.nextInt();
		if(n==2) {
			System.out.println(6);
			return;
		}

		if(k==1)
		{
			System.out.println(6+(Math.max(0,n-2)*3));
		}
		if(n>2 && k>=2)
		{
			int gg=(6+((n-(k+1))*3)+2+(n-k)+1+(Math.min(0, k-3)*3)+2);
			int rr=((k*3)+k+(n-(k+1))*3+2);
			int ll=((n-(k-1))*3+(n-k)+((k-1)*3));
			System.out.println(Math.min(rr, ll));
			//System.out.println(gg);
		}
	}
}


import java.util.Scanner;

public class codeForcesPblm1 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int alp = 0;
		boolean flag = false;
		if(s.length()<26) {
			System.out.println(-1);
		}
		else{
			for(int i = 0;i<s.length();i++) {
				if(s.charAt(i)!=97+alp && s.charAt(i)+1 != 97+alp) {
					continue;
				}else
					alp++;

			}
			if(alp==26)
			System.out.println("abcdefghijklmnopqrstuvwxyz");
			else
				System.out.println(-1);
		}

		}


mport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class D {
	static FastReader scan = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		Solver solver = new Solver();
		int testCases = 1;
		while (testCases--> 0) solver.solve();
		out.close();
	}

	static class Solver {

		void solve() {
			char[] s = scan.next().toCharArray();
			if(s.length < 26) {
				out.println(-1);
			}
			else {
				int curr = 'a', index = 0;
				while(index < s.length && curr <= 'z') {
					if(s[index] <= curr) {
						s[index] = (char) curr;
						curr++;
					}
					index++;
				}
				if(curr > 'z') out.println(new String(s));
				else out.println(-1);
			}
		}
	}

	//Sathvik's Template Stuff BELOW!!!!!!!!!!!!!!!!!!!!!!

	static class DSU {
		int[] root, size;
		int n;
		DSU(int n) {
			this.n = n;
			root = new int[n];
			size = new int[n];
			for(int i = 0; i < n; i++) {
				root[i] = i;
				size[i] = 1;
			}
		}
		int findParent(int idx) {
			while(root[idx] != idx) {
				root[idx] = root[root[idx]];
				idx = root[idx];
			}
			return idx;
		}
		boolean union(int x, int y) {
			int parX = findParent(x);
			int parY = findParent(y);
			if(parX == parY) return false;
			if(size[parX] < size[parY]) {
				root[parY] = parX;
				size[parX] += size[parY];
			} else {
				root[parX] = parY;
				size[parY] += size[parX];
			}
			return true;
		}
	}

	static class Extra {
		static void sort(int[] a) {
			Integer[] aa = new Integer[a.length];
			for (int i = 0; i < aa.length; i++) aa[i] = a[i];
			Arrays.sort(aa);
			for (int i = 0; i < aa.length; i++) a[i] = aa[i];
		}
		static void sort(long[] a) {
			Long[] aa = new Long[a.length];
			for (int i = 0; i < aa.length; i++) aa[i] = a[i];
			Arrays.sort(aa);
			for (int i = 0; i < aa.length; i++) a[i] = aa[i];
		}
		static void sort(double[] a) {
			Double[] aa = new Double[a.length];
			for (int i = 0; i < aa.length; i++) aa[i] = a[i];
			Arrays.sort(aa);
			for (int i = 0; i < aa.length; i++) a[i] = aa[i];
		}
		static void sort(char[] a) {
			Character[] aa = new Character[a.length];
			for (int i = 0; i < aa.length; i++) aa[i] = a[i];
			Arrays.sort(aa);
			for (int i = 0; i < aa.length; i++) a[i] = aa[i];
		}
		static long gcd(long a, long b) {
			while(b > 0) {
				long temp = b;
				b = a%b;
				a = temp;
			}
			return a;
		}
		static long lcm(long a, long b) {
			return a * (b / gcd(a,b));
		}
		static boolean isPrime(long n) {
			if (n <= 1) return false;
	        if (n <= 3) return true;
	        if (n % 2 == 0 || n % 3 == 0) return false;
	        for (long i = 5; i * i <= n; i = i + 6) {
	            if (n % i == 0 || n % (i + 2) == 0) return false;
	        }
	        return true;
		}
		static HashSet<Integer> sieve(int n) {
			boolean[] prime = new boolean[n+1];
			HashSet<Integer> res = new HashSet<>();
			for(int p = 2; p*p <= n; p++) {
				if(!prime[p]) {
					res.add(p);
					for(int i = p*p; i <= n; i+=p) prime[i] = true;
				}
			}
			return res;
		}
		static HashMap<Long, Integer> primeFactorization(long n) {
			HashMap<Long, Integer> res = new HashMap<>();
			while(n % 2 == 0) {
				res.put(2L, res.getOrDefault(2L, 0)+1);
				n/=2;
			}
			for(long i = 3; i*i <= n; i+=2) {
				while(n % i == 0) {
					res.put(i, res.getOrDefault(i, 0)+1);
					n/=i;
				}
			}
			if(n > 2) res.put(n, 1);
			return res;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

		int[] nextIntArray(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());
		}

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

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

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

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

}


import java.util.*;

public class Algo_Str{
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String s = input.next();
		char[] ans = s.toCharArray();
		if(s.length() < 26){
			System.out.println(-1);
		}
		else{
			long[] a = new long[26];
			char c = 'a';
			long index = -1;
			for(long i = 0;i<ans.length;i++){
				if(c == ans[i]){
					index = i;
					break;
				}
			}
			if(index == -1 ){
				System.out.println(-1);
			}
			else{
				a[0] = 1;
				for(long i = index+1;i<ans.length;i++){
					//a[s.charAt(i)-'a']++;
					if(c == s.charAt(i) || c ==  s.charAt(i)-1){
						c = (char)(c+1);
						ans[i] = c;
						a[ans[i] - 'a']++;
						//System.out.println(c);
					}
				}
				boolean bool = true;
				for(int i = 0;i<26;i++){
					if(a[i] == 0){
						bool = false;
						break;
					}
				}
				if(!bool){
					System.out.println(-1);
				}
				else{
					for(int i = 0;i<ans.length;i++){
						System.out.print(ans[i]+"");
					}
				}
			}
		}

	}
}


import java.util.*;
public class A{
	static char arr[];
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		arr = scan.next().toCharArray();
		solve();

	}
	public static void solve()
	{
		char cur = 'a';
		int flag = false;
		for(int i = 0;i < arr.length;i++)
		{
			if (arr[i]-cur == -1  || arr[i] == cur)
				{
					arr[i] = cur;
					if (arr[i] == 'z')
						flag = true;
					if (cur !='z')
						cur = (char)(cur+1);
				}

		}
		if (!flag)
			System.out.println(-1);
		else
		{
			for(int i = 0;i<arr.length;i++)
				System.out.print(arr[i]);
			System.out.println();
		}
	}
}


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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            char[] arr = in.next().toCharArray();
            int move = 0;
            int i;
            boolean f = false;
            int j;
            for (i = 0; i < n; i = j) {
                move++;
                if (i + d >= n - 1)
                    break;
                for (j = i + d; j > i; j--) {
                    if (arr[j] == '1')
                        break;
                }
                if (i == j) {
                    f = true;
                    break;
                }
                if (j >= n - 1)
                    break;
            }
            if (f)
                out.println("-1");
            else
                out.println(move);

            out.close();
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

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

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

    }

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

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {


import java.util.*;

import com.sun.java.util.jar.pack.Package.Class.Method;

import java.io.*;
public class TheWayToHome
{   private static final int v = Integer.MAX_VALUE / 3;
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        String q = in.next();
        TheWayToHome i = new TheWayToHome();
        System.out.println(i.Method(x, y, q));

    }

    public int Method(int x, int y, String q)
    {
        int[] z = new int[x];
        Arrays.fill(z,v);
        z[0] = 0;
        for(int i = 0; i < x; i++)
        {
            if(q.charAt(i) == '0')
                continue;
            for(int j = i - 1; j >= Math.max(0, i - y); --j)
            {
                z[i] = Math.min(z[i],z[j] + 1);

            }
        }
        return z[x - 1] == v ? -1 : z[x -1];
    }
}


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

public class wayhome{
  static int n;
  static int d;
  static int[] pond;
  static int[] visited;
  public static class Lily{
    int x;
    int days;
    public Lily(int a, int b){
      x = a;
      days = b;
    }
  }
  public static void bfs(){
    LinkedList<Lily> ll = new LinkedList<Lily>();
    ll.push(new Lily(0,0));
    Lily current;
    while(!ll.isEmpty()){
      current = ll.poll();
      if(current.x < 0 || current.x >= pond.length || pond[current.x] == 0 || visited[current.x] != -1){
        continue;
      }
      //System.out.println(current.days);
      if(current.x == n){
        return;
      }
      visited[current.x] = current.days;
      for(int i = 1; i <= d; i++){
        ll.push(new Lily(current.x + i, current.days + 1));
      }
    }
  }
  public static void main(String[] args) throws IOException{
    //Scanner sc = new Scanner(new File("input.in"));
    Scanenr sc = new Scanner(System.in);
    n = sc.nextInt();
    d = sc.nextInt();

    String str_pond = sc.next();
    char[] char_pond = str_pond.toCharArray();

    pond = new int[str_pond.length()];

    visited = new int[str_pond.length()];
    Arrays.fill(visited, -1);

    for(int i = 0; i < str_pond.length(); i++){
      pond[i] = Character.getNumericValue(char_pond[i]);
    }

    bfs();

    System.out.println(visited[n-1]);

    //System.out.println(Arrays.toString(pond));
    //System.out.println(Arrays.toString(visited));
    //System.out.println(pond.length);

  }
}


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

public class Main
{
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static class HM<T,Integer> extends HashMap<T,T> {};
    public static class AL<T> extends ArrayList<T> {};
    public static class HS<T> extends HashSet<T> {};

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

        int n=nxtInt();
        String s=nxtLn(),ans="";
        int[] frq=cntCharFrq(s);

        if(frq['B'-'A']>=1&&frq['R'-'A']>=1&&frq['G'-'A']>=1) ans="BGR";
        else if(frq['B'-'A']>=2)
        {
            if(frq['R'-'A']>=2&&frq['G'-'A']==0) ans="BGR";
            if(frq['R'-'A']==0&&frq['G'-'A']>=2) ans="BGR";
            else if(frq['R'-'A']==0&&frq['G'-'A']==1) ans="GR";
            else if(frq['R'-'A']==1&&frq['G'-'A']==0) ans="GR";
        }
        else if(frq['B'-'A']==0&&frq['R'-'A']>=2&&frq['G'-'A']>=2) ans="BGR";
        else if(frq['R'-'A']>=2)
        {
            else if(frq['B'-'A']==0&&frq['G'-'A']==1) ans="BG";
            else if(frq['B'-'A']==1&&frq['G'-'A']==0) ans="BG";
        }
        else if(frq['G'-'A']>=2)
        {
            else if(frq['B'-'A']==0&&frq['R'-'A']==1) ans="BR";
            else if(frq['B'-'A']==1&&frq['R'-'A']==0) ans="BR";
        }
        else if(frq['B'-'A']>=1&&frq['R'-'A']==0&&frq['G'-'A']==0) ans="B";
        else if(frq['B'-'A']==0&&frq['R'-'A']>=1&&frq['G'-'A']==0) ans="R";
        else if(frq['B'-'A']==0&&frq['R'-'A']==0&&frq['G'-'A']>=1) ans="G";

        pr.print(ans);
        pr.flush();
		pr.close();
    }

    static int nxtInt(){
        return Integer.parseInt(st.nextToken());
    }

    static long nxtLong(){
        return Long.parseLong(st.nextToken());
    }

    static double nxtDoub(){
        return Double.parseDouble(st.nextToken());
    }

    static String nxt(){
        return st.nextToken();
    }

    static String nxtLn() throws IOException{
        return br.readLine();
    }

    static int[] cntCharFrq(String str){
        int[] ltrs = new int[26];
        for(int i=0; i<str.length(); i++)
            ltrs[(int) (str.charAt(i) - 'A')]++;
        return ltrs;
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n=Integer.parseInt(in.nextLine());
		String s=in.nextLine();
		char[]arr=new char[n];
		int R=0,G=0,B=0;
		int a=0,b=0,c=0;
		for(int i=0;i<n;i++)
		{
			arr[i]=s.charAt(i);
		}

		for(int i=0;i<n;i++)
		{
			if(arr[i]=='R')
			{
				a=1;
				R++;
			}
			else if(arr[i]=='G')
			{
				b=1;
				G++;
			}
			else
			{
				c=1;
				B++;
			}
		}
		if(a==1 && b==1 && c==1) //site gi ima po ednas
		{
			System.out.println("BGR");

		}
		else if(a==1 && b==0 && c==0) //edna boja samo
		{
			System.out.println("R");
		;
		}
		else if(a==0 && b==1 && c==0)
		{
			System.out.println("G");

		}
		else if(a==0 && b==0 && c==1)
		{
			System.out.println("B");

		}
		else //sigurno ima razlicni dve boi a nema tri razlicni
		{
			if(R+G+B==2) // tocno dve bukvi
			{
				if(a!=0)
				{
					System.out.print("R");
				}
				if(b!=0)
				{
					System.out.print("G");
				}
				if(c!=0)
				{
					System.out.print("B");
				}
			}
			else  //po povekje bukvi od dve boi
			{
				if(R>1)
				{
					System.out.print("BG");
				}
				else if(G>1)
				{
					System.out.print("BR");

				}
				else if(B>1)
				{
					System.out.print("GR");
				}
			}
		}

	}

}
package Cards;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n=Integer.parseInt(in.nextLine());
		String s=in.nextLine();
		char[]arr=new char[n];
		int R=0,G=0,B=0;
		int a=0,b=0,c=0;
		for(int i=0;i<n;i++)
		{
			arr[i]=s.charAt(i);
		}

		for(int i=0;i<n;i++)
		{
			if(arr[i]=='R')
			{
				a=1;
				R++;
			}
			else if(arr[i]=='G')
			{
				b=1;
				G++;
			}
			else
			{
				c=1;
				B++;
			}
		}
		if(a==1 && b==1 && c==1) //site gi ima po ednas
		{
			System.out.println("BGR");

		}
		else if(a==1 && b==0 && c==0) //edna boja samo
		{
			System.out.println("R");
		;
		}
		else if(a==0 && b==1 && c==0)
		{
			System.out.println("G");

		}
		else if(a==0 && b==0 && c==1)
		{
			System.out.println("B");

		}
		else //sigurno ima razlicni dve boi a nema tri razlicni
		{
			if(R+G+B==2) // tocno dve bukvi
			{
				if(a!=0)
				{
					System.out.print("R");
				}
				if(b!=0)
				{
					System.out.print("G");
				}
				if(c!=0)
				{
					System.out.print("B");
				}
			}
			else  //po povekje bukvi od dve boi
			{
				if(R>1)
				{
					System.out.print("BG");
				}
				else if(G>1)
				{
					System.out.print("BR");

				}
				else if(B>1)
				{
					System.out.print("GR");
				}
			}
		}

	}

}


import com.sun.tools.doclets.formats.html.SourceToHTMLConverter;

import java.util.Scanner;

/**
 * Created by gopalan on 2/13/16.
 */
public class C626 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        runProblem2(scanner);
    }

    private static void runProblem2(Scanner scanner) {
            int n = scanner.nextInt();
            String output = scanner.next();
        int[] counts = new int[3];
        String value = "";
        for (char c : output.toCharArray()) {
            if (c == 'R') counts[0]++;
            if (c == 'G') counts[1]++;
            if (c == 'B') counts[2]++;
        }
            if (isTrue(counts[0], counts[1], counts[2])){
                value += 'R';
            }

            if (isTrue(counts[1], counts[0], counts[2])){
                value += 'G';
            }

            if (isTrue(counts[2], counts[0], counts[1])){
                value += 'B';
            }

        System.out.println(value);

    }

    private static boolean isTrue(int count, int count1, int count2) {
        if (count == 0 && count1 > 0 && count2 > 0) return  true;
        count += Math.min(count1, count2);
        if (count1 == count2) return true;
        count1 = Math.abs(count1 - count2);
        if (count1 > 1 && count >= 1 ) return true;
        return  false;

    }

    public C626() {
    }

    private static void runProblem1(Scanner scanner) {

        int n = scanner.nextInt();
        String value = scanner.next();
        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i+1; j <= n; j++) {
                if (isCorrect(value.substring(i, j))){
                    count++;
                }
            }
        }
        System.out.println(count);
    }

    private static boolean isCorrect(String substring) {
        int xcount = 0;
        int ycount = 0;
        for (char c : substring.toCharArray()) {
            if (c == 'U') xcount++;
            if (c == 'D') xcount--;
            if (c == 'L') ycount ++;
            if (c == 'R') ycount --;
        }
        return (xcount == 0 && ycount == 0);
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class solve {

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = sc.nextInt();
		Queue<String> q = new LinkedList<String>();
		q.add(sc.next());
		Set<String> ans = new TreeSet<String>();
		Set<String> visited = new TreeSet<String>();
		while (!q.isEmpty()) {
			Set<String> tset = new HashSet<String>();
			while (!q.isEmpty()) {
				String v = q.remove();
				if (visited.contains(v)) continue;
				else visited.add(v);
				StringBuilder b = new StringBuilder(v);
				if (b.length() == 1)
					ans.add(b.toString());
				else
					for (int i = 0; i < b.length(); i++) {
						for (int j = i + 1; j < b.length(); j++) {
							char ci = b.charAt(i);
							char cj = b.charAt(j);
							char c = move(ci, cj);
							StringBuilder t = new StringBuilder(b.toString());
							tset.add(t.replace(i, i + 1, c + "")
									.replace(j, j + 1, "").toString());
						}
					}
			}
			q.addAll(tset);
		}

		String o = "";
		for (String t : ans)
			o += t;
		out.println(o);
		out.close();
	}

	static String sort(String s) {
		List<Character> v = new ArrayList<Character>();
		for (char c : s.toCharArray())
			v.add(c);
		s = "";
		Collections.sort(v);
		for (char c : v)
			s += c;
		return s;
	}
	static char move(char a, char b) {

		if (a == b)
			return a;

		if (a == 'R' && b == 'G')
			return 'B';
		if (a == 'R' && b == 'B')
			return 'G';

		if (a == 'G' && b == 'R')
			return 'B';
		if (a == 'G' && b == 'B')
			return 'R';

		if (a == 'B' && b == 'R')
			return 'G';
		if (a == 'B' && b == 'G')
			return 'R';
		return a;
	}

	// -----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

}


import java.util.Scanner;

public class CF_1237_2 {
    static int sum=0;
    static int[] a=new int[3000];
    static int[] ans=new int[3000];
    static int n=0;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        for(int i=2;i<=Math.pow(2, n+1)-1;i++){
            a[i]=sc.nextInt();
        }
        dg(1);
        System.out.println(sum);

    }
    static int dg(int x){
        if (x>=Math.pow(2, n))
            return a[x];
        else {
            ans[2*x]=dg(2*x);
            ans[2*x+1]=dg(2*x+1);

            sum+=Math.abs(ans[2*x]-ans[2*x+1]);
            return a[x]+Math.max(ans[2*x],ans[2*x+1]);

        }

    }
}


/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        long c= sc.nextLong();
        long hr = sc.nextLong();
        long hb = sc.nextLong();
        long wr = sc.nextLong();
        long wb = sc.nextLong();
        long g = GCD(wr,wb);
        wr/=g;
        wb/=g;
        c/=g;
        if(wr>wb){
            long temp = wr;
            long temp2 = hr;
            wr=wb;
            wb=temp;
            hr=hb;
            hb=temp2;
        }
        // c/wr
        long max = 0;
        if(wb<=1000000){
            for(long x = 0;x<wb;x++){
                if(x*wr<=c){
                    long y = (c-x*wr)/wb;
                    max=Math.max(x*hr+y*hb,max);
                }
            }
            for(long y = 0;y<wr;y++){
                if(y*wb<=c){
                    long x = (c-y*wb)/wr;
                    max = Math.max(x*hr+y*hb,max);
                }
            }
        }
        else{
        for(long y = 0;y*wb<=c;y++){
            long x = (c-y*wb)/wr;
            max=Math.max(x*hr+y*hb,max);
        }
            }
        }
        System.out.println(max);
    }
    public static long GCD(long a, long b) { return b==0 ? a : GCD(b, a%b); }
}


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

public class P? {

  @SuppressWarnings("unchecked")
  public void run() throws Exception {
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P?().run();
    br.close();
    pw.close();
  }

  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 { println("" + 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;
  }
}


/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        long c= sc.nextLong();
        long hr = sc.nextLong();
        long hb = sc.nextLong();
        long wr = sc.nextLong();
        long wb = sc.nextLong();
        long g = GCD(wr,wb);
        wr/=g;
        wb/=g;
        c/=g;
        if(wr>wb){
            long temp = wr;
            long temp2 = hr;
            wr=wb;
            wb=temp;
            hr=hb;
            hb=temp2;
        }
        // c/wr
        long max = 0;
        if(wb<=1000000){
            for(long x = 0;x<wb;x++){
                if(x*wr<=c){
                    long y = (c-x*wr)/wb;
                    max=Math.max(x*hr+y*hb,max);
                }
            }
            for(long y = 0;y<wr;y++){
                if(y*wb<=c){
                    long x = (c-y*wb)/wr;
                    max = Math.max(x*hr+y*hb,max);
                }
            }
        }
        else{
            for(long xx = 0;xx<wr;xx++){
                long x = xx;
                long y;
                if(c<x*wr){
                    break;
                }
                else{
                    y=(c-x*wr)/wb;
                    max=Math.max(x*hr+y*hb,max);
                    while(y>=0){
                        max=Math.max(x*hr+y*hb,max);
                        x+=wb;
                        y-=wr;
                    }
                }
            }
        }
        System.out.println(max);
    }
    public static long GCD(long a, long b) { return b==0 ? a : GCD(b, a%b); }
}


import java.util.Scanner;
import java.util.Arrays;
import java.lang.Math;
public class MarvoloRing {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        String inp = kbd.nextLine();
        String[] input = inp.split(" ");
        long inpAx = Long.parseLong(input[0]) * 2;
        long inpAy = Long.parseLong(input[1]) * 2;
        long inpBx = Long.parseLong(input[2]) * 2;
        long inpBy = Long.parseLong(input[3]) * 2;
        long inpCx = Long.parseLong(input[4]) * 2;
        long inpCy = Long.parseLong(input[5]) * 2;

        long n = (Math.abs(inpAx - inpBx) * Math.abs(inpAx - inpBx)) + (Math.abs(inpAy - inpBy) * Math.abs(inpAy - inpBy));
        long m = (Math.abs(inpBx - inpCx) * Math.abs(inpBx - inpCx)) + (Math.abs(inpBy - inpCy) * Math.abs(inpBy - inpCy));
        long i = (inpAx + inpCx) / 2;
        long j = (inpAy + inpCy) / 2;

        if(n == m && && i != inpBx || j != inpBy)){
        	System.out.println("YES");
        } else{
        	System.out.println("NO");
        }
    }
}


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.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HossamDoma
 */
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 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int ax = in.nextInt();
            int ay = in.nextInt();

            int bx = in.nextInt();
            int by = in.nextInt();

            int cx = in.nextInt();
            int cy = in.nextInt();

            long ab = (long) (ax - bx) * (ax - bx) + (long) (ay - by) * (ay - by);
            long bc = (long) (bx - cx) * (bx - cx) + (long) (by - cy) * (by - cy);
            long ac = (long) (ax - cx) * (ax - cx) + (long) (ay - cy) * (ay - cy);

            // out.println(ab + " " + ac + " " + bc);

            if (ab != bc || (long) ax * (by - cy) + (long) bx * (cy - ay) + (long) cx * (ay - by)) {
                out.println("No");
            } else
                out.println("Yes");
        }

    }

    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());
        }

    }
}