import sys import csv import json import io
def main(): # Reads the entire content from the 'Stdin' box input_data = sys.stdin.read().strip()
if not input_data:
print("[]")
return
# Treat the input string as a file for the CSV reader
f = io.StringIO(input_data)
reader = csv.DictReader(f)
# Configuration for formatting
int_fields = {
"contest_level", "contestId1", "R1", "contestId2", "R2",
"contestId3", "R3", "contestId4", "R4"
}
# Fields where -1 or "null" should become actual JSON null
time_fields = {"T1", "T2", "T3", "T4"}
# The specific keys required by ThemeCP (removes performance, rating, etc.)
required_keys = [
"date", "topic", "contest_level",
"contestId1", "index1", "R1",
"contestId2", "index2", "R2",
"contestId3", "index3", "R3",
"contestId4", "index4", "R4",
"T1", "T2", "T3", "T4"
]
json_data = []
for row in reader:
entry = {}
for key in required_keys:
# Get value from CSV, default to empty string if column missing
val = row.get(key, "")
# Convert to string to check contents
str_val = str(val).strip()
# 1. Handle Null/Empty/Negative-1 conditions
if str_val.lower() == "null" or str_val == "-1" or str_val == "":
entry[key] = None
# 2. Handle Integer conversions
elif key in int_fields or key in time_fields:
try:
# Remove any quotes and convert to int
entry[key] = int(str_val.replace('"', ''))
except ValueError:
entry[key] = str_val
# 3. Handle Standard Strings (Date, Topic, Index)
else:
entry[key] = str_val.replace('"', '')
json_data.append(entry)
# Output the final JSON string to the 'Stdout' box
print(json.dumps(json_data, indent=2))if name == "__main__": main()