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# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    long N, K;
    long[] A, B;
    void Solve() {
        //input
        N = io.Long;
        K = io.Long;
        A = new long[N];
        B = new long[N];
        for (var i = 0; i < N;++i){
            A[i] = io.Long;
            B[i] = io.Long;
        }
        //cal
        var ans = 0L;
        //Kのbitwise_orを変更しない範囲での最大値を求める
        //i番目について調べる
        for (var i = 0; i < N;++i){
            var f = true;
            for (int j = 0; j <= 30;++j){
                //Kの該当するビットが1じゃないのにA[i]の該当するビットが1
                //->bitwise_orを変更してしまうので加えない
                if(((K>>j)&1)==0&&((A[i]>>j)&1)==1){
                    f = false;break;
                }
            }
            if (f)ans += B[i];
        }
        //最終状態をKより小さくして総和が大きくなるかもしれない
        //最終的な形から考える
        //K=5=(101)のとき,(100),(10?),(0??)が他の最終状態として考えられる(?はどっちでもいい)
        for (var i = 0; i <= 30; ++i) {
            //iビットを0に反転して，以降を1にしたK
            if (((K >> i) & 1) == 1) {
                //iビットを0にして，iビット以降を1にしたK
                var converted_K = (K & ~(1 << i)) | ((1 << i) - 1);
                var cur = 0L;
                for (int j = 0; j < N; ++j) {
                    var f = true;
                    for (int k = 0; k < 30; ++k) {
                        if (((converted_K >> k) & 1) == 0 && ((A[j] >> k) & 1) == 1) {
                            f = false;break;
                        }
                    }
                    if (f)cur += B[j];
                }
                //更新
                ans = Math.Max(ans, cur);
            }
        }
        //ret
        Console.WriteLine(ans);
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}