akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    int n;
    cin >> n;
    ll a[100005] = {};
    rep(i,0,n)cin >>a[i];

    int ans = 1,ud = 0;
    rep(i,1,n){
        if(ud == 0){
            if(a[i-1] > a[i]){
                ud = -1;
            }else if(a[i-1] < a[i]){
                ud = 1;
            }
        }else if(ud > 0){
            if(a[i-1] > a[i]){
                ud = 0;
                ans++;
            }
        }else{
            if(a[i-1] < a[i]){
                ud = 0;
                ans++;
            }
        }
    }
    P(ans);
	return  0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
//aのMODbでの逆元
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;
}
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll sum = 0;
    rep(i,n){
        sum+=a[i];
        sum%=MOD;
    }
    sum*=sum;
    sum%=MOD;
    rep(i,n){
        sum-=((a[i]*a[i])%MOD);
        sum%=MOD;
    }
    sum*=modinv(2,MOD);
    sum%=MOD;
    if(sum<0) sum+=MOD;
    cout << sum << endl;
}

Measured memory_bytes: 4836
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int A,B;
  cin >> A >> B;
  string s;
  cin >> s;
  int n = A+B+1;
  int flag = 0;
  int a = 0;
  int b = 0;
  if (s[A] == '-') flag = 1;
  for (int i=0; i<A; i++) {
    for (int j=0; j<=9; j++) {
      if (s[i]-'0' == j) a = 1;
    }
  }
  for (int i=A+1; i<n; i++) {
    for (int j=0; j<=9; j++) {
      if (s[i]-'0' == j) b = 1;
    }
  }
  int ans = flag*a*b;
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
s = list(input())
s.sort()
t = list(input())
t.sort(reverse = True)
for i in range(min(len(s),len(t))):
    if ord(s[i]) < ord(t[i]):
        print("Yes")
        sys.exit()
    elif ord(s[i]) > ord(t[i]):
        print("No")
        sys.exit()
print("Yes" if len(s) < len(t) else "No")

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] target = new int[n];
		int[] sample = new int[n];
		for(int i=0;i<n;i++) {
			int input=sc.nextInt();
			target[i]=input;
			sample[i]=input;
		}
		Arrays.sort(sample);
		int count=0;
		for(int i=0;i<n;i++) {
			if(target[i]!=sample[i]) {
				count++;
			}
		}
		
		System.out.println(count<=2? "YES": "NO");
	}
}


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

int main() {
  int n;cin>>n;
  vector<int> vec(n);
  rep(i,n){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int a=0;
  for (int i =1;i<n;i++){
    a+= vec.at(i);
  }
  if (vec.at(0) < a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main() {
    int l,r;cin >>l>>r;
    int d;cin >>d;
    int ans=0;
    for (int i =l; i <=r; ++i) {
        if(i%d==0)ans++;
    }
    cout <<ans <<endl;
}


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

int main(){
    long N;
    cin >> N;
    
    if(N%2 == 1){
        cout << 0 << "\n";
        return 0;
    }
    long ans = 0;
    N= N/2;
    while(N>=5){
        ans += N/5;
        N = N/5;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

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

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<int> r(4, 0);
  for(int i=0; i<n; i++) {
    string s;
    cin >> s;
    if(s == "AC") {
      r[0]++;
    }
    if(s == "WA") {
      r[1]++;
    }
    if(s == "TLE") {
      r[2]++;
    }
    if(s == "RE") {
      r[3]++;
    }
  }
  cout << "AC x " << r[0] << endl;
  cout << "WA x " << r[1] << endl;
  cout << "TLE x " << r[2] << endl;
  cout << "RE x " << r[3] << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<pair<int,int> >g[N];
int ans[N],tot,vis[N];
void dfs(int x,int pre){
	vis[x]=1;
//	if(x==1)tot=max(tot,(int)g[x].size());
//	 else tot=max(tot,(int)g[x].size());
	int cur=0;
	for(auto& u:g[x]){
		int v=u.first,id=u.second;
		if(vis[v])continue;
		++cur;
		if(cur==pre)cur++;
		ans[id]=cur;
		dfs(v,cur);
	}
}
int main(){
	int n;
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
	//	g[x].push_back({y,i});
	//	g[y].push_back({x,i});	
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	for(int i=1;i<=n;i++)tot=max(tot,(int)g[i].size());
	dfs(1,0);
	cout<<tot<<endl;
	for(int i=1;i<n;i++)cout<<ans[i]<<endl;
}

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

int main()
{
	auto ans = vector<int>({0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1});
	int x, y;
	cin >> x >> y;
	cout << (ans[x] == ans[y] ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, j;
  char p[8][9];

  for (i = 0; i < 8; i++) {
      scanf("%s", p[i]);
  }

  printf("90\n");
  for (i = 0; i < 8; i++) {
    for (j = 0; j < 8; j++) {
      printf("%c", p[7 - j][i]);
    }
    putchar('\n');
  }

  printf("180\n");
  for (i = 0; i < 8; i++) {
    for (j = 0; j < 8; j++) {
      printf("%c", p[7 - i][7 - j]);
    }
    putchar('\n');
  }

  printf("270\n");
  for (i = 0; i < 8; i++) {
    for (j = 0; j < 8; j++) {
      printf("%c", p[j][7 - i]);
    }
    putchar('\n');
  }
  return 0;
}



Measured memory_bytes: 1984
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int main()
{
	int n=read(),k=((n+3)>>2)<<1;
	if (n==1) { printf("1\n1\n"); return 0; }
	if (n==2) { printf("3\n1 1 1\n1 1 1\n2 2 2\n"); return 0; }
	printf("%d\n",k); 
	for (int i=1;i<=k;i++)
	{
		for (int j=1;j<=k;j++)
			if (!(i&1)) printf("%d ",(i+j)%k+1+((i+j)%k+1+k>n?0:k));
			else printf("%d ",(i+j)%k+1);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	unordered_map<int, int> cnt;
  	int val;
  	for(int i = 0; i < 6; i++) {
    	cin >> val;
      	cnt[val] += 1;
    }
  	int freq_2 = 0;
  	for(auto p: cnt) {
    	if (p.second == 2)
          freq_2 += 1;
    }
  	if (freq_2 == 2 && cnt.size() == 4)
    	cout << "YES" << endl;
  	else
     	cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 512
S = str(input())
K = int(input())
ans = int(0)
count = int(0)
count_first = int(0)
onelen = int(0)
if S[0]==S[-1]:
    count_first += 1
#if count_first == 0:
for i in range(1,len(S)):
    if S[i] == S[i - 1] and i != len(S) - 1:
        count += 1
    elif S[i] == S[i - 1] and i == len(S) - 1:
        count += 1
        if count != len(S)-1:
            onelen += (count + 1) // 2
        else:
            ans = ((count+1) * K) // 2

    else:
        onelen += (count + 1) // 2
        count = 0
if ans == 0:
    ans = onelen * K
#    if S[0] == S[-1]:
#        ans -= 2
if len(S)==1:
    ans = K//2

#else:
if count_first==1 and count != len(S)-1:
    i = int(0)
    while S[i] == S[i + 1]:
        count_first += 1
        i += 1
    i = int(-1)
    while S[i] == S[i - 1]:
        count_first += 1
        i -= 1
    if count_first % 2 == 1:
        ans += K-1

print(ans)


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

using namespace std;

#define ll long long

//#define TEST

signed main(){
    int n;
    cin >> n;
    int* a = new int[n];
    for (int i = 0;i < n;++i)
        cin >> a[i];

    /* sum[i] = a[0]+a[1]+...+a[i-1] */
    ll* sum = new ll[n + 1];
    sum[0] = 0;
    for (int i = 1;i <= n;++i)
        sum[i] = sum[i - 1] + a[i - 1];

#ifdef TEST
    cout << "----------sum----------" << endl;
    for (int i = 0;i <= n;++i)
        cout << sum[i] << " ";
    cout << endl;
#endif

    ll ans = (ll)1e15;

    /* cut the sequence into two sequences like 
            a[0] a[1] ... a[i] | a[i+1] a[i+2] ... a[n-1]
       and get the sum of each sequence. */
    for (int i = 1;i < n - 2;++i){
#ifdef TEST
        cout << "---------i = " << i << "---------" << endl;
#endif
        /* calculate the sum of the left sequence. */
        ll sum_left = sum[i + 1];
        /* calculate the sum of the right sequence. */
        ll sum_right = sum[n] - sum_left;
        /* find the best place to cut the left sequence
           by using binary search.
                a[0] a[1] ... a[j] | a[j+1] ... a[i] */
        auto iter = lower_bound(sum,sum + i,sum_left / 2.0);
        ll p = *iter;
        ll q = sum_left - p;
        iter += 1;
        ll p_ = *iter;
        ll q_ = sum_left - p_;
        if (abs(p_ - q_) < abs(p - q)){
            p = p_;
            q = q_;
        }
        iter -= 2;
        p_ = *iter;
        q_ = sum_left - p_;
        if (abs(p_ - q_) < abs(p - q)){
            p = p_;
            q = q_;
        }
#ifdef TEST
        cout << "p : " << p << " (" << p << ")" << endl;
        cout << "q : " << q << " (" << p + q << ")" << endl;
#endif
        /* find the best place to cut the right sequence. */
        iter = lower_bound(sum,sum + n + 1,sum_left + sum_right / 2.0);
        ll r = *iter - sum_left;
        ll s = sum[n] - (p + q + r);
        iter += 1;
        ll r_ = *iter - sum_left;
        ll s_ = sum[n] - (p + q + r_);
        if (abs(r_ - s_) < abs(r - s)){
            r = r_;
            s = s_;
        }
        iter -= 2;
        r_ = *iter - sum_left;
        s_ = sum[n] - (p + q + r_);
        if (abs(r_ - s_) < abs(r - s)){
            r = r_;
            s = s_;
        }
#ifdef TEST
        cout << "r : " << r << " (" << p + q + r << ")" << endl;
        cout << "s : " << s << " (" << p + q + r + s<< ")" << endl;
#endif
        /* update ans. */
        ans = min(ans,max({p,q,r,s}) - min({p,q,r,s}));
    }

#ifdef TEST
    cout << "----------ans----------" << endl;
#endif
    cout << ans << endl;

    delete[] a,sum;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    vector<bool> cleared(n+2, false);
    vector<ll> cnt(n+2, 0);
    ll ac = 0;
    ll wa = 0;
    for(int i = 0; i < m; i++){
        ll p;
        string s;
        cin >> p >> s;

        if(cleared[p] == false && s == "AC"){
            ac++;
            wa+=cnt[p];
            cleared[p] = true;
        }else if(cleared[p] == true && s == "AC"){
            ;
        }else if(cleared[p] == false && s == "WA"){
            cnt[p]++;
        }else if(cleared[p] == true && s == "WA"){
            ;
        }

    }
    cout << ac << " "<<wa<<endl;
    return 0;
}


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

#ifdef TEST
struct test {
    int ans;
} td[] = {
    {},
};
#endif

void
solver(long x)
{
    long n500, n5;
    n500 = x / 500;
    x -= n500 * 500;
    n5 = x / 5;
    printf("%ld\n", n500 * 1000 + n5 * 5);
}

int
main(int argc, char *argv[])
{
#ifdef TEST
    int tt;
    for(tt = 0; tt < sizeof(td) / sizeof(struct test); tt++) {
        solver();
        printf("%d\n", td[tt].ans);
    }
#endif
    long X;
    scanf("%ld", &X);
    solver(X);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int m=1e9+7;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fastio
    int ar[3];
    for(int i=0;i<3;++i) cin>>ar[i];
    int mx=max({ar[0],ar[1],ar[2]});
    cout<<accumulate(ar,ar+3,mx*9);
	return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int h, w;
	cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    rep(i,10) rep(j,10) cin >> c[i][j];
    rep(k,10) rep(i,10) rep(j,10) {
        if (c[i][j] > c[i][k] + c[k][j]) c[i][j] = c[i][k] + c[k][j];
    }
    int ans = 0, A;
    rep(i,h) rep(j,w) {
        cin >> A;
        if (A>=0) ans += c[A][1];
    }
	cout << ans << endl;
	return 0;
}


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

int main(){
  int N;
  char C;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>C;
    if(C=='Y'){
      cout<<"Four"<<endl;
      return 0;
    }
  }
  cout<<"Three"<<endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    map<int, int> M;
    for (int i = 0; i < k; ++i) {
        int aux;
        cin >> aux;
        M[aux]++;
    }
    while (true) {
        int aux = n;
        bool flag = true;
        while (aux != 0) {
            if (M[aux%10]) flag = false;
            aux /= 10;
        }
        if (flag) break;
        n++;
    }
    cout << n << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.close();
		int count = 0;
		for (int i = Math.min(a, b); i >= 1; i--) {
			if (a % i == 0 && b % i == 0) {
				count++;
				if (count == k) {
					System.out.println(i);
					return;
				}
			}
		}
	}

}


Measured memory_bytes: 21844
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');
static int n = int.Parse(input[0]);
static long w = long.Parse(input[1]);
static long answer = 0;
static long[][] dp = new long[1<<20][];//価値と重さ
static List<long> valueList = new List<long>();
static List<long> weightList = new List<long>();

	static void Main()
	{

    long[,] vertexes = new long[n,2];
    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      vertexes[i,0] = nums[0];
      vertexes[i,1] = nums[1];
      //Console.WriteLine(vertexes[i,0]);
    }

    for(int i = 0; i < (1<<20); i++)
    {
      dp[i] = new long[2];
    }

    for(long i = 0; i < (1<<Math.Min(20,n)); i++)//２進数で全通り試す
    {
      for(int j = 0; j < Math.Min(20,n); j++)//00001などに1があるか右側から見る
      {
        if((i&(1<<j)) != 0)
        {
          dp[i][0] += vertexes[j,0];
          dp[i][1] += vertexes[j,1];
        }
        //Console.WriteLine(i+" "+dp[i][0]+" "+dp[i][1]);
      }
    }

    var sorted = dp.OrderByDescending(a => a[0]).ThenBy(a => a[1]).ToList();

    long maxWeight = long.MaxValue;
    for(int i = 0; i < (1<<20); i++)
    {
      if(maxWeight > sorted[i][1])
      {
        valueList.Add(sorted[i][0]);
        weightList.Add(sorted[i][1]);
        maxWeight = sorted[i][1];
        //Console.WriteLine(sorted[i][0]+" "+sorted[i][1]);
      }
    }

    for(long i = 0; i < (1<<Math.Max(0,n-20)); i++)//２進数で全通り試す
    {
      long valueMemo = 0;
      long weightMemo = 0;
      for(int j = 0; j < Math.Max(0,n-20); j++)//00001などに1があるか右側から見る
      {
        if((i&(1<<j)) != 0)
        {
          valueMemo += vertexes[j+20,0];
          weightMemo += vertexes[j+20,1];
        }
      }
      if(weightMemo > w) continue;
      answer = Math.Max(answer,valueMemo+valueList[Search(0,valueList.Count()-1,w-weightMemo)]);
    }

		Console.WriteLine(answer);
	}

  static int Search(int min, int max, long w)//二分探索法で最小値を求める
  {
    while (true)
    {
      int mid = min + (max - min) / 2;
      if(Check(mid,w)) max = mid;//さらに小さくても成り立つかも
      else min = mid;

      if(max - min <= 1)
      {
        if(Check(min,w)) 
        {
          return min;//最小値で成り立つかの確認を優先
        }
        else
        {
          return max;
        }
      break;
      }  
    }
  }

  static bool Check(int testNum, long w)
  {
    //Console.WriteLine(testNum);
    if(w >= weightList[testNum]) return true;
    
    return false;
  }
  
}


Measured memory_bytes: 129608
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_2 100000
#define d9_7 1000000007
int main(void){
  int k,n;
  cin >> n>>k;
  string s;
  cin>>s;
  vector<int> accum(n,0);
  accum[0]=s[0]-'0';
  int num0=0;
  int num1=0;
  int nnn=0;
  rep(i,n){
    if(s[i]=='0'){
      num0++;
    }else{
      num1++;
    }
    if(i<n-1){
      if(s[i]=='0' && s[i+1]=='1'){
        nnn++;
      }
    }
  }
  //cout<<"a";
  if(s[n-1]=='0')nnn++;
  //kやたら多い場合
  if(nnn<=k){
    cout<<n<<endl;
    return 0;
  }
  //cout<<"b";
  vector<int> accum1;
  int cnt=1;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      cnt++;
    }else{
      accum1.push_back(cnt);
      cnt=1;
    }
  }
  //cout<<"c";
  accum1.push_back(cnt);

  int ini=s[0]-'0';
  int size=accum1.size();

/*rep(i,size){
  cout<<accum1[i]<<" ";
}
cout<<"ini "<<ini<<endl;*/
k--;

  vector<int> accum2(size);
  accum2[0]=accum1[0];
  rep(i,size-1){
    accum2[i+1]=accum1[i+1]+accum2[i];
  }
  int rmax=accum2[min(ini+k*2+1,size-1)];
  for(int now=ini+2;now+k*2<size;now+=2){
    //cout<<rmax<<" r ";
    rmax=max(rmax,accum2[min(now+k*2+1,size-1)]-accum2[now-2]);
  }
  //cout<<endl;
  cout<<rmax<<endl;
  return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long l,r,d,c=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
            c++;
    }
    cout<<c<<endl;
}


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

using ll=long long;
const ll MOD=1e9+7;
int main(){
    int n;
    cin>>n;
    vector<int> c(n);
    for(int i=0;i<n;i++) cin>>c[i];

    vector<set<int>> s(2*1e5+1);
    for(int i=0;i<n;i++) s[c[i]].insert(i);

    vector<ll> dp(n+1);
    dp[0]=true;
    for(int i=0;i<n;i++){
        dp[i+1]=dp[i];
        auto it=s[c[i]].find(i);
        if(it!=s[c[i]].begin()){
            it=prev(it);
            if(*it!=i-1){
                dp[i+1]+=dp[*it+1];
                dp[i+1]%=MOD;
            }
        }
        // cerr<<dp[i+1]<<" ";
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 21376
var n,ans,num:int64;
var i:longint;
var a:array[0..100020] of int64;
procedure qsort(l,r:int64);
var i,j,mid,t:int64;
begin
  i:=l;j:=r;mid:=a[(l+r)>>1];
  repeat
    while a[i]<mid do inc(i);
    while a[j]>mid do dec(j);
    if i<=j then begin
      t:=a[i];a[i]:=a[j];a[j]:=t;
      inc(i);dec(j);
    end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;
begin
  read(n);
  for i:=1 to n do read(a[i]);qsort(1,n);
  i:=1;
  while i<=n do
  begin
    num:=1;
    inc(ans);
    while (a[i]=a[i+1]) and (i<=n) do begin inc(i);inc(num);end;
    if num mod 2=0 then dec(ans);
    inc(i);
  end;
  writeln(ans);
end.

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=1; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<ll,ll>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  int n,k;
  cin >> n >>k ;
  vector<int> a(n+1);
  rep(i,n+1)cin>>a[i];
  rep(ki,k+1){
    vector<int> b(n+2,0);
    rep(i,n+1){
      int l=max(1,(int)(i-a[i]));
      int r=min(n+1,(int)(i+a[i]+1.5));
      b[l]++;b[r]--;
    }
    rep(i,n+1)b[i+1]+=b[i];
    b.pop_back();
    if(a==b)break;
    a=b;
  }
  rep(i,n+1)cout<<a[i]<<' ';
  cout<<endl;
}


Measured memory_bytes: 4836
MOD = 10**9 + 7

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs

def getCombNs(n, invs, MOD):
    combNs = [1] * (n//2+1)
    for k in range(1, n//2+1):
        combNs[k] = (combNs[k-1] * (n-k+1) * invs[k]) % MOD
    return combNs + combNs[:(n+1)//2][::-1]

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

invs = getInvs(N, MOD)

comb1s = getCombNs(N-K+1, invs, MOD)
comb2s = getCombNs(K-1, invs, MOD)

anss = []
for i in range(1, K+1):
    if N-K+1 < i or K-1 < i-1:
        ans = 0
    else:
        ans = comb1s[i] * comb2s[i-1] % MOD
    anss.append(ans)

print('\n'.join(map(str, anss)))


Measured memory_bytes: 39536
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

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

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
ll N, W, offset;
vector<vector<ll>> v(4, vector<ll>());






//サブ関数
//入力
void input()
{
	cin >> N >> W;
	ll a, b;
	cin >> a >> b;
	v[0].push_back(b);
	offset = a;

	REP(i, N-1) {
		cin >> a >> b;
		a -= offset;
		v[a].push_back(b);
	}
}


//計算
void calc()
{
	for (auto& row : v) {
		sort(row.begin(), row.end());
		row.push_back(0);
		reverse(row.begin(), row.end());
		REP(i, (int)row.size() - 1)row[i + 1] += row[i];
	}

	ll res = 0;
	REP(n0,v[0].size())REP(n1,v[1].size())
		REP(n2, v[2].size())REP(n3, v[3].size()) {
		ll weight = offset * (n0 + n1 + n2 + n3);
		weight += 1 * n1 + 2 * n2 + 3 * n3;
		if (weight > W)break;

		ll tmp = v[0][n0] + v[1][n1] + v[2][n2] + v[3][n3];
		res = max(res, tmp);
	}
	cout << res << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int prime[300001];

int main() {

  int n;

  int count;


  prime[0]=prime[1]=0;

  for(int i=2;i<=300000;i++) prime[i]=1;

  for(int i=2;i<=sqrt(300000);i++) {

    if(prime[i]==1) {

      for(int j=2*i;j<=300000;j+=i) prime[j]=0;

    }

  }

  //for(int i=0;i<=50;i++)  cout << prime[i] << " ";

  while(cin >> n,n) {

    count=0;

    for(int i=n+1;i<=2*n;i++) {

      if(prime[i]==1) count++;

    }

    cout << count << endl;

  }

  return 0;

}

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

long long GCD(long long X, long long Y) {
	if (Y == 0) return X;
	return GCD(Y, X % Y);
}

int main() {
	long long T;
	cin >> T;
	for (int i = 0; i < T; i++) {
		long long A, B, C, D;
		cin >> A >> B >> C >> D;
		if (A < B) cout << "No" << endl;
		else if (D < B) cout << "No" << endl;
		else if (B <= C + 1) cout << "Yes" << endl;
		else {
			if (C - A % GCD(B, D) >= B - GCD(B, D)) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 256
from bisect import *
N = int(input())
T, A = map(int, input().split())
H = []
for i, h in enumerate(map(int, input().split())):
    H.append((T-h*0.006, i))
H.sort()
H2 = [h for h, _ in H]
i = bisect_left(H2,A)
if i==N:
    print(H[-1][1]+1)
elif abs(H[i-1][0]-A) > abs(H[i][0]-A):
    print(H[i][1]+1)
else:
    print(H[i-1][1]+1)

Measured memory_bytes: 63704
# %%
class Stack:
    def __init__(self, size):
        self.size = size
        self.stack = [None] * self.size
        self.tail = 0

    def push(self, new):
        self.stack[self.tail] = new
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]


max_size = 105

li = list(map(str, input().split()))
#li = ['1', '2', '+', '3', '4', '-', '*']
N = len(li)
stack = Stack(max_size)

for i in range(N):
    ch = li[i]
    if ch in ['+', '-', '*']:
        num_2 = stack.pop()
        num_1 = stack.pop()
        if ch == '+':
            stack.push(num_1 + num_2)
        elif ch == '-':
            stack.push(num_1 - num_2)
        else:
            stack.push(num_1 * num_2)
    else:
        stack.push(int(ch))

print('{}'.format(stack.stack[0]))


# %%



Measured memory_bytes: 5600
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(std::vector<long long> h, std::vector<long long> m, long long k){
    int t1 = h[0] * 60 + m[0];
    int t2 = h[1] * 60 + m[1];
    int diff = t2 - t1;
    cout << diff - k << endl;
}


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


Measured memory_bytes: 3696
from datetime import date

if __name__ == '__main__':
    while True:
        # ??????????????\???
        month, day = [int(x) for x in input().split(' ')]
        if month == 0:
            break

        # ?????\????¨??????¨???????????????
        dt = date(2004, month, day)
        print(dt.strftime('%A'))

Measured memory_bytes: 8024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    ll ans;
    cin>>s;
    ans=0;
    fr(i,s.size()){
        ans+=s[i]-48;
    }
    if(ans%9==0) cout<<"Yes";
    else cout<<"No";
}

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

const ll MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector< ll > A(N), B(N);
  REP(i,N) {
    cin >> A[i];
    B[i] = A[i];
  }
  for( int i=N-1; i>0; i-- )  {
    B[i-1] = (B[i-1] + B[i]) % MOD;
  }

  ll ans = 0;
  for (int i=0; i<N-1; i++ ) {
    ans = (ans + (A[i] * B[i+1] % MOD)) % MOD;
  }

  cout << ans << endl;
}


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

using namespace std;

#define allof(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define exists(s, e) (s.find(e)!=s.end())
#define INF 0x3f3f3f3f
#define f first
#define s second
#define endl '\n'
#define mp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl;

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

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

void solve() {
    int n; cin >> n;
    vector<int> v(n);
    int maxx = 0;
    for(int i=0; i<n; i++) {
        cin >> v[i];
        maxx = max(maxx, v[i]);
    }
    int sum = 0;
    bool used = false;
    for(int i=0; i<sz(v); i++) {
        if(v[i]==maxx and not used) {
            sum += (v[i]/2);
            used = true;
            continue;
        }
        sum += v[i];
    }
    cout << sum << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,t,a,i,s=0,r;
    cin>>d>>t;
    for(i=0;i<t;i++){
        cin>>a;
        s+=a;
    }
    r=d-s;
    if(r<0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
    return 0;

}


Measured memory_bytes: 3632
<?php
        // Input
        do
        {
                $input = preg_split('/ /', trim(fgets(STDIN)));
                if(2 != count($input))
                {
                        continue;
                }

/*
                if( 0 < $input[0] and
                    100 >= $input[1] and
                    0 <= $input[0] * $input[1] and
                    100 >= $input[0] * $input[1]
*/
                if( 0 < $input[0] and
                    100 >= $input[1]
                )
                {
                        break;
                }
        } while(1);

        // 定義
        $r = (int)$input[0];    // 行
        $c = (int)$input[1];    // 列
        $array_table = array();
        $sum_r = array();

        for($loop_r = 0; $loop_r < $r; $loop_r++)
        {
                for($loop_c = 0; $loop_c < $c+1; $loop_c++)
                {
                        $array_table[$loop_r][$loop_c] = 0;
                        $sum_r[$loop_c] = 0;
                }
        }

        // 計算
        for($loop_r = 0; $loop_r < $r; $loop_r++)
        {
                // Input
                do
                {
                        $input_tmp = preg_split('/ /', trim(fgets(STDIN)));
                        if( $c == count($input_tmp) )
                        {
                                break;
                        }
                } while(1);

                $sum_c = 0;
                for($loop_c = 0; $loop_c < $c; $loop_c++)
                {
                        $sum_c += $input_tmp[$loop_c];
                        $sum_r[$loop_c] += $input_tmp[$loop_c];
                }
                $sum_r[$c] += $sum_c;

                array_push($input_tmp, $sum_c);
                $array_table[$loop_r] = $input_tmp;
        }
        $array_table[$r] = $sum_r;

        // Output
        for($loop_r = 0; $loop_r < count($array_table); $loop_r++)
        {
                echo $array_table[$loop_r][0];
                for($loop_c = 1; $loop_c < count($array_table[$loop_r]); $loop_c++)
                {
                        echo " " . $array_table[$loop_r][$loop_c];
                }
                echo "\n";
        }

?>


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

vector<long long int> p;	// 1 3 6 10 수열을 담은 벡터

void init()
{
	p.push_back(0);
	p.push_back(0);
	p.push_back(1);
	p.push_back(3);
}

long long int pb(long long int x)
{
	long long int l = p.size();
	if (x <= l - 1)
		return p[x];
	else
		for (int i = l; i <= x; i++)
			p.push_back(p[i - 1] + i - 1);
	return p[x];
}

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

	init();

	vector<long long int> a;	// 입력 순서대로 담은 벡터
	int b[200001]{};	// 각 수 별로 몇 개인지
	int n;
	long long int sum(0);
	long long int temp(0);
	cin >> n;
	a.push_back(temp);
	
	for (int i = 1; i <= n; i++)
	{
		cin >> temp;
		a.push_back(temp);
		b[a[i]]++;
		sum = sum + pb(b[a[i]]) - pb(b[a[i]] - 1);
	}

	for (int i = 1; i <= n; i++)
	{
		cout << sum - pb(b[a[i]]) + pb(b[a[i]] - 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 6756
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

K, N = map(int, input().split())
A = list(map(int, (input().split())))
A.append(K+A[0])

ans = K
for i in range(N):
    ans = min(ans, K-(A[i+1]-A[i]))

print(ans)

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

struct lunlun {
	string s = "";
	int l = 0;
	void inc(int pos = 0) {
		if (pos == l) {
			s += '1';
			l++;
			tomin(pos);
			return;
		}
		s[pos]++;
		if (s[pos] == '9' + 1 or (l > 1 and s[pos] == s[pos + 1] + 2)) {
			inc(pos + 1);
			tomin(pos + 1);
		}
	}
	void tomin(int qtd) {
		for (int i = qtd - 1;i >= 0;i--) {
			s[i] = max(s[i + 1] - 1, (int)'0');
		}
	}
	void print() {
		loop(l) {
			cout << s[l - i - 1];
		}
		cout << endl;
	}
};

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

	int k;
	cin >> k;
	lunlun s;
	loop(k) {
		s.inc();
	}
	s.print();
	return 0;
}



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

struct UnionFind {
    vector<int> par, rank;
    UnionFind(int n = 1) {
        init(n);
    }
    void init(int n = 1) {
        par.resize(n + 1);
        rank.resize(n + 1);
        for(int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x) {
        if(par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        par[x] = y;
        return true;
    }
};
int R[100500], C[100500];
bool r[100500], c[100500];
int main() {
    int N;
    cin >> N;
    UnionFind uni(N + 1);
    for(int i = 1; i <= N; i++) {
        cin >> R[i] >> C[i];
        if(r[R[i]] or c[C[i]]) {
            cout << -1 << endl;
            return 0;
        }
        r[R[i]] = true;
        c[C[i]] = true;
        uni.merge(R[i], C[i]);
    }
    int ans = N;
    for(int i = 1; i <= N; i++) {
        if(uni.root(i) == i) ans--;
        //cerr << uni.root(i) << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5720
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
//#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}

int fun(int n){
	int ans=0;
	rep(i,n){
		if(n%(i+1)==0){
			ans++;
		}
	}
	return ans;
}
		


int main(){
	int ans=0;
	int n;
	cin>>n;
	FOR(i,1,n+1){
		if( i%2==1 && fun(i)==8){
			ans++;
		}
	}
	cout<<ans<<endl;

}


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

int n, ans;
int h[20];
bool flag;

int main(){
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> h[i];

    ans = 1;
    for (int i = 1; i < n; ++i){
        flag = true;
        for (int j = 0; j < i; ++j){
            flag = (h[j] <= h[i]);
            if (!flag) break;
        }
        ans += flag;
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	int A, B; cin >> A >> B;
	vector<ll> X(N, 0LL);
	rep (i, N) cin >> X[i];
	ll res = 0LL;
	for (int i = 0; i < N - 1; ++i){
		res += (ll)min((X[i+1] - X[i]) * (ll)A, (ll)B);
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100000

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

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



Measured memory_bytes: 2108
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
 
long long n, s;

long long  f(long long b, long long n) { 
    if (b > n) return n;
    else return f(b, n/b) + n%b; 
}

void solve(){
    if (n < s) {
        cout << -1 << endl;
        return ;
    }
    if (n == s) {
        cout << n+1 << endl;
        return ;
    }

    long long rn = floor(sqrt(n));
    long long b = 2;
    while (b<=rn){
        if (f(b, n) == s) {
            cout << b << endl;
            return ;
        } 
        b++;
    }

    int p = rn;
    while (p > 0) {
        b = (n-s)/p + 1;
        if (b > p && f(b, n) == s) {
            cout << b << endl;
            return ;
        }
        p--;
    }

    cout << -1 << endl;
    return ;
}

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

    return 0;
}

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

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  char a[n][m];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  int dp[n][m];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      dp[i][j] = 1000000000;
    }
  }
  if(a[0][0] == '.'){
    dp[0][0] = 0;
  }else{
    dp[0][0] = 1;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      if(!i && !j){
        continue;
      }
      if(!i){
        if(a[i][j] == '.'){
          dp[i][j] = dp[i][j-1];
        }else{
          if(a[i][j-1] == '#'){
            dp[i][j] = dp[i][j-1];
          }else{
            dp[i][j] = dp[i][j-1]+1;
          }
        }
      }else if(!j){
        if(a[i][j] == '.'){
          dp[i][j] = dp[i-1][j];
        }else{
          if(a[i-1][j] == '#'){
            dp[i][j] = dp[i-1][j];
          }else{
            dp[i][j] = dp[i-1][j]+1;
          }
        }
      }else{
        if(a[i][j] == '.'){
          dp[i][j] = min(dp[i][j-1], dp[i-1][j]);
        }else{
          if(a[i][j] == a[i-1][j]){
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
          }else{
            dp[i][j] = min(dp[i][j], dp[i-1][j]+1);
          }
          if(a[i][j] == a[i][j-1]){
            dp[i][j] = min(dp[i][j], dp[i][j-1]);
          }else{
            dp[i][j] = min(dp[i][j], dp[i][j-1]+1);
          }
        }
      }
    }
  }
  cout << dp[n-1][m-1];
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
 
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;

int main(){
    ll n;
    cin >> n;
    vll a(n),v((ll)1000001,0);
    vector<bool> found(1000001,false);
    rep(i,0,n){
        cin >> a[i];
        v[a[i]]++;
    }
    sort(all(a));
    ll ans = 0;
    rep(i,0,n){
        if(!found[a[i]] && v[a[i]] == 1) ans += 1;
        if(!found[a[i]]){
            for(int j = a[i]; j <= a[n - 1]; j += a[i]){
                found[j] = true;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 12760
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a1: usize = iterator.next().unwrap().parse().unwrap();
    let a2: usize = iterator.next().unwrap().parse().unwrap();
    let a3: usize = iterator.next().unwrap().parse().unwrap();

    if a1 + a2 + a3 >= 22 {
        return "bust".to_string();
    }

    return "win".to_string();
}


Measured memory_bytes: 4352
xy = []
readlines.map(&:chomp).each_with_index{|line, i|
  xy[i] = line.split(",").map(&:to_f)
}
sum = 0.0
a = Math.sqrt((xy[1][0]-xy[0][0])**2 + (xy[1][1]-xy[0][1])**2)
2.upto(xy.size-1){|i|
  b = Math.sqrt((xy[i][0]-xy[0][0])**2 + (xy[i][1]-xy[0][1])**2)
  c = Math.sqrt((xy[i][0]-xy[i-1][0])**2 + (xy[i][1]-xy[i-1][1])**2)
  z = (a + b + c) / 2.0
  sum += Math.sqrt(z*(z-a)*(z-b)*(z-c))
  a = b
}

puts "%.6f" % sum

Measured memory_bytes: 8740