akhauriyash/Code-Regression huggingface dataset:
#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()
#define allR(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int, int>;
const int INF (1<<30);

int main() {
  string S;
  int K;
  cin >> K >> S;

  if (S.length() <= K) {
    cout << S << endl;
  }
  else {
    rep(i, K) cout << S[i];
    cout << "..." << endl;
  }

  return 0;
}


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

int main() {
    long long n;
    cin >> n;
    int l[n];
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l, l + n);

    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            long long tmp = lower_bound(l, l + n, l[i] + l[j]) - l;
            ans += tmp - j - 1;
        }
    }

    cout << ans << endl;
}

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

int main(){
  int N;
  cin>>N;
  for(int n=0;n<N;n++){
    string a;
    cin>>a;
    if(a=="Y"){
      cout<<"Four"<<endl;
      break;
    }
    else if(n==N-1&&a=="Y"){
      cout<<"Four"<<endl;
      break;
    }
    else if(n==N-1&&a=="G"||n==N-1&&a=="W"||n==N-1&&a=="P"){
      cout<<"Three"<<endl;
      break;
    }
  }
}  

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

using namespace std;
typedef long long LL;

template <typename T> void read(T & x) 
{
	int f = 1; char ch; x = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x *= f;
}

const int NX = 1005, mod = 1e9 + 7;
int n, m, a[NX][NX], ta[NX][NX]; LL K; 

int exp(int a, LL n)
{
	int res = 1;
	for (; n; n >>= 1)
	{
		if(n & 1)
			res = (LL) res * a % mod;
		a = (LL) a * a % mod;
	}
	return res;
}

struct matrix
{
	int x[2][2];
	int* operator [] (int i)
	{
		return x[i];
	}
	
	matrix operator * (matrix b)
	{
		matrix c = {};
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++)
				for (int k = 0; k < 2; k++)
					c[i][j] = (c[i][j] + (LL) x[i][k] * b[k][j]) % mod;
		return c;
	}
}T;

matrix exp(matrix a, LL n)
{
	matrix res = {}; 
	res[0][0] = res[1][1] = 1;
	
	for (; n; n >>= 1)
	{
		if(n & 1)
			res = res * a;
		a = a * a;
	}
	return res;
}

int main() 
{
	int total = 0;
	read(n); read(m); read(K);
	for (int i = 1; i <= n; i++) 
	{
		char s[NX]; 
		scanf("%s", s + 1);
		for (int j = 1; j <= m; j++)
		{
			a[i][j] = s[j] == '#';	
			total += a[i][j];
		}
	}
	
	bool row_u = false, col_u = false;
	for (int i = 1; i <= n; i++)
	{
		if(a[i][1] && a[i][m])
			row_u = true;
	}
	
	for (int i = 1; i <= m; i++)
	{
		if(a[1][i] && a[n][i]) 
			col_u = true;
	}
	
	if(!K || (col_u && row_u))
	{
		puts("1");
		return 0;
	}
	
	if(!col_u && !row_u)
	{
		printf("%d\n", exp(total, K - 1));
		return 0;
	}
	
	if(!row_u)
	{
		// rotate
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				ta[j][i] = a[i][j];
		swap(n, m);
		memcpy(a, ta, sizeof(a));
	}
	
	int same_adj = 0;
	int same_row = 0; 	
	
	for (int i = 1; i <= n; i++)
		if(a[i][1] && a[i][m])
			++same_row;
	
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j < m; j++)
			if(a[i][j] && a[i][j + 1])
				++same_adj;
	}
	
	T[0][0] = total; T[0][1] = same_adj;
	T[1][0] = 0;     T[1][1] = same_row;
	
	matrix ans = exp(T, K - 1);
	printf("%d\n", (ans[0][0] + mod - ans[0][1]) % mod);
	return 0;
}





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

int main () {
  int A, B, C;
  cin >> A >> B >> C;
  
  if ((A == 5) && (B == 5) && (C == 7)) cout << "YES" << endl;
  else if ((A == 7) && (B == 5) && (C == 5)) cout << "YES" << endl;
  else if ((A == 5) && (B == 7) && (C == 5)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =3e5+100;
const int mod =3e5;
char s[N][20];
int hashTable[mod];
ll cnt[mod];
void init()
{
    for(int i=0;i<mod;i++)
    {
        hashTable[i] =-1;
        cnt[i] =0;
    }
    return ;
}
int Hash(char *x)
{
    int c,base =5381,ha =0;
    while(c=*x++)
    {
        ha =(ha*base+c)%mod;
    }
    return ha;
}
bool compare(char *s1,char *s2)
{
    while(*s1)
    {
        if(*s1!=*s2)
            return 0;
        s1++,s2++;
    }
    return 1;
}
int getID(int t,int id)
{
    while(hashTable[t]!=-1)
    {
        if(compare(s[hashTable[t]],s[id]))
            return t;
        t++;
        if(t==mod)
            t =0;
    }
    return t;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        init();
        for(int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
            sort(s[i],s[i]+10);
            int t =Hash(s[i]);
            int id =getID(t,i);
            cnt[id]++;
            hashTable[id] =i;
        }
        ll ans =0;
        for(int i=0;i<mod;i++)
            ans +=(cnt[i]*(cnt[i]-1))/2;
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 6400
<?php

fscanf(STDIN, "%d", $n);

$dams = explode(" ", trim(fgets(STDIN)));

$start = 0;

$start_value = 0;
$next = $start_value;
for ($i = $start; $i < $n; $i++) {
    $next = $dams[$i] - $next;
}
$echo = $next;
$ans[$start] = $echo;
$next = $next / 2;


for ($i = $start; $i < $n; $i++) {
    $next = $dams[$i] - $next;
    if($i+1 < $n){
        $ans[$i+1] = $next * 2;
    }
}
echo implode(" ", $ans);


Measured memory_bytes: 20976
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int p[200100];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    
    rep(i, N) cin >> p[i + 1];
    rep(i, N) p[i + 1] += p[i];
    int ans = 0;
    rep(i, N - K + 1) {
        ans = max(ans, p[K + i] - p[i] + K);
        //cout << p[K + i] - p[i] << endl;
    }
    cout << fixed << setprecision(12) << ans/2.0 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod  = 1000000007;
ll qpow(int a,int b){
    ll ret = 1;
    while(b){
        //cout << b%2 << endl;
        if(b%2) ret=(ret*a)%mod;
        a=(1ll*a*a)%mod;
        b/=2;
    }
    return ret;
}
int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    ll ret = qpow(2,n);
    a=min(a,n-a);
    ll num = 1;
    for(int i=1;i<=a;i++)
        num=(num*i)%mod;
    ll num2 = 1;
    for(int i=n-a+1;i<=n;i++)
        num2=(num2*i)%mod;
    ret-=num2*qpow(num,mod-2)%mod;
    num =1;
    b=min(b,n-b);
    for(int i=1;i<=b;i++)
        num=(num*i)%mod;
    num2 = 1;
    for(int i=n-b+1;i<=n;i++)
        num2=(num2*i)%mod;
    ret-=num2*qpow(num,mod-2)%mod+1;
    cout << (ret%mod+mod)%mod << endl;
    return 0;
}


Measured memory_bytes: 3636
#!/usr/bin/env python
# coding: utf-8

# In[2]:


import math


# In[47]:


N = int(input())


# In[48]:


x = int(-(-math.sqrt(N*2)//1))
y = x*(x+1)//2
diff = y - N
while diff > x:
    diff -= x
    x -= 1
for i in range(1,x+1):
    if i != diff:
        print(i)


# In[ ]:






Measured memory_bytes: 9224
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int cnt[2];

void f(int n){
	while(n%2==0){
		cnt[0]++;
		n/=2;
	}
	while(n%5==0){
		cnt[1]++;
		n/=5;
	}
}

void solve(){  
	int n;
	cin>>n;
	if(n%2==1){
		cout<<0<<endl;
		return;
	}  
	else{
		int ans=0;
		int k=5;
		while(k<=(int)1e18){
			ans+=(n/k)/2;
			k*=5;
 		}
 		cout<<ans<<endl;
	}
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 1000050;
using namespace std;
typedef long long ll;
int p[maxn];
int main()
{
	ll n;
	cin>>n;
		int cnt=0;
	while(n){
		n--;
		p[cnt++]=n%26;
		n/=26;
	}
	for(int i=cnt-1;i>=0;i--){
		char c='a'+p[i];
		cout<<c;
	}
	
	return 0;
}


Measured memory_bytes: 3656
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

oldp = min(a)+min(b)

for _ in range(M):
    x, y, cp = map(int,input().split())
    p = a[x-1]+b[y-1]-cp
    if oldp > p:
        oldp = p

print(oldp)

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    int n;
    cin >> n;
    vi a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];

    ll acnt = 0;
    REP(i, n) {
        if(a[i] < b[i]) {
            auto num = (b[i] - a[i] + 1) / 2;
            acnt += num;
            a[i] += num * 2;
        }
    }

    ll bcnt = 0;
    REP(i, n) {
        if(b[i] < a[i]) {
            auto num = a[i] -b[i];
            bcnt += num;
        }
    }
    cout << (acnt >= bcnt ? "Yes" : "No") << endl;


    return 0;
}

Measured memory_bytes: 384
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        var S = Console.ReadLine();
        int length = (S.Length - 1) % 2 == 1 ? S.Length - 1 : S.Length;
        bool flag;
        while (true)
        {
            flag = true;
            for (int i = 0; i < length / 2; i++)
            {
                if (S[i] != S[length / 2 + i])
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                Console.WriteLine(length - 1);
                return;
            }
            length -= 2;
        }
    }
}

Measured memory_bytes: 13140
import math                                                                                            

n,k = raw_input().split()
s = list(raw_input())


cnt = 0

prev = ''
tmp = ''
ar = []
for i in s:
    if i == '0' and prev !=  1:
        tmp += '0'
        prev = 0
    elif i == '0' and prev == 1:
        prev = 0
        ar.append(tmp)
        tmp = '0'
    elif i == '1' and prev != 0:
        tmp += '1'
        prev = 1
    elif i == '1' and prev == 0:
        prev = 1
        ar.append(tmp)
        tmp = '1'

ar.append(tmp)
k = int(k)


j = 0
cnt = 0
total = 0
m = 0

for i in ar:
    total += len(i)
    if '0' in i:
        cnt += 1
        if cnt == k + 1:                           
            total -= len(ar[j-2*k]) 
            if j >= 2*k + 1:                       
                total -= len(ar[j-2*k-1])
            cnt = k
    m = max(m, total)
    j += 1

print m



Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main(){
  int mas[1401][1401] = {0};
  int H,W;
  int maxv = -(1 << 30);
  cin >> H >> W;
  for(int i = 1;i <= H;i++){
    for(int j = 1;j <= W;j++){
      cin >> mas[i][j];
      mas[i][j] = 1 - mas[i][j];
      if(mas[i][j])mas[i][j] = min(mas[i - 1][j - 1],min(mas[i - 1][j],mas[i][j - 1])) + 1;
      maxv = max(mas[i][j],maxv);
    }
  }
  cout << maxv * maxv << endl;
  return 0;
}
	

Measured memory_bytes: 10788
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD = 998244353;
const ll inf = 1e18;

// return a^b O(log b)
template<typename T>
T mypow(T a, T b){
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}
// return nCk 前処理 O(N) + query あたり O(1)
static bool init = false;
long long res = 1;
const ll M = 2e5 + 10;
vector<ll> frc(M + 1, 1), inv(M + 1, 1);
long long comb(int n, int k){
    if(!init){
        init = true;
        REP(i, M){
            frc[i + 1] = (frc[i] * (i + 1)) % MOD;
            inv[i + 1] = mypow(frc[i + 1], MOD - 2);
        }
    }
    if (k < 0 || n < k) return 0;
    res = (((frc[n] * inv[k]) % MOD) * inv[n - k]) % MOD;
    return res;
}

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, m, k;
    cin >> n >> m >> k;
    ll res = 0;
    REP(x, k + 1) {
        ll mem = ((m * comb(n - 1, x)) % MOD) * mypow(m - 1, n - 1 - x) % MOD;
        res += mem;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6284
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }


bool visited[52];
int N,M,a,b;
bool edge[52][52];


void dfs(int v){
    visited[v] = true;
    Rep(i,N){
        if (edge[v][i] && !visited[i]){
            dfs(i);
        }
    }
}

int main(){
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    K--;

    rep(i,N){
        if (i==K) cout << tolower(S[i],std::locale::classic());
        else cout << S[i];
    }
    cout << "" << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
D = list(map(int, input().split()))

D_list = [0] * (12 + 1)
for d in D:
  D_list[d] += 1
#print(D_list)
  
for d in D_list:
  if d >= 3:
    print(0)
    exit()    
    
answer = []
for n in range(2 ** 13):
  tmp = [0]
  for j in range(13):
    if D_list[j] == 0:
      continue
    if D_list[j] == 1:
      if (n >> j) & 1:
        tmp.append(j)
      else:
        tmp.append(24 - j)
    if D_list[j] == 2:
      tmp.append(j)
      tmp.append(24 - j)
  tmp.sort()
  tmp.append(tmp[0] + 24)
  #print(tmp)
  res = []
  for i in range(1, len(tmp)):
    res.append(tmp[i] - tmp[i - 1])
  answer.append(min(res))
print(max(answer))

Measured memory_bytes: 42844
#include <iostream>
using namespace std;
int main(){
  int N,x,s,l,t;
  cin >> N;
  int ans=N;
  for(int i=0;i<=N;i++){
    s=0;
    l=i;
 while(l>0){
        t=l%6;
      l=(l-t)/6;
      s+=t;}
  l=N-i;
 while(l>0){
        t=l%9;
      l=(l-t)/9;
        s+=t;}
  if (s<ans){
          ans=s;
        }}
        cout << ans << endl;
        return 0;
      }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    string S;
    cin >> S;
    int N = int(S.length());
    ve<vi> A(N,vi(27,0));
    rep(i,N){
        if(i != 0) A[i] = A[i-1];
        A[i][int(S[i]-'a')]++;
    }
    ll ans = 1;
    rep(i,N) {
        int a = int(S[i]-'a');
        ans += N-i-1-(A[N-1][a]-A[i][a]);
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 30084
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, k = LI()

    def a(n, k):
        if (n//k):
            return a(n//k, k)+str(n % k)
        return str(n % k)
    print(len(a(n, k)))
    return


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38256
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int K, N;
    cin >> K >> N;
    vi a(N);
    REP(i, N) {
        cin >> a[i];
    }
    int diff = K - a[N - 1] + a[0];
    REP(i, N - 1) {
        chmax(diff, a[i + 1] - a[i]);
    }
    cout << K - diff;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 4764
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int[] DP = new int[n+1];
    Arrays.fill(DP,Integer.MAX_VALUE);
    DP[0] = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }

    for(int i=0; i<n-2; i++){
      DP[i+1] = Math.min(DP[i+1],DP[i]+Math.abs(array[i+1]-array[i]));
      DP[i+2] = Math.min(DP[i+2],DP[i]+Math.abs(array[i+2]-array[i]));
    }

    DP[n-1] = Math.min(DP[n-1],DP[n-2]+Math.abs(array[n-1]-array[n-2]));

    System.out.println(DP[n-1]);


  }
}

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

int main(){
  int n,k;
  cin >> n >> k;
  	vector<long> arr(n);
  vector<long> dp(n,0);
  for(int i = 0; i < n; ++i)cin >> arr[i];
  dp[0] = 0;
  for(int i = 1; i < n; ++i){
  	dp[i] = LLONG_MAX;
    for(int j = 1; j <= k; ++j){
    	if(i < j)break;
      	dp[i] = min(abs(arr[i]-arr[i-j])+dp[i-j],dp[i]);
    }
  }
  cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
import sys


if __name__ == '__main__':
    D, G = map(int, input().split())
    p = ['-1'] * D
    c = ['-1'] * D
    for i in range(D):
        p[i], c[i] = map(int, input().split())

    answer = sys.maxsize
    for i in range(pow(2, D)):
        bonus_flags = format(i, "b").zfill(D)

        score = 0
        count = 0
        remain = []
        for index, bonus_flag in enumerate(bonus_flags):
            if bonus_flag == '1':
                score += (index + 1) * 100 * p[index] + c[index]
                count += p[index]
            else:
                remain.append(index)
        if score < G:
            R = G - score
            j = remain[-1]

            if (p[j] - 1) * (j+1) * 100 < R:
                continue
            count += -(-R//(100*(j+1)))
        answer = min(answer, count)

    print(answer)

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second


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

  int a,b,c;
  cin >> a >> b >> c;
  cout <<(a==b && b==c? "Yes": "No") << endl;

  return 0;
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
 
down=[0]*(n+1)
up=[0]*(n+1)
up[0]=n
ans=0 if k>1 else n+1
for i in range(1,n+1):
    down[i]=down[i-1]+i
    up[i]=up[i-1]+(n-i)
    if i>=k-1:
        ans+=up[i]-down[i]+1
print(ans%(10**9+7))

Measured memory_bytes: 67792
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
sa = []
for i in range(m - 1):
    sa.append(x[i + 1] - x[i])
sa.sort()
if n >= m:
    print(0)
else:
    print(sum(sa[:(m-n)]))

Measured memory_bytes: 13960
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


struct Corr{
    int pos;
    int w;
};

vi weight(101010, -1);
vi ispassed(101010,false);

bool dfs(Corr c, vector<vector<Corr>> &v){
    int res=1;
    rep(i,v[c.pos].size()){
        int nextPos=v[c.pos][i].pos;
        int nextW=c.w+v[c.pos][i].w;
        if(weight[nextPos]!=-1){
            if(nextW!=weight[nextPos])res=0;
        }
        if(ispassed[nextPos])continue;
        ispassed[nextPos]=1;
        weight[nextPos]=nextW;
        Corr next={nextPos, nextW};
        res*=dfs(next, v);
    }
    return res;
}

int main() {
    
    int n,m;
    cin>>n>>m;
    vector<vector<Corr>> v(n);
    rep(i,m){
        int l,r,d;
        cin>>l>>r>>d;
        l--;r--;
        Corr c={r,d};
        v[l].pb(c);
        c={l,-d};
        v[r].pb(c);
    }
    
    bool ans=1;
    rep(i,n){
        if(ispassed[i])continue;
        Corr c={i,0};
        weight[i]=0;
        ans*=dfs(c,v);
    }
    Yn(ans);
    // rep(i,10)fin(weight[i]);
}



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

int main() {
  char str[1001], temp[1001], p[1001], cmd[10];
  int q, a, b;

  scanf("%s", str);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", cmd, &a, &b);
    if (strcmp(cmd, "print") == 0) {
      for (int j = a; j <= b; j++) {
        printf("%c", str[j]);
      }
      printf("\n");      
    } else if (strcmp(cmd, "reverse") == 0) {
      strcpy(temp, str);
      for (int j = 0; j < b-a+1; j++) {
        str[a+j] = temp[b-j];
      }
    } else {
      scanf("%s", p);
      for (int j = 0; j < strlen(p); j++) {
        str[a+j] = p[j];
      }      
    }
  }  

  return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std ;
	#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#define lli long long int
	#define ulli unsigned long long int
	#define ff first
	#define ss second
	#define mp make_pair
	#define pb push_back
	#define pf pop_front()
	#define lb lower_bound
	#define ub upper_bound
	#define bs binary_search
	#define rep(i,a,b) for(lli i=a;i<b;i++)
	#define repe(i,a,b) for(lli i=a;i<=b;i++)
	#define all(v) v.begin(), v.end()
	#define mod 1000000007
	#define inf 100000000000000000
	#define lld long double
	#define pll pair<long long int,long long int>
	#define pii pair<int,int>
	#define vll vector<lli>
	#define vii vector<int>
	#define endl '\n'
	#define pie  acosl(-1.0);
	#define setp(k, x) fixed << setprecision(k) << (x)
	#define deb(x) cerr << #x << ": " << x << " " << endl;
	#define debug(x) cout << "m here-" <<#x<<" ..."<<"\n";
	#define printa(a,n) for(lli i=0;i<n;i++) cout<<a[i]<<" "; cout<<"\n";
  #define printv(a) for(lli i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<"\n";
	bool sortcol( const vector<lli>& v1, const vector<lli>& v2 ) //sort on basis of column //use- sort(vect.begin(), vect.end(),sortcol);
      { return v1[1] < v2[1]; }//[] o based indexing in column
	bool sortpair(const pair<lli, lli> &a, const pair<lli, lli> &b)
			{return a.second < b.second;}
	struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

//////////////////////////////////////////////////////////////////////////////////////////////
void solve();
//////////////////////////////////////////////////////////////////////////////////////////////



int main ()
{
	// fastio
 	// lli  t;
 	// cin>>t;
 	// while(t--)
 	{
	solve();

 	}
}
///////////////////////////////////////////
void solve()
{
	lli n,i,d,a,b,c,j,k,m;
  cin>>n>>m;
  string s[1001];
  for(i=0;i<n;i++)
  {
    s[i]="";
  }
  for(i=0;i<n;i++)
  {
    cin>>s[i];
  }
  static lli dp[1002][1002]={0};
  dp[0][0]=1;
  for(i=0;i<m;i++)
  {
    if(s[0][i]=='.')
      dp[0][i]=1;
    else
        break;
  }
  for(i=0;i<n;i++)
  {
    if(s[i][0]=='.')
      dp[i][0]=1;
    else
        break;
  }

  for(i=1;i<n;i++)
  {
    for(j=1;j<m;j++)
    {
        if(s[i][j]=='#')
          dp[i][j]=0;
        else
        {

           dp[i][j]= (dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }
    }
  }
  //
  // for(i=0;i<n;i++)
  // {
  //   for(j=0;j<m;j++)
  //   {
  //     cout<<dp[i][j]<<" ";
  //   }
  // cout<<"\n";
  // }

  cout<<dp[n-1][m-1]<<"\n";


}


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a;
  int f=0,s=0;
  for(int i=0;i<3;i++){
    cin>>a;
    if(a==5){
      f++;
    }
    else if(a==7){
      s++;
    }
  }
  if(f==2 && s==1){
    cout<<"YES"<<"\n";
  }
  else{
    cout<<"NO"<<"\n";
  }
  return 0;
}

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

struct ST{
    int num,p,y,pnum;
};

bool comp1(ST a, ST b){
    return a.num < b.num;
}

bool comp2(ST a, ST b){
    if(a.p == b.p) return a.y < b.y;
    else return a.p < b.p;
}


void solve(){
    int n, m;
    cin >> n >> m;

    vector<ST> data(m);

    for(int i = 0; i < m; ++i){
        data[i].num = i;
        cin >> data[i].p >> data[i].y;
    }

    sort(data.begin(),data.end(),comp2);

    int c = 1;

    for(int i = 0; i < m; ++i){
        data[i].pnum = c;
        c++;
        if(i != m - 1 && data[i].p != data[i + 1].p){
            c = 1;
        }
    }

    sort(data.begin(),data.end(),comp1);

    for(int i = 0; i < m; ++i){
        cout << setw(6) << setfill('0') << data[i].p << setw(6) << setfill('0') << data[i].pnum << endl;
    }

}

int main(){
    solve();

    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 998244353;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 ll N = 2e5 + 3 ;
 vector<ll> a(N,0),b(N,0) ;
 ll p = 0 ;
 vector<ll> visited(N,0) ;
 ll dfs(ll n)
 {
     if( !visited[n] ){
          visited[n] = 1 ;
          ll ret = dfs(a[n]) + 1 ;
          b[n] = ret ;
          return ret ;
        }
     else
     {
         p = n;
         return 0 ;
     }
     return 0 ;
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  //cin>>t ;
  while(t--)
  {
    ll k,n;
    cin>>k>>n;
    for( ll i =0 ; i<k ; i++ ) { ll x ; cin>>x ; a[i+1]=x ; }
    ll ans = dfs(1ll) ;
    ll y = b[1] - b[p] ;
    if( n<y ){
        ans = 1;
        for( ll  i = 0 ; i<n ; i++ )
            ans = a[ans];
        cout<<ans<<endl;
        return 0;
    }
    n-=y;
    if( n%b[p] == 0  ){
        cout<<p<<endl;
    }
    else
    {
        n = n%b[p];
        ans = p ;
        for( ll i = 0 ; i<n ; i++ )
        {
            ans =  a[ans] ;
        }
        cout<<ans<<endl;

    }

  }
  return 0;
  }


Measured memory_bytes: 11008
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int map[15][15],n,i,j,k,a,b,c,o,ans[15],zans;
int main()
{
	while(1)
	{
		o=0;
		scanf("%d",&n);
		if(n==0)
			return 0;
		for(i=0;i<=10;i++)
		{
			for(j=0;j<=10;j++)
				map[i][j]=2147483647;
		}
		for(i=1;i<=n;i++)
		{
			scanf("%d %d %d",&a,&b,&c);
			o=max(a,o);
			o=max(b,o);
			map[a][b]=min(c,map[a][b]);
			map[b][a]=min(c,map[b][a]);
		}
		for(k=0;k<=o;k++)
		{
			for(i=0;i<=o;i++)
			{
				for(j=0;j<=o;j++)
				{
					if(map[i][k]!=2147483647&&map[k][j]!=2147483647)
					map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
				}
			}
		}
		zans=0;
		for(i=0;i<=o;i++)
		{
			ans[i]=0;
			for(j=0;j<=o;j++)
			{
				if(i!=j)
				ans[i]=ans[i]+map[i][j];
			}
			if(ans[i]<ans[zans])
				zans=i;
		}
		printf("%d %d\n",zans,ans[zans]);
	}
}

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define precision(x) fixed << setprecision(x)
#define all(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000

int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double PI = acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
    int a, b, ans;
    string op;
    while(1){
        cin >> a >> op >> b;
        if(op == "?") break;
        if(op == "+") ans = a + b;
        else if(op == "-") ans = a - b;
        else if(op == "*") ans = a * b;
        else ans = a / b;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3160
#include <stdio.h>
#include <stdlib.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a < b) {
		if (a < c)
			if (b < c)
				printf("%d %d %d\n", a, b, c);
			else
				printf("%d %d %d\n", a, c, b);
		else
			printf("%d %d %d\n", c, a, b);
	}
	else {
		if (a < c)
			printf("%d %d %d\n", b, a, c);
		else
			if (b < c)
				printf("%d %d %d\n", b, c, a);
			else
				printf("%d %d %d\n", c, b, a);
	}
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 59;
int i,j,k,cnt,n,m,x,y,dx[] = {-1,-1,-1,0,1,1,1,0},dy[] = {-1,0,1,1,1,0,-1,-1};
char a[N][N];
int main()
{
   std::ios_base::sync_with_stdio(false); cin.tie(NULL);
   cin>>n>>m;
   rep(i,0,n) rep(j,0,m){
     cin>>a[i][j];
   }
   rep(i,0,n){
      rep(j,0,m){
        if(a[i][j] == '#') cout<<"#";
        else
        {
           cnt = 0;
           rep(k,0,8){
             x = i + dx[k]; y = j + dy[k];
             if(x>=0 and y>=0 and x<n and y < m and a[x][y] == '#') cnt++;
           }
           cout<<cnt;
        }
      }
      cout<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;


int main(){
  double t,x;
  cin >> t >> x;
  cout << t/x << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(){
	int n,k,i,j=0;

	scanf("%d %d",&n,&k);

	int h[n];
	for(i=0; i<n; i++){
		scanf("%d",&h[i]);
		if(h[i]>=k){
			j++;
		}
	}

	printf("%d",j);
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>> n;
    while ( n!=0) {
        int x =  n%10;
        if ( x == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n = n/10;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],cst[100001];
void khel()
{
cst[0]=0;
cst[1]=abs(a[1]-a[0]);
for(int j=2;j<n;j++)
{cst[j]=min(cst[j-1]+abs(a[j]-a[j-1]),cst[j-2]+abs(a[j]-a[j-2]));
}
}





int main()
{
	cin>>n;
	int i;
	for(i=0;i<n;i++)
		cin>>a[i];
	khel();
	cout<<cst[n-1];
	return 0;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 88
ll n = 88, f[N], g[N][N];

int main(){
	mset(f, -1); mset(g, -1);
	f[0] = 0; f[1] = 1;
	rep(i, N-2){
		f[i+2] = f[i]+f[i+1];
		if(f[i+2]>1e18){
			f[i+2] = -1;
			break;
		}
	}
	//rep(i, n) cerr<<f[i]<<endl;
	rep(i, n){
		g[i][0] = 0; g[i][1] = 1;
		rep(j, N-2){
			g[i][j+2] = g[i][j+1]+g[i][j];
			if(j==i) g[i][j+2] += g[i][j+1];
			if(g[i][j+2]>1e18){
				g[i][j+2] = -1;
				break;
			}
		}
	}
	memcpy(g[0], f, sizeof(f));
	ll q;
	cin>>q;
	rep(_, q){
		ll x, y;
		cin>>x>>y;
		if(x>y) swap(x, y);
		int p = 2;
		while(f[p+1]>0&&x>=f[p]&&y>=f[p+1]) p++;
		p--;
		ll res = 0;
		rep(i, p-1){
			if(g[i][p+1]<0) continue;
			if(g[i][p+1]>y||g[i][p]>x) continue;
			if(x>=g[i][p+1]) res++;
			(res+=(y-g[i][p+1])/g[i][p]+1)%=mod;
			//cerr<<i<<" "<<g[i][p]<<" "<<g[i][p+1]<<" "<<res<<endl;
		}
		if(p-1<=1){
			p = 2;
			res = x%mod*(y%mod)%mod;
		}
		cout<<p-1<<" "<<res<<endl;
	}
	return 0;
}


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

int a[2*100000];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];
  
  int now = 1;
  int cnt = 0;
  while(now!=2) {
    ++cnt;
    if(cnt > N) {
      cout << -1 << endl;
      return 0;
    }
    now = a[now-1];
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int H,W;  
vector<string>fi;
int Left[2100][2100],Right[2100][2100],Up[2100][2100],Down[2100][2100];
int main(){
  cin>>H>>W;
  fi.resize(H);
  for (int i=0;i<H;++i){
    cin>>fi[i];
  }
  for (int i=0;i<H;++i){
    int cur=0;
    for (int j=0;j<W;++j){
      if(fi[i][j]=='#'){
        cur=0;
      }
      else ++cur;
      Left[i][j]=cur;
    }
  }
  for (int i=0;i<H;++i){
    int cur=0;
    for (int j=W-1;j>=0;--j){
      if(fi[i][j]=='#'){
        cur=0;
      }
      else ++cur;
      Right[i][j]=cur;
    }
  }
  for (int j=0;j<W;++j){
    int cur=0;
    for (int i=0;i<H;++i){
      if(fi[i][j]=='#'){
        cur=0;
      }
      else ++cur;
      Down[i][j]=cur;
    }
  }
  for (int j=0;j<W;++j){
    int cur=0;
    for (int i=H-1;i>=0;--i){
      if(fi[i][j]=='#'){
        cur=0;
      }
      else ++cur;
      Up[i][j]=cur;
    }
  }
  
  int res=0;
  for (int i=0;i<H;++i){
    for (int j=0;j<W;++j){
      if(fi[i][j]=='#')continue;
      res=max(res,Left[i][j]+Right[i][j]+Down[i][j]+Up[i][j]-3);
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 72448
// music - INF    	
#include <bits/stdc++.h>

#define F first
#define S second 

#define farth(i, s) for (__typeof (s.begin ()) i = s.begin (); i != s.end (); ++i)
#define make make_pair

#define rall(x) x.rbegin (), x.rend () 
#define lower lower_bound

#define upper upper_bound
#define bp pop_back

#define pb push_back
#define sz(x) x.size()

#define pf push_front
#define bit __builtin_popcount

#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin (), x.end ()

#define TIME clock () * 1.0 / CLOCKS_PER_SEC
#define lcm (n, m) (((a) * 1ll * (b)) / __gcd (n, m))

#define int long long 
#define MAGARADZHA() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef vector < pair < ll, ll > > vpll;
typedef pair < pair < ll, ll >, pair < ll, ll > > pllll;
typedef vector < ll > vl;                                                         

typedef vector < string > vs;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll; 
typedef map <ll, ll> mll;
typedef set <ll> sl;
typedef set < pair < ll, ll > > spll;

const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 8;
const ll INF = (ll)1e18;
const double eps = (double)1e-9;

int n, k, d[N];
bool ok, used[N];

void Solutions() {
	MAGARADZHA();
	cin >> n >> k;
	for (int i = 1; i <= k; ++i) {
		cin >> d[i];
		used[d[i]] = 1;
	}
	for (int i = 1; i <= 100000; ++i) {
		int x = i;
		ok = 0;
		if (n <= i) {
			while (x) {
				if (used[x % 10] == 1) ok = 1;
				x /= 10;
			}
			if (ok == 0) {
				cout << i;
				return;
			}
		}
	}  


}
main () {
//2	freopen("l.txt", "r", stdin); 	
//	freopen("r.txt", "w", stdout);
	Solutions();      
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC042C{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var K = sr.Next<int>();
            var D = sr.Next<int>(K);

            for(var i = N; i < 100000; i++){
                if(!i.ToString().ToList().Exists(c => D.Contains(c - '0'))){
                    Console.WriteLine(i);
                    return;
                }
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 7000
#include "bits/stdc++.h"
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long LL;
#define REP(i,N) for (int i=0; i<N; i++)

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if ((10*g + b) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
        int n,k,t,t_min,min,max;
        scanf("%d %d",&n,&k);
        int x[n];
        for (int i=0;i<n;i++) scanf(" %d", x+i);
        for (int i=0;i<=n-k;i++) {
                min = x[i];
                max = x[i+k-1];
                if (min>=0)             t = max;
                else if (max<=0)        t = -min;
                else if (min+max>=0)    t = -min*2 + max;
                else if (min+max<=0)    t = -min + max*2;
                if (i==0)               t_min = t;
                else if (t<=t_min)      t_min = t;
        }
        printf("%d\n",t_min);
        return 0;
}

Measured memory_bytes: 512
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return

n,m = map(int,raw_input().split())

arr = map(int,raw_input().split())

uf = UnionFind(n)

for i in range(m):
    f,t = map(int,raw_input().split())
    f -= 1
    t -= 1
    uf.union(f,t)

ans = 0
for i in range(n):
    if uf.find(i) == uf.find(arr[i]-1):
        ans += 1

print ans



Measured memory_bytes: 12608