The first line contains a single integer $$$n$$$ ($$$4 \leq n \leq 50$$$) — the length of the string $$$s$$$. The second line contains the string $$$s$$$, consisting of exactly $$$n$$$ uppercase letters of the Latin alphabet.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Lalo
 */
public class ContestSandbox {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int length = Integer.parseInt(in.nextLine());
        String s = in.nextLine();
        String genome = "ACTG";
        int miniumChanges = 3215643;
        Map<String, Integer> alphabet = new HashMap<>();

        int a = 1;
        for (char ch = 'A'; ch <= 'Z'; ch++) {
            alphabet.put(String.valueOf(ch), a);
            a++;
        }

        for (int i = 0; (i + 4) <= length; i++) {
            int sum = 0;
            for (int x = 0; x < 4; x++) {
                if (Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1))) <= 13) {
                    sum += Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1)));
                } else if (alphabet.get(s.substring(i + x, i + x + 1)) > alphabet.get(genome.substring(x, x + 1))) {
                    sum += (26 - alphabet.get(s.substring(i + x, i + x + 1)) + alphabet.get(genome.substring(x, x + 1)));
                } else {
                    sum += (26 - alphabet.get(genome.substring(x, x + 1)) + alphabet.get(s.substring(i + x, i + x + 1)));
                }
            }

            if (sum < miniumChanges) {
                miniumChanges = sum;
            }
        }

        System.out.println(miniumChanges);
    }

}

NoteIn the first example, you should replace the letter "Z" with "A" for one operation, the letter "H" — with the letter "G" for one operation. You will get the string "ACTG", in which the genome is present as a substring.In the second example, we replace the letter "A" with "C" for two operations, the letter "D" — with the letter "A" for three operations. You will get the string "ZACTG", in which there is a genome.

Output the minimum number of operations that need to be applied to the string $$$s$$$ so that the genome appears as a substring in it.

Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string $$$s$$$ consisting of uppercase letters and length of at least $$$4$$$, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string $$$s$$$ with the next or previous in the alphabet. For example, for the letter "D" the previous one will be "C", and the next — "E". In this problem, we assume that for the letter "A", the previous one will be the letter "Z", and the next one will be "B", and for the letter "Z", the previous one is the letter "Y", and the next one is the letter "A".Help Maxim solve the problem that the teacher gave him.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Input:
4
ZCTH

Output: 2

Input:
5
ZDATG

Output: 5

Input:
6
AFBAKC

Output: 16

Input:
9
AAABBBCCC

Output: 14

Input:
8
ABCDABCD

Output: 13

Input:
4
NPGT

Output: 52

Input:
10
ABABABABAB

Output: 13

Input:
8
BBAACCZZ

Output: 14

Input:
50
ALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX

Output: 13

Input:
30
THCVHIPLYOOFCNWQJMBMEDTXLTCKMF

Output: 10

Input:
39
IHESTJHHSZRSHNUSPGMHDTKOJFEFLAUDXUEQWLO

Output: 11

Input:
33
IQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR

Output: 12

Input:
32
IWMQCTKRNXICANQUPLBOMDNRBOWWIXZB

Output: 14

Input:
6
NQNEVX

Output: 26

Input:
17
GNPBRASKVPECJKECD

Output: 16

Input:
18
KNGWZFHGQIADTBYWDC

Output: 6

Input:
14
ZXPFXCBVESQGAE

Output: 7

Input:
37
INUZOUSGLBHKDEFTQANRPIYMIBFLRTYFNWIFQ

Output: 17

Input:
50
VKRGXLUWYURTRNGAODFLYCKAPHGPHGDLWIGXEYVOAVYYXVDRAB

Output: 12

Input:
50
GOHDHOWWPMZBSEKHDBDKLIYRFEPOUHIHOHPUMVDAQRZDJMUBWV

Output: 5

Input:
50
QFWWIROYKRLAYBPSEXATCWILUBAZPWSGSKLTBLZOLZPHJKQQGF

Output: 9

Input:
50
ROWGGKNUITVHOBMKZXOZNBZMQGSFERNCZDFKLRBCFVVDXJEFLP

Output: 13

Input:
50
YUPJIRNPTCFJIPODTHJXTWJUTLKCUYFNZKMJRBZZYBPEDYLKCY

Output: 9

Input:
50
ZOMSHKIFVAMFATEIIEUJVITTYZGDWCGSOJMFQNYACRPOLGUZCM

Output: 9

Input:
50
LQFSFNEFCPBEARPMOGSSQVHAGNKOQXXCZKHSAEPTEHWOWSZMKH

Output: 13

Input:
50
HKKUWHLYYKBLLEHKVNIRYAPVFTAPRIFUZELKGRDXZNCNWHSAFG

Output: 14

Input:
50
MGDXLMPDPKUQOIMTLDUDTGTOMJCSYNRTSQSJANYDDPWQYTDTAW

Output: 7

Input:
8
ACTGACTG

Output: 0

Input:
10
ZZZZZZZZZZ

Output: 17

Input:
8
NPGTNPGT

Output: 22

Input:
5
ACTGA

Output: 0

Input:
4
AZTG

Output: 3

Input:
4
YCTG

Output: 2

Input:
4
ANTG

Output: 11

Input:
4
OCTG

Output: 12

Input:
4
ACHG

Output: 12

[{'input': '4\r\nNPGT\r\n', 'output': ['52']}, {'input': '50\r\nMGDXLMPDPKUQOIMTLDUDTGTOMJCSYNRTSQSJANYDDPWQYTDTAW\r\n', 'output': ['7']}, {'input': '33\r\nIQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR\r\n', 'output': ['12']}, {'input': '50\r\nQFWWIROYKRLAYBPSEXATCWILUBAZPWSGSKLTBLZOLZPHJKQQGF\r\n', 'output': ['9']}, {'input': '5\r\nZDATG\r\n', 'output': ['5']}]

[{'input': '50\r\nQFWWIROYKRLAYBPSEXATCWILUBAZPWSGSKLTBLZOLZPHJKQQGF\r\n', 'output': ['9']}, {'input': '8\r\nBBAACCZZ\r\n', 'output': ['14']}, {'input': '50\r\nZOMSHKIFVAMFATEIIEUJVITTYZGDWCGSOJMFQNYACRPOLGUZCM\r\n', 'output': ['9']}, {'input': '39\r\nIHESTJHHSZRSHNUSPGMHDTKOJFEFLAUDXUEQWLO\r\n', 'output': ['11']}, {'input': '9\r\nAAABBBCCC\r\n', 'output': ['14']}]

[{'input': '8\r\nABCDABCD\r\n', 'output': ['13']}, {'input': '50\r\nGOHDHOWWPMZBSEKHDBDKLIYRFEPOUHIHOHPUMVDAQRZDJMUBWV\r\n', 'output': ['5']}, {'input': '32\r\nIWMQCTKRNXICANQUPLBOMDNRBOWWIXZB\r\n', 'output': ['14']}, {'input': '17\r\nGNPBRASKVPECJKECD\r\n', 'output': ['16']}, {'input': '10\r\nZZZZZZZZZZ\r\n', 'output': ['17']}]

[{'input': '4\r\nAZTG\r\n', 'output': ['3']}, {'input': '17\r\nGNPBRASKVPECJKECD\r\n', 'output': ['16']}, {'input': '50\r\nALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX\r\n', 'output': ['13']}, {'input': '4\r\nACHG\r\n', 'output': ['12']}, {'input': '50\r\nZOMSHKIFVAMFATEIIEUJVITTYZGDWCGSOJMFQNYACRPOLGUZCM\r\n', 'output': ['9']}]

[{'input': '33\r\nIQHJDOVAGCIAEBAIXQYQCDVZGVOYIIYPR\r\n', 'output': ['12']}, {'input': '50\r\nALWLSFLXYPQYMIWXMYMXFYMIVFYJDTJAIGVOAUDAIIAHKNNVTX\r\n', 'output': ['13']}, {'input': '4\r\nNPGT\r\n', 'output': ['52']}, {'input': '6\r\nAFBAKC\r\n', 'output': ['16']}, {'input': '4\r\nACHG\r\n', 'output': ['12']}]


The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.

// Why do we fall ? So we can learn to pick ourselves up.
import java.util.*;
public class solve {
    static int mod = 1000000007;
    static int mod1 = 998244353;
    public static void  main(String[] args){
        Scanner sc = new Scanner(System.in);
        int lll = sc.nextInt(),rrr = sc.nextInt(),a = sc.nextInt();
        int l = Math.min(lll,rrr),r = Math.max(lll,rrr);
        if(lll==rrr) System.out.println(2*(l+a/2));
        else {
            int ll = Math.min(r-l,a);
            l += ll;
            int aa = a-ll;
            System.out.println(2*(l+aa/2));
        }
    }
}

NoteIn the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.

Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.

You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.

Input: 1 4 2

Output: 6

Input: 5 5 5

Output: 14

Input: 0 2 0

Output: 0

Input: 30 70 34

Output: 128

Input: 89 32 24

Output: 112

Input: 89 44 77

Output: 210

Input: 0 0 0

Output: 0

Input: 100 100 100

Output: 300

Input: 1 1 1

Output: 2

Input: 30 70 35

Output: 130

Input: 89 44 76

Output: 208

Input: 0 100 100

Output: 200

Input: 100 0 100

Output: 200

Input: 100 1 100

Output: 200

Input: 1 100 100

Output: 200

Input: 100 100 0

Output: 200

Input: 100 100 1

Output: 200

Input: 1 2 1

Output: 4

Input: 0 0 100

Output: 100

Input: 0 100 0

Output: 0

Input: 100 0 0

Output: 0

Input: 10 8 7

Output: 24

Input: 45 47 16

Output: 108

Input: 59 43 100

Output: 202

Input: 34 1 30

Output: 62

Input: 14 81 1

Output: 30

Input: 53 96 94

Output: 242

Input: 62 81 75

Output: 218

Input: 21 71 97

Output: 188

Input: 49 82 73

Output: 204

Input: 88 19 29

Output: 96

Input: 89 4 62

Output: 132

Input: 58 3 65

Output: 126

Input: 27 86 11

Output: 76

Input: 35 19 80

Output: 134

Input: 4 86 74

Output: 156

Input: 32 61 89

Output: 182

Input: 68 60 98

Output: 226

Input: 37 89 34

Output: 142

Input: 92 9 28

Output: 74

Input: 79 58 98

Output: 234

Input: 35 44 88

Output: 166

Input: 16 24 19

Output: 58

Input: 74 71 75

Output: 220

Input: 83 86 99

Output: 268

Input: 97 73 15

Output: 176

Input: 77 76 73

Output: 226

Input: 48 85 55

Output: 188

Input: 1 2 2

Output: 4

Input: 2 2 2

Output: 6

Input: 2 1 2

Output: 4

Input: 2 2 1

Output: 4

Input: 3 2 1

Output: 6

Input: 1 2 3

Output: 6

Input: 1 3 2

Output: 6

Input: 2 1 3

Output: 6

Input: 2 3 1

Output: 6

Input: 3 1 2

Output: 6

Input: 99 99 99

Output: 296

Input: 99 99 100

Output: 298

Input: 99 100 99

Output: 298

Input: 99 100 100

Output: 298

Input: 100 99 99

Output: 298

Input: 100 99 100

Output: 298

Input: 100 100 99

Output: 298

Input: 89 32 23

Output: 110

Input: 4 5 0

Output: 8

Input: 3 0 3

Output: 6

Input: 0 0 2

Output: 2

Input: 97 97 0

Output: 194

Input: 1 4 0

Output: 2

Input: 5 2 0

Output: 4

Input: 0 5 10

Output: 14

Input: 0 1 2

Output: 2

Input: 5 2 3

Output: 10

Input: 5 5 0

Output: 10

Input: 0 0 10

Output: 10

Input: 0 1 1

Output: 2

Input: 0 0 1

Output: 0


The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \ldots, x_n$$$ ($$$0 \le x_i \le 9$$$) representing the sequence. The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \ldots, y_m$$$ ($$$0 \le y_i \le 9$$$) — the keys with fingerprints.

import java.util.*;
public class A
{
    public static void main(String[] args)
    {
        int n,m;
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        m = s.nextInt();
        int a[] = new int[n];
        int b[] = new int[m];
        for(int i = 0 ; i < n ; i++)
        {
            a[i] = s.nextInt();
        }
        for(int j = 0 ; j < m ; j++)
        {
            b[j] = s.nextInt();
        }
        for(int i1 = 0 ; i1 < n ; i1++)
        {
            for(int j1 = 0 ; j1 < m ; j1++)
            {
                if(a[i1] == b[j1])
                {
                    System.out.print(a[i1] + " ");
                }
            }
        }
    }
}

NoteIn the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important.

In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.

You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.

Input:
7 3
3 5 7 1 6 2 8
1 2 7

Output: 7 1 2

Input:
4 4
3 4 1 0
0 1 7 9

Output: 1 0

Input:
9 4
9 8 7 6 5 4 3 2 1
2 4 6 8

Output: 8 6 4 2

Input:
10 5
3 7 1 2 4 6 9 0 5 8
4 3 0 7 9

Output: 3 7 4 9 0

Input:
5 5
1 2 3 4 5
6 7 8 9 0

Input:
10 10
1 2 3 4 5 6 7 8 9 0
4 5 6 7 1 2 3 0 9 8

Output: 1 2 3 4 5 6 7 8 9 0

Input:
1 1
4
4

Output: 4

Input:
3 7
6 3 4
4 9 0 1 7 8 6

Output: 6 4

Input:
10 1
9 0 8 1 7 4 6 5 2 3
0

Output: 0

Input:
6 1
4 2 7 3 1 8
9

Input:
5 10
6 0 3 8 1
3 1 0 5 4 7 2 8 9 6

Output: 6 0 3 8 1

Input:
8 2
7 2 9 6 1 0 3 4
6 3

Output: 6 3

Input:
5 4
7 0 1 4 9
0 9 5 3

Output: 0 9

Input:
10 1
9 6 2 0 1 8 3 4 7 5
6

Output: 6

Input:
10 2
7 1 0 2 4 6 5 9 3 8
3 2

Output: 2 3

Input:
5 9
3 7 9 2 4
3 8 4 5 9 6 1 0 2

Output: 3 9 2 4

Input:
10 6
7 1 2 3 8 0 6 4 5 9
1 5 8 2 3 6

Output: 1 2 3 8 6 5

Input:
8 2
7 4 8 9 2 5 6 1
6 4

Output: 4 6

Input:
10 2
1 0 3 5 8 9 4 7 6 2
0 3

Output: 0 3

Input:
7 6
9 2 8 6 1 3 7
4 2 0 3 1 8

Output: 2 8 1 3

Input:
1 6
3
6 8 2 4 5 3

Output: 3

Input:
1 8
0
9 2 4 8 1 5 0 7

Output: 0

Input:
6 9
7 3 9 4 1 0
9 1 5 8 0 6 2 7 4

Output: 7 9 4 1 0

Input:
10 2
4 9 6 8 3 0 1 5 7 2
0 1

Output: 0 1

Input:
10 5
5 2 8 0 9 7 6 1 4 3
9 6 4 1 2

Output: 2 9 6 1 4

Input:
6 3
8 3 9 2 7 6
5 4 3

Output: 3

Input:
4 10
8 3 9 6
4 9 6 2 7 0 8 1 3 5

Output: 8 3 9 6

Input:
1 2
1
1 0

Output: 1

Input:
3 6
1 2 3
4 5 6 1 2 3

Output: 1 2 3

Input:
1 2
2
1 2

Output: 2

Input:
1 10
9
0 1 2 3 4 5 6 7 8 9

Output: 9


A single line contains a single integer n (1 ≤ n ≤ 4000).

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

    static class TaskB {
        long[] equivalence_relations;
        int[][] bc;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int MOD = 1000000007;

            long ans = 0;
            compute_equivalence_relations(N, MOD);
            compute_binomial_coefficients(N, MOD);
            for (int m = 0; m < N; m++) {
                ans = (ans + equivalence_relations[m] * bc[N][N - m]) % MOD;
            }

            out.println(ans);
        }

        private void compute_binomial_coefficients(int N, int MOD) {
            bc = new int[N + 1][N + 1];
            for (int n = 1; n <= N; n++) {
                for (int k = 0; k <= n; k++) {
                    if (k == 0) bc[n][k] = 1;
                    else if (n == k) bc[n][k] = 1;
                    else bc[n][k] = (bc[n - 1][k - 1] + bc[n - 1][k]) % MOD;
                }
            }
        }

        private void compute_equivalence_relations(int N, int MOD) {
            long dp[][] = new long[N + 1][N + 1];

            dp[0][0] = 1;

            for (int elems = 1; elems <= N; elems++) {
                for (int classes = 1; classes <= elems; classes++) {
                    dp[elems][classes] = (long) (classes) * dp[elems - 1][classes] + dp[elems - 1][classes - 1];
                    dp[elems][classes] = dp[elems][classes] % MOD;
                }
            }

            equivalence_relations = new long[N + 1];

            for (int i = 0; i <= N; i++) {
                long tmp = 0;
                for (int j = 0; j <= i; j++) {
                    tmp = (tmp + dp[i][j]) % MOD;
                }
                equivalence_relations[i] = tmp;
            }
        }

    }

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

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

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

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

    }
}

NoteIf n = 1 there is only one such relation — an empty one, i.e. . In other words, for a single element x of set A the following is hold: .If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are , ρ = {(x, x)}, ρ = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.

In a single line print the answer to the problem modulo 109 + 7.

Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.A set ρ of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation ρ, if pair , in this case we use a notation .Binary relation is equivalence relation, if: It is reflexive (for any a it is true that ); It is symmetric (for any a, b it is true that if , then ); It is transitive (if  and , than ).Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":Take any two elements, a and b. If , then  (according to property (2)), which means  (according to property (3)).It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.


The first line contains single integer $$$n$$$ ($$$3 \le n \le 500$$$) — the number of vertices in the regular polygon.

import java.util.*;
import java.io.*;
public class Solution
{
    public static void main(String []ks) throws Exception
    {
       BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(bf.readLine());
        long a=2,b=3;
        long res=0;
        for(int i=3;i<=n;i++)
        {
            res+=(a*b);
            a++;
            b++;
        }
        System.out.println(res);
  }
}

NoteAccording to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $$$P$$$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $$$P$$$.In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $$$1 \cdot 2 \cdot 3 = 6$$$.In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $$$1-3$$$ so answer is $$$1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$$$.

Print one integer — the minimum weight among all triangulations of the given polygon.

You are given a regular polygon with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.Calculate the minimum weight among all triangulations of the polygon.


The first line contains two positive integers a and b (1 ≤ a < b ≤ 109) — the number which Vasily has and the number he wants to have.

import java.util.*;
public class transformation {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt(),k=num2;
        ArrayList<Integer> arr = new ArrayList<>();
        while(num2>num1){
            if(num2%2==0){
                num2=num2/2;
                arr.add(num2);
            }
            else if(num2%10==1){
                num2=num2/10;
                arr.add(num2);
            }
            else
                break;
        }
        if(num1==num2){
            System.out.println("YES");
            System.out.println(arr.size()+1);
            for(int i=arr.size()-1;i>=0;i--){
                System.out.print(arr.get(i)+" ");
            }
            System.out.print(k);
        }
        else
            System.out.println("NO");
    }
}

If there is no way to get b from a, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, ..., xk, where:   x1 should be equal to a,  xk should be equal to b,  xi should be obtained from xi - 1 using any of two described operations (1 < i ≤ k).  If there are multiple answers, print any of them.

Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations:  multiply the current number by 2 (that is, replace the number x by 2·x);  append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.

Input: 2 162

Output:
YES
5
2 4 8 81 162

Input: 4 42

Output: NO

Input: 100 40021

Output:
YES
5
100 200 2001 4002 40021

Input: 1 111111111

Output:
YES
9
1 11 111 1111 11111 111111 1111111 11111111 111111111

Input: 1 1000000000

Output: NO

Input: 999999999 1000000000

Output: NO

Input: 1 2

Output:
YES
2
1 2

Input: 1 536870912

Output:
YES
30
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912

Input: 11111 11111111

Output:
YES
4
11111 111111 1111111 11111111

Input: 59139 946224

Output:
YES
5
59139 118278 236556 473112 946224

Input: 9859 19718

Output:
YES
2
9859 19718

Input: 25987 51974222

Output:
YES
5
25987 259871 2598711 25987111 51974222

Input: 9411 188222222

Output:
YES
6
9411 94111 941111 9411111 94111111 188222222

Input: 25539 510782222

Output:
YES
6
25539 255391 2553911 25539111 255391111 510782222

Input: 76259 610072

Output:
YES
4
76259 152518 305036 610072

Input: 92387 184774

Output:
YES
2
92387 184774

Input: 8515 85151111

Output:
YES
5
8515 85151 851511 8515111 85151111

Input: 91939 9193911

Output:
YES
3
91939 919391 9193911

Input: 30518 610361

Output:
YES
3
30518 61036 610361

Input: 46646 373168844

Output:
YES
7
46646 466461 932922 9329221 93292211 186584422 373168844

Input: 30070 300701

Output:
YES
2
30070 300701

Input: 13494 1079528

Output:
YES
5
13494 134941 269882 539764 1079528

Input: 96918 775344422

Output:
YES
7
96918 193836 1938361 3876722 38767221 387672211 775344422

Input: 13046 260921

Output:
YES
3
13046 26092 260921

Input: 29174 5834811

Output:
YES
4
29174 58348 583481 5834811

Input: 79894 319576421

Output:
YES
6
79894 798941 1597882 15978821 31957642 319576421

Input: 96022 1920442

Output:
YES
3
96022 960221 1920442

Input: 79446 6355681

Output:
YES
5
79446 158892 317784 635568 6355681

Input: 5440 27853056

Output:
YES
11
5440 10880 108801 217602 435204 870408 1740816 3481632 6963264 13926528 27853056

Input: 250000000 705032705

Output: NO

Input: 17 35

Output: NO

Input: 1 3

Output: NO

Input: 2 11

Output: NO


The first line contains one integer $$$a$$$ $$$(1 \le a \le 100\,000)$$$ — the number of ties. The second line contains one integer $$$b$$$ $$$(1 \le b \le 100\,000)$$$ — the number of scarves. The third line contains one integer $$$c$$$ $$$(1 \le c \le 100\,000)$$$ — the number of vests. The fourth line contains one integer $$$d$$$ $$$(1 \le d \le 100\,000)$$$ — the number of jackets. The fifth line contains one integer $$$e$$$ $$$(1 \le e \le 1\,000)$$$ — the cost of one suit of the first type. The sixth line contains one integer $$$f$$$ $$$(1 \le f \le 1\,000)$$$ — the cost of one suit of the second type.

/*package whatever //do not write package name here */

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

public class GFG {
	public static void main (String[] args) {
	    Scanner s = new Scanner(System.in);
	    int a = s.nextInt();
	    int b = s.nextInt();
	    int c = s.nextInt();
	    int d = s.nextInt();
	    int e = s.nextInt();
	    int f = s.nextInt();
	    int cost=0;
	    if(e<f) {

	        int min = (int)Math.min(b,c);
	        min = (int)Math.min(min,d);
	        cost=min*f;
	        d=d-min;
	        if(d>0) {
	            cost=cost+(int)Math.min(a,d)*e;
	        }

	        System.out.println(cost);
	    }
	    else {
	          int min = (int)Math.min(a,d);

	        cost=min*e;

	        d=d-min;
	        if(d>0) {
	            min = (int)Math.min(b,c);

	        cost=cost+(int)Math.min(min,d)*f;
	        }

	         System.out.println(cost);
	    }

	}
}

NoteIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \cdot 4 + 11 \cdot 6 = 102$$$.

Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.

A new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.The store does not sell single clothing items — instead, it sells suits of two types:  a suit of the first type consists of one tie and one jacket;  a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).

Input:
4
5
6
3
1
2

Output: 6

Input:
12
11
13
20
4
6

Output: 102

Input:
17
14
5
21
15
17

Output: 325

Input:
43475
48103
50473
97918
991
974

Output: 89936047

Input:
35361
35182
68078
30077
870
907

Output: 27279839

Input:
84205
15736
30259
79331
647
378

Output: 51327157

Input:
220
623
94
463
28
656

Output: 67824

Input:
100000
100000
100000
100000
1000
1

Output: 100000000

Input:
22606
4759
37264
19105
787
237

Output: 15035635

Input:
630
312
279
823
316
915

Output: 427189

Input:
86516
30436
14408
80824
605
220

Output: 48898520

Input:
1
1
1
2
100
200

Output: 300

Input:
406
847
512
65
86
990

Output: 64350

Input:
250
400
766
246
863
166

Output: 212298

Input:
724
20
391
850
639
149

Output: 465616

Input:
30233
27784
36393
81065
782
953

Output: 50120358

Input:
61455
43924
94322
83903
855
232

Output: 57751961

Input:
68576
46084
31772
10708
632
408

Output: 6767456

Input:
19969
99297
44283
67490
71
20

Output: 2303459

Input:
68814
96071
14437
59848
848
195

Output: 50751104

Input:
58253
17658
9101
94990
625
178

Output: 38028103

Input:
179
762
909
155
768
278

Output: 119040

Input:
240
655
943
1000
545
262

Output: 302410

Input:
844
909
790
209
809
949

Output: 198341

Input:
15122
4341
98868
60319
760
49

Output: 11705429

Input:
23929
40873
44600
53185
833
328

Output: 29528825

Input:
6781
2030
73183
45619
802
208

Output: 5860602

Input:
260
538
587
231
49
308

Output: 71148

Input:
91
75
768
322
530
291

Output: 70055

Input:
438
541
215
575
795
274

Output: 385748

Input:
756
608
949
947
746
375

Output: 635601

Input:
129
203
206
749
11
358

Output: 74093

Input:
6870
43115
61342
70498
34
145

Output: 6485255

Input:
72593
77891
86639
87424
3
617

Output: 48087346

Input:
58967
2953
35483
681
780
304

Output: 531180

Input:
88
476
735
980
731
404

Output: 256632

Input:
988
657
824
346
996
387

Output: 344616

Input:
92
346
431
669
773
563

Output: 265914

Input:
685
236
234
965
101
832

Output: 263873

Input:
234
519
610
886
877
815

Output: 628203

Input:
184
301
373
420
93
602

Output: 192269

Input:
627
737
778
968
870
74

Output: 570724

Input:
81001
64465
98287
68848
309
982

Output: 64658977

Input:
60469
13310
49402
62958
790
861

Output: 50681830

Input:
88020
62154
14139
86851
863
844

Output: 74952413

Input:
66
393
648
651
6
648

Output: 255060

Input:
647
495
516
125
79
928

Output: 116000

Input:
708
774
307
44
47
103

Output: 4532

Input:
27989
77786
5733
14112
294
715

Output: 6562521

Input:
76294
65438
30385
94336
71
891

Output: 31613556

Input:
5771
19397
45992
46525
336
170

Output: 5236546

Input:
25432
28656
46763
79950
64
957

Output: 29051440

Input:
132
402
711
790
33
837

Output: 340830

Input:
100000
100000
100000
100000
1
1000

Output: 100000000

Input:
100000
100000
100000
100000
1000
1000

Output: 100000000

Input:
1
2
3
4
1
1

Output: 3

Input:
6
1
2
5
1
1

Output: 5

Input:
1
2
2
2
2
1

Output: 3

Input:
1
4
5
6
8
8

Output: 40

Input:
10
1
1
10
2
2

Output: 20

Input:
1
1
1
2
1
1

Output: 2


The only line of the input contains one integer $$$|s|$$$ ($$$1 \le |s| \le 100$$$) — the length of $$$s$$$. The second line of the input contains one string $$$s$$$ consisting of $$$|s|$$$ lowercase Latin letters.

import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		String str = in.next();
		System.out.println(getAns(str, N));
		in.close();
	}

	public static int getAns(String str, int N) {
		int ans = 0;
		StringBuilder sb = new StringBuilder(str);
		for (int i = 25; i >= 0; i--) {
			char ch = (char) (97 + i);
			for (int j = 0; j < sb.length(); j++) {
				if (sb.length() == 1) {
					break;
				}
				char ch1 = sb.charAt(j);
				if (ch != ch1) {
					continue;
				}
//				System.out.println(j);
				if (j == 0 && ((int) ch - 1 == (int) sb.charAt(j + 1))) {
					//System.out.println("leftMost " + j);
					sb.deleteCharAt(j);
					ans++;
					j -= 1;
					continue;
				} else if (j == sb.length() - 1 && ((int) ch - 1 == (int) sb.charAt(j - 1))) {
					//System.out.println("rightMost " + j);
					sb.deleteCharAt(j);
					ans++;
					j -= 1;
					continue;
				} else if ((j < sb.length() - 1 && (int) ch - 1 == (int) sb.charAt(j + 1))
						|| (j > 0 && (int) ch - 1 == (int) sb.charAt(j - 1))) {
					//System.out.println("middle " + j);
					sb.deleteCharAt(j);
					ans++;
					j -= 2;
					//System.out.println("middle " + j + " " + sb.toString() + " " + sb.length());
					continue;
				}
				//System.out.println(sb.toString());
			}
		}
		return ans;
	}

}

NoteThe first example is described in the problem statement. Note that the sequence of moves provided in the statement is not the only, but it can be shown that the maximum possible answer to this test is $$$4$$$.In the second example, you can remove all but one character of $$$s$$$. The only possible answer follows.  During the first move, remove the third character $$$s_3=$$$ d, $$$s$$$ becomes bca.  During the second move, remove the second character $$$s_2=$$$ c, $$$s$$$ becomes ba.  And during the third move, remove the first character $$$s_1=$$$ b, $$$s$$$ becomes a.

Print one integer — the maximum possible number of characters you can remove if you choose the sequence of moves optimally.

You are given a string $$$s$$$ consisting of lowercase Latin letters. Let the length of $$$s$$$ be $$$|s|$$$. You may perform several operations on this string.In one operation, you can choose some index $$$i$$$ and remove the $$$i$$$-th character of $$$s$$$ ($$$s_i$$$) if at least one of its adjacent characters is the previous letter in the Latin alphabet for $$$s_i$$$. For example, the previous letter for b is a, the previous letter for s is r, the letter a has no previous letters. Note that after each removal the length of the string decreases by one. So, the index $$$i$$$ should satisfy the condition $$$1 \le i \le |s|$$$ during each operation.For the character $$$s_i$$$ adjacent characters are $$$s_{i-1}$$$ and $$$s_{i+1}$$$. The first and the last characters of $$$s$$$ both have only one adjacent character (unless $$$|s| = 1$$$).Consider the following example. Let $$$s=$$$ bacabcab.  During the first move, you can remove the first character $$$s_1=$$$ b because $$$s_2=$$$ a. Then the string becomes $$$s=$$$ acabcab.  During the second move, you can remove the fifth character $$$s_5=$$$ c because $$$s_4=$$$ b. Then the string becomes $$$s=$$$ acabab.  During the third move, you can remove the sixth character $$$s_6=$$$'b' because $$$s_5=$$$ a. Then the string becomes $$$s=$$$ acaba.  During the fourth move, the only character you can remove is $$$s_4=$$$ b, because $$$s_3=$$$ a (or $$$s_5=$$$ a). The string becomes $$$s=$$$ acaa and you cannot do anything with it. Your task is to find the maximum possible number of characters you can remove if you choose the sequence of operations optimally.

Input:
8
bacabcab

Output: 4

Input:
4
bcda

Output: 3

Input:
6
abbbbb

Output: 5

Input:
1
a

Output: 0

Input:
1
t

Output: 0

Input:
100
ciftajmzqbfkvbhnyugneialytrkwjlhzwltylptheadmypbjxdzkxnqovimgmzkwpuelzbbhciinfiyspfatgoexeezolulnliu

Output: 0

Input:
100
yzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

Output: 99

Input:
100
aaaaaabbcccccccddffffhhhhhhhhiiiiiikkkkkkkkmmmmmmooooooopppprrrrrrrrrttttttvvvvvvvvvvvvxxxxxxxzzzzzz

Output: 21

Input:
100
babaababbaabbabababbabbbababababbaabababaaababaababbbaaababbaabbababababbababbabaabbaabaaaaabbababba

Output: 50

Input:
100
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

Output: 99

Input:
100
acdfijmnorszzyyzzzzzzyzzyzzzzxwzzzzzyzzzzzzyzzzzzzzyzzzzzyzzzzzzyxzzzyzzzzzyzzzzzyzzyzzzzvutqplkhgeb

Output: 99

Input:
100
abcdeghfgefedeefcabaaabcedfefedacbbcaaabehhjlkjikjloqrtuyzxwvspnmnlkjgfdcbacdcghfedfebaacbcbcdbccaaa

Output: 85

Input:
100
ababaaaabaabaaaaaaabaaaaaaaaaaaaacbaaaabaaaaaabaabaaaababaaaabaehijkmnpqvxzywutsrolgfdcbaaaabaabaaaa

Output: 40

Input:
100
aaaaaaabaaaaaabcaaaaaaaaaaaaaaaaaaaabbbaaaaaaabefhklmnopsuxzywvtrqjigdcaaaaaaaaaaaaaaaaaaaaaaaabaaaa

Output: 32

Input:
100
aaaaabcjkprsvxyzwutqonmlihgfedaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Output: 26

Input:
100
yltrygcqmgjzsxoahbvovspancmoaltdrxgjnxwxbrehubvradguoqgiodzanljxtszdutuzgcnihmwevoloceyidyvoopnqbtlb

Output: 9

Input:
100
aaaabbbcccccccdddddeeeeeffgggghhhiijjjjkkkllmmnnnoooppqqqrrrrssssssttttuuuuuuuuvvvvvwwwwxxxxyyyyzzzz

Output: 96

Input:
100
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Output: 0

Input:
100
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn

Output: 0

Input:
100
jupemetthxolktvhbmzdwlrekwmcugngajdgifwseksjlibsdgmegmqtmeeeqszqjxjhjenjxofvkesfjugbzephryjqqkxatrvl

Output: 1

Input:
100
mxjrojjwtrauhhccftvjsyfyfsnbdnwjfltyjetsylbddrkoqjxbmientcowknrecfqcvxfgsbymwyvakmbulhvrxzvzbygajtgc

Output: 2

Input:
100
bldubjepvkwhjbxrueydtpparjszjgwpxjlqlpsmdrjoaagfnrohfcabchmdwaoctmilfbpztwjrfdgdioqggokdftcniqywmvjd

Output: 3

Input:
100
zbzevxgewibujtbyvhzohoobudkghaivlbpaywiesizahkdxmcpdoqzsxqglezenmsgvsmxcrzcntauvarpakddglhrjmzylfuyq

Output: 4

Input:
100
whkbjjjrpcgsfaxgcmktmwypyfhbzvvowkvxltbmnyndqkswixxqxriopddrygymbcvadjjheugxgikrlirnhhsmnjmzpizyltau

Output: 5

Input:
1
z

Output: 0

Input:
5
babaa

Output: 2

Input:
5
abbdd

Output: 2

Input:
6
aaaaaa

Output: 0

Input:
6
bbbbab

Output: 5

Input:
6
baabbb

Output: 4

Input:
6
dacbab

Output: 3

Input:
7
aaaaaaa

Output: 0

Input:
7
baaabab

Output: 3

Input:
7
ccababa

Output: 2

Input:
7
cddcbcb

Output: 5

Input:
8
aaaaaaaa

Output: 0

Input:
8
aaabbaab

Output: 3

Input:
8
abababbc

Output: 5

Input:
8
bdaacddc

Output: 2

Input:
9
aaaaaaaaa

Output: 0

Input:
9
aabaaabab

Output: 3

Input:
9
baccbbaca

Output: 5

Input:
9
acacaabaa

Output: 1

Input:
10
aaaaaaaaaa

Output: 0

Input:
10
bbaabaabbb

Output: 6

Input:
10
cbbbbcaaca

Output: 6

Input:
10
cadbcdddda

Output: 6

[{'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '1\r\na\r\n', 'output': ['0']}, {'input': '100\r\naaaaaaabaaaaaabcaaaaaaaaaaaaaaaaaaaabbbaaaaaaabefhklmnopsuxzywvtrqjigdcaaaaaaaaaaaaaaaaaaaaaaaabaaaa\r\n', 'output': ['32']}, {'input': '5\r\nbabaa\r\n', 'output': ['2']}, {'input': '100\r\nababaaaabaabaaaaaaabaaaaaaaaaaaaacbaaaabaaaaaabaabaaaababaaaabaehijkmnpqvxzywutsrolgfdcbaaaabaabaaaa\r\n', 'output': ['40']}]

[{'input': '100\r\nababaaaabaabaaaaaaabaaaaaaaaaaaaacbaaaabaaaaaabaabaaaababaaaabaehijkmnpqvxzywutsrolgfdcbaaaabaabaaaa\r\n', 'output': ['40']}, {'input': '100\r\nacdfijmnorszzyyzzzzzzyzzyzzzzxwzzzzzyzzzzzzyzzzzzzzyzzzzzyzzzzzzyxzzzyzzzzzyzzzzzyzzyzzzzvutqplkhgeb\r\n', 'output': ['99']}, {'input': '100\r\naaaaabcjkprsvxyzwutqonmlihgfedaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n', 'output': ['26']}, {'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '100\r\nwhkbjjjrpcgsfaxgcmktmwypyfhbzvvowkvxltbmnyndqkswixxqxriopddrygymbcvadjjheugxgikrlirnhhsmnjmzpizyltau\r\n', 'output': ['5']}]

[{'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '100\r\nciftajmzqbfkvbhnyugneialytrkwjlhzwltylptheadmypbjxdzkxnqovimgmzkwpuelzbbhciinfiyspfatgoexeezolulnliu\r\n', 'output': ['0']}, {'input': '100\r\nacdfijmnorszzyyzzzzzzyzzyzzzzxwzzzzzyzzzzzzyzzzzzzzyzzzzzyzzzzzzyxzzzyzzzzzyzzzzzyzzyzzzzvutqplkhgeb\r\n', 'output': ['99']}, {'input': '100\r\nmxjrojjwtrauhhccftvjsyfyfsnbdnwjfltyjetsylbddrkoqjxbmientcowknrecfqcvxfgsbymwyvakmbulhvrxzvzbygajtgc\r\n', 'output': ['2']}, {'input': '8\r\nbdaacddc\r\n', 'output': ['2']}]

[{'input': '100\r\naaaabbbcccccccdddddeeeeeffgggghhhiijjjjkkkllmmnnnoooppqqqrrrrssssssttttuuuuuuuuvvvvvwwwwxxxxyyyyzzzz\r\n', 'output': ['96']}, {'input': '100\r\nabcdeghfgefedeefcabaaabcedfefedacbbcaaabehhjlkjikjloqrtuyzxwvspnmnlkjgfdcbacdcghfedfebaacbcbcdbccaaa\r\n', 'output': ['85']}, {'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '4\r\nbcda\r\n', 'output': ['3']}, {'input': '8\r\nbdaacddc\r\n', 'output': ['2']}]

[{'input': '9\r\nbaccbbaca\r\n', 'output': ['5']}, {'input': '4\r\nbcda\r\n', 'output': ['3']}, {'input': '6\r\nbbbbab\r\n', 'output': ['5']}, {'input': '100\r\nbldubjepvkwhjbxrueydtpparjszjgwpxjlqlpsmdrjoaagfnrohfcabchmdwaoctmilfbpztwjrfdgdioqggokdftcniqywmvjd\r\n', 'output': ['3']}, {'input': '7\r\ncddcbcb\r\n', 'output': ['5']}]


The first line contains integer n (1 ≤ n ≤ 109).

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

/**
 *
 * @author arif_
 * @date
 * @algo
 * @difficulty
 */
public class CF_876C {
    /* START OF I/O ROUTINE */
    // PrintWriter for faster output
    public static PrintWriter out;

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

        public MyInputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
        }

        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;
        }
    } // end of class MyInputReader
    /* END OF I/O ROUTINE */

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

        int n = in.nextInt();

        ArrayList<Integer> ans = new ArrayList<Integer>();
        for (int i=81; i>=1; i--) {
            if (i >= n) continue;

            int x = n - i;
            int sum = 0, y = x;
            while (y > 0) {
                sum += (y % 10);
                y /= 10;
            }

            if (sum+x == n) ans.add(x);
        }

        out.println(ans.size());
        for (Integer a : ans) {
            out.println(a);
        }
        out.close();
    } // end of method main()
} // end of class Main

NoteIn the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.In the second test case there are no such x.

In the first line print one integer k — number of different values of x satisfying the condition.  In next k lines print these values in ascending order.

Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

Output:
1
15

Output:
1
1

Output:
2
99999937
 100000000

Output:
2
99999937 100000000

Output:
2
99999937
100000000

Output:
1
999999932

Output:
2
999999899
 999999908

Output:
2
999999899 999999908

Output:
2
999999899
999999908

Output:
1
5

Output:
1
10

Output:
1
33

Output:
1
60

Output:
1
86

Output:
2
91
100

Output:
2
91
 100

Output:
2
91 100

Output:
2
1988
2006

Output:
2
1988 2006

Output:
2
1988
 2006


The first line contains the positive integer a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has.  The second line contains the positive integer b (1 ≤ b ≤ 1000) — the number of apples Nikolay has.  The third line contains the positive integer c (1 ≤ c ≤ 1000) — the number of pears Nikolay has.

import java.util.Scanner;

public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scanner=new Scanner(System.in);
        int lemon = scanner.nextInt();
        int apple = scanner.nextInt();
        int pear = scanner.nextInt();

         int result=0;

        for(int i=lemon;i>0;i--){
             if(2*i<=apple&&4*i<=pear){
                result=i+(2*i)+(4*i);
                System.out.println(result+"");
                return;
            }else if(i==1){
                 System.out.println(result+"");
            }

        }

    }

}

NoteIn the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.

Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.

Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.

Input:
2
5
7

Output: 7

Input:
4
7
13

Output: 21

Input:
2
3
2

Output: 0

Input:
1
1
1

Output: 0

Input:
1
2
4

Output: 7

Input:
1000
1000
1000

Output: 1750

Input:
1
1
4

Output: 0

Input:
1
2
3

Output: 0

Input:
1
1000
1000

Output: 7

Input:
1000
1
1000

Output: 0

Input:
1000
2
1000

Output: 7

Input:
1000
500
1000

Output: 1750

Input:
1000
1000
4

Output: 7

Input:
1000
1000
3

Output: 0

Input:
4
8
12

Output: 21

Input:
10
20
40

Output: 70

Input:
100
200
399

Output: 693

Input:
200
400
800

Output: 1400

Input:
199
400
800

Output: 1393

Input:
201
400
800

Output: 1400

Input:
200
399
800

Output: 1393

Input:
200
401
800

Output: 1400

Input:
200
400
799

Output: 1393

Input:
200
400
801

Output: 1400

Input:
139
252
871

Output: 882

Input:
109
346
811

Output: 763

Input:
237
487
517

Output: 903

Input:
161
331
725

Output: 1127

Input:
39
471
665

Output: 273

Input:
9
270
879

Output: 63

Input:
137
422
812

Output: 959

Input:
15
313
525

Output: 105

Input:
189
407
966

Output: 1323

Input:
18
268
538

Output: 126

Input:
146
421
978

Output: 1022

Input:
70
311
685

Output: 490

Input:
244
405
625

Output: 1092

Input:
168
454
832

Output: 1176

Input:
46
344
772

Output: 322

Input:
174
438
987

Output: 1218

Input:
144
387
693

Output: 1008

Input:
22
481
633

Output: 154

Input:
196
280
848

Output: 980

Input:
190
454
699

Output: 1218

Input:
231
464
928

Output: 1617

Input:
151
308
616

Output: 1057

Input:
88
182
364

Output: 616

Input:
12
26
52

Output: 84

Input:
204
412
824

Output: 1428

Input:
127
256
512

Output: 889

Input:
224
446
896

Output: 1561

Input:
146
291
584

Output: 1015

Input:
83
164
332

Output: 574

Input:
20
38
80

Output: 133

Input:
198
393
792

Output: 1372

Input:
120
239
480

Output: 833

Input:
208
416
831

Output: 1449

Input:
130
260
517

Output: 903

Input:
67
134
267

Output: 462

Input:
245
490
979

Output: 1708

Input:
182
364
727

Output: 1267

Input:
104
208
413

Output: 721

Input:
10
2
100

Output: 7

Input:
2
100
100

Output: 14

Input:
2
3
8

Output: 7

Input:
1
2
8

Output: 7

Input:
1
2
200

Output: 7

Input:
5
4
16

Output: 14

Input:
1
10
10

Output: 7

Input:
1
4
8

Output: 7

Input:
100
4
1000

Output: 14

Input:
2
6
12

Output: 14

Input:
10
7
4

Output: 7

Input:
2
10
100

Output: 14

Input:
2
3
4

Output: 7

Input:
1
2
999

Output: 7

Input:
1
10
20

Output: 7

Input:
100
18
20

Output: 35

Input:
100
1
100

Output: 0

Input:
3
7
80

Output: 21

Input:
2
8
24

Output: 14

Input:
1
100
100

Output: 7

Input:
2
1
8

Output: 0

Input:
10
5
23

Output: 14


The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \le a, b, c, d \le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.

import static java.lang.StrictMath.abs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Ropewalkers {
    static int a;
    static int b;
    static int c;
    static int d;
    static  List <Integer> list = new ArrayList();
    static int counter=0;
    public static void main(String args[]){
  Scanner in = new Scanner(System.in);
  a = in.nextInt();
  b = in.nextInt();
  c = in.nextInt();
  d = in.nextInt();
  list.add(a);
  list.add(b);
  list.add(c);
  int max = Collections.max(list);
  int min = Collections.min(list);
  int mid = (a+b+c) - (min+max);

  if (abs(mid - min) < d ){
    counter += d - (mid-min);

  }
  if(abs(max - mid) < d ){

    counter += d - max + mid;
  }
   System.out.println(counter);
  }

}

NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds.

Output one integer — the minimum duration (in seconds) of the performance.

Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.

Input: 5 2 6 3

Output: 2

Input: 3 1 5 6

Output: 8

Input: 8 3 3 2

Output: 2

Input: 2 3 10 4

Output: 3

Input: 1000000000 1000000000 1000000000 1000000000

Output: 2000000000

Input: 500000000 250000000 750000000 1000000000

Output: 1500000000

Input: 1 3 2 5

Output: 8

Input: 2 3 1 6

Output: 10

Input: 9 6 2 5

Output: 3

Input: 1 1 1 1

Output: 2

Input: 1 1 500 10

Output: 10

Input: 500 1 500 1000

Output: 1501

Input: 1 2 1 1

Output: 1

Input: 89 983 751 1000

Output: 1106

Input: 716270982 22102638 553198855 1000000000

Output: 1305831656

Input: 1000000000 1 1000000000 999999999

Output: 999999999

Input: 999999999 1 1 1000000000

Output: 1000000002

Input: 1 2 3 4

Output: 6

Input: 1 3 4 5

Output: 7

Input: 1 3 2 6

Output: 10

Input: 2 2 3 4

Output: 7

Input: 1 1 4 5

Output: 7

Input: 5 5 2 6

Output: 9

Input: 1 3 3 6

Output: 10

Input: 1 4 4 6

Output: 9

Input: 1 3 3 5

Output: 8

Input: 1 4 4 5

Output: 7

Input: 1000000000 1000000000 1000000000 1

Output: 2

Input: 2 1 1 3

Output: 5

Input: 3 2 2 3

Output: 5

Input: 5 5 4 1

Output: 1

Input: 3 1 4 2

Output: 1

Input: 5 4 2 3

Output: 3

Input: 3 2 1 4

Output: 6

Input: 3 2 3 5

Output: 9

Input: 1 3 4 6

Output: 9

Input: 3 1 2 7

Output: 12

Input: 1 5 4 8

Output: 12

Input: 1 4 3 9

Output: 15

Input: 5 3 4 10

Output: 18

Input: 3 5 8 1

Output: 0

Input: 1 1 2 100

Output: 199

Input: 5 5 7 5

Output: 8

Input: 1 5 10 3

Output: 0

Input: 1 2 9 5

Output: 4

Input: 2 4 7 6

Output: 7

Input: 1 1 1 1000000000

Output: 2000000000

Input: 1 500000000 1000000000 1000000000

Output: 1000000001

Input: 15 15 15 15

Output: 30


The first line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \leq n \leq 50$$$, $$$0 \leq p \leq 1$$$) — the number of pieces and Kuro's wanted parity. The second line contains $$$n$$$ integers $$$c_{1}, c_{2}, ..., c_{n}$$$ ($$$-1 \leq c_{i} \leq 1$$$) — the colors of the pieces.

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

public class Codeforces979E {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int p = Integer.parseInt(st.nextToken());
		int[] c = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(st.nextToken());
		}

		//list of powers of 2 until 2^{n^2}, mod 1000000007
		int[] twopower = new int[n*n+1];
		twopower[0] = 1;
		for (int i = 1; i <= n*n; i++) {
			twopower[i] = (2*twopower[i-1])%1000000007;
		}

		//Pascal's triangle until n choose k, mod 1000000007
		int[][] pascal = new int[n+1][n+1];
		for (int i = 0; i <= n; i++) {
			pascal[i][0] = 1;
			pascal[0][i] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				pascal[i][j] = (pascal[i][j-1]+pascal[i-1][j])%1000000007;
			}
		}

		//dp[x][y][z] means the last x have all arrows intact
		//and there are y 0's and z 1's at the start with no
		//arrows going between them.
		//we only care when 0 <= x+y+z <= n.
		//answer is dp[n][0][0].
		int[][][] dp = new int[n+1][n+1][n+1];
		//base case of x = 0
		for (int y = 0; y <= n; y++) {
			for (int z = 0; z <= (n-y); z++) {
				if (p == (y+z)%2) {
					dp[0][y][z] = 1;
				}
			}
		}

		for (int x = 1; x <= n; x++) {
			for (int y = 0; y <= (n-x); y++) {
				for (int z = 0; z <= (n-x-y); z++) {
					if (c[n-x] != 1) {
						int evenmultiple;
						int oddmultiple;
						if (z == 0) {
							evenmultiple = 1;
							oddmultiple = 0;
						}
						else {
							evenmultiple = twopower[z-1];
							oddmultiple = twopower[z-1];
						}
						long evenk = (long) evenmultiple * (long) dp[x-1][y+1][z];
						evenk %= 1000000007;
						long oddk = (long) oddmultiple * (long) dp[x-1][y][z];
						oddk %= 1000000007;
						oddk *= (long) twopower[x-1];
						oddk %= 1000000007;
						long totalk = evenk+oddk;
						totalk *= twopower[y];
						totalk %= 1000000007;
						dp[x][y][z] += (int) totalk;
					}
					if (c[n-x] != 0) {
						int evenmultiple;
						int oddmultiple;
						if (y == 0) {
							evenmultiple = 1;
							oddmultiple = 0;
						}
						else {
							evenmultiple = twopower[y-1];
							oddmultiple = twopower[y-1];
						}
						long evenk = (long) evenmultiple * (long) dp[x-1][y][z+1];
						evenk %= 1000000007;
						long oddk = (long) oddmultiple * (long) dp[x-1][y][z];
						oddk %= 1000000007;
						oddk *= (long) twopower[x-1];
						oddk %= 1000000007;
						long totalk = evenk+oddk;
						totalk *= twopower[z];
						totalk %= 1000000007;
						dp[x][y][z] += (int) totalk;
					}
					dp[x][y][z] %= 1000000007;
				}
			}
		}

		pw.println(dp[n][0][0]);

		pw.close();
	}
}

NoteIn the first example, there are $$$6$$$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $$$3, 3, 5$$$ for the first row and $$$5, 3, 3$$$ for the second row, both from left to right.

Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $$$p$$$.

Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.The paper is divided into $$$n$$$ pieces enumerated from $$$1$$$ to $$$n$$$. Shiro has painted some pieces with some color. Specifically, the $$$i$$$-th piece has color $$$c_{i}$$$ where $$$c_{i} = 0$$$ defines black color, $$$c_{i} = 1$$$ defines white color and $$$c_{i} = -1$$$ means that the piece hasn't been colored yet.The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($$$0$$$ or $$$1$$$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $$$[1 \to 0 \to 1 \to 0]$$$, $$$[0 \to 1 \to 0 \to 1]$$$, $$$[1]$$$, $$$[0]$$$ are valid paths and will be counted. You can only travel from piece $$$x$$$ to piece $$$y$$$ if and only if there is an arrow from $$$x$$$ to $$$y$$$.But Kuro is not fun yet. He loves parity. Let's call his favorite parity $$$p$$$ where $$$p = 0$$$ stands for "even" and $$$p = 1$$$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $$$p$$$.It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $$$10^{9} + 7$$$.

Input:
3 1
-1 0 1

Output: 6

Input:
2 1
1 0

Output: 1

Input:
1 1
-1

Output: 2

Input:
1 0
-1

Output: 0

Input:
1 1
0

Output: 1

Input:
5 1
-1 -1 -1 -1 -1

Output: 16512

Input:
5 0
-1 -1 -1 -1 -1

Output: 16256

Input:
10 1
1 1 1 1 0 0 0 1 0 0

Output: 185921272

Input:
50 1
-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1

Output: 803313751

Input:
20 1
0 0 -1 0 1 1 1 1 -1 -1 1 1 1 -1 0 0 1 1 1 0

Output: 483548109

Input:
30 0
1 0 1 1 0 -1 0 1 -1 0 1 -1 0 -1 1 1 -1 1 0 1 0 -1 1 1 0 1 -1 0 1 1

Output: 40673917

Input:
40 1
-1 1 1 1 0 -1 -1 1 1 -1 1 1 1 0 0 -1 1 0 1 -1 -1 1 0 1 1 0 1 0 0 -1 -1 1 -1 1 1 1 1 0 -1 0

Output: 73320910

Input:
50 1
-1 -1 0 -1 1 0 1 0 1 -1 -1 0 0 0 -1 0 0 -1 0 1 -1 0 1 -1 1 -1 1 -1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 0 0 -1 0 1 1 0 0

Output: 772364444

Input:
50 1
-1 -1 -1 -1 -1 0 -1 -1 -1 0 1 0 -1 0 1 -1 -1 -1 1 0 1 -1 0 1 0 1 0 0 1 1 -1 1 -1 -1 1 1 -1 -1 0 -1 -1 1 -1 1 -1 1 1 0 0 -1

Output: 279519499

Input:
3 1
0 -1 -1

Output: 18

Input:
4 0
1 -1 1 0

Output: 64

Input:
21 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 0

Input:
29 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 733922348

Input:
41 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output: 0

Input:
3 0
0 0 0

Output: 0

Input:
38 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 0

Input:
25 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 322050759

Input:
30 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 549790477

Input:
46 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: 480432768

Input:
10 0
1 0 -1 1 -1 0 0 1 1 0

Output: 743685088

Input:
6 0
-1 0 -1 1 1 1

Output: 61440

Input:
7 0
1 0 1 1 -1 1 1

Output: 2359296

Input:
9 0
0 -1 -1 -1 -1 -1 1 0 -1

Output: 560111071

Input:
6 1
1 -1 -1 -1 0 0

Output: 131072

Input:
6 0
0 -1 -1 0 0 -1

Output: 135168

Input:
8 0
-1 0 1 -1 1 -1 1 1

Output: 56964601

Input:
6 1
1 1 0 -1 -1 -1

Output: 133120

Input:
22 1
0 -1 1 0 0 1 1 1 -1 -1 1 1 1 -1 1 1 0 0 -1 0 1 1

Output: 981309322

Input:
47 1
0 -1 0 1 0 -1 1 -1 1 -1 1 -1 0 0 -1 0 -1 1 -1 -1 0 1 -1 1 0 0 1 -1 0 1 0 1 0 1 0 1 -1 -1 1 -1 -1 -1 0 1 1 0 1

Output: 716651774

Input:
2 1
0 1

Output: 1

Input:
36 1
-1 0 0 1 1 0 -1 -1 -1 -1 1 1 0 -1 0 1 0 -1 0 -1 0 1 0 -1 -1 0 1 -1 0 -1 0 -1 1 0 1 1

Output: 693536347

Input:
37 0
0 -1 0 0 0 -1 0 1 0 0 -1 0 -1 -1 0 1 1 0 -1 -1 -1 -1 1 -1 0 0 0 1 -1 -1 1 -1 1 1 -1 -1 -1

Output: 915368288

Input:
4 1
1 -1 -1 1

Output: 120

Input:
35 0
0 0 -1 -1 1 -1 1 -1 1 0 1 0 -1 0 1 1 -1 1 -1 0 0 -1 0 0 1 -1 -1 0 1 1 -1 1 1 1 -1

Output: 45647242

Input:
25 1
1 0 0 -1 -1 0 1 0 -1 1 0 0 0 -1 0 0 1 -1 -1 1 -1 -1 -1 1 1

Output: 66699122

Input:
36 1
-1 0 -1 -1 1 0 0 -1 1 0 0 -1 1 -1 1 0 1 0 0 0 1 1 1 0 1 1 0 -1 1 -1 0 0 0 1 1 -1

Output: 77953873

Input:
9 1
-1 -1 1 1 1 -1 -1 0 1

Output: 608326411

Input:
36 0
-1 0 0 -1 -1 -1 0 -1 0 1 -1 -1 1 1 -1 1 0 0 1 -1 1 1 -1 0 0 1 1 1 -1 1 1 -1 1 1 1 -1

Output: 152782818

Input:
10 1
1 1 1 -1 0 -1 -1 1 1 0

Output: 487370169

Input:
7 0
1 0 -1 1 -1 1 0

Output: 4194304

Input:
2 0
-1 0

Output: 3

Input:
5 1
-1 1 0 0 -1

Output: 1920

Input:
2 0
-1 -1

Output: 6

Input:
4 1
0 1 -1 -1

Output: 136

Input:
5 0
-1 0 0 0 1

Output: 1088

Input:
17 0
0 -1 -1 0 1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0

Output: 310296666

Input:
10 0
1 -1 0 1 1 -1 -1 0 1 0

Output: 487370169

Input:
31 0
1 -1 -1 0 -1 0 -1 -1 0 -1 -1 -1 1 1 0 1 -1 1 1 0 0 -1 0 1 -1 1 0 -1 1 -1 -1

Output: 304540143

Input:
41 1
0 0 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 0 1 1 1 0 0 1 1 -1 0 0 1 0 0 1 1 1 -1 0 -1 1 0 1 1 1 1

Output: 589337580

Input:
37 1
1 -1 1 -1 -1 -1 0 1 -1 -1 1 0 0 0 1 1 -1 0 -1 1 -1 0 1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 -1 -1 -1

Output: 916646835

Input:
31 0
1 0 1 1 0 0 0 -1 -1 -1 -1 -1 0 1 1 1 0 -1 1 -1 -1 1 -1 1 1 0 0 1 1 -1 0

Output: 253181331

Input:
4 1
1 0 1 0

Output: 32

Input:
26 1
1 -1 1 1 1 1 -1 1 -1 1 -1 -1 0 -1 -1 -1 1 0 -1 -1 0 1 -1 0 1 0

Output: 996763118

Input:
28 1
0 0 1 1 -1 1 -1 1 0 -1 -1 -1 0 -1 0 -1 1 0 -1 1 0 -1 -1 0 -1 1 1 -1

Output: 618844160

Input:
24 1
0 0 0 1 1 0 -1 0 -1 1 -1 -1 0 0 1 1 0 -1 0 0 0 0 1 1

Output: 189147304

Input:
17 0
-1 0 -1 1 0 0 1 1 -1 -1 -1 -1 -1 1 1 -1 -1

Output: 555719737

Input:
42 1
0 1 -1 0 -1 0 -1 1 -1 1 0 1 1 -1 0 -1 -1 1 -1 -1 0 -1 1 -1 0 1 0 1 -1 1 -1 1 0 0 -1 0 1 0 1 1 0 0

Output: 386658717

Input:
3 0
0 -1 -1

Output: 14

Input:
9 1
0 1 -1 -1 -1 -1 1 1 1

Output: 755810045

Input:
9 0
1 1 0 0 1 -1 -1 0 0

Output: 438952513

Input:
14 1
-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0

Output: 829277977

Input:
20 0
1 -1 1 -1 -1 -1 0 1 1 0 1 0 -1 1 1 -1 1 0 1 1

Output: 841268608

Input:
18 0
1 1 1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 -1 0 -1 1

Output: 557382306

Input:
16 0
1 -1 0 0 0 -1 -1 -1 0 -1 -1 1 0 0 -1 1

Output: 807669877

Input:
27 1
-1 0 -1 -1 -1 0 1 -1 1 0 0 -1 0 1 0 0 0 -1 -1 1 -1 -1 -1 0 1 0 0

Output: 61073361

Input:
2 0
-1 1

Output: 3

Input:
34 1
1 0 -1 0 0 0 -1 1 0 1 1 1 1 1 1 -1 0 0 1 0 -1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 1 -1

Output: 132603129

Input:
17 0
1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 -1 0

Output: 585862415

Input:
16 0
-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1

Output: 878929813

Input:
17 0
0 0 0 0 0 1 -1 -1 -1 1 -1 1 0 0 1 -1 -1

Output: 427689083

Input:
38 0
-1 -1 1 1 -1 -1 1 -1 0 1 -1 1 1 1 -1 1 0 1 0 -1 1 -1 -1 0 0 1 -1 -1 0 -1 0 -1 -1 0 1 0 -1 0

Output: 502273788

Input:
33 0
0 1 -1 -1 -1 1 -1 1 1 -1 -1 -1 -1 0 1 0 -1 0 0 -1 1 -1 -1 0 0 -1 0 0 1 0 1 1 1

Output: 52976952

Input:
32 1
0 0 1 0 -1 0 1 -1 -1 -1 0 1 0 0 1 0 -1 -1 1 1 1 0 0 1 -1 -1 1 0 0 -1 0 1

Output: 247728070

Input:
6 0
-1 1 1 -1 -1 -1

Output: 267264

Input:
27 1
0 -1 1 0 -1 1 1 -1 0 -1 0 0 0 -1 -1 0 0 -1 -1 0 -1 0 -1 0 0 1 1

Output: 28918236

Input:
27 1
0 -1 -1 1 1 1 -1 1 0 0 1 -1 -1 1 -1 1 1 1 1 1 0 0 0 0 -1 -1 0

Output: 69931865

Input:
17 1
0 -1 -1 0 0 1 -1 -1 0 0 -1 1 0 -1 1 0 0

Output: 427689083

Input:
34 0
1 1 1 0 0 0 0 1 0 0 1 -1 1 1 -1 0 -1 1 1 1 0 1 1 -1 0 0 1 -1 -1 0 0 0 -1 -1

Output: 115086916

Input:
31 1
1 0 0 0 0 0 0 0 -1 0 0 0 1 -1 -1 -1 0 0 -1 0 1 -1 1 0 1 1 1 1 -1 -1 1

Output: 186475897

Input:
48 1
1 0 0 0 1 -1 1 1 0 -1 0 -1 1 1 0 -1 -1 -1 0 0 0 1 0 1 0 -1 -1 -1 -1 1 0 1 -1 -1 -1 1 -1 0 1 0 0 1 -1 0 -1 0 0 0

Output: 763606955

Input:
5 0
0 -1 0 0 0

Output: 768

Input:
43 0
1 0 0 -1 0 -1 0 -1 1 1 -1 1 -1 0 0 1 -1 -1 -1 0 0 -1 1 -1 -1 1 0 0 1 -1 0 -1 -1 -1 -1 -1 1 1 0 -1 -1 -1 0

Output: 477560567

Input:
11 1
1 0 1 0 -1 1 0 -1 -1 0 0

Output: 67049563

Input:
13 1
-1 1 0 0 -1 0 -1 1 -1 -1 1 1 0

Output: 621572676


The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.

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

public class A {
    FScanner in = new FScanner();
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);

    void run() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            a[i] = x;
        }
        out.print(a[0] % 2 != 0 && a[n - 1] % 2 != 0 && n % 2 == 1 ?
                "Yes" :
                "No");
        out.close();
    }

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

    static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        char[][] nextCharArray(int n, int m) {
            char[][] g = new char[n][m];
            for (int i = 0; i < n; i++)
                g[i] = next().toCharArray();
            return g;
        }

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

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

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

NoteIn the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.

Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower).

Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.

Input:
3
1 3 5

Output: YES

Output: Yes

Input:
5
1 0 1 5 1

Output: YES

Output: Yes

Input:
3
4 3 1

Output: No

Output: NO

Input:
4
3 9 9 3

Output: No

Output: NO

Input:
1
1

Output: YES

Output: Yes

Input:
5
100 99 100 99 99

Output: No

Output: NO

Input:
100
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100

Output: No

Output: NO

Input:
1
0

Output: No

Output: NO

Input:
2
1 1

Output: No

Output: NO

Input:
2
10 10

Output: No

Output: NO

Input:
2
54 21

Output: No

Output: NO

Input:
5
0 0 0 0 0

Output: No

Output: NO

Input:
5
67 92 0 26 43

Output: YES

Output: Yes

Input:
15
45 52 35 80 68 80 93 57 47 32 69 23 63 90 43

Output: YES

Output: Yes

Input:
15
81 28 0 82 71 64 63 89 87 92 38 30 76 72 36

Output: No

Output: NO

Input:
50
49 32 17 59 77 98 65 50 85 10 40 84 65 34 52 25 1 31 61 45 48 24 41 14 76 12 33 76 44 86 53 33 92 58 63 93 50 24 31 79 67 50 72 93 2 38 32 14 87 99

Output: No

Output: NO

Input:
55
65 69 53 66 11 100 68 44 43 17 6 66 24 2 6 6 61 72 91 53 93 61 52 96 56 42 6 8 79 49 76 36 83 58 8 43 2 90 71 49 80 21 75 13 76 54 95 61 58 82 40 33 73 61 46

Output: No

Output: NO

Input:
99
73 89 51 85 42 67 22 80 75 3 90 0 52 100 90 48 7 15 41 1 54 2 23 62 86 68 2 87 57 12 45 34 68 54 36 49 27 46 22 70 95 90 57 91 90 79 48 89 67 92 28 27 25 37 73 66 13 89 7 99 62 53 48 24 73 82 62 88 26 39 21 86 50 95 26 27 60 6 56 14 27 90 55 80 97 18 37 36 70 2 28 53 36 77 39 79 82 42 69

Output: YES

Output: Yes

Input:
99
99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99

Output: YES

Output: Yes

Input:
100
61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46 79 41 37 61 16 29 82 28 22 14 64 49 86 92 82 55 54 24 75 58 95 31 3 34 26 23 78 91 49 6 30 57 27 69 29 54 42 0 61 83

Output: No

Output: NO

Input:
6
1 2 2 2 2 1

Output: No

Output: NO

Input:
3
1 2 1

Output: YES

Output: Yes

Input:
4
1 3 2 3

Output: No

Output: NO

Input:
6
1 1 1 1 1 1

Output: No

Output: NO

Input:
6
1 1 0 0 1 1

Output: No

Output: NO

Input:
4
1 4 9 3

Output: No

Output: NO

Input:
4
1 0 1 1

Output: No

Output: NO

Input:
10
1 0 0 1 1 1 1 1 1 1

Output: No

Output: NO

Input:
10
9 2 5 7 8 3 1 9 4 9

Output: No

Output: NO

Input:
99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2

Output: No

Output: NO

Input:
6
1 2 1 2 2 1

Output: No

Output: NO

Input:
6
1 0 1 0 0 1

Output: No

Output: NO

Input:
4
1 3 4 7

Output: No

Output: NO

Input:
8
1 1 1 2 1 1 1 1

Output: No

Output: NO

Input:
3
1 1 2

Output: No

Output: NO

Input:
5
1 2 1 2 1

Output: YES

Output: Yes

Input:
5
5 4 4 2 1

Output: YES

Output: Yes

Input:
6
1 3 3 3 3 1

Output: No

Output: NO

Input:
7
1 2 1 2 2 2 1

Output: YES

Output: Yes

Input:
4
1 2 2 1

Output: No

Output: NO

Input:
6
1 2 3 4 6 5

Output: No

Output: NO

Input:
5
1 1 2 2 2

Output: No

Output: NO

Input:
5
1 0 0 1 1

Output: YES

Output: Yes

Input:
3
1 2 4

Output: No

Output: NO

Input:
3
1 0 2

Output: No

Output: NO

Input:
5
1 1 1 0 1

Output: YES

Output: Yes

Input:
4
3 9 2 3

Output: No

Output: NO

Input:
6
1 1 1 4 4 1

Output: No

Output: NO

Input:
6
1 2 3 5 6 7

Output: No

Output: NO

Input:
6
1 1 1 2 2 1

Output: No

Output: NO

Input:
6
1 1 1 0 0 1

Output: No

Output: NO

Input:
5
1 2 2 5 5

Output: YES

Output: Yes

Input:
5
1 3 2 4 5

Output: YES

Output: Yes

Input:
8
1 2 3 5 7 8 8 5

Output: No

Output: NO

Input:
10
1 1 1 2 1 1 1 1 1 1

Output: No

Output: NO

Input:
4
1 0 0 1

Output: No

Output: NO

Input:
7
1 0 1 1 0 0 1

Output: YES

Output: Yes

Input:
7
1 4 5 7 6 6 3

Output: YES

Output: Yes

Input:
4
2 2 2 2

Output: No

Output: NO

Input:
5
2 3 4 5 6

Output: No

Output: NO

Input:
4
1 1 2 1

Output: No

Output: NO

Input:
3
1 2 3

Output: YES

Output: Yes

Input:
6
1 3 3 2 2 3

Output: No

Output: NO

Input:
4
1 1 2 3

Output: No

Output: NO

Input:
4
1 2 3 5

Output: No

Output: NO

Input:
5
3 4 4 3 3

Output: YES

Output: Yes

Input:
4
3 2 2 3

Output: No

Output: NO

Input:
6
1 1 1 1 2 1

Output: No

Output: NO

Input:
6
1 1 2 2 1 1

Output: No

Output: NO

Input:
10
3 4 2 4 3 2 2 4 4 3

Output: No

Output: NO

Input:
7
1 2 4 3 2 4 5

Output: YES

Output: Yes

Input:
28
75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67

Output: No

Output: NO

Input:
79
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18

Output: No

Output: NO

Input:
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Output: No

Output: NO


The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 250$$$, $$$1 \le k \le 10^{9}$$$).

//package cf589d2;
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class E {
	static long MOD = 1000000007;
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[][] choose = new long[n + 1][n + 1];
		long[][] pow = new long[n + 1][2];
		for(int i = 0; i <= n; i++) {
			choose[i][0] = 1;
			choose[i][i] = 1;
		}
		for(int i = 2; i <= n; i++)
			for(int j = 1; j < i; j++)
				choose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % MOD;
		for(int i = 0; i <= n; i++)
			for(int j = 0; j < 2; j++)
				pow[i][j] = pMod(k - j, i);
		long[][] dp = new long[n + 1][n + 1];
		dp[0][n] = 1;
		for(int i = 1; i <= n; i++)
			for(int j = 0; j <= n; j++)
				for(int l = 0; l <= j; l++) {
					long del = dp[i - 1][j] * choose[j][l] % MOD * pow[l][1] % MOD;
					if(l < j)
						del = del * pow[n - j][0] % MOD;
					else
						del = del * (pow[n - j][0] - pow[n - j][1] + MOD) % MOD;
					dp[i][l] = (dp[i][l] + del) % MOD;
				}
		out.println(dp[n][0]);
		out.close();
	}
	public static long pMod(long x, long p) {
		if(p == 0)
			return 1;
		long l = pMod(x, p / 2);
		return l * l % MOD * (p % 2 == 1 ? x : 1) % MOD;
	}
	public static PrintWriter out  = new PrintWriter(new BufferedOutputStream(System.out));
	public static class MyScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		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;
		}
	}
}

NoteIn the first example, following $$$7$$$ cases are possible.  In the second example, make sure you print the answer modulo $$$(10^{9} + 7)$$$.

Print the answer modulo $$$(10^{9} + 7)$$$.

You have $$$n \times n$$$ square grid and an integer $$$k$$$. Put an integer in each cell while satisfying the conditions below.  All numbers in the grid should be between $$$1$$$ and $$$k$$$ inclusive.  Minimum number of the $$$i$$$-th row is $$$1$$$ ($$$1 \le i \le n$$$).  Minimum number of the $$$j$$$-th column is $$$1$$$ ($$$1 \le j \le n$$$). Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo $$$(10^{9} + 7)$$$.  These are the examples of valid and invalid grid when $$$n=k=2$$$.

Input: 2 2

Output: 7

Input: 123 456789

Output: 689974806

Input: 250 1000000000

Output: 770503193

Input: 250 1

Output: 1

Input: 1 3

Output: 1

Input: 3 497285769

Output: 790515254

Input: 3 212096267

Output: 501206544

Input: 4 221874066

Output: 274467242

Input: 244 315404017

Output: 868949606

Input: 218 325181815

Output: 230476135

Input: 246 629926913

Output: 283598434

Input: 216 639704712

Output: 319243107

Input: 244 22597665

Output: 56808536

Input: 218 737408162

Output: 720936813

Input: 242 747185961

Output: 365665959

Input: 220 51931060

Output: 944377763

Input: 244 61708858

Output: 84446310

Input: 216 104981514

Output: 943178465

Input: 208 1

Output: 1

Input: 236 1

Output: 1

Input: 242 106758452

Output: 437620405

Input: 216 411503551

Output: 618370501

Input: 244 126314049

Output: 662993833

Input: 214 431059147

Output: 37643610

Input: 242 440836946

Output: 687163955

Input: 220 528762598

Output: 944995733

Input: 244 833507696

Output: 89218992

Input: 218 548318195

Output: 721573920

Input: 242 558095993

Output: 300047623

Input: 224 26911790

Output: 554883010

Input: 206 1

Output: 1

Input: 234 1

Output: 1

Input: 10 19549

Output: 843886139


The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers l, s, r, p — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.

NoteIn the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.

On a single line, print "YES" if an accident is possible, and "NO" otherwise.

Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.   An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.

Input:
1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1

Output: YES

Input:
0 1 1 0
1 0 1 0
1 1 0 0
0 0 0 1

Output: NO

Input:
1 0 0 0
0 0 0 1
0 0 0 0
1 0 1 0

Output: NO

Input:
0 0 0 0
0 0 0 1
0 0 0 1
0 0 0 1

Output: NO

Input:
1 1 1 0
0 1 0 1
1 1 1 0
1 1 1 1

Output: YES

Input:
0 1 1 0
0 1 0 0
1 0 0 1
1 0 0 0

Output: YES

Input:
1 0 0 0
0 1 0 0
1 1 0 0
0 1 1 0

Output: NO

Input:
0 0 0 0
0 1 0 1
1 0 1 1
1 1 1 0

Output: YES

Input:
1 1 0 0
0 1 0 1
1 1 1 0
0 0 1 1

Output: YES

Input:
0 1 0 0
0 0 0 0
1 0 0 0
0 0 0 1

Output: NO

Input:
0 0 1 0
0 0 0 0
1 1 0 0
0 0 0 1

Output: NO

Input:
0 0 1 0
0 1 0 1
1 0 1 0
0 0 1 0

Output: YES

Input:
1 1 1 0
0 1 0 1
1 1 1 1
0 0 0 1

Output: YES

Input:
0 0 1 0
0 0 0 0
0 0 0 1
0 0 0 1

Output: NO

Input:
0 0 0 0
0 1 0 1
1 0 1 1
0 0 0 1

Output: YES

Input:
1 1 0 0
0 1 0 0
1 1 1 0
1 0 1 0

Output: NO

Input:
0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1

Output: NO

Input:
1 0 1 0
1 1 0 0
1 1 0 0
0 0 0 0

Output: NO

Input:
0 0 1 0
1 1 0 0
1 0 1 0
1 0 0 0

Output: NO

Input:
0 0 1 0
1 0 0 0
0 0 0 1
0 0 0 1

Output: NO

Input:
0 1 1 0
1 1 0 1
1 0 0 1
1 1 1 0

Output: YES

Input:
1 0 0 0
1 1 0 0
1 1 0 1
0 0 1 0

Output: YES

Input:
0 0 0 0
1 1 0 0
0 0 0 1
0 0 1 0

Output: NO

Input:
0 1 0 0
0 0 0 1
0 1 0 0
0 0 0 1

Output: NO

Input:
0 1 0 0
1 1 0 1
1 0 0 1
1 1 0 1

Output: YES

Input:
1 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0

Output: YES

Input:
0 1 0 1
0 0 0 0
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 1 1
0 0 0 0
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 1
1 0 0 0
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 1
0 1 0 0
0 0 0 0
0 0 0 0

Output: NO

Input:
0 0 0 1
0 0 1 0
0 0 0 0
0 0 0 0

Output: NO

Input:
0 0 0 1
0 0 0 0
1 0 0 0
0 0 0 0

Output: NO

Input:
0 0 0 1
0 0 0 0
0 1 0 0
0 0 0 0

Output: YES

Input:
0 0 0 1
0 0 0 0
0 0 1 0
0 0 0 0

Output: NO

Input:
0 0 0 1
0 0 0 0
0 0 0 0
1 0 0 0

Output: NO

Input:
0 0 0 1
0 0 0 0
0 0 0 0
0 1 0 0

Output: NO

Input:
0 0 0 1
0 0 0 0
0 0 0 0
0 0 1 0

Output: YES

Input:
1 0 0 0
0 0 0 1
0 0 0 0
0 0 0 0

Output: NO

Input:
0 1 0 0
0 0 0 1
0 0 0 0
0 0 0 0

Output: NO

Input:
0 0 1 0
0 0 0 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 0
1 0 0 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 0
0 1 0 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 1 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 1
1 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 1
0 1 0 0
0 0 0 0

Output: NO

Input:
0 0 0 0
0 0 0 1
0 0 1 0
0 0 0 0

Output: NO

Input:
0 0 0 0
0 0 0 1
0 0 0 0
1 0 0 0

Output: NO

Input:
0 0 0 0
0 0 0 1
0 0 0 0
0 1 0 0

Output: YES

Input:
0 0 0 0
0 0 0 1
0 0 0 0
0 0 1 0

Output: NO

Input:
1 0 0 0
0 0 0 0
0 0 0 1
0 0 0 0

Output: NO

Input:
0 1 0 0
0 0 0 0
0 0 0 1
0 0 0 0

Output: YES

Input:
0 0 1 0
0 0 0 0
0 0 0 1
0 0 0 0

Output: NO

Input:
0 0 0 0
1 0 0 0
0 0 0 1
0 0 0 0

Output: NO

Input:
0 0 0 0
0 1 0 0
0 0 0 1
0 0 0 0

Output: NO

Input:
0 0 0 0
0 0 1 0
0 0 0 1
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 0
1 0 0 1
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 0
0 1 0 1
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 1 1
0 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 0 1
1 0 0 0

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 0 1
0 1 0 0

Output: NO

Input:
0 0 0 0
0 0 0 0
0 0 0 1
0 0 1 0

Output: NO

Input:
1 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1

Output: YES

Input:
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 1

Output: NO

Input:
0 0 1 0
0 0 0 0
0 0 0 0
0 0 0 1

Output: NO

Input:
0 0 0 0
1 0 0 0
0 0 0 0
0 0 0 1

Output: NO

Input:
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1

Output: YES

Input:
0 0 0 0
0 0 1 0
0 0 0 0
0 0 0 1

Output: NO

Input:
0 0 0 0
0 0 0 0
1 0 0 0
0 0 0 1

Output: NO

Input:
0 0 0 0
0 0 0 0
0 1 0 0
0 0 0 1

Output: NO

Input:
0 0 0 0
0 0 0 0
0 0 1 0
0 0 0 1

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 0 0
1 0 0 1

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 0 0
0 1 0 1

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 1

Output: YES

Input:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

Output: NO

Input:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

Output: YES

Input:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

Output: YES

Input:
1 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0

Output: YES

Input:
0 1 1 0
1 0 1 0
1 1 1 0
0 0 0 1

Output: YES

Input:
1 1 0 1
0 0 0 0
0 0 0 0
0 0 0 0

Output: YES

Input:
1 1 1 0
1 1 1 0
1 1 1 0
0 0 0 1

Output: YES

Input:
0 0 0 1
0 0 1 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 1
0 1 1 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 1
0 1 0 1
0 0 0 0
0 0 0 0

Output: YES

Input:
0 0 0 1
0 0 0 1
0 0 0 0
0 1 0 0

Output: YES

Input:
0 0 0 1
0 0 0 1
1 0 0 0
0 0 0 0

Output: YES


The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of figures. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 3$$$, $$$a_i \ne a_{i + 1}$$$) — types of the figures.

import java.util.Scanner;
public class InscribedFigures {

	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		int n=sc.nextInt();
		int A[]=new int[n];
		for (int x=0;x<n;x++)
			A[x]=sc.nextInt();
		int s=0;
		int d=0;
		for (int x=0;x<n-1;x++)
		{
			if (A[x]+A[x+1]==5)
			{
				s=-1;
				break;

			}
			else if(A[x]+A[x+1]==3)
				s=s+3;
			else
				s=s+4;
		}
		for (int x=0;x<n-2;x++)
			if (A[x]==3&&A[x+1]==1&&A[x+2]==2)
				d=d+1;

		if (s==-1)
			System.out.println("Infinite");
		else
		{
			System.out.println("Finite");
			System.out.println(s-d);

		}

	}

}

NoteHere are the glorious pictures for the examples. Note that the triangle is not equilateral but just isosceles with the length of height equal to the length of base. Thus it fits into a square in a unique way.The distinct points where figures touch are marked red.In the second example the triangle and the square touch each other for the whole segment, it contains infinite number of points.

The first line should contain either the word "Infinite" if the number of distinct points where figures touch is infinite or "Finite" otherwise. If the number is finite than print it in the second line. It's guaranteed that the number fits into 32-bit integer type.

The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier.Future students will be asked just a single question. They are given a sequence of integer numbers $$$a_1, a_2, \dots, a_n$$$, each number is from $$$1$$$ to $$$3$$$ and $$$a_i \ne a_{i + 1}$$$ for each valid $$$i$$$. The $$$i$$$-th number represents a type of the $$$i$$$-th figure:  circle;  isosceles triangle with the length of height equal to the length of base;  square. The figures of the given sequence are placed somewhere on a Cartesian plane in such a way that:  $$$(i + 1)$$$-th figure is inscribed into the $$$i$$$-th one;  each triangle base is parallel to OX;  the triangle is oriented in such a way that the vertex opposite to its base is at the top;  each square sides are parallel to the axes;  for each $$$i$$$ from $$$2$$$ to $$$n$$$ figure $$$i$$$ has the maximum possible length of side for triangle and square and maximum radius for circle. Note that the construction is unique for some fixed position and size of just the first figure.The task is to calculate the number of distinct points (not necessarily with integer coordinates) where figures touch. The trick is, however, that the number is sometimes infinite. But that won't make the task difficult for you, will it?So can you pass the math test and enroll into Berland State University?

Input:
3
2 1 3

Output:
Finite
7

Output:
Finite
7

Input:
3
1 2 3

Output: Infinite

Input:
99
3 1 3 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 3 1 3 1 2 1 2

Output:
Finite
341

Output:
Finite
341

Input:
100
3 1 3 1 2 1 2 3 1 2 3 2 3 2 3 2 3 1 2 1 2 3 1 2 3 2 1 2 1 3 2 3 1 2 3 1 2 3 1 3 2 1 2 1 3 2 1 2 1 3 1 3 2 1 2 1 2 1 2 3 2 1 2 1 2 3 2 3 2 1 3 2 1 2 1 2 1 3 1 3 1 2 1 2 3 2 1 2 3 2 3 1 3 2 3 1 2 3 2 3

Output: Infinite

Input:
100
1 2 1 2 1 2 1 2 1 3 1 3 1 2 1 3 1 2 1 3 1 2 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 2 1 3 1 2 1 2

Output:
Finite
331

Output:
Finite
331

Input:
100
1 3 2 3 2 1 3 2 3 1 2 1 3 1 2 1 3 1 2 1 3 2 3 2 1 2 1 3 2 1 3 2 3 1 3 1 3 1 3 1 3 2 3 2 3 2 3 1 2 1 2 3 1 3 2 3 2 3 2 3 2 3 2 1 3 1 2 3 1 2 3 2 1 2 3 1 2 1 3 2 1 2 1 2 1 3 1 2 1 2 1 2 3 1 2 1 3 1 3 1

Output: Infinite

Input:
99
1 2 1 2 1 2 1 3 1 2 1 3 1 3 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 2 1 3 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 3 1

Output:
Finite
331

Output:
Finite
331

Input:
100
2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 3 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1 2 1 2 1 3 1 2 1 2 1 3 1 2 1 3 1 3 1 3 1 2 1 2 1 3 1 2 1 2 1 2 1 3 1 3 1

Output:
Finite
329

Output:
Finite
329

Input:
2
3 2

Output: Infinite

Input:
3
3 1 2

Output:
Finite
6

Output:
Finite
6

Input:
11
3 1 2 1 3 1 2 1 3 1 2

Output:
Finite
32

Output:
Finite
32

Input:
2
3 1

Output:
Finite
4

Output:
Finite
4

Input:
4
1 3 1 2

Output:
Finite
10

Output:
Finite
10

Input:
4
3 1 2 3

Output: Infinite

Input:
8
3 1 2 1 3 1 2 1

Output:
Finite
22

Output:
Finite
22

Input:
8
3 1 2 1 3 1 3 1

Output:
Finite
25

Output:
Finite
25

Input:
2
1 2

Output:
Finite
3

Output:
Finite
3

Input:
4
3 1 2 1

Output:
Finite
9

Output:
Finite
9

Input:
16
3 1 2 1 3 1 2 1 2 1 3 1 3 1 2 1

Output:
Finite
49

Output:
Finite
49

Input:
5
3 1 2 1 2

Output:
Finite
12

Output:
Finite
12

Input:
4
2 3 1 2

Output: Infinite

Input:
3
1 3 2

Output: Infinite

Input:
4
3 1 3 2

Output: Infinite

Input:
2
2 3

Output: Infinite

Input:
3
2 3 1

Output: Infinite

Input:
2
2 1

Output:
Finite
3

Output:
Finite
3

Input:
3
1 2 1

Output:
Finite
6

Output:
Finite
6

Input:
5
2 1 3 1 2

Output:
Finite
13

Output:
Finite
13

Input:
15
2 1 2 1 2 1 2 1 2 1 2 1 2 1 2

Output:
Finite
42

Output:
Finite
42

Input:
15
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1

Output:
Finite
42

Output:
Finite
42


Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).

import java.util.Arrays;
import java.util.Scanner;
import java.util.function.Function;

public class CF287D {

    public static long modPower(long base, long exponent, long mod) {
        long result = 1;
        while (exponent > 0) {
            if ((exponent & 1) != 0)
                result = (result * base) % mod;
            base = (base * base) % mod;
            exponent >>= 1;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        long m = in.nextLong();
        long[] dp = new long[k];
        dp[0] = 1;
        long total = 0;
        for (int i = 0; i < n; i++) {
            long[] next = new long[k];
            for (int j = 0; j < k; j++)
                for (int d = (i == n - 1) ? 1 : 0; d < 10; d++) {
                    int res = (int) (modPower(10, i, k) * d + j) % k;
                    next[res] = (next[res] + dp[j]) % m;
                }
            if (i < n - 1)
                total += (next[0] + m - 1) * 9 % m * modPower(10, n - 2 - i, m)
                        % m;
            else
                total += next[0];

            total %= m;
            dp = next;
            dp[0] = 1;
        }
        System.out.println(total);
    }
}

NoteA suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.

Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:  Decimal representation of x (without leading zeroes) consists of exactly n digits;  There exists some integer y > 0 such that:   ;  decimal representation of y is a suffix of decimal representation of x.  As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.Can you help Amr escape this embarrassing situation?

Input: 1 2 1000

Output: 4

Input: 2 2 1000

Output: 45

Input: 5 3 1103

Output: 590

Input: 2 17 10000

Output: 5

Input: 3 9 10000

Output: 252

Input: 6 64 941761822

Output: 46530

Input: 183 3 46847167

Output: 29891566

Input: 472 44 364550669

Output: 122479316

Input: 510 76 811693420

Output: 546301720

Input: 783 30 602209107

Output: 279682329

Input: 863 47 840397713

Output: 433465398

Input: 422 22 411212542

Output: 63862621

Input: 370 9 385481464

Output: 163845824

Input: 312 41 915197716

Output: 912219984

Input: 261 32 49719977

Output: 19320923

Input: 434 6 56571287

Output: 56257936

Input: 355 3 945669623

Output: 219132384

Input: 905 71 999142682

Output: 825882209

Input: 900 84 526417573

Output: 281234824

Input: 387 3 521021345

Output: 435545521

Input: 246 33 996704992

Output: 385601286

Input: 443 29 106807555

Output: 7872021

Input: 621 43 356382217

Output: 251594310

Input: 782 84 643445347

Output: 208138038

Input: 791 23 94030462

Output: 41862326

Input: 543 98 508536403

Output: 117587951

Input: 20 96 238661639

Output: 198761428

Input: 845 60 888437864

Output: 193926448

Input: 998 85 501663165

Output: 145180249

Input: 123 72 56222855

Output: 32350599

Input: 12 39 618421525

Output: 115875938

Input: 462 35 144751085

Output: 79931198

Input: 674 22 494819681

Output: 19590614

Input: 650 66 579060528

Output: 224930740

Input: 432 80 133016247

Output: 25032672

Input: 176 70 196445230

Output: 64904804

Input: 393 71 933802677

Output: 366541352

Input: 37 92 9838905

Output: 7980021

Input: 993 26 108974437

Output: 87469631

Input: 433 93 36915724

Output: 20722839

Input: 957 88 512982771

Output: 161742313

Input: 170 94 82742818

Output: 1117330

Input: 624 33 145653575

Output: 99048377

Input: 56 48 961996131

Output: 199203510

Input: 889 6 225765429

Output: 193135878

Input: 1 93 727895661

Output: 0

Input: 470 61 617307737

Output: 428782123

Input: 520 94 712232167

Output: 199435818

Input: 531 78 460047919

Output: 117748792

Input: 776 32 523607700

Output: 309970800

Input: 648 74 329538445

Output: 177655063

Input: 885 6 743810885

Output: 297512873

Input: 712 53 592302770

Output: 147693148

Input: 426 72 589297447

Output: 316207784

Input: 561 69 310141994

Output: 245538618

Input: 604 97 26180786

Output: 6950800

Input: 586 32 846994504

Output: 579729448

Input: 514 67 260591607

Output: 88291586

Input: 429 45 103817253

Output: 41335161

Input: 767 27 364988776

Output: 259490746

Input: 497 33 479662107

Output: 84548778

Input: 262 71 404639692

Output: 93447345

Input: 125 33 152527721

Output: 59122415

Input: 857 98 70814341

Output: 58423075

Input: 375 79 416634034

Output: 175150318

Input: 886 10 902171654

Output: 134375492

Input: 335 28 979397289

Output: 675105408

Input: 769 30 474381420

Output: 157049322

Input: 736 31 26855044

Output: 24225276

Input: 891 7 814335325

Output: 611862019

Input: 346 23 947672082

Output: 59151110

Input: 1000 1 382210711

Output: 372462157

Input: 1 1 10000

Output: 9

Input: 1000 100 777767777

Output: 577920877

Input: 1000 13 10619863

Output: 8796170

Input: 1 100 1000

Output: 0

Input: 11 11 11

Output: 7

Input: 1 1 1

Output: 0

Input: 1 2 2

Output: 0