I. Mysterious Script
Source: codeforces
Tags: *special, expression parsing, number theory

An extraterrestrial species has visited the authors of April Fools Day Contest 2025 while they were preparing problems. They call themselves the "Balikons" and expressed interest in chatting with humans. Although they can make sounds that are similar to human speech, they seem to prefer communicating by writing using a variety of media.
Figure 1. A Balikon entity communicates with a human linguist (2025, colorized)
Fortunately, there is a linguistics expert in the author team. With some effort, they were eventually able to fully understand the Balikon language. The following is a table of some example phrases they translated.
Balikon script
Latin script
Translation
balikon
Balikon
balikong shas
three Balikons
fibucho shezali kin chakog leshas
buy shezali
$^{\text{∗}}$
for twelve chakos
$^{\text{†}}$
fibuchog zinfa bashin
(I) bought the wrong pen
shons ze tes to les konbilo lonshonletashashaleteshates
five plus seven minus one modulo 998244358
Table 1. A few pieces of text in the Balikon language
After some conversations, the Balikons learned about a popular human activity called competitive programming and were excited to try. In fact, they just created their first problem. Please check it out!
$^{\text{∗}}$a dish in traditional Balikon cuisine, similar to meatballs
$^{\text{†}}$currency unit

-----Input-----
The input contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).

-----Output-----
Print the sum $a + b$.

-----Examples-----
Input:
shons tes
Output:
leshas
Input:
leles lonshons
Output:
shatas
Input:
lonshonletashashaleteshalons shons
Output:
lonshonletashashaleteshates

C++ solution:
#include<bits/stdc++.h>
using namespace std;
string str[]={"la","le","lon","sha","she","shon","ta","te","ton"};
int trans(string s){
	s.pop_back();int ans=0;
	for (int i=0;i<s.size();)
		for (int j=0;j<9;j++){
			if (i+str[j].size()>s.size()) continue;
			bool flag=1;
			for (int k=0;k<str[j].size();k++)
				if (s[i+k]!=str[j][k]) {flag=0;break;}
			if (flag) {ans=ans*9+j;i+=str[j].size();break;}
		}
	return ans;
}
void print(int a){
	if (a<9) return cout<<str[a],void();
	print(a/9);cout<<str[a%9];
}
int main(){
	string s,t;cin>>s>>t;
	int a=trans(s),b=trans(t);
	print(a+b);cout<<'s';
	return 0;
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	// Define syllables and their corresponding digits
	syllables := []string{"la", "le", "lon", "sha", "she", "shon", "ta", "te", "ton"}

	// Read input
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	input := scanner.Text()
	words := strings.Fields(input)
	if len(words) != 2 {
		return
	}

	// Function to convert Balikon word to base-9 number
	wordToNumber := func(word string) int64 {
		// Remove trailing 's'
		if len(word) > 0 && word[len(word)-1] == 's' {
			word = word[:len(word)-1]
		}

		// Replace syllables with digits (process longer syllables first)
		for i := len(syllables) - 1; i >= 0; i-- {
			word = strings.ReplaceAll(word, syllables[i], strconv.Itoa(i))
		}

		// Parse as base-9 number
		num, err := strconv.ParseInt(word, 9, 64)
		if err != nil {
			return 0
		}
		return num
	}

	// Convert both words to numbers
	num1 := wordToNumber(words[0])
	num2 := wordToNumber(words[1])
	sum := num1 + num2

	// Convert sum back to Balikon word
	var result strings.Builder
	if sum == 0 {
		result.WriteString(syllables[0])
	} else {
		// Build digits in reverse order
		var digits []string
		for sum > 0 {
			digit := sum % 9
			digits = append(digits, syllables[digit])
			sum /= 9
		}
		// Reverse to get correct order
		for i := len(digits) - 1; i >= 0; i-- {
			result.WriteString(digits[i])
		}
	}
	result.WriteString("s")

	fmt.Println(result.String())
}

Java solution:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        String word1 = input[0];
        String word2 = input[1];
        
        // Remove the trailing 's'
        String num1Str = word1.substring(0, word1.length() - 1);
        String num2Str = word2.substring(0, word2.length() - 1);
        
        // Define the syllables and their corresponding digits
        String[] syllables = {"la", "le", "lon", "sha", "she", "shon", "ta", "te", "ton"};
        
        // Replace each syllable in num1Str with corresponding digit
        for (int i = 0; i < syllables.length; i++) {
            num1Str = num1Str.replace(syllables[i], Integer.toString(i));
        }
        
        // Replace each syllable in num2Str with corresponding digit
        for (int i = 0; i < syllables.length; i++) {
            num2Str = num2Str.replace(syllables[i], Integer.toString(i));
        }
        
        // Parse the base-9 numbers
        long num1 = Long.parseLong(num1Str, 9);
        long num2 = Long.parseLong(num2Str, 9);
        long sum = num1 + num2;
        
        // Convert the sum back to base-9 and then to Balikon syllables
        StringBuilder result = new StringBuilder();
        if (sum == 0) {
            result.append(syllables[0]);
        } else {
            while (sum > 0) {
                int digit = (int) (sum % 9);
                result.insert(0, syllables[digit]);
                sum /= 9;
            }
        }
        result.append('s');
        
        System.out.println(result.toString());
    }
}

JavaScript solution:
const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

const syllables = ['la', 'le', 'lon', 'sha', 'she', 'shon', 'ta', 'te', 'ton'];

function convertToDecimal(balikonStr) {
    // Remove trailing 's'
    const str = balikonStr.endsWith('s') ? balikonStr.slice(0, -1) : balikonStr;
    let numStr = str;
    
    // Replace syllables with digits
    for (let i = 0; i < syllables.length; i++) {
        numStr = numStr.split(syllables[i]).join(i);
    }
    
    // Handle empty string (should be 0)
    return numStr === '' ? 0 : parseInt(numStr, 9);
}

function convertToBalikon(num) {
    if (num === 0) return 'las';
    
    let result = '';
    while (num > 0) {
        const digit = num % 9;
        result = syllables[digit] + result;
        num = Math.floor(num / 9);
    }
    return result + 's';
}

rl.on('line', (line) => {
    const [word1, word2] = line.trim().split(/\s+/);
    
    const num1 = convertToDecimal(word1);
    const num2 = convertToDecimal(word2);
    const sum = num1 + num2;
    
    console.log(convertToBalikon(sum));
});

Python solution:
a=['la','le','lon','sha','she','shon','ta','te','ton']
b=input().split()
c,d=[b[0][:-1],b[1][:-1]]
for i in range(9):c,d=c.replace(a[i],str(i)),d.replace(a[i],str(i))
h=int(c, 9)+int(d, 9)
r=''
while h>0:r=a[h%9]+r;h//=9
print(r+'s')

Ruby solution:
# Define the syllable to digit mapping
SYLLABLES = {
  'la' => '0', 'le' => '1', 'lon' => '2',
  'sha' => '3', 'she' => '4', 'shon' => '5',
  'ta' => '6', 'te' => '7', 'ton' => '8'
}

# Convert Balikon word to integer
def word_to_number(word)
  num_str = word[0...-1]  # Remove trailing 's'
  SYLLABLES.each { |k, v| num_str = num_str.gsub(k, v) }
  num_str.empty? ? 0 : num_str.to_i(9)
end

# Convert integer back to Balikon word
def number_to_word(num)
  syllables = %w[la le lon sha she shon ta te ton]
  return 'las' if num == 0
  
  result = ''
  while num > 0
    digit = num % 9
    result = syllables[digit] + result
    num /= 9
  end
  result + 's'
end

# Main execution
input = gets.chomp.split
a, b = input[0], input[1]

sum = word_to_number(a) + word_to_number(b)
puts number_to_word(sum)