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

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int[] A=new int[N];
	    boolean f=true;
	    for(int i=0; i<N;i++) {
	    	A[i]=gi();
	    	if(A[i]%2==0 && A[i]%3!=0 && A[i]%5!=0)f=false;
	    }

       // System.out.print(sb.toString());

        if (f) {
    	    System.out.print("APPROVED");
        }else{
        	 System.out.print("DENIED");
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Score: 200 points

Problem Statement

You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.

According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:

All even numbers written on the document are divisible by 3 or 5.

If the immigrant should be allowed entry according to the regulation, output APPROVED; otherwise, print DENIED.

Notes

The condition in the statement can be rephrased as "If x is an even number written on the document, x is divisible by 3 or 5".
Here "if" and "or" are logical terms.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

If the immigrant should be allowed entry according to the regulation, print APPROVED; otherwise, print DENIED.

Sample Input 1

5
6 7 9 10 31

Sample Output 1

APPROVED

The even numbers written on the document are 6 and 10.

All of them are divisible by 3 or 5, so the immigrant should be allowed entry.

Sample Input 2

3
28 27 24

Sample Output 2

DENIED

28 violates the condition, so the immigrant should not be allowed entry.


import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		boolean aa = false;
		for(int i=0; i<N; i++) {
			int a = Integer.parseInt(sc.next());
			if(a % 2 == 0) {
				if(a % 3 == 0 || a% 5==0) {
					aa = true;
				} else {
					aa = false;
					break;
				}
			}
		}
		System.out.println(aa ? "APPROVED": "DENIED");

	}
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


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

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

        int n = in.nextInt();
    boolean flag = true;
        while(n > 0){
            int item = in.nextInt();

            if(item%2 == 0 ){       //even
                if(item%3 == 0 || item%5 ==0 ){
                    flag = true;
                }else{
                    flag = false;
                    break;
                }
            }

            n--;

        }
        if(flag)
            out.println("APPROVED");
        else out.println("DENIED");
        //int n = in.nextInt();

        out.close();
    }

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

    }
}


import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s[] = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        sc.close();

        Map<String, Integer> hm = new HashMap<>();
        for (String string : s) {
            if (hm.containsKey(string)) {
                hm.put(string, hm.get(string) + 1);
            } else {
                hm.put(string, 1);
            }
        }
        int max = 0;
        for (Integer v : hm.values()) {
            if (max < v)
                max = v;
        }
        final int fmax = max;
        List<String> t = hm.entrySet().stream().filter(e -> e.getValue() == fmax).map(e -> e.getKey()).sorted()
                .collect(Collectors.toList());
        for (String w : t) {
            System.out.println(w);
        }
    }
}

Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

1 \leq N \leq 2 \times 10^5

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int [] in = new int [a];
        String [] str = new String [a];
        for(int i=0;i<a;i++){str[i] = sc.next();
                            }
        Arrays.sort(str);
        int b = 0;
        int c = 0;
        for(int i=0;i<a;i++){if(i>=1 && str[i].equals(str[i-1])){in[b]++;if(in[b]>c){c = in[b];}

                                                                }else{b=i;in[i]++;}
                            }
        for(int i=0;i<a;i++){if(in[i]==c){System.out.println(str[i]);}
                              }

	}
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        Run run = new Run();
        new Thread(null, run, "Solver", 1l << 28).start();
        //run.run();
    }

    static class Run implements Runnable {
        @Override
        public void run() {
            try {
                new Solver().solve();
                System.exit(0);
            } catch (Error | Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }
}

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;

    final Timer timer;
    final TimerTask task;

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);

        timer = new Timer();
        task = new TimerTask() {
            @Override
            public void run() {
                try {
                    hp.flush();
                    System.exit(0);
                } catch (Exception e) {
                }
            }
        };
        //timer.schedule(task, 4700);
    }

    int N, M;
    int[] X, Y;

    void solve() throws Exception {
        int i, j, k;
        boolean testCases = false;

        int tc = testCases ? hp.nextInt() : 1;
        for (int tce = 1; tce <= tc; tce++) {
            int N = hp.next().length();
            for (i = 0; i < N; ++i) hp.print("x");
        }

        timer.cancel();
        hp.flush();
    }

}

class Helper {
    final long MOD;
    final int MAXN;
    final Random rnd;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
        rnd = new Random();
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFactorial(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
    }

    public String[] getStringArray(int size) throws Exception {
        String[] ar = new String[size];
        for (int i = 0; i < size; ++i) ar[i] = next();
        return ar;
    }

    public String joinElements(long... ar) {
        StringBuilder sb = new StringBuilder();
        for (long itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(int... ar) {
        StringBuilder sb = new StringBuilder();
        for (int itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(String... ar) {
        StringBuilder sb = new StringBuilder();
        for (String itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(Object... ar) {
        StringBuilder sb = new StringBuilder();
        for (Object itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long... ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int... ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long... ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int... ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long... ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int... ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public void shuffle(int[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public void shuffle(long[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public void reverse(int[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = ar.length - 1 - i;
            if (r > i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public void reverse(long[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = ar.length - 1 - i;
            if (r > i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static final int BUFSIZE = 1 << 20;
    static byte[] buf;
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
            buf = new byte[BUFSIZE];
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
            buf = new byte[BUFSIZE];
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}

Score : 200 points

Problem Statement

Given is a string S. Replace every character in S with x and print the result.

Constraints

S is a string consisting of lowercase English letters.

The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

Replace every character in S with x and print the result.

Sample Input 1

sardine

Sample Output 1

xxxxxxx

Replacing every character in S with x results in xxxxxxx.

Sample Input 2

xxxx

Sample Output 2

xxxx

Sample Input 3

gone

Sample Output 3

xxxx


Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300


import java.util.Scanner;

class Solver {
    public void Solve() {
        String s = sc.next();
        int k = sc.nextInt();
        long len = s.length();
        int first = Integer.parseInt(s.substring(0, 1));
        long ans = 0;
        if (k == 1) {
            ans = solve1(len, s);
        } else if (k == 2) {
            ans = solve2(len, s);
        } else {
            ans = solve3(len, s);
        }
        System.out.println(ans);
        int a = 0;

    }

    public long solve1(long len, String s) {
        // System.out.println(s);
        while (true) {
            if (s.length() == 0) {
                return 0;
            }
            if (s.charAt(0) != '0') {
                break;
            } else {
                s = s.substring(1);
            }
        }
        len = s.length();
        int first = Integer.parseInt(s.substring(0, 1));
        long ans = 0;
        ans += (len - 1) * 9;
        ans += first;
        // System.out.println(ans);
        return ans;
    }

    public long solve2(long len, String s) {
        // System.out.println(s);
        while (true) {
            if (s.length() <= 1) {
                return 0;
            }
            if (s.charAt(0) != '0') {
                break;
            } else {
                s = s.substring(1);
            }
        }
        len = s.length();
        int first = Integer.parseInt(s.substring(0, 1));
        long ans = 0;
        ans += (len - 1) * (len - 2) / 2 * 9 * 9;
        ans += (first - 1) * (len - 1) * 9;
        ans += solve1(len, s.substring(1));
        // System.out.println(ans);
        return ans;
    }

    public long solve3(long len, String s) {
        // System.out.println(s);
        while (true) {
            if (s.length() < 3) {
                return 0;
            }
            if (s.charAt(0) != '0') {
                break;
            } else {
                s = s.substring(1);
            }
        }
        long ans = 0;
        int first = Integer.parseInt(s.substring(0, 1));
        ans += (len - 1) * (len - 2) * (len - 3) / 2 * 3 * 9 * 9;
        ans += (first - 1) * (len - 1) * (len - 2) / 2 * 9 * 9;
        ans += solve2(len, s.substring(1));
        // System.out.println(ans);
        return ans;
        // int next = Integer.parseInt(s.substring(1, 2));
        // if (len == 3) {
        // ans += (first - 1) * 9 * 9;
        // ans += next * 9;
        // System.out.println(ans);
        // return 0;
        // }
        // // 先頭使わない
        // ans += (len - 1) * (len - 2) * (len - 3) / 2 * 3 * 9 * 9;
        // // 先頭使う 最大ではない
        // ans += (first - 1) * (len - 1) * (len - 2) / 2 * 9 * 9;
        // if (next != 0) {
        // // 先頭最大値 2番目最大でない
        // ans += (next - 1) * (len - 2) * 9;
        // }
        // ans += (len - 2) * (len - 3) / 2 * 9 * 9;
        // // ans += (len - 3) * 9;
        // for (int i = 2; i < len; i++) {
        // int a = Integer.parseInt(s.substring(i, i + 1));
        // if (a == 0) {
        // continue;
        // } else {
        // ans += a;
        // ans += (len - 1 - i) * 9;
        // break;
        // }
        // }
        // // 先頭最大 2番目も最大
        // // ans += (third - 1) * (len - 3) * 9;
        // System.out.println(ans);
        // return ans;
    }

    Scanner sc;

    Solver(Scanner in) {
        this.sc = in;
    }
}

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


import java.util.Scanner;

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

		int h = sc.nextInt();
		int a = sc.nextInt();

		if ((h % a) != 0) {
			System.out.println((h / a) + 1);
		} else {
			System.out.println((h / a));
		}

		sc.close();
	}
}

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

In one attack, Serval can decrease the monster's health by A.
There is no other way to decrease the monster's health.

Serval wins when the monster's health becomes 0 or below.

Find the number of attacks Serval needs to make before winning.

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

Print the number of attacks Serval needs to make before winning.

Sample Input 1

10 4

Sample Output 1

3

After one attack, the monster's health will be 6.

After two attacks, the monster's health will be 2.

After three attacks, the monster's health will be -2.

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();

        if(h % a == 0) {
            System.out.println(h / a);
        }else {
            System.out.println(h / a + 1);
        }

    }
}


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

    		Scanner sc = new Scanner(System.in);

    		  int a = sc.nextInt();
    		  int b = sc.nextInt();
    		   int c=(a/b)+1;

    	         System.out.println(c);

    	}
    }


import java.lang.reflect.Array;
import java.util.*;

public class Main {

    static int MOD = 1000000007;

    public static void main(String[] args) {

        //int ans=Integer.MAX_VALUE;
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt();
        int a =sc.nextInt();
        int ans;
        if(h%a==0)ans=h/a;
        else ans=h/a+1;

        System.out.println(ans);

    }

}


import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();

		int a = sc.nextInt();
		int n = h/a;
		if(n*a==h) {
			System.out.println(n);
		}else {
			System.out.println(n+1);

		}
	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		ArrayList<Long>hp=new ArrayList<>();

		//モンスターの数
		long N=sc.nextLong();
		//使える必殺技の回数
		long K=sc.nextLong();
		//フェネックの総攻撃回数
		long attackResult=0;

		//個々のモンスターの体力
		for(int i=0;i<N;i++) {
			hp.add(sc.nextLong());
		}

		if(N>K) {

			for(int i=0;i<K;i++) {
				hp.remove(Collections.max(hp));
			}
			for(long attack:hp) {
				attackResult+=attack;
			}

			System.out.println(attackResult);

		}else {
			System.out.println(0);
		}
	}

}

Score : 300 points

Problem Statement

Fennec is fighting with N monsters.

The health of the i-th monster is H_i.

Fennec can do the following two actions:

Attack: Fennec chooses one monster. That monster's health will decrease by 1.

Special Move: Fennec chooses one monster. That monster's health will become 0.

There is no way other than Attack and Special Move to decrease the monsters' health.

Fennec wins when all the monsters' healths become 0 or below.

Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq K \leq 2 \times 10^5

1 \leq H_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 ... H_N

Output

Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.

Sample Input 1

3 1
4 1 5

Sample Output 1

5

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.

Sample Input 2

8 9
7 9 3 2 3 8 4 6

Sample Output 2

0

She can use Special Move on all the monsters.

Sample Input 3

3 0
1000000000 1000000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}

		if (k >= n) {
			System.out.println(0);
		} else {
			long ans = 0;
			for (int i = 0; i < n - k; i++) {
				ans += a[i];
			}
			System.out.println(ans);
		}
	}
}


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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numMon = scanner.nextInt();
        int special = scanner.nextInt();
        int[] hps = new int[numMon];
        for(int i = 0; i < numMon; i++) {
            hps[i] = scanner.nextInt();
        }
        scanner.close();

        Arrays.sort(hps);
        int removeNum = Math.min(special, numMon);
        long remainSum = 0;
        for(int i = removeNum; i < numMon; i++) {
            remainSum += hps[i];
        }

        System.out.println(remainSum);
    }
}


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

  private static class Magic {

    int attackPoint;
    int cost;

    Magic(int attackPoint, int cost) {
      this.attackPoint = attackPoint;
      this.cost = cost;
    }
  }

  private static int minCost;
  private static List<Magic> magicsInAscendingOrderOfCost = new ArrayList<>();

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    int hitPoint = scanner.nextInt();
    final int numberOfMagic = scanner.nextInt();
    final List<Magic> magics = new ArrayList<>();

    minCost = Integer.MAX_VALUE;
    for (int i = 0; i < numberOfMagic; i++) {
      Magic magic = new Magic(scanner.nextInt(), scanner.nextInt());
      magics.add(magic);

      if (minCost > magic.cost) {
        minCost = magic.cost;
      }
    }
    magicsInAscendingOrderOfCost = magics.stream()
        .sorted(Comparator.comparingInt(magic -> magic.cost))
        .collect(Collectors.toList());

    System.out.println(getCost(hitPoint));
  }

  private static long getCost(int hitPoint) {
    final int attackPointOfMinCost = magicsInAscendingOrderOfCost.get(0).attackPoint;
    if (hitPoint <= attackPointOfMinCost) {
      return minCost;
    }

    long[] minCosts = new long[hitPoint + 1];
    for (int i = 0; i <= attackPointOfMinCost; i++) {
      minCosts[i] = minCost;
    }

    for (int currentHitPoint = attackPointOfMinCost + 1; currentHitPoint <= hitPoint;
        currentHitPoint++) {

      long minCostCandidate = Long.MAX_VALUE;
      for (Magic magic : magicsInAscendingOrderOfCost) {
        int remainingHitPoint = currentHitPoint - magic.attackPoint;

        long candidate =
            remainingHitPoint > 0 ? minCosts[remainingHitPoint] + magic.cost : magic.cost;

        if (candidate < minCostCandidate) {
          minCostCandidate = candidate;
        }
      }

      minCosts[currentHitPoint] = minCostCandidate;
    }

    return minCosts[hitPoint];
  }
}

Score : 500 points

Problem Statement

Ibis is fighting with a monster.

The health of the monster is H.

Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.

The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.

Ibis wins when the health of the monster becomes 0 or below.

Find the minimum total Magic Points that have to be consumed before winning.

Constraints

1 \leq H \leq 10^4

1 \leq N \leq 10^3

1 \leq A_i \leq 10^4

1 \leq B_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 B_1
:
A_N B_N

Output

Print the minimum total Magic Points that have to be consumed before winning.

Sample Input 1

9 3
8 3
4 2
2 1

Sample Output 1

4

First, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.

Then, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.

In this way, we can win at the total cost of 4 Magic Points.

Sample Input 2

100 6
1 1
2 3
3 9
4 27
5 81
6 243

Sample Output 2

100

It is optimal to cast the first spell 100 times.

Sample Input 3

9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461

Sample Output 3

139815


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        ArrayList<Pair> l = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            l.add(new Pair(a[i], b[i]));
        }
        Collections.sort(l);
        int dp[][] = new int[n][h + 20000];
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < h + 20000; j++) {
                dp[i][j] = 1000000000;
            }
        }

        int s = l.get(0).key;
        int v = l.get(0).value;
        for (int i = 0; i * s < h + 20000; i++) {
            dp[0][i * s] = v * i;
        }
        for (int i = 1; i < n; i++) {
            Pair newP = l.get(i);
            for (int j = 0; j < h + 20000; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j - newP.key < 0) {
                    continue;
                }
                if (dp[i - 1][j - newP.key] + newP.value < dp[i][j]) {
                    dp[i][j] = dp[i - 1][j - newP.key] + newP.value;
                } else {
                }
            }
        }
        int min = 1000000000;
        for (int i = h; i < h + 20000; i++) {
            min = Math.min(min, dp[n - 1][i]);
        }
        System.out.println(min);
        sc.close();

    }

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

}

class Pair implements Comparable<Pair> {
    // key , value 昇順ソート
    int key;
    int value;

    Pair(int key, int value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public int compareTo(Pair other) {
        if (this.key == other.key) {
            return this.value - other.value;
        }
        // return this.value - other.value;
        return this.key - other.key;
    }
}


import java.util.Scanner;

public class Main {
	//C問題

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n, m;
		String ans;
		n = scanner.nextInt();
		m = scanner.nextInt();

		//橋君の提出が AC となる場合は Yes, そうでない場合は No と出力せよ。

		if (n == m) {
			ans = "Yes";
		} else {
			ans = "No";
		}

		System.out.println(ans);
	}

}

Score : 100 points

Problem Statement

Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.

The problem has N test cases, all of which must be passed to get an AC verdict.

Takahashi's submission has passed M cases out of the N test cases.

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

If Takahashi's submission gets an AC, print Yes; otherwise, print No.

Sample Input 1

3 3

Sample Output 1

Yes

All three test cases have been passed, so his submission gets an AC.

Sample Input 2

3 2

Sample Output 2

No

Only two out of the three test cases have been passed, so his submission does not get an AC.

Sample Input 3

1 1

Sample Output 3

Yes


import java.util.Scanner;

public class Main {

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

        String[] substr = str.split(" ", 0);

        //System.out.println(str);
        //System.out.println(substr[0]);
        //System.out.println(substr[1]);
        int a = Integer.parseInt(substr[0]);
        int b = Integer.parseInt(substr[1]);
        if (a == b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        scan.close();
    }

}


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

public class Main {
	public static void main(String args[]) throws IOException {
		// 2020/1/30 No.152
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		if (n == m )
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


import java.util.Scanner;

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

    if(N==M){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


import java.util.*;

public class Main {

    static int MOD = 1000000007;
    public static void main(String[] args) {

        int ans=0;
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();

        int[] p = new int[n];
        HashSet<Integer> ff = new HashSet<>();

        for(int i=0;i<n;i++)p[i]=sc.nextInt();

        for(int i=0;i<n;i++){
            boolean ok=true;

            for(int j=0;j<i;j++){
                if(p[i]<p[i-1]&&ff.contains(i))break;
                if(p[i]>p[j]){
                    ok=false;
                    break;
                }

            }
            if(ok){
                ans++;
                ff.add(i);
            }
        }

        System.out.println(ans);

    }

}

Score : 300 points

Problem Statement

Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:

For any integer j (1 \leq j \leq i), P_i \leq P_j.

Constraints

1 \leq N \leq 2 \times 10^5

P_1, \ldots, P_N is a permutation of 1, \ldots, N.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.

Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

Sample Input 2

4
4 3 2 1

Sample Output 2

4

All integers i (1 \leq i \leq N) satisfy the condition.

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1


import java.util.*;
public class Main {
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int o=0;
       int n=sc.nextInt();
      int mini=2000000;
      for(int i=0;i<n;i++){
      	int p=sc.nextInt();
        if(p<=mini){
        	o++;
            mini=p;
        }
      }
      System.out.println(o);
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;

		for (int i = 1; i < n; i++) {
			for (int j = 1; j < n; j++) {
				if(checkNum(i,j)) {
					count++;
				}
			}
		}

		System.out.println(count);

	}

	private static boolean checkNum(int i, int j) {
		String a = String.valueOf(i);
		String b = String.valueOf(j);

		if(a.charAt(0) == b.charAt(b.length()-1) && a.charAt(a.length()-1) == b.charAt(0)) {
			return true;
		}
		return false;
	}
 }

Score : 400 points

Problem Statement

Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:

When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Constraints

1 \leq N \leq 2 \times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

25

Sample Output 1

17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Sample Input 2

1

Sample Output 2

1

Sample Input 3

100

Sample Output 3

108

Sample Input 4

2020

Sample Output 4

40812

Sample Input 5

200000

Sample Output 5

400000008


import java.util.Scanner;

public class Main {

    private static int f(int i, int j, int n) {
        int r = 0;
        for (int k = 1; k <= n; k++) {
            String s = Integer.toString(k);
            if (Integer.parseInt(s.substring(0, 1)) == i && Integer.parseInt(s.substring(s.length() - 1)) == j)
                r++;
        }
        return r;
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int n = Integer.parseInt(scanner.next());
            int r = 0;
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    r += f(i, j, n) * f(j, i, n);
                }
            }
            System.out.println(r);
        }
    }

}


import java.util.*;

public class Main{

    public static final int MOD = (int)1e9+7;

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

        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        ModLcm ml = new ModLcm((int)1e6+6);

        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
            ml.lcm(a[i]);
        }

        int lcm = ml.getModLcm(MOD);
        //System.out.println(lcm);

        long ans = 0;
        for(int i=0; i<n; i++){
            long inv = ModLcm.mod_pow(a[i], MOD-2, MOD);
            ans += lcm * inv;
            ans %= MOD;
        }

        System.out.println(ans);

    }

}

class ModLcm{
    private int max;
    private int[] exponent;

    public ModLcm(int max){
        this.max = max;
        exponent = new int[max];
    }

    public void lcm(int n){
        while(n%2==0){
            int ex = 0;
            while(n%2==0){
                ex++;
                n /= 2;
            }
            exponent[2] = Math.max(exponent[2], ex);
        }
        for(int i=3; i*i<=n; i+=2){
            int ex = 0;
            while(n%i==0){
                ex++;
                n /= i;
            }
            exponent[i] = Math.max(exponent[i], ex);
        }
        if(n!=1){
            exponent[n] = Math.max(1, exponent[n]);
        }
    }

    public static long mod_pow(long x, long p, long m){
        long a = 1;
        while(p>0){
            if(p%2==1){
                a = a*x%m;
            }
            x = x*x%m;
            p /= 2;
        }
        return a;
    }

    public int getModLcm(int mod){
        long res = 1;
        for(int i=0; i<max; i++){
            if(exponent[i]==0){
                continue;
            }
            res *= mod_pow(i, exponent[i], mod);
            res %= mod;
        }
        return (int)res;
    }
}

Score : 500 points

Problem Statement

Given are N positive integers A_1,...,A_N.

Consider positive integers B_1, ..., B_N that satisfy the following condition.

Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.

Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.

Since the answer can be enormous, print the sum modulo (10^9 +7).

Constraints

1 \leq N \leq 10^4

1 \leq A_i \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).

Sample Input 1

3
2 3 4

Sample Output 1

13

Let B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.

Sample Input 2

5
12 12 12 12 12

Sample Output 2

5

We can let all B_i be 1.

Sample Input 3

3
1000000 999999 999998

Sample Output 3

996989508

Print the sum modulo (10^9+7).