백준
1.Python
import sys
input = sys.stdin.readline
data = input().rstrip()
sum = 0
data = sorted(data, reverse = True)
if '0' not in data:
print(-1)
else:
for d in data:
sum += int(d)
if sum % 3 != 0:
print(-1)
else:
print(''.join(data))
2. C++
#include <cstdio>
char s[100001];
int sum, count[128];
int main() {
scanf("%s", s);
for (int i = 0 ; s[i] ; i++) {
sum += s[i] - '0';
count[s[i]]++;
}
if (sum % 3 != 0 || count['0'] == 0) {
printf("-1");
return 0;
}
for (int i = '9' ; i >= '0' ; i--) {
for (int j = 0 ; j < count[i] ; j++) {
printf("%c", i);
}
}
}