akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18+5
#define mod 1000000007
#define MAXN 100005
#define ll long long
#define pb push_back
#define sortv(v) sort(v.begin(),v.end())
#define tc(t) int t;cin>>t;while(t--)
#define copy copy_n
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define frr(i,a,b) for(long long i=a;i>=b;i--)
#define frn(i,a,b,n) for(long long i=a;i<=b;i=i+n)
#define gcd(x,y) __gcd(x,y)
#define ld long double
#define um unordered_map
#define mkp make_pair
#define b_s binary_search
#define des greater<ll>()
#define fi first
#define se second
ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
void input(ll a[], ll sz) {fr(i, 0, sz) cin >> a[i];}
void print(ll a[], ll sz) {fr(i, 0, sz) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}}
ll maxr(ll a[], ll sz) {ll ma; fr(i, 0, sz) {if (i == 0) ma = a[i]; else if (a[i] > ma) ma = a[i];} return ma;}
ll minr(ll a[], ll sz) {ll mi; fr(i, 0, sz) {if (i == 0) mi = a[i]; else if (a[i] < mi) mi = a[i];} return mi;}
ll isprm(ll n) {
    if (n <= 1)  return 0;
    if (n <= 3)  return 1;
    if (n % 2 == 0 || n % 3 == 0) return 0;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;
    return 1;
}
/*ll spf[MAXN];
void sieve()
{
    spf[1]=1;
    for (ll i=2; i<MAXN; i++)
        spf[i] = i;
    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for(ll i=3;i*i<MAXN;i++)
    {
        if (spf[i]==i)
        {
            for (int j=i*i;j<MAXN;j+=i)
                if (spf[j]==j)
                    spf[j]=i;
        }
    }
}*/
ll power(ll x, ll y, ll p = mod)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
//a+b=xor(a,b)+2*(a&b)//
struct comp
{
    bool operator()(const pair<ll, ll> &a,
                    const pair<ll, ll> &b)const
    {
        if (a.fi == b.fi)
        {
            return (a.se > b.se); //second elem in descending
        }
        return (a.first < b.first);//first elem in ascending
    }
};

ll n;
ld p[3005],dp[3005][3005];

ld solve(ll i,ll h)
{
    ll k=(n/2)+1;
    if(h>=k && i>=n)
    return 1;
    else if(i>=n)
    return 0;
    if(dp[i][h]!=-1)
    return dp[i][h];
    ld a=p[i]*solve(i+1,h+1);
    a+=(1-p[i])*solve(i+1,h);
    dp[i][h]=a;
    return dp[i][h];
}







int main()
{
    fio;
    cin>>n;
    fr(i,0,n)
    cin>>p[i];
    fr(i,0,3005)
    fr(j,0,3005)
    dp[i][j]=-1;
    cout<<fixed<<setprecision(15)<<solve(0,0)<<"\n";
    return 0;
}


Measured memory_bytes: 145164
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-7;
const double PI  = acos(-1.0);

set<string> dfs(map<string,vs> &m,string &member,map<string,set<string> > &dp){
	if(EXIST(dp,member)){
		return dp[member];
	}
	if(!EXIST(m,member)){
		set<string> ret;
		ret.insert(member);
		return ret;
	}
	set<string> ret;
	REP(i,m[member].size()){
		set<string> s=dfs(m,m[member][i],dp);
		ret.insert(ALL(s));
	}
	return dp[member]=ret;
}

int main(){
	int n;
	while(cin>>n,n){
		map<string,vs> m;
		string first_group;
		REP(i,n){
			string s;
			cin>>s;
			string group;
			int pos=0;
			while(s[pos]!=':'){
				group+=s[pos++];
			}
			if(i==0){
				first_group=group;
			}
			pos++;
			m[group]=vs();
			do{
				string member;
				while(s[pos]!=','&&s[pos]!='.'){
					member+=s[pos++];
				}
				m[group].push_back(member);
			}while(s[pos++]!='.');
		}
		map<string,set<string> > dp;
		set<string> ans;
		REP(i,m[first_group].size()){
			set<string> r=dfs(m,m[first_group][i],dp);
			ans.insert(ALL(r));
		}
		cout<<ans.size()<<endl;
	}
}

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

int main()
{
    // 入力
    int64_t N;
    cin >> N;

    // 1から割っていてNを二つに分ける
    // 桁数の最小値を更新していく
    int64_t res = 99;
    for(int64_t a = 1; a <= N; a++)
    {
        if(N % a == 0)
        {
            int64_t b = N / a;
            int c = max(to_string(a).length(), to_string(b).length());
            if(c < res)
            {
                res = c;
            }
        }
        // A, B の桁数が同じか、A の方が大きくなったら終了（計算コスト削減）
        //if(to_string(a).length() >= to_string(b).length())
        if(to_string(a).length() >= to_string(N).length()/2+2)
        {
            //cout << "a: " << a << " b: " << b << endl;
            break;
        }
    }

    // 出力
    cout << res << endl;
}

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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    rotate(s.begin(), s.begin() + 1, s.end());
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int N,A,B,C;
vector<int> L(10);

int dfs(int i,int a,int b,int c){
  // cout << "i:" << i << " a:" << a << " b:" << b << " c:" << c << endl;
  if (i >= N){
    if(min({a,b,c})>0){
      return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    }else{
      return 1e8;
    }
  }
  int ret0 = dfs(i+1,a,b,c);
  int ret1 = dfs(i+1,a+L[i],b,c) + 10;
  int ret2 = dfs(i+1,a,b+L[i],c) + 10;
  int ret3 = dfs(i+1,a,b,c+L[i]) + 10;
  return min({ret0,ret1,ret2,ret3});
}

int main(){
  cin >> N >> A >> B >> C;
  rep(i,N){
    cin >> L[i];
  }
  cout <<  dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int A=sc.nextInt();
		int[] cards=new int[N];
		int sum=0;
		for(int i=0; i<N; i++) {
			cards[i]=sc.nextInt();
			sum+=cards[i];
		}
		long[][][] dp=new long[N+1][sum+1][N+1];	//dp[今までに見たカードの枚数][部分和][部分和が達成できる枚数]
		//部分和が達成できる枚数とは 7が[1,2,4]でつくれるなら 3。 7が[1,1,1,1,1,1,1]で作れるなら7。
		//dp[i][j][k]にはいっているのは,今までに見たカードの枚数i枚の中で、部分和jをk枚で達成できる場合の数である
		for(int i=0; i<=N; i++) {
			for(int j=0; j<=sum; j++) {
				for(int k=0; k<=N; k++) {
					dp[i][j][k]=0;		//クソみたいな3重ループから繰り出される初期化
				}
			}
		}
		dp[0][0][0]=1;		//何もなくても総和0は達成できるためdp[0][0][0]は1
		for(int i=0; i<N; i++) {
			for(int j=0; j<sum; j++) {
				for(int k=0; k<=i; k++) {
					if(dp[i][j][k]>0) {
						dp[i+1][j][k]+=dp[i][j][k];	//いま見ているカードを使わない 総和はそのまま 部分和を達成する枚数もそのまま
						dp[i+1][j+cards[i]][k+1]+=dp[i][j][k];	//いま見ているカードを使う 総和は増える　部分和を達成する枚数も増える
					}
				}
			}
		}
		long SOUWA=0;		//求める場合の数の総和
		for(int i=1; i<=Math.min((sum/A),N); i++) {
			SOUWA+=dp[N][i*A][i];		//平均がAになる　つまり i枚で合計がiAになるので dp[N][i*A][i]を足す。
			//dp[N][hoge][hoge]は最後のカードまで見た状態を見ている
		}
		pl(SOUWA);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 84800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
long long a[100000+10];
bool cmp(long long x,long long y)
{
	return x>y;
} 
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
    	int i;
    	map<long long,long long>ss;
    	scanf("%lld",&a[0]);
    	for(i=1;i<n;i++)
    	scanf("%lld",&a[i]);
    	sort(a,a+n,cmp); 
    	ss[a[0]]=1;
    	for(i=1;i<n;i++)
    	{
    		if(a[i]==a[i-1]) ss[a[i]]++;
			else ss[a[i]]=1; 
		}
		long long s1[3];
		int k=0,t=0,t1=0;
    	map<long long,long long>::reverse_iterator it;
    	for(it=ss.rbegin();it!=ss.rend();it++)
    	{
    		if(it->second>=4&&k==0) 
			{
				printf("%lld\n",(it->first)*(it->first));
				t1=1;
				break;
			}
    		else if(it->second>=2)
    			s1[k++]=it->first;
			if(k>=2) 
			{
				t=1;
				break;
			}
		}
		//printf("t=%d\n",t);
		if(!t1)
		{
			if(t) printf("%lld\n",s1[0]*s1[1]);
	        else printf("%lld\n",0);
		}
	        	
	}
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
int a[100010],b[100010];
int ans;
pii p[100010];
int len;
void solve(){
	for(int i=2;i<=a[0];i++){
		p[++len]=mp(b[1],a[i]);
		b[1]-=a[i];
	}
	for(int i=2;i<=b[0];i++){
		p[++len]=mp(a[1],b[i]);
		a[1]-=b[i];
	}
	p[++len]=mp(a[1],b[1]);
	ans=a[1]-b[1];
}
void solvee(int x,int cnt){
	if(cnt>3){
		p[++len]=mp(x,x);
		p[++len]=mp(0,x);
		if(x<=0){
			a[0]=1;
			a[a[0]]=-x;
			b[0]=0;
			for(int i=1;i<=cnt-3;i++)b[++b[0]]=x;
		}else{
			b[0]=1;
			b[b[0]]=-x;
			a[0]=0;
			for(int i=1;i<=cnt-3;i++)a[++a[0]]=x;
		}
		solve();
	}else if(cnt==2){
		p[++len]=mp(x,x);
		ans=0;
	}else{
		ans=x;
		p[++len]=mp(x,x);
		if(x>0)ans=x,p[++len]=mp(x,0);
		else ans=-x,p[++len]=mp(0,x);
	}
}
void print(){
	cout<<ans<<endl;
	for(int i=1;i<=len;i++)cout<<p[i].F<<' '<<p[i].S<<endl;
}
signed main(){
	cin>>n;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		if(x>0)a[++a[0]]=x;
		else b[++b[0]]=x;
	}
	if(a[0]==0){
		sort(b+1,b+b[0]+1);
		if(b[1]==b[b[0]]){
			solvee(b[1],b[0]);
			print();
			return 0;
		}
		p[1].F=b[b[0]],p[1].S=b[1];
		len++;
		a[++a[0]]=b[b[0]]-b[1];
		for(int i=1;i<b[0]-1;i++)b[i]=b[i+1];
			b[0]-=2;
		// for(int i=1;i<=b[0];i++)cout<<b[i]<<' ';
		// 	puts("");
		solve();
	}else if(b[0]==0){
		sort(a+1,a+a[0]+1);
		if(a[1]==a[a[0]]){
			solvee(a[1],a[0]);
			print();
			return 0;
		}
		p[1].F=a[1],p[1].S=a[a[0]];
		b[++b[0]]=a[1]-a[a[0]];
		len++;
		for(int i=1;i<a[0]-1;i++)a[i]=a[i+1];
			a[0]-=2;
		solve();
	}else solve();
	print();
	return 0;
}//-4 -3 -2 -1

Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

S = input()
parts = [S[i:i + 3] for i in range(len(S) - 2)]

ans = 100000

for s in parts:
    if abs(int(s) - 753) < ans:
        ans = abs(int(s) - 753)

print(ans)


Measured memory_bytes: 3060
i,j=map(int,input().split())
listA=[]
for n in range(i):
    listA.append(list(map(int,input().split())))
    listA[n].append(sum(listA[n]))
listA.append([])
for n in range(j+1):
    number=0
    for m in range(i):
        number+=listA[m][n]
    listA[i].append(number)
for n in range(i+1):
    print(' '.join(map(str,listA[n])))



Measured memory_bytes: 5696
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a<b){
if(b<c){
printf("%d %d %d\n",a,b,c);
}else if(a<b){
printf("%d %d %d\n",a,c,b);
}else{
printf("%d %d %d\n",c,a,b);
}
}else if(b>c){
printf("%d %d %d\n",c,b,a);
}else{
if(a<c){
printf("%d %d %d\n",b,a,c);
}else{
printf("%d %d %d\n",b,c,a);
}
}
return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int>;
using P = pair<int,int>;


int main()
{
    int n,k;cin >>n>>k;
    int ans=0;
    while(n>0){
        n/=k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}

int main()
{
    ll k, x;
    cin >> k >> x;
    if(500*k >= x){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

int main() {
  string s;
  cin>>s;
  int count=0;
  for(int i=0;i<s.size()-1;i++){
    if(s.at(i)!=s.at(i+1)){
      count++;
    }
  }
  cout<<count;
}

Measured memory_bytes: 512
import math
a,b,h,m = map(int, input().split())

rb = h*(360/12) + m*1/2
ra = m*(360/60)

ang = abs(rb - ra)
if 360-ang<=180:
      ang = 360 - ang
      ang = math.radians(ang)
else:
      ang = math.radians(ang)
#print(math.cos(ang))
ans =  a**2 + b**2 - 2*a*b*(math.cos(ang))
print(math.sqrt(ans))

Measured memory_bytes: 9520
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    string s;
    cin>>s;
    bool ans=false;
    if(s.size()<4)ans=false;
    else if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')ans=true;
    
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int w[n];
    for(int i = 0; i < n; i++) cin >> w[i];
    int min = 10000;
    for(int i = 0; i < n; i++){
        int s1 = 0, s2 = 0;
        for(int j = 0; j <= i; j++) s1 += w[j];
        for(int j = i + 1; j < n; j++) s2 += w[j];
        if(min > abs(s1 - s2)) min = abs(s1 - s2);
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  char s[100000];
  int i = 0;
 
  if(scanf("%s",s));
 
  //printf("iA= %d",i);
  while(1){
    if(strncmp("dream",&s[i],5)==0){
      i += 5;
      //printf("iB= %d",i);
      if(strncmp("er",&s[i],2)==0 && strncmp("era",&s[i],3)!=0){
        i += 2;
         //printf("iBC= %d",i);
      }
    }
    else if(strncmp("erase",&s[i],5)==0){
      i += 5;
       //printf("iC= %d",i);
      if(strncmp("r",&s[i],1)==0 /*&& strncmp("ra",&s[i],2)!=0*/){
        i += 1;
         //printf("iD= %d",i);   
      }
    } 
    else if(s[i] == '\0'){
      printf("YES");      
      break;
    }
    else{
      printf("NO");
      break;
    }
  }
  
  //if(noFrag ==0)
  //  printf("YES");
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, j, n, A[100][100], u, k, v;

  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  A[i][j] = 0;
	}
    }

  for(i = 0; i < n; i++)
    {
      scanf("%d%d",&u,&k);
      u--;
      for(j = 0; j < k; j++)
	{
	  scanf("%d",&v);
	  v--;
	  A[u][v] = 1;
	}
    }

  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n-1; j++)
	{
	  printf("%d ",A[i][j]);
	}
      printf("%d\n",A[i][j]);
    }
  
  return 0;
}



Measured memory_bytes: 2132
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)1e5 + 228;

using namespace std;

int n, k, depth[N], a[N], ans;
vector < int > g[N];

void dfs(int v, int pr)
{
	for (auto to : g[v])
	{
		if (to == pr)
			continue;
		dfs(to, v);
		if (v != 1 && depth[to] + 1 == k)
		{
			ans++;
		}
		else
			depth[v] = max(depth[v], depth[to] + 1);
	}
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d%d", &n, &k);
	forn(i, n)
		scanf("%d", &a[i]);
	//~solve
	if (a[1] != 1)
		ans++;
	for (int i = 2; i <= n; i++)
		g[a[i]].pb(i);
	dfs(1, -1);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 12800
/*input
5
*/
#include <bits/stdc++.h>
using namespace std; 
#define int long long int
#define max(x, y) ((x) > (y) ? (x) :(y))
#define pii pair< int , int> 
#define vi vector<int>
#define REP( i , st , en ) for ( int i =st; i < (int)en; i++)
#define REPD( i , en , st ) for ( int i =en; i >= (int)st; i--)
#define SZ(a) (int)a.size()
#define all(v) v.begin() , v.end()
#define F first
#define S second
#define bitch_i_m_on_fiyaah_yeahhhh ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod = 998244353;
// const int mod = 1e9+7;
ostream& operator << ( ostream&  o, vector<int> s){for ( int i = 0;  i < (int)s.size() ; i++)o << s[i] << " ";o << "\n";return o;}
void  add( int &a, int b){a = a + b;if ( a< 0 ) a += mod; if ( a> mod ) a-= mod;}
void sub( int &a, int b){a = a - b;if ( a < 0) a += mod;}
int mul( int a , int b){return ((a %mod) * (b %mod) ) %mod;}
int exp( int a , int pow){ return (pow == 0 ? 1 : ( pow & 1  ? mul ( a ,exp( mul(a, a) , pow /2) ) : exp(mul(a ,a) , pow/2)));}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
// const int inf = 1e18;
const int maxn = 6e5 +5;
void solve(int test ) 
{	
		int  n ; set<int> primes;
		cin >> n;
		if ( n == 2){
			cout << 1;
			return;
		}
		for ( int i =2; i * i <= n ; i++){
			if ( n% i ==  0) {
				int temp = n ;
				while( temp %i  == 0) temp /=i;
				if ( temp % i == 1) primes.insert(i); 
			}
		}
		n-=1;
		for ( int i =2; i*i <= n ;  i ++ ) {
				if ( n % i == 0 ) { primes.insert(i);
					if ( n /i != i) primes.insert( n / i);
				}
		}
		cout << SZ(primes) + 2;
}
signed main(){
	bitch_i_m_on_fiyaah_yeahhhh
	int t =1; 
	// cin >> t;
	for ( int i = 0 ; i < t; i++)
	solve(i+1 );
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
// #define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 1e16;
const int upper = (int) 2e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

bool check (int a, int b) {
	return (b >= 1 and b <= 12);
}
signed main () {
	start_routine();
	speed();
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif	

	string s; cin >> s;
	int a = (s[0] - '0') * 10 + (s[1] - '0');
	int b = (s[2] - '0') * 10 + (s[3] - '0');
	bool yymm = check(a, b);
	bool mmyy = check(b, a);
	if (mmyy and yymm) {
		cout << "AMBIGUOUS";
	}
	else if (mmyy) {
		cout << "MMYY";
	}
	else if (yymm) {
		cout << "YYMM";
	}
	else {
		cout << "NA";
	}
 	end_routine();		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define f first
#define s second
#define mp make_pair
#define sz size()
#define ll long long
int n, W;
ll w[101], v[101];
ll dp[101][(int)1e5+10];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> W;
	for(int i = 1; i <= n; ++i) cin >> w[i] >> v[i];
	for(int i = 0; i <= W; ++i) dp[0][i] = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j <= W; ++j) {
			if(w[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[n][W];
	return 0;
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    int num;
    num = 0;
    int max;
    max = 0;
    for(int i=0; i<n; i++){
        if(h[i]>=max){
            max = h[i];
        }
        if(h[i]>=max){
            num++;
        }
    }
    cout << num << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int s;
  cin>>s;
  vector<int>f(1000000);
  f.at(0)=s;
  rep(i,1000000-1){
    if(f.at(i)%2==0)f.at(i+1)=f.at(i)/2;
    else f.at(i+1)=3*f.at(i)+1;
  }
  for(int i=0;i<1000000-1;i++){
    for(int j=i+1;j<1000000;j++){
      if(f.at(i)==f.at(j)){
        cout<<j+1<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4096
import java.io.*;// 从这行开始复制，这是第一行
import java.util.*;

public class Main {

    private static void fun(int h1, int m1, int h2, int m2, int k) {
        int mm1 = h1 * 60 + m1;
        int mm2 = h2 * 60 + m2;

        System.out.println(mm2-mm1-k);
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        int h1 = sc.nextInt();
        int m1 = sc.nextInt();
        int h2 = sc.nextInt();
        int m2 = sc.nextInt();
        int k = sc.nextInt();

        fun(h1, m1, h2, m2, k);
    }
}

Measured memory_bytes: 35700
n = int(input())
S = sorted([int(input()) for _ in range(n)])
if sum(S)%10 != 0:
    print(sum(S))
else:
    # 10の倍数以外
    a = 0
    for s in S:
        if s%10 != 0:
            print(sum(S) - s)
            break
    else:
        print(0)

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

int abs(int x){
	return x>0?x:-1*x;
}

int min(int a, int b){
	return a<b?a:b;
}

int max(int a, int b){
	return a>b?a:b;
}

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d",&n);
	int a[n][3],dp[n][3];
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for(int i=1;i<n;i++){
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i][0];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + a[i][1];
		dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + a[i][2];
	}
	printf("%d\n", max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
	return 0;
}

Measured memory_bytes: 2560
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    static long cl(long a, long b)
    {
        //return Math.ceil((double)a / b);
        return (0 < a % b) ? a / b + 1 : a / b;
    }

    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);

        final int N = nextInt();

        long BT = 1;
        long BA = 1;

        long T = 0;
        long A = 0;

        for (int i = 0; i < N; i++) {
            T = nextLong();
            A = nextLong();

            long p = Math.max(cl(BT, T), cl(BA, A));

            T *= p;
            A *= p;

            BT = T;
            BA = A;
        }

        out.println(T + A);

        out.flush();
    }

    // FastScanner start
    static final InputStream in = System.in;
    static final byte[] buffer = new byte[1024];
    static int ptr = 0;
    static int buflen = 0;
    static boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    static int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    static boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    static String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    static long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    static int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    static double nextDouble() {
        return Double.parseDouble(next());
    }
    // FastScanner end
}


Measured memory_bytes: 22868
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * size
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


N, M = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

AB.sort(key=lambda ab: (-ab[1], ab[0]))
bit = BinaryIndexedTree(size=M)

ans = 0
for a, b in AB:
    if M - a < 0:
        continue
    # 入れられる？
    cap = M - a - bit.sum(M - a) + 1
    if cap > 0:
        ans += b
        # どこに入れよう？
        ok = -1
        ng = M - a
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if mid - bit.sum(mid) + 1 != cap:
                ok = mid
            else:
                ng = mid
        bit.add(ok + 1, 1)
print(ans)


Measured memory_bytes: 64092
#include<bits/stdc++.h>
using namespace std;
const int MAXN_O=10,MAXN_S=15;
char o[MAXN_O],s[MAXN_S];
map<string,string> d;
int main()
{
	//input
	int N_line;
	cin>>N_line;
	while(N_line--)
	{
		//aligorithm
		cin>>o;
		cin>>s;
		if(o[0]=='i')    d[s]="whatever";
		else if(o[0]=='f')
		{
			if(d.count(s))	cout<<"yes\n";
			else	cout<<"no\n";
		}
	}
	return 0;
}


Measured memory_bytes: 46284
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll              long long
#define ull             unsigned long long
#define pb              push_back
#define fastread()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
    fastread();
    int n;
    cin>>n;

    int div = 0,ans = 0;
    div = n/1000;
    if(div*1000 < n){
        div++;
        ans = (div*1000)-n;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};



int main(){
 
    int k;
    cin >> k;
    int x = 7%k;
    set<int> s;
    int ans = 1;
    while(s.count(x) == 0){
        if(x == 0) {
            cout << ans << endl;
            return 0;
        }
        s.insert(x);
        x = (10*x+7)%k;
        ++ans;
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 49996
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] nums = new int[num];
		int sum = 0;
		double divisor = 0, dividend = 1;
		for(int i = 0; i < num; i++){
			nums[i] = sc.nextInt();
			dividend *= nums[i];
		}
		for(int i : nums){
			divisor += dividend / i;
		}
		double ans = dividend / divisor;

		System.out.println(ans);
	}
}




Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n, k; cin >> n >> k;
  vector<int> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  int index = 1;
  long long cnt = 0;
  vector<int> route;
  route.push_back(1);
  vector<bool> seen(n + 1, false);
  int ind;
  while(true){
    if(seen[index]){
      ind = index;
      route.pop_back();
      break;
    }
    cnt++;
    seen[index] = true;
    index = v[index - 1];
    route.push_back(index);
  }
  vector<bool> sen(n + 1, false);
  vector<int> rr;
  rr.push_back(ind);
  int cnt2 = 0;
  while(true){
    if(sen[ind]){
      rr.pop_back();
      break;
    }
    cnt2++;
    sen[ind] = true;
    ind = v[ind - 1];
    rr.push_back(ind);
  }
  if(k < cnt) cout << route[k % cnt] << endl;
  else {
    long long temp = k - cnt;
    temp = temp % cnt2;
    cout << rr[temp] << endl;
  }
}

Measured memory_bytes: 6264
"use strict"
var Main=function(input){
  input=input.split('\n');
  var L=parseInt(input.shift());
  var parity=[];
  var a=[];
  var b=[];
  var c=[];
  for(let i=0;i<L;i++){
    if(input[i]==='0')parity[i]=0;
    else{
      parity[i]=parseInt(input[i][input[i].length-1]);
      parity[i]=(parity[i]%2===0)?2:1;
    }
    input[i]=parseInt(input[i]);
    a[i]=input[i];
    b[i]=2-parity[i];
    c[i]=(parity[i]===1)?0:1;
  }

var dp=[];
  dp[0]=[0,0,0,0,0];
  for(let i=0;i<L;i++){
    dp[i+1]=[];
    dp[i+1][0] = dp[i][0]+a[i];
    dp[i+1][1] = Math.min(dp[i+1][0],dp[i][1]+b[i]);
    dp[i+1][2] = Math.min(dp[i+1][1],dp[i][2]+c[i]);
    dp[i+1][3] = Math.min(dp[i+1][2],dp[i][3]+b[i]);
    dp[i+1][4] = Math.min(dp[i+1][3],dp[i][4]+a[i]);
  }
  console.log(dp[L][4]);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main(){
  ll N,M,H[100000];
  vector<ll> G[100001];
  cin>>N>>M;
  for(int i(0);i<N;i++){
    cin>>H[i];
  }
  for(int i(0);i<M;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int cnt(0);
  for(int i(1);i<=N;i++){
    bool flag(true);
    for(int j(0);j<int(G[i].size());j++){
      if(H[G[i][j]-1] >= H[i-1]) flag = false; 
    }
    if(flag == true) cnt++;
  }
  cout << cnt << endl;
  return 0;
}



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

#define DEBUG(C) cerr << #C << " = " << C << endl

using namespace std;

class FenwickTree {
private:
  vector<int> bit;
public:
  FenwickTree(int n) {
    bit.resize(n + 1);
  }
  void add(int idx, int val) {
    ++idx;
    while (idx < bit.size()) {
      bit[idx] += val;
      idx += idx & -idx;
    }
  }
  int sum(int idx) {
    ++idx;
    int res = 0;
    while (idx > 0) {
      res += bit[idx];
      idx -= idx & -idx;
    }
    return res;
  }
  int sum(int l, int r) {
    return sum(r) - sum(l - 1);
  }
};

const int MAX = 1e5 + 10;
int R, C, N;
vector<pair<int, int>> v;
map<int, int> cmp;

inline int calc(int x, int y) {
  if (x == 0) return y;
  else if (y == C) return C + x;
  else if (x == R) return C + R + C - y;
  else if (y == 0) return C + R + C + R - x;
  else return -1;
}

int main() {
  scanf("%d%d%d", &R, &C, &N);
  set<int> se;
  for (int i = 0; i < N; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int buf1 = calc(x1, y1);
    int buf2 = calc(x2, y2);
    if (buf1 != -1 && buf2 != -1) {
      if (buf1 > buf2) {
        swap(buf1, buf2);
      }
      se.emplace(buf1);
      se.emplace(buf2);
      se.emplace(buf2 + 1);
      v.emplace_back(make_pair(buf1, buf2));
    }
  }
  int cnt = 0;
  for (auto &&e : se) {
    cmp[e] = cnt++;
  }
  FenwickTree bit(cnt);
  for (auto &&p : v) {
    bit.add(cmp[p.first], 1);
    bit.add(cmp[p.second + 1], -1);
  }
  for (auto &&p : v) {
    if (bit.sum(cmp[p.first]) != bit.sum(cmp[p.second])) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 30324
import math

n = int(input())
ta = [[int(i) for i in input().split()] for j in range(n)]

a = 1
b = 1
for i in range(n):
    n = max(~-a//ta[i][0] + 1, ~-b//ta[i][1] + 1)
    a = n * ta[i][0]
    b = n * ta[i][1]

print(a+b)

Measured memory_bytes: 3188
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] a = new int[h][w];
	    for(int i = 0; i < h; i++){
	        for(int j = 0; j < w; j++){
	            a[i][j] = sc.nextInt()%2;
	        }
	    }
	    
		// 計算
		ArrayList<Integer[]> result = new ArrayList<Integer[]>();
		for(int i = 0; i < h; i++){
	        for(int j = 0; j < w-1; j++){
	            if(a[i][j] == 1){
	                Integer[] move = {i+1, j+1, i+1, j+2};
	                result.add(move);
	                a[i][j+1] += a[i][j];
	            }
	        }
	    }
	    for(int i = 0; i < h-1; i++){
	        if(a[i][w-1]%2 == 1){
	            Integer[] move = {i+1, w, i+2, w};
	            result.add(move);
	            a[i+1][w-1] += a[i][w-1];
	        }
	    }
		
		// 出力
		System.out.println(result.size());
		for(Integer[] move : result){
		    System.out.println(move[0] + " " + move[1] + " " + move[2] + " " + move[3]);
		}
		
	}
}


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

int main(){

    char b;cin >> b;

    if(b=='A')cout << 'T' << endl;
    else if(b=='T')cout << 'A' << endl;
    else if(b=='C')cout << 'G' << endl;
    else cout << 'C' << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<LL> A(N),B(N),C(N);
    rep(i,N)cin>>A[i];
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>C[i];
    sort(all(A));
    sort(all(B));
    sort(all(C));
    vector<LL> As(N);
    vector<LL> Cl(N);
    LL ub;
    LL lb;
    rep(i,N){   // 二分探索をA,Cに施す
        ub = N-1,lb = 0;   
        if(A[0]>=B[i])As[i] = 0;
        else if(A[N-1]<B[i])As[i] = N;
        else{  
         while(ub - lb > 1){ // Asmall
            LL mid = (ub + lb)/2;
            if(A[mid] < B[i])lb = mid;      //  if内を満たす者のうち最大のもの
            else ub = mid;  // ifを満たさないもので最小のもの
         }
        As[i] = lb + 1;
        }

        ub = N-1,lb = 0;
        if(C[N-1]<=B[i])Cl[i] = 0;
        else if(C[0]>B[i])Cl[i] = N;
        else{
         while(ub - lb > 1){ // Clarge
            LL mid = (ub + lb)/2;
            if(C[mid] > B[i])ub = mid;  // 条件を満たすうち最小のもの
            else lb = mid;  // 条件を満たさないもののうち最大のもの
         }
        Cl[i] = N - ub;
        }
    }
    LL ans = 0;
    rep(i,N)ans += As[i]*Cl[i];
    cout << ans << endl;
}


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

#define ll long long int

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	int k;
	cin>>n>>k;

	bool digits[10];

	for(int i=0;i<10;i++)digits[i] = true;
	
	int t;
	for(int i=0;i<k;i++){
		cin>>t;
		digits[t] = false;		
	}

	bool ok = false;

	int tmp = n;
	
	while(!ok){
		tmp = n;
		while(tmp>0){
			if(digits[tmp%10]){
				tmp = tmp/10;	
			}else{
				break;
			}
		}	
		if(tmp == 0){
			ok = true;
			break;
		}
		n++;		
	}

	cout<<n<<endl;

	return 0;

}


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

#define ll long long int
#define mp make_pair 
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define ff first
#define ss second
#define MOD  1000000007
#define ll_MAX 922337203685477999
#define endl "\n"
inline ll absdiff(ll a,ll b) {return (a>b)?a-b:b-a;}
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

int main()
{
    // fast
    ll t_c;t_c = 1;
    // cin>>t_c;
    for (ll ti = 0; ti < t_c; ++ti)
    {   
        ll h,n;cin>>h>>n;
        ll tot=0;
        for(ll i=0;i<n;++i) {
            ll temp;cin>> temp;
            tot+=temp;
        }
        if(tot>=h) cout<<"Yes";
        else cout<<"No";
    }
    return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  int sumA = 1;
  cin >> N >> K;
  for(int i = 0;i<N;i++){
    if(sumA*2 < sumA + K){
    sumA *= 2; 
    }else{
    sumA += K;
    }
  }
  
  cout << sumA << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define INPUT()              freopen("input.txt", "r", stdin)
    #define OUTPUT()             freopen("output.txt", "w", stdout)
    #define F                    first
    #define S                    second
//Templatefunctions
    template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
    template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
    template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
//datatypes
    typedef long long int ll;
    typedef unsigned long long int ull;
    typedef long double ld;
//constants
    const double INF = 1e+9;
    const double INFLL = 1e+18;
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
           //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
           //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
//helpers
    //#define MOD         1000000007LL
    #define MAX         2000005
    const ll MOD = 1000000000 + 7;
    //int arr[10000005];
    char str[MAX+10];
    int dp[MAX],bad[MAX];
//Global Variables
    //int dp[MAX],n;
    std::map<int,int>::iterator it;
     signed main()
    {
//        int t;
//        scanf("%d",&t);
//        int x = 2;
//        while(t--)
//        {
//        }
        char arr[105][105];
        int h ,w;
        scanf("%d%d",&h,&w);
        for(int i = 0 ; i < h ; i++)
        {
            scanf("%s",arr[i]);
        }

        for(int i = 0 ; i < h ; i++)
        {
            int flag = 1;
            for(int j = 0 ; j < w ; j++)
            {
                if(arr[i][j] == '.' || arr[i][j] == '@')
                {
                    continue;
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            if(flag)
            {
                for(int j = 0 ; j < w ; j++)
                {
                    arr[i][j] = '@';
                }
            }
        }
        for(int i = 0 ; i < w ; i++)
        {
            int flag = 1;
            for(int j = 0 ; j < h ; j++)
            {
                if(arr[j][i] == '.' || arr[j][i] == '@')
                {
                    continue;
                }
                else
                {
                    flag = 0;
                    break;
                }
            }

            if(flag)
            {
                for(int j = 0 ; j < h ; j++)
                {
                    arr[j][i] = '@';
                }
            }
        }

        for(int i = 0 ; i < h ; i++)
        {
            int flag = 1;
            for(int j = 0 ; j < w ; j++)
            {
                if(arr[i][j] == '@')flag++;
                if(arr[i][j] != '@')printf("%c",arr[i][j]);
            }
            if(flag < h)printf("\n");

        }
    }
//


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

#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
using namespace std;



int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>> a(h,vector<char> (w));
  rep(i,h){
    rep(j,w){
      cin>>a[i][j] ;
    }
  }
  ///////////
  
  bool ok;
  rep(i,h){
     ok=true;
    rep (j,w){
       if(a[i][j]=='#'){
         ok=false; 
       }
    }
    if(ok){
      a.erase(a.begin()+i);
      h--;
      i--;
      //cout<<1<<endl;
    }
  }
  

  
  
  
  
  rep(i,w){
     ok=true;
    rep (j,h){
       if(a[j][i]=='#'){
         ok=false; 
       }
    }
    if(ok){
      rep(k,h){///上かあらk行目
        a[k].erase(a[k].begin()+i);
        
       // cout<<1<<endl;
      }
      i--;
      w--;
    }
  }
  
  rep(i,h){
     rep(j,w){
       cout<<a[i][j]; 
       
     }
    
    cout<<endl;
  }
  
  
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool prime(long long a){
  for(int i = 2; i <= sqrt(a); i++){
    if(a % i == 0) return false;
  }
  return true;
}
 
int main(){
  long long a;
  cin >> a;
  while(1){
    if(prime(a)) break;
    a++;
  }
  cout << a;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

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

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

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

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

  int N;
  cin >> N;
  vector<vector<P>> xy(N, vector<P>());
  rep(i, N) {
    int A;
    cin >> A;
    rep(j, A) {
      int x, y;
      cin >> x >> y;
      x--;
      xy[i].emplace_back(x, y);
    }
  }

  int ans = 0;
  rep(bit, 1 << N) {
    vector<int> id(N, 0);
    rep(k, N) {
      if (bit >> k & 1) {
        id[k] = 1;
      }
    }

    bool ok = true;
    rep(i, N) {
      if (id[i] == 0) continue;
      for (auto v : xy[i]) {
        if (id[v.first] == 0 && v.second == 1) ok = false;
        if (id[v.first] == 1 && v.second == 0) ok = false;
      }
    }
    int cnt = 0;
    if (ok) {
      rep(i, N) {
        if (id[i]) cnt++;
      }
      ans = max(ans, cnt);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int A[202020];
int n, k;

bool check(double l) {
    int rest = k;
    rep(i, n) {
        rest -= ceil(A[i]/l) - 1;
    }
    if(rest >= 0) return true;
    else return false;
}

void solve() {
    cin >> n >> k;
    rep(i, n) cin >> A[i];
    long double ng = 0, ok = 1e9, eps = 1e-9;
    while(ok - ng > eps) {
        long double mid = (ok + ng) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ll fans = floor(ok), ans = ceil(ok);
    if (check(fans)) {
        cout << fans << endl;
    } else {
        cout << ans << endl;
    }
    return;
}

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

Measured memory_bytes: 4436