akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <list>

#define ll long long

using namespace std;
int N;

int main() {
	int k;
	cin >> k;
	printf("%d\n", (k / 2) * ((k + 1) / 2));
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    int n;
    cin>>n;
    int ans=0,num=1;
    for(int i=1;i<=n;i++){
        int cnt=0;
        if(i%2==0){
            int t=i;
            while(t%2==0){
                t=t/2;
                cnt++;
            }
            if(ans<cnt){ans=cnt;
                num=i;
            }
        }
    }
    cout<<num<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>



using namespace std;


int main() {
	
	int A, B, C;
	cin >> A >> B >> C;

	int D;

	D = max(0, C - A + B);

	cout << D << endl;

}


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

const ll INF = 1LL<<60;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n), s(n+1,0);
  rep(i,n) {
    cin >> a[i];
    s[i+1] = s[i] + a[i];
  }
  vector<vector<ll> > dp(n+5, vector<ll>(n+5,INF));
  rep(i,n+2) {
    dp[i][i] = 0;
  }
  rep(i,n) {
    dp[i][i+1] = 0;
  }
  for (int w = 2; w <= n; ++w) {
    for (int l = 0; l <= n-w; ++l) {
      int r = l + w;
      if (w == 2) dp[l][r] = a[l] + a[l+1];
      else {
        for (int k = l+1; k < r; ++k) {
          ll temp = 0;
          if (k == l+1) temp += a[l];
          else if (r == k+1) temp += a[k];
          dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + (s[r] - s[l]));
        }
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}

Measured memory_bytes: 1536
def answer(destination, services):
    P, M = ("POSSIBLE", "IMPOSSIBLE")
    dic = {}
    for a, b in services:
        if dic.get(a) is None:
            dic[a] = [b]
        else:
            dic[a].append(b)
        if dic.get(b) is None:
            dic[b] = [a]
        else:
            dic[b].append(a)
    if dic.get(destination) is None: return M
    arr = dic[destination]
    for i in arr:
        if 1 in dic[i]:
            return P
    return M

n, m = map(int, input().split())
services = []
for _ in range(m):
    a, b = map(int, input().split())
    services.append((a, b))
print(answer(n, services))

Measured memory_bytes: 104532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll x, k, d;
    cin >> x >> k >> d;
    if(x == 0) {
        if(k & 1) cout << abs(x + d);
        else cout << abs(x);
    }
    else if(x > 0) {
        if(x - d <= 0) {
            if(k & 1) cout << abs(x - d);
            else cout << x;
        }
        else {
            ll moves = x / d;
            if(k <= moves) cout << abs(x - (k * d));
            else {
                k -= moves;
                x -= moves * d;
                if(k & 1) cout << abs(x - d);
                else cout << abs(x);
            }
        }
    }
    else {
        if(x + d >= 0) {
            if(k & 1) cout << abs(x + d);
            else cout << abs(x);
        } 
        else {  
            ll moves = abs(x) / d;
            if(k <= moves) cout << abs(x + (k * d));
            else {
                k -= moves;
                x += moves * d;
                if(k & 1) cout << abs(x + d);
                else cout << abs(x);
            }
        }
    }
}

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

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

int main(void) {
	// your code goes here
	int n,i,j,d[101];
	char w[101][11];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%s",w[i]);
		d[i]=strlen(w[i]);
	}
	for(i=1;i<n;i++){
		if(w[i+1][0]!=w[i][d[i]-1]){
			printf("No\n");
			return 0;
		}
	}
	for(i=1;i<n;i++){
		for(j=i+1;j<=n;j++){
			if(strcmp(w[i],w[j])==0){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N ; i++) cin >> D.at(i);
  vector<int> count(N);
  bool can = true;
  long long S = 1;
  
  if (D.at(0) != 0) {
    can = false;
  } else {
    for (int i = 1; i < N; i++) {
      if (D.at(i) == 0) can = false;
    }
    for (int i = 0; i < N && can == true; i++) count.at(D.at(i))++;
    
    for (int i = 1; i < N && can == true; i++) {
      if (count.at(i) != 0) {
        for (int j = 1; j <= count.at(i); j++) {
          S = S * count.at(i-1);
          S = S % 998244353;
        }
      } else {
        for (int j = i; j < N;j++) {
          if (count.at(j) != 0) {
            can = false;
          } else if (j == N-1) {
            goto OUT;
          }
        }
      }
    }
  }
  
  OUT:
  
  if (can) {
    cout << S << endl;
  } else {
    cout << 0 << endl;
  }
}

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

int main() {
	long Q, A, B, C, ans;
	cin >> Q;
	for(int i = 0; i < Q; i++){
		cin >> A >> B;
		if(A > B) swap(A, B);
		C = floor(sqrt(A * B));
		if(C == sqrt(A * B)) C--;
		if(A == B) ans = 2 * A - 2;
		else if((A + 1) == B) ans = 2 * A -2;
		else if((C * (C + 1)) >= (A * B)) ans = 2 * C - 2;
		else if((C * C) < (A * B)) ans = 2 * C - 1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,m,i,j,u,sum,w,x;
	int k[100001],k1[100001],y[100001];
	scanf("%d %d",&n,&m);
	k[1]=0;
	for(i=2;i<=n;i++) scanf("%d",&k[i]);
	for(i=0;i<m;i++) scanf("%d",&y[i]);
	sum=0;
	for(i=1;i<=n;i++){
		sum+=k[i]; k1[i]=sum;
	}	
	u=0; w=1;
	for(i=0;i<m;i++){
		x=y[i];
		if(x>=0) u+=k1[w+x]-k1[w];
		else u+=k1[w]-k1[w+x];
		u%=100000;
		w+=x;
	}
	printf("%d\n",u);
	return 0;
}

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

const int N = 1e5;
const int R = 1e6;

typedef pair<int, int> P;
const int inf = 1e9;

struct SEG {
  P data[N*4];
  int n;
  SEG(int t) {
    n = 16;
    while(n < t) n <<= 1;
  }
  void set(int i, P v) {
    data[i += n-1] = v;
    while(i>0)i = (i-1)/2, data[i] = min(data[i*2+1],data[i*2+2]);
  }
  P get(int i) {
    return data[i+=n-1];
  }
  P query(int a, int b,int k=0,int l=0, int r=-1){
    if(r<0)r=n;
    if(b<=l||r<=a)return P(inf,inf);
    if(a<=l&&r<=b)return data[k];
    return min(
        query(a, b,k*2+1,l,(l+r)>>1),
        query(a, b,k*2+2,(l+r)>>1,r));
  }
};

int cnt[N];
int d[R], t[R], x[R];
int n, r, l;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> r >> l;
  SEG seg(n);
  for(int i = 0; i < n; i++) seg.set(i,P(0, i));
  int last = 0;
  for(int i = 0; i < r; i++) {
    cin >> d[i] >> t[i] >> x[i];
    --d[i];
    ///
    P p2 = seg.query(0, n);
    // cout << i << ":" << p2.second << endl;
    cnt[p2.second] += t[i] - last;
    last = t[i];
    ///
    P p = seg.get(d[i]);
    p.first -= x[i];
    seg.set(d[i], p);
  }
  P p2 = seg.query(0, n);
  cnt[p2.second] += l - last;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(cnt[ans] < cnt[i]) ans = i;
  }
  cout << ans +1 << endl;
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  char c;
  for (int i = 0; i < s.length(); ++i) {
    c = s[i];
    if (c + n <= 'Z')
      c += n;
    else
      c = c + n - 26;
    cout << c;
  }
  cout << endl;
  return 0;
}


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

int main(){
    int H, W, N[60][60]={0};
    cin >> H >> W;
    char S[50][50], T[50][50];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> S[i][j];
        }
    }
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#'){
                N[i][j]++;
                N[i][j+1]++;
                N[i][j+2]++;
                N[i+1][j]++;
                N[i+1][j+2]++;
                N[i+2][j]++;
                N[i+2][j+1]++;
                N[i+2][j+2]++;
            }
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            T[i][j] = '0' + N[i+1][j+1];
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') T[i][j] = S[i][j];
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cout << T[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  pb push_back
#define  xx first
#define  yy second
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
int h,n;
int dp[1001][100100];
int a[4000],b[4000];

int go(int i,int sum){

         if(i>n) return 1e9;
         if(sum<=0) return 0;
       int &ret  = dp[i][sum];
        if(ret!=-1) return ret;
        ret = 0;
       ret =min(b[i]+go(i,sum-a[i]),go(i+1,sum));
       return ret;
}
 int main()
{

       cin >> h >> n;

     for(int i = 1; i<=n; i++){
        cin >> a[i] >> b[i];
     }
     memset(dp,-1,sizeof dp);
     cout << go(1,h) << '\n';

   return 0;
}


Measured memory_bytes: 392320
N=int(input())
E=[]
for i in range(N-1):
    E.append(list(map(int,input().split())))
V=[]
for i in range(N):
    V.append([])
for e in E:
    if e[0]>e[1]:
        V[e[0]-1].append(e[1]-1)
    else:
        V[e[1]-1].append(e[0]-1)
S=0
F=0
for i in range(N):
    F=F+i+1-sum([j+1 for j in V[i]])
    S+=F
print(S)

Measured memory_bytes: 75668
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int N_MAX = 200000;

ll fact[N_MAX+1], rfact[N_MAX+1];

ll perm(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (fact[n] * rfact[n-k]) % MOD;
}

ll comb(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (perm(n, k) * rfact[k]) % MOD;
}

ll modpow(ll a, ll p) {
    ll ret = 1LL;
    while(p) {
        if(p & 1) {
            ret = (ret * a) % MOD;
        }
        a = (a * a) % MOD;
        p >>= 1;
    }
    return ret;
}

void init_fact(ll n) {
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(ll i=2;i<=n;++i) {
        fact[i] = (fact[i-1] * i) % MOD;
        rfact[i] = modpow(fact[i], MOD-2);
    }
}

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

    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = 0LL;
    for(int i=0;i<=k;++i) {
        ll p = n - i; // 色を選ぶ機会が p 回ある
        ans += (((comb(n-1, i) * m) % MOD) * modpow(m-1, p-1)) % MOD;
        ans %= MOD;
    }


    cout << ans << endl;
}

Measured memory_bytes: 6760
m,d=map(int,input().split())
cnt = 0
for i in range(1, m+1):
    for j in range(1, d+1):
        j1 = j // 10
        j2 = j % 10
        if j1 >= 2 and j2 >= 2 and j1 * j2 == i:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
   int a, b;
   cin >> a >> b;
   cout << a+ (b/2) << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
dp = Array.new(N + 10, 1 << 60)
dp[0] = 0
(0...N).each do |n|
  dp[n + 1] = dp[n] + 1 if dp[n] + 1 < dp[n + 1]
  c = 1
  while n + 6 ** c <= N
    if dp[n] + 1 < dp[n + 6 ** c]
      dp[n + 6 ** c] = dp[n] + 1
    end
    c += 1
  end
  c = 1
  while n + 9 ** c <= N
    if dp[n] + 1 < dp[n + 9 ** c]
      dp[n + 9 ** c] = dp[n] + 1
    end
    c += 1
  end
end
puts dp[N]


Measured memory_bytes: 4220
import sys
sys.setrecursionlimit(10 ** 5)

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
amin, amax = A[0], A[N-1]

BC = {}
for _ in range(M):
    b, c = map(int, input().split())
    if c in BC:
        BC[c] += b
    else:
        BC[c] = b

BC = sorted(BC.items(), reverse=True)

b = 0
c = 0
cmax = len(BC)
for i in range(N):
    if BC[c][0] <= A[i]:
        break
    A[i] = BC[c][0]
    b += 1
    if b == BC[c][1]:
        c += 1
        b = 0
        if c == cmax:
            break

print(sum(A))


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

ll r,d,x;

ll f(ll x) {
  return r*x - d;
}

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

  cin>>r>>d>>x;
  for (int i=1; i<=10; i++) {
    x = f(x);
    cout<<x<<endl;
  }
  
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
 
char od[3] = {'R', 'U', 'D'};
char ev[3] = {'L', 'U', 'D'};
vector<long long> ans(100001,0);
int main(){
	long n;
	long long k;
	long q;
	long s;
	cin >> n >> k >> q;
	for(int i=0;i<q;i++){
		cin >> s;
		ans[s-1]++;
	}
	for(int i=0;i<n;i++){
		if(k-q+ans[i] > 0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1408
import sys


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


n = int(input())
xxx = list(map(int, input().split()))
MOD = 10 ** 9 + 7
factorials, invs = prepare(n, MOD)

ans = 0
dp = 1
for i in range(n - 1):
    cur = dp * factorials[i] % MOD
    ans = (ans + (xxx[i + 1] - xxx[i]) * cur * invs[i + 1]) % MOD
    dp = (dp + (cur + factorials[i + 1]) * invs[i + 1]) % MOD
ans = ans * factorials[n - 1] % MOD
print(ans)


Measured memory_bytes: 14992
n, m = map(int, input().split())
l = [list(map(int, input().split())) [1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
on_off = [[0], [1]]

for _ in range(n-1):
  tmp = []
  for j in on_off:
    tmp.append(j+[0])
    tmp.append(j+[1])
  on_off = tmp

for x in on_off:
  cnt = 0
  for y in range(m):
    z = 0
    for c in l[y-1]:
      z += x[c-1]
    if z%2 == p[y-1]%2:
      cnt += 1
  if cnt == m:
    ans += 1
print(ans)

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<m; i++){
        for(int j=0; j<n-1; j++){
            if(a[j]%(i+1) > a[j+1]%(i+1)) swap(a[j], a[j+1]);
        }
    }
    for(int i=0; i<n; i++){
        cout << a[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
using namespace std;

const int MAX_ROOM = 110;
int N;
vector<int> E[MAX_ROOM];
queue<int> Q[MAX_ROOM];

void addEdge(int a, int b) {
  E[a].push_back(b);
  E[b].push_back(a);
}

void rec(int p, int t, int num_door, queue<int>& que) {
  for(int i = 0; i < num_door; ++i) {
    if(!Q[t].empty()) {
      addEdge(p,Q[t].front());
      Q[t].pop();
    } else {
      int a;
      a = que.front();
      que.pop();
      if(a > 0) {
	addEdge(p,++N);
	rec(N, t+1, a-1, que);
      } else {
	Q[t+a].push(p);
      }
    }
  }
}

int main() {
  int t;
  cin >> t;
  while(t--) {
    for(int i = 0; i < MAX_ROOM; ++i) {
      E[i].clear();
      while(!Q[i].empty()) Q[i].pop();
    }
    int a;
    queue<int> que;
    while(cin >> a && a) que.push(a);

    a = que.front(); que.pop();
    N = 1;
    rec(1,0,a,que);

    for(int i = 1; i <= N; ++i) {
      cout << i;
      sort(E[i].begin(), E[i].end());
      for(int j = 0; j < E[i].size(); ++j)
	cout << " " << E[i][j];
      cout << endl;
    }
  }
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int Q; cin >> Q;
  vector<bool> isP(101010,true);
  vector<int> is2017(101010, false);
  isP[0] = isP[1] = false;
  for(int i = 2; i < 101010; i++) {
    if (isP[i]) {
        for (int j = i * 2; j < 101010; j += i)
          isP[j] = false;
        if(isP[(i + 1) / 2]) is2017[i] = true;
    }
  }
  vector<int> sum(101011);
  rep(i, 0, 101010)  sum[i+1] = sum[i] + is2017[i];
  rep(i, 0, Q) {
    int l, r;
    cin >> l >> r;
    cout << sum[r + 1] - sum[l] << "\n";
  }
  return 0;
}


Measured memory_bytes: 1408
import sys
import math

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

s, c = [0] * M, [0] * M
for i in range(M):
	s[i], c[i] = map(int, input().split())

for i in range(0 if N == 1 else 10 ** (N - 1), 10 ** N):
	x = str(i)
	if M == 0:
		print(i)
		sys.exit(0)
	for j in range(M):
		if x[s[j] - 1] != str(c[j]):
			break
		elif j == M - 1:
			print(i)
			sys.exit(0)

print(-1)

Measured memory_bytes: 3064
import java.io.*;

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

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        long r =Long.parseLong(lines[0]);
        long d =Long.parseLong(lines[1]);
        long x =Long.parseLong(lines[2]);

        long ans = 0;
        for (int i = 0; i < 10; i++) {
          ans = r * x - d;
          out.println(ans);
          x = ans;
        }

        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 21076
import math

n=int(input())
a=[int(input())for _  in range(n)]

count=0

def isPrime (x):
  if x==2:
    return True
  
  if x<2 or x%2==0:
    return False
  
  i=3
  while i<=math.sqrt(x):
    if x%i==0:
      return False
    i+=2
  
  return True

for j in range(n):
  if isPrime(a[j]):
    count+=1

print(count)


Measured memory_bytes: 6012
#include <iostream>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
    int N;
    cin >> N;

    int hon[] = {2, 4, 5, 7, 9};
    int pon[] = {0, 1, 6, 8};
    int bon[] = {3};

    if (find(begin(hon), end(hon), N % 10) != end(hon))
    {
        cout << "hon" << endl;
    }
    else if (find(begin(pon), end(pon), N % 10) != end(pon))
    {
        cout << "pon" << endl;
    }
    else if (find(begin(bon), end(bon), N % 10) != end(bon))
    {
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = 0;
	ans += n / (a + b) * a;
	ans += min(n % (a + b), a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int h = 0; h < n; h++){
			boolean[] base = {false,false,false};
			int score = 0;
			int count = 0;
			while(count != 3){
				String event = scan.next();
				switch(event){
				case "HIT":score = hit(base, score);break;
				case "OUT":count++;break;
				case "HOMERUN":score = homerun(base, score);break;
				}
			}
			System.out.println(score);
		}
	}

	private static int homerun(boolean[] base, int score) {
		int i;
		int cnt = 0;
		for(i = 0; i < 3; i++){
			if(base[i] == true){
				cnt++;
			}
		}
		for(int x = 0; x < 3; x++){base[x] = false;}
		return score + cnt + 1;
	}

	private static int hit(boolean[] base, int score){
		int i;
		for(i = 0; i < 3; i++){
			if(base[i] == false){
				break;
			}
		}
		if(i == 3){
			score++;
		} else {
			base[i] = true;
		}

		return score;
	}
}

Measured memory_bytes: 26148
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N, A, B;
  cin >> N >> A >> B;

  int sum = A + B;
  int ans = 0;

  ans += (N / sum) * A;
  N %= sum;

  ans += min(A, N);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N,T,A;
    cin >> N >> T >> A;
    vector<ll> H(N);

    for(int i = 0;i < N;i++)
        cin >> H.at(i);
    
    int ans = 0;
    double mini = 1000000.0,hyoukou;

    for(int i = 0;i < N;i++){
        hyoukou = T - H.at(i) * 0.006;
        if(abs(A - hyoukou) < mini){
            mini = abs(A - hyoukou);
            ans = i;
        }
    }

    cout << ans + 1 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
     ll n,x,temp;
     cin>>x>>n;
     ll a[400]={0};
 
      if(n==0)
        cout<<x;
     else{
     for(int i=0;i<n;i++)
        {
            cin>>temp;
            a[temp]=1;
        }
        for(int i=0;;i++)
        {
            if(a[x-i]==0)
            {
                cout<<x-i<<endl;
                break;
            }
            if(a[x+i]==0)
            {
                cout<<x+i<<endl;
                break;
            }
        }
 
     }
 
 return 0;
}

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

template<typename type>
struct union_find{
	vector<type>par;
	vector<size_t>rank,len;
	explicit union_find(size_t n)
		:par(n,-1),rank(n,0),len(n,1){}
	type find(type a){
		if(par.at(a)<0)return a;
		return par.at(a)=find(par.at(a));
	}
	void unite(type a,type b){
		a=find(a),b=find(b);
		if(a==b)return;
		if(rank.at(a)<rank.at(b)){
			par.at(a)=b;
			len.at(b)+=len.at(a);
		}
		else{
			if(rank.at(a)==rank.at(b))++rank.at(a);
			par.at(b)=a;
			len.at(a)+=len.at(b);
		}
	}
	bool same(type a,type b){
		return find(a)==find(b);
	}
	size_t size(type i){
		return len.at(find(i));
	}
};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m,k; cin>>n>>m>>k;
	union_find<int>uf(n+1);
	vector<int>fre(n+1,0);
	vector<vector<int>>blk(n+1);
	for(int i=0;i<m;++i){
		int a,b; cin>>a>>b;
		uf.unite(a,b);
		++fre.at(a);
		++fre.at(b);
	}
	for(int i=0;i<k;++i){
		int c,d; cin>>c>>d;
		blk.at(c).emplace_back(d);
		blk.at(d).emplace_back(c);
	}
	int bcnt=1;
	for(auto&&i:blk.at(1)){
		if(uf.same(1,i))++bcnt;
	}
	cout<<uf.size(1)-fre.at(1)-bcnt;
	for(int i=2;i<=n;++i){
		bcnt=1;
		for(auto&&j:blk.at(i)){
			if(uf.same(i,j))++bcnt;
		}
		cout<<" "s<<uf.size(i)-fre.at(i)-bcnt;	
	}
	cout<<"\n"s;
}


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

using namespace std;

int main()

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

    int r, d, x;

    cin >> r >> d >> x;

    for (int i = 0; i < 10; i++) {

        x = r*x-d;

        cout << x << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import math 
a,b,x = map(int,input().split())

def f(a,b,x):
    theta = 0
    v = a * a * b / 2
    if x <= v:
        theta = math.degrees(math.atan((a * b * b / 2)/x))
        print(theta)
    else:
        theta = math.degrees(math.atan((2 * b -(2 * x /(a * a))) / a))
        print(theta)

f(a,b,x)

Measured memory_bytes: 3060
#include <iostream>
#include <set>

using namespace std;

int main() {
    string S;
    set<char> s;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        s.insert(S[i]);
    }
    if (s.size() == 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

const int MAX = 100100;

int N, M;
vector<int> X;
vector<int> mod, modc, modd;
int counts[MAX];
// pair countを取る

int main(){
    cin >> N >> M;
    X.resize(N);
    for(auto &v: X)
        cin >> v;
    
    mod.resize(M);
    modc.resize(M);
    modd.resize(M);
    
    for(int i=0; i<N; i++){
        mod[X[i]%M]++;
        counts[X[i]]++;
    }
    for(int i=0; i<MAX; i++){
        modc[i%M] += counts[i]/2 * 2;
        modd[i%M] += counts[i]%2;
    }
    int ans = 0;
    for(int i=0; i<=M/2; i++){
        if(i == M-i || i == 0){
            ans += mod[i]/2;
        }else{
            int s = min(mod[i], mod[M-i]);
            ans += s;
        
            int t;
            
            t = max(0, s - modd[i]);
            ans += max(0, modc[i] - t) / 2;
            
            t = max(0, s - modd[M-i]);
            ans += max(0, modc[M-i] - t) / 2;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2176
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    if str(n + 1)[0] != str(n)[0]:
        print(sum(map(int, list(str(n)))))
    else:
        print(int(str(n)[0]) + (len(str(n)) - 1) * 9 - 1)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
int main () {
	int a,b=9,c=9,d=9,e=9,f=0,g=1000,h;
	int kaisu[1000];
	for(g=0;g<1001;g++)kaisu[g]=0;

	while(scanf("%d",&a)!=EOF){

		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++){
					for(e=0;e<10;e++){
						if(b+c+d+e==a)kaisu[f]=kaisu[f]+1;
					}
				}
			}
		}
		f++;


	}
	for(h=0;h<f;h++)printf("%d\n",kaisu[h]);
	

	scanf("%d",&a);
	return 0;}

Measured memory_bytes: 596
/*pata hai na?*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

//#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const ld pi=acos(-1);
//const int inf=1e18,M=1e9+7;
const int N=5e5+10;

int tree[26][4*N];

void update(int node,int beg,int en,int idx,int val,int pos)
{
    if(beg==en)
    {
        tree[pos][node]=val;
        return;
    }

    int mid=(beg+en)/2;
    if(beg<=idx and idx<=mid)
        update(2*node,beg,mid,idx,val,pos);
    else
        update(2*node+1,mid+1,en,idx,val,pos);

    tree[pos][node]=tree[pos][2*node]+tree[pos][2*node+1];
}

int query(int node,int beg,int en,int l,int r,int pos)
{
    if(r<beg || en<l)
        return 0;

    if(l<=beg && en<=r)
        return tree[pos][node];

    int mid=(beg+en)/2;
    int q1=query(2*node,beg,mid,l,r,pos);
    int q2=query(2*node+1,mid+1,en,l,r,pos);

    return (q1+q2);
}

void solve()
{
    mem(tree,0);

    int n;
    cin>>n;

    string s;
    cin>>s;

    for(int i=0;i<n;++i)
        update(1,1,n,i+1,1,s[i]-'a');

    int q;
    cin>>q;

    int t,x,l,r,cnt,tmp;
    char ch;

    for(;q;--q)
    {
        cin>>t;

        if(t==1)
        {
            cin>>x>>ch;

            if(s[x-1]!=ch)
            {
                update(1,1,n,x,0,s[x-1]-'a');
                s[x-1]=ch;
                update(1,1,n,x,1,s[x-1]-'a');
            }
        }
        else
        {
            cin>>l>>r;

            cnt=0;
            for(int i=0;i<26;++i)
            {
                tmp=query(1,1,n,l,r,i);
                if(tmp>0)
                    ++cnt;
            }

            cout<<cnt<<"\n";
        }
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll K, T;
    cin >> K >> T;
    ll amax = 0;
    ll ai;
    for(int i=0;i<T;i++){
        cin >> ai;
        amax = max(amax, ai);
    }
    cout<<max((ll)0, (2*amax-K)-1)<<endl;

    return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    rep (i, (tx - sx)) {
        cout << "R";
    }
    rep (i, (ty - sy)) {
        cout << "U";
    }
    rep (i, (tx - sx)) {
        cout << "L";
    }
    rep (i, (ty - sy) + 1) {
        cout << "D";
    }
    rep (i, (tx - sx) + 1) {
        cout << "R";
    }
    rep (i, (ty - sy) + 1) {
        cout << "U";
    }
    cout << "LU";
    rep (i, (tx - sx) + 1) {
        cout << "L";
    }
    rep (i, (ty - sy) + 1) {
        cout << "D";
    }
    cout << "R" << endl;
    
    return 0;
}



Measured memory_bytes: 256
N, M = map(int,input().split(' '))
A = []
B = set() #奇数のものだけ入れる
for i in range(M):
    a,b = map(int,input().split(' '))
    A.append([a,b])
    if a in B:
        B.remove(a)
    else:
        B.add(a)
    if b in B:
        B.remove(b)
    else:
        B.add(b)

if len(B) == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 21660
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t; cin>>s >>t;
  string ans="No";
  for(int i=0;i<s.size();i++){
    if(s==t){
      ans="Yes";
      break;
    }else{
      s=s.back()+s.substr(0,s.size()-1);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
vector<int> to[200005];
vector<int> ans;
void dfs(int v,int p=-1){
  for(int u:to[v]){
    if(u==p) continue;
      ans[u]+=ans[v];
      dfs(u,v); 
  }
}
const int INF = 1001001001;
int main(){
  int n,q;cin >> n >> q;
  ans.resize(n);
  for(int i=0;i<n-1;i++){
    int a,b;cin >> a >> b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
    ans.at(i)=0;
  }
  for(int i=0;i<q;i++){
    int p,x; cin >> p >> x; p--;
    ans[p]+=x;
  }
  
  dfs(0);
  for(int i=0;i<n;i++){
   cout << ans[i] << endl;
  }
}

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

int n, k, x, ans;

int main() {
    cin >> n;
    cin >> k;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        ans += (x < k - x) ? 2 * x : 2 * (k - x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    string k;
    int d;
    cin >> k >> d;
    vector< vector<int> > dp(d, vector<int>(2));
    dp[0][true] = 1;

    rep(i, k.size()) {
        int  here = k[i] - '0';
        vector< vector<int> > after(d, vector<int>(2));

        for(int prevmod = 0; prevmod < d; prevmod++) {
            for(int now = 0; now <= 9; now++) {
                int nowmod = (prevmod + now) % d;
                if(now < here) {
                    after[nowmod][false] += dp[prevmod][true];
                    after[nowmod][false] %= MOD;
                } else if(now == here) {
                    after[nowmod][true] += dp[prevmod][true];
                    after[nowmod][true] %= MOD;
                }
                after[nowmod][false] += dp[prevmod][false];
                after[nowmod][false] %= MOD;
            }
        }
        dp = after;
    }

    cout << (dp[0][true] + dp[0][false] - 1 + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll calc(ll n){
    if(n<=0) return 0;
    n++;
    ll ans=0;
    for(int i=0;i<50;i++){
        ll loop = 1LL << (i+1);
        ll cnt = (n/loop)*(loop/2);
        cnt += max(0LL,(n%loop)-(loop/2));
        if(cnt%2==1){
            ans += 1LL << i;
        }
    }

    return ans;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans = calc(b)^calc(a-1);
    cout << ans << endl;
}

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

const int MOD = (int)1e9+7;

int main(){
	int N,M;
	cin >> N >> M;
	vector<pair<int,int>> ba(M);
	for(int i=0;i<M;i++)	cin >> ba.at(i).second >> ba.at(i).first;

	sort(ba.begin(),ba.end());
	int ans=0;
	int now=0;
	for(int i=0;i<M;i++){
		if(now<=ba.at(i).second){
			ans++;
			now=ba.at(i).first;
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
n,k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
    
flags = [0]*n
roots = []
for i in range(n):
  if flags[i] == 1:
    continue
  root = [i+1]
  while True:
    root.append(p[root[-1]-1])
    flags[root[-1]-1] = 1 
    if root[-1] == i+1:
      root.pop(-1)
      break
  roots.append(root)

ans = max(c)
for root in roots:
  root.extend(root)
  ruisekiwa = [0]*len(root)
  ruisekiwa[0] = c[root[0]-1]
  for i in range(1, len(root)):
    ruisekiwa[i] = ruisekiwa[i-1] + c[root[i]-1]
  scoreCir = ruisekiwa[len(root)//2-1]
  #print(root)
  scoreForRoot = -10**15
  for i in range(1, min(k+1, len(root)//2+1)): #移動回数
    scoreForKaisuu = -10**15
    for j in range(0, len(root)//2):
      score = ruisekiwa[j+i] - ruisekiwa[j]
      scoreForKaisuu = max(score, scoreForKaisuu)
    #print(scoreForKaisuu)
    if scoreCir > 0 and k-i >= len(root)//2:
      #print((k-i)//(len(root)//2))
      scoreForKaisuu += (k-i)//(len(root)//2)*scoreCir
    scoreForRoot = max(scoreForKaisuu, scoreForRoot)
  ans = max(ans, scoreForRoot)
print(ans)


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

bool ck(int s, const VI& ng){
	for(;s >0; s/=10){
		if(ng[s%10]) return false;
	}
	return true;
}


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,k;
	cin >>n >>k;
	VI ng(10);
	rep(i, k){
		int d; cin >>d;
		ng[d] = 1;
	}
	rep2(i, n, 10000000){
		
		if(ck(i, ng)){
			cout << i <<"\n"; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
int N, L, Q;
int X[MAXN];

int nxt[30][MAXN], prv[30][MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N; 
    for (int i = 0; i < N; i++)
        cin >> X[i];
    cin >> L;
    memset(nxt, -1, sizeof(nxt));
    memset(prv, -1, sizeof(prv));
    for (int i = 0; i < N; i++) {
        if (i == N-1) {
            nxt[0][i] = N-1;
            continue;
        }
        int low = i+1, high = N;
        while (high-low > 1) {
            int med = (high+low)/2;
            if (X[med] - X[i] <= L) low = med;
            else high = med;
        }
        nxt[0][i] = low;
    }
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            prv[0][i] = 0;
            continue;
        }
        int low = -1, high = i;
        while (high - low > 1) {
            int med = (high+low)/2;
            if (X[i] - X[med] <= L) high = med;
            else low = med;
        }
        prv[0][i] = high;
    }
    for (int i = 0; i < 30-1; i++) {
        for (int j = 0; j < N; j++) {
            if (nxt[i][j] == -1) nxt[i+1][j] = -1;
            else nxt[i+1][j] = nxt[i][nxt[i][j]];
            assert(nxt[i][j] != -1);

            if (prv[i][j] == -1) prv[i+1][j] = -1;
            else prv[i+1][j] = prv[i][prv[i][j]];
            assert(prv[i][j] != -1);
        }
    }
    cin >> Q;
    for (int t = 0; t < Q; t++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a < b) {
            int low = 0, high = N;
            while (high - low > 1) {
                int med = (low+high)/2;
                int now = a;
                for (int i = 30-1; i >= 0; i--) {
                    if ((med)&(1<<i)) {
                        now = nxt[i][now];
                    }
                }
                if (now >= b) high = med;
                else low = med;
            }
            cout << high << endl;
        } else {
            int low = 0, high = N;
            while (high - low > 1) {
                int med = (low+high)/2;
                int now = a;
                for (int i = 30-1; i >= 0; i--) {
                    if ((med)&(1<<i)) {
                        now = prv[i][now];
                    }
                }
                if (now <= b) high = med;
                else low = med;
            }
            cout << high << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 24704
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
//#define len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect


void solve() {
    int n, ans = 0;
    cin >> n;
    int calc[10][10] = {0};
    loop(i, 10)
        loop(j, 10) calc[i][j] = 0;
    loop1(i, n) {
        int x = i, mod;
        while (x > 0) {
            mod = x % 10;
            x /= 10;
        }
        ++calc[mod][i % 10];
    }
    loop1(i, 9)
        loop1(j, 9)
            ans += calc[i][j] * calc[j][i];
    cout << ans;
}

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


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int run[15][15],w,h;
int memo[15][15];

int ski(int x,int y,bool s)
{
	if(y>=h)			return 1;
	if(memo[y][x]!=-1)	return memo[y][x];
	if(run[y][x]==1)	return memo[y][x]=0;
	if(run[y][x]==2)	return s?ski(x,y+2,true):0;

	if(y==h-1)	return memo[y][x]=1;

	int cnt=0;
	for(int dx=-1;dx<=1;dx++){
		int xx=x+dx;
		if(0<=xx && xx<w)	cnt+=ski(xx,y+1,!dx);
	}
	return memo[y][x]=cnt;
}

int main()
{
	for(;scanf("%d%d",&w,&h),w;){
		for(int y=0;y<h;y++)
			for(int x=0;x<w;x++)
				scanf("%d",run[y]+x),memo[y][x]=-1;

		int cnt=0;
		for(int x=0;x<w;x++)	cnt+=ski(x,0,true);
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 60);
int n,k, m, a, b, d, t; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}ll ans = 0; vector<bool> mod;
struct Corr {
    ll sum;
    ll cost;
};
deque<Corr> dq;
ll bfs() {
    while (!dq.empty()) {
        Corr now = dq.front(); dq.pop_front();
        if (now.sum % k == 0 && now.sum != 0) return now.cost;
        now.sum %= k;
        if (mod[now.sum]) continue;
        mod[now.sum] = 1;
        Corr next = { now.sum * 10,now.cost };
        dq.push_front(next);
        next = { now.sum + 1,now.cost + 1 };
        dq.push_back(next);
    }
}
int main() {
    cin >> k;mod.resize(k, 0);
    dq.push_back({ 0,0 });
    cout << bfs() << endl;
}

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

#define LEN 100005

typedef struct pp
{
    char name[100];
    int t;
} P;

P Q[LEN];
int head;
int tail;
int n;
// bool isEmpty()
// {
//     return head == tail;
// }
// bool isFull()
// {
//     return head == (tail + 1) % LEN;
// }
void enqueue(P x)
{
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}
P dequeue()
{
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int main()
{
    int elaps = 0;
    int c, q;
    P u;
    scanf("%d %d", &n, &q);

    for (int i = 1; i <= n; i++)
    {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }

    head = 1;
    tail = n + 1;
    while (head != tail)
    {
        u = dequeue();
        c = std::min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0)
            enqueue(u);
        else
        {
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}


Measured memory_bytes: 13256