akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

H,W = mint()
S = [input() for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            print('#',end='')
        else:
            tmp = 0
            for a in [-1,0,1]:
                for b in [-1,0,1]:
                    if (a,b)!=(0,0) and 0<=i+a<H and 0<=j+b<W and S[i+a][j+b]=='#':
                        tmp += 1
            print(tmp,end='')
    print('')

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

int main(int argc, char const *argv[])
{
	int n, x; cin >> n >> x;
	vector<int> v(n); {
		rep(i, n) {
			int t; cin >> t;
			v[i] = abs(x - t);
		}
	}

	int ans = 0;
	rep(i, n) ans = __gcd(ans, v[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
n, x, y = [int(i) for i in input().split()]
x, y = [x - 1, y - 1]

def shortest_dist(a, b):
    return min(min(abs(a - b), abs(a - x) + 1 + abs(b - y)), abs(a - x) + 2 + abs(b - x))

distance = [0] * n
for i in range(n):
    for j in range(i+1, n):
        distance[shortest_dist(i, j)] += 1

for i in range(1,n):
    print(distance[i])


# abs(a - b)
# abs(a - x) + 1 + abs(b - y)
# abs(a - x) + 2 + abs(b - x) 
# ↑のうち最小

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;
const int MOD = 1000 * 1000 * 1000 + 7;

LL A[MAX];
LL B[MAX];
LL RES[MAX];

struct Fen
{
	LL A[MAX];
	int n;

	void init(int N)
	{
		n = N;
		FILL(A, 0);
	}

	void add(int x, LL val)
	{
		for (; x < n; x |= x+1)
		{
			A[x] += val;
		}
	}

	LL get(int x)
	{
		LL res = 0;
		for (; x >= 0; x = (x & (x + 1)) - 1)
		{
			res += A[x];
		}
		return res;
	}

	LL get(int L, int R)
	{
		return get(R) - get(L-1);
	}
} D, M;

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	LL X, Y;
	cin>>n>>X>>Y;
//	n = 10;
//	X = Y = 2;
	FOR (i, 0, n)
	{
	//	A[i] = INF * 10ll + i * 10;
		cin>>A[i];
	}

	if (X < Y) swap(X, Y);

	A[n] = 2 * LINF;
	n++;

	FOR (i, 1, n)
	{
		B[i-1] = A[i] - A[i-1];
	}

	D.init(n);
	M.init(n);

	FOR (i, 0, n)
	{
		if (B[i] < Y) M.add(i, 1);
	}

	D.add(0, 1);
	RES[0] = 1;
	FOR (i, 1, n)
	{
		int L = -1, R = i;
		while(R - L > 1)
		{
			int m = (R + L) / 2;
			if (A[i] - A[m] >= X) L = m;
			else R = m;
		}

		int pos = L;

		L = -1, R = i-1;
		while(R - L > 1)
		{
			int m = (R + L) / 2;
			if (M.get(m, i-2) == 0) R = m;
			else L = m;
		}

		int pos2 = R - 1;

	//	cout<<i<<' '<<pos<<' '<<pos2<<endl;

		LL res;

		if (pos == -1 && pos2 == -1) res = 1;
		else
		{
			if (pos < pos2) continue;
			LL cur = D.get(pos2, pos);

		//	if (
			res = cur;
			if (pos2 == -1) res++;

		}

		res %= MOD;
		if (A[i+1] - A[i-1] >= Y) D.add(i, res);
		RES[i] = res;
	}
/*
	cout<<"=="<<endl;

	FOR (i, 0, n)
	{
		cout<<D.get(i, i)<<endl;
	}

	LL res = 0;

	RFOR(i, n, 0)
	{
		if (i < n-2 && M.get(i+1, n-2) != 0) break;
		res += D.get(i, i);
	}

	res %= MOD;*/

/*	FOR (i, 0, n)
	{
		cout<<i<<' '<<RES[i]<<endl;
	}*/

	LL res = RES[n-1];
	cout<<res<<endl;


}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer a = scanner.nextInt();
        Integer b = scanner.nextInt();
        Integer h = scanner.nextInt();
        Integer m = scanner.nextInt();

        double result;

        double rad = Math.PI * 2 * ((double)h / 12 + ((double)m / 60) / 12 - (double)m / 60);

        result = Math.sqrt(Math.pow(a,2) + Math.pow(b,2) - 2*a*b*Math.cos(rad));

        System.out.printf("%.20f",result);
    }
}


Measured memory_bytes: 27244
#include<bits/stdc++.h>
#define int long long
using namespace std;

vector<int> vet,v;

int n, k;

int gen(int b){
	v.clear();
	
	for(int i = 0;i<vet.size();i++){
		if(vet[i] & (1LL<<b))
			v.push_back(vet[i]);
	}
	
	return v.size();

}

int geno(int b){
	v.clear();
	for(auto &it: vet){
		if(it&(1LL<<b))
			v.push_back(it);
	}
	if(v.size() >= k)
		vet = v;

}

main(){
	cin >> n >> k;
	v.resize(n);
	
	for(int i =0;i<n;i++) cin >> v[i];
	
	for(int i = 0;i<n;i++){
		int soma = 0;
		for(int j = i;j<n;j++){
			soma += v[j];
			vet.push_back(soma);
		}
	}
	
	int f = -1;
	
	for(int i = 40;i>=0;i--){
		int val = gen(i);
		if(val >= k){
			f = i	;
			break;
		}
	}
	
	if(f==-1){
		cout<<0;
		return 0;
	}
	
	vet = v;
	v.clear();
	
	for(int i = f-1;i>=0;i--){
		geno(i);
		
	}
	int v1 = vet[0];
	for(int i =0;i<k;i++)
		v1&=vet[i];	
	cout<<v1<<endl;	
}

Measured memory_bytes: 6388
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int askRow(int s, int n) {
	cout << "?";
	for (int i = s+1; i <= s+n; ++i) cout << ' ' << i;
	cout << endl;
    cout.flush();
	string res;
	cin >> res;
	return (res == "Red") ? 1 : -1;
}
int askEq(int i, int s, int n) {
	cout << "? " << i+1;
	for (int j = s+1; j < s+n; ++j) {
		if (j > 2*n) cout << ' ' << j - 2*n;
		else cout << ' ' << j;
	}
	cout << endl;
	cout.flush();
	string res;
	cin >> res;
	return (res == "Red") ? 1 : -1;
}

const int N = 100;
int col[2*N];

int main() {

	int n;
	cin >> n;

	// Ask first N. Shift window right one-by-one until the answer changes.
	// Since last N must have opposite answer, this happens at some point.
	// Binary search where it happens. Note that we don't need to find the first such position.
	// 1 + log2(100) ~ 8 < 10

	int x = askRow(0, n); // Sum of first n has more of x
	int low = 1;
	int high = n;
	while(low != high) {
		int mid = (low + high) >> 1;
		int y = askRow(mid, n);
		if (x != y) high = mid;
		else low = mid + 1;
	}

	// Now askRow(low-1, n) and askRow(low, n) give different answers, hence both colors appear an equal number of times in [low, low+n-2].
	for (int i = 0; i < low; ++i) col[i] = askEq(i, low, n);
	for (int i = low; i < low + n - 1; ++i) col[i] = askEq(i, low + n, n);
	for (int i = low + n - 1; i < 2*n; ++i) col[i] = askEq(i, low, n);

	cout << "! ";
	for (int i = 0; i < 2*n; ++i) {
		if (col[i] == 1) cout << 'R';
		else cout << 'B';
	}
	cout << endl;
	cout.flush();
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int n = in(), p = in();
vi a;

lint dp[100][3];

lint dfs(int i=0, int sum=0) {
  if (i == n) return sum == p;
  lint &ret = dp[i][sum];
  if (~ret) return ret;
  ret = dfs(i + 1, sum) + dfs(i + 1, (sum + a[i]) % 2);
  return ret;
}

signed main() {
  memset(dp, -1, sizeof(dp));
  rep(i, n) a.pb(in());

  cout << dfs() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, i;
	char str_h[100];
	char str_t[100];
	int p_h, p_t;
	
	p_h = p_t = 0;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s %s", str_t, str_h);
		
		if (strcmp(str_t, str_h) > 0){
			p_t += 3;
		}
		else if (strcmp(str_t, str_h) < 0){
			p_h += 3;
		}
		else {
			p_t++;
			p_h++;
		}
	}
	
	printf("%d %d\n", p_t, p_h);
	
	return (0);
}

Measured memory_bytes: 604
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        int A=input.nextInt();
        int B=input.nextInt();
        int H=input.nextInt();
        int M=input.nextInt();
        double angle=Math.abs(5.5*M-H*30)%360;
        double c=Math.sqrt(A*A+B*B-2*A*B*Math.cos(Math.PI*angle/180));
      System.out.print(c);
    }   
}

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

int main()
{
    int n;
    cin >> n;

    int a = 0;
    for (int b = n; b; a += b % 10, b /= 10);

    cout << (n % a ? "No" : "Yes") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

typedef long long int int64;

void run(void){
  int64 n,p;
  scanf("%lld%lld",&n,&p);
  if(n==1){
    printf("%lld\n",p);
    return;
  }
  int64 ans=1;
  int64 k;
  for(k=2;k*k<=p;k++){
    int c=0;
    while(p%k==0){
      p/=k;
      c++;
    }
    c/=n;
    while(c--){
      ans*=k;
    }
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2000+10;
string str;
int main() {
    while(cin>>str){
        int sum=0,n=str.length();
        for(int i=0;i<n;i++){
            sum+=str[i]-'0';
        }
        int xx=sum-(str[n-1]-'0');
        for(int i=n-2;i>=0;i--){
            if(str[i]-'0'>0){
                int dd=xx-1;
                for(int j=i+1;j<n;j++){
                    dd+=9;
                }
                sum=max(sum,dd);
            }


            xx-=(str[i]-'0');
        }
        printf("%d\n",sum);
    }
    return 0;
}


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

using namespace std;

int main() {
    string s, t;
    cin >> s;
    t = s;
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    cout << (s.size() == t.size() ? "yes" : "no") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q,h,s,d,n;
    cin >> q >> h >> s >> d;
    cin >> n;
    ll ans = 0;
    ll max2 = min(min(q*8, h*4), min(s*2, d));
    ll max1 = min(s, min(q*4, h*2));
    if(n % 2 == 1){
        ans = (n/2) * max2 + max1;
    }else{
        ans = (n/2) * max2;
    }
    print(ans);


 }

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef struct {
    double x;
    double y;
}P;

void koch(int,P,P);

int main(){
    P p1 = {0,0},p2 = {100,0};
    int d;

    scanf("%d",&d);

    printf("%f %f\n",p1.x,p1.y);
    koch(d,p1,p2);
    printf("%f %f\n",p2.x,p2.y);

    return 0;
}

void koch(int d, P p1, P p2){
    P s,t,u;
    double th;
    
    if (d == 0)
        return;

th = M_PI * 60 / 180;
s.x = (2 * p1.x + 1 * p2.x) / 3;
s.y = (2 * p1.y + 1 * p2.y) / 3;
t.x = (1 * p1.x + 2 * p2.x) / 3;
t.y = (1 * p1.y + 2 * p2.y) / 3;
u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(d - 1, p1, s);
    printf("%f %f\n", s.x,s.y);
    koch(d - 1, s, u);
    printf("%f %f\n", u.x,u.y);
    koch(d - 1, u, t);
    printf("%f %f\n", t.x,t.y);
    koch(d - 1, t, p2);

}


Measured memory_bytes: 2132
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes"<<"\n";
    }
    else
    {
        cout<<"No"<<"\n";
    }
    return 0;
}




Measured memory_bytes: 3612
from sys import stdin
import numpy as np

def bit_search(a, n, m, x):
    min_price = np.inf
    for i in range(2 ** n):
        price = 0
        skill = np.zeros((n, m))
        for j in range(n):
            if (i >> j) & 1:
                price += a[j][0]
                skill[j] = a[j][1:]
        skill_sum = np.sum(skill, axis=0)\
                        if skill.shape[0] > 1 else skill
        if not (skill_sum >= x).all() or price > min_price: continue
        min_price = price
    return  min_price

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    min_price = bit_search(a, n, m, x)
    return print('-1' if np.isinf(min_price) else  min_price)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27252
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int main(){
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];
    auto calc = [&]() {
        vector<pll> x(n);
        ll s = a[0], t = a[1];

        ll j = 1;
        x[1] = make_pair(min(s,t), max(s, t));
        REP(i, 2, n) {
            t += a[i];
            while(abs(s-t) > abs(s+a[j] - (t-a[j]))) {
                s += a[j];
                t -= a[j];
                ++j;
            }
            x[i] = make_pair(min(s,t), max(s, t));
        }
        return x;
    };
    auto x = calc();
    reverse(all(a));
    auto y = calc();
    reverse(all(y));
    ll ans = 1e18;
    REP(i, 1, n-2) {
        ans = min(ans, max(x[i].se, y[i+1].se) - min(x[i].fi, y[i+1].fi));
    }
    cout << ans << endl;
    dumpV(x);
    dumpV(y);
    return 0;
}

Measured memory_bytes: 8064
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var P = Console.ReadLine().Replace(" ", "");
            var Q = Console.ReadLine().Replace(" ", "");

            var list = Permutation.Enumerate(Enumerable.Range(1, N)).Select(elem1 => new string(elem1.Select(elem2 => elem2.ToString()[0]).ToArray())).ToList();
            var orderP = list.IndexOf(P) + 1;
            var orderQ = list.IndexOf(Q) + 1;
            var answer  = Math.Abs(orderP - orderQ);

            Console.WriteLine(answer);
        }
    }

    public static class Permutation {
        public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items)
        {
            if (items.Count() == 1)
            {
                yield return new T[] { items.First() };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };
                var unused = items.Except(leftside);
                foreach (var rightside in Enumerate(unused))
                {
                    yield return leftside.Concat(rightside).ToArray();
                }
            }
        }
    }
}


Measured memory_bytes: 24512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int a[n];
    vector<int>b(n);
    int cnt = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b[i] = a[i];
    }
    
    sort(b.begin(),b.end());
    for(int i = 0;i < n;i++){
        if(a[i] != b[i]){
            cnt++;
        }
    }
    if(cnt > 2){
        cout <<"NO";
    }else{
        cout <<"YES";
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int h,w,i,j,k;
    cin >> h >> w;
    char c[h][w];
    for(i=0;i<h;i++) for(j=0;j<w;j++) cin >> c[i][j];
    int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
    int from,to,ans=1;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            from=0; to=0;
            for(k=0;k<4;k++){
                if(i+dy[k]<0||i+dy[k]>=h||j+dx[k]<0||j+dx[k]>=w) continue;
                if(c[i+dy[k]][j+dx[k]]=='#'){
                    if(k==0||k==2) to++;
                    else from++;
                }
            }
            if(from>=2||to>=2) ans = 0;
        }
    }
    if(ans) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int arr[1001] ; 

int main()
{   
    int n ; cin >> n ; 
    for(int i=0 ; i<n ; i++){
        cin >> arr[i] ; 
    }
    int def = 0 ; 
    
    for(int i=0 ; i<n ; i++){
        if(arr[i]!=i+1){
            def++;
        }
    }
    if(def>2){
        cout << "NO"; 
    }
    else{
        cout << "YES"; 
    }
    
    
    
    
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1001000;
int n,pw[20],pos[N];
char s[N];
struct node {
	node *s[3];
	int lab;
	bool rev;
	void setr() {
		rev^=1;
		swap(s[1],s[2]);
	}
	void push() {
		if (rev) { rep(j,0,3) if (s[j]) s[j]->setr(); rev=0; }
	}
}pool[N],*cur=pool,*rt;

int main() {
	scanf("%d",&n);
	pw[0]=1;
	for (int i=1;i<=n;i++) pw[i]=pw[i-1]*3;
	rt=cur++;
	rep(i,0,pw[n]) {
		node *p=rt;
		rep(j,0,n) {
			int w=i/pw[j]%3;
			if (!p->s[w]) p->s[w]=cur++;
			p=p->s[w];
		}
		p->lab=i;
	}
	scanf("%s",s);
	int m=strlen(s);
	rep(i,0,m) if (s[i]=='S') {
		rt->setr();
	} else {
		node *p=rt;
		rep(j,0,n) {
			p->push();
			node *t=p->s[2]; p->s[2]=p->s[1]; p->s[1]=p->s[0]; p->s[0]=t;
			p=p->s[0];
		}
	}
	rep(i,0,pw[n]) {
		node *p=rt;
		rep(j,0,n) {
			int w=i/pw[j]%3;
			p->push(); p=p->s[w];
		}
		//printf("zz %d\n",p-cur);
		pos[p->lab]=i;
		//printf("%d ",p->lab);
	}
	rep(i,0,pw[n]) printf("%d%c",pos[i]," \n"[i==pw[n]-1]);
}


Measured memory_bytes: 31232
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int n;
	cin >> n;

	vector<PII> vp;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		vp.PB(MP(tmp,i));
	}

	SORT(vp);

	for (auto&& var : vp) {
		dump(var.first);
		dump(var.second);
	}

	int max = 1, row = 1;
	int prev = vp[0].second;
	for (auto&& var : vp) {
		if (prev < var.second) {
			row++;
		}
		else {
			if (max < row) {
				max = row;
			}
			row = 1;
		}
		prev = var.second;
	}
	if (max < row) {
		max = row;
	}


	cout << vp.size() - max;
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <complex>
using namespace std;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int e = min(b,d) - max(a,c);
    if(e <= 0){
        cout << 0 << endl;
    }else{
        cout << e << endl;
    }
}

Measured memory_bytes: 256
main = do
 li <- getLine
 let [a,b,h,m] = map read $ words li
 let ans = compute a b h m
 print ans

{-
分針は m / 60 * 2pi の b の位置
時針は h / 12 * 2pi + m / 60 / 12 * 2pi の a の位置
-}

compute :: Double -> Double -> Double -> Double -> Double
compute a b h m = sqrt ((x1-x2)^2 + (y1-y2)^2)
  where
    r1 = m * 2 * pi / 60
    (x1,y1) = (b * cos r1, b * sin r1)
    r2 = (h + m / 60) * 2 * pi / 12
    (x2,y2) = (a * cos r2, a * sin r2)

Measured memory_bytes: 4520
N = int(input())
a = []
for i in range(0, N):
  a.append(int(input()))
  a[i] -= 1;

ans = 1
n = 0
flag = 0
for i in range(0, N):
  if(a[n] == 1):
    flag = 1
    break
  else:
    ans += 1
    n = a[n]
if flag == 0:
  ans = -1
print(ans)

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

int main() {
  int N;
  cin >> N;
  int count = 0;
  if (N < 10) count = N;
  else if (N < 100) count = 9;
  else if (N < 1000) count = N - 90;//9 + N - 99
  else if (N < 10000) count = 909;
  else if (N < 100000) count = N - 9090;//909 + N - 9999
  else count = 90909;
  
  cout << count;
    
   
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    def make_divisors(n):
             divisors = []
             for i in range(1, int(n**0.5)+1):
                 if n % i == 0:
                     # 約数の片割れをリストに
                     divisors.append(i)
                     # 平方数じゃなければ片割れの相方をリストに
                     if i != n // i:
                         divisors.append(n//i)
             divisors.sort(reverse=True) # sort必要なかったらコメントアウト
             return divisors
    for i in make_divisors(m):
        if i*n<=m:
            print(i)
            break

resolve()

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ms memset
//#define MAXN 10005
//#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int N, n;
int A[200010];

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

	cin >> N;

	for(int i = 0; i < N-1; i++){
		cin >> n;
		A[n]++;
	}

	for(int i = 1; i <= N; i++){
		cout << A[i] << "\n";
	}

	return 0;	
}

Measured memory_bytes: 4424
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vll as(n + 1);
  as[0] = 0;
  rep(i, n) cin >> as[i + 1];
  Sort(as);

  auto f = [&](ll idx) {
    ll sum = as[idx];
    rep(i, n+1){
      if (i == idx) continue;
      if (sum * 2 >= as[i])
        sum += as[i];
      else
        return false;
    }
    return true;
  };

  ll l = 0, r = n;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    if (f(m))
      r = m;
    else
      l = m;
  }
  cout << n - r + 1 << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException{
		FastScanner f = new FastScanner(); //Replace "problem" with problem name
        
        int[] powers = {1,2,4,8,16,32,64,128};
        int n = f.nextInt();
        int j = 0;
        for(int i = 0; i < powers.length; i++){
        	if (powers[i] > n){
        		j = i;
        		break;
        	}
        }
        System.out.println(powers[j-1]);
	}

	public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

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

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

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


Measured memory_bytes: 21332
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int A, B, C, D;
    bool isTakahashi = true;
    cin >> A >> B >> C >> D;

    while (A > 0 && C > 0) {

        if (isTakahashi) {
            C -= B;
        } else {
            A -= D;
        }

        isTakahashi = !isTakahashi;
    }

    if (isTakahashi) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    for(int i = n-1; i > 0; i--){
        if(h[i] < h[i-1]) h[i-1]--;
        if(h[i] < h[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m;
vector<int> G[100010];
bool used[100010];
int dp[100010], a[100010];

int solve(int pos)
{
    if (dp[pos] != -1)
        return dp[pos];
    int res = 0;
    rep(i, G[pos].size()) res = max(res, solve(G[pos][i]) + 1);
    dp[pos] = res;
    return res;
}

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

    cin >> n >> m;
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[y].push_back(x);
        a[x]++;
    }
    int ans = 0;
    rep(i, n) dp[i] = -1;
    rep(i, n) if (a[i] == 0) ans = max(ans, solve(i));
    cout << ans << endl;
}

Measured memory_bytes: 12032
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <typeinfo>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
#define REP(i, a, b) for (ll i = a; i < (ll)b; i++)
#define PER(i, a, b) for (ll i = b - 1; i >= (ll)a; i--)
#define all(v) (v).begin(), (v).end()
#define fill(v, n) fill(v.begin(), v.end(), n)
#define deb(sum) cout << #sum << "=" << sum << "\n"
#define lpi(v, x) (lower_bound(all(v), x) - v.begin()) //lowermost possible index
#define upi(v, x) (upper_bound(all(v), x) - v.begin()) //uppermost possible index
#define bpc(n) __builtin_popcountll(n)
//#define PI 3.1415926535897932384626
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
const ll INF = 9223372036854775807;
const int mod = 1000000007;
const long double PI = acos(-1.0);
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x,y;
    ll ans;
    /*
    for(int i=a; i<=b; i++){
        for(int j=c;j<=d; j++){
            ans = max(ans,i*j);
        }
    }
    */
    if(a>=0 && b>=0){
        ll prod1 = b*d;
        ll prod2 = a*d;
        ans = max(prod1,prod2);
        //cout<<ans;
    }
    else if(a<=0 && b>=0){
        ll prod1 = a*c;
        ll prod2 = a*d;
        ll prod3 = b*d;
        ans = max(prod1,max(prod2,prod3));
    }
    else if(a<=0 && b<=0){
        ll prod1 = a*c;
        ll prod2 = b*c;
        ans = max(prod1,prod2);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<vector<int> > Matrix;
Matrix d; 
const int INF = 100000000;


int main(){
  string s;
  int le;
  
  std::cin >> s;
  le=int(s.size());
  std::vector<int> han(le,0);
  for (int i = 0; i < le; i++) {
    /* code */
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')han[i]=1;
  }
 // rep(i,le)std::cout << han[i] << std::endl;
  int ans=0,d=0;
  for (int i = 0; i < le; i++) {
    int dum=1;
    for (int j = i; j < le; j++) {
      dum*=han[j];
      /* code */
      if(dum==1){
      }else{
        if(ans<j-i)ans=j-i;
        break;
      }
      if(j==le-1 &&dum==1)ans=max(le-i,ans);
    }
    /* code */
  }
  std::cout << ans << std::endl;
  
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

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

fn gcd(a: i32, b: i32) -> i32 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn main() {
    let N: i32 = read_line().parse().unwrap();
    let A: Vec<i32> = read_vec();
    let ans = A.iter().fold(A[0], |g, &val| gcd(g, val));
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int k = 0;
    for (i = 0; i < n; i++)
        if (a[i] % 2 == 1)
            k++;
    if (k % 2 == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N;ll K;
    cin >>N>>K;

    vector<int> A(N);
    rep(i,N) cin >> A[i];
    
    //-----------------------------------
    ll ans=0,Sk=(K*(K+1)/2)%mod,Skm=(K*(K-1)/2)%mod;
    rep(l,N-1){
        repd(r,l+1,N){
            if(A[l]>A[r]){
                ans+=Sk;
                ans%=mod;
            }else if(A[l]<A[r]){
                ans+=Skm;
                ans%=mod;
            }
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	set<int> A;
	for (auto i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		A.insert(a);
	}

	auto num = N - (int)A.size();
	cout << (int)A.size() - (num % 2) << endl;

	return 0;
}

Measured memory_bytes: 4992
// ------------------------------------
// Date:2018/ 3/27
// Problem:A - Getting re_a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N, K;

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

  cin >> N >> K;
  vector< int > A(N);
  REP(i, N)
    cin >> A[i];

  sort(ALL(A));

  bool ok = false;
  if (K > A[A.size() - 1]) {
    OK(ok);
    return 0;
  }
 
  int m_gcd = A[0];
  FOR(i, 1, N) {
    // debug(m_gcd);
    if (A[i] % m_gcd == 0) continue;
    m_gcd = A[i] % m_gcd;
  }
  
  if (K % m_gcd == 0) ok = true;
  OK(ok);

  return 0;
}



Measured memory_bytes: 640
program main
  implicit none
  integer :: q, i, p1, p2
  logical :: flipped
  character(100000) :: s
  character(900000) :: s2
  character(5) :: query
  read (*, *) s
  p1 = 400000
  p2 = 400000 + len_trim(s) - 1
  flipped = .false.
  s2(p1:p2) = s(:)
  read (*, *) q
  do i = 1, q
    read (*, "(a5)") query
    if (query(1:1) == "1") then
      flipped = (.not. flipped)
    else
      if (query(3:3) == "1" .neqv. flipped) then
        p1 = p1 - 1
        s2(p1:p1) = query(5:5)
      else
        p2 = p2 + 1
        s2(p2:p2) = query(5:5)
      end if
    end if
  end do
  if (flipped) call flip(s2(p1:p2), p2 - p1 + 1)
  write (*, "(a)") s2(p1:p2)
  contains
  subroutine flip(s, n)
    integer, intent(in) :: n
    character(n), intent(inout) :: s
    character(1) :: c
    integer :: i
    do i = 1, n / 2
      c = s(i:i)
      s(i:i) = s(n - i + 1:n - i + 1)
      s(n - i + 1:n - i + 1) = c
    end do
  end subroutine flip
end program main


Measured memory_bytes: 1444
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
       int n = in.nextInt();
       int k = in.nextInt();
       ArrayList<Integer> list = new ArrayList<>(k);
      while(k--!=0){
          list.add(in.nextInt());}
      while(true){
          boolean flag = true;
          String s = n+"";
           for (int i =0;i<s.length();i++){
              if (list.contains(Character.getNumericValue(s.charAt(i)))){
                  flag = false;}}
              if(flag){
                  break;}
              else{
                  n++;}}
        System.out.println(n);
      }
}
     


Measured memory_bytes: 43564
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String[] s = new String[n];
      int[] t = new int[n];
      for(int i=0;i<n;i++){
        s[i]=sc.next();
        t[i]=sc.nextInt();
      }
      String z = sc.next();
      int sum = 0;
      int idx = 0;
      for(int i=0;i<n;i++){
        if(s[i].equals(z)){
          idx=i;
          break;
        }
      }
      for(int i=idx+1;i<n;i++)sum+=t[i];
      System.out.println(sum);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 24532
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
void Main()
{
  int n, k;
  cin >> n >> k;
  int d[k];
  int a[k][n];
  int count = 0;
  
  for(int i = 0; i < k; i++){
    cin >> d[i];
    //printf("%d\n", d[i]);
    
    for(int j = 0; j < d[i]; j++){
      cin >> a[i][j];
      //printf("%d ", a[i][j]);
    }
    
  }
  
  int s[n];
  
  for(int i = 0; i < n; i++){
    s[i] = i + 1;
  }
  
  for(int i = 0; i < k; i++){
    for(int j = 0; j < d[i]; j++){
      for(int l = 0; l < n; l++){
        if(a[i][j] == s[l]){
          s[l] = 0;
        }
        
      }
    }
  }
  
  for(int i = 0; i < n; i++){
    if(s[i] != 0)
      count++;
  }
  
  printf("%d", count);
}
 
int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int H, W;
vector<vector<char>> s;
int bfs(pii start) // (y, x)
{
    vvi dist(H+1, vi(W+1, INF));
    queue<pii> q;
    q.push(start);
    dist[start.first][start.second] = 0;
    while(!q.empty())
    {
        pii p = q.front(); q.pop();
        if(p.first == H && p.second == W )return dist[p.first][p.second] + 1;
        for(int dx = -1; dx <= 1; dx++)
        {
            for(int dy = -1; dy <= 1; dy++)
            {
                if(dx * dy != 0) continue;
                int x = p.second + dx;
                int y = p.first + dy;
                if(1 <= x && x <= W && 1 <= y && y <= H && dist[y][x] == INF && s[y][x] != '#')
                {
                    dist[y][x] = dist[p.first][p.second] + 1;
                    q.push(pii(y, x));
                }
            }
        }
    }
    return -1;
}

void solve()
{
    cin >> H >> W;
    s = vector<vector<char>>(H+1, vector<char>(W+1));
    int white = 0;
    REP1(i, H)
    {
        REP1(j, W)
        {
            cin >> s[i][j];
            if(s[i][j] == '.') white++;
        }
    }

    int d = bfs(pii(1, 1));
    if(d == -1) cout << -1 << endl;
    else cout << white - d << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
//============================
// ABC134b Golden Apple
//
// 2019/08/14
//============================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n, d;
  cin >> n >> d;

  if(n % (2*d+1) == 0) cout << n / (2*d+1) << endl;
  else                 cout << (n / (2*d+1)) + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(c > a && c < b){
        printf("Yes");
    }else if(c < a && c > b ){
       printf("Yes");
    } else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
a,b,c,d=list(map(str,input()))

for i in range(2**3):
    ls = ["+"] *3
    for j in range(len(ls)):
        if (i>>j) & 1:
            ls[j] = "-"
    ans = a+ls[0]+b+ls[1]+c+ls[2]+d
    if eval(ans) == 7:
        print(ans+"=7")
        break

# def solve(m,n):
#     if eval(m)==7:
#         print(m+"=7")
#         exit(0)
#     elif n<7:
#         solve(m,n+2)
#         solve(m[:n]+"-"+m[n+1:],n+2)

# solve(a+"+"+b+"+"+c+"+"+d,1)


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}

const int N = 2e5 + 7;
vector<int> adj[N];
vector<int> sts;
vector<int> where;
int here;


void dfs(int a, int p) {
        where[a] = ++here;
        sts[a] = 1;
        for (auto b: adj[a]) {
                if (p ^ b) {
                        dfs(b, a);
                        sts[a] += sts[b];
                }
        }
}


void _main() {
        int n, q; cin >> n >> q;
        sts.resize(n+2), where.resize(n+2);
        for (int i = 1; i <= n-1; i++) {
                int a, b; cin >> a >> b;
                adj[a].emplace_back(b);
                adj[b].emplace_back(a);
        }

        dfs(1, 0);
        vector<ll> ans(n + 1);
        while (q--) {
                int a, b; cin >> a >> b;
                ans[where[a]] += b;
                ans[where[a] + sts[a]] -= b;
        }

        for (int i = 1; i <= n + 1; i++) ans[i] += ans[i - 1];
        for (int i = 1; i <= n; i++) cout << ans[where[i]] << ' ';
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

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

int main() {
    long long A,ans;
    long long At, Ab;
    double B;
    cin >> A >> B;
    Ab = A % 100;
    At = (long long)((A - Ab)/100);
    int Bc = (int)(B*100 + 0.00005);
    ans = At*Bc + (int)(Ab*B);
    cout << ans << endl;
}



Measured memory_bytes: 3732
N,M = map(int,raw_input().split())
data = []

#for i in range(M):
#    A,B = map(int,raw_input().split())
#    data.append([A,B,i])

for i in range(M):
    A,B = map(int,raw_input().split())
    data.append([A,B,i])

data.sort()
P = data[0][0]
counter = 0

for i in range(len(data)):
    if P != data[i][0]:
        P = data[i][0]
        counter = 0
    data[i] = [data[i][2],P,counter+1]
    counter += 1

data.sort()
for i in data:
    print format(i[1],'06')+format(i[2],'06')

Measured memory_bytes: 25332
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,result;
    scanf("%d %d",&a,&b);
    result=(a+b)/2;
    if(abs(a-result)==abs(b-result))
        printf("%d",result);
        else
            printf("IMPOSSIBLE");
        return 0;
}


Measured memory_bytes: 1732