#include <stdio.h>

long long int gcd(long long int,long long int);

void main(){
    long  long int a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld",a*b/gcd(a,b));
}
long  long int gcd(long long int m,long long int n){
    if(n==0)
        return m;
    else
        return gcd(n,m%n);
}

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


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int min(int a, int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    long long int a, b, gcd = 1, sqrt;
    scanf("%lld%lld", &a,&b);
    long long int ans;
    for (long long int i = 2; i <= min(a,b); i++) {
        if (a%i==0 && b%i==0) {
            gcd = i;
        }
    }
    ans = a*b/gcd;
    printf("%lld\n", ans);
    return 0;
}

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.


#include <stdio.h>
#include <stdlib.h>

int	main(void)
{
  	int	N;
  	int	*a;
  	int	num;
  	int i;
  	int j;
  	int	flag;
  	int place;

  	num = scanf("%d", &N);
  	if (num != 1)
      	return (0);

  	a = (int *)malloc(sizeof(int) * (N + 1));
  	for (i=1; i<=N; i++)
    {
      	num = scanf("%d", &a[i]);
      	if (num != 1)
          	return (0);
    }

    flag = 0;
    for (i=1; i<=N; i++)
    {
        if (a[i] == 1)
        {
            place = i;
            flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("-1");
        return (0);
    }

  	for (i=place; i<=N; i++)
    {
        for (j=1; j<=N; j++)
        {
            if (a[i] == j)
            {
                place = j;
                break ;
            }
        }
    }
  	printf("%d", N - j);
  	return (0);
}

Score : 400 points

Problem Statement

We have N bricks arranged in a row from left to right.

The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.

Among them, you can break at most N-1 bricks of your choice.

Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.

Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.

Constraints

All values in input are integers.

1 \leq N \leq 200000

1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.

Sample Input 1

3
2 1 2

Sample Output 1

1

If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.

Sample Input 2

3
2 2 2

Sample Output 2

-1

In this case, there is no way to break some of the bricks to satisfy Snuke's desire.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

There may be no need to break the bricks at all.


#include<stdio.h>
#include<string.h>
#include<math.h>

int main(void) {
	long long n,ans = 0;
	long long div = 1;
	scanf("%lld", &n);
	if (n % 2) printf("%d", 0);
	else {
		long long a = n / 2;
		while (a / div) {
			div *= 5;
			ans += a / div;
		}
		printf("%lld", ans);
	}
	return 0;
}

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


#include <stdio.h>

int main(void) {
	long long int n;
	scanf("%lld", &n);

	if (n%2 != 0) {
		puts("0");
		return 0;
	}

	long long int cnt = 0;
	long long int div = 2;
	while (n/(div *= 5)) {
		cnt += n/div;
	}

	printf("%lld\n", cnt);
}


#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
  int a,b,c,sum;
  scanf("%d%d%d",&a,&b,&c);
  sum=a+b+c;
    if(sum<=21)
    {
      printf("win");
    }else{
      printf("bust");
    }
}

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.


#include <stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d",&a, &b,&c);
    d=a+b+c;
    if (d>=22)
    {
        printf("bust\n");
    }
    else
    {
        printf("win\n");
    }

    return 0;
}


#include<stdio.h>
int main()
{
    int a1, a2, a3, t;

    scanf("%d %d %d", &a1, &a2, &a3);

    t=a1+a2+a3;

    if(t>=22)
    {
        printf("bust\n");
    }
    else
    {
        printf("win\n");
    }

    return 0;
}


  #include <stdio.h>
  int main(void)
  {
    int a,b,c;

    // 入力
    scanf("%d %d %d", &a, &b, &c);
    if((a+b+c) >= 21)
      printf("%s\n","bust");
    else
      printf("%s\n","win");

    return 0;

  }


#include<stdio.h>
//#include<conio.h>
int main(){
  int A1;
  int A2;
  int A3;
  int result=0;
printf("Enter A1, A2, A3:");
  scanf("%d",&A1);
  scanf("%d",&A2);
  scanf("%d",&A3);
  if(result>=22)
  	printf("bust");
  else
    printf("win");
 return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a+b+c<22)
  printf("win");
  else
    printf("bust");
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
char s[101];
int i,k;
int main(void){
    scanf("%s",s);
    for (i = 0; i < strlen(s) / 2; i++)
    {
        if (s[i] != s[strlen(s)-i-1])
        {
            k++;
        }
    }
    printf("%d\n",k);
    return 0;
}

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


Score : 300 points

Problem Statement

There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.

Person i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.

How many honest persons can be among those N people at most?

Constraints

All values in input are integers.

1 \leq N \leq 15

0 \leq A_i \leq N - 1

1 \leq x_{ij} \leq N

x_{ij} \neq i

x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)

y_{ij} = 0, 1

Input

Input is given from Standard Input in the following format:

N
A_1
x_{11} y_{11}
x_{12} y_{12}
:
x_{1A_1} y_{1A_1}
A_2
x_{21} y_{21}
x_{22} y_{22}
:
x_{2A_2} y_{2A_2}
:
A_N
x_{N1} y_{N1}
x_{N2} y_{N2}
:
x_{NA_N} y_{NA_N}

Output

Print the maximum possible number of honest persons among the N people.

Sample Input 1

3
1
2 1
1
1 1
1
2 0

Sample Output 1

2

If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.

Sample Input 2

3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0

Sample Output 2

0

Assuming that one or more of them are honest immediately leads to a contradiction.

Sample Input 3

2
1
2 0
1
1 0

Sample Output 3

1


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


#include <stdio.h>

int main(void) {
	int X;
	int i;
	if (scanf("%d", &X) != 1) return 1;
	for (i = 0; 101 * i <= X; i++) {
		int kitaeri = X - 100 * i;
		if(i <= kitaeri && kitaeri <= 5 * i) {
			puts("1");
			return 0;
		}
	}
	puts("0");
	return 0;
}

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.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int N;
    char mozi[10000];
    scanf("%d", &N);
    scanf("%s", mozi);
    int n=strlen(mozi);

    for (int i = 0; i < n; i++) {
        int x=mozi[i]-'A';
        x=(x+N)%26;
        putchar(x+'A');}
 }

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


#include <stdio.h>
#include <string.h>

int main(void)
{
    int N;
    char S[10001];
    int i;

    scanf("%d", &N);
    scanf("%s", S);

    for(i=0; i<strlen(S); i++)
        printf("%c", 65+((int)S[i]-65+N)%26);

    printf("\n");

    //system("pause");

    return 0;
}


Score: 100 points

Problem Statement

We held two competitions: Coding Contest and Robot Maneuver.

In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen.

DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver.
Find the total amount of money he earned.

Constraints

1 \leq X \leq 205

1 \leq Y \leq 205

X and Y are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the amount of money DISCO-Kun earned, as an integer.

Sample Input 1

1 1

Sample Output 1

1000000

In this case, he earned 300000 yen in Coding Contest and another 300000 yen in Robot Maneuver. Furthermore, as he won both competitions, he got an additional 400000 yen.
In total, he made 300000 + 300000 + 400000 = 1000000 yen.

Sample Input 2

3 101

Sample Output 2

100000

In this case, he earned 100000 yen in Coding Contest.

Sample Input 3

4 4

Sample Output 3

0

In this case, unfortunately, he was the highest-ranked contestant without prize money in both competitions.


#include <stdio.h>

int main(void){
    int m;
    scanf("%d", &m);
    long long int ans = 0;
    long long int i, d, c;
    long long int sum = 0;
    for(i = 0; i < m; i++){
        scanf("%lld%lld", &d, &c);
        sum += c * d;
        ans += c;
    }
    ans--;

    ans += sum / 9;
    if(sum % 9 == 0){
        ans--;
    }
    printf("%lld\n", ans);
}

Score: 500 points

Problem Statement

N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.

The preliminary stage consists of several rounds, which will take place as follows:

All the N contestants will participate in the first round.

When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:

The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.

For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).

When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.

The preliminary stage ends when 9 or fewer contestants remain.

Ringo, the chief organizer, wants to hold as many rounds as possible.
Find the maximum possible number of rounds in the preliminary stage.

Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.

Constraints

1 \leq M \leq 200000

0 \leq d_i \leq 9

d_1 \neq 0

d_i \neq d_{i+1}

c_i \geq 1

2 \leq c_1 + \ldots + c_M \leq 10^{15}

Input

Input is given from Standard Input in the following format:

M
d_1 c_1
d_2 c_2
:
d_M c_M

Output

Print the maximum possible number of rounds in the preliminary stage.

Sample Input 1

2
2 2
9 1

Sample Output 1

3

In this case, N = 229 contestants will participate in the first round. One possible progression of the preliminary stage is as follows:

229 contestants participate in Round 1, 49 contestants participate in Round 2, 13 contestants participate in Round 3, and 4 contestants advance to the finals.

Here, three rounds take place in the preliminary stage, which is the maximum possible number.

Sample Input 2

3
1 1
0 8
7 1

Sample Output 2

9

In this case, 1000000007 will participate in the first round.


#include<stdio.h>

int main(void)
{
  int n,i;
  char s[110];
  scanf("%d%s",&n,s);
  if(n%2==1){
    printf("No\n");
    return -1;
  }
  for(i=0;i<n/2;i++)
    if(s[i]!=s[n/2+i]){
      printf("No\n");
      return -1;
    }
  printf("Yes\n");
  return 0;
}

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


#include<stdio.h>
#include<string.h>

int main(){
  int n,i;

  scanf("%d\n",&n);
  if(n%2==1){
  printf("No");
    return 0;
  }
  char str1[n/2];
  char str2[n/2];
  for(i=0;i<n/2;i++){
  scanf("%c",&str1[i]);
  }
  for(i=0;i<n/2;i++){
  scanf("%c",&str2[i]);
  }

  if(strncmp(str1,str2,n/2)==0){
  printf("Yes");
  return 0;
  }else{
  printf("No\n");
  }

  return 0;
}


#include <stdio.h>
#include <stdbool.h>

int main() {
    bool result = true;
    int n, half; char s[101];
    scanf("%d%100s", &n, s);
    if (n & 1)result = false;
    half = n / 2;
    for (int i = 0; i < half && result; ++i)
        if (s[i] != s[half + i])result = false;
    puts(result ? "Yes" : "No");
}


#include<stdio.h>
#include<string.h>
main()
{
  int N;
  char S [N];
  char T [50];
  char TT[100];
  scanf("%d",&N);
  scanf("%s",S);
  if(N%2==0){
    strncpy(T,S,N/2);
    T[N/2]='\0';
      strcat(TT,T);
      if(S==TT){
    printf("Yes");}
    else{
      printf("No");
  }
  }
  else{
    printf("No");
  }
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#define pai 3.1415926535

int main(void) {
	int N;
	scanf("%d", &N);
	char S[101];
	scanf("%s", S);
	int count = 0;
	for (int i = 0; i <= N; i++) {
		if (S[i] == S[N / 2 + i]) {
			count++;
		}
	}

	if(count==N/2){
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#define pai 3.1415926535

int main(void) {

	int N;
	int x[8], y[8];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &x[i], &y[i]);
	}
	double avg=0;
	int sum1 = 1;
	int sum2 = 1;
	for (int i = N; i > 1; i--) {
		sum1 *= i;
	}
	for (int i = N - 1; i > 1; i--) {
		sum2 *= i;
	}

	for (int i = 0; i < N; i++) {
		for (int j =i+1; j < N; j++) {
			avg += (sqrt((double)(x[j] - x[i])*(x[j] - x[i])+(y[j] - y[i])*(y[j] - y[i])))*2*sum2;
		}
	}
	printf("%f", avg/sum1);

	return 0;
}

Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387


#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int ans = 0;
    for(int i = 1; i < (n + 1) / 2; i++)
        if(i != n - i)
            ans ++;
    printf("%d\n",ans);
    return 0;
}

Score : 100 points

Problem Statement

How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Constraints

1 \leq N \leq 10^6

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

4

Sample Output 1

1

There is only one way to choose two distinct integers totaling 4: to choose 1 and 3. (Choosing 3 and 1 is not considered different from this.)

Sample Input 2

999999

Sample Output 2

499999


#include <stdio.h>

int main() {
    long long int n, ans = 1;
    scanf("%lld", &n);
    long long int d[n];
    for (long long int i = 0; i < n; i++){
        scanf("%lld", &d[i]);
        ans*=(d[i]?d[i]:1)%998244353;
    }
    printf("%lld\n", ans==1?0:ans%998244353);
}

Score : 300 points

Problem Statement

Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Notes

A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.

Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24


/* ex3-3
   Sagzar1993  */

#include <stdio.h>

int main(void) {
    //表す整数と基数を定義
    int num;

    //入力を受け取る
    scanf("%d", &num);

    //numが各数字で割り切れ、かつその商が１から９の間であるとき、Yesを表示
    if(num % 1 == 0 && num / 1 <= 9){
        printf("Yes\n");
    }else if(num % 2 == 0 && num / 2 <= 9){
        printf("Yes\n");
    }else if(num % 3 == 0 && num / 3 <= 9){
        printf("Yes\n");
    }else if(num % 4 == 0 && num / 4 <= 9){
        printf("Yes\n");
    }else if(num % 5 == 0 && num / 5 <= 9){
        printf("Yes\n");
    }else if(num % 6 == 0 && num / 6 <= 9){
        printf("Yes\n");
    }else if(num % 7 == 0 && num / 7 <= 9){
        printf("Yes\n");
    }else if(num % 8 == 0 && num / 8 <= 9){
        printf("Yes\n");
    }else if(num % 9 == 0 && num / 9 <= 9){
        printf("Yes\n");
    }else{
        printf("No\n"); //どれにも当てはまらなかった場合はNoを表示
    }
    return 0;
}

Score : 200 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.

Constraints

1 \leq N \leq 100

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.

Sample Input 1

10

Sample Output 1

Yes

10 can be represented as, for example, 2 \times 5.

Sample Input 2

50

Sample Output 2

No

50 cannot be represented as the product of two integers between 1 and 9.

Sample Input 3

81

Sample Output 3

Yes


/* ex3_4
        fmuacshai */

#include<stdio.h>

int main(void){
    //整数number、割る数div_number、商quotient
    int number,div_number,quotient;
    //numberの入力
    scanf("%d",&number);
    //div_numberの初期設定
    div_number=9;
    //余りが出なくなるまで計算
    while(number%div_number>0){
        div_number=div_number-1;
    }
    //quotientの計算
    quotient=number/div_number;
    //quotientが10未満ならYes、10以上ならNoと出力
    if(quotient<10){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


#include<stdio.h>

int main(void){
	int a = 0;
	int flag = 0;
	int i,j = 0;

	scanf("%d",&a);

	for(i = 1 ; i < 10;i++){

		for(j = 1;j < 10;j++){
			if((a / i > 0 && a / i <= 9) && j * (a/i) == a){
				flag = 1;
				break;
			}else{
			flag = 0;
			}
		}
		if(flag == 1) break;

	}

	if(flag == 1){
		printf("Yes");
	}else{
		printf("NO");
	}

	return 0;
}


#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    int i = 9;
    int c = 0;
    scanf("%d",&a);
    while(i >= 1){
        b = a / i;
        if(b < 10 && a%i == 0){
            c+=1;
            printf("Yes");
            break;
        }
        i--;
    }
    if(c == 0){
    printf("No");
    }
}


#include <stdio.h>

int main()
{
  int a,i,j;
  scanf("%d", &a);
  for(i=1;i<=9;i++)
    for(j=1;j<=9;j++)
      if(i*j==a){
        printf("Yes\n");
        return 0;
      }
  printf("No\n");
  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int compara(const void * a, const void * b){
  int x = *(int *) a;
  int y = *(int *) b;
  return x>y?1:x<y?-1:0;
}

void soma(int *v, int *r, int a){
  r[0] = 1;
  r[1] = 1;
  for (int i = 0; i < a; i++) {
    if (i>=(a+1)/2) {
      r[1]*=v[i];
    }else{
      r[0]*=v[i];
    }
  }
}

int dec(int *v,int num1) {
  int k=0,j,i;
  for (i = 2; i <= num1;) {
    if (num1%i==0) {
      v[k]=i;
      num1/=i;
      k++;
    }else{
      i++;
    }
  }
  qsort(v,k,sizeof(v[0]),compara);
  return k;
}

int main(int argc, char const *argv[]) {
  int a, b,j;
  scanf("%d",&a);
  int vec[a],r[2];
  int i = dec(vec,a);

  if (i>1) {
    soma(vec,r,i);

    if (r[0]>9 ||r[1] >9) {
      printf("No\n");
    }else{
      printf("Yes\n");
    }
  }else{
    if (r[0] >9) {
      printf("No\n");
    }else{
      printf("Yes\n");
    }
  }

  return 0;
}


#include <stdio.h>
int main(void){
    int a=0;
    scanf("%d",&a);
    //printf("a=%d\n",a);

    //素因数分解できるかを9から調べる
    int waretakazu=0;
    int i=0;
    for(i=9;i>=2;i--){
        if(a%i==0){
            waretakazu++;
            a=a/i;
            i++;
          //  printf("i=%d,a=%d\n",i,a);
        }

    }
    //printf("waretakazu=%d\n",waretakazu);

    if(waretakazu<=2&&a==1){
        printf("Yes");
    }else{
        printf("No");
    }
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)

//your code here!

int main(void){
    ll N;
    scanf("%lld", &N);
    ll n=N, ans=1e15;
    for(ll i=2; i*i<=n; i++) {
        if(n%i==0) {
            ll cnt=1;
            do{
                n /= i;
                ll x=power(i, cnt++);
                chmin(ans, x + N/x);
            }while(n%i==0);
        }
    }
    if(n>1) chmin(ans, n + N/n);
    printf("%lld\n", ans-2);
    return 0;
}

Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.


#include <stdio.h>
#include <math.h>

int main(void)
{
    double a,b,x,th;
    scanf("%lf %lf %lf", &a, &b, &x);
    if(a*a*b<=2*x) {
        th = atan(2*(b/a-x/a/a/a));
    } else {
        th = atan(a*b*b/2/x);
    }
    printf("%.10lf\n", th/asin(1)*90);
    return 0;
}

Score : 400 points

Problem Statement

Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.)

We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.

When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.

Constraints

All values in input are integers.

1 \leq a \leq 100

1 \leq b \leq 100

1 \leq x \leq a^2b

Input

Input is given from Standard Input in the following format:

a b x

Output

Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees.
Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

2 2 4

Sample Output 1

45.0000000000

This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees.

Sample Input 2

12 21 10

Sample Output 2

89.7834636934

This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.

Sample Input 3

3 1 8

Sample Output 3

4.2363947991

This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.


#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int rea =a- (b*2);
    if (rea<0)
        rea=0;
    printf ("%d\n",rea);
}

Score : 100 points

Problem Statement

The window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)

We will close the window so as to minimize the total horizontal length of the uncovered part of the window.
Find the total horizontal length of the uncovered parts of the window then.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the total horizontal length of the uncovered parts of the window.

Sample Input 1

12 4

Sample Output 1

4

We have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.

Sample Input 2

20 15

Sample Output 2

0

If the window is completely covered, print 0.

Sample Input 3

20 30

Sample Output 3

0

Each curtain may be longer than the window.


#include<stdio.h>

int main(void){
  int a=0,b=0;
  scanf("%d %d",&a,&b);
  if(a-2*b>0)
    printf("%d",a-2*b);
  else
    printf("0");
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
  int n,i,j,ans=0;
  int *a;

  scanf("%d",&n );

  a = calloc(n,sizeof(int));

  for(i=0; i<n; i++)
    scanf("%d", &a[i]);

  for(i=0; i<n-1; i++){
    for(j=i+1; j<n; j++){
      ans += a[i]*a[j];
    }
  }
  printf("%d", ans);
  free(a);
  return 0;
}

Score : 200 points

Problem Statement

It's now the season of TAKOYAKI FESTIVAL!

This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.

As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points.

There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values.

Constraints

All values in input are integers.

2 \leq N \leq 50

0 \leq d_i \leq 100

Input

Input is given from Standard Input in the following format:

N
d_1 d_2 ... d_N

Output

Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served.

Sample Input 1

3
3 1 2

Sample Output 1

11

There are three possible choices:

Eat the first and second takoyaki. You will restore 3 health points.

Eat the second and third takoyaki. You will restore 2 health points.

Eat the first and third takoyaki. You will restore 6 health points.

The sum of these values is 11.

Sample Input 2

7
5 0 7 8 3 3 2

Sample Output 2

312


#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
	int n, cnt = 1;

	scanf("%d\n", &n);
	char pc = getchar();
	for (size_t i = 1; i < n; i++)
	{
		char c = getchar();
		if (pc!=c)
		{
			cnt++;
			pc = c;
		}
	}

	printf("%d", cnt);
}

Score : 300 points

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

1 \leq N \leq 10^5

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Sample Input 1

10
aabbbbaaca

Sample Output 1

5

Ultimately, these slimes will fuse into abaca.

Sample Input 2

5
aaaaa

Sample Output 2

1

All the slimes will fuse into one.

Sample Input 3

20
xxzaffeeeeddfkkkkllq

Sample Output 3

10


#include <stdio.h>
#include <stdlib.h>
int main(void) {
int N;
char S[10000]={'\0'};
scanf("%d",&N);
scanf("%s",S);
int i=0;
int count=1;

while (i<N-1){
    if (S[i]==S[i+1]) {i++;}
    else if (S[i]!=S[i+1]) {count++;i++;}
}
printf("%d",count);
 return EXIT_SUCCESS;
}


#include <stdio.h>

int main(void) {
    int n, count = 1;
    scanf("%d", &n);
    char s[n+1], t;
    scanf("%s", s);
    t = s[0];
    for(int i = 0; i < n; i++) {
        if(t != s[i]) {
            t = s[i];
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23


#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int merge(long int a1[], long int a2[], long int a1_size, long int a2_size, long int a[]);
int mergeSort(long int a[], long int number);

int main(void)
{
	long int n;
	long int count;
	long int i, j, k;
	long int work;
	long int flg;
	long int l[2000];

	scanf("%ld", &n);

	for(i = 0; i < n; i++) {
		scanf("%ld", &l[i]);
	}

	mergeSort(l, n);
	/*
	for(i = 0; i < n; i++) {
		printf("%ld\n", l[i]);
	}
	*/

	count = 0;

	for(i = 0; i < n - 2; i++) {
		flg = 0;
		for(j = i + 1; j < n - 1; j++) {
			if(i == j) {
				continue;
			}
			for(k = j + 1; k < n; k++) {
				if( (i == k) || (j == k) ) {
					continue;
				}
				if(l[i] < l[j] + l[k]) {
					count++;
				} else {
					if(k == j + 1) {
						flg = 1;
					}
					break;
				}
			}
			if(flg) {
				break;
			}
		}
	}

	printf("%ld\n", count);

	return 0;
}

int merge(long int a1[], long int a2[], long int a1_size, long int a2_size, long int a[])
{
	long int i = 0, j = 0;

	while( (i < a1_size ) || (j < a2_size) ){
		if( (j >= a2_size ) || ( (i < a1_size) && (a1[i] > a2[j]) ) ) {
			a[i + j] = a1[i];
			i++;
		} else {
			a[i + j] = a2[j];
			j++;
		}
	}

	return 0;
}

int mergeSort(long int a[], long int number)
{
	long int m = number / 2, n = number - m;
	long int a1[m];
	long int a2[n];
	int i, j;

	if(number > 1) {
		for(i = 0; i < m; i++) {
			a1[i] = a[i];
		}
		for(i = 0; i < n; i++) {
			a2[i] = a[m + i];
		}
		mergeSort(a1, m);
		mergeSort(a2, n);
		merge(a1, a2, m, n, a);
	}

	return 0;
}


#include <stdio.h>

int main(){

  //人数 N, 制限身長 K, それぞれのメンバーの身長 h[i]
  int i;
  int N;
  int K;

  scanf("%d %d", &N, &K);
  int h[N];

  for(i = 1; i <= N; i++){

    scanf("%d", &h[i - 1]);
  }

  int count = 0;
  //h の値を K と比較し，K 以上であればカウントを一つ増やす
  for(i = 1; i <= N; i++){

    if(h[i - 1] >= K){
      count++;
    }
  }

  printf("%d", count);

  return 0;
}

Score : 100 points

Problem Statement

Given is an integer N.

Takahashi chooses an integer a from the positive integers not greater than N with equal probability.

Find the probability that a is odd.

Constraints

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the probability that a is odd.
Your output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

4

Sample Output 1

0.5000000000

There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \frac{2}{4} = 0.5.

Sample Input 2

5

Sample Output 2

0.6000000000

Sample Input 3

1

Sample Output 3

1.0000000000


#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);

    if(n%2 == 0) printf("%lf",(double)1/(double)2);
    if(n%2 == 1) printf("%lf",(double)(n/2+1)/(double)n);

    return 0;
}


#include <stdio.h>
int main()
{
    long long n;
    scanf("%lli",&n);
    long long a[n];
    long long t[n];
    for (int i=0;i<n;i++) {
        t[i] = 0;
    }
    long long tmp;
    for (long long i=0;i<n;i++) {
        scanf("%lli",&a[i]);
        tmp = a[i];
        t[tmp-1] = i+1;
    }
    for(int i=0;i<n;i++) {
        printf("%lli ",t[i]);
    }
    return 0;
}

Score : 300 points

Problem Statement

Takahashi is a teacher responsible for a class of N students.

The students are given distinct student numbers from 1 to N.

Today, all the students entered the classroom at different times.

According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).

From these records, reconstruct the order in which the students entered the classroom.

Constraints

1 \le N \le 10^5

1 \le A_i \le N

A_i \neq A_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the student numbers of the students in the order the students entered the classroom.

Sample Input 1

3
2 3 1

Sample Output 1

3 1 2

First, student number 3 entered the classroom.

Then, student number 1 entered the classroom.

Finally, student number 2 entered the classroom.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

1 2 3 4 5

Sample Input 3

8
8 2 7 3 4 5 6 1

Sample Output 3

8 2 4 5 6 7 3 1


#include <stdio.h>
#define ll long long
ll gcd(ll p,ll q){while(q){ll t=p%q;p=q;q=t;}return p;}
int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll d=gcd(a,b);
	int ans=1;
	for(ll i=2;i*i<=d;i++)if(d%i==0){
		ans++;
		while(d%i==0)d/=i;
	}
	printf("%d",ans+(d!=1));
}

Score : 400 points

Problem Statement

Given are positive integers A and B.

Let us choose some number of positive common divisors of A and B.

Here, any two of the chosen divisors must be coprime.

At most, how many divisors can we choose?

Definition of common divisor

An integer d is said to be a common divisor of integers x and y when d divides both x and y.

Definition of being coprime

Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.

Definition of dividing

An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Constraints

All values in input are integers.

1 \leq A, B \leq 10^{12}

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of divisors that can be chosen to satisfy the condition.

Sample Input 1

12 18

Sample Output 1

3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.

1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.

Sample Input 2

420 660

Sample Output 2

4

Sample Input 3

1 2019

Sample Output 3

1

1 and 2019 have no positive common divisors other than 1.


#include"stdio.h"
#include"stdlib.h"
int gcd( int A, int B){
  if( A>B ){
    return gcd( A-B, B);
  }
  else if( B>A ){
    return gcd( A, B-A);
  }
  else{
    return A;
  }
}
int* divisor(int num){
  int i,j=0;
  int* list = (int*) calloc(1000,sizeof(int));
  for(i=1;i<=num;i++){
    if(num%i == 0){
      list[j++] = i;
    }
  }
  return list;
}
int main(void){
  int A,B,C,i,j,count,ct=0;
  int flag=1;
  int* list;
  scanf("%d %d",&A,&B);
  C = gcd( A, B);

  // output'C' is max gcd(A,B)
  //printf("C:%d\n",C);

  // list is sosuu
  list = divisor(C);
  for(i=0; list[i]!=0;i++){
    //printf("list[%d]:%d ", i, list[i]);
  }
  count=i;
  //printf("count:%d\n",count);

  for( i=0; i<count; i++){
    for( j=2; j<list[i]; j++){
      if( list[i]%j==0 ){
        flag=0;
        break;
      }
    }
    if( flag==1 ){
      //printf("list[%d]:%d\n", i, list[i]);
      ct++;
    }
    flag=1;
  }

  printf("%d\n", ct);
  free(list);
  return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int A, B,x,min,Ans=0;
	scanf("%d %d", &A, &B);

	if (A >= B) min = B;
	else min = A;

	for (x = min; x > 0; x--) {

		int  t, m = 0;

		if (x >= 4) {
			for (t = 2; t < x; t++) {
				if (x % t == 0) {
					m++; //素数にならないものはmを1以上にする
					break;
				}
			}
		}
		if (A % x == 0 && B % x == 0 && m==0) Ans++;
	}
	printf("%d", Ans);
}


#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
#define SWAP(type, a, b) { const type tmp = a; a = b; b = tmp; }

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_u64_asc(const void* a, const void* b) {
    return *((uint64_t*)a) < *((uint64_t*)b) ? -1 : 1;
}

int compare_u64_desc(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

int compare_dp_asc(const void* a, const void* b) {
    return *((double*)a) < *((double*)b) ? -1 : 1;
}

static uint64_t modinvU64(const uint64_t a, const uint64_t m) {
    int64_t aa = (int64_t)a;
    const int64_t mm = (int64_t)m;
    int64_t b = mm;
    int64_t u = 1;
    int64_t v = 0;

    while (b != 0) {
        const int64_t t = aa / b;

        aa -= t * b;
        SWAP(uint64_t, aa, b);
        u -= t * v;
        SWAP(uint64_t, u, v);
    }

    u %= mm;
    if (u < 0) {
        u += m;
    }

    return (uint64_t)u;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64WMod(const uint64_t n, const uint64_t r, const uint64_t m) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result = result * (n - i) % m;
        result = result * modinvU64(i + 1, m) % m;
    }

    return result;
}

static uint64_t permU64WMod(const uint64_t n, const uint64_t m) {
    uint64_t result = 1;

    for (uint64_t v = 2; v <= n; v++) {
        result *= v;
        result %= m;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

typedef struct {
    uint64_t val;
}BHeap_Val;

#define BHEAP_VAL_TYPE BHeap_Val

#define BHEAP_INVALID_NODE ((size_t)100000000)

typedef struct {
    BHEAP_VAL_TYPE val;
} BHeap_Node;

struct _BHeap_Ctx {
    size_t size;
    int (*compare)(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node);
    void(*notifyNodeChange)(const struct _BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList);
    BHeap_Node* node;
};

typedef struct _BHeap_Ctx BHeap_Ctx;

static void bHeap_Init(BHeap_Ctx* const ctx, int(*compare)(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node), void(*notifyNodeChange)(const BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList), BHeap_Node* const nodes) {
    ctx->size = 0;
    ctx->compare = compare;
    ctx->notifyNodeChange = notifyNodeChange;
    ctx->node = nodes;
}

static void bHeap_Swap(BHeap_Ctx* const ctx, const size_t node0, const size_t node1) {
    const BHEAP_VAL_TYPE tmp = ctx->node[node0].val;
    ctx->node[node0].val = ctx->node[node1].val;
    ctx->node[node1].val = tmp;

    if (ctx->notifyNodeChange != NULL) {
        const size_t nodeList[2] = { node0,node1 };
        ctx->notifyNodeChange(ctx, 2, nodeList);
    }
}

static void bHeap_UpHeap(BHeap_Ctx* const ctx, const size_t nodeIdx) {
    if (nodeIdx == 0) {
        return;
    }

    const size_t parentIdx = (nodeIdx + 1) / 2 - 1;

    const int compareResult = ctx->compare(&(ctx->node[parentIdx].val), &(ctx->node[nodeIdx].val));

    if (0 < compareResult) {
        bHeap_Swap(ctx, nodeIdx, parentIdx);

        if (parentIdx != 0) {
            bHeap_UpHeap(ctx, parentIdx);
        }
    }
}

static void bHeap_DownHeap(BHeap_Ctx* const ctx, const size_t nodeIdx) {
    if (ctx->size - 1 <= nodeIdx) {
        return;
    }

    const size_t leftIdx = 2 * (nodeIdx + 1) - 1;

    if (leftIdx < ctx->size) {
        const int leftResult = ctx->compare(&(ctx->node[nodeIdx].val), &(ctx->node[leftIdx].val));

        size_t swapTarget = leftResult < 0 ? BHEAP_INVALID_NODE : leftIdx;

        const size_t rightIdx = leftIdx + 1;

        if (rightIdx < ctx->size) {
            const int rightResult = ctx->compare(&(ctx->node[nodeIdx].val), &(ctx->node[rightIdx].val));

            if (swapTarget == BHEAP_INVALID_NODE) {
                if (0 < rightResult) {
                    swapTarget = rightIdx;
                }
            }
            else {
                if (0 < rightResult) {
                    const int rightLeftResult = ctx->compare(&(ctx->node[leftIdx].val), &(ctx->node[rightIdx].val));

                    if (0 < rightLeftResult) {
                        swapTarget = rightIdx;
                    }
                }
            }
        }

        if (swapTarget != BHEAP_INVALID_NODE) {
            bHeap_Swap(ctx, nodeIdx, swapTarget);

            bHeap_DownHeap(ctx, swapTarget);
        }
    }
}

static void bHeap_Add(BHeap_Ctx* const ctx, const BHEAP_VAL_TYPE val) {
    ctx->node[ctx->size].val = val;

    ctx->size++;

    if (ctx->notifyNodeChange != NULL) {
        const size_t node = ctx->size - 1;
        ctx->notifyNodeChange(ctx, 1, &node);
    }

    bHeap_UpHeap(ctx, ctx->size - 1);
}

static void bHeap_RemoveTop(BHeap_Ctx* const ctx) {
    if (ctx->size == 0) {
        return;
    }

    if (ctx->size == 1) {
        ctx->size--;
        return;
    }

    ctx->node[0].val = ctx->node[ctx->size - 1].val;

    if (ctx->notifyNodeChange != NULL) {
        const size_t node = 0;
        ctx->notifyNodeChange(ctx, 1, &node);
    }

    ctx->size--;

    bHeap_DownHeap(ctx, 0);
}

static void bHeap_RemoveNode(BHeap_Ctx* const ctx, const size_t node) {
    if (node == ctx->size - 1) {
        ctx->size--;
    }
    else {
        ctx->node[node].val = ctx->node[ctx->size - 1].val;

        ctx->size--;

        if (ctx->notifyNodeChange != NULL) {
            ctx->notifyNodeChange(ctx, 1, &node);
        }

        bHeap_DownHeap(ctx, node);
        bHeap_UpHeap(ctx, node);
    }
}

static BHEAP_VAL_TYPE* bHeap_GetTopVal(const BHeap_Ctx* const ctx) {
    return ctx->size == 0 ? NULL : &(ctx->node[0].val);
}

typedef struct {
    uint64_t cnt;
    size_t* child;
    size_t numChild;
    size_t maxNumChild;
} Tree_Node;

#define TREE_INIT_ALLOC (128)

static Tree_Node tree_Node[200000];

static void tree_Init(const uint64_t N) {
    for (uint64_t i = 0; i < N; i++) {
        tree_Node[i].cnt = 0;
        tree_Node[i].numChild = 0;
        tree_Node[i].child = malloc(sizeof(size_t) * TREE_INIT_ALLOC);
        tree_Node[i].maxNumChild = TREE_INIT_ALLOC;
    }
}

static void tree_AddChild(const size_t parent, const size_t child) {
    if (tree_Node[parent].maxNumChild <= tree_Node[parent].numChild) {
        tree_Node[parent].child = realloc(tree_Node[parent].child, sizeof(size_t) * tree_Node[parent].maxNumChild * 2);
        tree_Node[parent].maxNumChild *= 2;
    }

    tree_Node[parent].child[tree_Node[parent].numChild] = child;
    tree_Node[parent].numChild++;
}

static BHeap_Node BN_Asc[200000];
static BHeap_Node BN_Desc[200000];

static int _bHeap_Compare_Asc(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node) {
    return parent->val <= node->val ? -1 : 1;
}

static int _bHeap_Compare_Desc(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node) {
    return parent->val >= node->val ? -1 : 1;
}

static size_t PBHeap_Asc_Idx[200000];
static size_t PBHeap_Desc_Idx[200000];

static void _bHeap_NotifyNodeChange_Asc(const BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList) {
    for (size_t i = 0; i < nodeListSize; i++) {
        PBHeap_Asc_Idx[ctx->node[nodeList[i]].val.val] = nodeList[i];
    }
}

static void _bHeap_NotifyNodeChange_Desc(const BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList) {
    for (size_t i = 0; i < nodeListSize; i++) {
        PBHeap_Desc_Idx[ctx->node[nodeList[i]].val.val] = nodeList[i];
    }
}

#define MOD_VAL (UINT64_C(1000000007))

static uint64_t cnt[2][1000001];

int main(void) {
    uint64_t A, B;

    scanf("%"PRIu64"%"PRIu64, &A, &B);

    for (uint64_t i = 0; i <= 1000000; i++) {
        cnt[0][i] = 0;
        cnt[1][i] = 0;
    }

    uint64_t divisor = 2;
    while (1 < A) {
        if (A % divisor == 0) {
            cnt[0][divisor]++;

            A /= divisor;
        }
        else {
            divisor++;
        }
    }

    divisor = 2;

    uint64_t res = 0;

    while (1 < B) {
        if (B % divisor == 0) {
            cnt[1][divisor]++;

            B /= divisor;
        }
        else {
            if (0 < cnt[0][divisor] && 0 < cnt[1][divisor]) {
                res++;
            }

            divisor++;
        }
    }

    printf("%"PRIu64, res + 1);

    return 0;
}


#include<stdio.h>

int main(){
  char S[6];
  scanf("%s",S);
  if(S[0]=='S')
    printf("Cloudy\n");
  else if(S[0]=='R')
    printf("Sunny\n");
  else
    printf("Rainy\n");

  return 0;
}

Score: 100 points

Problem Statement

The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...

Given is a string S representing the weather in the town today. Predict the weather tomorrow.

Constraints

S is Sunny, Cloudy, or Rainy.

Input

Input is given from Standard Input in the following format:

S

Output

Print a string representing the expected weather tomorrow, in the same format in which input is given.

Sample Input 1

Sunny

Sample Output 1

Cloudy

In Takahashi's town, a sunny day is followed by a cloudy day.

Sample Input 2

Rainy

Sample Output 2

Sunny


#include <stdio.h>

int main() {
     char dance[101];
     scanf("%s", dance);
     for (int i = 0; i != '\0'; i++) {

          if ((i+1)%2 != 0) {
               if (dance[i] == 'L' || dance[i] == 'U' || dance[i] == 'D') {
                    continue;
               } else {
                    printf("No\n");
                    return 0;
               }
          }
          else {
               if (dance[i] == 'R' || dance[i] == 'U' || dance[i] == 'D') {
                    continue;
               } else {
                    printf("No\n");
                    return 0;
               }
          }

     }
     printf("Yes\n");

     return 0;
}

Score: 200 points

Problem Statement

Takahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.

S is said to be easily playable if and only if it satisfies both of the following conditions:

Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is R, U, or D.

Every character in an even position (2-nd, 4-th, 6-th, \ldots) is L, U, or D.

Your task is to print Yes if S is easily playable, and No otherwise.

Constraints

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

Each character of S is L, R, U, or D.

Input

Input is given from Standard Input in the following format:

S

Output

Print Yes if S is easily playable, and No otherwise.

Sample Input 1

RUDLUDR

Sample Output 1

Yes

Every character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D.

Every character in an even position (2-nd, 4-th, 6-th) is L, U, or D.

Thus, S is easily playable.

Sample Input 2

DULL

Sample Output 2

No

The 3-rd character is not R, U, nor D, so S is not easily playable.

Sample Input 3

UUUUUUUUUUUUUUU

Sample Output 3

Yes

Sample Input 4

ULURU

Sample Output 4

No

Sample Input 5

RDULULDURURLRDULRLR

Sample Output 5

Yes


#include <stdio.h>
#include <math.h>

int main(void){
    int n;

    scanf("%d", &n);

    printf("%d\n", (int)pow(n, 3));

    return 0;
}

Score : 100 points

Problem Statement

Takahashi is going to set a 3-character password.

How many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)?

Constraints

1 \leq N \leq 9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of possible passwords.

Sample Input 1

2

Sample Output 1

8

There are eight possible passwords: 111, 112, 121, 122, 211, 212, 221, and 222.

Sample Input 2

1

Sample Output 2

1

There is only one possible password if you can only use one kind of character.


#include <stdio.h>

int main(){
	int N;
  	scanf("%d", &N);
  	printf("%d", N*N*N);
}


#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    printf("%d\n",2<<(n-1));
    return 0;
}


#include<stdio.h>
int main(){
  int a,b;

  scanf("%d",&a);
  b=a*a*a;
  printf("%d",b);
  return 0;}


#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int a=1;
    int i;
    for(i=0;i<n;i++){
        a=a*3;
    }
    printf("%d",a);
    return 0;
}


#include<stdio.h>
int main()
{
 int n;
 scanf("%d",&n);
 int a[n],b[n],c[n-1];

 for(int i=0;i<n;i++)
 scanf("%d",&a[i]);

 for(int i=0;i<n;i++)
 scanf("%d",&b[i]);

 for(int i=0;i<n-1;i++)
 scanf("%d",&c[i]);

 int count=0;

for(int i=0;i<n;i++)
{
    count+=b[a[i]-1];

}
for(int i=1;i<n;i++)
{
    if(a[i]-1==a[i-1])
        count+=c[a[i-1]-1];
}
printf("%d",count);
}

Score : 200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

A_1, A_2, ..., A_N are all different.

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

First, he ate Dish 3 and gained 4 satisfaction points.

Next, he ate Dish 1 and gained 2 satisfaction points.

Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.

Sample Input 2

4
2 3 4 1
13 5 8 24
45 9 15

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150


#include <stdio.h>

int main(void) {
	int A[20];
	int B[50];
	int C[50];
	int N;
	char As[100];
	char Bs[100];
	char Cs[100];
	scanf("%d\n", &N);
	fgets(As, 150, stdin);
	fgets(Bs, 150, stdin);
	fgets(Cs, 150, stdin);
	int i = N;
	while (i > 0) {
		sscanf(As + 2*(N - i), "%d", &A[N - i]);
		i--;
	}
	i = N;
	while (i > 0) {
		sscanf(Bs + 2*(N - i), "%d", &B[N - i]);
		i--;
	}
	i = N - 1;
	while (i > 0) {
		sscanf(Cs + 2*(N - i - 1), "%d", &C[N - i - 1]);
		i--;
	}
	int sum = 0;
	int prev = -1;
	for (int i = 0; i < N; i++) {
		sum += B[A[i] - 1];
		if (prev == A[i] - 1) {
			sum += C[prev - 1];
		}
		prev = A[i];
	}
	printf("%d", sum);
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
    int n;
    int a[50]={0},b[50]={0},c[50]={0};
    int point = 0, bonus = 0, sumPoint = 0;

    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        scanf("%d ",&a[i]);
        // printf("%3d ",a[i]);
    }
    // printf("\n");
    for(int i = 1; i <= n; i++){
        scanf("%d ",&b[i]);
        //  printf("%3d ",b[i]);
        point += b[i];
    }
    // printf("\n");
    for(int i = 1; i <= n; i++){
        scanf("%d ",&c[i]);
        //  printf("%3d ",c[i]);
        bonus += c[i];
    }
    // printf("\n");

    sumPoint = point + bonus - c[a[n]];
    //  printf("%d %d/n",a[n-1],c[a[n-1]-1]);
    printf("%d",sumPoint);

}


#include <stdio.h>

int main(void)
{
        char s[4],t[4];
        int c=0;

        scanf("%s%s",s,t);
        for(int i=0;i<3;i++){
                if(s[i]==t[i]) c++;
        }
        printf("%d\n",c);
        return 0;
}

Score : 100 points

Problem Statement

You will be given a string S of length 3 representing the weather forecast for three days in the past.

The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.

You will also be given a string T of length 3 representing the actual weather on those three days.

The i-th character (1 \leq i \leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.

Print the number of days for which the forecast was correct.

Constraints

S and T are strings of length 3 each.

S and T consist of S, C, and R.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the number of days for which the forecast was correct.

Sample Input 1

CSS
CSR

Sample Output 1

2

For the first day, it was forecast to be cloudy, and it was indeed cloudy.

For the second day, it was forecast to be sunny, and it was indeed sunny.

For the third day, it was forecast to be sunny, but it was rainy.

Thus, the forecast was correct for two days in this case.

Sample Input 2

SSR
SSR

Sample Output 2

3

Sample Input 3

RRR
SSS

Sample Output 3

0


#include <stdio.h>
#include <string.h>

int main(void){
    //input
    char S[3];
    scanf("%s",S);
    char T[3];
    scanf("%s",T);

    //calu
    int count = 0;
    for(int i = 0;i < 3; i++){
        if(strncmp(&S[i],&T[i],1)==0){
            count++;
        }
    }

    //output
    printf("%d",count);
    return 0;
}


Score : 200 points

Problem Statement

Takahashi's house has only one socket.

Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.

One power strip with A sockets can extend one empty socket into A empty sockets.

Find the minimum number of power strips required.

Constraints

All values in input are integers.

2 \leq A \leq 20

1 \leq B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of power strips required.

Sample Input 1

4 10

Sample Output 1

3

3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.

Sample Input 2

8 9

Sample Output 2

2

2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.

Sample Input 3

8 8

Sample Output 3

1


#include <stdio.h>
int main(){
	int a;
	scanf("%d",&a);
	int b;
	scanf("%d",&b);
	b -= a;
	if(b <= 0){
		printf("1");
		return 0;
		}
		int count = 1;
	while(1){
		if(b > 0){
		   b -= (a - 1);
		   count++;
		   }

		if(b <= 0)break;
		 }
		 printf("%d",count);
     return 0;
}


#include <stdio.h>

int main(void) {
	int A,B;
	int count=1,ans;
	scanf("%d %d",&A,&B);
	if(A==B){
		printf("1\n");
	}else{
  	ans=A;
  	while(ans<=B){
  	if(ans<=B){
  		ans+=A-1;
  		count++;
  	}
	}
		printf("%d",count);
	}
	return 0;
}


#include <stdio.h>

int main(){
    int i=1, a, c, b;

    scanf("%d %d", &a, &b);
    c=a;
    if(a>=b){
        printf("%d\n", i);
    }
    else{
        for(i;c<b;++i){
            c+=a-1;
        }
        printf("%d\n", i);
    }
    return 0;
}


#include<stdio.h>

int main(){
    long long int N,max;
    scanf("%lld",&N);
    max = N*(N-1)/2;
    printf("%lld",max);
    return 0;
}

Score : 400 points

Problem Statement

For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}.

Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.

Find the maximum possible value of M_1 + M_2 + \cdots + M_N.

Constraints

N is an integer satisfying 1 \leq N \leq 10^9.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible value of M_1 + M_2 + \cdots + M_N.

Sample Input 1

2

Sample Output 1

1

When the permutation \{P_1, P_2\} = \{2, 1\} is chosen, M_1 + M_2 = 1 + 0 = 1.

Sample Input 2

13

Sample Output 2

78

Sample Input 3

1

Sample Output 3

0


Score : 500 points

Problem Statement

N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.

The tournament is round-robin format, and there will be N(N-1)/2 matches in total.
Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.

Each player plays at most one matches in a day.

Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.

Constraints

3 \leq N \leq 1000

1 \leq A_{i, j} \leq N

A_{i, j} \neq i

A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.

Input

Input is given from Standard Input in the following format:

N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}

Output

If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.

Sample Input 1

3
2 3
1 3
1 2

Sample Output 1

3

All the conditions can be satisfied if the matches are scheduled for three days as follows:

Day 1: Player 1 vs Player 2

Day 2: Player 1 vs Player 3

Day 3: Player 2 vs Player 3

This is the minimum number of days required.

Sample Input 2

4
2 3 4
1 3 4
4 1 2
3 1 2

Sample Output 2

4

All the conditions can be satisfied if the matches are scheduled for four days as follows:

Day 1: Player 1 vs Player 2, Player 3 vs Player 4

Day 2: Player 1 vs Player 3

Day 3: Player 1 vs Player 4, Player 2 vs Player 3

Day 4: Player 2 vs Player 4

This is the minimum number of days required.

Sample Input 3

3
2 3
3 1
1 2

Sample Output 3

-1

Any scheduling of the matches violates some condition.


#include <stdio.h>

int main(void)
{
  int i, n, a[n];
  double result = 0;
  scanf("%d", &n);
  for( i = 0; i < n; i++ ){
    scanf("%d", &a[i]);
  }

  for( i = 0; i < n; i++ ){
    result += 1 / (double)a[i];
  }

  printf("%lf\n", 1/result);
  return 0;
}

Score : 200 points

Problem Statement

Given is a sequence of N integers A_1, \ldots, A_N.

Find the (multiplicative) inverse of the sum of the inverses of these numbers, \frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}.

Constraints

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 \ldots A_N

Output

Print a decimal number (or an integer) representing the value of \frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}.

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

Sample Input 1

2
10 30

Sample Output 1

7.5

\frac{1}{\frac{1}{10} + \frac{1}{30}} = \frac{1}{\frac{4}{30}} = \frac{30}{4} = 7.5.

Printing 7.50001, 7.49999, and so on will also be accepted.

Sample Input 2

3
200 200 200

Sample Output 2

66.66666666666667

\frac{1}{\frac{1}{200} + \frac{1}{200} + \frac{1}{200}} = \frac{1}{\frac{3}{200}} = \frac{200}{3} = 66.6666....

Printing 6.66666e+1 and so on will also be accepted.

Sample Input 3

1
1000

Sample Output 3

1000

\frac{1}{\frac{1}{1000}} = 1000.

Printing +1000.0 and so on will also be accepted.


/* ABC138-B
   Takatan */

#include<stdio.h>
int main(void){
    int number, i;
    double answer, a;
    answer = 0;

    scanf( "%d" , &number);
    for(i=0; i < number; i++){
        scanf( "%lf" , &a);
        answer += 1 / a; /* 逆数にして加算 */
    }
    answer = 1 / answer; /* 逆数の総和の逆数をとる */
    printf( "%f\n" , answer);
    return 0;
}


#include <stdio.h>

int main(){
  int N,i;
  scanf("%d", &N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d", &A[i]);
  }
  double bunbo=0,bunsi=1,seki=1;
  for(i=0;i<N;i++){
    bunsi = bunsi*A[i];
  }
  for(i=0;i<N;i++){
    seki = seki*A[i];
  }
  for(i=0;i<N;i++){
    bunbo += seki/A[i];
  }
  printf("%le\n", bunsi/bunbo);
}


#include<stdio.h>
int main(){
  int n, i, a;
  double sum = 0.0, ans;
  scanf("%d", &n);
  for(i = 0; i < n; ++i){
    scanf("%d", &a);
    sum += 1 / a;
  }
  ans = 1 / sum;
  printf("%f", ans);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}

int main(void) {
    int N;
scanf("%d",&N);
int array[N];

for (int i=0;i<N;i++)
scanf("%d",&array[i]);
 qsort(array, N, sizeof(int), cmpfunc);
 int i=0;
 float sum = (float)(array[i]+array[i+1])/2;
for (int i=1;i<N-1;i++){
    sum=(sum+(float)array[i+1])/2;
}
printf("%.10f",sum);
return EXIT_SUCCESS;
}

Score : 300 points

Problem Statement

You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i.

When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.

After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Constraints

2 \leq N \leq 50

1 \leq v_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
v_1 v_2 \ldots v_N

Output

Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

Sample Input 1

2
3 4

Sample Output 1

3.5

If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.

Printing 3.50001, 3.49999, and so on will also be accepted.

Sample Input 2

3
500 300 200

Sample Output 2

375

You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:

Use the ingredients of values 500 and 300 to produce an ingredient of value (500 + 300) / 2 = 400. The next composition will use this ingredient and the ingredient of value 200, resulting in an ingredient of value (400 + 200) / 2 = 300.

Use the ingredients of values 500 and 200 to produce an ingredient of value (500 + 200) / 2 = 350. The next composition will use this ingredient and the ingredient of value 300, resulting in an ingredient of value (350 + 300) / 2 = 325.

Use the ingredients of values 300 and 200 to produce an ingredient of value (300 + 200) / 2 = 250. The next composition will use this ingredient and the ingredient of value 500, resulting in an ingredient of value (250 + 500) / 2 = 375.

Thus, the maximum possible value of the last ingredient remaining is 375.

Printing 375.0 and so on will also be accepted.

Sample Input 3

5
138 138 138 138 138

Sample Output 3

138


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main(void){
	int N,i,j,v[55],temp,max=0,submax=0;
  	double ans;
  	scanf("%d",&N);
  	for(i=0;i<N;i++){
      scanf("%d",&v[i]);
    }
      /* sort */
      for(i=0;i<N-1;i++){
		for(j=i+1;j<N;j++){
          if(v[i]>v[j]){
            temp = v[i];
            v[i] = v[j];
            v[j] = temp;
          }
        }
      }
      /* sort */
  submax= v[i-1];
  max = v[i];

  ans = (v[0]+v[1])/(double)2.0;
  if(N>=3){
  	for(i=2;i<=N-1;i++){
 	   ans = (ans + v[i])/(double)2.0;
 	 }
  }
  if(N%2==0 && ans<(v[N-1]+v[N-2])/(double)2.0){
    printf("%f",(v[N-1]+v[N-2])/(double)2.0);
  }else{
     printf("%f",ans);
  }
}


#include <stdio.h>
#include <stdlib.h>

int main( void ){
  int N, n, flag;
  double buf, ans;
  double* v;

  scanf("%d", &N);

  v = (double*)malloc(sizeof(double) * N);

  for(int i = 0; i < N; i++){
    scanf("%lf", &v[i]);
  }

  n = N;
  do{
    flag = 0;
    n--;
    for(int i = 0; i < n; i++){
      if(v[i] > v[i+1]){
        buf = v[i];
        v[i] = v[i+1];
        v[i+1] = buf;
        flag = 1;
      }
    }
  }while(flag == 1);

  ans = v[0];
  for(int i = 1; i < N; i++){
    ans += v[i];
    ans /= 2.0;
  }

  printf("%lf\n", ans);

  free(v);

  return 0;
}


#include<stdio.h>
int main ()
{
 int A,B,a,b,c;
 scanf ("%d %d",&A,&B);
 a=A+B;
 b=A-B;
 c=A*B;
     if (a>=b&&a>=c)
     {
         printf ("%d\n",a);
     }
   else if (b>=a&&b>=c)
     {
         printf ("%d\n",b);
     }
    else
     {
         printf ("%d\n",c);
     }
 return 0;
}

Score : 100 points

Problem Statement

We have two integers: A and B.

Print the largest number among A + B, A - B, and A \times B.

Constraints

All values in input are integers.

-100 \leq A,\ B \leq 100

Input

Input is given from Standard Input in the following format:

A B

Output

Print the largest number among A + B, A - B, and A \times B.

Sample Input 1

-13 3

Sample Output 1

-10

The largest number among A + B = -10, A - B = -16, and A \times B = -39 is -10.

Sample Input 2

1 -33

Sample Output 2

34

The largest number among A + B = -32, A - B = 34, and A \times B = -33 is 34.

Sample Input 3

13 3

Sample Output 3

39

The largest number among A + B = 16, A - B = 10, and A \times B = 39 is 39.


#include "stdio.h"

int main()
{
	int a,b,ans;
	scanf("%d %d", &a,&b);
	if (a + b > a - b && a + b > a*b)ans = a + b;
	if (a - b > a * b && a - b > a+b)ans = a - b;
	if (a * b > a - b && a * b > a+b)ans = a * b;
	printf("%d", ans);
	return 0;
}


#include <stdio.h>
typedef long long ll;

int main(){
    int a,b,ans;
    scanf("%d %d",&a,&b);
    if((a>0&&b>0)||(a<0&&b<0)||(a<0&&b==0)) ans=a*b;
    else if(a>=0&&b<0) ans=a-b;
    else ans=a+b;
    printf("%d",ans);
}


#include <stdio.h>
int main(){
  int K,X,ret,i;
  ret = scanf( "%d %d" , &K,&X );
  if( ret == EOF ) {
    return -1;
  }
  X-=K;
  for(i=0;i<=K;i++){
  printf("%d ",X+i);
  }
  return 0;
}

Score : 200 points

Problem Statement

There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.

Among them, some K consecutive stones are painted black, and the others are painted white.

Additionally, we know that the stone at coordinate X is painted black.

Print all coordinates that potentially contain a stone painted black, in ascending order.

Constraints

1 \leq K \leq 100

0 \leq X \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K X

Output

Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.

Sample Input 1

3 7

Sample Output 1

5 6 7 8 9

We know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:

The three stones painted black are placed at coordinates 5, 6, and 7.

The three stones painted black are placed at coordinates 6, 7, and 8.

The three stones painted black are placed at coordinates 7, 8, and 9.

Thus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.

Sample Input 2

4 0

Sample Output 2

-3 -2 -1 0 1 2 3

Negative coordinates can also contain a stone painted black.

Sample Input 3

1 100

Sample Output 3

100


#include<stdio.h>

int main(void)
{
	int a, b,c,i;

	scanf("%d %d", &a, &b);

	c = b - a+1;
	b = a * 2 - 1;
	for(i=0;i<b;i++,c++)
	printf("%d ", c);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int tmp(const void *l, const void *r) {
  return strcmp((char *)l, (char *)r);
}

int main (int argc, char* argv[]) {
  long long n;
  scanf("%lld", &n);
  char s[n][12];
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    qsort(s[i], 10, sizeof(char), tmp);
  }

  qsort(s, n, sizeof(s[0]), tmp);

  long long ans = 0
    , j = 0
    , k = 0
    , l = 0;
  while (j < n) {
    if (strcmp(s[j], s[k+1]) == 0) {
      ans++;
      ans += l;
      k++;
      l++;
    } else {
      j = k + 1;
      k = j;
      l = 0;
    }
  }

  printf("%lld\n", ans);

  return 0;
}

Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.


#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int N; scanf("%d", &N);
  /* int S[MEM][26]; */
  int **S;
  S = (int **)malloc(N * sizeof(int *));
  for (int i = 0; i < N; i++) S[i] = (int *)calloc(26, sizeof(int));
  char buf[12];
  fgets(buf, 12, stdin);

  for (int i = 0; i < N; i++) {
    fgets(buf, 12, stdin);
    for (int j = 0; j < 10; j++) S[i][buf[j]-'a']++;
  }

  long long res = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      int flag = 1;
      for (int k = 0; k < 26; k++) {
	if (S[i][k] != S[j][k]) {
	  flag = 0;
	  break;
	}
      }
      res += flag;
    }
  }
  printf("%lld\n", res);
  return 0;
}


#include <stdio.h>
#include<stdlib.h>

//
// utility
//
void swap(int* p, int* q) {
  int swp = *q;
  *q = *p;
  *p = swp;
}

//
// data structure
//
enum pqueue_order {
  PQUEUE_ORDER_DESC = -1,
  PQUEUE_ORDER_ASC = 1
};

typedef struct pqueue {
  int* heap;
  int reserved;                     // reserved memory size
  int size;                         // heap size
  int (*push)(struct pqueue*, int);
  int (*pop)(struct pqueue*);
  int (*empty)(struct pqueue*);
  enum pqueue_order ord;
} pqueue_t;

//
// methods
//
int pqueue_push(pqueue_t* self, int n) {
  int node;
  int *heap;

  // ordering
  n *= self->ord;

  // expand heap size if stervation occured
  if (self->size >= self->reserved) {
    self->reserved = self->reserved * 2;
    self->heap = realloc(self->heap, self->reserved * sizeof(int));
  }

  heap = self->heap - 1; // index start from 1
  heap[++self->size] = n;

  // up-heap
  for (node = self->size; heap[node] < heap[node / 2] && node != 1; node/=2)
    swap(heap + node, heap + node/2);

  return 0;
}

int pqueue_pop(pqueue_t* self) {
  int ret;
  int left, rght;
  int node, downto;
  int *heap = self->heap - 1; // index start from 1

  if (self->size == 0) return -1;

  // de-ordering
  ret = heap[1] * self->ord;

  // down-heap
  heap[1] = heap[(self->size)--];
  for (node = 1, downto = -1; node != downto; swap(heap + node, heap + downto), node = downto) {
    int left = node*2    ;
    int rght = node*2 + 1;

    downto = node;
    // downto = min(parent, left child, right child)
    if (left <= self->size && heap[left] < heap[downto])
      downto = left;
    if (rght <= self->size && heap[rght] < heap[downto])
      downto = rght;
  }

  return ret;
}

int pqueue_empty(pqueue_t* self) {
  return self->size == 0;
}

//
// constructor
//
pqueue_t* create_pqueue(enum pqueue_order ord) {
  pqueue_t *p = malloc(sizeof(pqueue_t));

  p->size = 0;
  p->reserved = 2;
  p->heap = malloc(p->reserved * sizeof(int));

  p->ord = ord;

  p->push = pqueue_push;
  p->pop = pqueue_pop;
  p->empty = pqueue_empty;

  return p;
}

//
// destructor
//
void dispose_pqueue(pqueue_t* q) {
  free(q->heap);
  free(q);
}

int test() {
  pqueue_t *q;
  q = create_pqueue(PQUEUE_ORDER_DESC);

  q->push(q, 5);
  q->push(q, 1);
  q->push(q, 8);
  q->push(q, 9);
  q->push(q, -1);

  while (!q->empty(q))
    printf("%d%c", q->pop(q), 10);

  dispose_pqueue(q);

  return 0;
}

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

typedef struct pair{
  int x,y;
}point;

int compare_pair(const void *a,const void *b){
  if((*(point*)a).x > (*(point*)b).x) return 1;
  if((*(point*)a).x == (*(point*)b).x)
    if((*(point*)a).y < (*(point*)b).y) return 1;
  return -1;
}

int main(void){
  int N, M;
  scanf("%d%d", &N, &M);

  point A[N];
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &A[i].x, &A[i].y);
  }

  qsort(A, N, sizeof(point), compare_pair);

  long long ans = 0;
  int num = 0;
  pqueue_t *q;
  q = create_pqueue(PQUEUE_ORDER_DESC);
  for (int i = 1; i <= M; i++) {
    while(A[num].x <= i && num < N){
      q->push(q, A[num].y);
      num++;
    }
    if (!q->empty(q)) ans += q->pop(q);
  }

  printf("%lld\n", ans);

  /* printf("\n"); */
  /* for (int i = 0; i < N; i++) { */
  /*   printf("%d %d\n", A[i].x, A[i].y); */
  /* } */

  /*   printf("\n"); */
  /*   for (int i = 0; i < M; i++) { */
  /*     for (int j = 0; j < N; j++) { */
  /*       printf("%d ", arr[i][j]); */
  /*     } */
  /*     printf("\n"); */
  /*   } */

  return 0;
}

Score : 400 points

Problem Statement

There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.

You can take and complete at most one of these jobs in a day.

However, you cannot retake a job that you have already done.

Find the maximum total reward that you can earn no later than M days from today.

You can already start working today.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i \leq 10^5

1 \leq B_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the maximum total reward that you can earn no later than M days from today.

Sample Input 1

3 4
4 3
4 1
2 2

Sample Output 1

5

You can earn the total reward of 5 by taking the jobs as follows:

Take and complete the first job today. You will earn the reward of 3 after four days from today.

Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.

Sample Input 2

5 3
1 2
1 3
1 4
2 1
2 3

Sample Output 2

10

Sample Input 3

1 1
2 1

Sample Output 3

0


//set many funcs template
//Ver.20181228
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    srand(time(0));
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

typedef struct{
long long val;
long long node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
long long node;
long long cost;
}data;

data heap[262144];
long long hsize=0;

void resheap(){
    long long i;
    heap[0].node=-1;
    heap[0].cost=inf;
    for(i=1;i<262144;i++){
        heap[i].node=-1;
        heap[i].cost=-inf;
    }
}

long long swjud(data high,data low){
    if(high.cost < low.cost){return 1;}
    return -1;
}

void pqpush(data x){
    long long a,b;
    data m;
    hsize++;
    heap[hsize]=x;
    a=hsize;
    while(1){
        b=a/2;
        if(swjud(heap[b],heap[a]) == 1){
            m=heap[a];heap[a]=heap[b];heap[b]=m;
        }
        else{break;}
        a=b;
    }
}

data pqpop(){
    long long a,b,c;
    data m,sw;
    m=heap[1];
    heap[1]=heap[hsize];
    heap[hsize].node=-1;
    heap[hsize].cost=-inf;
    hsize--;
    a=1;
    while(1){
        b=a*2;c=a*2+1;
        if(swjud(heap[a],heap[b])==-1 && swjud(heap[a],heap[c])==-1){break;}
        if(swjud(heap[b],heap[c])==-1){
            sw=heap[a];heap[a]=heap[b];heap[b]=sw;
            a=b;
        }
        else{
            sw=heap[a];heap[a]=heap[c];heap[c]=sw;
            a=c;
        }
    }
    return m;
}

int main(void){
    resheap();
    long long i,j,n,m,k,a[524288],b,c,h,w,r=0,l,t;
    data pd,od;
    sd dat[262144];
    scanf("%lld%lld",&n,&k);
    for(i=0;i<n;i++){
      scanf("%lld%lld",&dat[i].val,&dat[i].node);
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    dat[n].val=inf;
    j=0;
    for(i=1;i<=k;i++){
      while(dat[j].val<=i){
        pd.cost=dat[j].node;
        pqpush(pd);
        j++;
      }
      if(hsize>0){
        od=pqpop();
        r+=od.cost;
      }
    }
    printf("%lld\n",r);
    return 0;
}


Score : 200 points

Problem Statement

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

Constraints

1 \leq N \leq 10^5

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.

Sample Input 1

11

Sample Output 1

9

Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \ldots, 9.

Sample Input 2

136

Sample Output 2

46

In addition to 1, 2, \ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \ldots, 136.

Sample Input 3

100000

Sample Output 3

90909


    #include <stdio.h>

    int main(void)
    {
        int n,out;
        scanf("%d",&n);
        if(n>9999)
        {
            out=n-9999+900+9;
            if(n==100000)
                out--;
        }
        else if(n>999)
            out=999-99+9;
        else if(n>99)
            out=n-99+9;
        else if(n>=9)
            out=9;
        else
            out=n;
        printf("%d",out);
        return 0;
    }


Score : 200 points

Problem Statement

We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.

You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.

Print YES if you can sort p in ascending order in this way, and NO otherwise.

Constraints

All values in input are integers.

2 \leq N \leq 50

p is a permutation of {1,\ 2,\ ...,\ N}.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

Print YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.

Sample Input 1

5
5 2 3 4 1

Sample Output 1

YES

You can sort p in ascending order by swapping p_1 and p_5.

Sample Input 2

5
2 4 3 5 1

Sample Output 2

NO

In this case, swapping any two elements does not sort p in ascending order.

Sample Input 3

7
1 2 3 4 5 6 7

Sample Output 3

YES

p is already sorted in ascending order, so no operation is needed.


#include <stdio.h>
int main(){
 int n;
 scanf("%d",&n);
 int p[n];
 for(int a=0;a<n;a++){
     scanf("%d",&p[a]);
 }
 int count=0;
 for(int b=0;b<n-1;b++){
     for(int c=1;c<n-b;c++){
         if(count==0){
             if(p[b]>p[b+c]){int tmp=b+c;int tmp3=p[b+c];
                 for(int d=1;d<n-b-c;d++){
                     if(tmp3>p[b+c+d]){tmp3=p[b+c+d];tmp=b+c+d;}}
                     int tmp2;
                     tmp2=p[b];
                     p[b]=p[tmp];
                     p[tmp]=tmp2;
                     count++;}
             else{}
         }
         else{if(p[b]<p[b+c]){}
              else{printf("NO\n");return 0;}}
     }
 }
 printf("YES\n");
 return 0;
}


#include<stdio.h>
#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
int main(void){
  int n,cnt=0;
  scanf("%d",&n);
  FOR(n){
    int a;
    scanf("%d",&a);
    if(a-i)cnt++;
  }
  if(cnt<3){
    PRS("YES");
  }else{
    PRS("NO");
  }
  return 0;
}


#include <stdio.h>

int main(void){
    int n;
    int count = 0;
    scanf("%d",&n);
    int a[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    for(int i = 0;i < n;i++){
        if(a[i]!=i+1){
            count++;
        }
    }
    if(count <= 2){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

       return (0);

}


#include <stdio.h>
#include <math.h>

int main(void){
  long s;
  int x1,y1,x2,y2,x3,y3;
  double m;
  long n;
  int k,l;
  x1 = 0;

  scanf("%ld",&s);
  //printf("%ld",s);

  m = sqrt(s);
  n = (int)m;
  //printf("%d",n);

  int sr = s -n*n;
  printf("%d\n",sr);
  if(sr ==0){
    printf("%d %d %d %d %d %d\n",sr,sr,n,sr,sr,n);
  }else{

  for(int i = 2;i<1000000001;i++){
    if(sr%i==0){
      k =i;
      l = sr/i;
      break;
    }
    if(i ==1000000000){
      k = 1;
      l =sr;
    }
  }
  printf("%d %d %d %d %d %d\n",x1,k,n,x1,l,n+k);
  }

  return 0;
}

Score : 400 points

Problem Statement

Given is an integer S.
Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:

0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9

The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.

We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.

Constraints

1 \leq S \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

S

Output

Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between.
If multiple solutions exist, any of them will be accepted.

Sample Input 1

3

Sample Output 1

1 0 2 2 0 1

The area of the triangle in a two-dimensional plane whose vertices are (1,0),(2,2), and (0,1) is 3/2.
Printing 3 0 3 1 0 1 or 1 0 0 1 2 2 will also be accepted.

Sample Input 2

100

Sample Output 2

0 0 10 0 0 10

Sample Input 3

311114770564041497

Sample Output 3

314159265 358979323 846264338 327950288 419716939 937510582


#include<stdio.h>
int main()
{
	int r;

	scanf("%d",&r);

	printf("%d",3*r*r);
	return 0;
}

Score : 100 points

Problem Statement

It is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.

Given an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.

Constraints

1 \leq r \leq 100

r is an integer.

Input

Input is given from Standard Input in the following format:

r

Output

Print an integer representing the area of the regular dodecagon.

Sample Input 1

4

Sample Output 1

48

The area of the regular dodecagon is 3 \times 4^2 = 48.

Sample Input 2

15

Sample Output 2

675

Sample Input 3

80

Sample Output 3

19200