A. Vanya and Table
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.

In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles.

Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

Output

In a single line print the sum of all values in the cells of the table.

Examples
input
2
1 1 2 3
2 2 3 3
output
10
input
2
1 1 3 3
1 1 3 3
output
18
Note

Note to the first sample test:

Values of the table in the first three rows and columns will be as follows:

121

121

110

So, the sum of values will be equal to 10.

Note to the second sample test:

Values of the table in the first three rows and columns will be as follows:

222

222

222

So, the sum of values will be equal to 18.

题意:n个矩形 给你左下 右上 两点 计算矩形面积之和

题解:水

 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<iostream>
 9 #include<cstring>
10 #include<cstdio>
11 #include<map>
12 #include<algorithm>
13 #include<queue>
14 #define LL __int64
15 #define pii pair<int,int>
16 #define MP make_pair
17 const int N=1000006;
18 using namespace std;
19 int n;
20 int x1,x2,y1,y2;
21 int main()
22 {
23     scanf("%d",&n);
24     int sum=0;
25     for(int i=1;i<=n;i++)
26     {
27         scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
28         sum=sum+(x2-x1+1)*(y2-y1+1);
29     }
30     cout<<sum<<endl;
31     return 0;
32 }

 

 

B. Vanya and Books
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.

Vanya wants to know how many digits he will have to write down as he labels the books.

Input

The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.

Output

Print the number of digits needed to number all the books.

Examples
input
13
output
17
input
4
output
4
Note

Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.

Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.

题意:计算1~n的n个数一共有多少位

题解:很容易发现从(9,99,999,....)分界 随便搞一下

 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<iostream>
 9 #include<cstring>
10 #include<cstdio>
11 #include<map>
12 #include<algorithm>
13 #include<queue>
14 #define LL __int64
15 #define pii pair<int,int>
16 #define MP make_pair
17 const int N=1000006;
18 using namespace std;
19 LL n;
20 LL a[15];
21 int main()
22 {
23     scanf("%I64d",&n);
24     LL jishu=1;
25     LL exm=9;
26     LL ans=0;
27     a[1]=1;
28     for(int i=2;i<=10;i++)
29         a[i]=10*a[i-1];
30     a[1]=0;
31     while(n>=exm)
32     {
33        ans=ans+(exm-a[jishu]+1)*jishu;
34        jishu++;
35        exm=exm*10+9;
36     }
37     ans=ans+(n-a[jishu]+1)*jishu;
38     printf("%I64d\n",ans-1);
39     return 0;
40 }

 

 

C. Vanya and Scales
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2(exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of massm and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.

Input

The first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109) — the number defining the masses of the weights and the mass of the item.

Output

Print word 'YES' if the item can be weighted and 'NO' if it cannot.

Examples
input
3 7
output
YES
input
100 99
output
YES
input
100 50
output
NO
Note

Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.

Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.

Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.

题意:w0, w1, w2, ..., w100 质量的砝码 用天平秤 m质量的东西 砝码可以放置在天平的两侧 如果可以秤出物体m 输出 YES

题解:对于w^k,系数只能取-1,0,1

/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^    ^ ^
 O      O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define LL __int64
#define pii pair<int,int>
#define MP make_pair
const int N=1000006;
using namespace std;
LL w,m;
LL a[50];
int main()
{
    scanf("%I64d %I64d",&w,&m);
    while(m)
    {
        if(m%w==1)m--;
        if(m%w==w-1)m++;
        if(m%w==0)m/=w;
        else
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}