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

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

	private void solve() throws Exception {
		reader = new BufferedReader(new InputStreamReader(System.in));

		n = Integer.parseInt(reader.readLine());
		a = new int[n];
		st = new StringTokenizer(reader.readLine());

		for (int i = 0; i < n; ++i) {
			a[i] = Integer.parseInt(st.nextToken());
		}

		reader.close();

		if (func(0, false)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	private BufferedReader reader;
	private StringTokenizer st;
	private int n;
	private int[] a;

	private boolean func(int indx, boolean flag) {

		if (indx >= n) {
			return flag;
		}

		if (a[indx] % 2 == 0 || a[n - 1] % 2 == 0) {
			return false;
		}

		if (!flag && (n - indx) % 2 == 1) {
			return true;
		}

		for (int j = indx; j < n; j += 2) {
			if (a[j] % 2 == 0) {
				continue;
			}

			if (func(j + 1, !flag)) {
				return true;
			}
		}

		return false;
	}
}


// package Practice1.CF29;

import java.util.Scanner;

public class CF029B {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int l = s.nextInt(),d =s.nextInt(),v = s.nextInt(),g = s.nextInt(),r = s.nextInt();
        double timeToreachTL = (d*1.0)/v;
        if(timeToreachTL < g){
            //Light is green right now, the car can simply pass.
            timeToreachTL += ((l-d)*1.0)/v;
            System.out.println(timeToreachTL);
        } else {
            double mod = timeToreachTL % (g+r);
            if(mod > g){
                timeToreachTL += (g+r) - mod;
            }
            timeToreachTL += ((l-d)*1.0)/v;
            System.out.println(timeToreachTL);
        }
    }
}


import java.util.*;

public class CopyOfNuble {

    static void metod() throws Exception {
        Scanner in = new Scanner(System.in);
        int l = in.nextInt();
        int d = in.nextInt();
        int v = in.nextInt();
        int g = in.nextInt();
        int r = in.nextInt();

        double t = (double) d / (double) v;
        double t1 = t % ((double) g + (double) r);

        if (t1 < (double) g) {
            System.out.println((double) l / (double) v);
        } else {
            System.out.println((double) l / (double) v + 2 * (double) t1
                    - (double) g - (double) r);
        }

    }

    public static void main(String args[]) throws Exception {
        CopyOfNuble.metod();
    }
}


import java.text.NumberFormat;
import java.util.Scanner;

public class light {

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

    private void run() {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int d = sc.nextInt();
        int v = sc.nextInt();
        int g = sc.nextInt();
        int r = sc.nextInt();
        int x = 0, secsf = 0, rORg = g;
        double sec = 0;
        boolean isGreen = true;
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(8);

        if (d<v)
        {
           System.out.print(nf.format((double)l/v));
           System.exit(0);
        }

        while (x<l)
        {
            if (x+v<=d)
            {
                 x+=v;
            }
            else
            {
                 if (x<=d)
                 {
                     if (isGreen)
                         x+=v;
                     else
                         x=d;
                }
            }

            secsf++;
            if (secsf>=rORg)
            {
                isGreen=!(isGreen);
                secsf=0;
                if (rORg==g)
                    rORg=r;
                else
                    rORg=g;
            }

            sec++;
        }

        System.out.print(nf.format((sec-1)+(double)(v-x+l)/v));

    }

}


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

public class Main {
//        File file = new File("input.txt");
//        Scanner in = new Scanner(file);
//        PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
        FastReader in = new FastReader();

//        int test_cases = in.nextInt();
//        while (test_cases -- > 0){

        	int n = in.nextInt();
        	long ans = 0;
        	for(int i = 1; i<=n; i++) {
        		ans+=Math.pow(2, i);
        	}
        	System.out.println(ans);

//        }

    }

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

	static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

public class Main {

    public static void main(String[] args) {
        FastReader in = new FastReader();
        StringBuilder out = new StringBuilder();
       int n = in.nextInt();
       int k = in.nextInt();
       String c = in.next();
       HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < c.length(); i++) {
            set.add(c.charAt(i));
        }
        if(set.size()==n/k){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }

}

class FastReader {

    BufferedReader br;
    StringTokenizer st;

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

    }

    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

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

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.BufferedReader;
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;
        CustomReader in = new CustomReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, CustomReader in, PrintWriter out) {

            int n = in.nextInt();
            int k = in.nextInt();
            String colors = in.next();

            Map<Character, Integer> colorCount = new HashMap<>();
            for (char ch : colors.toCharArray()) {
                if (!colorCount.containsKey(ch)) {
                    colorCount.put(ch, 0);
                }
                int count = colorCount.get(ch);
                colorCount.put(ch, ++count);
            }

            for (Map.Entry<Character, Integer> entry : colorCount.entrySet()) {
                if (!(entry.getValue() < k) && 0 < entry.getValue() % k) {
                    out.write("NO");
                    return;
                }
            }

            out.write("YES");
        }

    }

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

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

    }
}


import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Codeforces {
    public static void main(String args[]) throws Exception {
        //Scanner s = new Scanner(new FileInputStream("input.txt"));
        //PrintStream p = new PrintStream("output.txt");
        Scanner s = new Scanner(System.in);

        int f = 5 * 60;
        int l = 24 * 60 - 1;

        int a, Ta, b, Tb, start;
        a = s.nextInt();
        Ta = s.nextInt();
        b = s.nextInt();
        Tb = s.nextInt();

        s.nextLine();
        String tmp = s.nextLine();
        String[] tmp1 = tmp.split(":");
        start = ((tmp1[0].toCharArray()[0] - '0') * 10 + (tmp1[0].toCharArray()[1]) - '0') * 60 + (tmp1[1].toCharArray()[0] - '0') * 10 + (tmp1[1].toCharArray()[1] - '0');
        //System.out.println(start);

        //int lb = (start - Tb - f) / b * b + f;
        //int rb = (start + Ta - f) / b * b + f;
        int lb = f, rb = f;
        while (lb <= start - Tb) lb += b;
        while (rb <= start + Ta) rb += b;
        rb -= b;
        //System.out.println("" + f + ' ' + lb + ' ' + l + ' ' + rb);

        //if (lb + Tb <= start) lb += b;
        //if (rb >= a + Ta) rb -= b;

        //System.out.println("" + f + ' ' + lb + ' ' + l + ' ' + rb);
        while (lb < f) lb += b;
        while (rb > l) rb -= b;
        //System.out.println("" + f + ' ' + lb + ' ' + l + ' ' + rb);
        System.out.print((rb - lb) / b);
    }
}


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

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 1e9 + 10;
    static final long OO = (long) 2e18 + 20;
    static final int MOD = (int) 1e9 + 7;

    static int n;
    static int[] par, p;

    static int findSet(int u) {
        if (par[u] == u)
            return u;
        return par[u] = findSet(par[u]);
    }

    static class SegTree {
        class Node {
            int max;
            Pair lr;

            Node(int max, Pair lr) {
                this.max = max;
                this.lr = lr;
            }
        }
        Node[] t;
        int size;

        void push(int u) {
            if (t[u].lr.l != -1) {
                t[u * 2 + 1].lr.l = t[u].lr.l;
                t[u * 2 + 1].lr.r = t[u].lr.r;
                t[u * 2 + 2].lr.l = t[u].lr.l;
                t[u * 2 + 2].lr.r = t[u].lr.r;
                t[u].lr.l = t[u].lr.r = -1;
            }
        }
        void pull(int u) {
            t[u].max = p[t[u * 2 + 1].max] > p[t[u * 2 + 2].max] ? t[u * 2 + 1].max : t[u * 2 + 2].max;
        }
        void build(int u, int tl, int tr, int[][] initial) {
            if (tl == tr) {
                t[u] = new Node(initial[tl][0], new Pair(initial[tl][1], initial[tl][2]));
            } else {
                int tm = (tl + tr) / 2;
                build(u * 2 + 1, tl, tm, initial);
                build(u * 2 + 2, tm + 1, tr, initial);
                t[u] = new Node(-1, new Pair(-1, -1));
                pull(u);
            }
        }
        int maxPOn(int u, int tl, int tr, int l, int r) {
            if (r < tl || tr < l)
                return n;
            if (l <= tl && tr <= r)
                return t[u].max;
            int tm = (tl + tr) / 2;
            push(u);
            int v1 = maxPOn(u * 2 + 1, tl, tm, l, r);
            int v2 = maxPOn(u * 2 + 2, tm + 1, tr, l, r);
            return p[v1] > p[v2] ? v1 : v2;
        }
        void setPIn(int u, int tl, int tr, int i, int p) {
            if (tl == tr) {

            } else {
                int tm = (tl + tr) / 2;
                push(u);
                if (i <= tm) {
                    setPIn(u * 2 + 1, tl, tm, i, p);
                } else {
                    setPIn(u * 2 + 2, tm + 1, tr, i, p);
                }
                pull(u);
            }
        }
        void setLROn(int u, int tl, int tr, int l, int r, int newL, int newR) {
            if (r < tl || tr < l)
                return;
            if (l <= tl && tr <= r) {
                t[u].lr.l = newL;
                t[u].lr.r = newR;
                return;
            }
            int tm = (tl + tr) / 2;
            push(u);
            setLROn(u * 2 + 1, tl, tm, l, r, newL, newR);
            setLROn(u * 2 + 2, tm + 1, tr, l, r, newL, newR);
            pull(u);
        }
        Pair LRIn(int u, int tl, int tr, int i) {
            if (tl == tr) {
                return t[u].lr;
            }
            int tm = (tl + tr) / 2;
            push(u);
            if (i <= tm) {
                return LRIn(u * 2 + 1, tl, tm, i);
            } else {
                return LRIn(u * 2 + 2, tm + 1, tr, i);
            }
        }

        void build(int[][] initial) {
            size = initial.length;
            t = new Node[size * 4];
            build(0, 0, size - 1, initial);
        }
        int maxPOn(int l, int r) {
            return maxPOn(0, 0, size - 1, l, r);
        }
        void setPIn(int i, int p) {
            setPIn(0, 0, size - 1, i, p);
        }
        void setLROn(int l, int r, int newL, int newR) {
            setLROn(0, 0, size - 1, l, r, newL, newR);
        }
        Pair LRIn(int i) {
            return LRIn(0, 0, size - 1, i);
        }
    }

    static class Pair {
        int l, r;

        Pair(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }

    static class Edge {
        int u, v, l1, r1, l2, r2;
        boolean removed;

        Edge(int u, int v) {
            this.u = u;
            this.v = v;
            l1 = r1 = l2 = r2 = -1;
        }
    }

    static class Query {
        int type, x;

        Query(int type, int x) {
            this.type = type;
            this.x = x;
        }
    }

    static void solve() {
        n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();

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

        Edge[] edges = new Edge[m];
        for (int i = 0; i < m; i++) {
            int u = in.nextInt() - 1;
            int v = in.nextInt() - 1;
            edges[i] = new Edge(u, v);
        }

        Query[] queries = new Query[q];
        for (int i = 0; i < q; i++) {
            int type = in.nextInt();
            int x = in.nextInt() - 1;
            queries[i] = new Query(type, x);
            if (type == 2)
                edges[x].removed = true;
        }

        par = new int[n];
        int[] size = new int[n];
        ArrayList<Integer>[] subtree = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            par[i] = i;
            size[i] = 1;
            subtree[i] = new ArrayList<>(List.of(i));
        }

        for (Edge e : edges) {
            if (e.removed)
                continue;
            int u = findSet(e.u);
            int v = findSet(e.v);
            if (u == v)
                continue;
            if (size[u] < size[v]) {
                u ^= v; v ^= u; u ^= v;
            }
            par[v] = u;
            size[u] += size[v];
            subtree[u].addAll(subtree[v]);
        }

        for (int i = q - 1; i >= 0; i--) {
            Query query = queries[i];
            if (query.type == 1)
                continue;
            Edge e = edges[query.x];
            int u = findSet(e.u);
            int v = findSet(e.v);
            if (u == v)
                continue;
            if (size[u] < size[v]) {
                u ^= v; v ^= u; u ^= v;
            }
            par[v] = u;
            size[u] += size[v];
            e.l1 = subtree[u].get(0);
            e.r1 = subtree[u].get(subtree[u].size() - 1);
            e.l2 = subtree[v].get(0);
            e.r2 = subtree[v].get(subtree[v].size() - 1);
            subtree[u].addAll(subtree[v]);
        }

        int[][] initial = new int[n][3];
        int[] pos = new int[n];
        for (int u = 0, i = 0; u < n; u++) {
            if (findSet(u) == u) {
                initial[u][1] = i;
                initial[u][2] = i + size[u] - 1;
                for (int v : subtree[u]) {
                    initial[i][0] = v;
                    initial[i][1] = initial[u][1];
                    initial[i][2] = initial[u][2];
                    pos[v] = i;
                    i++;
                }
            }
        }

        SegTree st = new SegTree();
        st.build(initial);

        for (int i = 0; i < q; i++) {
            Query query = queries[i];
            if (query.type == 1) {
                int u = query.x;
                Pair lr = st.LRIn(pos[u]);
                int v = st.maxPOn(lr.l, lr.r);
                out.println(p[v]);
                if (v != n) {
                    p[v] = 0;
                    st.setPIn(pos[v], 0);
                }
            } else {
                Edge e = edges[query.x];
                if (e.l1 != -1) {
                    st.setLROn(pos[e.l1], pos[e.r1], pos[e.l1], pos[e.r1]);
                    st.setLROn(pos[e.l2], pos[e.r2], pos[e.l2], pos[e.r2]);
                }
            }
        }

    }

    public static void main(String[] args) {
        in = new FastReader();
        out = new PrintWriter(System.out);
//        fileInputOutput();

        int T = 1;
//        T = in.nextInt();
        while (T-- > 0)
            solve();

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

    static void fileInputOutput() {
        try {
            in = new FastReader("input.txt");
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    static void runInThread() {
        Thread thread = new Thread(null, () -> {
            int T = 1;
//            T = in.nextInt();
            while (T-- > 0)
                solve();
        }, "thread1", 1 << 28);
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            this(System.in);
        }
        FastReader(String file) throws FileNotFoundException {
            this(new FileInputStream(file));
        }
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }
        String nextLine() {
            String line;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


import java.io.*;
import java.util.*;
public class Main{
	static int[] p, rank, treeNode,adj[];
	static boolean[]root;
	static int numSets,N;
	static int lastNode=0;
	static void preProcessDSU(int n) {
		N=n;
		p = new int[numSets = N];
		rank = new int[N];
		treeNode = new int[N];
		root=new boolean[N<<1];
		adj=new int[N<<1][2];

		for (int i = 0; i < N; i++) {
			p[i] = i; treeNode[i] = lastNode++; root[i]=true;
			adj[i<<1][0]=adj[i<<1][1]=adj[i<<1|1][0]=adj[i<<1|1][1]=-1;
		}
	}
	public static int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); }

	public static boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); }

	public static void unionSet(int i, int j)
	{
		if (isSameSet(i, j))
			return;
		numSets--;
		int x = findSet(i), y = findSet(j);

		int u=treeNode[x],v=treeNode[y];
		root[u]=false;root[v]=false;
		int newRoot=lastNode++;
		root[newRoot]=true;
		adj[newRoot][0]=u;adj[newRoot][1]=v;

		if(rank[x] > rank[y]) { p[y] = x; treeNode[x]=newRoot;}
		else
		{	p[x] = y; treeNode[y]=newRoot;
			if(rank[x] == rank[y]) rank[y]++;
		}

	}
	static int time,tin[],tout[];
	static void dfs(int i) {
		tin[i]=++time;
		for(int j:adj[i]) {
			if(j==-1)continue;
			dfs(j);
		}
		tout[i]=time;
	}
	static int[]segTree,index;
	static void updatePoint(int idx) {
		updatePoint(1, 1, time, idx);
	}
	static void updatePoint(int node,int l,int r,int idx) {
		if(l==r) {
			segTree[node]=0;
			return;
		}
		int mid=(l+r)>>1;
		if(idx<=mid) {
			updatePoint(node<<1, l, mid, idx);
		}
		else {
			updatePoint(node<<1|1, mid+1, r, idx);
		}
		if(segTree[node<<1|1]>segTree[node<<1]) {
			segTree[node]=segTree[node<<1|1];
			index[node]=index[node<<1|1];
		}
		else {
			segTree[node]=segTree[node<<1];
			index[node]=index[node<<1];
		}
	}
	static int[] query(int l,int r) {
		return query(1, 1, time,l,r);
	}
	static int[] query(int node,int curL,int curR,int l,int r) {
		if(curR<l || curL>r)return new int[] {-1,-1};
		if(curL>=l && curR<=r) {
			return new int[] {segTree[node],index[node]};
		}
		int mid=(curL+curR)>>1;
		int[]q1=query(node<<1, curL, mid, l, r),q2=query(node<<1|1, mid+1, curR, l, r);
		if(q1[0]>q2[0]) {
			return q1;
		}
		return q2;
	}
	static void insert(int idx,int val) {
		insert(1, 1, time, idx,val);
	}
	static void insert(int node,int l,int r,int idx,int val) {
		if(l==r) {
			segTree[node]=val;
			index[node]=idx;
			return;
		}
		int mid=(l+r)>>1;
		if(idx<=mid) {
			insert(node<<1, l, mid, idx,val);
		}
		else {
			insert(node<<1|1, mid+1, r, idx,val);
		}
		if(segTree[node<<1|1]>segTree[node<<1]) {
			segTree[node]=segTree[node<<1|1];
			index[node]=index[node<<1|1];
		}
		else {
			segTree[node]=segTree[node<<1];
			index[node]=index[node<<1];
		}
	}
	static void main() throws Exception{
		int n=sc.nextInt(),m=sc.nextInt(),q=sc.nextInt();
		int[]vals=sc.intArr(n);
		int[][]edges=new int[m][];
		for(int i=0;i<m;i++) {
			edges[i]=new int[] {sc.nextInt()-1,sc.nextInt()-1};
		}
		int[][]qs=new int[q][];
		boolean[]edgeRemoved=new boolean[m];
		for(int i=0;i<q;i++) {
			qs[i]=new int[] {sc.nextInt(),sc.nextInt()-1};
			if(qs[i][0]==2) {
				edgeRemoved[qs[i][1]]=true;
			}
		}
		preProcessDSU(n);
		for(int i=0;i<m;i++) {
			if(!edgeRemoved[i]) {
				unionSet(edges[i][0], edges[i][1]);
			}
		}
		int[]subtreeRoot=new int[q];
		for(int i=q-1;i>=0;i--) {
			if(qs[i][0]==1) {
				subtreeRoot[i]=treeNode[findSet(qs[i][1])];
			}
			else {
				int edge=qs[i][1];
				unionSet(edges[edge][0], edges[edge][1]);
			}
		}
		tin=new int[n<<1];
		tout=new int[n<<1];
		for(int i=0;i<lastNode;i++) {
			if(root[i]) {
				dfs(i);
			}
		}
		segTree=new int[time<<2];
		index=new int[time<<2];
		for(int i=0;i<n;i++) {
			insert(tin[i], vals[i]);
		}
		for(int i=0;i<q;i++) {
			if(qs[i][0]==1) {
				int curRoot=subtreeRoot[i];
				int left=tin[curRoot],right=tout[curRoot];
				int[]curQ=query(left, right);
				pw.println(curQ[0]);
				updatePoint(curQ[1]);
			}
		}
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int numQueries = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = -in.nextInt();
            }
            int[] a = new int[m];
            int[] b = new int[m];
            for (int i = 0; i < m; i++) {
                a[i] = in.nextInt() - 1;
                b[i] = in.nextInt() - 1;
            }
            int[] type = new int[numQueries];
            int[] val = new int[numQueries];
            boolean[] willDie = new boolean[m];
            for (int i = 0; i < numQueries; i++) {
                type[i] = in.nextInt();
                val[i] = in.nextInt() - 1;
                if (type[i] == 2) {
                    willDie[val[i]] = true;
                }
            }

            int[] parent = new int[n];
            Arrays.fill(parent, -1);
            DSU dsu = new DSU(n);
            Graph g = new Graph(n + 1);
            for (int i = 0; i < m; i++) {
                if (willDie[i]) {
                    continue;
                }
                int u = dsu.findComp(a[i]);
                int v = dsu.findComp(b[i]);
                if (u == v) {
                    continue;
                }
                dsu.merge(u, v);
                if (dsu.p[v] == u) {
                    int t = u;
                    u = v;
                    v = t;
                }
                parent[u] = v;
                g.addEdge(v, u, i);
            }

            for (int i = numQueries - 1; i >= 0; i--) {
                if (type[i] == 1) {
                    val[i] = dsu.findComp(val[i]);
                    continue;
                }
                int u = dsu.findComp(a[val[i]]);
                int v = dsu.findComp(b[val[i]]);
                if (u == v) {
                    continue;
                }
                parent[u] = v;
                dsu.merge(u, v);
                if (dsu.p[v] == u) {
                    int t = u;
                    u = v;
                    v = t;
                }
                g.addEdge(v, u, i);
            }

            int root = n;
            for (int i = 0; i < n; i++) {
                if (parent[i] < 0) {
                    g.addEdge(root, i, -1);
                }
            }
            EulerTourNumbering et = new EulerTourNumbering(g, root);

            MinTree mt = new MinTree(n + 1);
            int[] q = new int[n + 1];
            for (int i = 0; i < n; i++) {
                q[et.timeIn[i]] = p[i];
                mt.set(et.timeIn[i], p[i]);
            }

            boolean[] dead = new boolean[m];
            for (int i = 0; i < numQueries; i++) {
                if (type[i] == 2) {
                    dead[val[i]] = true;
                    continue;
                }
                int pos = et.timeIn[val[i]];
                int l = pos;
                int r = pos;
                for (int e = g.firstEdge[val[i]]; e >= 0; e = g.edgeNxt[e]) {
                    int origId = g.edgeId[e];
                    int dst = g.edgeDst[e];
                    if (dead[origId]) {
                        if (l >= 0) {
                            int cand = mt.getMinPos(l, r);
                            if (q[pos] > q[cand]) {
                                pos = cand;
                            }
                            l = -1;
                        }
                        continue;
                    }
                    if (l < 0) {
                        l = et.timeIn[dst];
                    }
                    r = et.timeOut[dst] - 1;
                }
                if (l >= 0) {
                    int cand = mt.getMinPos(l, r);
                    if (q[pos] > q[cand]) {
                        pos = cand;
                    }
                    l = -1;
                }
                out.println(-q[pos]);
                q[pos] = 0;
                mt.set(pos, 0);
            }
        }

        class EulerTourNumbering {
            Graph g;
            int[] tour;
            int[] timeIn;
            int[] timeOut;
            int globalTime;

            EulerTourNumbering(Graph g, int root) {
                this.g = g;
                int n = g.n;
                timeIn = new int[n];
                timeOut = new int[n];
                tour = new int[n];

                dfs(root, -1);
                if (globalTime != n) {
                    throw new AssertionError();
                }
            }

            void dfs(int v, int p) {
                tour[globalTime] = v;
                timeIn[v] = globalTime++;
                for (int e = g.firstEdge[v]; e >= 0; e = g.edgeNxt[e]) {
                    int u = g.edgeDst[e];
                    if (u == p) {
                        continue;
                    }
                    dfs(u, v);
                }
                timeOut[v] = globalTime;
            }

        }

        class Graph {
            int n;
            int[] firstEdge;
            int[] edgeDst;
            int[] edgeNxt;
            int[] edgeId;
            int numEdges;

            Graph(int n) {
                this.n = n;
                firstEdge = new int[n];
                Arrays.fill(firstEdge, -1);
                final int initialCapacity = 2 * n - 2;
                edgeDst = new int[initialCapacity];
                edgeNxt = new int[initialCapacity];
                edgeId = new int[initialCapacity];
                numEdges = 0;
            }

            void addEdge(int a, int b, int origId) {
                int e = numEdges++;
                if (e >= edgeDst.length) {
                    reallocate();
                }
                edgeDst[e] = b;
                edgeNxt[e] = firstEdge[a];
                firstEdge[a] = e;
                edgeId[e] = origId;
            }

            private void reallocate() {
                int k = edgeDst.length;
                edgeDst = Arrays.copyOf(edgeDst, 3 * k / 2);
                edgeNxt = Arrays.copyOf(edgeNxt, 3 * k / 2);
                edgeId = Arrays.copyOf(edgeId, 3 * k / 2);
            }

        }

        class MinTree {
            int n;
            int[] a;
            int[] where;
            final int infinity = (int) 1e9;

            MinTree(int size) {
                n = 1;
                while (n < size) {
                    n *= 2;
                }
                a = new int[2 * n];
                where = new int[2 * n];
                Arrays.fill(a, infinity);
            }

            void set(int pos, int val) {
                pos += n;
                a[pos] = val;
                where[pos] = pos - n;
                while (pos > 1) {
                    pos /= 2;
                    a[pos] = Math.min(a[2 * pos], a[2 * pos + 1]);
                    if (a[pos] == a[2 * pos]) {
                        where[pos] = where[2 * pos];
                    } else {
                        where[pos] = where[2 * pos + 1];
                    }
                }
            }

            int getMinPos(int l, int r) {
                if (l > r) {
                    return infinity;
                }
                l += n;
                r += n;
                if (l == r) {
                    return where[l];
                }
                int lm = a[l];
                int rm = a[r];
                int lp = where[l];
                int rp = where[r];
                while (r - l > 1) {
                    if (l % 2 == 0) {
                        if (lm > a[l + 1]) {
                            lm = a[l + 1];
                            lp = where[l + 1];
                        }
                    }
                    if (r % 2 != 0) {
                        if (rm > a[r - 1]) {
                            rm = a[r - 1];
                            rp = where[r - 1];
                        }
                    }
                    l /= 2;
                    r /= 2;
                }
                return lm < rm ? lp : rp;
            }

        }

        class DSU {
            int[] rank;
            int[] p;
            int numComps;

            DSU(int n) {
                rank = new int[n];
                p = new int[n];
                reset();
            }

            void reset() {
                for (int i = 0; i < p.length; i++) {
                    rank[i] = 0;
                    p[i] = i;
                }
                numComps = p.length;
            }

            private int findComp(int x) {
                int r;
                int saved;

                saved = x;
                while (x != p[x]) {
                    x = p[x];
                }
                r = x;

                x = saved;
                while (x != r) {
                    saved = p[x];
                    p[x] = r;
                    x = saved;
                }
                return r;
            }

            private void merge(int a, int b) {
                a = findComp(a);
                b = findComp(b);
                if (a == b) {
                    return;
                }
                --numComps;
                if (rank[a] < rank[b]) {
                    p[a] = b;
                } else {
                    p[b] = a;
                    if (rank[a] == rank[b]) {
                        ++rank[a];
                    }
                }
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int numQueries = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = -in.nextInt();
            }
            int[] a = new int[m];
            int[] b = new int[m];
            for (int i = 0; i < m; i++) {
                a[i] = in.nextInt() - 1;
                b[i] = in.nextInt() - 1;
            }
            int[] type = new int[numQueries];
            int[] val = new int[numQueries];
            boolean[] willDie = new boolean[m];
            for (int i = 0; i < numQueries; i++) {
                type[i] = in.nextInt();
                val[i] = in.nextInt() - 1;
                if (type[i] == 2) {
                    willDie[val[i]] = true;
                }
            }

            int[] parent = new int[n];
            Arrays.fill(parent, -1);
            DSU dsu = new DSU(n);
            Graph g = new Graph(n + 1);
            for (int i = 0; i < m; i++) {
                if (willDie[i]) {
                    continue;
                }
                int u = dsu.findComp(a[i]);
                int v = dsu.findComp(b[i]);
                if (u == v) {
                    continue;
                }
                dsu.merge(u, v);
                if (dsu.p[v] == u) {
                    int t = u;
                    u = v;
                    v = t;
                }
                parent[u] = v;
                g.addEdge(v, u, i);
            }

            for (int i = numQueries - 1; i >= 0; i--) {
                if (type[i] == 1) {
                    val[i] = dsu.findComp(val[i]);
                    continue;
                }
                int u = dsu.findComp(a[val[i]]);
                int v = dsu.findComp(b[val[i]]);
                if (u == v) {
                    continue;
                }
                dsu.merge(u, v);
                if (dsu.p[v] == u) {
                    int t = u;
                    u = v;
                    v = t;
                }
                parent[u] = v;
                g.addEdge(v, u, val[i]);
            }

            int root = n;
            for (int i = 0; i < n; i++) {
                if (parent[i] < 0) {
                    g.addEdge(root, i, -1);
                }
            }
            EulerTourNumbering et = new EulerTourNumbering(g, root);

            MinTree mt = new MinTree(n + 1);
            int[] q = new int[n + 1];
            for (int i = 0; i < n; i++) {
                q[et.timeIn[i]] = p[i];
                mt.set(et.timeIn[i], p[i]);
            }

            boolean[] dead = new boolean[m];
            for (int i = 0; i < numQueries; i++) {
                if (type[i] == 2) {
                    dead[val[i]] = true;
                    continue;
                }
                int pos = et.timeIn[val[i]];
                int l = pos;
                int r = pos;
                for (int e = g.firstEdge[val[i]]; e >= 0; e = g.edgeNxt[e]) {
                    int origId = g.edgeId[e];
                    int dst = g.edgeDst[e];
                    if (dead[origId]) {
                        if (l >= 0) {
                            int cand = mt.getMinPos(l, r);
                            if (q[pos] > q[cand]) {
                                pos = cand;
                            }
                            l = -1;
                        }
                        continue;
                    }
                    if (l < 0) {
                        l = et.timeIn[dst];
                    }
                    r = et.timeOut[dst] - 1;
                }
                if (l >= 0) {
                    int cand = mt.getMinPos(l, r);
                    if (q[pos] > q[cand]) {
                        pos = cand;
                    }
                    l = -1;
                }
                out.println(-q[pos]);
                q[pos] = 0;
                mt.set(pos, 0);
            }
        }

        class EulerTourNumbering {
            Graph g;
            int[] tour;
            int[] timeIn;
            int[] timeOut;
            int globalTime;

            EulerTourNumbering(Graph g, int root) {
                this.g = g;
                int n = g.n;
                timeIn = new int[n];
                timeOut = new int[n];
                tour = new int[n];

                dfs(root, -1);
                if (globalTime != n) {
                    throw new AssertionError();
                }
            }

            void dfs(int v, int p) {
                tour[globalTime] = v;
                timeIn[v] = globalTime++;
                for (int e = g.firstEdge[v]; e >= 0; e = g.edgeNxt[e]) {
                    int u = g.edgeDst[e];
                    if (u == p) {
                        continue;
                    }
                    dfs(u, v);
                }
                timeOut[v] = globalTime;
            }

        }

        class Graph {
            int n;
            int[] firstEdge;
            int[] edgeDst;
            int[] edgeNxt;
            int[] edgeId;
            int numEdges;

            Graph(int n) {
                this.n = n;
                firstEdge = new int[n];
                Arrays.fill(firstEdge, -1);
                final int initialCapacity = 2 * n - 2;
                edgeDst = new int[initialCapacity];
                edgeNxt = new int[initialCapacity];
                edgeId = new int[initialCapacity];
                numEdges = 0;
            }

            void addEdge(int a, int b, int origId) {
                int e = numEdges++;
                if (e >= edgeDst.length) {
                    reallocate();
                }
                edgeDst[e] = b;
                edgeNxt[e] = firstEdge[a];
                firstEdge[a] = e;
                edgeId[e] = origId;
            }

            private void reallocate() {
                int k = edgeDst.length;
                edgeDst = Arrays.copyOf(edgeDst, 3 * k / 2);
                edgeNxt = Arrays.copyOf(edgeNxt, 3 * k / 2);
                edgeId = Arrays.copyOf(edgeId, 3 * k / 2);
            }

        }

        class MinTree {
            int n;
            int[] a;
            int[] where;
            final int infinity = (int) 1e9;

            MinTree(int size) {
                n = 1;
                while (n < size) {
                    n *= 2;
                }
                a = new int[2 * n];
                where = new int[2 * n];
                Arrays.fill(a, infinity);
            }

            void set(int pos, int val) {
                pos += n;
                a[pos] = val;
                where[pos] = pos - n;
                while (pos > 1) {
                    pos /= 2;
                    a[pos] = Math.min(a[2 * pos], a[2 * pos + 1]);
                    if (a[pos] == a[2 * pos]) {
                        where[pos] = where[2 * pos];
                    } else {
                        where[pos] = where[2 * pos + 1];
                    }
                }
            }

            int getMinPos(int l, int r) {
                if (l > r) {
                    return infinity;
                }
                l += n;
                r += n;
                if (l == r) {
                    return where[l];
                }
                int lm = a[l];
                int rm = a[r];
                int lp = where[l];
                int rp = where[r];
                while (r - l > 1) {
                    if (l % 2 == 0) {
                        if (lm > a[l + 1]) {
                            lm = a[l + 1];
                            lp = where[l + 1];
                        }
                    }
                    if (r % 2 != 0) {
                        if (rm > a[r - 1]) {
                            rm = a[r - 1];
                            rp = where[r - 1];
                        }
                    }
                    l /= 2;
                    r /= 2;
                }
                return lm < rm ? lp : rp;
            }

        }

        class DSU {
            int[] rank;
            int[] p;
            int numComps;

            DSU(int n) {
                rank = new int[n];
                p = new int[n];
                reset();
            }

            void reset() {
                for (int i = 0; i < p.length; i++) {
                    rank[i] = 0;
                    p[i] = i;
                }
                numComps = p.length;
            }

            private int findComp(int x) {
                int r;
                int saved;

                saved = x;
                while (x != p[x]) {
                    x = p[x];
                }
                r = x;

                x = saved;
                while (x != r) {
                    saved = p[x];
                    p[x] = r;
                    x = saved;
                }
                return r;
            }

            private void merge(int a, int b) {
                a = findComp(a);
                b = findComp(b);
                if (a == b) {
                    return;
                }
                --numComps;
                if (rank[a] < rank[b]) {
                    p[a] = b;
                } else {
                    p[b] = a;
                    if (rank[a] == rank[b]) {
                        ++rank[a];
                    }
                }
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        final int N = scanner.nextInt();
        final int arr[] = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
        }
        System.out.println(isPossible(arr, 0, 0) ? "Yes" : "No");
    }
    static boolean isPossible(final int arr[], final int l, final int cnt) {
        if (l >= arr.length) {
            if ((cnt & 1) == 1) return true;
            return false;
        }
        if ((arr[l] & 1) == 0) return false;
        for (int i = l; i < arr.length; i+=2) {
            if ((arr[i] & 1) == 1 && isPossible(arr, i + 1, cnt + 1)) {
                return true;
            }
        }
        return false;
    }
}


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 Toni Rajkovski
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    FastReader in = new FastReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {
    int[] nums;

    public void solve(int testNumber, FastReader in, PrintWriter out) {
      int n = in.nextInt();
      nums = new int[n];

      for (int i = 0; i < n; i++) nums[i] = in.nextInt() % 2;
      out.println(check(0, n - 1, false) ? "Yes" : "No");

    }

    private boolean check(int fromPos, int toPos, boolean pair) {
      if (nums[fromPos] == 0 || nums[toPos] == 0) return false;
      if ((toPos - fromPos + 1) % 2 == 1 && !pair) return true;
      for (int i = fromPos; i < toPos; i++) {
        if ((i - fromPos + 1) % 2 == 1 && nums[i] == 1) {
          if (check(i + 1, toPos, !pair)) return true;
        }
      }
      return false;
    }

  }

  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

  }
}


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

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int n, m, a, b, c, d, array[] = new int[1101];

		n = scanner.nextInt();
		m = scanner.nextInt();
		c =  scanner.nextInt();
		d = scanner.nextInt();
		for(int i = c; i <= n; i++)
		    array[i] = mas[i-c] + d;
		for(int i = 0; i < m; i++){
		    a = scanner.nextInt();
		    b = scanner.nextInt();
		    c = scanner.nextInt();
		    d = scanner.nextInt();
		    for(int j = 0; j < a / b; j++)
		        for(int k = n; k >= c; k--)
		            array[k] = Math.max(array[k], array[k-c] + d);
		}
		System.out.println(array[n]);
	}
}


import java.math.*;
import java.util.*;
import java.util.stream.IntStream;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		final int c0, d0;
		int n, m, a, b, c, d, array[] = new int[1005];
		n = scanner.nextInt();
		m = scanner.nextInt();

		c0 =  scanner.nextInt();
		d0 = scanner.nextInt();
		IntStream.rangeClosed(c0, n).forEach(i -> array[i] = array[i-c0] + d0);
		IntStream.range(0, m).forEach(i -> {
		    a = scanner.nextInt();
		    b = scanner.nextInt();
		    c = scanner.nextInt();
		    d = scanner.nextInt();
		    for(int j = 0; j < a / b; j++)
		        for(int k = n; k >= c; k--)
		            array[k] = Math.max(array[k], array[k-c] + d);
		});
		System.out.println(array[n]);
	}
}


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

public class Main {

	static int[] dough, stuffing ,constuffing, earn;
	static int n, m ;
	static long[][][] dp ;
	static long solve(int n , int index , int rem)
	{
		if(n==0 || index>m)
			return 0;

		if(dp[n][index][rem]!=-1)
		{
			return dp[n][index][rem];
		}
		long result = 0;

			if(index==0 && n-dough[0]>=0)
			{
				result = Math.max(result, earn[0]+solve(n-dough[0],index,0));
			}

			else if(stuffing[index] - constuffing[index] >=0 && n-dough[index]>=0 )
			{
				int temp1 = stuffing[index];
				stuffing[index] -= constuffing[index] ;
				result =   earn[index]+solve(n-dough[index],index,stuffing[index]);
				stuffing[index]= temp1 ;

			}
			if(index<m)
				result = Math.max(result, solve(n,index+1,stuffing[index+1]));

		return dp[n][index][rem]=result ;

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

		BufferedReader re = new BufferedReader(new InputStreamReader(System.in));

		String[] temp = re.readLine().split(" ");
		n = Integer.parseInt(temp[0]);
		m = Integer.parseInt(temp[1]);
		dough = new int[m+1];
		stuffing = new int[m+1];
		constuffing= new int[m+1];
		earn = new int[m+1];
		dp = new long[n+1][(1<<m ) +1][100+1];
		for (int i = 0; i < n+1; i++) {
			for (int j = 0; j <= 1<<m; j++) {
				for (int j2 = 0; j2 <= 100; j2++) {
					dp[i][j][j2] =-1;
				}

			}
		}
		dough[0] = Integer.parseInt(temp[2]);
		earn[0]  = Integer.parseInt(temp[3]);

		for (int i = 0; i < m; i++) {
			temp = re.readLine().split(" ");
			stuffing[i+1]  = Integer.parseInt(temp[0]);
			constuffing[i+1]  = Integer.parseInt(temp[1]);
			dough[i+1]  = Integer.parseInt(temp[2]);
			earn[i+1] =   Integer.parseInt(temp[3]);
		}

		System.out.println(solve(n,0,0));

	}

}


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

public class Main {

	static int tam;
	static rell[] s;
	static int precio[],peso[];
	static int dp[][];

	static int solve(int w, int index) {
		if (index >= tam || w <= 0) return 0;
		if(dp[w][index] != 0) return dp[w][index];
		if (w < peso[index]) return solve(w,index + 1);
		dp[w][index] = Math.max(solve(w - peso[index],index + 1) + precio[index], solve(w,index + 1));
		return dp[w][index];
	}

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tk;
		int n,m,c0,d0,a,b,c,d;
		tk = new StringTokenizer(bf.readLine());
		n = Integer.parseInt(tk.nextToken());
		m = Integer.parseInt(tk.nextToken());
		c0 = Integer.parseInt(tk.nextToken());
		d0 = Integer.parseInt(tk.nextToken());
		s = new rell[m+1];
		s[0] = new rell(n, c0, c0, d0);
		tam = n/c0;
		for (int i = 1; i <= m; i++) {
			tk = new StringTokenizer(bf.readLine());
			a = Integer.parseInt(tk.nextToken());
			b= Integer.parseInt(tk.nextToken());
			c= Integer.parseInt(tk.nextToken());
			d= Integer.parseInt(tk.nextToken());
			s[i] = new rell(a, b, c, d);
			tam += (a/b);
		}
		peso = new int [tam];
		precio = new int[tam];
		dp = new int[n+1][tam];
		int cont = 0;
		int max = 0;
		for (int i = 0; i < m+1; i++) {
			max = cont  + (s[i].a / s[i].b);
			for (int j = cont; j < max; j++) {
				peso[j] = s[i].c;
				precio[j] = s[i].d;
				cont ++;
			}
		}
		System.out.println(solve(n,0));
	}
	class rell {
	int a,b,c,d;

	public rell(int a, int b, int c, int d) {
		super();
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = d;
	}
}
}


import java.util.*;
public class A
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String str=sc.next();
        int count=0;
        String ans="";
        String com="xxx";
        for(int i=0;i<n-3;i++)
        {
            ans=str.substring(i,i+3);
            if(ans.compareTo(com))
            count++;
        }
        System.out.println(count);
    }
}


import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class A978 {
	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.nextLine());
		String str = scan.nextLine();
		int bo = 0;
		for(int i = 0; i < n; i ++){
		    if(str.charAt(i)=='x'){
		        bo++;
		    }
		}
		if(bo == n){
		    System.out.println(n - 2);
		    System.exit(0);
		}
		s =   str + "i";
	//	System.out.println(s);
		char[] bar = s.toCharArray();
		ArrayList<Integer> non_x = new ArrayList<Integer>();

		int x =0;
		for(int i =0 ; i < n+1; i++) {
			if(bar[i] != 'x') {
				non_x.add(i);
			}
		}

		int counter = 0;

	//	System.out.println(non_x);

		ArrayList<Integer> arr = new ArrayList<Integer>();
		for(int i =0 ; i < non_x.size()-1; i ++) {
			arr.add(non_x.get(i+1)- non_x.get(i));
		}

		if(non_x.get(0)> 2) {

			counter += non_x.get(0)-2;
		}
		for(int i =1 ; i < arr.size(); i ++) {
			if(arr.get(i)>2) {
				counter += arr.get(i)-2;

			}
		}
		System.out.println(counter);

	}

}


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

import static java.lang.Math.*;

public class Main {
    static ArrayList<Integer>[] gr, g;
    static TreeMap<Integer, Integer> way;
    static int[] types, dist;
    static boolean[] used;
    static int INF = (int) 1e9;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        gr = new ArrayList[n];
        g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            gr[i] = new ArrayList<>();
            g[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int from = sc.nextInt() - 1;
            int to = sc.nextInt() - 1;
            gr[from].add(to);
            g[to].add(from);
        }
        int k = sc.nextInt();
        int[] p = new int[k];
        for (int i = 0; i < k; i++)
            p[i] = sc.nextInt() - 1;
        way = new TreeMap<>();
        for (int i = 0; i < k - 1; i++)
            way.put(p[i], p[i + 1]);
        types = new int[n];
        //0 - none
        //1 - +
        //2 - -
        //3 - +-
        used = new boolean[n];
        dist = new int[n];
        Arrays.fill(dist, INF);
        dist[p[k - 1]] = 0;
        dfs(p[k - 1], -1);
        int cntMin = 0;
        int cntMax = 0;
        for (int i = 0; i < k - 1; i++) {
            if(types[p[i]] == 2) {
                cntMin++;
                cntMax++;
            }
            if(types[p[i]] == 3)
                cntMax++;
        }
        pw.print(cntMin + " " + cntMax);
        pw.close();
    }

    public static void dfs(int v, int p) {
        used[v] = true;
        for (int to : g[v]) {
            if (dist[to] > dist[v] + 1) {
                dist[to] = dist[v] + 1;
                if (way.containsKey(to) && way.get(to) == v)
                    types[to] = 1;
                else
                    types[to] = 2;
            } else if (dist[to] == dist[v] + 1) {
                if (way.containsKey(to) && way.get(to) == v)
                    types[to]++;
                else {
                    if (types[to] < 2)
                        types[to] += 2;
                }
            }
            if (!used[to])
                dfs(to, v);
        }
    }

    public static boolean isVowel(char a) {
        return a == 'a' || a == 'e' || a == 'u' || a == 'o' || a == 'y';
    }

    public static long binPow(long a, int n) {
        long p = a;
        long res = 1;
        while (n > 0) {
            if (n % 2 == 1)
                res *= p;
            p *= p;
            n /= 2;
        }
        return res;
    }

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

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

class chr {
    char a;
    int index;

    public chr(char a, int index) {
        this.a = a;
        this.index = index;
    }
}

class chrComp implements Comparator<chr> {
    public int compare(chr o1, chr o2) {
        return Character.compare(o1.a, o2.a);
    }
}

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

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

    public FastScanner(String fileName) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(fileName));
    }

    public boolean hasNext() {
        try {
            while (!st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return true;
        } catch (Exception e) {
            return false;
        }
    }

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

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

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

    public String next() {
        hasNext();
        return st.nextToken();
    }
}


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

import static java.lang.Math.*;

public class Main {
    static ArrayList<Integer>[] gr, g;
    static TreeMap<Integer, Integer> way;
    static int[] types, dist;
    static boolean[] used;
    static int INF = (int) 1e9;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        gr = new ArrayList[n];
        g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            gr[i] = new ArrayList<>();
            g[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int from = sc.nextInt() - 1;
            int to = sc.nextInt() - 1;
            gr[from].add(to);
            g[to].add(from);
        }
        int k = sc.nextInt();
        int[] p = new int[k];
        for (int i = 0; i < k; i++)
            p[i] = sc.nextInt() - 1;
        way = new TreeMap<>();
        for (int i = 0; i < k - 1; i++)
            way.put(p[i], p[i + 1]);
        types = new int[n];
        //0 - none
        //1 - +
        //2 - -
        //3 - +-
        used = new boolean[n];
        dist = new int[n];
        Arrays.fill(dist, INF);
        dist[p[k - 1]] = 0;
        dfs(p[k - 1], -1);
        int cntMin = 0;
        int cntMax = 0;
        for (int i = 0; i < k - 1; i++) {
            if (types[p[i]] == 2) {
                cntMin++;
                cntMax++;
            }
            if (types[p[i]] == 3)
                cntMax++;
        }
        pw.print(cntMin + " " + cntMax);
        pw.close();
    }

    public static void dfs(int v, int p) {
        used[v] = true;
        for (int to : g[v]) {
            if (dist[to] > dist[v] + 1) {
                dist[to] = dist[v] + 1;
                if (way.containsKey(to) && way.get(to) == v)
                    types[to] = 1;
                else
                    types[to] = 2;
                dfs(to, v);
            } else if (dist[to] == dist[v] + 1) {
                if (way.containsKey(to) && way.get(to) == v)
                    types[to]++;
                else {
                    if (types[to] < 2)
                        types[to] += 2;
                }
            }
        }
    }

    public static boolean isVowel(char a) {
        return a == 'a' || a == 'e' || a == 'u' || a == 'o' || a == 'y';
    }

    public static long binPow(long a, int n) {
        long p = a;
        long res = 1;
        while (n > 0) {
            if (n % 2 == 1)
                res *= p;
            p *= p;
            n /= 2;
        }
        return res;
    }

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

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

class chr {
    char a;
    int index;

    public chr(char a, int index) {
        this.a = a;
        this.index = index;
    }
}

class chrComp implements Comparator<chr> {
    public int compare(chr o1, chr o2) {
        return Character.compare(o1.a, o2.a);
    }
}

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

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

    public FastScanner(String fileName) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(fileName));
    }

    public boolean hasNext() {
        try {
            while (!st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return true;
        } catch (Exception e) {
            return false;
        }
    }

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

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

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

    public String next() {
        hasNext();
        return st.nextToken();
    }
}


//import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author zezo
 */
public class ASoftDrinking {
//
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {

        Scanner cs= new Scanner(System.in);
        int n=cs.nextInt();
        int k=cs.nextInt();
        int l=cs.nextInt();
        int c=cs.nextInt();
        int d=cs.nextInt();
        int p=cs.nextInt();
        int nl=cs.nextInt();
        int np=cs.nextInt();
        int milliliters=(k*l)/(n*nl);
        int grams=p/(n*np);
        int sliceoflime=(c*d)/n;
   //     System.out.println(" "+"milliliters= "+milliliters+" grams= "+grams+" sliceoflime= "+sliceoflime);
        int result =Math.min(milliliters, grams);
        int RESULT=Math.min(sliceoflime, result);
        System.out.println(RESULT);
    }

}


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

public class Solution
{

public static void main (String[] args)
	{

	Scanner  s=new Scanner(System.in);
int n=s.nextInt();
    String st=""+n;
    int i;
    for(i=st.length()-1;i>=0;i--){
    	if(st.charAt(i)!='0')
    		break;
    }
    int j=0;
    boolean ans=true;
    while(j<i){
    	if(st.charAt(j)!=st.charAt(i)){
    		ans=false;
    		break;
    	}
    	j++;
    	i--;
    }
	if(ans)
		System.out.println("YES");
	else
		System.out.println("NO");
	}


public class NastyaStudiesInformatics {
    static Integer[][] dp;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int l=scanner.nextInt();
        int r=scanner.nextInt();
        int x=scanner.nextInt();
        int y=scanner.nextInt();
        int count=0;
        dp=new Integer[r+1][r+1];
        for(int a=l;a<=r;a++){
            for (int b=a;b<=r;b++){
                int gcd=gcd(a,b);
                int lcm=a*b/gcd;
                if(x==gcd && lcm==y){
                    if(a==b){
                        count++;
                    }
                    else {
                        count=count+2;
                    }
                    //System.out.println(a+":"+b+":"+gcd);

                }

            }
        }
        System.out.println(count);
    }
    static int gcd(int a, int b){
        if(dp[a][b]!=null){
            return  dp[a][b];
        }
        if(b == 0) return a;
        dp[a][b]=gcd(b, a% b);
        return dp[a][b];
    }

}


import java.util.Scanner;

public class NastyaStudiesInformatics {
    static Integer[][] dp;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int l=scanner.nextInt();
        int r=scanner.nextInt();
        int x=scanner.nextInt();
        int y=scanner.nextInt();
        int count=0;
        dp=new Integer[r+1][r+1];
        for(int a=l;a<=r;a++){
            for (int b=a;b<=r;b++){
                int gcd=gcd(a,b);
                int lcm=a*b/gcd;
                if(x==gcd && lcm==y){
                    if(a==b){
                        count++;
                    }
                    else {
                        count=count+2;
                    }
                    //System.out.println(a+":"+b+":"+gcd);

                }

            }
        }
        System.out.println(count);
    }
    static int gcd(int a, int b){
        if(dp[a][b]!=null){
            return  dp[a][b];
        }
        if(b == 0) return a;
        dp[a][b]=gcd(b, a% b);
        return dp[a][b];
    }

}


import java.util.Scanner;

public class Main {

    public static int valueOf(char letter,int [] values)
    {
        return values[(int)letter-97];
    }
    public static int max(int[] values)
    {
        int max = values[0];
        for(int i = 1;i<values.length;i++)
        {
            if(values[i]>max)
                max = values[i];
        }

         return max;
    }

    public static void main(String [] args) {

        Scanner input = new Scanner(System.in);

        int r = input.nextInt();

        int x = input.nextInt();
        int y = input.nextInt();
        int x1 = input.nextInt();
        int y1 = input.nextInt();

        int dx = Math.abs(x-x1);
        int dy = Math.abs(y-y1);

        int c = 0;

        if(dx == 0 && dy == 0)
        {
            System.out.println(0);
            return;
        }

        {
            while(true)
            {
                if(dx == 0 && dy == 0)
                {
                    break;
                }
                else if (dx> 0 && dy > 0)
                {
                    dx -= r;
                    dy -= r;
                    c++;
                }
                else if(dx>0)
                {
                    dx -= 2*r;
                    c++;
                }
                 else if(dy>0)
                {
                     dy -= r*r;
                     c++;
                }
            }
        }

        System.out.println(c);

    }

}


import java.util.*;
public class Factorial{
	public static void main (String [] args){
		int a,b;
		Scanner sc = new Scanner (System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		System.out.println(factorial(Math.min(a, b);));

    }
	public static int factorial(int a){
		int fact=1;
		for(int k=1; k<=a;k++){
		fact*=k;
	}
	return fact;
	}
	public static long gcd(int p, int q){
		if (q==0){
			return p;
		}
		return gcd(q,p%q);
	}

}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Árysson Cavalcanti
 */
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 {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n=in.readInt(), sx=in.readInt()%n, sy=in.readInt()%n, dx=in.readInt()%n, dy=in.readInt()%n;
		long t=in.readLong(), Sx=(2L*sx+dx+sy)%n, Sy=(2L*sy+dy+sx)%n, Dx=(dx+sx+sy)%n, Dy=(dy+sy+sx)%n, t0=(t%2==0?t/2:t)%n, t1=(t%2==1?(t-1)/2:t-1)%n;
		Matrix.mod=n;
		Matrix base=new Matrix(new long[][] {
			{2, 1, 1, 1},
			{1, 2, 1, 1},
			{1, 0, 1, 0},
			{0, 1, 0, 1}
		}), matrix=new Matrix(new long[][]{
			{Sx, Sy, Dx, Dy},
			{sx, sy, dx, dy}
		});
		long[][] data=Matrix.multiply(matrix, base.power(t)).data;
		Sx=(data[1][0]+t0*t1%n)%n;
		Sy=(data[1][1]+t0*t1%n)%n;
		out.printLine(Sx==0?n:Sx, Sy==0?n:Sy);
    }
}

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 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 print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

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

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

}

class Matrix {
	public static long mod = Long.MAX_VALUE;
	public final long[][] data;
	public final int rowCount;
	public final int columnCount;

	public Matrix(int rowCount, int columnCount) {
		this.rowCount = rowCount;
		this.columnCount = columnCount;
		this.data = new long[rowCount][columnCount];
	}

	public Matrix(long[][] data) {
		this.rowCount = data.length;
		this.columnCount = data[0].length;
		this.data = data;
	}

	public static Matrix multiply(Matrix first, Matrix second) {
		Matrix result = new Matrix(first.rowCount, second.columnCount);
		for (int i = 0; i < first.rowCount; i++) {
			for (int j = 0; j < second.rowCount; j++) {
				for (int k = 0; k < second.columnCount; k++)
					result.data[i][k] = (result.data[i][k] + first.data[i][j] * second.data[j][k]) % mod;
			}
		}
		return result;
	}

	public static Matrix identityMatrix(int size) {
		Matrix result = new Matrix(size, size);
		for (int i = 0; i < size; i++)
			result.data[i][i] = 1;
		return result;
	}

	public Matrix power(long exponent) {
		if (exponent == 0)
			return identityMatrix(rowCount);
		if (exponent == 1)
			return this;
		Matrix result = power(exponent >> 1);
		result = multiply(result, result);
		if ((exponent & 1) == 1)
			result = multiply(result, this);
		return result;
	}

}


import java.util.Scanner;

public class E {
    static int mod;

    public static long[][] identity() {
        long[][] a = new long[6][6];
        for (int i = 0; i < 6; i++)
            a[i][i] = 1;
        return a;
    }

    public static long[][] modMul(long[][] A, long[][] B) {
        long[][] C = new long[6][6];
        for (int i = 0; i < 6; i++)
            for (int j = 0; j < 6; j++)
                for (int k = 0; k < 6; k++)
                    C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
        return C;
    }

    public static long[][] modPow(long[][] M, long p) {
        if (p == 0)
            return identity();
        long[][] temp = modPow(M, p >> 1);
        temp = modMul(temp, temp);
        if ((p & 1) != 0)
            temp = modMul(M, temp);
        return temp;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        mod = in.nextInt();
        long x = in.nextLong() - 1;
        long y = in.nextLong() - 1;
        long dx = in.nextLong();
        long dy = in.nextLong();
        long t = in.nextLong();
        long[][] a = { { 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 } };
        long[][] ans = modPow(a, t);
        long[] v = { x, y, dx, dy, 0, 1 };
        long ansX = 0;
        long ansY = 0;
        for (int i = 0; i < 6; i++) {
            ansX = (ansX + (ans[0][i] * v[i]) % mod) % mod;
            ansY = (ansY + (ans[1][i] * v[i]) % mod) % mod;
        }
        System.out.println((ansX + 1) + " " + (ansY + 1));
    }
}


import java.util.*;
public class Prog1064A{
     public static void main(String[] args){
          Scanner sc=new Scanner(System.in);
          byte[] tri=new byte[3];
          for (byte i=0;i<3;i++){
               tri[i]=sc.nextByte();
          }
          short cout=0;
          short sum=0;
          for(byte i=0;i<3;i++){
               sum=0;
               for(byte j=0;j<3;j++){
                    if (i==j){
                         continue;
                    }
                    sum=sum+tri[j];
               }
               if (sum<=tri[i]){
                    cout=cout+((tri[i]-sum)+1);
                    tri[i]=(tri[i]-sum)+1;
               }
          }
          System.out.println(cout);
     }
}


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

public class Problem {

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

		int n = keyBoard.nextInt();
		double a = keyBoard.nextDouble();
		int[] a_array = new int[n];
		String a_string = "";

		for(int i = 0; i<n ;i++)
		{
			a_array[i] = (int) (a%10);

			if(a_array[i] % 2 == 0  && a_array[i] != 0)
			{
				int temp = a_array[i];
				int count = 0;

				while(temp>1)
				{
					if(temp%2==0)
					{
						count++;
						temp/=2;
					}
					else
						count=0;
				}
				for(int j = 0; j<count ; j++)
				{
					a_string = a_string + "2";
				}
				a_array[i]--;
			}
			if(a_array[i] != 1 && a_array[i] != 0)
			a_string = a_string + a_array[i];

			a/=10;
		}

		char[] a_charArray = a_string.toCharArray();

		for(int i = 0; i<a_charArray.length ;i++)
		{
			a_charArray[i]*=-1;
		}

		java.util.Arrays.sort(a_charArray);

		for(int i = 0; i<a_charArray.length ;i++)
		{
			a_charArray[i]*=-1;
		}

		System.out.println(a_charArray);

	}

}


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

public class B5 {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner (System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		if (n == 0){
			out.print(1);
			out.flush();
			return ;
		}
		n--;
		int i, ans = 1;
		for (i = 0;i < n;i++){
			ans *= 3;
			ans %= (1000000 + 3);
		}
		out.print(ans);
	}
}


import java.io.*;

/**
 * Codeforces Beta Round #64 (Div. 1), A
 * @author Roman Kosenko <madkite@gmail.com>
 */
public class Cookies {
	private static final int P = (int)(1e6 + 3);
	public static void main(String[] args) throws IOException {
		if(!Boolean.parseBoolean(System.getProperty("ONLINE_JUDGE")))
			System.setIn(new FileInputStream(new File("input.txt")));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		System.out.println(pow(3, n - 1, P));
	}
	private static int pow(long a, long n, int p) {
		long r = 1;
		while(n != 0) {
			if((n & 1) != 0)
				r = r * a  % p;
			a = a * a % p;
			n >>= 1;
		}
		return (int)r;
	}
}


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

import static java.lang.Math.*;

public class A {

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

	final int mod = (int)1e6 + 3;

	long func(int n) {
		if(n <= 1) return 1;
		return 3 * func(n-1) % mod;
	}

	private void solve() throws Exception {
		int n = nextInt();
		out.printf("%d\n", func(n));
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

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

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

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

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


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

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            boolean[][] f;
            int n;

            boolean ok(int x, int y, int sz) {
                for(int j = 0; j < sz; ++j) {
                    int tx = x + j;
                    int ty = y + j;

                    if(tx >= n || ty >= n || f[ty][n-tx-1])
                        return false;
                }

                return true;
            }

            void cook(int x, int y, int sz) {
                if(ok(x, y, sz)) {
                    int c = 0;

                    for(int i = y; i < y+sz; ++i, ++c)
                        for(int j = x; j < x+sz-c; ++j)
                            f[i][n-j-1] = true;
                }
            }

            @Override
            public void run() {
                n = (int)Math.pow(2,nextInt());
                f = new boolean[n][n];

                int sz = n;
                while(sz != 1) {
                    for(int i = 0; i < n; ++i)
                        for(int j = 0; j < n; ++j)
                            cook(i, j, sz);

                    sz /=2;
                }

//              for(boolean[] b1:f) {
//                  for(boolean b:b1)
//                      print((b?1:0)+" ");
//                  print("\n");
//              }

                int c = 0;
                for(boolean[] b1:f)
                    for(boolean b:b1)
                        if(!b)
                            ++c;
                print(c);
                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

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

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

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

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

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

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

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void println(Object o) {
                out.write(o.toString() + '\n');
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


import java.util.Scanner;

public class A_The_New_Year_Meeting_Friends
    {
        public static void main(String[] args)
            {
                Scanner cin = new Scanner(System.in);
                int a, b, c ;
                a = cin.nextInt();
                b = cin.nextInt();
                c = cin.nextInt();
                int mid = (a+b+c)/3;
                /*if (a > b )
                    {
                       a = a+b;
                       b = a - b ;
                       a = a - b ;
                    }
                if (a > c )
                    {
                           a = a+c;
                           c = a - c ;
                           a = a - c ;
                    }
                if (b > c )
                    {
                            b = b+c;
                            c = b - c ;
                            b = b - c ;
                    }*/
                mid = Math.abs(a-mid) + Math.abs(b-mid) + Math.abs(c-mid) ;
                System.out.print(mid);
            }
    }


/**
 * Ashesh Vidyut (Drift King) *
 */
public class B {
    public static void main(String[] args) {
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String ak[] = (in.readLine()).split(" ");
            int num[] = new int[ak[0].length()];
            int k = Integer.parseInt(ak[1]);
            for (int i = 0; i < num.length; i++) {
                num[i] = Integer.parseInt(Character.toString(ak[0].charAt(i)));
            }
            for (int i = 0; i < num.length; i++) {
                if(num[i] == 9){
                    continue;
                }
                int maxv = num[i];
                int maxind = i;
                if(k <=0 ){
                    break;
                }
                if(i+1 < num.length){
                    for (int j = i+1; j < Math.min(num.length, i+k+1); j++) {
                        if(maxv < num[j]){
                            maxv = num[j];
                            maxind = j;
                        }
                    }
                    if(maxv == num[i]){
                        continue;
                    }
                    int noswap = maxind - i;
                    if(k >= noswap){
                        k -= noswap;
                        int tmp = num[i];
                        num[i] = maxv;
                        for (int j = i+1; j <= maxind; j++) {
                            int tmp2 = tmp;
                            tmp = num[j];
                            num[j] = tmp2;
                        }
                    }
                }
            }
            StringBuilder res = new StringBuilder("");
            for (int i = 0; i < num.length; i++) {
                res.append(num[i]);
            }
            System.out.println(res);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}


public class cyclic
{
     public static void main(String args[])
     {
         Scanner s= new Scanner(System.in);
         String x= s.nextLine();
         int n=x.length();
         String st[]= new String[n];
         char ch[]= new char[n];
         st[0]=x;
         int m=0, sum=0;
         for(int i=1; i<n; i++)
         {
              char c= st[i-1].charAt(n-1);
              for(int j=1; j<n; j++)
              ch[j]=st[i-1].charAt(j-1);
              ch[0]=c;
              st[i]=String.valueOf(ch);
              for(int k=0; k<i; k++)
              {
                  if(st[i].compareTo(st[k])==0)
                  m++;
              }
              if(m!=0)
              sum++;
              m=0;
         }
         System.out.println(n-sum);
     }
}


import java.util.HashSet;
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        HashSet<String> set = new HashSet<>();
        for (int i = 0; i < str.length(); i++) {
            set.add(str.substring(i) + str.substring(0,i));
        }
        System.out.println(set.size());
    }
}


import java.util.Scanner;
public class codeforce {

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

		Scanner in2 = new Scanner(System.in);
		int b = in2.nextInt();

		Scanner in3 = new Scanner(System.in);
		int c = in3.nextInt();

		int be = a*2;
		int ce = a*4;
		int o = b/be;
		int p = c/ce;
		if (o==0 || p==0) {
		for ( p=c/ce , o=b/be ; p==0 || o==0; )	{
	     	a=a-1;  if (a>0) {
	        be=a*2; ce=a*4; o=b/be; p=c/ce;     }
	     	if (a==0) {p=1; o=1; be=0; ce=0;}
		    }
		}
		System.out.println(a+be+ce);
	}
}
→Judgement Protocol


import java.io.*;

public class Compote {

   public static void main(String[] args){
       try{

           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
           int lemon = Integer.parseInt(br.readLine());
           int apple = (Integer.parseInt(br.readLine()))/2;
           int pears = (Integer.parseInt(br.readLine()))/4;

           System.out.println(Math.min(a, Math.min(b, c)*7));

       }catch(IOException ioe){
         ioe.printStackTrace();
       }
   }
}


import java.util.*;

public class Main {

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

        int n = scan.nextInt();
        boolean[] arr = new boolean[n];
        boolean[] ansArr = new boolean[n];

        for (int index = 0; index < n; index++)
            arr[index] = scan.nextInt() == 1 ? true : false;

        int max = 0;
        for (int index = 0; index < n; index++)
            if(arr[index]) max++; // 현재 1의 개수

        int i = 0, j = 0, tempMax = 0;

        while (j < n) {
            i = 0;
            while (i <= j) {
                ansArr = arr.clone(); // ansArr 초기화
                tempMax = 0;

                for (int k = i; k <= j; k++)
                    ansArr[k] = !ansArr[k]; // flip

                for(int index = 0; index < n; index++)
                    if(ansArr[index]) tempMax++;

                if(tempMax > max) max = tempMax;

                i++;
            }
            j++;
        }

        System.out.println(max);
    }
}


* 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 hexa
{
public static void main(String[] args) throws java.lang.Exception {
Scanner f = new Scanner(System.in);
			int a = f.nextInt();
		int b = f.nextInt();
		int c = f.nextInt();
		int n = (b + a - 1) * (c + a - 1) - a * (a - 1);

		System.out.println(n);
}
}


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

public class A {
    public static void solution(BufferedReader reader, PrintWriter out)
            throws IOException {
        In in = new In(reader);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
        int cnt = 0;
        int n = a - 1;
        for (int i = 0; i < Math.min(b, c); i++) {
            n++;
            cnt += n * 2;
        }
        cnt += n * Math.max(0, Math.abs(b - c) - 1);
        out.println(cnt);
    }

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(
                new OutputStreamWriter(System.out)));
        solution(reader, out);
        out.close();
    }

    protected static class In {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public In(BufferedReader reader) {
            this.reader = reader;
        }

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

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

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

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


public class Main {

    public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        a*=2;
        String [] inp = new String [4];
        int [] arr = new int [10];
        for(int i = 0 ; i < 4 ; i++){
            inp[i] = sc.next();
            for(int j = 0 ; j < 4 ; j++)
                if(inp[i].charAt(j) >=48 && inp[i].charAt(j) <= 57)
                    arr[(int)inp[i].charAt(j)-48]++ ;
        }
        boolean f ;
        f = true;
        for(int i = 0 ; i < 10 ; i++)
            if(arr[i] > a)
                f = false ;

        if(f)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.Scanner;

public class c {
 static int Am,Dm,Hm;
 static int h,a,d;
static int [][][]dp;
static int pr=0;
    public static void main(String[] args) {
Scanner sc =new Scanner (System.in);
      int Hy=sc.nextInt();
      int Ay=sc.nextInt();
      int Dy=sc.nextInt();
       Hm=sc.nextInt();
        Am=sc.nextInt();
        Dm=sc.nextInt();
        h=sc.nextInt();
        a=sc.nextInt();
        d=sc.nextInt();
        dp=new int [400][400][400];

        System.out.println(solve(Ay,Dy,Hy,0));
    }
private static int solve(int ay, int dy, int hy, int p) {
        if (won(ay,dy,hy)) {
        //  if (p<pr)pr=p;
            return p;
        }
    //  if (pr !=0 && p>pr)return p;
    //  if (ay==400 || dy==400 || hy==400)System.out.println("yes");
        try{
        if (dp[ay][dy][hy]!=0)return dp[ay][dy][hy];
        }catch(Exception e){
            return 100000000;
        }
        int c1= solve (ay+1,dy,hy,p+a);
        int c2= solve (ay,dy+1,hy,p+d);
        int c3= solve (ay,dy,hy+1,p+h);
        return dp[ay][dy][hy]=Math.min(c1,Math.min(c2,c3));

    }
public static boolean won(int Ay,int Dy,int Hy ){
    if (Ay<=Dm)return false;
    if (Am<=Dy){
    //  System.out.println("h");
        return true;
    }
    //return (Hm*1.0)/(Ay-Dm)<(Hy*1.0)/(Am-Dy) && (Hy*1.0)/(Am-Dy)>0;
    int h=Hm;
    while (true){
        if (Hy>0 && h<=0)return true;
        if (Hy<=0)return false;
        h-=Math.max(0,Ay-Dm);
        Hy-=Math.max(0,Am-Dy);
    }
}

}