Skip to main content
Back to problems
Codeforces
Easy
Math
Simulation
Strange Addition

Convert each input number from a special base-4 representation to decimal, add them, and print the result in decimal.

Acceptance 0%
Problem Statement

Problem

You are given two numbers written in a strange numeral system.

Each number uses digits from 0 to 3, but the value of a digit depends on its position as if the number were written in base 4.

Your task is to read the two numbers, interpret them as base-4 values, add them, and output the sum in decimal.

Explanation

For a number like 321: 342+241+1403 \cdot 4^2 + 2 \cdot 4^1 + 1 \cdot 4^0

Do this for both input numbers, then compute their sum.

Input Format

Input

A single line contains two space-separated integers a and b.

Each integer is written using only digits 0 to 3 and should be interpreted as a base-4 number.

Output Format

Output

Print one integer — the sum of the two numbers in decimal.

Constraints

Constraints

  • The input numbers contain only digits 0 to 3
  • The values fit in standard 64-bit signed integer arithmetic after conversion and addition
Examples
Sample cases returned by the problem API.

Example 1

Input

10 2

Output

6

Explanation

10 in base 4 equals 4 in decimal, and 2 equals 2. Their sum is 6.

Example 2

Input

321 3

Output

60

Explanation

321 in base 4 is 3*16 + 2*4 + 1 = 57, and 3 is 3. The sum is 60.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.