akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    long double p[n];
    for(int i=0;i<n;i++) cin >> p[i];
    long double dp[n+1][n+1];
    memset(dp, 0.0, sizeof(dp));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0) dp[i][j]=dp[i-1][j]*(1.0-p[i-1]);
            else dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1.0-p[i-1]);
        }
    }
    long double s=0.0;
    for(int i=(n+1)/2;i<=n;i++){
        s+=dp[n][i];
    }
    cout << fixed << setprecision(10) << s << "\n";
}


Measured memory_bytes: 140928
/*                          /
/      2014.08.23           /
/                          */

//真っ白な紙にインクを垂らしインク絵汚れていない部分の数を出力し、汚れる回数が多いエリアを出力する。
//落とすインク液は少しならば１、中ぐらいなら２、多いならば３とする。
#include<stdio.h>

void littleDrop(int,int,int *,int);
void midiumDrop(int,int *,int);
void largeDrop(int,int *);
void showArray(int [][10]);

void largeDrop(int center,int *tbl){
	if(center >= 20)//二つ上に配列があるか確認
		*(tbl - 20) += 1;
	if(center % 10 >= 2)//二つ左に配列があるか確認
		*(tbl - 2) += 1;
	if(center % 10 <= 7)//二つ右に配列があるか確認
		*(tbl + 2) += 1;
	if(center <= 80)//二つ下に配列がある確認
		*(tbl + 20) += 1;
}

void midiumDrop(int center,int *tbl ,int size){
//真ん中と八方に+1//
	if(center % 10 != 0 && center > 10)//左、上に配列があるか確認
		*(tbl - 11) += 1;
	if(center % 10 != 9 && center > 10)//右、上に配列があるか確認
		*(tbl - 9) += 1;
	if(center % 10 != 0 && center < 90)//左、下に配列があるか確認
		*(tbl + 9) += 1;
	if(center % 10 != 9 && center < 90)//右、下に配列があるか確認
		*(tbl + 11) += 1;
	if(size == 3)
		largeDrop(center,tbl);
}


void littleDrop(int x ,int y ,int *tbl,int size){
//インクを落とす場所は左上(0,0)から何番目かを求める。
	int center = x + y * 10;
//(0,0)から中央へと移動させる
	tbl = (tbl + center);

//真ん中に+1
	*(tbl) += 1;
//上に+1
	if(center >= 10)//上に配列があるか確認
		*(tbl - 10) += 1;
	if(center <= 90)//下に配列があるか確認
		*(tbl + 10) += 1;
	if(center % 10 != 0)//左に配列があるか確認
		*(tbl - 1) += 1;
	if(center % 10 != 9)//右に配列があるか確認
		*(tbl + 1) += 1;
	if(size >= 2)
		midiumDrop(center, tbl, size);
}

void showArray(int in[10][10]){
	int i,j;
	for(i = 0 ; i < 10 ;i ++){
		for(j = 0; j < 10; j ++){
			printf("%d ",in[i][j]);
		}
		printf("\n");
	}
}


int main(void){
	int i,j,clear=0,max=0;
	int x,y,size;
	int tbl[10][10] = {0};

	while(scanf("%d,%d,%d",&x ,&y ,&size) != EOF){
		getchar();//改行をとることでバッファに\nがたまるのを防ぐ
		if(x >= 0 && y >= 0 && size >= 0 && size <= 3 && x <= 9 && y <= 9)
			littleDrop(x,y,*tbl,size);
		//showArray(tbl);
	}

	for(i = 0 ; i < 10 ;i ++){
		for(j = 0; j < 10; j ++){
			//printf("%d ",tbl[i][j]);
			if(tbl[i][j] == 0)
				clear ++;
			else if(tbl[i][j] > max)
				max = tbl[i][j];
		}
		//printf("\n");
	}
	printf("%d\n",clear);//インクが落ちていない個所の合計
	printf("%d\n",max);//一番多くインクが落ちた量
	//getchar();//visual studio用
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, x, s = 0, ans = 1;

    scanf("%d", &n);
    while (n--) {
        scanf("%d", &x);
        if (x & 1) {
            s++;
        }
    }
    if (s & 1) {
        ans = 0;
    }
    puts(ans ? "YES" : "NO");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
	// your code goes here
		int n;
		cin >> n;
		int ar[n], dp[n];
		for(int i=0;i<n;++i){
			cin >> ar[i];
		}
  		dp[0] = 0;
		dp[1] = abs(ar[1]-ar[0]);
		for(int i = 2;i<n;++i){	
			dp[i] = min(abs(ar[i] - ar[i-2]) + dp[i-2], abs(ar[i] - ar[i-1]) + dp[i-1]);
        }
		cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int a = Integer.parseInt(br.readLine());
		int b = Integer.parseInt(br.readLine());
		int h = Integer.parseInt(br.readLine());
		sb.append((a+b)*h/2);
		System.out.print(sb);
	}
}

Measured memory_bytes: 8020
// luogu-judger-enable-o2
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<string>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long LL;
typedef double db;
using namespace std;
template<typename T>void read(T &x) {
    char ch=getchar(); x=0; T f=1;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}
string a="CODEFESTIVAL2016",b;
int main(){
	int ans=0;
    cin>>b;
    for(int i=0;i<a.size();i++)
    if(a[i]!=b[i])
    ans++;
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = as.nextInt();
		int[] a;
		int t = 0;
		int k = 10000;
		int s = 0;
		a = new int[100001];
		for(int i=0;i<n;i++){
			t = Integer.parseInt(as.next());
			a[t]++;
			k = Math.min(k, t);
			s = Math.max(s, t);
		}
		int q=0;
		int l=0;
		for(int i=k;i<=s;i++){
			if(a[i]==0){
				continue;
			}else if(a[i]%2==1){
				l++;
			}else{
				q++;
			}
		}
		if(q%2==1){
			l+=q-1;
		}else{
			l+=q;
		}
		System.out.println(l);
	}
}

Measured memory_bytes: 31740
#include <bits/stdc++.h>
using namespace std;

int main(){
    /* A */
    int n,x,t;
    cin >> n >> x >> t;
    int ans;
    if(n%x!=0)ans=(n/x+1)*t;
    else ans=n/x*t;
    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        double[][] memo = new double[n + 1][n + 1];
        memo[0][0] = 1;

        for (int i = 1; i <= n; i++) {
            double p = in.nextDouble();
            for (int j = 0; j <= n; j++) {
                if (j == 0) {
                    memo[i][j] = memo[i - 1][j] * (1 - p);
                } else {
                    memo[i][j] = memo[i - 1][j] * (1 - p) + memo[i - 1][j - 1] * p;
                }
            }
        }
        in.close();


        double result = 0;
        for (int i = 0; i <= n; i++) {
            if (i > n - i) {
                result = result + memo[n][i];
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 135004
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;
#define ll long long int

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string n;
	cin>>n;
	bool flag;
	flag=false;
	for (int i = 0; i < n.size(); ++i)
	{
		if(n[i]=='7'){
			flag=true;
			break;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;
		
}


Measured memory_bytes: 3652
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        _: usize,
        a: Chars,
        b: Chars,
        c: Chars,
    };
    let mut count = 0;
    for ((a_i, b_i), c_i) in a.iter().zip(b.iter()).zip(c.iter()) {
        if a_i == b_i && b_i == c_i {
            // do nothing
        } else if a_i == b_i || b_i == c_i || a_i == c_i {
            count += 1;
        } else {
            count += 2;
        }
    }
    let ans = count;
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e6+5;
signed
main(){
	//10e6までの素数を列挙
	//初期化
	bool isPrime[MAX+5];
	isPrime[1] = false;
	for(int i=2;i<=MAX;i++)
			isPrime[i] = true;

	for(int i=2;i<=MAX;i++)
	{
			if(isPrime[i])
					for(int j=2*i;j<=MAX;j+=i)
							isPrime[j] = false;
	}

	int a,d,n;
	while(cin >> a >> d >> n && !(a==0 && d==0 && n==0)){
			int cnt = 0;
			int ans = a;
			while(1)
			{
					if(isPrime[ans])
					{
							cnt++;
							if(cnt==n)
									break;
					}
					ans += d;
			}
			cout << ans << endl;
	}
}


Measured memory_bytes: 4052
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 100000;

char s[N + 1];

int solve()
{
    scanf("%s", s);
    int n = strlen(s);
    std::vector<int> idxs;
    for (int i = 0; i < n; ++ i) {
        if (s[i] != 'x') {
            idxs.push_back(i);
        }
    }
    bool ok = true;
    for (int i = 0; i < (int)idxs.size(); ++ i) {
        ok &= s[idxs[i]] == s[idxs[(int)idxs.size() - 1 - i]];
    }
    if (!ok) {
        return -1;
    }
    if (idxs.empty()) {
        return 0;
    }
    std::vector<int> cnts;
    cnts.push_back(idxs[0]);
    for (int i = 1; i < (int)idxs.size(); ++ i) {
        cnts.push_back(idxs[i] - idxs[i - 1] - 1);
    }
    cnts.push_back(n - 1 - idxs.back());
    int l = (int)idxs.size() >> 1;
    int r = (int)idxs.size() + 1 >> 1;
    int result = 0;
    while (l >= 0) {
        result += std::abs(cnts[l] - cnts[r]);
        l --;
        r ++;
    }
    return result;
}

int main()
{
    printf("%d\n", solve());
}


Measured memory_bytes: 1528
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
	s := ScanWord()
	if s == "ABC" {
		P("ARC")
	} else {
		P("ABC")
	}
	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 1772
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n,m;
  cin >> n >> m;
  cout << (1900*m+(n-m)*100)*pow(2,m) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
int K,S ;
    cin >> K >> S ;
int count=0;
  for (int i=0;i<=K;i++){
   for (int j=0; j<=K; j++){
    int z=S-i-j;
     if (z>=0 && z<=K) count ++;
   }
  }
  
  cout << count << endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back({a, i + 1});
  }
  sort(rbegin(v), rend(v));
  vector<int> r = {v.front().second};
  v.front().first--;
  for (; k >= 0; k--) {
    int t = r.back();
    sort(rbegin(v), rend(v));
    bool ng = false;
    for (auto& e : v) {
      if (e.second == t) continue;
      r.push_back(e.second);
      e.first--;
      ng |= e.first < 0;
    }
    if (ng) break;
  }
  if (k == -1) {
    cout << r.size() << endl;
    for (auto e : r) {
      cout << e << " ";
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 4e3 + 5;
const int MOD = 1e9 + 7;
int n, k;
int C[N][N];
void init() {
    C[0][0] = 1;
    for (int i = 1; i < N; ++i) {
        C[i][0] = 1;
        for (int j = 1; j <= i; ++j) C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
    }
}
int main() {
    init();
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= k; ++i) {
        LL tot = 0;
        if(n == k && i == 1) tot = 1;
        if(n-k-1 >= i-2 && i-2 >= 0) tot += C[k-1][i-1]*1LL*C[n-k-1][i-2]%MOD;
        if(n-k-1 >= i-1 && i-1 >= 0) tot += C[k-1][i-1]*2LL*C[n-k-1][i-1]%MOD;
        if(n-k-1 >= i && i >= 0) tot += C[k-1][i-1]*1LL*C[n-k-1][i]%MOD;
        printf("%lld\n", tot%MOD);
    }
    return 0;
}


Measured memory_bytes: 61440
#include <iostream>
#include <string>

int main(){
	std::string s, begin, end;
	
	std::cin >> s;

	begin = s.substr(0, 1);
	end = s.substr(s.size()-1, 1);

	std::cout << begin << s.size()-2 << end << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long x;
    long long cur = 100;
    cin >> x;

    long long res = 0;
    while (x > cur) {
        cur = cur + cur / 100;
        ++res;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import defaultdict
INF = float("inf")


def solve(s: str, t: str):

    S = len(s)
    T = len(t)
    ABC = defaultdict(list)
    for i, c in enumerate(s):
        ABC[c].append(i)

    counter = 0
    head = 0
    # print(ABC)
    for tt in t:
        if len(ABC[tt]) == 0:
            print(-1)
            return
        j = bisect_left(ABC[tt], head) % len(ABC[tt])
        counter += (ABC[tt][j]-head) % S + 1
        # print(tt, ABC[tt], j, ABC[tt][j], "head:",
        # head, ",counter:", counter, S)
        head = (ABC[tt][j]+1) % S
    print(counter)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8044
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  long double sum=0;
  for(int i=0;i<N;i++){
  double x;
    string v;
    cin>>x>>v;
    if(v=="JPY"){
    sum+=x;
    }
    else{
    sum+=380000 * x;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3824
key_hash = {"1": [".", ",", "!", "?", " "],
            "2": ["a", "b", "c"],
            "3": ["d", "e", "f"],
            "4": ["g", "h", "i"],
            "5": ["j", "k", "l"],
            "6": ["m", "n", "o"],
            "7": ["p", "q", "r", "s"],
            "8": ["t", "u", "v"],
            "9": ["w", "x", "y", "z"]}

(gets.to_i).times do
  answer = []
  ary = gets.chomp.split("0")
  ary.delete("")
  ary.each do |str|
    push_num = str.size
    key = str[0, 1].to_sym
    key_ary = key_hash[key]
    answer << key_ary[(push_num % key_ary.size) - 1]
  end
  puts answer.join
end

Measured memory_bytes: 8800
#include <iostream>
using namespace std;

int main() {

    int n, k;
    while ( cin >> n && n ) {

	int less1Cnt = 0;
	int zeroCnt = 0;
	for ( int i=0; i<n; ++i ) {
	    cin >> k;
	    if (k <= 1) ++less1Cnt;
	    if (k == 0) ++zeroCnt;
	}

	if (n == less1Cnt) cout << "NA" << endl;
	else cout << n - zeroCnt + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3108
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;

int main() {
	int K; cin >> K;
	string S; cin >> S;
	if (S.size() <= K)cout << S;
	else {
		cout << S.substr(0, K) << "...";
	}
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define MOD 1000000007
#define md 998244353
#define INF LLONG_MAX
#define F first
#define S second
#define sz(x) (long long)x.size()
#define vi vector<int>
#define vll vector<long long>
#define vpl vector<pair<long long,long long> >
#define vpi vector<pair<int,int> >
#define pb push_back
#define debug(x) cerr<<#x<<"= "<<x<<endl
#define all(v) v.begin(),v.end()
#define TT ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define endl '\n'
#define MAXN 200005
typedef long long ll;
typedef long double ld;
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll res=0;
    ll pre[n+5];
    pre[1]=pre[0]=0;
    for(ll i=2;i<=n+1;i++)pre[i]=pre[i-1]+i-1;
    for(ll i=k;i<=n+1;i++){
    	ll x=pre[i];
    	ll y=pre[n+1]-pre[n+1-i];
    	//cerr<<x<<" "<<y<<endl;
        res=(res+y-x+1)%MOD;
    }
    cout<<res;


    return 0;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<bool> D(10);
	for (int i = 0; i < K; ++ i) {
		int d;
		cin >> d;
		D[d] = true;
	}
	for (int i = N; ; ++ i) {
		string s = to_string(i);
		for (char c : s) if (D[c-'0']) goto next;
		cout << s << endl;
		break;
		next:;
	}
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class AACOrWA {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m; cin >> n >> m;
      if (n == m) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
};

signed main() {
  AACOrWA solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        auto a = vector<int>(n);
        for (int i = 0; i < n; ++i) cin >> a[i];

        int ans = 0;    
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (a[i] + a[j] > m) continue;
                ans = max(ans, a[i] + a[j]);
            }
        }
        cout << ( (ans) ? to_string(ans) : "NONE" ) << endl;
    }
}


Measured memory_bytes: 3172
#include <iostream>
using namespace std;
typedef long long ll;

ll calc(ll t){
    ll ans = 0;
    for(ll i = (t/4)*4;i <= t;i++) ans ^= i;
    return ans;
}

int main(void){
    ll a,b,tmp;
    cin >> a >> b;
    tmp = calc(a-1)^calc(b);
    cout << tmp << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	switch (n%10){
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		break;
	case 3:
		cout << "bon" << endl;
		break;
	default:
		cout << "pon" << endl;
		break;
	}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;

int main(){
  string tumiki;
  cin>>tumiki;
  int count1=0;
  int count2=0;
  for(int i=0;i<tumiki.size();++i){
    if(tumiki.at(i)=='0'){
      count1++;
    }
    else{
      count2++;
    }
  }
  int ans=min(count1,count2);
  cout<<ans*2<<endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    string stones;
    cin >> n >> stones;
    int r = 0;
    int w = 0;
    char c;
    for (int i = 0; i < n; i++) {
        c = stones.at(i);
        if (c == 'R') r++;
    }
    for (int i = 0; i < r; i++) {
        c = stones.at(i);
        if (c == 'W') w++;
    }
    cout << w;
}


Measured memory_bytes: 3744
#include <stdio.h>
#define N 25

typedef struct node{
    int id, depth, height, degree, sibling;
    struct node* parent;
    struct node* left;
    struct node* right;
} NODE;

void calcDepth(NODE* node){
    if(node == NULL) return;
    if(node->parent == NULL) node->depth = 0;
    else node->depth = node->parent->depth+1;
    calcDepth(node->left);
    calcDepth(node->right);
}

void calcHeight(NODE* node){
    if(node == NULL) return;
    calcHeight(node->left);
    calcHeight(node->right);

    if((node->left == NULL) && (node->right == NULL)) node->height = 0;
    else if((node->left != NULL) && (node->right == NULL)){
        node->height = node->left->height+1;
    }
    else if((node-> left == NULL) && (node->right != NULL)){
        node->height = node->right->height+1;
    }
    else if((node->left->height) > (node->right->height)){
        node->height = node->left->height+1;
    }
    else node->height = node->right->height+1;
}

int main(){
    int i, j, n;
    int id, leftid, rightid, root;
    NODE node[N];

    scanf("%d",&n);

    for(i = 0; i < n; i++){
        node[i].parent = NULL;
        node[i].degree = 0;
        node[i].left = NULL;
        node[i].right = NULL;
    }

//nodeへの情報入力
    for(i = 0; i < n; i++){
        scanf("%d",&id);
        node[id].id = id;

        scanf("%d",&leftid);
        if(leftid != -1){
            node[id].degree++;
            node[leftid].id = leftid;
            node[id].left = &node[leftid];
            node[leftid].parent = &node[id];
        }

        scanf("%d",&rightid);
        if(rightid != -1){
            node[id].degree++;
            node[rightid].id = rightid;
            node[id].right = &node[rightid];
            node[rightid].parent = &node[id]; 
        }   

//siblingについて
        if((leftid != -1) && (rightid == -1)){
            node[leftid].sibling = -1;
        }
        else if((leftid == -1) && (rightid != -1)){
            node[rightid].sibling = -1;
        }
        else if((leftid != -1) && (rightid != -1)){
            node[leftid].sibling = rightid;
            node[rightid].sibling = leftid;
        }
    }

//depthについて
    i = 0;
    while(1){
        if(node[i].parent == NULL){
            root = i;
            break;
        }
        i++;
    }

    calcDepth(&node[root]);
    calcHeight(&node[root]);

//出力
    for(i = 0; i < n; i++){
        printf("node %d: ",i);

        printf("parent = ");
        if(node[i].parent == NULL) printf("-1, ");
        else printf("%d, ",node[i].parent->id);

        printf("sibling = ");
        if(node[i].parent == NULL) printf("-1, ");
        else printf("%d, ",node[i].sibling);

        printf("degree = %d, ",node[i].degree);

        printf("depth = %d, ",node[i].depth);

        printf("height = %d, ",node[i].height);

        if(node[i].parent == NULL) printf("root");
        else if((node[i].left == NULL) && (node[i].right == NULL)) printf("leaf");
        else printf("internal node");

        printf("\n");
    }


return 0;
}



Measured memory_bytes: 2148
using System;
using System.Text.RegularExpressions;

namespace StableSort
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var initCards = Console.ReadLine().Split(' ');
            var Cards = new string[N];


            Array.Copy(initCards, Cards, N);

            BubbleSort(Cards, N);
            Console.WriteLine(string.Join(" ", Cards));
            Console.WriteLine("Stable");

            Array.Copy(initCards, Cards, N);

            SelectionSort(Cards, N);
            Console.WriteLine(string.Join(" ", Cards));
            if (StableCheck(initCards, Cards))
                Console.WriteLine("Stable");
            else
                Console.WriteLine("Not stable");
        }

        public static void BubbleSort(string[] Cards, int N)
        {
            var temp = "";
            for (var i = 0; i < N; i++)
            {
                for (var j = N - 1; j > i; j--)
                {
                    if (Cards[j][1] < Cards[j - 1][1])
                    {
                        temp = Cards[j];
                        Cards[j] = Cards[j - 1];
                        Cards[j - 1] = temp;
                    }
                }
            }
        }

        public static void SelectionSort(string[] Cards, int N)
        {
            var minj = 0;
            var temp = "";
            for (var i = 0; i < N; i++)
            {
                minj = i;
                for (var j = i; j < N; j++)
                {
                    if (Cards[j][1] < Cards[minj][1])
                    {
                        minj = j;
                    }
                }
                temp = Cards[i];
                Cards[i] = Cards[minj];
                Cards[minj] = temp;
            }
        }

        public static bool StableCheck(string[] inCards, string[] outCards)
        {
            var N = inCards.Length;
            for(var i = 0; i < N; i++)
            {
                for(var j = i + 1; j < N; j++)
                {
                    for(var a = 0; a < N; a++)
                    {
                        for(var b = a + 1; b < N; b++)
                        {
                            if (inCards[i][1] == inCards[j][1] && inCards[i] == outCards[b] && inCards[j] == outCards[a])
                                return false;
                        }
                    }
                }
            }
            return true;
        }
    }
}



Measured memory_bytes: 15988
#include <stdio.h>

int main() {
    int x;
    int y;
    
    scanf("%d %d",&x,&y);
    while (!(x==0 && y==0)){
        if(x>y) printf("%d %d\n",y,x);
        else if(x<=y) printf("%d %d\n",x,y);
        scanf("%d %d",&x,&y);
    }
    return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

class UF
{
private:
	vector<int> root;
	vector<vector<int> > edge;

public:
	UF(int n)
	{
		root = vector<int>(n + 1, -1);
		edge = vector<vector<int> >(n + 1);
	}

	int getroot(int x)
	{
		if(root[x] == -1) return x;
		else return root[x] = getroot(root[x]);
	}

	void add(int x, int y)
	{
		edge[x].push_back(y);
		edge[y].push_back(x);
		x = getroot(x);
		y = getroot(y);
		if(x == y) return;
		if(x > y) swap(x, y);
		root[y] = x;
	}

	bool isbipartite(int x)
	{
		vector<int> checked(root.size(), -1);
		queue<int> qu;
		qu.push(x);
		checked[x] = 0;
		while(!qu.empty()){
			int node = qu.front();
			qu.pop();
			// cout << node << " " << checked[node] << endl;
			for(int i = 0; i < edge[node].size(); i++){
				int next = edge[node][i];
				if(checked[next] == checked[node]) return false;
				if(checked[next] < 0){
					checked[next] = (checked[node] + 1) % 2;
					qu.push(next);
				}
			}
		}
		return true;
	}
};

int main()
{
	long long int n, m;
	cin >> n >> m;
	UF uf(n);
	vector<bool> isnoedge(n + 1, true);
	for(int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		uf.add(u, v);
		isnoedge[u] = false;
		isnoedge[v] = false;
	}
	long long int bipartite = 0, notbipartite = 0;
	long long int noedgenode = 0;
	for(int i = 1; i <= n; i++){
		if(isnoedge[i]){
			noedgenode++;
		} else if(uf.getroot(i) == i){
			if(uf.isbipartite(i)) bipartite++;
			else notbipartite++;
			// cout << i << " " << uf.isbipartite(i) << endl;
		}
	}
	long long int ans = 2 * bipartite * bipartite + 2 * bipartite * notbipartite + notbipartite * notbipartite;
	ans += 2 * n * noedgenode - noedgenode * (noedgenode + 1) + noedgenode;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7552
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	while(n--){
		int b=-1,c=-1,a,flag=true;
		for(int i=0;i<10;i++){
			scanf("%d",&a);
			if(a>b){
				b=a;
			}else if(a>c){
				c=a;
			}else{
				flag=false;
			}
		}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define XOX
using namespace std;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int fun(int x)
{
    int a=sqrt((int)1+((int)8*x));
    a=(a-1)/2;
    return a;
}

int32_t main()
{
    int n;
    cin>>n;
    int res=0;
    int c=n;
    for(int i=2;i*i<=n;i++)
    {
        if(c%i==0)
        {
            int cnt=0;
            while(c%i==0)
            {
                c/=i;
                cnt++;
            }
            res+=fun(cnt);
        }
    }
    if(c!=1)
     res++;
    cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;

    if((N+1)/2>=K){
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int N; cin >> N;

  vector < vector<pair<int, long long> > > graph(N);
  for (int i = 0; i < N - 1; i++){
    int u, v, w; cin >> u >> v >> w;
    u--; v--;
    graph[u].push_back(make_pair(v, w));
    graph[v].push_back(make_pair(u, w));
  }

  vector <int> ans(N);
  for (int i = 0; i < N; i++){
    ans[i] = -1;
  }
  
  queue <int> que;
  ans[0] = 0; que.push(0);
  
  while (!que.empty()){
    int edge = que.front(); que.pop();

    for (int i = 0; i < graph[edge].size(); i++){
      int next = graph[edge][i].first;
      long long dist = graph[edge][i].second;

      if (ans[next] == -1){
        que.push(next);
        if (dist % 2 == 0) ans[next] = ans[edge];
        else ans[next] = 1 - ans[edge];
      }
    }
  }
  
  for (int i = 0; i < N; i++){
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 8320
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
H,W = LI()
a = [S() for _ in range(H)]
a2,a3 = [],[]
for x in a:
    if '#' in x:
        a2.append(x)
for y in zip(*a2):
    if '#' in y:
        a3.append(y)
for z in zip(*a3):
    print(*z,sep='')


Measured memory_bytes: 4468
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    map<char, char> m;
    m['b'] = 'd';
    m['d'] = 'b';
    m['p'] = 'q';
    m['q'] = 'p';
    string s;
    cin >> s;
    string t = s;
    reverse(t.begin(), t.end());
    for(char& c : t) c = m[c];
    cout << (s == t ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>

using namespace std;


#define MAX_NUM 200000

bool IsPrime(int a) {
  if (a == 2 || a == 3 || a == 5) return true;
  else if (a%2 == 0) return false;
  else if (a%3 == 0) return false;
  else if (a%5 == 0) return false;

  for(int i = 3; i < a; i+=2) {
    if(a%i == 0) return false;
  }
  return true;
}

int main(){
  int x;
  cin >> x;
  if(x%2 == 0 && x != 2) {
    x++;
  }

  while(1) {
    if(IsPrime(x) == true) {
      break;
    } else {
      x++;
    }
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
	string str;
	int afit,beit,ans=0;
	char n;
	while(cin>>n){
		str.push_back(n);
	}
	beit=0;
	afit=str.size()-1;
	while(afit-beit>0){
		if(str[beit]=='x'){
			beit++;
			if(str[afit]=='x'){
				afit--;
			}
			else{
				ans++;
			}
		}
		else if(str[afit]=='x'){
			afit--;
			ans++;
		}
		else if(str[beit]==str[afit]){
			beit++;
			afit--;
		}
		else{
			cout << "-1";
			return 0;
		}
	}
	
	cout << ans;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <climits>
#include <algorithm>

using namespace std;

int main(){
    int n,s,r[20001];
    while(cin>>n,n){
        cin>>s;
        for(int i=0; i<n; i++)cin>>r[i];
        sort(r,r+n);
        int ans=0;
        for(int i=0; i<n; i++){
            int* p=upper_bound(r+(i+1),r+n,s-r[i]);
            ans+=n-(p-r);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1228
// date: 26/09/20 17:24:27 // 
#include <bits/stdc++.h>
using namespace std;

#define iterall(x) x.begin(), x.end()
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <double> vd;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef vector <vector <long long>> vvll;
typedef vector <vd> vvd;
typedef pair <int, int> pii;
typedef pair<ll , ll> pll;
typedef vector <pair <int, int>> vpii;
typedef vector <pll> vpll;

const ll INF = 1e9+5;
const double EPS = 1e-9;


int main()
{
    int k;
    cin >> k;
    for(int i = 0; i < k; i++)
        cout << "ACL";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

const int MAX_N=100010;

//Ｏ(n*log(logn))≒Ｏ(n)
int prime[MAX_N];         //i番目の素数
bool is_prime[MAX_N+1];    //is_prime[i]がtrueならiは素数

//n以下の素数の個数を返す。
int sieve(int n){
  int p=0;
  for(int t=0;t<=n;t++)is_prime[t]=true;
  is_prime[0]=is_prime[1]=false;
  for(int t=2;t<=n;t++){
    if(is_prime[t]==true){
      prime[p++]=t;
      for(int i=2*t;i<=n;i+=t)is_prime[i]=false;
    }
  }
  return p;
}

signed main(){
  int Q;cin>>Q;

  sieve(100000);
  int cont[100010]={0};
  for(int t=1;t<=100005;t++){
    cont[t]=cont[t-1];
    if(is_prime[t]&&is_prime[(t+1)/2]){
      cont[t]++;
    }
  }

  queue<int>q;
  for(int t=1;t<=Q;t++){
    int l,r;cin>>l>>r;
    int ans=cont[r]-cont[l-1];
    q.push(ans);
  }
  while(!q.empty()){
    cout<<q.front()<<"\n";
    q.pop();
  }
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;

string s;
int cnt[2][2] = {0};

int solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

int solve() {
  int n = s.size();
  for(int i = 0; i < n; ++i) ++cnt[i % 2][s[i] - '0'];
  return min(cnt[0][0] + cnt[1][1], cnt[1][0] + cnt[0][1]);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>

#define int long long

#define Vanya Unstoppable

#define double long double

using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n; cin >> n;
    cout << n / 500 * 1000 + (n % 500) / 5 * 5;
}


Measured memory_bytes: 256
#line 1 "template.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

void dfs(int n, vector<string> &ans, char ma, string current) {
  if ((int)current.length() == n) {
    ans.push_back(current);
    return;
  }
  int m = ma - 'a' + 1;

  REP(i, m + 1) {
    char ima = 'a' + i;
    string po = current + ima;
    char tmp = ma < ima ? ima : ma;
    dfs(n, ans, tmp, po);
  }
}

int main() {
  int n;
  cin >> n;
  vector<string> ans;
  dfs(n, ans, 'a', "a");
  int len = ans.size();
  REP(i, len) { cout << ans[i] << endl; }
}


Measured memory_bytes: 7924
//ALDS1_4C
#include <stdio.h>
#include <string.h>

#define M 1046527
//#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
 if(ch=='A') return 1;
 else if(ch=='C') return 2;
 else if(ch=='G') return 3;
 else if(ch=='T') return 4;
 else return 0;
}

long long getKey(char str[]){
 long long sum=0,p=1,i;
 for(i=0;i<strlen(str);i++){
  sum+=p*(getChar(str[i]));
  p*=5;
 }
 return sum;
}

int h1(int key) {return key%M;}
int h2(int key) {return 1+(key%(M-1));}

int find(char str[]){
 long long key,i,h;
 key=getKey(str);
 for(i=0;;i++){
  h=(h1(key)+i*h2(key))%M;
  if(strcmp(H[h],str)==0) return 1;
  else if(strlen(H[h])==0) return 0;
  } 
 return 0;
}

int insert(char str[]){
 long long key,i,h;
 key=getKey(str);
 for(i=0;;i++){
  h=(h1(key)+i*h2(key))%M;
  if(strcmp(H[h],str)==0) return 1;
  else if(strlen(H[h])==0){
   strcpy(H[h],str);
   return 0;
  }
 }
 return 0;
}

int main(){
 int i,n,h;
 char str[L],com[9];
 for(i=0;i<M;i++) H[i][0]='\0';
 scanf("%d",&n);
 for(i=0;i<n;i++){
  scanf("%s %s",com,str);
  if(com[0]=='i'){
   insert(str);
  }else{
    if(find(str)){
     printf("yes\n");
    }else{
     printf("no\n");
   }
  }
 }
 return 0;
}

Measured memory_bytes: 15344
#include<cstdio>
#include<queue>
#include<algorithm>
typedef long long ll;
const int inf=1e9;
int N,K[33],M,U[55],V[55],W[55];
struct Jewel{int S,P;ll C;bool operator<(const Jewel&j)const{return S<j.S;}}J[33][33];
int no(int i,int j){return j?j<K[i]?2+i+(j-1)*N:1:0;}
struct Edge{int to,cap;ll cost;Edge*rev,*next;}E[33333],*ne=E,*fir[999];
void link(int a,int b,int c,int cr,ll cost){
	*ne=(Edge){b,c,cost,ne+1,fir[a]};fir[a]=ne++;
	*ne=(Edge){a,cr,-cost,ne-1,fir[b]};fir[b]=ne++;
}
ll D[999],h[999];
bool vis[999];
Edge*fr[999];
struct Item{int v;ll d;Edge*e;bool operator<(const Item&it)const{return d>it.d;}};
void sp(){
	std::priority_queue<Item>Q;
	Q.push((Item){0,0,0});
	for(int i=0;i<N;i++)
		for(int j=0;j<=K[i];j++)h[no(i,j)]=D[no(i,j)],vis[no(i,j)]=0;
	while(!Q.empty()){
		Item it=Q.top();Q.pop();
		if(vis[it.v])continue;
		vis[it.v]=1;D[it.v]=it.d+h[it.v];fr[it.v]=it.e;
		for(Edge*e=fir[it.v];e;e=e->next)if(e->cap&&!vis[e->to])Q.push((Item){e->to,D[it.v]+e->cost-h[e->to],e});
	}
}
int cnt,X[111111];
ll Y[111111],kr[111111];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",K+i);
		for(int j=0;j<K[i];j++)
			scanf("%d%d%lld",&J[i][j].S,&J[i][j].P,&J[i][j].C);
		std::sort(J[i],J[i]+K[i]);
		for(int j=0;j<K[i];j++){
			link(no(i,j),no(i,j+1),J[i][j].P,inf,0);
			link(no(i,j),no(i,j+1),inf,0,J[i][j].C);
		}
	}
	scanf("%d",&M);
	for(int i=0;i<M;i++){
		scanf("%d%d%d",U+i,V+i,W+i);
		--U[i];--V[i];
		for(int j=0,k=0;j<K[V[i]];j++){
			while(k<K[U[i]]&&J[V[i]][j].S>J[U[i]][k].S+W[i])k++;
			if(k)link(no(V[i],j),no(U[i],k),inf,0,0);
		}
	}
	int c=0;ll f=0;
	for(;;){
		sp();
		int mc=inf;
		for(int v=1;v;v=fr[v]->rev->to)
			if(fr[v]->cap<mc)mc=fr[v]->cap;
		kr[cnt]=D[1];X[cnt]=c;Y[cnt++]=f;
		if(mc>inf/2)break;
		c+=mc;f+=1ll*mc*D[1];
		for(int v=1;v;v=fr[v]->rev->to)
			fr[v]->cap-=mc,fr[v]->rev->cap+=mc;
	}
	int Q;scanf("%d",&Q);
	while(Q--){
		ll A;scanf("%lld",&A);
		int i=std::lower_bound(kr,kr+cnt,A)-kr;
		printf("%lld\n",i<cnt?X[i]*A-Y[i]:-1ll);
	}
}

Measured memory_bytes: 3524
import itertools
N,M=map(int,input().split())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
z=[0 for i in range(N)]
for i in range(N):
    x[i],y[i],z[i]=map(int,input().split())
w=[[0 for i in range(N)] for i in range(8)]
S=list(itertools.product([-1,1],repeat=3))
def num(inp):
    res=0
    for i in range(3):
        res+=2**i*(inp[i]+1)//2
    return res
for sg in S:
    for i in range(N):
        w[num(sg)][i]=x[i]*sg[0]+y[i]*sg[1]+z[i]*sg[2]
tmp=[0 for i in range(8)]
for sg in S:
    w[num(sg)].sort(reverse=True)
    for i in range(M):
        tmp[num(sg)]+=w[num(sg)][i]
print(max(tmp))

Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

//降順
int des(const void *a, const void *b)
{
  return *(int *)b - *(int *)a;
}

int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i=0; i<n; i++)
    scanf("%d", a+i);
  qsort(a, n, sizeof(int), des);
  int ans = 0;
  for (int i=0; i<n; i++) {
    if (i%2 == 0) ans += a[i];
    else ans -= a[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

bool check(ll x){

	for(int i=3;i<x;i+=2){
		if(x%i == 0) return false;
	}
	return true;
}


int main(void){


	ll X; cin >> X;

	bool flag = true;
	if(X > 2){
		while(flag){
			if(X % 2 != 0 and check(X)) break; 
			X++;
		}
	}

	cout << X << endl;


	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main(){
string s;
cin>>s;
string s1=string(s.rbegin(),s.rend());
int ans=0;
for(int i=1;i<s1.length();i++){
    if(s[i]!=s[i-1]){ans++;}
}
cout<<ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    string s,t; cin>>s>>t;
    for (int i = 0; i < 26; ++i)
    {
        char c=i+'a';
        if(s+c==t){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    int n; cin>>n;
    int ar[n][3];

    for(int i=0;i<n-1;i++) cin>>ar[i][0]>>ar[i][1]>>ar[i][2];
    
    long long int ans = 0;
    

    for(int i=0;i<n-1;i++){
    	ans = ar[i][0]+ar[i][1];
    	
        for(int j=i+1;j<n-1;j++){
    		
    		int temp = ar[j][1];
    		while(temp < ans){
    		  temp += ar[j][2];
    		}
            ans = temp;
    		ans += ar[j][0];
    	}
    	cout<<ans<<endl;
    }
    cout<<0;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
	int a;
	int  b;
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World";
	}
	if (n == 2) {
		cin >> a;
		cin >> b;
		cout << a + b;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll long long int
#define MOD 1000000007
#define sc(a) scanf("%lld",&a)
#define f0(n) for(ll i=0;i<n;i++)
#define f1(n) for(ll i=1;i<=n;i++)
#define pb(v,a) v.push_back(a)
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end());

ll floorRoot5(ll n) 
{ 
    ll ans;
    double nn=(double)n;
    double a=pow(n,(1.0/5.0));
    ans=(ll)a;
    return ans; 
} 

int main()
{
	ll x;
	cin>>x;
	ll y=floorRoot5(x);
	y=(y+1)*2;
	//cout<<y<<endl;
	for(ll i=-y;i<=y;i++)
	{
		for(ll j=-y;j<=y;j++)
		{
			ll a=1;
			ll b=1;
			//cout<<i<<" "<<j<<" ";
			for(ll it=1;it<=5;it++)
			{
				a=a*i;
				b=b*j;
			}
			//cout<<a<<" "<<b<<endl;1
			if(a-b==x)
			{
				cout<<i<<" "<<j<<endl;
				return 0;
			}
			else if(b-a==x)
			{
				cout<<j<<" "<<i<<endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 4064