import std.algorithm, std.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.bitmanip, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto g = rd[0], c = rd[1], p = rd[2]; auto s = readln.chomp; int[int[3]] memo; memo[[g, c, p]] = 0; foreach (t; s) { int[int[3]] memo2; foreach (gcp, a; memo) { if (gcp[0] > 0) { int[3] key = [gcp[0] - 1, gcp[1], gcp[2]]; auto sc = score('G', t); memo2[key] = key in memo2 ? max(memo2[key], a + sc) : a + sc; } if (gcp[1] > 0) { int[3] key = [gcp[0], gcp[1] - 1, gcp[2]]; auto sc = score('C', t); memo2[key] = key in memo2 ? max(memo2[key], a + sc) : a + sc; } if (gcp[2] > 0) { int[3] key = [gcp[0], gcp[1], gcp[2] - 1]; auto sc = score('P', t); memo2[key] = key in memo2 ? max(memo2[key], a + sc) : a + sc; } } memo = memo2; } writeln(memo[[0, 0, 0]]); } int score(char s, char o) { final switch (s) { case 'G': final switch (o) { case 'G': return 1; case 'C': return 3; case 'P': return 0; } case 'C': final switch (o) { case 'G': return 0; case 'C': return 1; case 'P': return 3; } case 'P': final switch (o) { case 'G': return 3; case 'C': return 0; case 'P': return 1; } } }