akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	if(N==M) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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


int main(){
    int N;
    cin >> N;
    vector<int> A(N+2);
    A[0] = A[N+1] = 0;
    for(int i=1; i<=N; i++) cin >> A[i];
    
    int S=0;
    for(int i=0; i<N+1; i++){
        S += abs(A[i]-A[i+1]);
    }
    
    int Si=0;
    for(int i=1; i<=N; i++){
        Si = S + abs(A[i-1]-A[i+1]) - (abs(A[i-1]-A[i])+abs(A[i]-A[i+1]));
        cout << Si << endl;
    }
}



Measured memory_bytes: 1664
#include <iostream>

int main(int argc, char const* argv[])
{
    int H, W, h, w;

    std::cin >> H >> W >> h >> w;

    int result = H * W;

    result -= W * h;
    result -= H * w;
    result += h * w;

    std::cout << result << std::endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    ll N, K;
    cin >> N >> K;
    vec<ll> A(N);
    rep(i, N) cin >> A[i];

    ll msk = 0;
    for (int i = 40; i >= 0; --i) {
        int cnt = 0;
        rep(j, N) if ((A[j] >> i) & 1)++ cnt;
        if (cnt * 2 <= N && (msk + (1LL << i)) <= K) {
            msk |= (1LL << i);
        }
    }
    int first1                            = 0;
    rep(i, 40) if (K & (1LL << i)) first1 = max(first1, i);

    ll msk2 = 0;
    for (int i = first1 - 1; i >= 0; --i) {
        int cnt = 0;
        rep(j, N) if ((A[j] >> i) & 1)++ cnt;
        if (cnt * 2 <= N) {
            msk2 |= (1LL << i);
        }
    }

    ll ans = 0;
    rep(i, N) ans += (msk ^ A[i]);

    ll ans2 = 0;
    rep(i, N) ans2 += (msk2 ^ A[i]);
    cout << max(ans,ans2) << endl;
}

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

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

    string s;
    cin >> s;
    deque<char> dq;
    for(int i = 0; i < s.size(); i++){
        dq.push_back(s[i]);
    }

    bool fr = true;

    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t == 1){
            fr ^= 1;
        }else{
            int f;
            char c;
            cin >> f >> c;

            if(fr){
                if(f == 1) dq.push_front(c);
                else dq.push_back(c);
            }else{
                if(f == 1) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }

    if(!fr) reverse(dq.begin(), dq.end());

    for(auto x: dq){
        cout << x;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 976
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    string s;
    cin >> s;
    rep(i, s.length()) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


Measured memory_bytes: 512
N = int(input())
lst = [[] for _ in range(N)]

for i in range(N):
    S, P = input().split()
    lst[i].append(S)
    lst[i].append(P)
    lst[i].append(i+1)
    
lst_a = sorted(lst, key=lambda x:(x[0], -int(x[1])))
for i in range(N):
    print(lst_a[i][2])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VS A(N);
  rep(i,N) cin>>A[i];
  VI B(N),C(N),D(N),E(N);
  rep(i,N) rep(j,N) B[i]+=(A[i][j]=='#');
  rep(i,N){
    C[i]=1;
    rep(j,N) C[i]&=(A[i][j]=='#');
  }
  rep(i,N) rep(j,N) D[i]+=(A[j][i]=='#');
  rep(i,N){
    E[i]=1;
    rep(j,N) E[i]&=(A[j][i]=='#');
  }
  int F=0;
  rep(i,N) F+=B[i];
  int G=0;
  rep(i,N) G+=E[i];
  int ans=N*2;
  rep(i,N){
    if(C[i]){
      ans=min(ans,N-G);
      continue;
    }
    if(D[i]) ans=min(ans,N-B[i]+N-G);
    else ans=min(ans,N-B[i]+1+N-G);
  }
  cout<<(F?ans:-1)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define 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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){	
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	if(a==b) 
		cout << a + b << '\n';
	else{
		int x = max(a, b);
		cout << x + x-1 << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

int color (int[] c1, int[] c2) {
  return (c1[0] - c2[0])^^2 + (c1[1] - c2[1])^^2 + (c1[2] - c2[2])^^2;
}

void main()
{
  while (1) {
    if (!readln.chomp.to!int) break;
    auto x = readln.chomp.split.map!(to!int).array;
    auto num = 32;
    int turn;
    bool ply;
    while (num > 0) {
      if (ply) {
        num -= x[turn++%x.length];
      } else {
        num -= (num - 1) % 5;
      }
      if (num < 0) num = 0;
      num.writeln;
      ply = !ply;
    } 
  }
}

Measured memory_bytes: 1056
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define pq priority_queue<ll>
using namespace std;
int a[N],b[N];
int main() {
	int n,x=0,y=0;
	ll ans=0;
	cin>>n;
	rep(i,1,n)cin>>a[i];
	rep(i,1,n)cin>>b[i];
	rep(i,1,n) {
		if(a[i]-b[i]>0) ans+=a[i]-b[i];
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll h, w, k; cin >> h >> w >> k;
    string mat[h];
    rep(i, h){
        cin >> mat[i];
    }

    int ans[h][w] = {};
    int cnt = 1;
    rep(i, h){
        rep(j, w){
            if(mat[i][j] == '#'){
                ans[i][j] = cnt;
                cnt++;
            }
        }
    }

    rep(i, h){
        reps(j, 1, w){
            if(ans[i][j-1] == 0) continue;
            if(ans[i][j] == 0){
                ans[i][j] = ans[i][j-1];
            }
        }
        reprs(j, 0, w-1){
            if(ans[i][j+1] == 0) continue;
            if(ans[i][j] == 0){
                ans[i][j] = ans[i][j+1];
            }
        }
    }

    reps(i, 1, h){
        if(ans[i][0] == 0){
            rep(j, w){
                ans[i][j] = ans[i-1][j];
            }
        }
    }

    reprs(i, 0, h-1){
        if(ans[i][0] == 0){
            rep(j, w){
                ans[i][j] = ans[i+1][j];
            }
        }
    }

    rep(i, h){
        rep(j, w){
            cout << ans[i][j] << " " ;
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 1280
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	ll a,b;
	cin>>a>>b;
	ll cnt=0;
	while(a<=b){
		a*=2;
		cnt++;
	}
	cout<<cnt;

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
int arr[(int)10e5+2]={0};
int p[(int)10e5];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,l,r;
    cin>>n;
    int ans=0;
    for (int i=0;i<n;i++){
        cin>>l>>r;
        ans+=(r-l+1);
    }cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    char a[9][8];
    int x,y,temp;
    int i = 0,n = 0;

    while(scanf("%s",a[i]) != EOF){
        i++;
        n++;
        if(n != 8) continue;
        getchar();
        for(y = 0; y < 8; y++){
            for(x = 0; x < 8; x++){
                if(a[y][x] == '1' && a[y][x + 1] == '1' && a[y + 1][x] == '1' && a[y + 1][x + 1] == '1') printf("A\n");
                if(a[y][x] == '1' && a[y + 1][x] == '1' && a[y + 2][x] == '1' && a[y + 3][x] == '1') printf("B\n");
                if(a[y][x] == '1' && a[y][x + 1] == '1' && a[y][x + 2] == '1' && a[y][x + 3] == '1') printf("C\n");
                if(a[y][x] == '1' && a[y + 1][x - 1] == '1' && a[y + 1][x] == '1' && a[y + 2][x - 1] == '1') printf("D\n");
                if(a[y][x] == '1' && a[y + 1][x] == '1' && a[y + 1][x + 1] == '1' && a[y + 2][x + 1] == '1') printf("F\n");
                if(a[y][x] == '1' && a[y][x + 1] == '1' && a[y + 1][x + 1] == '1' && a[y + 1][x + 2] == '1') printf("E\n");
                if(a[y][x] == '1' && a[y][x + 1] == '1' && a[y + 1][x - 1] == '1' && a[y + 1][x] == '1') printf("G\n");
            }
        }
        i = n = 0;
    }

    return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
 
	public static void main(String[] args) {
 
		long N = in.nextLong();
		long M = in.nextLong();

		long amari = N % M;
		long ura = Math.abs(M-amari);

		System.out.println(Math.min(amari, ura));
	}

	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)


struct Node {
  int begin, end, id;  // range is [begin, end)
  Node* next;
  Node(int begin, int end, int id)
    : begin(begin), end(end), id(id), next(NULL) {}

  void insert(Node* new_next) {
    new_next->next = next;
    next = new_next;
  }
  void remove(Node* prev) {
    prev->next = next;
    delete this;
  }
};

void removeSome(Node* root, int id) {
  for (Node *node = root->next, *prev = root;
       node;
       prev = node, node = node->next) {
    if (id >= 0 ? (node->id == id) : (node->id != -1)) {
      node->remove(prev);
      node = prev;
    }
  }
}

int main() {
  int n;
  Node* root = new Node(-1,0,-1);
  int INF = 1000000000 + 5;
  Node* last = new Node(INF, INF+1, -1);
  root->next = last;

  ios::sync_with_stdio(false);

  while(cin >> n, n) {
    rep(_,n) {
      char cmd;
      cin >> cmd;
      if (cmd == 'W') {
        int id, s;
        cin >> id >> s;
        for (Node *node = root->next, *prev = root;
             node && s > 0;
             prev = node, node = node->next) {
          int diff = node->begin - prev->end;
          if (diff > 0) {
            int size = min(s, diff);
            prev->insert(new Node(prev->end, prev->end + size, id));
            s -= size;
          }
        }
      }
      else if (cmd == 'D') {
        int id;
        cin >> id;
        removeSome(root, id);
      }
      else if (cmd == 'R') {
        int addr;
        cin >> addr;
        for (Node *node = root->next;
             node;
             node = node->next) {
          if (addr < node->end) {
            if (node->begin <= addr) cout << node->id << "\n";
            else cout << "-1\n";
            break;
          }
        }
      }
    }

    removeSome(root, -1);  //clear
    cout << "\n";  // puts("")とios::sync_with_stdio(false)を同時に使うと死ぬ
  }

  return 0;
}

Measured memory_bytes: 1308
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,i,j;
    cin>>n;
    vector<double> a(n);
    for(i=0;i<n;i++)
        cin>>a[i];
    double tot=0;
    for(auto in:a)
        tot+=in;
    double N=n;
    double avg=tot/N;
    pair<double,ll> p[n];
    for(i=0;i<n;i++)
        p[i].first=abs(a[i]-avg),p[i].second=i;
    sort(p,p+n);
    cout<<p[0].second<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict

if __name__ == '__main__':
    N = int(input().strip())
    s = [input().strip() for _ in range(N)]
    M = int(input().strip())
    t = [input().strip() for _ in range(M)]

    d = defaultdict(int)
    d[""] = 0

    for word in s:
        d[word] += 1

    for word in t:
        d[word] -= 1

    max_key = None
    max_value = -1
    for (key, value) in d.items():
        if max_key is None:
            max_key = key
            max_value = value
            continue

        if max_value < value:
            max_key = key
            max_value = value

    print(max_value)


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<int> a_list(N, 0);

	int odd = 0;
	int even = 0;
	int four = 0;
	
	for (int i = 0; i < N; i++)
	{
		cin >> a_list[i];
	
		if (a_list[i] % 2 == 1) odd++;
		else if (a_list[i] % 4 == 0) four++;
		else even++;
	}

	odd += (even != 0);
	if (odd > four + 1)
	{
		cout << "No";
	}
	else
	{
		cout << "Yes";
	}

	return 0;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

#define MOD 1000000007

int N, M;
vector<int> edge[100000];
LL cost[100000][3];
int S, T;

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int u, v;
		cin >> u >> v;
		edge[u-1].PB(v-1);
	}
	cin >> S >> T;
	S--; T--;
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cost[i][j] = INT_MAX;
		}
	}
	cost[S][0] = 0;
	queue<pair<int,int>> que;
	que.push(MP(S, 0));
	while(!que.empty()){
		int p = que.front().first;
		int s = que.front().second;
		que.pop();
		for(int i=0; i<edge[p].size(); i++){
			if(cost[edge[p][i]][(s+1)%3] > cost[p][s] + 1){
				cost[edge[p][i]][(s+1)%3] = cost[p][s] + 1;
				que.push(MP(edge[p][i], (s+1)%3));
			}
		}
	}
	if(cost[T][0] == INT_MAX) cout << -1 << endl;
	else cout << cost[T][0]/3 << endl;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector 
vector<pair<ll, ll>> pFactor;

void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        pFactor.pb({2,count}); 
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            pFactor.pb({i,count});
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        pFactor.pb({n,1}); 
} 



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   int n;
   cin>>n;
   int freq[n+1] = {0};
   for(int i=1; i<=sqrt(n); i++){
       for(int j=1; j<=sqrt(n) ;j++){
           for(int k=1; k<=sqrt(n); k++){
               int a = i*i + j*j + k*k + i*j+i*k+k*j;
               if(a<=n)
               freq[a]++;
           }
       }
   }
   lp(1, n+1){
       cout<<freq[i]<<endl;
   }
}


Measured memory_bytes: 3696
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> B = new ArrayList<>();

        for(int i=0; i<N-1; i++){
            B.add(scanner.nextInt());
        }

        int res = 0;
        res = res + B.get(0);
        for(int i=0; i<N-2; i++){
            res = res + Math.min(B.get(i), B.get(i+1));
        }
        res = res + B.get(N-2);

        System.out.println(res);
    }
}

Measured memory_bytes: 24916
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

typedef long long int Int;

int main(void) {
    int n,a;
    cin>>n;
    cin>>a;

    cout<<n*n-a<<endl;

    return 0;
}


Measured memory_bytes: 504
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
    ll N;
    ll cnt[63];
    memset(cnt, 0x00, 63 * sizeof(ll));
    cin >> N;
    rep(i, 0, N){
        ll temp = 0;
        cin >> temp;
        rep(ii, 0, 63){
            if (temp & 1){
                cnt[ii]++;
            }
            temp = temp >> 1;
            if (temp == 0){
                break;
            }
        }
    }
    ll ans = 0;
    ll temp2 = 1;
    rep(i, 0, 63){
        ll cnt2 = cnt[i] * (N - cnt[i]) % MOD;
        ans = (ans + ((temp2 * cnt2) % MOD)) % MOD;
        temp2 = temp2 * 2 % MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////
#define int long long



int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif


	int n;
	cin >> n;
	vector<int>a(n);

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

	cout << ans << endl;



}


Measured memory_bytes: 4780
h, w, d = map(int, input().split())
g = [[] for _ in range(w)]
for _ in range(h):
    tmp_list = list(map(int, input().split()))
    for i in range(w):
        g[i].append(tmp_list[i])
q = int(input())
qs = [list(map(int, input().split())) for _ in range(q)]
loc = [0]*(h*w+1)
for i in range(h):
    for j in range(w):
        loc[g[j][i]] = (i,j)
roots = [0]*(h*w+1)
for i in range(1,d+1):
    j = i + d
    while j < h*w+1:
        cost = abs(loc[j][0]-loc[j-d][0]) + abs(loc[j][1]-loc[j-d][1])
        roots[j] = cost + roots[j-d]
        j += d
for i in qs:
    l, r = i[0], i[1]
    print(roots[r] - roots[l])

Measured memory_bytes: 41348
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s;
    cin >> s;

    int n = s.size() + 1;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        if ((i == 0 || s[i - 1] == '>') && (i == n - 1 || s[i] == '<')) {
            a[i] = 0;
            int c = 0;
            for (int j = i + 1; j < n; j++) {
                if (s[j - 1] != '<') break;
                a[j] = max(a[j], ++c);
            }
            c = 0;
            for (int j = i - 1; j >= 0; j--) {
                if (s[j] != '>') break;
                a[j] = max(a[j], ++c);
            }
        }
    }
    //s[i]はa[i]とa[i+1]の関係を表す

    ll r = 0;
    for (int i = 0; i < n; i++) {
        r += a[i];
        //cout << a[i] << ' ';
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 2844
import math
a, b, h, m = [int(i)  for i in input().split()]

hw = 360 * (h/12) + 30 * m/60
mw = 360 * (m/60)
ans=0
#print("hw, mw", hw, mw)
w = abs(hw-mw)
#print(w)
if w > 180:
  w = 360 - w
elif w == 180:
  ans = a+b

#print("w",w)
if w == 90:
  ans = math.sqrt(a**2 + b**2)
#elif w < 90:
 # ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(w)))
else:
  ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(w)))

print(ans)

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

int main() {
    int N; cin >> N;
	vector<long long> A(N);
	for(int i=0; i<N; ++i) cin >> A[i];

	long long x = 1000;
	long long mi = A[0];
	for(int i=0; i+1<N; ++i) {
	    if(A[i] > A[i + 1]) {
		    long long tmp = x / mi;
			x += (A[i] - mi) * tmp;
			mi = A[i + 1];
		}
	}
	if(A[N - 2] <= A[N - 1]) {
	    long long tmp = x / mi;
		x += (A[N - 1] - mi) * tmp;
	}
	cout << x << '\n';
}



Measured memory_bytes: 3596
a = int(input())
b = input().split()
x = []
for i in b:
    x.append(int(i))

count = 0

for i in x:
    if i % 2 != 0:
        count += 1


z = count % 2

if z == 1:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 14108
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f >>= mapM_ print
    main
  where
    -- f = readi B.readInt <$> B.getLine
    f = map read <$> words <$> getLine

solve :: [[Integer]] -> [Integer]
solve xss = let ps = map f xss
                g = foldl1' gcd ps
            in map (flip div g) ps
  where
    pon = (product . map head) xss
    f [d, v] = pon `div` d * v



Measured memory_bytes: 4388
def warshall_floyd(graph, edges):
    N = len(graph)
    for i in xrange(N):
        for j in xrange(N):
            if i == j:
                graph[i][j] = 0
            else:
                graph[i][j] = Infinity()
    for e in edges:
        graph[e.source][e.destination] = e.weight
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
    for i in xrange(N):
        if graph[i][i] < 0:
            raise NegativeCycleError

def main():
    V, E = map(int, raw_input().split())
    graph = [[None] * V for _ in xrange(V)]
    edges = []
    for _ in xrange(E):
        s, t, d = map(int, raw_input().split())
        edges.append(Edge(s, t, d))
    try:
        warshall_floyd(graph, edges)
        for g in graph:
            print " ".join(map(str, g))
    except NegativeCycleError:
        print "NEGATIVE CYCLE"

class Infinity(object):
    def __eq__(self, other):
        return other is self

    def __lt__(self, other):
        return False

    def __gt__(self, other):
        return True

    def __add__(self, other):
        return self

    def __radd__(self, other):
        return self

    def __str__(self):
        return "INF"
    __repr__ = __str__

class NegativeCycleError(Exception):
    pass

class Edge(object):
    def __init__(self, source, destination, weight):
        self.source = source
        self.destination = destination
        self.weight = weight

if __name__ == "__main__":
    main()

Measured memory_bytes: 8496
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int a, b, c;
    cin>>a>>b>>c;
    cout<<(((a+b+c)>=22) ? "bust" : "win") <<endl;
    return 0;
}


Measured memory_bytes: 256
//Bellman_Ford法
//ABC061D

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long


struct edge {
  int to;
  LINT cost;  // 辺の接続先頂点, 辺の重み
  edge(int to, LINT cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
                // graph[v][i]は頂点vから出るi番目の辺edge

const LINT INF = 1000000000000000;

vector<LINT> dist; // 最短距離
vector<bool> negative; //正のループで得点をinfにできるかどうか

// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
  dist = vector<LINT>(n, INF);
  dist[s] = 0; // 開始点の距離は0
  for (int i = 0; i < n-1; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        edge e = graph[v][k];
        if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
        }
      }
    }
  }
  return false;
}

bool bellman_ford2(int n) {
  negative = vector<bool>(n, false);
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < graph[v].size(); k++) {
        edge e = graph[v][k];
        if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          negative[e.to] = true;
        }
        if(negative[v]) negative[e.to] = true;
      }
    }
  }
  return negative[n-1];
}

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

  graph = AdjList(n);

  for (int i = 0; i < m; i++) {
    int from, to;
    LINT cost;
    cin >> from >> to >> cost;
    graph[from-1].push_back(edge(to-1, -cost));
  }

  bellman_ford(n, 0);
  if(bellman_ford2(n)) {
    cout << "inf" << endl;
    return 0;
  }
  cout << -dist[n-1] << endl;

  return 0;
}


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

ll func(string s){
    ll len = s.size();
    if(s[0] == s[len-1]){
        //sの先頭から同じ文字がつながっている個数
        ll a = 1;
        rep(i, len){
            if(s[i] == s[i+1]) a++;
            else break;
        }
        //sの末尾から同じ文字がつながっている個数
        ll b = 1;
        for(int i = len-1; i >= 0; i--){
            if(s[i] == s[i-1]) b++;
            else break;
        }

        ll val = (a/2) + (b/2) - (a+b)/2;
        return val;
    }else{
        return 0;
    }
}

int main(){
    string s;
    ll K;
    cin >> s >> K;
    ll len = (ll)s.size();
    //書き換えなければ行けない文字数
    ll ans = 0;
    //S内で書き換えなければならない文字数
    ll count = 0;
    //Sの文字がすべて同じ場合はコーナーケースとして扱う
    bool is = true;
    rep(i, len-1){
        if(s[i] != s[i+1]) is = false;
    }
    if(is){
        ans = len * K / 2;
        cout << ans << endl;
        return 0;
    }
    //S内で書き換えなければならない個数のカウントを行う
    rep(i, len-1){
        if(s[i] == s[i+1]){
            ll val = 1;
            while(i < len && s[i] == s[i+1]){
                i++;
                val++;
            }
            count += val / 2;
        }
    }
    ans = count * K;
    //Sの先頭と末尾の文字が一致している場合の処理
    if(s[0] == s[len-1] && len > 1){
        ll a = 1, b = 1;
        rep(i, len-1){
            if(s[i] == s[i+1]) a++;
            else break;
        }
        for(int i = len-1; i > 0; i--){
            if(s[i] == s[i-1]) b++;
            else break;
        }
        ll sub = a/2 + b/2 - (a+b)/2;
        sub *= (K-1);
        ans -= sub;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main(){
	char c[20];
	while(cin.getline(c,16)){
		int y,m,d;
		y = c[0]*1000+c[1]*100+c[2]*10+c[3];
		y -= '0'*1111;
		m = d = 0;
		int i = 5;
		while(c[i] != ' '){
			m *= 10;
			m += c[i]-'0';
			++i;
		}
		++i;
		while(c[i]){
			d *= 10;
			d += c[i]-'0';
			++i;
		}
		if(y > 1989 || (y == 1989 && (m > 1 || d >= 8))) cout << "heisei " << y-1988 << " " << m << " " << d << endl;
		else if(y-1926 > 0 || (y == 1926 && m == 12 && d >= 25)) cout << "showa " << y-1925 << " " << m << " " << d << endl;
		else if(y > 1912 || (y == 1912 && (m > 7 || (m == 7 && d >= 30)))) cout << "taisho " << y-1911 << " " << m << " " << d << endl;
		else if(y > 1868 || (y == 1868 && (m > 9 || ( m == 9 && d >= 8)))) cout << "meiji " << y-1867 << " " << m << " " << d << endl;
		else cout << "pre-meiji" << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,k,q;cin>>n>>k>>q;
    map<ll,ll>mp;
    for(ll i=0;i<q;i++){
        ll x;cin>>x;
        x--;
        mp[x]++;
    }
    ll ar[100005];
    for(ll i=0;i<n;i++){
        ar[i]=k;
    }
    for(ll i=0;i<n;i++){
        ll rs=q-mp[i];
        ar[i]=ar[i]-rs;
    }
    for(ll i=0;i<n;i++){
        if(ar[i]<=0)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 7680
S = list(input())
runlength = []
temp = S[0]
if len(set(S)) == 1:
    print(0)
    exit() 
for i in range(1,len(S)):
    if temp != S[i]:
        runlength.append(temp)
        temp = S[i]
runlength.append(temp)
print(len(runlength)-1)

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

using namespace std;

int main(){
  string s;
  int n;
  int count = 0;
  cin >>n>> s;
  for (int i = 0; i < s.size()-2; i++){
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      count++;
    }
  }
  cout << count << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H') puts(b=='H'?"H":"D");
	else puts(b=='H'?"D":"H");
	return 0;
}

Measured memory_bytes: 3624
n  = int(input())
a_ls = list(map(int, input().split()))
yes_flg = 1
for i in range(len(a_ls)):
    if (a_ls[i] % 2 == 0) :
        if a_ls[i] % 3 != 0:
            if a_ls[i] % 5 != 0:
                yes_flg = 0
if yes_flg == 1:
    print("APPROVED")
else:
    print("DENIED")


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};

int main(){

  ll n,k;cin>>n>>k;
  Radix s;

  out(to_string((s.to(n,k)).size()));

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    int a1 = a * 25 / 2 + a % 2;
    int a2;
    a2 = 25 * (a + 1);
    int b1, b2;
    int res;
    b1 = 10 * b;
    b2 = 10 * (b + 1);
    res = max(a1, b1);
    if (res * 2 < a2 && res < b2) {
        printf("%d\n", res);
    } else {
        printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	int br=0,i,n=s.size();
	for(i=0;i<n;i++)
		if(s[i]=='o')br++;
	if(15-n+br>7)cout<<"YES\n";
	else cout<<"NO\n";
}


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

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

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'


int n;
VP v(50);

map<PII, int> mp;


signed main()
{
    cin >> n;

    REP(i, n){
        cin >> v[i].first >> v[i].second;
    }
    v.resize(n);

    int cnt = -1LL;
    REP(i, n){
        REP(j, n){
            int dx = v[i].first - v[j].first;
            int dy = v[i].second - v[j].second;
            if (dx == 0 && dy == 0) continue;
            mp[make_pair(dx, dy)]++;
            cnt = max(cnt, mp[make_pair(dx, dy)]);
        }
    }
    if (n == 1){
        cout << 1 << endl;
    } else {
        cout << n - cnt << endl;
    }
    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    
    if (a==b) cout << "a == b" << endl;
    else if (a > b) cout << "a > b" << endl;
    else cout << "a < b" << endl;
    
    return 0;
    
    
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct gds{
    string name;
    int a;
    int b;
};

int main(){
    int n,i,P,A,B,C,D,E,F,S,M;
    int a,b;
    string L;
    while(1){
        cin>>n;
        if(!n){break;}
        vector<gds> items(n);
        for(i=0;i<n;i++){
            cin>>L>>P>>A>>B>>C>>D>>E>>F>>S>>M;
            a=F*S*M-P;
            b=A+B+C+D+E+(D+E)*(M-1);
            struct gds buf={L,a,b};
            items[i]=buf;
        }
        sort(items.begin(),items.end(),[](const gds& a, const gds& b){return a.a*b.b==b.a*a.b ? a.name<b.name : a.a*b.b>b.a*a.b;});
     
        for(auto it=items.begin();it!=items.end();it++){
            cout<<it->name<<endl;
        }
        cout<<"#"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0;
     string s,m;
     set<char>se;
     cin>>s;
     for(i=0;i<s.size();i++){
        se.insert(s[i]);
     }
     if(se.size()==2){
        cout<<"Yes"<<endl;
     }
     else{
        cout<<"No"<<endl;
     }


     return EXIT_SUCCESS;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;



int main()
{
  string s;
  cin >> s;
  if(s =="ABC"){
    cout << "ARC" << endl;
  }else{
    cout << "ABC" << endl;
  }

}

Measured memory_bytes: 3544
#include <iostream>
#include<string>
using namespace std;
int has_no(string &s,bool arr[]){
	for(int i=0;i<s.length();i++){
		if(arr[s[i]-'0']) return false;
	}
	return true;
}
int main() {
	// your code goes here
	int N,K;
	cin>>N>>K;
	bool arr[10]={};
	for(int i=0;i<K;i++){
		int n;
		cin>>n;
		arr[n]=true;
	}
	for(int i=N;i<100000;i++){
		string s=to_string(i);
		if(has_no(s,arr)){
			cout<<s<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3676
// 勘 なにもかも勘
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	fmt.Scan(&S)
	SS := make([]string, len(S))
	for i, c := range []rune(S) {
		SS[i] = string(c)
	}
	D := make(map[int]int)
	D[0] = 1 // ncrが失敗するので（？？？？？？？？？？？？？？？？？
	tmp := 0
	x10 := 1
	for i := len(SS) - 1; i >= 0; i-- {
		a, _ := strconv.Atoi(SS[i])
		tmp = (a*x10 + tmp)
		tmp %= 2019
		x10 *= 10
		x10 %= 2019
		D[tmp]++
	}
	ans := 0
	for _, v := range D {
		if v > 1 {
			ans += v * (v - 1) / 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7544
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005

enum Type{
	FROM_S,
	FROM_T,
};

struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index,bool arg_is_rev){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
		is_rev = arg_is_rev;
	}
	int to,capacity,rev_index;
	bool is_rev;
};

int V,E;
int N,M,S,T;

vector<Edge> G[NUM];
bool used[NUM];
bool can_reach[2][NUM];

void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size(),false));
	G[to].push_back(Edge(from,0,G[from].size()-1,true));
}

int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow;
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		Edge &e = G[node_id][i];
		if(used[e.to] == false && e.capacity > 0){
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity));
			if(tmp_flow > 0){
				e.capacity -= tmp_flow;
				G[e.to][e.rev_index].capacity += tmp_flow;
				return tmp_flow;
			}
		}
	}
	return 0;
}

void reach_check(Type type,int node_id){

	can_reach[type][node_id] = true;
	int base;

	if(type == FROM_S){
		base = 1;
	}else{
		base = 0;
	}

	for(int i = 0; i < G[node_id].size(); i++){
		if(G[node_id][i].capacity == base && can_reach[type][G[node_id][i].to] == false){
			reach_check(type,G[node_id][i].to);
		}
	}
}

int max_flow(int source,int sink){
	int flow = 0,add;
	while(true){
		for(int i = 0; i < V; i++)used[i] = false;
		add = dfs(source,sink,BIG_NUM);
		if(add == 0)break;
		flow += add;
	}
	return flow;
}

void func(){

	for(int i = 0; i < N; i++){
		G[i].clear();
		can_reach[FROM_S][i] = false;
		can_reach[FROM_T][i] = false;
	}

	S--;
	T--;

	int from,to;
	for(int loop = 0; loop < M; loop++){
		scanf("%d %d",&from,&to);
		from--;
		to--;
		add_edge(from,to,1);
	}

	V = N;

	int FLOW = max_flow(S,T);
	int MAX_FLOW = FLOW;

	reach_check(FROM_S,S);
	reach_check(FROM_T,T);

	int num_edge = 0,diff;

	for(int i = 0; i < N; i++){
		for(int k = 0; k < G[i].size(); k++){
			if(G[i][k].is_rev == true || G[i][k].capacity == 0 ||
					can_reach[FROM_S][G[i][k].to] == false || can_reach[FROM_T][i] == false)continue;

			num_edge++;
			MAX_FLOW = FLOW+1;

		}
	}

	printf("%d %d\n",MAX_FLOW,num_edge);
}


int main(){

	while(true){
		scanf("%d %d %d %d",&N,&M,&S,&T);
		if(N == 0 && M == 0 && S == 0 && T == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3640
from collections import deque
N=int(input())
ten=[0]*N
G=[[] for i in range(N)]
for i in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w])
    G[v-1].append([u-1,w])
que=deque()
que.append(0)
visited=[[0] for i in range(N)]
visited[0]=1
while que:
    v=que.pop()
    for u in G[v]:
        #print(u)
        if visited[u[0]]==1:
            continue
        if u[1]%2==0:
            ten[u[0]]=ten[v]
        else:
            if ten[v]==0:
                ten[u[0]]=1
                #print("a",ten[u[0]])
            else:
                ten[u[0]]=0
        #print(ten)
        visited[u[0]]=1
        que.appendleft(u[0])
for i in range(N):
    print(ten[i])


Measured memory_bytes: 92192
from scipy.sparse.csgraph import dijkstra
# 二部グラフ完全マッチング
# 最大フロー
N = int(input())
NN = N * 2
XY = [[int(x) for x in input().split()] for _ in range(NN)]
graph = [[0] * (NN+2) for _ in range(NN+2)]
start = NN
goal = NN+1

for i,(a,b) in enumerate(XY[:N]):
  for j,(c,d) in enumerate(XY[N:], N):
    if a < c and b < d:
      graph[i][j] = 1

for i in range(N):
  graph[start][i] = 1
for i in range(N,NN):
  graph[i][goal] = 1
  
INF = 10 ** 9

def max_flow(graph):
  dist, pred = dijkstra(graph, indices = start, return_predecessors = True)
  if dist[goal] > INF:
    return 0
  y = goal
  while y != start:
    x = pred[y]
    graph[x][y] -= 1
    graph[y][x] += 1
    y = x
  return 1 + max_flow(graph)

answer = max_flow(graph)
print(answer)

Measured memory_bytes: 15132
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



vector<vector<int>> calc(const vector<vector<char>>& field, int H, int W) {
    
    vector<vector<int>> ret(H + 1, vector<int>(W + 1, 0));
    rep(i, H) {
        int count = 0;
        vint count_vec;
        rep(j, W + 1) {
            if (field[i][j] == '#') {
                count_vec.push_back(count);
                count = 0;
            }
            else
                count++;

        }
        int k = 0;
        rep(j, W + 1) {
            
            if (field[i][j] == '.')
                ret[i][j] = count_vec[k];
            else {
                ret[i][j] = 0;
                k++;
            }
        }
    }

    return ret;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> field(H + 1, vector<char>(W + 1, '#'));
    vector<vector<char>> field_rev(W + 1, vector<char>(H + 1, '#'));
    rep(i, H) {
        rep(j, W) {
            cin >> field[i][j];
            field_rev[j][i]  = field[i][j];
        }
    }

    v2int ans1 = calc(field, H, W );
    v2int ans2 = calc(field_rev, W, H);
    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            ans = max(ans, ans1[i][j] + ans2[j][i] - 1);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 39680