akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += sc.nextInt();
        }
        int[] c = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            c[i] = sc.nextInt();
        }
        sc.close();

        for (int i = 0; i < n - 1; i++) {
            if (a[i + 1] - a[i] == 1) {
                ans += c[a[i] - 1];
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 100001

int partition(int A[],int p,int r){
  int x,i,j,temp;
  x = A[r];
  i=p-1;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}


int main(){
  int i,j,key,n;
  int A[MAX];

  scanf("%d",&n);
  for(i=0; i<n; i++)scanf("%d",&A[i]);
  key = partition(A,0,n-1);
  
  for(i=0; i<key; i++){
    if(i >=1)printf(" ");
    printf("%d",A[i]);
  }
  printf(" ");
  printf("[%d]",A[key]);
  
  for(j=key+1; j<n; j++){
    if(j>key)printf(" ");
    printf("%d",A[j]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2172
#include<iostream>
using namespace std;
typedef long long ll;
bool exist[100005];
int num[100005]={0};
int main(){
  int pos=1;
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    exist[i]=false;
    num[i]  =1;
  }
  exist[1]=true;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    if(num[x]==1){
      if(exist[x]){
        exist[y]=true;
        exist[x]=false;
      }
      num[y]++;
      num[x]--;
    }
    else{
      if(exist[x]) exist[y]=true;
      num[x]--;
      num[y]++;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++) if(exist[i]) ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    long long int N,t,a,b,x=0,y=0,T=0,S,flag=1;
    cin >> N;
    while(N--){
        cin >>t >> a >> b;
        S = abs(x-a)+abs(y-b);
        if(S==0)    S+=2;
        if((t-T)<S||(((t-T)%2)!=(S%2)&&(t-T)%S!=0)){
            flag = 0;
        }
        x = a;
        y = b;
        T = t;
    }
    if(flag) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
am = int(input())
arr = list(map(int,input().split()))
if am == 1:
    print(0)
else:
    dp = [0,abs(arr[1]-arr[0])]
for i in range(2,am):
    dp.append(min(dp[i-2] + abs(arr[i]-arr[i-2]), dp[i-1] + abs(arr[i]-arr[i-1])))
print(dp[-1])

Measured memory_bytes: 83232
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define ld long double
#define N 10005
vector<int> a[N];
bool used[N], ap[N];
int par[N], low[N], disc[N];
int vtime; // par[root]==-1
void find_ap(int u)
{
    int child=0;
    used[u]=true;
    low[u]=disc[u]=vtime++;
    for(auto v:a[u])
    {
        if(!used[v])
        {
            child++;
            par[v]=u;
            find_ap(v);
            low[u]=min(low[u],low[v]);
            if(par[u]==-1 && child>1)
            {
                ap[u]=true;
            }
            if(par[u]!=-1 && low[v]>=disc[u])
            {
                ap[u]=true;
            }
            continue;
        }
        if(v!=par[u])
        {
            low[u]=min(low[u],disc[v]);
        }
    }
}
void init()
{
    for(auto &it:a)
    {
        it.clear();
    }
    memset(used,0,sizeof used);
    memset(low,0,sizeof low);
    memset(disc,0,sizeof disc);
    memset(par,0,sizeof par);
    vtime=1;
    par[0]=-1;
}
void solve()
{
    init();
    int n,m;
    scanf("%d%d",&n,&m);
    int i;
    int x,y;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        a[x].pb(y);
        a[y].pb(x);
    }
    find_ap(0);
    int ans=0;
    for(i=0;i<n;i++)
    {
        if(ap[i])
        {
            printf("%d\n",i);
        }
    }
}
int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 4908
s=input()
n=len(s)
for i in range(n-1):
  if s[i]==s[i+1]:
    print(i+1,i+2)
    exit()
for i in range(n-2):
  if s[i]==s[i+2]:
    print(i+1,i+3)
    exit()
print(-1,-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define int long long

signed main() {
  int h,w;
  cin >> h >> w;

  vector<vector<char>> board(h, vector<char> (w));

  vector<int> row(h, 0);
  vector<int> col(w, 0);
  rep(i,h) rep(j,w) {
    cin >> board[i][j];
    if(board[i][j] == '#') {
      row[i] = 1;
      col[j] = 1;
    }
  }

  for (int i = 0; i < h; i++) {
    if(!row[i]) continue;
    for (int j = 0; j < w; j++) {
      if(!col[j]) continue;
      cout << board[i][j];
    }
    cout << '\n';
  }


}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
int main(int argc, char *argv[])
{
    int n, m;
    ll a_sum = 0;

    std::cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a;
        std::cin >> a;
        a_sum += a;
    }

    if (a_sum > n) {
        std::cout << "-1" << std::endl;
    } else {
        std::cout << n - a_sum << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;


int main()
{
	string str;
	getline(cin, str);
	if (str.size() == 2) {
		cout << str << endl;
	}
	else {
		for (int i = 2; i >= 0; i--) {
			cout << str[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <deque>
using namespace std;
typedef long long int ll;

struct Dice{
    int a,b,c,d,e,f;
};

void rotate(Dice &D,char c){
    int tmp;
    if(c=='N'){
        tmp=D.a;D.a=D.b;D.b=D.f;D.f=D.e;D.e=tmp;
    }
    if(c=='S'){
        tmp=D.a;D.a=D.e;D.e=D.f;D.f=D.b;D.b=tmp;
    }
    if(c=='W'){
        tmp=D.a;D.a=D.c;D.c=D.f;D.f=D.d;D.d=tmp;
    }
    if(c=='E'){
        tmp=D.a;D.a=D.d;D.d=D.f;D.f=D.c;D.c=tmp;
    }
}

void spin(Dice &D){
    int tmp;
    tmp=D.b;D.b=D.c;D.c=D.e;D.e=D.d;D.d=tmp;
}

bool same(Dice &D,Dice &E){
    if(D.a==E.a&&D.b==E.b&&D.c==E.c&&D.d==E.d&&D.e==E.e&&D.f==E.f)return true;
    else return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Dice d[n];
    for(int i=0;i<n;i++){
        cin >> d[i].a >> d[i].b >> d[i].c >> d[i].d >> d[i].e >> d[i].f;
    }
    bool ok=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            Dice D=d[i],E=d[j];
            for(int i=0;i<4;i++){
                for(int j=0;j<4;j++){
                    if(same(D,E))ok=1;
                    spin(E);
                }
                rotate(E,'N');
            }
            rotate(E,'E');
            for(int i=0;i<4;i++){
                for(int j=0;j<4;j++){
                    if(same(D,E))ok=1;
                    spin(E);
                }
                rotate(E,'N');
            }
        }
    }
    if(ok){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3208
#include <iostream>
#include <cmath>
using namespace std; 
inline void prime_fac(int n){
	int m=(int)floor(sqrt(n)+0.5);
	for (int i=2;i<=m;++i){
		if (n%i==0){
			while (n%i==0) cout <<" "<< i,n/=i ;
		}
	}
	if (n!=1) cout << " " << n ;
}
int main(){
	int x;
	cin >> x;
	cout << x << ":";
	prime_fac(x);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3100
T = input()

s = list(T)
for i, x in enumerate(T):
  if x == "?":
    s[i] = "D"


count = 0
flag = False
for x in s:
  if x == "P":
    flag = True
  
  if x == "D":
    count += 1
    if flag:
      count += 1
      flag = False

print("".join(s))

Measured memory_bytes: 10792
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int h, w;
  cin >> h >> w;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      string s;
      cin >> s;
      if (s == "snuke") printf("%c%d\n", 'A' + x, y + 1);
    }
  return 0;
}


Measured memory_bytes: 256
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int a = b; a < c; a++)
#define setp cout << fixed << setprecision(7)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;

const ll inf = ~0ull/4;
const int maxn = 210000;

/////////////////////////////////////////////////////////////////////

int a[maxn];

int32_t main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int k; cin >> k;
	int n = 50;
	int m = k%n;

	int t = 0;
	for2(i,0,m) a[i] = n;
	for2(i,0,m) a[i] += (n-1-(m-1));
	for2(i,m,n) a[i] += (n-1-m);

	cout << n << endl;
	for2(i,0,n){
		int x = a[i]+k/n;
//		x += k/n;
//		if(m > 0) x ++;
		m --;

		cout << x << ' ';
	}

	/*int m = k%(n*n);
	int d = (k-m)/n;
	int md = m%n;
	cout << n << endl;
	for2(i,0,n){
		int x = n-1 + d + m/n ;
		x += md;
		md = 0;
		cout << x << ' ';
	}
	cout << endl;*/
	return 0;
}

Measured memory_bytes: 256
#n = int(input())
a, b = map(int, input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0:
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 9036
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void insertionSort(int array[], int N, int g, int *cnt){
    int i,j,v;
    for(i = g; i < N; i++){
        v = array[i];
        j = i - g;
        while( j >= 0 && array[j] > v){
            array[j+g] = array[j];
            j = j - g;
            (*cnt)++;
        }
        array[j+g] = v;
    }
    return;
}



int main(int argc, const char * argv[]){
    
    //Input
    int i, N, value, ans;
    int cnt = 0;
    scanf("%d", &N);
    
    int *array = NULL;
    array = (int*)malloc(sizeof(int) * N);
    
    REP(i, N){
        scanf("%d", &value);
        array[i] = value;
    }
    
    int m;
    int G[100];
    for( i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] = N / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }
    
    
    ans = 0;
    for(int i = 0; i < m; i++){
        insertionSort(array, N, G[i], &cnt);
    }
    
    //print m
    printf("%d\n", m);
    
    //print G[]
    for(i = 0; i < m; i++){
        printf("%d", G[i]);
        if(i != m-1){
            printf(" ");
        }
    }
    printf("\n");
    
    //print cnt
    printf("%d\n", cnt);
    
    
    
    REP(i, N){
        printf("%d\n", array[i]);
    }
    return 0;
}

Measured memory_bytes: 4940
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m, d;
    cin >> n >> m >> d;
    double sum = 0.0;
    if(d == 0){
        sum = (double)(m - 1) * (1.0 / (double)n);
    }
    else {
        int low = d + 1;
        int hi = n - d;
        int k;
        if(hi >= low){
            k = hi - low + 1;
            sum += k * 2.0 / (double)n;
            sum += (n - k) * 1.0 / (double)n;
        }
        else {
            sum += (double)(2 * hi) * 1.0 / (double)n;
        }
        sum /= (double)n;
        sum *= (double)(m - 1);
    }
    printf("%.15f\n", sum);
    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static Scanner scanner = new Scanner(System.in);
	static int n = scanner.nextInt();
	static int a[][] = new int[2][n];

	@SuppressWarnings("resource")
	public static void main(String args[]) {

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = scanner.nextInt();
			}
		}

		dfs(0, 0, a[0][0]);

		int max = 0;
		for (int i = 0; i < scores.size(); i++) {
			max = Math.max(scores.get(i), max);
		}

		System.out.println(max);
	}

	static List<Integer> scores = new ArrayList<>();

	private static void dfs(int x, int y, int score) {
		if (x == n - 1 && y == 1) {
			scores.add(score);
			return;
		}

		try {
			score += a[y + 1][x];
			dfs(x, y + 1, score);
			score -= a[y + 1][x];
		} catch (Exception e) {

		}
		try {
			score += a[y][x + 1];
			dfs(x + 1, y, score);
		} catch (Exception e) {

		}

	}
}

Measured memory_bytes: 31060
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

N, M=map(int, input().split())


# 各スイッチがどの電球につながっているかの情報をビットで保持する配列
# 1番目のスイッチが2番目と3番目の電球につながっていた場合以下のようにいなる
# (1 << 1) | (1 << 2) = (110)b   ※ zero index
mask_list = [0 for _ in range(N)]

for i in range(M):
    switches = list(map(int, input().split()))

    # switchesの2番目以降の要素には、スイッチの番号が入っている
    for j in range(1, len(switches)):
        sw_num = (switches[j] - 1) # スイッチの番号をzero index で管理する
        sw_bit = 1 << i # つながっている電球を二進数で表す
        mask_list[sw_num] = mask_list[sw_num] | sw_bit

conds = list(map(int, input().split()))

conds_dec = 0

for i in range(len(conds)):
    conds_dec |= conds[i] << i

light_num = 0
for s in range(1 << N):
    t = 0
    for i in range(N):
        if s >> i & 1:
            t = t ^ mask_list[i]
    if t == conds_dec:
        light_num += 1


print(light_num)


Measured memory_bytes: 21208
hill = []
while True:
    try:
        hill.append(int(input()))
    except:
        break
for i in range(1, len(hill)):
    key = hill[i]
    j = i-1
    while j >= 0 and hill[j] < key:
        hill[j+1] = hill[j]
        j -= 1
    hill[j+1] = key

for i in range(3):
    print(hill[i])

Measured memory_bytes: 7648
#include <stdio.h>

int main(void){

	int n,i,x,y,z;

	scanf("%d",&n);

	i=1;
	x=1;

	do{
		

		y=x%3;

		switch(y){

			case 0:
				printf(" %d",i);
				break;

			default:

				z=x%10;
				if(z==3){
					printf(" %d",i);
					break;
				}

				while(x>10){
					x/=10;
					z=x%10;
					if(z==3){
						printf(" %d",i);
						break;
					}

				}


		}

		i++;
		x=i;

	}while(i<=n);

	printf("\n");

	return 0;
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,m,n;
    cin >> n >> m;
    for(i=1;i<=max(m,n);i++)cout << min(m,n);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    ################
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意)，根の場合は"-(要素数）"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        重いかも！　　members(x):要素xが属するグループに属する要素をリストで返す
        roots():全ての根の要素を返す
        group_count():グループの数を返す
        重いかも！　all_group_members():{根要素：[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            #根を探す&つなぎかえる
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    ################
    
    N,Q=MI()
    uf=UnionFind(N)
    for _ in range(Q):
        t,u,v=MI()
        if t==0:
            uf.union(u,v)
        else:
            ans=0
            if uf.same(u,v):
                ans=1
            print(ans)



main()


Measured memory_bytes: 80788
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
LL f1[100002], f2[100002], dp[100002];
LL pow2(LL a, LL b){
    LL ans = 1;
    while(b){
        if(b%2 == 1) ans = ans*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return ans;
}
LL nCr(LL a, LL b){
    return f1[a]*f2[b]%mod*f2[a-b]%mod;
}
int main(){
    f1[0] = f2[0] = 1;
    for(int i=1;i<=100000;i++) f1[i] = f1[i-1]*i%mod, f2[i] = pow2(f1[i], mod-2);
    int n, k;
    scanf("%d%d", &n, &k);

    LL ans = 0;
    for(int i=k;i>=1;i--){
        LL res = 0;
        int cnt = 0;
        for(int j=i;j<=k;j+=i){
            res = (res - dp[j] + mod)%mod;
            cnt++;
        }
        res = (res + pow2(cnt, n))%mod;
        dp[i] = res;
        ans = (ans + i*dp[i])%mod;
    }
    printf("%lld\n", ans);
}

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

using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;

#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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; }

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            res.push_back(i);
            if (N / i != i) res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; a++) {
        if (N % a != 0) continue;
        long long ex = 0;

        while (N % a == 0) {
            ex++;
            N /= a;
        }

        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;
}

ll N;

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

    cin >> N;
    vector<pair<ll, ll>> pf = prime_factorize(N);

    ll ans = 0;

    for (auto p : pf) {
        ll e = p.second;
        ll tmp = 0, cur = 1;
        while (e >= cur) {
            e -= cur;
            cur++;
            tmp++;
        }
        ans += tmp;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n,m;
   cin>>n>>m;
   vector<bool> a(n,false);
   vector<bool> b(n,false);
   rep(i,m){
      int x,y;
      cin>>x>>y;
      if(x==1) a[y]=true;
      if(y==n) b[x]=true;
   }
   bool f=false;
   rep(i,n){
      if(a[i]==true && b[i]==true){
         f=true;
         break;
      }
   }
   f? cout<<"POSSIBLE":cout<<"IMPOSSIBLE";

   return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int dp[400];
int table[400];
int main(){
	int n;
	cin >> n;
	for(int i = 0 ; i < 400 ; i++) table[i] = dp[i] = -1e9;
	for(int i = 0 ; i < n ; i++){
		int l,r,p;
		cin >> l >> r >> p;
		for(int j = l ; j <= r ; j++)
			table[j] = max(table[j],p);
	}
	dp[0] = 0;
	for(int i = 0 ; i < 400 ; i++){
		for(int j = i ; j < 400 ; j++){
			dp[j] = max(dp[j],dp[j-i]+table[i]); 
		}
	}
	vector<int> res;
	int m;
	cin >> m;
	for(int i = 0 ; i < m ; i++){
		int w;
		cin >> w;
		if( dp[w] < 0 ) {
			cout << -1 << endl;
			return 0;
		}
		res.push_back(dp[w]);
	}
	for(int i = 0 ; i < m ; i++)
		cout << res[i] << endl;
	
}

Measured memory_bytes: 1228
#include<stdio.h>
#include<math.h>
#include<string.h>
int main() {
	int sum=0;
	int n,x=0,y;
	char a[101];
	scanf("%d",&n);
	getchar();
	scanf("%s",a);
	for(int i=0;i<n;i++){
		if(a[i]=='I'){
			x++;
		}
		if(a[i]=='D'){
			x--;
		}
		if(sum<x){
			sum=x;
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define nl "\n"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;
#define mt make_tuple
#define vec vector

#define int long long

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


void solve() {

	int n; cin >> n ;
	int a[n], b[n]; rep(i,0,n) cin >> a[i] >> b[i] ;

	rep(i,0,n-2) {
		if(a[i] == b[i] and a[i+1] == b[i+1] and a[i+2] == b[i+2]) {
			cout << "Yes"; return ; 
		}
	}

	cout << "No"; 
}

int32_t main() {

#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif

    fast;

	// int t; cin >> t; while(t--)
		solve() ;

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main() {
  int N, X, T;
  scanf("%d%d%d", &N, &X, &T);
  
  if (N % X == 0) {
    printf("%d", (N / X) * T);
  } else {
    printf("%d", ((int)(N / X) + 1) * T);
  }
  
  return 0;
}

Measured memory_bytes: 1676
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>


using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int>a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	long long min = 10000000000;
	for (int i = 0; i < 100; i++) {
		long long tmp = 0;
		for (int j = 0; j < N; j++) {
			tmp += (i - a[j])*(i - a[j]);
		}
		if (tmp < min)min = tmp;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy
n=int(input())
s=[list(map(int,input().split()))for _ in range(n)]

l = []

for i in range(n):
    ans = 0
    for j,k in s:
        a = s[i][0] - j
        b = s[i][1] - k
        ans += numpy.sqrt(a**2 + b**2)
    l.append(ans)

print(sum(l)/n)

Measured memory_bytes: 27176
N,K = map(int, input().split())

A = list(map(int, input().split()))

C = [1]
D = {1}
i = 0
C1 = []
C2 = []
while True:
    if A[i] not in D:
        C.append(A[i])
        D.add(A[i])
        i = A[i]-1
    else:
        index = C.index(A[i])
        C1 = C[:index]
        C2 = C[index:]
        break

        
if K <= len(C1)-1:
    print(C1[K])
else:
    r = (K-len(C1))%len(C2)
    print(C2[r])



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

#define ll long long
void chmin(ll& a, ll b) {
  if (a > b) a = b;
}

int main() {
  int N;
  cin >> N;
  ll sum = 0;
  
  vector<ll> subsum(N+1, 0);
  
  for (int i = 0; i < N; i++) {
    ll x;
    cin >> x;
    subsum[i+1] = subsum[i] + x;
  }
  
  ll ans = 1000000000000000;
  for (int i = 1; i < N; i++) {
    chmin(ans, abs(subsum[i] * 2 -subsum[N]));
  }
  
  cout << ans << endl;
         
  
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
const int N=1e6+3;
ll a[N];
ll cal(ll x)
{
    return ((-1.0+sqrt(1.0+8.0*x))/2.0);
}
int main()
{
    ft
    ll i,n,m=2,l=0;
    cin>>n;
    for(i=2; i<=(n/i); i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
            {
                a[i]++;
                n/=i;
            }
            m=max(m,i);
        }
    }
    if(n>1)
    {
        l++;
    }
    for(i=2; i<=m; i++)
    {
        if(a[i]>0)
        {
            l+=cal(a[i]);
        }
    }
    cout<<l<<"\n";
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

int n, m;
vii g;
vi answ(1e5 + 1, 0);
vi dp(1e5 + 1, 1);
vii pref(1e5), suff(1e5);

void dfs(int v, int p = -1) {
    for (int i = 0; i < g[v].size(); ++i) {
        int w = g[v][i];

        if (w == p) {
            g[v].erase(g[v].begin() + i);
            --i;
            continue;
        }

        dfs(w, v);

        dp[v] *= dp[w] + 1;
        dp[v] %= m;
    }

    if (g[v].empty()) return;

    pref[v].resize(g[v].size());
    suff[v].resize(g[v].size());

    pref[v][0] = dp[g[v][0]] + 1;
    suff[v][g[v].size() - 1] = dp[g[v][g[v].size() - 1]] + 1;

    for (int i = 1; i < g[v].size(); ++i) {
        int j = g[v].size() - i - 1;

        pref[v][i] = (pref[v][i - 1] * (dp[g[v][i]] + 1)) % m;
        suff[v][j] = (suff[v][j + 1] * (dp[g[v][j]] + 1)) % m;
    }
}

void dfs2(int v, int d) {
    if (g[v].empty()) return;

    for (int i = 0; i < g[v].size(); ++i) {
        int w = g[v][i];

        int u = 1;
        if (i > 0) {
            u *= pref[v][i - 1];
            u %= m;
        }
        if (i < g[v].size() - 1) {
            u *= suff[v][i + 1];
            u %= m;
        }

        int l = (d * u) % m;

        answ[w] = (dp[w] * (l + 1)) % m;

        dfs2(w, l + 1);
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    g.resize(n + 1);

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        g[a].pb(b);
        g[b].pb(a);
    }

    dfs(0);
    answ[0] = dp[0];
    dfs2(0, 1);

    for (int j = 0; j < n; ++j) {
        cout << answ[j] << "\n";
    }
}

Measured memory_bytes: 26124
N = int(input())
A = list(map(float, input().split()))
def solve():
    dp = [[[0]*(N+1-i-j) for j in range(N+1-i)] for i in range(N+1)]
    dp[N][0][0] = 0
    for i in range(N-1,-1,-1):
        for j in range(N-i,-1,-1):
            for k in range(N-i-j,-1,-1):
                dp[i][j][k] = 1/(1-i/N)
                if j != 0:
                    dp[i][j][k] += dp[i+1][j-1][k]*(j/(N-i))
                if k != 0:
                    dp[i][j][k] += dp[i][j+1][k-1]*(k/(N-i))
                if i+j+k != N:
                    dp[i][j][k] += dp[i][j][k+1]*(1-(j+k)/(N-i))
    c = {}
    for i in range(1,3):
        c[i] = A.count(i)
    ans = dp[0][c[1]][c[2]]
    # print(*dp,sep='\n')
    return ans
print(solve())

Measured memory_bytes: 155784
n,k =map(int,input().split())


b=[int(i) for i in range(1,n+1)]


for i in range(k):
    d = int(input())
    a =[int(x) for x in input().split()]
           
    for j in (a):
        if j in b:
            b.remove(j)

print(len(b))

Measured memory_bytes: 9208
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	
	int d = a/b, r = a%b;
	
	double f = (double)r / b + d;
	
	cout << fixed << setprecision(8) << d << " " << r << " " << f << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1244
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, a, b] <- map read.words <$> getLine :: IO [Int]
    putStrLn . unwords . map show $ solve n a b

solve n a b = [min a b, max 0 $ a + b - n]    


Measured memory_bytes: 508
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int N;
int a[]={111,222,333,444,555,666,777,888,999};
int main()
{
    while(cin>>N)
    {
        int flag=0;
        for(int i=N;i<1000;i++)
        {
            for(int j=0;j<9;j++)
            {
                if(a[j]>=i)
                {
                    cout<<a[j]<<endl;
                    flag=1;
                    break;
                }
            }
            if(flag) break;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int first = Integer.parseInt(sc.next());
        int second = Integer.parseInt(sc.next());
        String postCd = sc.next();
        for(int x=1; x<=first;x++) {
            try {
                Integer.parseInt(postCd.substring(x-1,x));
            } catch(Exception e){
                System.out.println("No");
                return;
            }
        }
        if(!postCd.substring(first,first+1).equals("-")) {
            System.out.println("No");
            return;
        }
        for(int x=first+2; x<=first+second+1;x++) {
            try {
                Integer.parseInt(postCd.substring(x-1,x));
            } catch(Exception e){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 21716
#include <stdio.h>

int fibonacci(int);

int fibonacci(int n){
  int num1=1, num2=1, tmp=1;
  int i;

  for(i=1; i<n; i++){
    tmp = num1+ num2;
    num1 = num2;
    num2 = tmp;
  }
  return tmp;
}

int main() {
    int n;
    scanf( "%d", &n );
    printf( "%d\n", fibonacci(n) );

    return 0;
}



Measured memory_bytes: 2104
hai = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(hai[k - 1])

Measured memory_bytes: 3060
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

int a[N];
int main(){
    //freopen("A.in","r",stdin);
    //freopen("B.out","w",stdout);
    //cout<<setprecision(9)<<fixed;
    int T,i,j,k,ca=0,m,K,n;
    scanf("%d",&n);
    rep(i,0,n)scanf("%d",&a[i]);
    int sn=0,ans=1;
    rep(i,1,n){
        if(a[i]==a[i-1])continue;
        if(sn==1){
            if(a[i]<a[i-1]){
                ans++;sn=0;
            }
        }
        else if(sn==-1){
            if(a[i]>a[i-1]){
                ans++;sn=0;
            }
        }
        else{
            if(a[i]>a[i-1])sn=1;
            else sn=-1;
        }
    }
    printf("%d\n",ans);
    //cerr<<clock()*1./CLOCKS_PER_SEC<<"ms\n";
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(false)
#define For(i, x, y) for(int i = x; i <= y; i++)
#define For_(i, x, y) for(int i = x; i >= y; i--)
const int inf = 0x3f3f3f3f;
const ll Inf = 1e18;
const int maxn = 2e5 + 5;

int an[maxn];
int bn[maxn];

int main(void)
{
	int k, n;
	cin >> k >> n;
	For(i, 1, n) cin >> an[i];
	sort(an + 1, an + n + 1);
	For(i, 2, n) bn[i - 1] = an[i] - an[i - 1];
	bn[n] = k - an[n] + an[1];
	sort(bn + 1, bn + n + 1);
	cout << k - bn[n] << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;

namespace LevelB
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            long buf = 0;
            for (int i = 0; i < x+1; i++)
            {
                if (!Program.Judge(i))
                {
                    buf += i;
                }
            }
            Console.WriteLine(buf.ToString());
        }

        private static bool Judge(int x)
        {
            if (x % 5 == 0 || x % 3 == 0)
                return true;
            else
                return false;
        }
    }
}


Measured memory_bytes: 27540
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_D
sample_input = list(range(3))
sample_input[0] = '''5
5
1
4
3
2'''
sample_input[1] = '''3
3
2
1'''
sample_input[2] = '''5
5
1
4
3
2'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
def print_list(l):
    output = ''
    for elem in l:
        output += str(elem) + ' '
    output = output.rstrip()
    print(output)

def determine_G(n):
    G = []
    pot = 1
    while True:
        pot *= 2
        if pot-1 > n:
            break
        G.append(pot-1)
    G.reverse()
    return G

def log_m_floor(n):
    m = 2
    pot = 1
    power = 0
    while (pot < n):
        pot *= 2
        power += 1
    return power

def insertion_sort(A, n, g):
    cnt = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while (j >= 0 and A[j] > v):
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt

def shell_sort(A, n):
    cnt = 0
    G = determine_G(n)
    m = len(G)
    if m == 0:
        print(1)
        print(1)
        print(0)
        return
    print(m)
    print_list(G)
    for i in range(m):
        cnt += insertion_sort(A, n, G[i])
    print(cnt)
        
num_of_data = int(input())
data = []
for i in range(num_of_data):
    data.append(int(input()))
shell_sort(data, num_of_data)
for d in data:
    print(d)

Measured memory_bytes: 47456
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int n;
int k;
bool num[10];

bool check(int x){
  int number;
  while(1){
    number = x % 10;
    x /= 10;
    if(num[number]){
      if(x == 0){
	return true ;
      }
      continue;
    }else{
      break;
    }
  }
  return false ;
}


void solve(){
  for(int ans = n; ; ans ++){
    if(check(ans)){
      cout << ans << endl;
      return ;
    }
  }
  
  return ;
}

int main(){
  int x;
  cin >> n >> k;
  for(int i = 0; i < 10; i++) num[i] = true;
  for(int i = 0; i < k; i++){
    cin >> x;
    num[x] = false;
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
import sys, heapq, bisect, math, fractions
from collections import deque
from collections import Counter
from collections import OrderedDict

H, W = map(int, input().split())
A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(H)]

res = []
for i in range(H):
    for j in range(W):
        if j == W - 1 and i != H - 1 and A[i][j] % 2 != 0:
            A[i][j] -= 1
            A[i + 1][j] += 1
            res.append([i + 1, j + 1, i + 2, j + 1])
        elif j < W - 1 and A[i][j] % 2 != 0:
            A[i][j] -= 1
            A[i][j + 1] += 1
            res.append([i + 1, j + 1, i + 1, j + 2])

print(len(res))
for i in range(len(res)):
    print(*res[i])


Measured memory_bytes: 32284
n = int(input())
A = list(map(int, input().split()))
A2 = A.copy()
ans = 0

A.sort()

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return (x * y) // gcd(x, y)

for i in range(n - 1):
    A[i + 1] = lcm(A[i], A[i + 1])
    
m = A[-1] - 1

for i in range(n):
    ans += m % A2[i]
    
print(ans)

Measured memory_bytes: 13044
n, a, b, c, d = map(lambda x: int(x)-1, input().split())
s = input()


def can_reach(x, y):
    return '##' not in s[x:y+1]


def can_jump(x, y):
    return '...' in s[x-1:y+2]


if can_reach(a, c) and can_reach(b, d):
    if c < d:
        print('Yes')
    else:
        if can_jump(b, d):
            print('Yes')
        else:
            print('No')
else:
    print('No')


Measured memory_bytes: 9400
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n,ll m);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l,r,a,b,c=0,d=0,e,g=0,p,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
       string s,s1; cin >> s >> s1;
    n = s1.size();
    if(s==s1.substr(0,n-1)) cout << "Yes";
    else cout << "No";

}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


Measured memory_bytes: 3656
N = int(input())
ans = N * (N + 1) // 2
ans = 2 * ans - 1
if N == 1:
    print(ans)
    exit()
for i in range(2, N // 2 + 1):
    M = N - (N % i)
    ans += (i + M) * (M // i) // 2
    ans -= i
print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  string s; cin>>s;
  int a=s.length();
  for(int i=0;s[i];i++){
    s[i]='x';
  }
  cout<<s<<endl;
  return 0;
}

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

int main() {
  int age;
  cin >> age;
  if (age == 7) cout << "YES" << endl;
  else if (age == 5) cout << "YES" << endl;
  else if (age == 3) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main()
{
    int N, M, x, y;
    cin >> N >> M;
    vector<int> vec(N, 0);
    for (int i = 0; i < M; ++i)
    {
        cin >> x >> y;
        ++vec.at(x - 1);
        ++vec.at(y - 1);
    }
    for (int i = 0; i < N; ++i)
    {
        cout << vec.at(i) << endl;
    }
}

Measured memory_bytes: 3596
n=list(map(str,input()))
for i in range(0,len(n)):
    if n[i]>="D":
        n[i]=ord(n[i])
        n[i]=n[i]-3
        n[i]=chr(n[i])
    elif n[i]=="A":
        n[i]="X"
    elif n[i]=="B":
        n[i]="Y"
    else:
        n[i]="Z"
print("".join(n))


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

signed main()
{
        int W,H,N; cin>>W>>H>>N;
        int minX=0,maxX=W;
        int minY=0,maxY=H;
        while(N--){
                int x,y,a; cin>>x>>y>>a;
                if(a==1) minX=max(minX,x);
                if(a==2) maxX=min(maxX,x);
                if(a==3) minY=max(minY,y);
                if(a==4) maxY=min(maxY,y);
        }
        cout<<max(0LL,maxX-minX)*max(0LL,maxY-minY)<<endl;
}


Measured memory_bytes: 256