jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 2; i < 1e7; i++ {
		j := i
		for n%j == 0 {
			ans++
			n /= j
			j *= i
		}
		for n%i == 0 {
			n /= i
		}
	}
	if n >= 1e7 {
		ans++
	}
	fmt.Println(ans)
}
//  [ruby]
require 'prime'

N = gets.to_i

factors = N.prime_division

S = {}
S[0] = 0

1.upto(N) do |i|
  s = S[i] = S[i-1] + i

  break if s > N
end

T = S.invert

c = 0

factors.each do |(_, n)|
  j = n

  while T[j].nil?
    j -= 1
  end

  c += T[j]
end

p c
//  [ruby]
require 'prime'

n = gets.to_i
mem = {}
ans = 0
if Prime.prime?(n)
  ans = 1
else
  loop do
    last = n
    Prime.each do |pr|
      mem[pr] ||= 1
      z = pr**mem[pr]
      if n % z == 0
        n /= z
        mem[pr] += 1
        ans += 1
        break
      end
      break if n < pr
    end
    if Prime.prime?(n)
      ans += 1 unless mem[n]
      break
    end
    break if last == n
  end
end
puts ans
//  [ruby]
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
N = gets_i

require 'prime'

factors = N.prime_division

dpp factors

if factors.empty?
  puts 0
else
  count = 0
  factors.each do |_, c|
    i = 1
    loop do
      break if c < i
      c = c - i
      count += 1
      i += 1
    end
  end
  puts count
end
//  [rust]
use text_io::read;
use whiteread::{parse_line, reader::Result};
use num_integer::Roots;

fn isprime(x: i64, ps: Vec<&i64>) -> bool {
    ps.iter().all(|&y| x%y != 0)
}

fn until_sqrt(v: &Vec<i64>, x: i64) -> Vec<&i64> {
    v.iter().take_while(|y| y.pow(2) <= x).collect()
}

fn primes(max: i64) -> Vec<i64> {
    let mut ps: Vec<i64> = Vec::new();
    let n = max.sqrt();

    for x in 2..=n {
        if isprime(x, until_sqrt(&ps, x)) {
            // println!("{} is prime", x);
            ps.push(x)
        }
    }

    ps
}

fn main() -> Result<()> {
    let n: i64 = read!();

    if n == 1 {
        println!("0");
    } else {
        let ps = primes(n);
        println!("{}", f(n, ps));
    }

    Ok(())
}

fn f(x: i64, ps: Vec<i64>) -> i32 {
    let mut y = x;
    let mut ans: i32 = 0;
    let mut z;

    for p in ps {
        z = p;
        while y % z == 0 {
            y /= z;
            z *= p;
            ans += 1;
        }
        while y % p == 0 {
            y /= p;
        }
    }

    if y != 1 {
        ans += 1;
    }

    ans
}
//  [rust]
struct Get<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R: std::io::BufRead> Get<R> {
    pub fn new(stdin: R) -> Self {
        Get {
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0;
        self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut iter = buf.split_whitespace();
        loop {
            let x = iter.next();
            if x.is_none() {
                break;
            }
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn once<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {
            self.read_line();
        }
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
}
mod prime {
    #[allow(dead_code)]
    pub fn is_prime(n: usize) -> bool {
        match n {
            0 | 1 => false,
            2 => true,
            _ => {
                if n % 2 == 0 {
                    return false;
                }
                let mut i = 3;
                while i <= (n as f64).sqrt() as usize + 1 {
                    if n % i == 0 {
                        return false;
                    }
                    i+=2;
                }
                true
            }
        }
    }
    #[allow(dead_code)]
    pub fn prime_all(n: usize) -> Vec<usize> {
        let mut list = Vec::new();
        for i in 2..n + 1 {
            if is_prime(i) {
                list.push(i);
            }
        }
        list
    }
    #[allow(dead_code)]
    pub fn factorize(mut n: usize) -> Vec<(usize, usize)> {
        let mut list = Vec::new();
        if is_prime(n) {
            list.push((n, 1));
            return list;
        }
        let primes = prime_all((n as f64).sqrt() as usize + 1);
        for x in &primes {
            let x = *x;
            if n % x != 0 {
                continue;
            }
            list.push((x, 0_usize));
            while n % x == 0 {
                n/=x;
                let index = list.len() - 1;
                list[index].1 += 1;
            }
            if is_prime(n) {
                list.push((n,1));
                break;
            }
        }
        list
    }
}
fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let get = Get::new(stdin);
    solve(get);
}

use std::cmp;
fn solve<R: std::io::BufRead>(mut get:Get<R>) {
    let n:usize = get.once();
    let fact_list = prime::factorize(n);
    let mut ans = 0;
    //println!("{:?}",fact_list);
    for (p, e) in &fact_list {
        let mut sum = 0;
        for i in 1.. {
            sum+=i;
            if sum > *e {
                break;
            }
            ans+=1;
        }
    }
    println!("{}",ans);
}
//  [python]
def no_dislike_number(num, D):
    for dislike in D:
        if dislike in num:
            return False
    return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1
//  [python]
N, _ = [int(x) for x in input().split()]
D = set(range(10)) - set([int(x) for x in input().split()])
n = [int(x) for x in list(str(N))]

i = 0
while i < len(n):
    if n[i] not in D:
        cand = {x for x in D if x > n[i]}
        if len(cand) > 0:
            n[i] = min(cand)
            for j in range(i + 1, len(n)):
                n[j] = 0
            i += 1
        elif i > 0:
                n[i - 1] += 1
                n[i] = 0
                i -= 1
        else:
            n = [1] + [0] * len(n)
    else:
        i += 1

print(''.join([str(x) for x in n]))
//  [python]
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in range(n, 100000):
        s = np.array(list(map(int, str(i))), dtype=np.int64)
        ok = True
        for j in s:
            ok &= j not in a
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int64, sep=' ')
    a = np.fromstring(read(), dtype=np.int64, sep=' ')
    main(n, k, a)
//  [java]
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] D = new int[K];
		for(int i = 0; i < K; i++)
			D[i] = sc.nextInt();
		int ans = N;
		while(true) {
			boolean ok = true;
			for(int i = 0; i < K; i++) {
				for(int j = 0; j < String.valueOf(ans).length(); j++) {
					if(D[i] == ans/(int)Math.pow(10, j)%10) {
						ok = false;
					}
				}
			}
			if(ok)
				break;
			ans++;
		}
		System.out.println(ans);
	}

}
//  [java]
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int payment = Integer.parseInt(scanner.nextLine().split(" ")[0]);
		List<String> dislikes = Arrays.stream(scanner.nextLine().split(" ")).sorted().collect(Collectors.toList());

		while(!isAcceptable(payment, dislikes)) {
			payment++;
		}

		System.out.println(payment);
	}

	private static boolean isAcceptable(int payment, List<String> dislikes) {
		return !Arrays.stream(Integer.toString(payment).split("")).anyMatch(dislikes::contains);
	}
}
//  [cpp]
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//内積
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//外積
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//直行？
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//平行？
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


int main()
{
	int n, k; cin >> n >> k;
	vector<string> st;
	for (int i = 0; i < k; i++)
	{
		string s; cin >> s;
		st.push_back(s);
	}
	while (1)
	{
		stringstream ss;
		ss << n;
		bool ok = true;
		for (int i = 0; i < k; i++)
		{
			for (int j = 0; j < ss.str().size(); j++)
			{
				if (ss.str()[j] == st[i][0])ok = false;
			}
		}
		if (ok)break;
		n++;
	}
	cout << n << endl;

}
//  [cpp]
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int N, K, min = 0, t=0;
    bool answer = true;
    cin >> N >> K;
    vector<char> D(K);
    for(int i = 0; i < K; i++){
        cin >> D[i];
    }
    for(int i = N; i < 10*N; i++){
        answer = true;
        for(int j = 0; j < to_string(i).size(); j++){
            for(int l = 0; l < K;l++){
                if(to_string(i).at(j) == D[l]){answer = false;}
            }
        }
        if(answer == true){
                min = i;
                break;
        }
    }
    cout << min << endl;
}
//  [c]
#include <math.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y)(x>y?x:y)
int main(){
	int n,k,t,all[6]={0},d[10]={0};
	scanf("%d%d",&n,&k);
	rep(i,k){scanf("%d",&t);d[t]++;}
	if(n==1&&d[1]!=1){printf("1");return 0;}
	t++;
	Rep(i,2<n?n:2,1e5){
		rep(j,log10(i)+1){
			all[j]=(i%(int)pow(10,j+1))/(int)pow(10,j); 
			rep(x,10)if(d[all[j]])t=0;
		}
		if(t){printf("%d",i);return 0;}
		t++;
	}
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long lld;
typedef long double Lf;
#define Ma(x,y)((x)>(y)?(x):(y))
#define mi(x,y)((x)<(y)?(x):(y))

int main() {
	int n, k, t, all[6] = { 0 }, d[10] = { 0 };
	scanf("%d%d", &n, &k);
	rep(i, k) { scanf("%d", &t); d[t]++; }
	if (n == 1 && d[1] != 1) { printf("1"); return 0; }
	t++;
	Rep(i, 2 < n ? n : 2, 1e5) {
		rep(j, log10(i) + 1) {
			all[j] = (i % (int)pow(10, j + 1)) / (int)pow(10, j);
			rep(x, 10)if (d[all[j]])t = 0;
		}
		if (t) { printf("%d", i); return 0; }
		t++;
	}
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long lld;
typedef long double Lf;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {
	int n, k, t, all[6] = { 0 }, d[10] = { 0 };
	scanf("%d%d", &n, &k);
	rep(i, k) { scanf("%d", &t); d[t]++; }
	if (n == 1 && d[1] != 1) { printf("1"); return 0; }
	t++;
	Rep(i, 2 < n ? n : 2, 1e9) {
		rep(j, log10(i) + 1) {
			all[j] = (i % (int)pow(10, j + 1)) / (int)pow(10, j);
			rep(x, 10)if (d[all[j]])t = 0;
		}
		if (t) { printf("%d", i); return 0; }
		t++;
	}
}
//  [javascript]
function Main(input) {
	var lines = input.split("\n");
	var n_num = Number(lines[0].split(' ')[0])
	var n_str = lines[0].split(' ')[0].split('')
	var d = lines[1].split(' ')
	while(1) {
		if(n_str.some(n => d.indexOf(n) > -1)) {
			n_num++
			n_str = (n_num + '').split('')
		} else {
			console.log(n_num)
			break
		}
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=t.in(),n=new Array(r),i=0;i<r;i++)n[i]=t.in();for(var o=e;o<=1e6;o++){for(var s=o,u=!0;s>0;){for(var c=s%10,f=0;f<r;f++)if(n[f]==c){u=!1;break}if(!u)break;s=Math.floor(s/10)}if(u)return void console.log(o)}}}]);
//  [javascript]
'use strict';

function main(input) {
  const lines = input.split('\n');
  const n = lines[0].split(' ').shift() | 0;
  const d = lines[1].split(' ').map((x) => x | 0);

  let ans = n;
  const reg = RegExp(d.join('|'));
  while (reg.test(ans)) {
    ans += 1;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"fmt"
	"sort"
	"strconv"
)

func main() {
	var N, K, w int
	fmt.Scan(&N, &K)
	m := map[int]int{}
	for i := 0; i < K; i++ {
		fmt.Scan(&w)
		m[w]++
	}
	var a []int
	for i := 0; i < 10; i++ {
		if _, ok := m[i]; !ok {
			a = append(a, i)
		}
	}
	var p []string
	for i := 0; i < len(a); i++ {
		p = append(p, strconv.Itoa(a[i]))
	}
	for i := 1; i < 6; i++ {
		q := len(p)
		for j := 0; j < q; j++ {
			if len(p[j]) == i {
				for k := 0; k < len(a); k++ {
					p = append(p, p[j]+strconv.Itoa(a[k]))
				}
			}
		}
	}
	var r []int
	for i := 0; i < len(p); i++ {
		v, _ := strconv.Atoi(p[i])
		r = append(r, v)
	}
	sort.Sort(sort.IntSlice(r))
	for i := 0; i < len(r); i++ {
		if r[i] >= N {
			fmt.Println(r[i])
			return
		}
	}
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	var k int
	fmt.Scan(&n, &k)
	sc.Split(bufio.ScanWords)

	hates := getHates(k)

	var count int

	for i := n; i < 100000; i++ {
		if count != len(hates) {
			count = 0
			for j := 0; j < len(hates); j++ {
				str := strconv.Itoa(i)
				if !strings.Contains(str, hates[j]) {
					count++
				}
			}
		} else {
			fmt.Println(i - 1)
			return
		}
	}
}

func getHates(k int) []string {
	var hates = make([]int, k, k)

	for i := 0; i < k; i++ {
		hates[i] = nextInt()
	}

	var strHates = make([]string, len(hates), len(hates))

	for i, hate := range hates {
		strHates[i] = strconv.Itoa(hate)
	}

	return strHates
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
//  [ruby]
kingaku,=gets.chomp.split.map(&:to_i)
i=kingaku
kirai_array=gets.chomp.split.map(&:to_i)
 
while 1
	if (i.to_s.split("").map(&:to_i) - kirai_array).size == i.to_s.split("").map(&:to_i).size
		puts i
        break
    end
i+=1
end
//  [ruby]
while line = gets
  a,b =line.chomp.split(" ").map(&:to_i);
  array =gets.chomp.split(" ").map(&:to_i);

  index = 0
  while true
    now = (a + index).to_s

    flg = true
    (now.length).times do|i|
      flg = false if array.any?{|c| c.to_s == now[i]}
    end
    if flg
      puts now
      break;
    end
    index += 1;
  end

end
//  [ruby]
def illegal_number? (price, denies)
  price.to_s.split('').map(&:to_i).each {|i|
    if denies.include?(i) then
      return true
    end
  }

  return false
end

price, count = gets.chomp.split.map(&:to_i)
denies = gets.chomp.split.map(&:to_i)

# base = 1

while illegal_number?(price, denies) do
  price += 1
end

puts price
//  [rust]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let K: usize = sc.get();
    let D: Vec<usize> = sc.vec(K);
    let mut ans = INF;
    for pay in N..1000000 {
        let mut rem = pay;
        let mut d = HashSet::new();
        while rem != 0 {
            d.insert(rem % 10);
            rem /= 10;
        }
        let mut ok = true;
        for i in 0..K {
            if d.contains(&D[i]) {
                ok = false;
            }
        }
        if ok {
            ans = min(ans, pay);
        }
    }
    println!("{}", ans);
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        k: i8,
        d: [i8; k],
    }

    let mut pay = n;
    loop {
        let mut contains = false;
        for num in d.iter() {
            if pay.to_string().contains(num.to_string().as_str()) {
                contains = true;
            }
        }
        if contains {
            pay += 1;
        } else {
            println!("{}", pay);
            return;
        }
    }
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(n: usize, k: usize, d: [i32; k]);
    let mut answer = n;
    while d
        .iter()
        .map(|item| format!("{}", answer).contains(&item.to_string()))
        .fold(false, |acc, second| acc || second)
    {
        answer += 1;
    }
    println!("{}", answer);
}
//  [typescript]
const fs = require('fs')
const reader = (s: string) => (s.split("\n"))
 
function Main(input: string) {

  const [aaa,bbb] = reader(input);
  const D = bbb.split(' ');
  const [N,K] = aaa.split(' ').map(a => (parseInt(a)));
  for(let i= N; i < 100000 ; i++)
  {
    if(D.every( d =>(!(i.toString().includes(d)))))
    {
      console.log(i);
      break;
    }
  }

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))
//  [python]
import itertools
k = int(input())

d = [[] for _ in range(k)]

for i in range(1, k+1):
    n = 1
    while i*n <= k:
        d[i*n-1].append(i)
        n += 1

seq = [i for i in range(1, k+1)]
ans = 0
A = list(itertools.combinations_with_replacement(seq, 3))
for a in A:
    a1 = a[0]
    a2 = a[1]
    a3 = a[2]
    if a1 == a2 == a3:
        m = 1
    elif a1 == a2 or a1 == a3 or a2 == a3:
        m = 3
    else:
        m = 6
    ans += max(set(d[a1-1]) & set(d[a2-1]) & set(d[a3-1])) * m

print(ans)
//  [python]
from math import gcd as gcd

K = int(input())

ans = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(gcd(j, k), i)

print(ans)
//  [python]
import math

def gcd(n1,n2,n3):
    return math.gcd(math.gcd(n1,n2), n3)
    
ans = 0
K = int(input())
r = range(1, K+1)

print(sum([gcd(x1,x2,x3) for x1 in r for x2 in r for x3 in r ]))
//  [java]
import java.io.*;
import java.util.*;

public class Main {
    static int gcd(int a, int b)
    {
        // Everything divides 0
        if (a == 0)
            return b;
        if (b == 0)
            return a;

        // base case
        if (a == b)
            return a;

        // a is greater
        if (a > b)
            return gcd(a-b, b);
        return gcd(a, b-a);
    }
    public static void main(String[] args) throws Exception{

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));


        int k = fs.nextInt();
      long ans = 0 ;
        for(int i=1 ; i<=k ; i++){
          for(int j=1 ; j<=k ; j++){
          	for(int l=1 ; l<=k ; l++){
            	ans += gcd(gcd(i,j),l);
            }
          }
        }
       
        out.println(ans);
        


        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}
//  [java]
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        BigInteger sum = BigInteger.ZERO;
        int tmpGcd;
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Map<String, Integer> tmpMap = new HashMap<>();
        for (int a = 1; a <= N; a++) {
            for (int b = 1; b <= N; b++) {
                for (int c = 1; c <= N; c++) {
                    tmpGcd = mygcd(a, b, tmpMap);
                    sum = sum.add(BigInteger.valueOf(mygcd(tmpGcd, c, tmpMap)));
                }
            }
        }
        System.out.println(sum);
    }

    public static int mygcd(int a, int b, Map<String, Integer> tmpMap) {
        if (a == b) {
            return a;
        }
        int tmpGcd;
        List<Integer> tmp = new ArrayList<Integer>();
        tmp.add(a);
        tmp.add(b);
        Collections.sort(tmp);
        String tmpStr = "" + tmp.get(0) + tmp.get(1);
        if (false && tmpMap.containsKey(tmpStr)) {
            tmpGcd = tmpMap.get(tmpStr);
        } else {
            tmpGcd = gcd(a, b);
            tmpMap.put(tmpStr, tmpGcd);
        }
        return tmpGcd;
    }

    public static int gcd(int num1, int num2) {
        if (num2 == 0)
            return num1;
        else
            return gcd(num2, num1 % num2);
    }

    public static int gcda(int a, int b) {
        int tmp, r;
        if (a < b) {
            tmp = a;
            a = b;
            b = tmp;
        }

        r = a % b;
        while (r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }

}
//  [java]


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int max = sc.nextInt();
		
		long result = 0;
		
		long kouyaku = 1;
		
		for(int a = 1; a <= max; a++) {
		
			for(int b = 1; b <= max; b++) {
			
				for(int c= 1; c <= max; c++) {
				
					int ap = a;
					
					int bp = b;
					
					int cp = c;
					
					for(int j= 1; j <= ap && j <= bp && j <= cp; j++) {
							
							if(ap%j == 0 && bp%j ==0 && cp%j == 0) {
								
								kouyaku *= j;
								
								ap /= j;
								
								bp /= j;
								
								cp /= j;
								
								j = 1;
								
							}
							
					}
						
						result += kouyaku;
						
						kouyaku = 1;
						
					}
					
				}
			}
		
						
		
		sc.close();
		
		System.out.println(result);
		
	}
	
}
//  [cpp]
#include<iostream>
using namespace std;
int GCD(int a,int b,int c)
{
	int i,t=1;
	for(i=2;i<=a;i++)
	{
		if(a%i==0&&b%i==0&&c%i==0)
		t=i;
	}
	return t;
}
int main()
{
	int k,i,j,l,m=0;
	cin>>k;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			for(l=1;l<=k;l++)
			{
				m+=GCD(i,j,l);
			}
		}
	}
	cout<<m;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int K;

int gcd(int a, int b, int c){
    for(int d = c; d > 0; d--){
        if(a%d == 0 and b%d == 0 and c%d == 0){
            return d;
        }
    }
}

int main(){
    int ans = 0;
    cin >> K;

    for(int a = 1; a < K + 1; a++){
        for(int b = 1; b < K + 1;b++){
            for(int c = 1; c < K + 1; c++){
                ans += gcd(a, b, c);
            }
        }
    }

    cout << ans << endl;
}
//  [cpp]
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
map<int,int>p;
int a[200000];
int gcd(int x,int y,int z)
{
	int i;
	for(i=z;i>=1;i--)
	{
		if(x%i==0&&y%i==0&&z%i==0)
		return i;
		
	}
}
int main()
{
	ll m,n,i,j,t,s=0,k;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				s+=gcd(i,j,k);
			}
		}
	}
	cout<<s;
 }
//  [c]
#include <stdio.h>
int gcd(int a,int b);

int main(){
	int N, sum=0;
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
	    for(int j=1; j<=N; j++){
	        for(int k=1; k<=N; k++){
	            sum+= gcd(i,gcd(j,k));
	           
	        }
	    }
	}

	 printf("%d\n",sum);
	return 0;
}

int gcd(int a, int b){
	int small;
	if(a<b){
	    small = a;
	}else{
		small = b;
	}
	int max = 1;
	for(int i=1; i<=small; i++){
	    if((a%i==0)&&(b%i==0)){
	        max = i;
	    }
	}
	//printf("a= %d b= %d max=%d\n",a,b,max);
	return max;
}
//  [c]
#include<stdio.h>
int gcd(int a,int b);
int main(){
    int k,sum=0;
    scanf("%d",&k);
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                sum+=gcd(i,gcd(j,l));
                

            }
        }
    }

    printf("%d\n",sum);
    
    
    
    return 0;
}

int gcd(int a,int b){
    int small;
    if(a<b){
        small=a;
    }else{
        small=b;
    }
    int max=1;
    for(int i=1;i<=small;i++){
        if((a%i==0)&&(b%i==0)){
            max=i;
        }
    }
    return max;
}
//  [c]
#include<stdio.h>

int main(){
  int k; 
  int m;
  long int ans= 0;
 
  scanf("%d",&k);
  
  for(int c = 1;c<=k;c++){    
    for(int b = 1;b<=k;b++){
      for(int a = 1;a<=k;a++){
         int l=0;
        
        if(a<=b && a<=c){
         m = a;
        }
        if(b<=a && b<=c){
          m=b;
        }
        if(c<=a && c<=b){
          m=c;
        }
        
        for(int i=1;i<=m;i++){
          if(a%i==0 && b%i==0){
            if(c%i==0){
            l=i;
            }
          }
        }
        ans+=l;
      }
    }
  }
  printf("%ld",ans);
  return 0;
}
//  [javascript]
const fs = require("fs");
const buffer = fs.readFileSync(0); // STDIN_FILENO = 0
const K = parseInt(buffer.toString());


function* combinations(elements, length) {
  for (let i = 0; i < elements.length; i++) {
    if (length === 1) {
      yield [elements[i]];
    } else {
      let remaining = combinations(elements.slice(i, elements.length), length - 1);
      for (let next of remaining) {
        yield [elements[i], ...next];
      }
    }
  };
}


function gcd(a, b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

function solve(K) {
  const numbers = Array(K).fill().map((_, i) => i + 1)
  const combs = Array.from(combinations(numbers, 3));
  let result = 0;
  for (let comb of combs) {
    if (comb[0] === comb[1] && comb[1] === comb[2]) {
      result += comb[0]
    } else if(comb[0] === comb[1] || comb[1] === comb[2]) {
      result += 3 * gcd(comb[0], gcd(comb[1], comb[2]));
    }else{
      result += 6 * gcd(comb[0], gcd(comb[1], comb[2]));
    }
  }
  console.log(result)
}

solve(K)
//  [javascript]
function Main(input) {
  const k = input;
  let sum = 0;

  const dv = n => {
    const divisors = [];
    const s = Math.sqrt(n);

    for (let i = 1; i <= s; i++) {
      if (n % i === 0) {
        if (i === n / i) {
          divisors.push(i);
        } else {
          divisors.push(i, n / i);
        }
      }
    }

    return divisors;
  }

  const gcd = (a, b, c) => {
    const min = Math.min(a, b, c);
    const dvmin = dv(min);
    const candidate = [];

    dvmin.forEach(i => {
      if (a % i === 0 && b % i === 0 && c % i === 0) {
        candidate.push(i);
      }
    })

    return Math.max(...candidate);
  }

  for (let a = 1; a <= k; a++) {
    for (let b = 1; b <= k; b++) {
      for (let c = 1; c <= k; c++) {
        sum += gcd(a, b, c);
      }
    }
  }

  console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  var count = 0
  for(var i = 1;i <= input;i++){
    for(var j = 1;j <= input;j++){
     for(var k = 1;k <= input;k++){
        count+=gcd(i,j,k);   
  }
  }
  }
      console.log(count);
}

function gcd() {
    var f = (a, b) => b ? f(b, a % b) : a
    var ans = arguments[0]
    for (var i = 1; i < arguments.length; i++) {
        ans = f(ans, arguments[i]); 
    }
    return ans 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func gcd2(a, b int) int {
	if b == 0 {
		return a
	}

	return gcd2(b, a%b)
}

func gcd3(a, b, c int) int {
	buf := []int{a, b, c}

	sort.Ints(buf)

	g2 := gcd2(buf[2], buf[1])

	if buf[0] == g2 {
		return g2
	}

	if buf[0] < g2 {
		return gcd2(g2, buf[0])
	} else {
		return gcd2(buf[0], g2)
	}
}

func main() {
	line1 := inputs(1)

	k, _ := strconv.Atoi(line1[0])

	sum := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += gcd3(a, b, c)
			}
		}
	}

	fmt.Println(sum)

	return
}
//  [go]
package main

import (
        "fmt"
)

var divisor[201]map[int]bool

func makeDivisor() {

        for i := 0; i <= 200; i++ {
                divisor[i] = make(map[int]bool)
        }
        for v := 1; v <= 200; v++ {
                for m := 1; v * m <= 200; m++ {
                        divisor[v*m][v] = true
                }
        }
}

func gcd(a,b,c int) int {
        max := 1
        for av, _ := range divisor[a] {
                if divisor[b][av] && divisor[c][av] && av > max {
                        max = av
                }
        }
        return max
}

func main() {
        makeDivisor()

        var K int
        fmt.Scanf("%d", &K)
        var sum uint64
        for a := 1; a <= K; a++ {
                for b := 1; b <= K; b++ {
                        for c := 1; c <= K; c++ {
                                sum += uint64(gcd(a,b,c))
                        }
                }
        }
        fmt.Printf("%v\n", sum)
}
//  [ruby]
K = gets.to_i

arr = [*(1..K)]

sum = 0
new_arr = arr.repeated_permutation(3).to_a

new_arr.each do |a,b,c|
  sum += a.gcd(b.gcd(c))
end

puts sum
//  [ruby]
eval"k=*1..%d;f=->a{a.product(k).map{|a,b|a.gcd b}};p f[f[k]].sum"%gets
//  [ruby]
k=*1..gets.to_i;f=->a{a.product(k).map{_1.gcd _2}};p f[f[k]].sum
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        k:i64,
    }
    let mut ans = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                ans += gcd_list(&vec![a, b, c]);
            }
        }
    }
    println!("{}", ans);
}
pub fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
pub fn gcd_list(list: &[i64]) -> i64 {
    list.iter().fold(list[0], |a, &b| gcd(a, b))
}
//  [rust]
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let k: usize = read();
    let mut ans: usize = 0;
    for a in 1..=k {
      for b in 1..=k {
        for c in 1..=k {
          ans += gcd(a, gcd(b, c));
        }
      }
    }

    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
  if b > a {
    gcd(b, a);
  }

  if a % b == 0 {
    return b;
  }

  let r: usize = a % b;

  return gcd(b, r);
}
//  [swift]
func gcd(_ a: Int, _ b: Int) -> Int {
    guard b != 0 else { return a }
    return gcd(b, a % b)
}

func gcda(_ s: [Int]) -> Int {
    guard !s.isEmpty else { return 0 }
    guard s.count > 1 else { return s.first! }

    var tmpS = s
    let first = tmpS.removeFirst()
    return tmpS.reduce(first) { gcd($0, $1) }
}

func memoize(_ f: @escaping ([Int]) -> Int) -> ([Int]) -> Int {
    var dic = [[Int] : Int]()
    return { nums in
        if let value = dic[nums.sorted()] {
            return value
        } else {
            let result = f(nums)
            dic[nums] = result
            return result
        }
    }
}

let m_gcda = memoize(gcda)

let k = Int(readLine()!)!

var results = [Int]()
for a in 1...k {
    for b in 1...k {
        for c in 1...k {
            results.append(gcda([a, b, c]))
        }
    }
}

let sum = results.reduce(into: 0) { $0 += $1 }
print(sum)
//  [swift]
import Foundation


    func solveGCD(_ a: Int, _ b: Int) -> Int {
        if a == 0 || b == 0 {
            fatalError("Fount zero value in the arguments")
        }
        var i = a, j = b
        
        if i < j {
            swap(&i, &j) // a < b だとwhile内で処理が a >= b のときより一度だけ多く行われて計算の無駄
         }
        
        while let l: Int = i%j, l != 0 {
            i = j
            j = l
        }
        
        return abs(j) //最小公倍数は常に正の整数とする
    }
    func solveGCD(numbers numbers_: Int...) -> Int {
        if numbers_.count < 2 {
            fatalError("No enough arguments")
        }
        var numbers = numbers_
        while numbers.count != 2 {
            numbers[1] = solveGCD(numbers[0], numbers[1])
            numbers.remove(at: 0)
        }
        return solveGCD(numbers[0], numbers[1])
    }
 
let inputLine: String = readLine()!
 
let k: Int = Int(inputLine)!

let a = 1
let b = 1
let c = 1
 
var ans = 0;

for a in 1...k {
  for b in 1...k {
    for c in 1...k {
      ans += solveGCD(numbers: a, b, c)
    }
  }
}


 
print(ans)
//  [swift]
import Foundation

func gcd(_ A: Int, _ B: Int) -> Int {
  var a = A, b = B
  while b > 0 {
    var r = a % b; a = b; b = r
  }
  return a
}

let K = Int(readLine()!)!
var sum = 0
for a in 1...K {
  for b in 1...K {
    for c in 1...K {
      sum += gcd(a, gcd(b, c))
    }
  }
}
print(sum)
//  [typescript]
import * as fs from 'fs';

function gcd(a: number, b: number, c: number) {
    const min = Math.min(a, b, c);
    let gcd = 1;
    for (let i = 2; i <= min; i++) {
        if (a % i === 0 &&
            b % i === 0 &&
            c % i === 0) {
            gcd = i;
        }
    }
    return gcd;
}

function Main(input: string) {
    const constraintK = parseInt(input);
    let sum = 0;

    for (let a = 1; a <= constraintK; a++) {
        for (let b = 1; b <= constraintK; b++) {
            for (let c = 1; c <= constraintK; c++) {
                sum += gcd(a, b, c);
            }
        }
    }

    //output
    console.log(sum);
}

Main(fs.readFileSync("/dev/stdin", "utf8"));
//  [typescript]
import { readFileSync } from "fs";

const memo: number[][] = [];
const gcd = (a: number, b: number): number => {
  memo[a] || (memo[a] = []);
  return memo[a][b] || (memo[a][b] = a === 0 ? b : gcd(b % a, a));
};

export const solveC = (n: number): number => {
  let sum = 0;
  for (let i = 1; i <= n; i++)
    for (let j = 1; j <= n; j++)
      for (let k = 1; k <= n; k++) {
        const [a, b, c] = [i, j, k].sort((x, y) => x - y);
        sum += gcd(gcd(a, b), c);
      }
  return sum;
};

if (require.main === module)
  console.log(solveC(+readFileSync("/dev/stdin", "utf8")));
//  [typescript]
function gcd(a: number, b: number, c: number) {

    const f = (x: number, y: number) => y ? f(y, x % y) : x

    var ans = a
    ans = f(ans, b);
    ans = f(ans, c);
    return ans
}

import * as fs from "fs";
const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [k] = input[0].split(" ").map((x: string): number => +x);
// const k = 200

var sum = 0
let maps: Map<string, number> = new Map<string, number>()

for (var x: number = 1; x <= k; x++) {
    for (var y: number = 1; y <= k; y++) {
        for (var z: number = 1; z <= k; z++) {
            // let t = [x, y, z]
            // t = t.sort(function (p: number, q: number) {
            //     return p - q
            // })
            // const xyz: string = t[0].toString() + t[1].toString() + t[2].toString()
            // if (!maps.has(xyz)) {
            //     const res = gcd(x, y, z)
            //     maps[xyz] = res
            // }
            // sum += maps[xyz]
            sum += gcd(x, y, z)
        }
    }
}

console.log(sum)
//  [python]
S = input()
L = len(S)
ans = "NO"
for i in range(8):
    if S[:i] + S[i-7:] == "keyence":
        ans = "YES"
print(ans)
//  [python]
#!/usr/bin/python3

secret = 'keyence'
s = input()
n = len(s)
m = len(secret)

if n < m:
    print("NO")
    exit(0)

for i in range(m):
    if s[:i] + s[-(m - i):] == secret:
        print("YES")
        exit(0)

print("NO")
//  [python]
s = input()
K = "keyence"

def solve():
    if s.startswith(K) or s.endswith(K):
        return "YES"
    else:
        for i in range(len(K)):
            head = K[:i]
            tail = K[i:]
            if s.startswith(head) and s.endswith(tail):
                return "YES"
    return "NO"

print(solve())
//  [python]
import numpy as np

s = input()
if s == 'keyence':
    print('YES')
    exit()

for i in range(0,len(s)):
    for j in range(len(s)):
        tmp = s[:i] + s[j:]
        if tmp=='keyence':
            print('YES')
            exit()
print('NO')
//  [python]
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
m = list(input())
n = list("keyence")

a=0
for i in range(len(n)):
    if m[i]==n[i]:
        a += 1
    else:
        break

for i in range(1,len(n)):
    if m[-i]==n[-i]:
        a += 1
    else:
        break    

if a >= 7:
    print("YES")
else:
    print("NO")
//  [python]
import copy
S = str(input())
s = list(S)
L = len(s)
break2 = 0
text = ""
for i in range(L):
    j = 0
    for j in range(L):
        t = copy.deepcopy(s)
        del t[i:j+1]
        text = "".join(t)
        if text == "keyence":
            print("YES")
            break2 = 1
            break
        else:
            pass
    if break2 == 1:
        break
if break2 == 0:
    print("NO")
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] start = {"keyenc", "keyen", "keye", "key", "ke", "k"};
		String[] end = {"e", "ce", "nce", "ence", "yence", "eyence"};

		if(str.startsWith("keyence") || str.endsWith("keyence")) {
			System.out.println("YES");
		}else {
			for(int i=0; i<6; i++) {
				if(str.startsWith(start[i]) && str.endsWith(end[i])) {
					System.out.println("YES");
					break;
				}
				if(i==5) {
					System.out.println("NO");
				}
			}

		}
	}

}