import numpy as np
N=int(input())
x=list(map(int,input().split()))
m=int(round(np.mean(x),0))
x_mean=[(y-m)**2 for y in x]
print(sum(x_mean))

Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354


import math
import numpy as np

N = int(input())
x = list(map(int,input().split()))
A2 = max(x); A1 = min(x)
k = 0; Solve = np.zeros(A2-A1);
for A in range(A1,A2):
  B=0
  for i in range(0,N):
    B = (x[i]-A)**2 + B
  Solve[k] = B
  k += 1
print(int(min(Solve)))

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.


n=int(input())
x=[int(i) for i in input().split(" ")]
x=sorted(x)
mind=-1
for i in range(x[0],x[len(x)-1]+1):
    sum=0
    for j in x:
        sum+=(j-i)**2
    if mind>sum or mind==-1:
        mind=sum

print(mind)


from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

def lcm(n, m):
    return int(n * m / gcd(n, m))

def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x

p = 10**9+7

def cmb(n, r):
    temp1 = 1
    temp2 = 1
    for i in range(n-r+1, n+1):
        temp1 *= i
        temp1 %= p
    for i in range(1, r+1):
        temp2 *= i
        temp2 %= p
    return temp1 * pow(temp2,p-2,p) % p

def main():
    n, a, b = map(int, input().strip().split())
    # eprint('pow(2,n,p) - cmb(n, a) - cmb(n, b) - 1 ',end=':\n')
    # eprint(pow(2,n,p) - cmb(n, a) - cmb(n, b) - 1)

    # eprint('pow(2,n,p) ',end=':\n')
    # eprint(pow(2,n,p))
    # eprint('cmb(n,a) ',end=':\n')
    # eprint(cmb(n,a))
    # eprint('cmb(n,b) ',end=':\n')
    # eprint(cmb(n,b))

    # if pow(2,n,p) - cmb(n, a) - cmb(n, b) - 1<-1:
    #     print(pow(2,n,p) - cmb(n, a) - cmb(n, b) - 1 + p)
    # elif pow(2,n,p) - cmb(n, a) - cmb(n, b) - 1 == -1:
    #     print(0)
    # else:
    #     print(max( (pow(2,n,p) - cmb(n, a) - cmb(n, b) - 1) , 0 ))

    #
    eprint('pow(2,n,p) ',end=':\n')
    eprint(pow(2,n,p))

    #
    xxx = pow(2,n,p) - cmb(n, a) - cmb(n, b)
    if xxx<0:
        print(xxx-1+p)
    elif xxx == 0:
        print(0)
    else:
        print(xxx-1)

if __name__ == '__main__':
    main()

Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

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


n,a,b=map(int,input().split())
mod=10**9+7

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            result%=mod

    return result

allp=pow(2,n,mod)-1
ans=(allp-cmb(n,a)%mod-cmb(n,b)%mod+mod)%mod
if n==2:
    ans=0

print(ans)


MAX = 1000005
MOD = 10**9+7
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX

# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD

# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD

# 前処理完了
COMinit()

N, K = map(int, input().split())
ans = 0
for i in range(min(K, N)+1):  # 空にできるのはK部屋または、N-1部屋までのみ。
    ans += COM(N, i) * COM(N-1, i)
    ans %= MOD
print(ans)

Score : 500 points

Problem Statement

There is a building with n rooms, numbered 1 to n.

We can move from any room to any other room in the building.

Let us call the following event a move: a person in some room i goes to another room j~ (i \neq j).

Initially, there was one person in each room in the building.

After that, we know that there were exactly k moves happened up to now.

We are interested in the number of people in each of the n rooms now. How many combinations of numbers of people in the n rooms are possible?

Find the count modulo (10^9 + 7).

Constraints

All values in input are integers.

3 \leq n \leq 2 \times 10^5

2 \leq k \leq 10^9

Input

Input is given from Standard Input in the following format:

n k

Output

Print the number of possible combinations of numbers of people in the n rooms now, modulo (10^9 + 7).

Sample Input 1

3 2

Sample Output 1

10

Let c_1, c_2, and c_3 be the number of people in Room 1, 2, and 3 now, respectively. There are 10 possible combination of (c_1, c_2, c_3):

(0, 0, 3)

(0, 1, 2)

(0, 2, 1)

(0, 3, 0)

(1, 0, 2)

(1, 1, 1)

(1, 2, 0)

(2, 0, 1)

(2, 1, 0)

(3, 0, 0)

For example, (c_1, c_2, c_3) will be (0, 1, 2) if the person in Room 1 goes to Room 2 and then one of the persons in Room 2 goes to Room 3.

Sample Input 2

200000 1000000000

Sample Output 2

607923868

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

Sample Input 3

15 6

Sample Output 3

22583772


a=list(input().split())

if len(set(a))==2:
    print("Yes")
else:
    print("No")

Score: 100 points

Problem Statement

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.

Constraints

A, B, and C are all integers between 1 and 9 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C

Output

If the given triple is poor, print Yes; otherwise, print No.

Sample Input 1

5 7 5

Sample Output 1

Yes

A and C are equal, but B is different from those two numbers, so this triple is poor.

Sample Input 2

4 4 4

Sample Output 2

No

A, B, and C are all equal, so this triple is not poor.

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes


n = list(map(int,input().split()))
if len(set(n)) == 2:
  print('Yes')
else:
  print('No')


a,b,c = map(int, input().split())
if a == b == c:
    print('No')
elif a == b or b == c or c == a:
    print('Yes')
else:
    print('No')


a, b, c = map(int, input().split())

if a == b and b != c:
    print("Yes")
elif a != b and b == c:
    print("Yes")
elif a == c and a != b:
    print("Yes")
else:
    print("No")


a,b,c = map(int,input().split())

if len(set([a,b,c])) == 2:
    print("Yes")
else:
    print("No")


N = int(input())

a = [0]*N
a = list(map(int, input().split()))
for i in range(N):

  if a[i]%2 == 0:
    if a[i]%3 != 0 and a[i]%5 != 0:
      print('DENIED')
      break
  if i == N-1:
    print('APPROVE')

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.


n=int(input())
b = ''
for i in range(n):
    b += (input() + ' ')
a = list(b.split())
a_count = [a.count(i) for i in a]
print('\n'.join(sorted(set([a[i] for i in range(len(a_count)) if a_count[i] == max(a_count)]))))

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


N = int(input())
str = {}
for i in range(N):
    key = input()
    if(key in str.keys()):
        str[key] += 1
    else:
        str[key] = 1
m = max(str.values())
str = sorted(str.items(),key=lambda x:x[1],reverse=True)
z = []
for i in range(len(str)):
    if(str[i][1] == m):
        z.append(str[i][0])
z.sort()
for i in z:print(i)


import collections

N=int(input())
data=[input() for i in range(N)]
c = collections.Counter(data)
score=c
com=c.most_common()

score_sorted = sorted(score.items(), key=lambda x:x[1], reverse=True)

val=score_sorted

count="Yes"
ii=0
ansa=1
while count=="Yes":
    if val[ii][1]==val[ii+1][1]:
        ii+=1
        ansa+=1
    else:
        count="No"
data2=[]
for i in range(ansa):
    data2.append(val[i][0])

data2.sort()
for i in range(ansa):
    print(data2[i])


from collections import defaultdict
N = int(input())
S = defaultdict(int)
S2 = []
max = 0
for _ in range(N):
    s = input()
    S[s] += 1
    if max < S[s]:
        max = S[s]
for k, v in sorted(S.items(), key=lambda x: -x[1]):
    if max == v:
        S2.append(k)
    else:
        break
for s in sorted(S2):
    print(s)


from itertools import groupby

def fivefunction(num):
    if num>=5:
        return 1
    else:
        return 0

N=input()
A=[int(N[i]) for i in range(0,len(N))]
fiveonlyzone=0
for i in range(0,len(N)):
    if i==0:
        if A[i]==5 and A[i+1]<5:
            fiveonlyzone+=1
    elif i==len(N)-1:
        if A[i-1]<5 and A[i]==5:
            fiveonlyzone+=1
    else:
        if A[i-1]<5 and A[i]==5 and A[i+1]<5:
            fiveonlyzone+=1

Ndigitsum=sum(A)
data=[fivefunction(A[i]) for i in range(0,len(N))]
Adigitsum=0
for i in range(0,len(N)):
    if fivefunction(A[i])==0:
        Adigitsum+=A[i]
X=groupby(data)
zone=0
digit=0
for key,group in X:
    g=len(list(group))
    if key==1:
        zone+=1
        digit+=g
print(9*digit+2*zone+2*Adigitsum-Ndigitsum-fiveonlyzone)

Score: 500 points

Problem Statement

In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. (Takoyaki is the name of a Japanese snack.)

To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N.

What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?

Assume that you have sufficient numbers of banknotes, and so does the clerk.

Constraints

N is an integer between 1 and 10^{1,000,000} (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum possible number of total banknotes used by you and the clerk.

Sample Input 1

36

Sample Output 1

8

If you give four banknotes of value 10 each, and the clerk gives you back four banknotes of value 1 each, a total of eight banknotes are used.

The payment cannot be made with less than eight banknotes in total, so the answer is 8.

Sample Input 2

91

Sample Output 2

3

If you give two banknotes of value 100, 1, and the clerk gives you back one banknote of value 10, a total of three banknotes are used.

Sample Input 3

314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170

Sample Output 3

243


s, t = list(input().split())
a, b = list(map(int, input().split()))
u = input()
if u==s:
	a-=1
elif u==t:
	b-=1
print(a,b)

Score : 100 points

Problem Statement

We have A balls with the string S written on each of them and B balls with the string T written on each of them.

From these balls, Takahashi chooses one with the string U written on it and throws it away.

Find the number of balls with the string S and balls with the string T that we have now.

Constraints

S, T, and U are strings consisting of lowercase English letters.

The lengths of S and T are each between 1 and 10 (inclusive).

S \not= T

S=U or T=U.

1 \leq A,B \leq 10

A and B are integers.

Input

Input is given from Standard Input in the following format:

S T
A B
U

Output

Print the answer, with space in between.

Sample Input 1

red blue
3 4
red

Sample Output 1

2 4

Takahashi chose a ball with red written on it and threw it away.
Now we have two balls with the string S and four balls with the string T.

Sample Input 2

red blue
5 5
blue

Sample Output 2

5 4

Takahashi chose a ball with blue written on it and threw it away.
Now we have five balls with the string S and four balls with the string T.


S,T=input().split()
A,B=map(int,input().split())
U=input()
print(A-1,B) if U==S else print(A,B-1)


s,t=input().split()
a,b=map(int,input().split())
u=input()
if s==u:
    print(a-1,b)
else:
    print(a,b-1)


a=list(map(str,input().split()))
b=list(map(int,input().split()))
b[a.index(input())]-=1
print(*b)


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


n = int(input())
print(['NO','YES'][len(set(list(map(int, input().split()))))==n])

Score : 300 points

Problem Statement

Given is a sequence of integers A_1, A_2, ..., A_N.
If its elements are pairwise distinct, print YES; otherwise, print NO.

Constraints

2 ≤ N ≤ 200000

1 ≤ A_i ≤ 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

Sample Input 1

5
2 6 1 4 5

Sample Output 1

YES

The elements are pairwise distinct.

Sample Input 2

6
4 1 3 1 6 2

Sample Output 2

NO

The second and fourth elements are identical.

Sample Input 3

2
10000000 10000000

Sample Output 3

NO


from itertools import accumulate
N, K = map(int, input().split())
P = [0]+list(map(int, input().split()))
Psum = list(accumulate(P))
total = 0
for i in range(K, N+1):
    if Psum[i]-Psum[i-K] > total:
        total = Psum[i]-Psum[i-K]
        index = i
ans = 0
for i in range(index, index-K, -1):
    ans += (P[i]+1)*0.5

print(ans)

Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000


N,K = map(int,input().split())
ruiseki = [0]*(N+1)
now = 0
maximum = -999999999
ans = 0
p = list(map(int,input().split()))
for i in range(N):
    now += p[i]
    ruiseki[i+1] = now
for i in range(0,N-K+1):
    P = ruiseki[i+K]-ruiseki[i]
    if P > maximum:
        maximum = P
        Q = p[i:i+K]
for i in range(len(Q)):
    ans += (0.5*Q[i]*(Q[i]+1))/Q[i]
print(ans)


N,K=map(int,input().split(" "))
p_list=list(map(int,input().split(" ")))
def expect(i):
    return 0.5*(p_list[i]+1)

e_list=[expect(i) for i in range(N)]

expect_list=[sum(e_list[i:K+i]) for i in range(0,N-K+1+1)]

print(max(expect_list))


import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int k = nextInt();
    double[] p = new double[n];
    for(int i=0;i<n;i++){
      p[i] = nextDouble();
    }

    double[] eachK = new double[n-k+1];

    double Sum = 0;

    for(int i=0;i<k;i++){
      Sum += (1+p[i])/2;
    }

    double max = Sum;

    for(int i=1;i<n-k+1;i++){
      Sum -= (1+p[i-1])/2;
      Sum += (1+p[i+k-1])/2;
      max = Math.max(max,Sum);
    }

    System.out.println(max);

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

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

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

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


n, k = map(int, input().split())
ps = list(map(int, input().split()))

maxs = [0]
# print(ps)
for i in range(n-k + 1):

    vs = ps[i:i+k]
    # print(i, vs)
    if sum(vs) > sum(maxs):
        maxs = vs

result = 0
for m in maxs:
    result += (m + 1)/2
print(result)


n,k = map(int,input().split())
l = list(map(int,input().split()))
ans = 0
tmp = sum(l[:k])
for i in range(k,n):
  tmp += l[i]-l[i-k]
  ans = max(ans, tmp)
print((ans+k)/2)


n, k = (int(i) for i in input().split())
p = [int(i) for i in input().split()]

for i in range(n):
    p[i] = (p[i]+1) / 2
_max = -1
for i in range(n-k+1):
    _sum = 0
    for j in range(k):
        _sum += p[i+j]
    _max = max(_sum, _max)

print(_max)


s = input()
l = len(s)
K = int(input())
def com(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child = child * (x-i)
        mother = mother * (i+1)
    if x == 1 and y >=2:
        return 0
    else:
        return int(child / mother)
tasumae = (9**K)*com(l-1,K) #与えられた数字よりも一桁少ない999999999・・・までの個数
li = list(s)
doko = []
if l < K:
    print(0)
    exit()
if K == 1:
    print(tasumae+int(li[0]))
    exit()
for i in range(1,l):
    if li[i] != "0":
        doko.append(i)
if K == 2:
    if not doko:
        print(tasumae)
        exit()
    ans = int(li[doko[0]]) + 9*(l-1-doko[0]) + tasumae + (int(li[0])-1)*com(l-1,1)*9
    print(ans)
    exit()
if len(doko) <= 1:
    print(tasumae)
    exit()
ans = (int(li[0])-1)*com(l-1,2)*(9**2) + (int(li[doko[0]])-1) * 9 * (l-1-doko[0]) + int(li[doko[1]]) + 9*(l-1-doko[1]) + com(l-1-doko[0],2)*(9**2) + tasumae
print(ans)

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 sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = [int(i) for i in STR()]
k = INT()
l = len(n)
dp = [[[0, 0] for _ in range(l)] for _ in range(k + 1)] #dp[i個の0以外][j桁目まで][0:未満 1:未決定]
dp[0][0][0] = 1 #0
dp[1][0][1] = 1 #n[0]
dp[1][0][0] = n[0] - 1 #1からn[0] - 1
for j in range(1, l):
    dp[0][j][0] = dp[0][j - 1][0] #全部0

    for i in range(1, k + 1):
        dp[i][j][0] += dp[i - 1][j - 1][0] * 9 #0以外i-1個に0以外を
        dp[i][j][0] += dp[i - 1][j - 1][1] * (n[j] - 1) if n[j] > 0 else 0 #0以外i個の未満未決定にn[j]未満の数を
        dp[i][j][0] += dp[i][j - 1][0] #0以外i個かつ未満に0を
        dp[i][j][0] += dp[i][j - 1][1] if n[j] > 0 else 0 #0以外i個かつ未満未決定に0を

        dp[i][j][1] += dp[i][j - 1][1] if n[j] == 0 else 0 #0以外i個の未満未決定にn[j]を
        dp[i][j][1] += dp[i - 1][j - 1][1] if n[j] > 0 else 0 #0以外i-1個の未満未決定にn[j]を
print(sum(dp[k][l - 1]))


n=input()
k=input()
sum=0
for i in range(1,k+1):
    a=list(str(i))
    if list.count(0)=k:
        sum+=1
print(sum)


def factorial(a):
    r = 1
    for i in range(a):
        r *= i+1
    return r

def combinations(a, b):
    if a>=0 and b>=0 and a >= b:
        return pow(9, b) * factorial(a) // factorial(b) // factorial(a-b)
    else:
        return 0

def count(m, a, b):
    # return the count of numbers in range [0, m x 10^a] with b non zero digitals
    ## the count of numbers in range [0, m x 10^a) with b non zero digitals
    r = combinations(a-1, b) + (m-1) * combinations(a-1, b-1)
    if b == 1:
        ## m x 10^a
        r += 1
    return r

N = int(input())
K = int(input())

digit = list(map(int, str(N)))
M = len(digit)

C = 0
for i in range(K):
    C += count(digit[i], M-i, K-i)

print(C)


import math
H,A=map(int, input().split())
print(math.ceil(H/A))

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


h,a = list(map(int,input().split()))
ans = 0
syou = h // a
mod = h % a
ans = syou
if(mod != 0):
    ans += 1
print(ans)


H, A = map(int, input().split())

a = int(H/A)
b = int(H%A)

if b==2:
  b+=1

print(b)


h, a = map(int, input().split())
print(int((h-0.1)//a + 1))


H,N = list(map(int,input().split()))
A = list(map(int,input().split()))
if H <= sum(A):
  print('Yes')
else:
  print('No')

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.
There is no other way to decrease the monster's health.

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

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Constraints

1 \leq H \leq 10^9

1 \leq N \leq 10^5

1 \leq A_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 A_2 ... A_N

Output

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

The monster's health will become 0 or below after, for example, using the second and third moves.

Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No


def win(h,n,arr):
  	cnt=0
  	for i in range(n):
    	h-=arr[i]
    if h<=0:
      cnt=1
    return cnt

h=int(input())
n=int(input())
arr=[]
for i in range(n):
  a=int(input())
  arr.append(a)
l=win(h,n,arr)
if l=1:
  print("yes")
else
	print("no")


N,K = map(int,input().split())
if N<=K :
    print(0)
else :
    H = list(map(int,input().split()))
    H.sort()
    if 0<K :
        del H[-K:]
    print(sum(H))

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.


N,K = map(int,input().split())
H = list(map(int,input().split()))
H.sort()
ans = sum(H[0:max(0,N-K)])
print(ans)


N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

H = sorted(H, key= lambda x:-x)[K:]
print(sum(H))


H = int(input())

ans = 0

for i in range(100):
    if(H < 2**i):
        max_range = i
        break
    ans += 2**i

print(ans)

Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is 1, it drops to 0.

If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775


h,n=map(int,input().split())
INF=10**18
dp=[INF]*(h+1)
dp[0]=0
for _ in range(n):
  a,b=map(int,input().split())
  for i in range(h+1):
    dp[min(i+a,h)]=min(dp[min(i+a,h)],dp[i]+b)
print(dp[h])

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


h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [_[0] for _ in ab]

inf = float('inf')
dp = [inf] * (h + max(a) + 1)

for i in range(1, len(dp)):
    for x, y in ab:
        if i - x > 0:
            dp[i] = min(dp[i], dp[i - x] + y)
        else:
            dp[i] = min(dp[i], y)

print(dp[h])


from bisect import bisect_right
import sys
input=sys.stdin.readline

class LazySegTree():
    def __init__(self, N):
        self.INF = 2**31-1
        self.LV = (N-1).bit_length()
        self.N0 = 2**self.LV
        self.data = [0]*(2*self.N0)
        self.lazy = [0]*(2*self.N0)

    def gindex(self, l, r):
        L = (l + self.N0) >> 1; R = (r + self.N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()

        m = []
        for i in range(self.LV):
            if rc <= i:
                m.append(R)
            if L < R and lc <= i:
                m.append(L)
            L >>= 1; R >>= 1

        return m

    # 遅延伝搬処理
    def propagates(self, ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            if not v:
                continue
            self.lazy[2*i-1] += v; self.lazy[2*i] += v
            self.data[2*i-1] += v; self.data[2*i] += v
            self.lazy[i-1] = 0

    # 区間[l, r)にxを加算
    def update(self, l, r, x):
        ids = self.gindex(l, r)
        self.propagates(ids)

        L = self.N0 + l; R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R-1] += x; self.data[R-1] += x
            if L & 1:
                self.lazy[L-1] += x; self.data[L-1] += x
                L += 1
            L >>= 1; R >>= 1
        for i in ids:
            self.data[i-1] = max(self.data[2*i-1], self.data[2*i])

    # 区間[l, r)内の最小値を求める
    def query(self, l, r):
        self.propagates(self.gindex(l, r))
        L = self.N0 + l; R = self.N0 + r

        s = -self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R-1])
            if L & 1:
                s = max(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

    def set_list(self, l, N):
        for i in range(N):
            self.data[i+self.N0-1] = l[i]
        for i in range(self.N0-1)[::-1]:
            self.data[i] = max(self.data[2*i+1], self.data[2*i+2])

def solve():
    N, D, A = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(N)]

    l.sort()
    lh = [h for x,h in l]
    lx = [x for x,h in l]
    tree = LazySegTree(N)
    tree.set_list(lh, N)
    ans = 0

    for i in range(N):
        v = tree.query(i, i+1)
        if v>0:
            c = (v+A-1)//A
            tree.update(i, min(N, i+2*D+1), -c*A)
            ans += c

    print(ans)

if __name__ == "__main__":
    solve()

Score : 600 points

Problem Statement

Silver Fox is fighting with N monsters.

The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.

Silver Fox can use bombs to attack the monsters.
Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A.
There is no way other than bombs to decrease the monster's health.

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

Find the minimum number of bombs needed to win.

Constraints

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

0 \leq D \leq 10^9

1 \leq A \leq 10^9

0 \leq X_i \leq 10^9

1 \leq H_i \leq 10^9

X_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D A
X_1 H_1
:
X_N H_N

Output

Print the minimum number of bombs needed to win.

Sample Input 1

3 3 2
1 2
5 4
9 2

Sample Output 1

2

First, let us use a bomb at the coordinate 4 to decrease the first and second monsters' health by 2.

Then, use a bomb at the coordinate 6 to decrease the second and third monsters' health by 2.

Now, all the monsters' healths are 0.
We cannot make all the monsters' health drop to 0 or below with just one bomb.

Sample Input 2

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

Sample Output 2

5

We should use five bombs at the coordinate 5.

Sample Input 3

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


import sys
input=sys.stdin.readline
n,m=map(int,input().split())
if n==m:
    print('Yes')
else:
    print('No')

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


N,M = map(int,input().split())

if (N==M):
  print("Yes")
else:
  print("No")


n, m = tuple(map(int, input().split()))
print("Yes" if (n == m) else "No")


a, b = map(int, input().split())

A = ""
B = ""

for i in range(b):
  A += str(a)

for i in range(a):
  B += str(b)

print(min(A, B))

Score : 200 points

Problem Statement

Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Constraints

1 \leq a \leq 9

1 \leq b \leq 9

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)

Sample Input 1

4 3

Sample Output 1

3333

We have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.

Sample Input 2

7 7

Sample Output 2

7777777


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

ans = 0
m = p[0]

for i in p:
	if m >= i:
		ans += 1
		m = i

print(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


n = int(input())
lst = list(map(int, input().split()))
nowmin = 10 ** 9
res = 0
for i in range(n):
  if nowmin >= lst[i]:
    res += 1
    nowmin = lst[i]
print(res)


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

ans = 1
min_val = p[0]

for i in range(1, n):
  min_val = min(p[i], min_val)
  if min_val == p[i]:
    ans += 1

print(ans)


"""
the condition is quite simple actually.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

def gcd(x, y):
  return 1

def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing

def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value

if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))

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).


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

def gcd(a,b):
    return a if b == 0 else gcd(b,a%b)

lcm = 1
for v in a:
    lcm = lcm * v // gcd(lcm, v)

MOD = 1000000007
ans = 0
for v in a:
    ans += lcm // v
    ans %= MOD;

print(ans)


import sys
readline = sys.stdin.readline

def main():
    H = int(readline())
    W = int(readline())
    N = int(readline())
    print(-(-N // max(H, W)))

if __name__ == '__main__':
    main()

Score : 100 points

Problem Statement

We have a grid with H rows and W columns, where all the squares are initially white.

You will perform some number of painting operations on the grid.
In one operation, you can do one of the following two actions:

Choose one row, then paint all the squares in that row black.

Choose one column, then paint all the squares in that column black.

At least how many operations do you need in order to have N or more black squares in the grid?
It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.

Constraints

1 \leq H \leq 100

1 \leq W \leq 100

1 \leq N \leq H \times W

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H
W
N

Output

Print the minimum number of operations needed.

Sample Input 1

3
7
10

Sample Output 1

2

You can have 14 black squares in the grid by performing the "row" operation twice, on different rows.

Sample Input 2

14
12
112

Sample Output 2

8

Sample Input 3

2
100
200

Sample Output 3

2


N = int(input())

p = []
for i in range(N):
  a,b = map(int,input().split())
  p.append([max(0,a - b),a + b])

q = sorted(p,key=lambda x:x[1])

cnt = 0
d = q[0][1]
for j,k in q[1:]:
  if j < d:
    cnt += 1
  else:
    d = k

print(N-cnt)

Score : 200 points

Problem Statement

In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.

We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

0 \leq X_i \leq 10^9 (1 \leq i \leq N)

1 \leq L_i \leq 10^9 (1 \leq i \leq N)

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

By removing Robot 2, we can keep the other three robots.

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5


N = int(input())
A = []
for _ in range(N):
    X, L = map(int, input().split())
    A.append((X-L, X+L))

A = sorted(A, key=lambda x:x[1])
p = -10**10
ans = 0
for l, r in A:
    if l>=p:
        ans += 1
        p = r
print(ans)


import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K,S = MI()
if S == 10**9:
    ANS = [10**9]*K + [1]*(N-K)
else:
    ANS = [S]*K + [10**9]*(N-K)

print(*ANS)

Score : 400 points

Problem Statement

Given are three integers N, K, and S.

Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below.
We can prove that, under the conditions in Constraints, such a sequence always exists.

There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq N and A_l + A_{l + 1} + \cdots + A_r = S.

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N

1 \leq S \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K S

Output

Print a sequence satisfying the condition, in the following format:

A_1 A_2 ... A_N

Sample Input 1

4 2 3

Sample Output 1

1 2 3 4

Two pairs (l, r) = (1, 2) and (3, 3) satisfy the condition in the statement.

Sample Input 2

5 3 100

Sample Output 2

50 50 50 30 70


al = list("abcdefghijklmnopqistuvwxyz")

c = input()

print(al[al.index(c)+1])

Score : 100 points

Problem Statement

Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.

Constraints

C is a lowercase English letter that is not z.

Input

Input is given from Standard Input in the following format:

C

Output

Print the letter that follows C in alphabetical order.

Sample Input 1

a

Sample Output 1

b

a is followed by b.

Sample Input 2

y

Sample Output 2

z

y is followed by z.


import string
c = input()

upper = string.ascii_lowercase
ind = upper.index(c)
print(upper[ind+1])


alphabet = {chr(i):chr(i+1) for i in range(97, 123)}
a = input()
print(alphabet[a])


N, M = [int(s) for s in input().split(' ')]

acd = dict()
ac = 0
pc = 0
for i in range(M):
    p, S = input().split(' ')
    if int(p) <= N and p not in acd:
        if S == 'AC':
            acd[p] = 1
            ac += 1
        elif S == 'WA':
            pc += 1

print("{} {}".format(ac, pc))

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

Find the numbers of Takahashi's correct answers and penalties.

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

2 2

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.

Sample Input 3

6 0

Sample Output 3

0 0


n, m= map(int, input().split())
p = ""
s = ""
l = []
ans = 0

for i in range(m):
    p, s =input().split()
    if s == "AC":
        if p in l:
            continue
        else:
            l.append(p)
    else:
        if p not in l:
            ans += 1

print(len(l), end=" ")
print(ans)


# Author: cr4zjh0bp
# Created: Tue Mar 17 19:50:06 UTC 2020
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
m = nsn(h)

dist = [[inf] * (h * w) for _ in range(h * w)]
dx, dy = [0, 1, -1, 0], [1, 0, 0, -1]
for i in range(h):
    for j in range(w):
        for k in range(4):
            ni, nj = i + dy[k], j + dx[k]
            if ni >= 0 and ni < h and nj >= 0 and nj < w and m[ni][nj] != '#' and m[i][j] != '#':
                dist[i * h + j][ni * h + nj] = 1
        dist[i * h + j][i * h + j] = 0

def floyd_warshall(n, dist):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

floyd_warshall(h * w, dist)

ans = 0
for i in range(h * w):
    for j in range(h * w):
        if dist[i][j] != inf:
            ans = max(ans, dist[i][j])

print(ans)

Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

1 \leq H,W \leq 20

S_{ij} is . or #.

S contains at least two occurrences of ..

Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

Sample Input 2

3 5
...#.
.#.#.
.#...

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.


from collections import deque

INF = -1

sizeI, sizeJ = map(int, input().split())
a = [input().rstrip() for _ in range(sizeI)]

def bfs(startI, startJ):
    dist = [[INF for _ in range(sizeJ)] for _ in range(sizeI)]
    dist[startI][startJ] = 0
    q = deque([(startI, startJ)])
    while q:
        i, j = q.pop()
        curDist = dist[i][j]
        for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < sizeI and 0 <= nj < sizeJ and dist[ni][nj] == INF and a[ni][nj] == '.':
                dist[ni][nj] = 1 + curDist
                q.appendleft((ni, nj))
    return max([max(row) for row in dist])

ret = -float('inf')
for i in range(sizeI):
    for j in range(sizeJ):
        if a[i][j] == '.':
            ret = max(ret, bfs(i, j))
print(ret)


N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

def extgcd(a,b):
    a0,b0=a,b
    x0,y0=1,0
    x1,y1=0,1

    while b0!=0:
        q = a0 // b0
        r = a0 % b0

        a0,b0=b0,r
        x0,x1=x1,x0-q*x1
        y0,y1=y1,y0-q*y1

    return a0,x0,y0

def mo(x,mod):
    return (mod+x%mod)%mod

def inv(a,mod):
    g,x,y=extgcd(a,mod)
    ans=mo(x,mod)
    return ans

def combi_mod(n,k):
    invlist = [1]
    for i in range(1, k + 1):
        temp = inv(i, mod)
        invlist.append(temp)
    k1 = 1
    k3 = 1

    for i in range(n, 0, -1):

        if i > n - k:
            k1 *= i
        if i < k + 1:
            k3 *= invlist[i]
    ans = k1 * k3
    ans = ans % mod
    return ans

A.sort()

ans=0

for i in range(N-1,K-2,-1):
    ans+=(A[i]-A[(N-1)-i])*combi_mod(i,K-1)

ans%=mod

print(ans)

Score : 500 points

Problem Statement

For a finite set of integers X, let f(X)=\max X - \min X.

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

We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways.

Since the answer can be enormous, print it \bmod (10^9+7).

Constraints

1 \leq N \leq 10^5

1 \leq K \leq N

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 ... A_N

Output

Print the answer \bmod (10^9+7).

Sample Input 1

4 2
1 1 3 4

Sample Output 1

11

There are six ways to choose S: \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 1s). The value of f(S) for these choices are 0,2,3,2,3,1, respectively, for the total of 11.

Sample Input 2

6 3
10 10 10 -10 -10 -10

Sample Output 2

360

There are 20 ways to choose S. In 18 of them, f(S)=20, and in 2 of them, f(S)=0.

Sample Input 3

3 1
1 1 1

Sample Output 3

0

Sample Input 4

10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0

Sample Output 4

999998537

Print the sum \bmod (10^9+7).


N = int(input())

S = list()
T = list()

for i in range(N):
  s,t = input().split()
  t = int(t)
  S.append(s)
  T.append(t)

X = input()

A = T[S.index(X)+1:]
print(sum(A))

Score : 200 points

Problem Statement

Niwango created a playlist of N songs.
The title and the duration of the i-th song are s_i and t_i seconds, respectively.
It is guaranteed that s_1,\ldots,s_N are all distinct.

Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)
However, he fell asleep during his work, and he woke up after all the songs were played.
According to his record, it turned out that he fell asleep at the very end of the song titled X.

Find the duration of time when some song was played while Niwango was asleep.

Constraints

1 \leq N \leq 50

s_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.

s_1,\ldots,s_N are distinct.

There exists an integer i such that s_i = X.

1 \leq t_i \leq 1000

t_i is an integer.

Input

Input is given from Standard Input in the following format:

N
s_1 t_1
\vdots
s_{N} t_N
X

Output

Print the answer.

Sample Input 1

3
dwango 2
sixth 5
prelims 25
dwango

Sample Output 1

30

While Niwango was asleep, two songs were played: sixth and prelims.

The answer is the total duration of these songs, 30.

Sample Input 2

1
abcde 1000
abcde

Sample Output 2

0

No songs were played while Niwango was asleep.

In such a case, the total duration of songs is 0.

Sample Input 3

15
ypnxn 279
kgjgwx 464
qquhuwq 327
rxing 549
pmuduhznoaqu 832
dagktgdarveusju 595
wunfagppcoi 200
dhavrncwfw 720
jpcmigg 658
wrczqxycivdqn 639
mcmkkbnjfeod 992
htqvkgkbhtytsz 130
twflegsjz 467
dswxxrxuzzfhkp 989
szfwtzfpnscgue 958
pmuduhznoaqu

Sample Output 3

6348


n=int(input())
x=list(map(int,input().split()))
a=1
B=[1,1]
mod=10**9+7
for i in range(2,n):
  a=a*i%mod
  B.append(pow(i,mod-2,mod))
d=[0]*(n-1)
for i in range(n-1):
  d[i]=x[i+1]-x[i]
D=[d[-1]]
for i in range(n-2):
  D.append(D[-1]+d[-2-i])
D=D[::-1]
ans=0
for i in range(n-1):
  ans=(ans+D[i]*a*B[i+1])%mod
print(ans)

Score : 600 points

Problem Statement

There are N slimes standing on a number line.
The i-th slime from the left is at position x_i.

It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}.

Niwango will perform N-1 operations. The i-th operation consists of the following procedures:

Choose an integer k between 1 and N-i (inclusive) with equal probability.

Move the k-th slime from the left, to the position of the neighboring slime to the right.

Fuse the two slimes at the same position into one slime.

Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.

Constraints

2 \leq N \leq 10^{5}

1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}

x_i is an integer.

Subtasks

400 points will be awarded for passing the test cases satisfying N \leq 2000.

Input

Input is given from Standard Input in the following format:

N
x_1 x_2 \ldots x_N

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

5

With probability \frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.

With probability \frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.

The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.

Sample Input 2

12
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932

Sample Output 2

750927044

Find the expected value multiplied by (N-1)!, modulo (10^9+7).


LARGE = 10 ** 9 + 7

def solve(n, x_list):

    n_1_fac = 1
    for i in range(2, n):
        n_1_fac *= i
        n_1_fac %= LARGE

    res = 0
    for i in range(n - 1):
        res += (x_list[n - 1] - x_list[i]) * n_1_fac * pow(n - 1 - i, LARGE - 2, LARGE)
        res %= LARGE

    x_left = 0
    x_right = 0
    for k in range(1, n - 1):
        x_right += x_list[n - 1 - k]
        x_left += x_list[k - 1]
        res += (x_right - x_left) * n_1_fac * pow(k, LARGE - 2, LARGE) * pow(k + 1, LARGE - 2, LARGE)
        res %= LARGE
    return res

def main():
    n = int(input())
    x_list = list(map(int, input().split()))
    res = solve(n, x_list)
    print(res)

def test():
    assert solve(3, [1, 2, 3]) == 5
    assert solve(12, [
        161735902, 211047202, 430302156, 450968417, 628894325, 707723857,
        731963982, 822804784, 880895728, 923078537, 971407775, 982631932
    ]) == 750927044

if __name__ == "__main__":
    test()
    main()


K,X = map (int, input ().split ())
if K*500 < X:
  print ('No')
else:
  print ('Yes')

Score : 100 points

Problem Statement

Takahashi has K 500-yen coins. (Yen is the currency of Japan.)
If these coins add up to X yen or more, print Yes; otherwise, print No.

Constraints

1 \leq K \leq 100

1 \leq X \leq 10^5

Input

Input is given from Standard Input in the following format:

K X

Output

If the coins add up to X yen or more, print Yes; otherwise, print No.

Sample Input 1

2 900

Sample Output 1

Yes

Two 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.

Sample Input 2

1 501

Sample Output 2

No

One 500-yen coin is worth 500 yen, which is less than X = 501 yen.

Sample Input 3

4 2000

Sample Output 3

Yes

Four 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.


K, X = map(int, input().split())

if K * 500 >= X:
  print('Yes')
else:
  print('No')


n = int(input())
s = input()
print(s.count("ABC"))

Score : 200 points

Problem Statement

We have a string S of length N consisting of uppercase English letters.

How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print number of occurrences of ABC in S as contiguous subsequences.

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

Two contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5


import itertools
import math

N = int(input())
P = int(''.join(input().split()))
Q = int(''.join(input().split()))

N_list = []
for i in itertools.permutations(range(1,N+1)):
    N_list.append(int(''.join([str(x) for x in i])))

pointer1 = 0
pointer2 = 0

for i,x in enumerate(N_list):
  if x == P:
    pointer1 = i
  if x == Q:
    pointer2 = i

print(abs(pointer1 - pointer2))

Score : 300 points

Problem Statement

We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).

There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Notes

For two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \leq i < k) and X_k < Y_k.

Constraints

2 \leq N \leq 8

P and Q are permutations of size N.

Input

Input is given from Standard Input in the following format:

N
P_1 P_2 ... P_N
Q_1 Q_2 ... Q_N

Output

Print |a - b|.

Sample Input 1

3
1 3 2
3 1 2

Sample Output 1

3

There are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.

Sample Input 2

8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1

Sample Output 2

17517

Sample Input 3

3
1 2 3
1 2 3

Sample Output 3

0


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

a = LIST()

# a = [x//2 for x in a]
# if a[0] % 2 == 0:  # 偶数の時
# 	for x in a:
# 		if x % 2 == 1:
# 			print(0)
# 			sys.exit(0)
# 	for x in a:
# 		if a[0] != x and abs(a[0]-x)%gcd(2*a[0], 2*x) != 0:
# 			print(0)
# 			sys.exit()

# 	tmp = 1
# 	for x in a:
# 		tmp = x*tmp//gcd(x, tmp)
# 	print((M-tmp)//(tmp*2)+1)

# else:
# 	for x in a:
# 		if x % 2 == 0:
# 			print(0)
# 			sys.exit(0)
# 	tmp = 1
# 	for x in a:  # 奇数の時
# 		tmp = x*tmp//gcd(x, tmp)
# 	print((M-tmp)//(tmp*2)+1)

for i in range(1, N):
	if abs(a[0]//2-a[i]//2) % gcd(a[0], a[i]) != 0:
		print(0)
		sys.exit()
tmp = 1
for x in a:
	tmp = x//2*tmp//gcd(x//2, tmp)
print((M-tmp)//(tmp*2)+1)

Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6 \times 2.5

15 = 10 \times 1.5

45 = 6 \times 7.5

45 = 10 \times 4.5

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667


a, b, k = map(int, input().split())

if a >= k:
  print(a - k, b)
else:
  print(0, max(0, a + b - k))

Score : 200 points

Problem Statement

Takahashi has A cookies, and Aoki has B cookies.
Takahashi will do the following action K times:

If Takahashi has one or more cookies, eat one of his cookies.

Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.

If they both have no cookies, do nothing.

In the end, how many cookies will Takahashi and Aoki have, respectively?

Constraints

0 \leq A \leq 10^{12}

0 \leq B \leq 10^{12}

0 \leq K \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the numbers of Takahashi's and Aoki's cookies after K actions.

Sample Input 1

2 3 3

Sample Output 1

0 2

Takahashi will do the following:

He has two cookies, so he eats one of them.

Now he has one cookie left, and he eats it.

Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.

Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.

Sample Input 2

500000000000 500000000000 1000000000000

Sample Output 2

0 0

Watch out for overflows.


A,B,K =  map(int, input().split())

S=max([0,A-K])

if A<K:
  T=max([0,B-(K-A)])

else:
  T=B

print(str(S)+" "+str(T))


a = input()
b = input()

print("123".replace(a,"").replace(b,""))

Score: 100 points

Problem Statement

Takahashi is solving quizzes. He has easily solved all but the last one.

The last quiz has three choices: 1, 2, and 3.

With his supernatural power, Takahashi has found out that the choices A and B are both wrong.

Print the correct choice for this problem.

Constraints

Each of the numbers A and B is 1, 2, or 3.

A and B are different.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print the correct choice.

Sample Input 1

3
1

Sample Output 1

2

When we know 3 and 1 are both wrong, the correct choice is 2.

Sample Input 2

1
2

Sample Output 2

3


a=int(input())
b=int(input())

if a+b==3:
    print(3)
elif a+b==4:
    print(2)
else:
    print(1)


A = int(input())
B = int(input())
if 1 not in (A,B):
    print(1)
elif 2 not in (A,B):
    print(2)
else:
    print(3)


N=int(input())

S,T=input().split()
S=list(S)
T=list(T)
ans=""
for i in range(N):
    ans+=S[i]
    ans+=T[i]

print(ans)

Score : 200 points

Problem Statement

Given are strings s and t of length N each, both consisting of lowercase English letters.

Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

Constraints

1 \leq N \leq 100

|S| = |T| = N

S and T are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S T

Output

Print the string formed.

Sample Input 1

2
ip cc

Sample Output 1

icpc

Sample Input 2

8
hmhmnknk uuuuuuuu

Sample Output 2

humuhumunukunuku

Sample Input 3

5
aaaaa aaaaa

Sample Output 3

aaaaaaaaaa


N = int(input())
print(N)
S = input().split()
Output = ""

for i in range(N) :
  Output = Output + S[0][i] + S[1][i]

print(Output)


N = int(input())
S, T = input().split()

ans = ''
for i in range(N):
  ans += S[i]
  ans += T[i]

print(ans)


from math import gcd

a,b = map(int,input().split())
print(a*b//gcd(a,b))

Score : 300 points

Problem Statement

Takahashi is organizing a party.

At the party, each guest will receive one or more snack pieces.

Takahashi predicts that the number of guests at this party will be A or B.

Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.

We assume that a piece cannot be divided and distributed to multiple guests.

Constraints

1 \leq A, B \leq 10^5

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.

Sample Input 1

2 3

Sample Output 1

6

When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.

Sample Input 2

123 456

Sample Output 2

18696

Sample Input 3

100000 99999

Sample Output 3

9999900000


import fractions
a,b=map(int, input().split())
f=fractions.gcd(a,b)
f2=a*b//f
print(f2)


A, B = map(int,input().split())

def euclid(a0, b0):
    a = max(a0, b0)
    b = min(a0, b0)
    while(a%b != 0):
        a = a%b
        if a<b: # 入れ替え
          a = a^b
          b = a^b
          a = a^b
        #print(a,end=" ")
        #print(b)
    return b

print(A*B//euclid(A,B))


import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    cnt = 0
    val = 10
    while True:
        if n//val < 1: break
        cnt += n//val
        val *= 5
    print(cnt)

if __name__ == '__main__':
    main()

Score : 500 points

Problem Statement

For an integer n not less than 0, let us define f(n) as follows:

f(n) = 1 (if n < 2)

f(n) = n f(n-2) (if n \geq 2)

Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).

Constraints

0 \leq N \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of trailing zeros in the decimal notation of f(N).

Sample Input 1

12

Sample Output 1

1

f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.

Sample Input 2

5

Sample Output 2

0

f(5) = 5 × 3 × 1 = 15, which has no trailing zeros.

Sample Input 3

1000000000000000000

Sample Output 3

124999999999999995


A = [int(x) for x in input().split()]
if sum(A) >= 22:
  print("bust")
else:
  print("win")

Score : 100 points

Problem Statement

Given are three integers A_1, A_2, and A_3.

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Constraints

1 \leq A_i \leq 13 \ \ (i=1,2,3)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Sample Input 1

5 7 9

Sample Output 1

win

5+7+9=21, so print win.

Sample Input 2

13 7 2

Sample Output 2

bust

13+7+2=22, so print bust.


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

if sum(S) >= 22:
    print('bust')
else:
    print('win')


n = sum(list(map(int, input().split())))
print('win' if n <= 21 else 'bust')


N = input().split()
print(N)

sum = 0
for i in range(len(N)):
  sum += int(N[i])

if sum >= 22:
  print('bust')
else:
  print('win')


import sys
input = sys.stdin.readline

S = input()
l = len(S)
count = 0
if len(S)%2 == 1:
    #print("here")
    for i in range(int(len(S)/2)):
        #print(S[i], S[l-i-2])
        if S[i] != S[l-i-2]:
            count += 1
else:
    for i in range(int((len(S)-1)/2)):
        #print(S[i], S[l-i-2])
        if S[i] != S[l-i-2]:
            count += 1

print(count)

Score : 200 points

Problem Statement

Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.

Given is a string S. Find the minimum number of hugs needed to make S palindromic.

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

Print the minimum number of hugs needed to make S palindromic.

Sample Input 1

redcoder

Sample Output 1

1

For example, we can change the fourth character to o and get a palindrome redooder.

Sample Input 2

vvvvvv

Sample Output 2

0

We might need no hugs at all.

Sample Input 3

abcdabc

Sample Output 3

2


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
mod = 7 + 10**9
A = []
leng = len(format(max(a), 'b'))
bit_acc = [0 for i in range(leng)]
for i in range(n):
    A.append(list(map(int, format(a[i], 'b').zfill(leng))))
for i in range(leng):
    bit_acc[i] = sum([A[j][i] for j in range(n)])
ans = 0
for i in range(n):
    for j in range(leng):
        if A[i][j] == 1:
            ans += (n - bit_acc[j]) * (2 ** (leng - j - 1))
        else:
            ans += bit_acc[j] * (2 ** (leng - j - 1))
print((ans * 500000004) % mod)

Score : 400 points

Problem Statement

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

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

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

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


n = int(input())
A = list(map(int,input().split()))
C = [0 for i in range(60)]
mod = 1000000007
for a in A:
  for i in range(60):
    C[i] += a%2
    a>>=1
    if a==0:
      break
ans = 0
for i in range(60):
  u = (2**(i))%mod
  num = C[i]*(n-C[i])
  ans+=u*num
  ans%=mod
print(ans)


N = int(input())
A = list(map(int, input().split()))

def sumXOR( arr,  n):
    sum = 0
    for i in range(0, 64):

        #  Count of zeros and ones
        zc = 0
        oc = 0

        # Individual sum at each bit position
        idsum = 0
        for j in range(0, n):
            if (arr[j] % 2 == 0):
                zc = (zc + 1)

            else:
                oc = (oc + 1)
            arr[j] = int(arr[j] / 2)

        # calculating individual bit sum
        idsum = (oc * zc * ((1 << i))) % 1000000007

        # final sum
        sum = (sum + idsum)

    return sum

print(sumXOR(A, N)  % 1000000007)


import numpy as np
HW = list(map(int, input().split()))
H = HW[0]
W = HW[1]
A = np.empty((H, W), dtype=np.int64)
B = np.empty((H, W), dtype=np.int64)
for i in range(H):
  A[i] = np.fromstring(input(), dtype = np.int64, sep = ' ')
for i in range(H):
  B[i] = np.fromstring(input(), dtype = np.int64, sep = ' ')

C = np.abs(A - B)
K = (H + W) * (C.max())

D = np.full((H, W, K), False)
D[0][0][C[0][0]] = True
D[0][1][C[0][0] + C[0][1]] = True
D[0][1][abs(C[0][0] - C[0][1])] = True
D[1][0][C[0][0] + C[1][0]] = True
D[1][0][abs(C[0][0] - C[1][0])] = True

for i in range(1, H):
  for j in range(1, W):
    for k in range(K):
      if k + C[i][j] < K:
        if D[i-1][j][k + C[i][j]] or D[i][j-1][k + C[i][j]]:
          D[i][j][k] = True
          continue
      if D[i-1][j][abs(k - C[i][j])] or D[i][j-1][abs(k - C[i][j])]:
        D[i][j][k] = True

for k in range(K):
  if D[H-1][W-1][k]:
    print(k)
    break

Score : 500 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.

The square (i, j) has two numbers A_{ij} and B_{ij} written on it.

First, for each square, Takahashi paints one of the written numbers red and the other blue.

Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.

Let the unbalancedness be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).

Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.

Find the minimum unbalancedness possible.

Constraints

2 \leq H \leq 80

2 \leq W \leq 80

0 \leq A_{ij} \leq 80

0 \leq B_{ij} \leq 80

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W
A_{11} A_{12} \ldots A_{1W}
:
A_{H1} A_{H2} \ldots A_{HW}
B_{11} B_{12} \ldots B_{1W}
:
B_{H1} B_{H2} \ldots B_{HW}

Output

Print the minimum unbalancedness possible.

Sample Input 1

2 2
1 2
3 4
3 4
2 1

Sample Output 1

0

By painting the grid and traveling on it as shown in the figure below, the sum of red numbers and the sum of blue numbers are 3+3+1=7 and 1+2+4=7, respectively, for the unbalancedness of 0.

Sample Input 2

2 3
1 10 80
80 10 1
1 2 3
4 5 6

Sample Output 2

2


h, w = list(map(int, input().split()))

aa = [list(map(int, input().split())) for _ in range(h)]
bb = [list(map(int, input().split())) for _ in range(h)]

dif = []
for i in range(h):
    dif.append([int(abs(a - b)) for a, b in zip(aa[i], bb[i])])

dp = [[set() for _ in range(w + 2)] for _ in range(h + 2)]

dp[1][0] = set([0])

lim = [[0 for _ in range(w + 2)] for _ in range(h + 2)]
for i in reversed(range(1, h + 1)):
    for j in reversed(range(1, w + 1)):
        lim[i][j] = max(lim[i + 1][j], lim[i][j + 1]) + dif[i - 1][j - 1]

for i in range(1, h + 1):
    for j in range(1, w + 1):
        origin = dp[i - 1][j] | dp[i][j - 1]
        cand = {x + dif[i - 1][j - 1] for x in origin} | {x - dif[i - 1][j - 1] for x in origin}
        dp[i][j] = {x for x in cand if x <= lim[i][j]} | {min({10 ** 10}.union({x for x in cand if x > lim[i][j]}))}

print(min([abs(x) for x in dp[h][w]]))


import sys
n=int(input())
for i in range(n):
    if (int(i*108/100)==n):
        print (i)
        sys.exit()
print(":(")

Score: 200 points

Problem Statement

Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.

The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).

Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.

If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

Constraints

1 \leq N \leq 50000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If there are values that could be X, the price of the apple pie before tax, print any one of them.

If there are multiple such values, printing any one of them will be accepted.

If no value could be X, print :(.

Sample Input 1

432

Sample Output 1

400

If the apple pie is priced at 400 yen before tax, you have to pay 400 \times 1.08 = 432 yen to buy one.

Otherwise, the amount you have to pay will not be 432 yen.

Sample Input 2

1079

Sample Output 2

:(

There is no possible price before tax for which you have to pay 1079 yen with tax.

Sample Input 3

1001

Sample Output 3

927

If the apple pie is priced 927 yen before tax, by rounding down 927 \times 1.08 = 1001.16, you have to pay 1001 yen.


N = int(input())

for i in range(1, 50001):
    if int(i * 1.08) == N:
        print(i)
        exit()

print(":(")


n = int(input())

for i in range(1, 1000000):
    if int(i * 1.08) == n:
        print(i)
        break
else:
    print(":(")


x = int(input())

# 最大n個は買う必要がある
n = x // 100

# 最低m個買う必要がある
m = x // 105

ans = 0
# もし割り切れたら、OK
for i in range(100,106):
  if x % i == 0:
    ans = 1
    break

y = x % 100

import itertools
shinamono = [0,1,2,3,4,5] * (n%100)
for i in range(m,n+1):
  if ans == 1:
    break
  a = itertools.combinations(shinamono, i)
  for j in a:
    if sum(j) == y:
      ans = 1
      break

print(ans)

Score: 300 points

Problem Statement

AtCoder Mart sells 1000000 of each of the six items below:

Riceballs, priced at 100 yen (the currency of Japan) each

Sandwiches, priced at 101 yen each

Cookies, priced at 102 yen each

Cakes, priced at 103 yen each

Candies, priced at 104 yen each

Computers, priced at 105 yen each

Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.

(Ignore consumption tax.)

Constraints

1 \leq X \leq 100000

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

If it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.

Sample Input 1

615

Sample Output 1

1

For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.

Sample Input 2

217

Sample Output 2

0

No set of items costs 217 yen in total.


import collections

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
dic=collections.defaultdict(int)
dic[-1]=3
ans=1
for i in range(n):
  dic[arr[i]]+=1
  ans*=dic[arr[i]-1]
  ans%=mod
  dic[arr[i]-1]-=1
print(ans)

Score: 500 points

Problem Statement

N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green.

The person numbered i says:

"In front of me, exactly A_i people are wearing hats with the same color as mine."

Assuming that all these statements are correct, find the number of possible combinations of colors of the N people's hats.

Since the count can be enormous, compute it modulo 1000000007.

Constraints

1 \leq N \leq 100000

0 \leq A_i \leq N-1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print the number of possible combinations of colors of the N people's hats, modulo 1000000007.

Sample Input 1

6
0 1 2 3 4 5

Sample Output 1

3

We have three possible combinations, as follows:

Red, Red, Red, Red, Red, Red

Blue, Blue, Blue, Blue, Blue, Blue

Green, Green, Green, Green, Green, Green

Sample Input 2

3
0 0 0

Sample Output 2

6

Sample Input 3

54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Sample Output 3

115295190


t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

delta1 = (a1 - b1) * t1
delta2 = (a2 - b2) * t2

if delta1 + delta2 == 0:
    print('infinity')
    exit()

if delta1 * delta2 >= 0:
    print(0)
    exit()

if abs(delta1) > abs(delta2):
    print(0)
    exit()

steps = delta1 + delta2

ans = 2 * (min(abs(delta1), abs(delta2)) // steps) + 1
print(ans)

Score: 600 points

Problem Statement

Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east.

They start simultaneously at the same point and moves as follows towards the east:

Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.

Constraints

1 \leq T_i \leq 100000

1 \leq A_i \leq 10^{10}

1 \leq B_i \leq 10^{10}

A_1 \neq B_1

A_2 \neq B_2

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T_1 T_2
A_1 A_2
B_1 B_2

Output

Print the number of times Takahashi and Aoki will meet each other.

If they meet infinitely many times, print infinity instead.

Sample Input 1

1 2
10 10
12 4

Sample Output 1

1

They will meet just once, \frac{4}{3} minutes after they start, at \frac{40}{3} meters from where they start.

Sample Input 2

100 1
101 101
102 1

Sample Output 2

infinity

They will meet 101, 202, 303, 404, 505, 606, ... minutes after they start, that is, they will meet infinitely many times.

Sample Input 3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output 3

113

The values in input may not fit into a 32-bit integer type.


s = input()

if s == 'SUN':
	print('7')
elif s == 'MON':
	print('6')
elif s == 'TUE':
	print('5')
elif s == 'WED':
	print('4')
elif s == 'THU':
	print('3')
elif s == 'FRI':
	print('2')
elif s == 'SAT':
	print('1')

Score : 100 points

Problem Statement

Given is a string S representing the day of the week today.

S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.

After how many days is the next Sunday (tomorrow or later)?

Constraints

S is SUN, MON, TUE, WED, THU, FRI, or SAT.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of days before the next Sunday.

Sample Input 1

SAT

Sample Output 1

1

It is Saturday today, and tomorrow will be Sunday.

Sample Input 2

SUN

Sample Output 2

7

It is Sunday today, and seven days later, it will be Sunday again.


import math

a, b, x = map(int, input().split())
n = 0
i = 1
f = int(1e9)
ans = 0

while f-i > 1:
  n = (i+f)//2
  d = math.trunc(math.log10(n)) + 1
  if a*n + b*d <= x:
    i = n
  else:
    f = n

if a*f + b*d <= x:
  ans = f
elif a*i + b*d <= x:
  ans = i
else:
  ans = 0

print(ans)


n = int(input())
s = list(input())

m = len(s)

for i in range(m):
	if ord(s[i])+n-65<26:
		s[i]=chr(ord(s[i])+n)
	else:
		s[i]=chr(ord(s[i])+n-26)
"".join(s)
print("".join(s))

Score : 200 points

Problem Statement

We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.

Shift each character of S by N in alphabetical order (see below), and print the resulting string.

We assume that A follows Z. For example, shifting A by 2 results in C (A \to B \to C), and shifting Y by 3 results in B (Y \to Z \to A \to B).

Constraints

0 \leq N \leq 26

1 \leq |S| \leq 10^4

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the string resulting from shifting each character of S by N in alphabetical order.

Sample Input 1

2
ABCXYZ

Sample Output 1

CDEZAB

Note that A follows Z.

Sample Input 2

0
ABCXYZ

Sample Output 2

ABCXYZ

Sample Input 3

13
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output 3

NOPQRSTUVWXYZABCDEFGHIJKLM


N = input()
S = input()

# A = list('A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z')
A = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
print(A)
T =""
for i in S:
    print(i)
    k=A.index(i)+int(N)
    print(k)
    t=A[k]
    print(t)
    T +=t

print(T)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

from collections import deque

n = int(input())
uf = UnionFind(n)
g = [[] for i in range(n)]
cnt = [0] * n
ans = [0] * (n - 1)
ans_index = []

for i in range(n - 1):
    a, b = map(lambda x:int(x) - 1, input().split())
    uf.union(a, b)
    g[a].append(b)
    g[b].append(a)
    cnt[a] += 1
    cnt[b] += 1
    ans_index.append((a, b))

for i in uf.roots():
    visited = [0] * n
    visited[i] = 1
    que = deque()
    que.append([i, 0])
    while que:
        s = que.popleft()
        k = 0
        for j in g[s[0]]:
            if not visited[j]:
                while True:
                    k += 1
                    if k != s[1]:
                        que.append([j, k])
                        visited[j] = 1
                        #ans[ans_index.index((s[0], j))] = k
                        break

print(max(cnt))
print(*ans, sep = "\n")

Score : 400 points

Problem Statement

Given is a tree G with N vertices.
The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.

Consider painting the edges in G with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

2 \le N \le 10^5

1 \le a_i \lt b_i \le N

All values in input are integers.

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}

Output

Print N lines.

The first line should contain K, the number of colors used.

The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \le c_i \le K must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Sample Input 1

3
1 2
2 3

Sample Output 1

2
1
2

Sample Input 2

8
1 2
2 3
2 4
2 5
4 7
5 6
6 8

Sample Output 2

4
1
2
3
4
1
1
2

Sample Input 3

6
1 2
1 3
1 4
1 5
1 6

Sample Output 3

5
1
2
3
4
5


from collections import deque
n = int(input())
key = [0]*n
child = [[] for i in range(n)]
input_order = [0]*(n-1)

for i in range(n-1):
    a, b = map(int, input().split())
    input_order[i] = [a-1, b-1]
    key[a-1] += 1
    key[b-1] += 1
    child[a-1].append([a-1, b-1])

ans = max(key)
print(ans)
color = [[0]*n for i in range(n)]
color_min = [1]*n
yet = [[False]*n for i in range(n)]
not_yet = deque(child[0])

#本番
while len(not_yet) > 0:
    key = not_yet.popleft()
    a, b = key[0], key[1]
    color[a][b] = max([color_min[a], color_min[b]])
    if color[a][b] == color_min[a]:
        color_min[a] += 1
    if color[a][b] == color_min[b]:
        color_min[b] += 1

    for value in child[b]:
        if yet[value[0]][value[1]] == True:
            continue
        not_yet.append(value)
        yet[value[0]][value[1]] = True

for i in range(n-1):
    a, b = input_order[i][0], input_order[i][1]
    print(color[a][b])


N = int(input())
l = [0 for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    l[a-1] += 1
    l[b-1] += 1
print(max(l))
for i in range(N-1):
    print(i % max(l) + 1)


Score : 100 points

Problem Statement

Given is an integer r.

How many times is the area of a circle of radius r larger than the area of a circle of radius 1?

It can be proved that the answer is always an integer under the constraints given.

Constraints

1 \leq r \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

r

Output

Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.

Sample Input 1

2

Sample Output 1

4

The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.

Note that output must be an integer - for example, 4.0 will not be accepted.

Sample Input 2

100

Sample Output 2

10000


N = int(input())
S = str(input())

cnt=0
if N%2==1:
    print('No')
else:
    for i in range(int(N/2)):
        if S[i]==S[int(N/2)+i]:
            cnt+=1
        else:
            print('No')
            break
if cnt==int(N/2):
    print('Yes')

Score : 200 points

Problem Statement

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string T such that S = T + T.

Constraints

1 \leq N \leq 100

S consists of lowercase English letters.

|S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print Yes; otherwise, print No.

Sample Input 1

6
abcabc

Sample Output 1

Yes

Let T = abc, and S = T + T.

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No


N = int(input())
S = str(input())

if N % 2 != 0:
  print('No')

if S[:N / 2] == S[N / 2:]:
  print('Yes')