<commit_before>package leetcode;

/**
 * https://leetcode.com/problems/beautiful-arrangement/
 */
public class Problem526 {
    public int countArrangement(int N) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem526 prob = new Problem526();
        System.out.println(prob.countArrangement(2)); // 2
    }
}<commit_msg>Update problem 526<commit_after>package leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * https://leetcode.com/problems/beautiful-arrangement/
 */
public class Problem526 {
    public int countArrangement(int N) {
        List<Integer> numbers = new ArrayList<>();
        for (int i = 1; i <= N; i++) {
            numbers.add(i);
        }
        IntRef result = new IntRef();
        countArrangement(numbers, new HashSet<>(), 1, result);
        return result.ref;
    }

    private static class IntRef {
        int ref;
    }

    private static void countArrangement(List<Integer> numbers,
                                         Set<Integer> processed,
                                         int count,
                                         IntRef result) {
        if (count > numbers.size()) {
            result.ref++;
            return;
        }
        for (int i = 0; i < numbers.size(); i++) {
            int val = numbers.get(i);
            if (processed.contains(val)) {
                continue;
            }
            if (val % count == 0 || count % val == 0) {
                processed.add(val);
                countArrangement(numbers, processed, count + 1, result);
                // backtracking
                processed.remove(val);
            }
        }
    }

    public static void main(String[] args) {
        Problem526 prob = new Problem526();
        System.out.println(prob.countArrangement(2)); // 2
        System.out.println(prob.countArrangement(3)); // 2
        System.out.println(prob.countArrangement(10)); // 700
        System.out.println(prob.countArrangement(15)); // 24679
    }
}
{'fraction_non_alphanumeric': 0.12164750957854406, 'fraction_numerical': 0.022030651340996167, 'mean_word_length': 1.712987012987013, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6424337', 'n_tokens_mistral': 624, 'n_tokens_neox': 571, 'n_words': 134}