Problem A

Problem Statement

You are given an integer N that has exactly four digits in base ten. How many times does 2 occur in the base-ten representation of N?

Constraints

  • $ 1000 \leq N \leq 9999 $

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

1222

Sample Output 1

3

2 occurs three times in 1222. By the way, this contest is held on December 22 (JST).


Sample Input 2

3456

Sample Output 2

0

Sample Input 3

9592

Sample Output 3

1

AC code:

1
2
3
4
5
6
7
8
9
10
11
12
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
int cnt=0;
cin>>s;
for(int i=0;i<s.size();i++)
if(s[i]=='2')
cnt++;
cout<<cnt;
return 0;
}

Problem B

Problem Statement

There are $N$ rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are $A_i \times B_i$ ($A_i$ vertically and $B_i$ horizontally).

Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly $H \times W$. He is trying to obtain such a plate by choosing one of the $N$ materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a $5 \times 3$ material cannot be used as a $3 \times 5$ plate.

Out of the $N$ materials, how many can produce an $H \times W$ plate if properly cut?

Constraints

  • $1 \leq N \leq 1000$
  • $1 \leq H \leq 10^9$
  • $1 \leq W \leq 10^9$
  • $1 \leq A_i \leq 10^9$
  • $1 \leq B_i \leq 10^9$

Input

Input is given from Standard Input in the following format:

$N$ $H$ $W$

$A_1$ $B_1$

$A_2$ $B_2$

$:$

$A_N$ $B_N$

Output

Print the answer.


Sample Input 1

3 5 2
10 3
5 2
2 5

Sample Output 1

2

Takahashi wants a $5 \times 2$ plate.

  • The dimensions of the first material are $10 \times 3$. We can obtain a $5 \times 2$ plate by properly cutting it.
  • The dimensions of the second material are $5 \times 2$. We can obtain a 5 \times 2 plate without cutting it.
  • The dimensions of the third material are $2 \times 5$. We cannot obtain a $5 \times 2$ plate, whatever cuts are made. Note that the material cannot be rotated and used as a $5 \times 2$ plate.

Sample Input 2

10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268

Sample Output 2

8

AC code:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<bits/stdc++.h>
using namespace std;
long long n,h,m;
long long a,b,cnt=0;
int main() {
cin>>n>>h>>m;
for(int i=1;i<=n;i++) {
scanf("%lld%lld",&a,&b);
if(a>=h && b>=m) cnt++;
}
printf("%lld",cnt);
return 0;
}

Problem C

AC code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<bits/stdc++.h>
using namespace std;
long long n,p;
map<long long,long long> f;
map<long long,long long>::iterator it;
void get() {
long long temp=p;
for(long long i=2;i*i<=p;i++) {
if(temp==1) break;
if(temp%i==0) {
while(temp%i==0) {
temp/=i;
f[i]++;
}
}
}
}
int main() {
cin>>n>>p;
get();
long long cnt=1;
if(n==1) {
cout<<p;
exit(0);
}
for(it=f.begin();it!=f.end();it++) {
while(it->second>=n) {
cnt*=it->first;
it->second-=n;
}
}
cout<<cnt;
return 0;
}

Problem D

AC code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,temp;
cin>>n;
for(int i=1;i<=n;i++) {
scanf("%d",&temp);
if(temp%2==1) {
cout<<"first";
exit(0);
}
}
cout<<"second";
return 0;
}