Language: C++

import java.util.*;
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(true) {
			int t = sc.nextInt();
			int n = sc.nextInt();
			
			if(t == 0 && n == 0) break;
			int len = String.valueOf(n).length();
			int ans = -1;
			
			for(int i = 0; i < 1 << len; i++) {
				int sum = 0;
				String tmp = String.valueOf(i);
				int b = 0;
				for(int j = 0; j < tmp.length(); j++) {
					if(tmp.charAt(j) == '1') {
						sum += Integer.parseInt(tmp.subString(b,j));
						b = j;
					}
				}
				if(sum > ans && sum <= t) {
					ans = sum;
				}
			}
			System.out.println(ans);

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:16: error: 'Scanner' does not name a type
    3 |         static Scanner sc = new Scanner(System.in);
      |                ^~~~~~~
a.cc:4:15: error: expected ':' before 'static'
    4 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:4:33: error: 'String' has not been declared
    4 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:4:42: error: expected ',' or '...' before 'args'
    4 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:27:49: error: expected '}' at end of input
   27 |                         System.out.println(ans);
      |                                                 ^
a.cc:2:12: note: to match this '{'
    2 | class Main {
      |            ^
a.cc: In static member function 'static void Main::main(int*)':
a.cc:6:33: error: 'sc' was not declared in this scope
    6 |                         int t = sc.nextInt();
      |                                 ^~
a.cc:10:35: error: 'String' was not declared in this scope
   10 |                         int len = String.valueOf(n).length();
      |                                   ^~~~~~
a.cc:15:40: error: expected ';' before 'tmp'
   15 |                                 String tmp = String.valueOf(i);
      |                                        ^~~
a.cc:17:52: error: 'tmp' was not declared in this scope
   17 |                                 for(int j = 0; j < tmp.length(); j++) {
      |                                                    ^~~
a.cc:19:56: error: 'Integer' was not declared in this scope
   19 |                                                 sum += Integer.parseInt(tmp.subString(b,j));
      |                                                        ^~~~~~~
a.cc:27:25: error: 'System' was not declared in this scope
   27 |                         System.out.println(ans);
      |                         ^~~~~~
a.cc:27:49: error: expected '}' at end of input
   27 |                         System.out.println(ans);
      |                                                 ^
a.cc:5:29: note: to match this '{'
    5 |                 while(true) {
      |                             ^
a.cc:27:49: error: expected '}' at end of input
   27 |                         System.out.println(ans);
      |                                                 ^
a.cc:4:48: note: to match this '{'
    4 |         public static void main(String[] args) {
      |                                                ^
a.cc: At global scope:
a.cc:27:49: error: expected unqualified-id at end of input
   27 |                         System.out.println(ans);
      |                                                 ^