akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int N,M,Q;
    cin>>N>>M>>Q;
    vi res(N+M-1,1);
    rep(i,0,N)res[i]=0;
    vi a(Q),b(Q),c(Q),d(Q);
    rep(i,0,Q)cin>>a[i]>>b[i]>>c[i]>>d[i];
    ll ans=0;
    do{
        vi A(N+1,1);
        int cnt=0;
        int p=1;
        rep(i,0,N+M-1){
            if(res[i]==0)A[p++]+=cnt;
            else cnt++;
        }
        ll res=0;
        rep(i,0,Q){
            if(A[b[i]]-A[a[i]]==c[i])
                res+=d[i];
        }
        chmax(ans,res);
    }while(next_permutation(res.begin(),res.end()));
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const ll MOD = 1000000007;
ll power(ll x,ll y){ll R=1;x%=MOD;while(y>0){if(y&1)R=(R*x)%MOD;y=y>>1,x=(x*x)%MOD;}return R;}

int main(){
    int t;
    cin>>t;
  if(t) cout<<0<<endl;
   else cout<<1<<endl;
}
 

Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main()
{
    vector<int> v;
    set<int> s;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int t;
         cin >> t;
         v.push_back(t);
         s.insert(t);
    }

    int diff = v.size() - s.size();
    int ans = s.size();
    if(diff % 2 != 0)
    {
        --ans;
    }

    cout << ans << endl;

}

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

int judgement(double, int);
int main(){
    int n, m;
    cin >> n >> m;
    int *heap;
    heap = new int[n];
    int sm = 0;
    for(int i=0; i<n; i++){
        cin >> heap[i];
        sm += heap[i];
    }

    int k = sm / (4 * m);
    int kk = sm % (4 * m);
    int ct = 0;
    if(kk == 0){ //基準票数kが整数値
        for(int i=0; i<n;i++){
            if(k <= heap[i]) ct++;
        if(ct >= m) break;
        }
        
    }else{  //基準票数kが小数の切り捨て値
        for(int i=0; i<n; i++){
            if(k < heap[i]){
                ct++;
            }
            if(ct >= m) break;
        }
    }
    if(ct >= m) cout << "Yes" << endl;
    else cout << "No" <<endl;

    delete[] heap;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

void _main() {
  int N, K;
  cin >> N >> K;

  ll ans = K * pow(K-1, N-1);
  cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;

public class Main{
	int [] work;
	int n;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			work = new int[n];
			work[0] = n;
			dfs(0, n);
		}
	}

	private void dfs(int deep, int min) {
		//print
		if(work[deep] <= min){
			System.out.print(work[0]);
			for(int i = 1; i < n; i++){
				if(work[i] == 0) continue;
				System.out.print(" " + work[i]);
			}
			System.out.println();
		}
		if(deep == n) return;
		
		for(int i = work[deep]-1; i >= 1; i--){
			if(min < i) continue;
			work[deep + 1] = work[deep] - i;
			work[deep] = i;
			dfs(deep + 1, Math.min(i, min));
			work[deep] = work[deep + 1] + i;
			work[deep + 1] = 0;
		}
		
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 38300
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
  int n;
  cin >> n;
  ll a[n+1]={};
  for(int i=1;i<=n;i++){
    cin >> a[i];
    a[i] += a[i-1];
  }
  sort(a,a+n+1);
  ll ans = 0, cnt = 0, prev = -1;
  for(int i = 0; i <= n; i++){
    if(a[i] != prev){
      if(cnt >= 2){
        ans += cnt * (cnt - 1) / 2;
      }
      cnt = 1;
      prev = a[i];
    }else{
      cnt++;
      if(i == n){
        ans += cnt * (cnt - 1) / 2;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const int e = -1;
vector<long long> ten;
vector<long long> sum;
void precalc(){
  ten = vector<long long>(300000);
  ten[0] = 1;
  for (int i = 1; i < 300000; i++){
    ten[i] = ten[i - 1] * 10 % MOD;
  }
  sum = vector<long long>(300001);
  sum[0] = 0;
  for (int i = 0; i < 300000; i++){
    sum[i + 1] = (sum[i] + ten[i]) % MOD;
  }
};
template <typename T>
struct range_update_range_sum{
	int N;
	vector<T> ST;
	vector<T> lazy;
	range_update_range_sum(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		lazy = vector<T>(N * 2 - 1, e);
	}
	void eval(int i, int l, int r){
		if (lazy[i] != e){
			if (i < N - 1){
				lazy[i * 2 + 1] = lazy[i];
				lazy[i * 2 + 2] = lazy[i];
			}
			ST[i] = lazy[i] * (sum[r] + MOD - sum[l]) % MOD;
//cout << "l = " << l << ", r = " << r << ", lazy = " << lazy[i] << ", ST = " << ST[i] << endl;
          	lazy[i] = e;
		}
	}
	void range_update(int L, int R, T x, int i, int l, int r){
		eval(i, l, r);
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			lazy[i] = x;
			eval(i, l, r);
		} else {
			int m = (l + r) / 2;
			range_update(L, R, x, i * 2 + 1, l, m);
			range_update(L, R, x, i * 2 + 2, m, r);
			ST[i] = (ST[i * 2 + 1] + ST[i * 2 + 2]) % MOD;
		}
	}
	void range_update(int L, int R, T x){
		range_update(L, R, x, 0, 0, N);
	}
	T range_sum(int L, int R, int i, int l, int r){
		eval(i, l, r);
		if (R <= l || r <= L){
			return 0;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return (range_sum(L, R, i * 2 + 1, l, m) + range_sum(L, R, i * 2 + 2, m, r)) % MOD;
		}
	}
	T range_sum(int L, int R){
		return range_sum(L, R, 0, 0, N);
	}
};
int main(){
  precalc();
  int N, Q;
  cin >> N >> Q;
  range_update_range_sum<long long> ST(N);
  ST.range_update(0, N, 1);
  for (int i = 0; i < Q; i++){
    int L, R, D;
    cin >> L >> R >> D;
    ST.range_update(N - R, N - L + 1, D);
    cout << ST.range_sum(0, N) << endl;
  }
}

Measured memory_bytes: 16204
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = 0; i < m; ++i) {
    int p, x;
    cin >> p >> x;
    --p;
    if (a[p] != -1 && a[p] != x) {
      cout << "-1\n";
      return;
    }
    a[p] = x;
  }
  if (a[0] == 0 && a.size() > 1) {
    cout << "-1\n";
    return;
  }
  char allow_zero = n == 1;
  for (int i = 0; i < n; ++i) {
    if (a[i] == -1) {
      a[i] = !allow_zero;
    }
    allow_zero = 1;
  }
  for (int x : a) {
    cout << x;
  }
  cout << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n);
    map<int,int,greater<int>> map;
    rep(i,n){
        cin >> a[i];
        map[a[i]]+=2;
    }
    sort(all(a),greater<int>());
    int res=0;
    int max=a[0];

    for(auto m:map){
        m.S*=2;
    }
    //cout<<max<<endl;
    map[max]/=2;


    

    //for(auto m:map) cout<<m.F<<' '<<m.S<<endl;
    
    res+=max*(map[max]-1);
    int rest=n-map[max];

    //cout<<rest<<' '<<res<<endl;
    for(auto &m:map){
        while(rest>0 && m.S>0){
            //cout<<m.F<<endl;
            res+=m.F;
            m.S--;
            rest--;
        }
    }
    cout<<res<<endl;

}

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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 1e5+5;

ll n , m , a[N] , ans;
map<ll,ll> cnt;

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

    cin >> n >> m;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        a[i] %= m;
        a[i] += a[i-1];
        a[i] %= m;

        ans += cnt[a[i]];
        if (!a[i]) ans++;


        cnt[a[i]]++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4992
unittest
{
	assert( [ "4 3 2" ].parse.expand.solve == "YES" );
	assert( [ "2 3 4" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	return ( ( a * 100 + b * 10 + c ) % 4 == 0 ) ? "YES" : "NO";
}


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

int main() {
  long long H,N,X,SUM=0;
  cin>>H>>N;
  rep(i,N){cin>>X;SUM+=X;}
  if(H>SUM){cout<<"No"<<endl;}else{cout<<"Yes"<<endl;}
}


Measured memory_bytes: 3616
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    hand = ['r', 's', 'p']
    score = [p, r, s]
    dic_score = dict(zip(hand, score))
    win = [0] * n
    ans = 0
    for i in range(k):
        ans += dic_score[t[i]]
        win[i] = 1
    for i in range(k, n):
        if t[i] == t[i - k] and win[i - k]:
            continue
        ans += dic_score[t[i]]
        win[i] = 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9868
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;

public class Main {
	public static void main(String[] args) throws IOException, ParseException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		final int AB = Integer.parseInt(str.split(" ")[0]);
		final int BC = Integer.parseInt(str.split(" ")[1]);

		System.out.println(AB * BC / 2);
	}
}


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

int main(void)
{
    char A[11],B[11],C[11];
    
    scanf("%s %s %s", A,B,C);
    
    printf("%s\n", (A[strlen(A)-1]==B[0] && B[strlen(B)-1]==C[0]) ? "YES":"NO");
    
    return 0;
}

Measured memory_bytes: 128
import sys

class Node:
    def __init__(self, id, left, right, degree, depth, type):
        self.id = id
        self.parent = None
        self.sibling = -1
        self.degree = degree
        self.depth = depth
        self.height = 0
        self.type = type
        self.left = left
        self.right = right

    def printInfo(self):
        print "node {0.id}: parent = {0.parent.id}, sibling = {0.sibling}, degree = {0.degree}, depth = {0.depth}, height = {0.height}, {0.type}".format(self)

def buildTree(id, nodeList, depth):
    leftId, rightId = nodeList[id][0], nodeList[id][1]
    if leftId == -1 and rightId == -1:
        dummy = Node(-1, None, None, 0, 0, "")
        return Node(id, dummy, dummy, 0, depth, "leaf")
    degree = 0
    if leftId == -1:
        left = Node(-1, None, None, 0, 0, "")
    else:
        left = buildTree(leftId, nodeList, depth + 1)
        degree += 1
    if rightId == -1:
        right = Node(-1, None, None, 0, 0, "")
    else:
        right = buildTree(rightId, nodeList, depth + 1)
        degree += 1
    node = Node(id, left, right, degree, depth, "internal node")

    node.left.parent = node
    node.left.sibling = node.right.id
    node.right.parent = node
    node.right.sibling = node.left.id
    node.height = max(node.left.height, node.right.height) + 1
    return node

def tree2linear(node, list):
    list[node.id] = node
    if node.left.id != -1:
        tree2linear(node.left, list)
    if node.right.id != -1:
        tree2linear(node.right, list)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    N = int(lines[0])
    del lines[0]

    nodeList = [[]] * N
    sum = N * (N - 1) / 2
    for line in lines:
        line = map(int, line.split())
        id, children = line[0], line[1:]
        nodeList[id] = children
        for child in children:
            if child == -1:
                continue
            sum -= child

    root = buildTree(sum, nodeList, 0)
    root.type = "root"
    root.parent = Node(-1, None, None, 0, 0, "")

    nodeList = [0] * N
    tree2linear(root, nodeList)
    for node in nodeList:
        node.printInfo()

Measured memory_bytes: 6520
from sys import stdin
input = stdin.readline

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

MAX_N = int(1e5+5)

dp = VI(MAX_N, MAX_N)
dp[0] = 0
dp[1] = 1

for i in range(2, MAX_N):
  dp[i] = min(dp[i], dp[i-1]+1)
  for j in range(10):
    six = POW(6, j)
    if six > i:
      break
    else:
      dp[i] = min(dp[i], dp[i-six]+1)

  for j in range(10):
    nine = POW(9, j)
    if nine > i:
      break
    else:
      dp[i] = min(dp[i], dp[i-nine]+1)

N = int(input().rstrip())
print(dp[N])



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

int main() {
    string s, t; cin >> s >> t;
    int flag = 1;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) flag = 0;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int n;
    cin>>n;
    ll mod = 1e9+7;
    ll ans=1;
    for(int i=1;i<=n;i++){
        ans=(ans*i)%mod;
    }
    
    cout<< ans <<endl;
    
}


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

#define loop(i,n) for(int i=0;i<n;i++)
vector<int> v;

int main(){
  int n,m;
  string s;
  while(cin>>n,n){
    cin>>m>>s;
    v.clear();
    s+="XX";
    loop(i,m){
      if(s[i]=='I'){
        v.push_back(0);
        while(s[i+1]=='O'&&s[i+2]=='I'){
          i+=2;
          v.back()++;
        }
      }
    }
    int c=0;
    loop(i,v.size()){
      if(v[i]>=n){
        c+=v[i]-n+1;
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 3932
#include<iostream>
#include<stdio.h>
using namespace std;

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

  if(S.size()>100){
  cout<<"The length of S is over. "<<endl;
  }

  for(int i=0;i<S.size();i++){
    S[i]='x';
  }

   cout<<S<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long double w,h,x,y;
    std::cin >> w >>h >>x >>y;
    long double men=w*h/2;
    std::cout << men <<" ";
    if(w/2==x && h/2==y){
        std::cout << 1 << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }
}


Measured memory_bytes: 256
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {n:usize,s:[String;n]}
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for c in s {
        if c == "AC" {
            ac += 1;
        } else if c == "WA" {
            wa += 1;
        } else if c == "TLE" {
            tle += 1;
        } else {
            re += 1;
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


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

int main() {
 int n, k;
  cin >> n >> k;
  
  long long sum = 0;
  vector<int> arr(n);
  for(int i=0; i<n; i++)
    cin >> arr[i];
  
  sort(arr.rbegin(), arr.rend());
  
  for(int i=k; i<n; i++)
    sum += arr[i];
  
  	cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 30;
const int inf = 1<<20;

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int rev[]={1,0,3,2};
bool edge[N][N][4];

int cost[N][N];
int bfs(int r,int c,int sy,int sx){
  rep(i,r)rep(j,c)cost[i][j]=inf;
  cost[sy][sx]=0;
  queue<int> Q;
  Q.push(sy*c+sx);
  while(!Q.empty()){
    int y=Q.front()/c,x=Q.front()%c;Q.pop();
    if (y == r-1 && x == c-1)return cost[r-1][c-1];
    rep(i,4){
      int nex=x+dx[i],ney=y+dy[i];
      if (nex == -1 || ney == -1 || nex == c || ney == r || !edge[y][x][i] || cost[ney][nex] != inf)continue;
      cost[ney][nex] = cost[y][x] + 1;
      Q.push(ney*c+nex);
    }
  }
  return inf;
}

bool vis[N][N];

int opt[N][N];
int solve(int r,int c){
  rep(i,r)rep(j,c)opt[i][j]=inf,vis[i][j]=false;
  opt[r-1][c-1]=0;
  while(true){
    bool fg=false;
    rep(i,r){
      rep(j,c){
	int tmp = opt[i][j];
	rep(k,4){
	  int nex=j+dx[k],ney=i+dy[k];
	  if (ney == -1 || nex == -1 || ney == r || nex == c || !edge[i][j][k] || opt[ney][nex] >= opt[i][j])continue;
	  edge[i][j][k]=false;
	  int a=bfs(r,c,i,j);
	  edge[i][j][k]=true;
	  //cout << ney <<" " << nex <<" " << 1+opt[ney][nex] <<" " << a << endl;
	  if (i == 0 && j == 1){
	    //cout <<i <<" " << j <<" " << ney <<" " << nex <<" " <<  k <<" " << 1+opt[ney][nex] <<" "<< a << endl;
	  }
	  opt[i][j]=min(opt[i][j],max(1+opt[ney][nex],a));
	}
	//cout << i <<" " << j <<" " << opt[i][j] <<" " <<  endl;
	if (opt[i][j] != tmp)fg=true;
      }
    }
    if (!fg)break;
  }
  rep(i,r){
    //rep(j,c)cout << opt[i][j] <<" " ;cout << endl;
  }
  return opt[0][0]==inf?-1:opt[0][0];
}

main(){
  int r,c;
  while(cin>>r>>c && r){
    rep(i,r)rep(j,c)rep(k,4)edge[i][j][k]=true;
    rep(i,r){
      rep(j,c-1){
	cin>>edge[i][j][0];edge[i][j][0]=1-edge[i][j][0];edge[i][j+1][1]=edge[i][j][0];
      }
      if (i == r-1)break;
      rep(j,c){
	cin>>edge[i][j][2];edge[i][j][2]=1-edge[i][j][2];edge[i+1][j][3]=edge[i][j][2];
      }
    }
    


    cout << solve(r,c) << endl;
  }
}

Measured memory_bytes: 924
#include <cstdio>

using namespace std;

int main() {
    int a, b, c, n, ans = 0;
    scanf("%d%d%d%d", &a, &b, &c, &n);
    for (int i = 0; i <= n / a; ++i) for (int j = 0; j <= (n - a * i) / b; ++j) if ((n - a * i - b * j) % c == 0) ++ans;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}
vector<vc>a;
vc vis;
void dfs(ll node)
{
    if(vis[node])
        return;
    vis[node]++;
    for(auto child:a[node])
    {
        if(!vis[child])
        {
           dfs(child);
        }
    }
    //return cnt;
}
int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	//Read the qstn. properlyyyyy!!!
	ll t,n,i,j,m,k,c,f;
	cin>>n>>m;
	a.reserve(n+1);
	vis.reserve(n+1);ll u,v;
	unordered_map<ll,ll>mp;
	for(i=1;i<=m;i++)
	{
	    cin>>u>>v;
	    a[u].push_back(v);
	    a[v].push_back(u);
	    mp[u]++;mp[v]++;
	}
	ll cnt1=0,cnt2=0;
	for(i=1;i<=n;i++)
	{
	    if(!vis[i]&&mp[i])
	    {
	        dfs(i);
	        cnt1++;
	    }
	    else if(!mp[i])cnt2++;
	}
	cout<<cnt1-1+cnt2;;
	return 0;
}


Measured memory_bytes: 14692
N = int(input())
p = list(map(int, input().split()))
cnt = 2

for i in range(N):
    #print(p[i])
    if p[i] != i + 1:
        cnt -= 1
        #print("del cnt")
if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		if(a.equals(b)) {
			System.out.println("H");
		}else {
			System.out.println("D");
		}
	}
}


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

char getC( char prev_c, int a, int b, int c, string s ){
	if( s[a] == s[b] && s[b] == s[c] && s[a] != 's' )
		return s[a];
	return prev_c;
}

int main()
{
	string s;
	while( cin >> s ){
		char c = 'd';
		for( int i = 0; i < 3; i++ )
			c = getC(c, i, i+3, i+6, s);
		for( int i = 0; i < 9; i += 3 )
			c = getC(c, i, i+1, i+2, s);
		c = getC(c, 0, 4, 8, s);
		c = getC(c, 2, 4, 6, s);
		cout << c << endl;
	}
	return 0;
}

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

int main() {
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    for (int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
    }
    int ans = 100000;
    for (int pwr = 0; pwr <= (1 << d) - 1; pwr++) {
        int choice = pwr;
        vector<pair<int, int>> probs;
        int sum = 0;
        int cand = 0;
        for (int i = 0; i < d; i++) {
            if (choice & 1) {
                sum += c[i];
                sum += p[i] * (i + 1) * 100;
                cand += p[i];
            } else {
                probs.push_back(make_pair((i + 1) * 100, p[i]));
            }
            choice >>= 1;
        }
        sort(probs.rbegin(), probs.rend());
        for (auto prob : probs) {
            if (sum >= g) break;
            for (int i = 0; i < prob.second; i++) {
                if (sum >= g) break;
                sum += prob.first;
                cand++;
            }
        }
        if (sum >= g) ans = min(ans, cand);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int flag=0,a[10][10],i,j,k,n,x[10],y[10],b[10];
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d %d\n",&x[i],&y[i]);
  }
  for(i=0;i<8;i++){
    b[i]=i;
  }
  do{
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
        a[i][j]=0;
      }
    }
    for(i=0;i<8;i++){
      a[i][b[i]]=1;
    }
    k=0;
    for(i=0;i<n;i++){
      if(a[x[i]][y[i]]==0){
        k=1;
      }
    }
    if(k==1){
      continue;
    }
    for(i=0;i<8;i++){
      j=i-1,k=b[i]-1;
      while(j>=0 && j<=7 && k>=0 && k<=7){
        if(a[j][k]==1){
          flag=1;
        }
        j--,k--;
      }
    }
    for(i=0;i<8;i++){
      j=i+1,k=b[i]-1;
      while(j>=0 && j<=7 && k>=0 && k<=7){
        if(a[j][k]==1){
          flag=1;
        }
        j++,k--;
      }
    }
    for(i=0;i<8;i++){
      j=i-1,k=b[i]+1;
      while(j>=0 && j<=7 && k>=0 && k<=7){
        if(a[j][k]==1){
          flag=1;
        }
        j--,k++;
      }
    }
    for(i=0;i<8;i++){
      j=i+1,k=b[i]+1;
      while(j>=0 && j<=7 && k>=0 && k<=7){
        if(a[j][k]==1){
          flag=1;
        }
        j++,k++;
      }
    }
    if(flag==0){
      break;
    }
    flag=0;
  }while(next_permutation(b,b+8));
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(a[i][j]==0){
        printf(".");
      }
      else{
        printf("Q");
      }
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 3156
from collections import deque

n = int(input())
words = deque()
for i in range(n):
    words.append(input())

unique = {}
count = 0

for word in words:
    sorted_word = sorted(word)
    if ''.join(sorted_word) in unique:
        count += unique[''.join(sorted_word)]
        unique[''.join(sorted_word)] += 1
    else:
        unique[''.join(sorted_word)] = 1

print(count)

Measured memory_bytes: 71896
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0

ans += A[0]

for i in range(1, N-1):
    if i % 2 != 0:
        idx = int(i // 2 + 1)
    else:
        idx = int(i / 2)
    ans += A[idx]

print(ans)


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

const int INF = 1000000008;

int main()
{
    int n;
    cin >> n;
    int a[100002];
    for(int i = n - 1; i >= 0; i--) cin >> a[i];
    int dp[100002];
    fill(dp, dp + n, INF);
    for(int i = 0; i < n; i++){
        *upper_bound(dp, dp + n, a[i]) = a[i];
    }
    cout << upper_bound(dp, dp + n, INF - 1) - dp << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
const int MAX_N = (1e+5)+10;
typedef struct edge{
    ll to,rev;
    edge(ll t,ll r){
        to = t;
        rev = r;
    }
}edge;
vector<vector<edge> > G(MAX_N,vector<edge>(0,{0,0}));//0-indexed;
vector<bool> dused(MAX_N,false), lrmade(MAX_N,false);
mat edp(MAX_N,vec(0)),ldp(MAX_N,vec(0)),rdp(MAX_N,vec(0));

ll dfs(ll from, edge ne){//辺neの上にいる気持ち
    ll ans = 1;
    bool NE = false;
    if(ne.rev == MAX_N-5) NE = true;
    edge back(0,0);
    if(!NE) {
        back = G.at(ne.to).at(ne.rev);
        if (edp.at(from).at(back.rev) != -1) return edp.at(from).at(back.rev);
        if (lrmade.at(ne.to)) {
            ans = (ldp.at(ne.to).at(ne.rev) * rdp.at(ne.to).at(ne.rev)) % M;
            edp.at(from).at(back.rev) = ans;
            return ans;
        }
    }
    dused.at(ne.to) = true;
    rep(i,G.at(ne.to).size()){
        edge e =G.at(ne.to).at(i);
        if(!dused.at(e.to)) (ans *= dfs(ne.to,e)+1)%=M;
    }
    dused.at(ne.to) = false;
    if(!NE) edp.at(from).at(back.rev) = ans;
    //cout<<'a'<<endl;
    return ans;
}

int main() {
    cin>>N>>M;
    for(int i = 0; i < N-1; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        --s;
        --t;
        G.at(s).emplace_back(t, G.at(t).size());
        G.at(t).emplace_back(s, G.at(s).size() - 1);
        edp.at(s).push_back(-1);
        ldp.at(s).push_back(-1);
        rdp.at(s).push_back(-1);
        edp.at(t).push_back(-1);
        ldp.at(t).push_back(-1);
        rdp.at(t).push_back(-1);
    }
    vec ans(MAX_N,-100);
    queue<ll> que;
    vector<bool> inque(MAX_N,false);
    que.push(0);
    inque.at(0) = true;
    while(que.size()){
        ll nv = que.front();
        que.pop();
        ans.at(nv) = dfs(MAX_N-5,edge(nv,MAX_N-5));
        ll l = 1, r = 1;
        ll gs =G.at(nv).size();
        rep(i,gs){
            ldp.at(nv).at(i) = l;
            rdp.at(nv).at(gs-i-1) = r;
            (l *= edp.at(nv).at(i)+1)%=M;
            (r *= edp.at(nv).at(gs-i-1)+1)%=M;
            edge e = G.at(nv).at(i);
            if(!inque.at(e.to)){
                que.push(e.to);
                inque.at(e.to) = true;
            }
        }
        lrmade.at(nv) = true;
    }
    rep(i,N) cout<<ans.at(i)<<endl;
    /*rep(i,3){
        cout<<"l r"<<endl;
        cout<<ldp.at(0).at(i)<<' '<<rdp.at(0).at(i)<<endl;
    }*/
}

Measured memory_bytes: 33280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[25];
int main() {
	ll n;
	cin>>n;
	a[0]=1;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a[x]++;
	}
	ll ans=24;ll now=0;
	bool ch=true;
	for(ll i=0;i<=12;i++){
		if(i!=0&&i!=12){
			if(a[i]==2){
				a[i]--;
				a[24-i]++;
			}
			else if(a[i]==1){
				if(ch){
					a[i]--;
					a[24-i]++;
					ch=false;
				}
				else{
					ch=true;
				}
			}
		}
	}
	for(ll i=0;i<24;i++){
		if(a[i]>1){
			cout << 0;
			return 0;
		}
		if(a[i]==1&&i!=0){
			ans=min(ans,i-now);
			now=i;
			continue;
		}
		if(i==23){
			ans=min(ans,24-now);
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {
    int n,m;
    Scd2(n,m);

    int ans = 0;
    if(n == 1) {
        printf ("%d\n", m);
        return 0;
    }
    if(n == 2) {
        if( m % 2 == 0){
            printf ("%d\n", m/2);
            return 0;
        }
        for(int i = 2; i*i <= 1000000000; i++ ){
            if( m % i == 0 && m / i >= n ){
                ans = m / i;
                break;
            }
        }
        printf ("%d\n", ans);
        return 0;
    }
    for(int i = 1; i*n <= 1000000000; i++ ){
        if( m % i == 0 && m / i >= n ){
            ans = i;
        }
    }

    printf ("%d\n", ans );

    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

vector<int> cnt(222222,0);
vector<bool> check(222222,false);
ll res = 0;
int idx = 0, sz;

void dfs(const vector<vector<int>> &g, int v, int pre){
    for(auto next:g[v]){
        if(next==pre) continue;
        if(g[next].size()==1){
            int tmp = min(cnt[v], cnt[next]);
            res += tmp;
            cnt[v]-= tmp;
            cnt[next]-=tmp;
        }
        else{
            dfs(g,next,v);
            int tmp = min(cnt[v], cnt[next]);
            res += tmp;
            cnt[v]-= tmp;
            cnt[next]-=tmp;
        }
    }
}

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

    int n;
    cin >> n;
    map<ll, ll> mp;
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        mp[a]++;
    }
    sz = mp.size();
    vector<vector<int>> g(sz);
    map<ll, int> imap;
    for (auto v : mp)
    {
        imap[v.first] = idx;
        cnt[idx] = v.second;
        for (int i = 1; i <= 30; i++)
        {
            ll gt = (1LL << i) - v.first;
            if (imap.find(gt) == imap.end())
                continue;
            if (gt == v.first)
            {
                check[idx] = true;
                continue;
            }
            int idx2 = imap[gt];
            g[idx].push_back(idx2);
            g[idx2].push_back(idx);
        }
        idx++;
    }
    for(int i=0;i<idx;i++){
        if(cnt[i]>0) dfs(g, i, -1);
    }
    for(int i=0;i<idx;i++){
        if(check[i]) res += cnt[i]/2;
    }
    cout << res << endl;
}


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

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

const int maxn = 2005, maxp = 1e7 + 5;

int n, m, x[maxn], p[maxn];
int Vis[maxp];

struct edge
{
	int to, next, cap;
} e[maxn * maxn * 2];
int h[maxn], cur[maxn], tot = 1, dis[maxn], s, t;
bool vis[maxn];

inline void add(int u, int v, int w)
{
	e[++tot] = (edge) {v, h[u], w}; h[u] = tot;
	e[++tot] = (edge) {u, h[v], 0}; h[v] = tot;
}

void pre()
{
	static int p[maxp], cnt;
	Vis[1] = 1;
	for (int i = 2; i <= 1e7; ++i) {
		if (!Vis[i]) p[++cnt] = i, Vis[i] = i;
		for (int j = 1; j <= cnt && i * p[j] <= 1e7; ++j) {
			Vis[i * p[j]] = p[j];
			if (p[j] >= Vis[i]) break;
		}
	}
	Vis[2] = 1;
	for (int i = 2; i <= 1e7; ++i)
		if (Vis[i] == i) Vis[i] = 0;
}

bool bfs()
{
	static int u, l, r, q[maxn];
	l = 0; q[r = 1] = s; vis[s] = 1;
	while (l < r) {
		u = q[++l];
		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
			if (!vis[v] && e[i].cap) {
				vis[v] = 1; dis[v] = dis[u] + 1;
				q[++r] = v;
			}
	}
	return vis[t];
}

int dfs(int u, int a)
{
	if (u == t || !a) return a;
	int f = 0, flow = 0;
	for (int &i = cur[u], v; v = e[i].to, i; i = e[i].next)
		if (dis[v] == dis[u] + 1 && (f = dfs(v, min(e[i].cap, a)))) {
			e[i].cap -= f; e[i ^ 1].cap += f;
			flow += f; a -= f;
			if (!a) break;
		}
	return flow;
}

int dinic()
{
	int res = 0;
	while (bfs()) {
		memset(vis + 1, 0, sizeof(bool) * t);
		memcpy(cur + 1, h + 1, sizeof(int) * t);
		res += dfs(s, 1e9);
	}
	return res;
}

int main()
{
	n = gi();
	for (int i = 1; i <= n; ++i) x[i] = gi();
	sort(x + 1, x + n + 1);

	pre();

	for (int i = 1, j; i <= n; i = j + 1) {
		j = i;
		while (x[j + 1] == x[j] + 1) ++j;
		p[++m] = x[i]; p[++m] = x[j] + 1;
	}

	s = m + 1; t = s + 1;
	int odd = 0;
	for (int i = 1; i <= m; ++i)
		if (p[i] & 1) add(s, i, 1), ++odd;
		else add(i, t, 1);
	for (int i = 1; i <= m; ++i)
		if (p[i] & 1)
			for (int j = 1; j <= m; ++j)
				if ((~p[j] & 1) && !Vis[abs(p[i] - p[j])])
					add(i, j, 1);

	int ans = dinic();
	printf("%d\n", ans + ((odd - ans) / 2 + (m - odd - ans) / 2) * 2 + ((odd - ans) & 1) * 3);
	
	return 0;
}


Measured memory_bytes: 43392
a = input()
if a[-1] == "2" or a[-1] == "4" or a[-1] == "5" or a[-1] == "7" or a[-1] == "9":
    print('hon')
elif a[-1] == "0" or a[-1] == "1" or a[-1] == "6" or a[-1] == "8":
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9052
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, m;
    ll ans = 0;

    cin >> n >> m;

    if (n >= m)
    {
        cout << 0 << endl;
        return 0;
    }

    vector<ll> x(m);
    priority_queue<ll> s;

    for (int i = 0; i < m; i++)
    {
        cin >> x[i];
    }

    sort(x.begin(), x.end());

    for (int i = 1; i < m; i++)
    {
        s.push(x[i] - x[i - 1]);
    }

    ans = *x.rbegin() - *x.begin();

    for (int i = 0; i < n - 1; i++)
    {
        ans -= s.top();
        s.pop();
    }

    cout << ans << endl;
}


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

using namespace std;

int x[10][10];

bool check(int n){
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(x[i][j] == n) return true;
        }
    }
    return false;
}

int main(void){
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            x[i][j] = i * j;
        }
    }
    if(check(n)){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
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 int INF = 1e9;
const ll LINF = 1e18;
// clang-format on

void solve(long long N, long long K, std::vector<ll> D) {
  ll ans = N;
  for (;; ans++) {
    string n = to_string(ans);
    sort(all(n));
    n.erase(unique(all(n)), n.end());
    for (char &c : n) {
      for (ll d : D) {
        if (c == '0' + d) {
          goto next;
        }
      }
    }
    break;
  next:;
    // set<char> n(all(to_string(ans)));
    // set<char> d(all(D));
    // set<char> intersection;
    // set_intersection(all(n), all(d), inserter(intersection, intersection.end()));
    // if (intersection.size() == 0) {
    //   cout << ans << endl;
    //   break;
    // }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> D(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &D[i]);
  }
  solve(N, K, std::move(D));
  return 0;
}


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

#define INF 1e9
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int main(void){
  while(true){
    int w, h;
    cin >> w >> h;
    if(w == 0 && h == 0){ break; }


    int c[4];
    vector<vector<int> > s(h + 2, vector<int>(w + 2, -1));
    for(int i = 1; i <= h; i++)
      for(int j = 1; j <= w; j++)
        cin >> s[i][j];
    cin >> c[0] >> c[1] >> c[2] >> c[3];

    int cost[5][4][4];
    for(int i = 0; i < 5; i++){
      for(int in = 0; in < 4; in++){
        for(int out = 0; out < 4; out++){
          int compass = (out + 4 - in) % 4;
          if(i == compass){ cost[i][in][out] = 0; }
          else{ cost[i][in][out] = c[compass]; }
        }
      }
    }
      
    priority_queue<pair<int, pair<pair<int, int>, int> > > wait;
    vector<vector<vector<int> > > result(h + 2, vector<vector<int> >(w + 2, vector<int>(4, INF)));
    wait.push(make_pair(0, make_pair(make_pair(1, 1), 0)));
    result[1][1][0] = 0;
    while(!wait.empty()){
      int nowcost = -wait.top().first;
      int nowX = wait.top().second.first.first;
      int nowY = wait.top().second.first.second;
      int nowCompass = wait.top().second.second;
      wait.pop();
      if(s[nowX][nowY] == -1 || result[nowX][nowY][nowCompass] < nowcost){ continue; }
      
      for(int i = 0; i < 4; i++){
        int nextCompass = i;
        int nextcost = nowcost + cost[s[nowX][nowY]][nowCompass][nextCompass];
        int nextX = nowX + dx[i];
        int nextY = nowY + dy[i];
        if(result[nextX][nextY][nextCompass] > nextcost){
          wait.push(make_pair(-nextcost, make_pair(make_pair(nextX, nextY), nextCompass)));
          result[nextX][nextY][nextCompass] = nextcost;
        }
      }
    }

    int ans = INF;
    for(int i = 0; i < 4; i++){ ans = min(ans, result[h][w][i]); }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3244
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; x + y <= s && y <= k; y++) {
            if (s - x - y <= k && s - x - y >= 0)
                cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
vector<int> videos(105);
double now=0;
queue<int> num;
ll k,a,b;
int main(int argc,char const* argv[])
{
  cin >> k >> a >> b;
  if(a<=b && a<k)
    {
      cout << -1 << endl;
      return 0;
    }
  else if(a>=k)
    {
      cout << 1 << endl;
      return 0;
    }
  else
    {
      ll ans=1;
      if((k-a)%(a-b)) ans+=2;
      ans+=(k-a)/(a-b) *2;
      cout << ans << endl;	
      return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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 ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int n;
    cin >> n;
    double x;
    string s;
    double sum = 0;
    REP(i,n){
        cin >> x >> s;
        if(s == "JPY") sum += x;
        else sum += x * 380000.0;
    }
    cout << sum << endl;
    return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long n; cin >> n;
    string s = "";
    while (n)
    {
        s += (char)((--n % 26) + 'a');
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   long long int n,a,k,p,q,g=0,s=0,i,b[100005];for(i=0;i<100001;i++)b[i]=0;
   cin>>n;
  // cout<<n*100000;
   for(i=0;i<n;i++)
   {
       cin>>a;
       s+=a;
       b[a]++;
   }
   cin>>k;
   while(k--)
   {
       g=0;
       cin>>p>>q;
  /*     for(i=0;i<n;i++)
       {
           if (a[i]==p){g++;
           a[i]=q;}
       }*/
       g=b[p];
       b[p]=0;
       b[q]+=g;
       s=s+(g*(q-p));
       cout<<s<<endl;
   }
}

Measured memory_bytes: 4376