The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
- ti = 1, if the i-th child is good at programming,
- ti = 2, if the i-th child is good at maths,
- ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
7 1 3 1 3 2 1 2
2 3 5 2 6 7 4
4 2 1 1 2
0
/*************************************************************************
> File Name: a.cpp
> Author: gwq
> Mail: gwq5210@qq.com
> Created Time: 2014年11月23日 星期日 17时09分20秒
************************************************************************/
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#define INF (INT_MAX / 10)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define pb push_back
#define sz(a) ((int)(a).size())
using namespace std;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
const double esp = 1e-5;
#define N 5010
int val[4][N], num;
int main(int argc, char *argv[])
{
int n;
while (scanf("%d", &n) != EOF) {
int cnt[5];
clr(cnt, 0);
for (int i = 0; i < n; ++i) {
scanf("%d", &num);
val[num][cnt[num]++] = i + 1;
}
int mx = INF;
for (int i = 1; i <= 3; ++i) {
mx = min(cnt[i], mx);
}
printf("%d\n", mx);
for (int i = 0; i < mx; ++i) {
printf("%d %d %d\n", val[1][i], val[2][i], val[3][i]);
}
}
return 0;
}
/*************************************************************************
> File Name: b.cpp
> Author: gwq
> Mail: gwq5210@qq.com
> Created Time: 2014年11月23日 星期日 17时18分50秒
************************************************************************/
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#define INF (INT_MAX / 10)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define pb push_back
#define sz(a) ((int)(a).size())
using namespace std;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
const double esp = 1e-5;
#define N 1000010
int a[N], b[N], ans[N], num1[N], num2[N];
int main(int argc, char *argv[])
{
int n;
while (scanf("%d", &n) != EOF) {
//不存在的值一定要和其他可能的取值区分开
clr(a, -1);
clr(b, -1);
for (int i = 0; i < n; ++i) {
int u, v;
scanf("%d%d", &num1[i], &num2[i]);
u = num1[i];
v = num2[i];
a[u] = v;
b[v] = u;
}
int tmp = a[0];
int cnt = 2;
while (cnt <= n) {
ans[cnt] = tmp;
tmp = a[tmp];
cnt += 2;
}
if (n % 2 == 0) {
tmp = b[0];
cnt = n - 1;
while (cnt >= 1) {
ans[cnt] = tmp;
tmp = b[tmp];
cnt -= 2;
}
} else {
int num = 0;
for (int i = 0; i < n; ++i) {
if (a[num1[i]] != 0 && b[num1[i]] < 0) {
num = num1[i];
break;
}
}
tmp = num;
cnt = 1;
while (cnt <= n) {
ans[cnt] = tmp;
tmp = a[tmp];
cnt += 2;
}
}
for (int i = 1; i <= n; ++i) {
printf("%d%c", ans[i], (i == n) ? '\n' : ' ');
}
}
return 0;
}
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
The first line of the input contains the public key of the messenger — an integer without leading zeroes, its length is in range from 1 to 106digits. The second line contains a pair of space-separated positive integers a, b (1 ≤ a, b ≤ 108).
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines — the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
116401024 97 1024
YES 11640 1024
284254589153928171911281811000 1009 1000
YES 2842545891539 28171911281811000
120 12 1
NO
/*************************************************************************
> File Name: c.cpp
> Author: gwq
> Mail: gwq5210@qq.com
> Created Time: 2014年11月23日 星期日 18时06分42秒
************************************************************************/
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#define INF (INT_MAX / 10)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define pb push_back
#define sz(a) ((int)(a).size())
using namespace std;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
const double esp = 1e-5;
#define N 1000010
int dp1[N], dp2[N];
int main(int argc, char *argv[])
{
int a, b;
string s;
while (cin >> s) {
scanf("%d%d", &a, &b);
int i = 0;
int len = s.length();
dp1[0] = (s[0] - '0') % a;
for (i = 1; i < len; ++i) {
int tmp = s[i] - '0';
dp1[i] = (dp1[i - 1] * 10 + tmp) % a;
}
dp2[len] = 0;
int base = 1;
for (int i = len - 1; i >= 0; --i) {
int tmp = s[i] - '0';
dp2[i] = (base * tmp + dp2[i + 1]) % b;
base = (base * 10) % b;
}
int pos = -1;
for (int i = 0; i < len - 1; ++i) {
if (dp1[i] == 0 && dp2[i + 1] == 0 && s[i + 1] != '0') {
pos = i;
break;
}
}
if (pos < 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
cout << s.substr(0, pos + 1) << endl;
cout << s.substr(pos + 1, len - pos - 1) << endl;
}
}
return 0;
}