from typing import List


def f1_score(real_labels: List[int], predicted_labels: List[int]) -> float:
    """
    f1 score: https://en.wikipedia.org/wiki/F1_score
    """
    # precsion = true positives / positives pred
    # recall = true positives classified / total positives 
    # 2 * [ (precision * recall) / (precision + recall) ]

    assert len(real_labels) == len(predicted_labels)
    truePositPred = sum(1 if (p == 1 and r == p) else 0 for r,p in zip(real_labels, predicted_labels))
    positPred = sum(1 if p ==1 else 0 for p in predicted_labels)
    precision = truePositPred / positPred

    totalPosit = sum(1 if r == 1 else 0 for r in real_labels)
    recall = truePositPred / totalPosit
    if (precision + recall) == 0:
        return 0
    return 2 * ((precision * recall) / (precision+recall))