Problem:
Score : 100 points

Problem Statement

Snuke prepared 6 problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.

You are given a string S of length 6.
If the i-th character of s is 1, it means that the i-th problem prepared by Snuke is accepted to be used; 0 means that the problem is not accepted.

How many problems prepared by Snuke are accepted to be used in the contest?

Constraints

The length of S is 6.

S consists of 0 and 1.

Inputs

Input is given from Standard Input in the following format:

S

Outputs

Print the number of problems prepared by Snuke that are accepted to be used in the contest.

Sample Input 1

111100

Sample Output 1

4

The first, second, third and fourth problems are accepted, for a total of four.

Sample Input 2

001001

Sample Output 2

2

Sample Input 3

000000

Sample Output 3

0

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int gcd(int u, int v) {
int r;
while (0 != v) {
r = u % v; u = v; v = r;
}
return u;
}
 
map<int,int>up;
map<int,int>down;
 
int main(void) {
 
	int N;
 
	scanf("%d",&N);
 
	int a,b,c;
 
	for(c=1;c<=3500;c++){
		if((4*c)-N>0){
		int div=gcd(N*c,(4*c)-N);
		up[((4*c)-N)/div]=c;
		down[(N*c)/div]=c;
		}
	}
 
	for(a=1;a<=3500;a++){
		for(b=max(a,3*N/4);b<=3500;b++){
			int div2=gcd(a+b,a*b);
			if(up[(a+b)/div2]>0&&down[(a*b)/div2]>0 &&
			up[(a+b)/div2]==down[(a*b)/div2]){
				printf("%d %d %d\n",a,b,up[(a+b)/div2]);
				return 0;
			}
		}
	}
 
	return 0;
}