A. Ciel and dancing

Source: Internet
Author: User
Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Fox Ciel and her friends are in a dancing room. There areNBoys andMGirls
Here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:

  • Either the boy in the dancing pair must dance for the first time (So, He didn't dance with anyone before );
  • Or the girl in the dancing pair must dance for the first time.

Help Fox Ciel to make a schedule that they can dance as your songs as possible.

Input

The first line contains two integersNAndM(1 digit ≤ DigitN, Bytes,MLimit ≤0000100)
-The number of boys and girls in the dancing room.

Output

In the first line printK-The number of songs during which they can dance. Then in the followingKLines,
Print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1N, And the girls
Are indexed from 1M.

Sample test (s) Input
2 1
Output
21 12 1
Input
2 2
Output
31 11 22 2
Note

In Test Case 1, there are 2 boys and 1 girl. we can have 2 dances: The 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song ).

And in Test Case 2, we have 2 boys with 2 girls, the answer is 3.

Explanation: in the question, it is required that boys or girls dance for the first time. Since the total number is n + M, to ensure that a new person can join each time, it is easy to know that in this case, he can dance N + M-1 most (the first dance is the first time for boys and girls ), one easy way to think of is to let the first boy dance with all the girls first, ensure that the girls dance for the first time, and then let the first girl dance with the remaining n-1 boys, this ensures that boys dance for the first time.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main(){    int i,n,m;scanf("%d%d",&n,&m);printf("%d\n",n+m-1);for(i=1;i<=m;i++){printf("1 %d\n",i);}for(i=2;i<=n;i++){printf("%d 1\n",i);}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.