akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
int n, m, v, p, a[N];
bool check(int mid) {
    if (mid >= n - p)
        return 1;
    vector <int> t;
    for (int i = 0; i <= n - p; ++i)
        if (i != mid)
            t.app(a[i]);
    int add = max(0ll, v - p);            
    int sum = 0;
    for (int e : t)
        if (a[mid] + m < e)
            return 0;
    for (int e : t)
        sum += min(m, a[mid] + m - e);
    return sum >= add * m;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> m >> v >> p;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    int l = -1;
    int r = n - p;
    while (l < r - 1) {
        int mid = (l + r) >> 1;
        if (check(mid))
            r = mid;
        else
            l = mid;
    }   
    cout << n - r << '\n';
}   

Measured memory_bytes: 2916
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int N, X;
int L[1<<20], R[1<<20], B[1<<20];
long long min_score = 0;
vector<pair<long long, int> > v;
vector<long long> csum(1<<20);

bool possible(long long num_study_hrs) {

  if(num_study_hrs == 0) return (min_score >= 0);

  int num_complete = num_study_hrs / X;
  int partial = num_study_hrs % X;

  if(partial == 0) return ((csum[num_complete-1] + min_score) >= 0);

  for(int i = 0; i < N;i++) {
    long long tsr = 0;
    if(partial <= B[v[i].second]) tsr = partial*1LL*L[v[i].second];
    else tsr = B[v[i].second]*1LL*L[v[i].second]
               + (partial-B[v[i].second])*1LL*R[v[i].second];

    if(num_complete != 0) {
      if(i <= (num_complete-1))
        tsr = csum[num_complete] - v[i].first + tsr;
      else
        tsr = csum[num_complete-1]  + tsr;
    }

    if((tsr + min_score) >= 0) return true;
  }

  return false;
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> X;
  for(int i = 0;i < N;i++) {
    cin >> B[i] >> L[i] >> R[i];
    min_score += -(1LL*B[i])*L[i];

    v.push_back({B[i]*1LL*L[i] + (X - B[i])*1LL*R[i], i});
  }

  sort(v.begin(), v.end(), greater<>());
  csum[0] = v[0].first;
  for(int i = 1;i < N;i++) {
     csum[i] = csum[i-1] + v[i].first;
  }

  long long lo = 0, hi = (1LL*N)*X, mid = 0;
  while(lo < hi) {
    mid = (lo + hi) / 2;
    if(possible(mid)) {hi = mid;}//cout<<mid<<endl;}
    else lo = mid + 1;
  }

  cout << lo;// << v[0].first <<" "<<v[1].first<<endl;

  return 0;
}


Measured memory_bytes: 15988
from math import floor
from collections import Counter

def factoring(n):
    # 素因数の合算を知りたいときはcをグローバルに定義(下を消す)
    c = Counter()
    sup = floor(pow(n,1/2))
    for i in range(2,sup+1):
        while n % i == 0:
            c[i] += 1
            n //= i
    if n != 1:
        c[n] += 1
    return c

N, P = map(int,input().split())
ans = 1
for key, value in factoring(P).items():
    ans *= pow(key,(value // N))
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int n,m,r;
int d[201][201];
int l[9];
int a,b,c;
int res;
bool used[9];

void dfs(int c,int las,int dist){
  if(c==r+1){
    if(res>dist) res=dist;
    return;
  }
  for(int i=1;i<=r;i++)
  if(!used[i]){
    used[i]=true;
    if(las==-1) dfs(c+1,i,0);
    else dfs(c+1,i,dist+d[l[las]][l[i]]);

    used[i]=false;
  }
}

int main(){
  cin>>n>>m>>r;
  for(int i=1;i<=n;i++)
  for(int j=1;j<=n;j++){
    if(i!=j) d[i][j]=inf;
  }
  for(int i=1;i<=r;i++) cin>>l[i];
  for(int i=1;i<=m;i++){
    cin>>a>>b>>c;
    if(d[a][b]>c) d[a][b]=d[b][a]=c;
  }

  for(int k=1;k<=n;k++)
  for(int i=1;i<=n;i++)
  for(int j=1;j<=n;j++){
    if(d[i][j]>d[i][k]+d[k][j]) d[i][j]=d[i][k]+d[k][j];
  }
  res=inf;
  dfs(1,-1,0);
  cout<<res<<endl;
}

Measured memory_bytes: 384
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)

n = int(input())
ans = 0
for i in range(1,n+1,2):
    if make_divisors(i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 9384
#include<iostream>
 
using namespace std;
 
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==5 && b==5 && c==7) || (b==5&&c==5 && a==7) || (a==5 && c==5 && b==7))cout<<"YES";
  else cout<<"NO";
  return 0;
}

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

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

    int x = 0;
    int xMax = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') {
            x++;
        } else {
            x--;
        }
        xMax = max(x, xMax);
    }

    cout << xMax << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
   int a, b, i, key, flag = 0;;
   scanf("%d %d", &a, &b);
   while ( 1 ) {
    if ( flag == 1 ) printf("\n");
    flag = 1;
      key = 0;
      for ( i = a; i <= b; i++ ) {
         if ( i % 4 == 0 ) {
            if ( i % 100 != 0 || i % 400 == 0){
               printf("%d\n", i);
               key++;
            }
         }
      }
      if ( key == 0) printf("NA\n");
      scanf("%d %d", &a, &b);
      if ( a == 0 && b == 0 ) break;
   }
   return 0;
}

Measured memory_bytes: 1680
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int h, w;
char field[100][100];
bool visit[100][100];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

void dfs(int y, int x, char c) {
  visit[y][x] = true;
  REP(i, 4) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (0 <= ny && ny < h && 0 <= nx && nx < w && !visit[ny][nx] &&
        field[ny][nx] == c)
      dfs(ny, nx, c);
  }
}

int main() {
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) {
      return 0;
    }
    REP(i, h) REP(j, w) {
      cin >> field[i][j];
      visit[i][j] = false;
    }
    int ans = 0;
    REP(i, h) REP(j, w) {
      if (!visit[i][j]) {
        dfs(i, j, field[i][j]);
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,2654){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3192
import sys
import math
import collections
import bisect
import copy
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, c = ns()
    d = [na() for _ in range(c)]
    color = [na() for _ in range(n)]

    cnt = [[0] * c for _ in range(3)]

    for i in range(n):
        for j in range(n):
            cnt[(i + j) % 3][color[i][j] - 1] += 1

    ans = INF
    for cost in itertools.permutations(range(c), 3):
        tmp_ans = 0
        for i in range(3):
            for j in range(c):
                tmp_ans += cnt[i][j] * d[j][cost[i]]
        ans = min(ans, tmp_ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12132
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    int cur = 0;
    int res = 0;
    for(int i = 0; i < N; i++) {
        res += max(0, (h[i] - cur));
        cur = h[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

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

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    string S;
    cin >> S;
    int cnt = 0;
    LL res = 0;
    for (int i = 0; i < SZ(S); i++) {
        if (S[i] == 'B') continue;
        res += i-cnt;
        cnt++;
    }
    cout << res << "\n";
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

struct Modcomb{
  int mod; //$BAG?t(B
  std::vector<long long int>fac;  //$B3,>h(B
  std::vector<long long int>finv; //$B3,>h$N5U85(B
  std::vector<long long int>inv;  //$B5U85(B

  //nCr=n!/r!(n-r)!
  Modcomb(int max,int mod){
    this->mod=mod;
    fac.resize(max+1,0);
    finv.resize(max+1,0);
    inv.resize(max+1,0);
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<=max;i++){
      fac[i]=(fac[i-1]*i%mod)%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }

  long long int slove(int n,int r){
    if(n<r)return 0;
    if(n<0||r<0)return 0;
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod;
  }
};

ll modpow(ll x,ll n){
  if(n==0)return 1;
  if(n%2)return ((x%MOD)*(modpow(x,n-1)%MOD))%MOD;
  else {
    ll half=modpow(x,n/2)%MOD;
    return (half*half)%MOD;
  }
}


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

  int N,M,K;
  cin>>N>>M>>K;

  Modcomb comb(N*M,MOD);

  ll ans=0;
  vector<ll>sumN(N+1),sumM(M+1);
  sumN[0]=0,sumM[0]=0;
  for(int i=1;i<=N;i++)sumN[i]=(sumN[i-1]+i)%MOD;
  for(int i=1;i<=M;i++)sumM[i]=(sumM[i-1]+i)%MOD;
  for(ll i=1;i<=M;i++){
    ans=((ans%MOD+((N*N)%MOD*(sumM[M]-sumM[i-1])%MOD)%MOD)%MOD)%MOD;
    ans=(ans%MOD-((N*N)%MOD*((M+1-i)*i)%MOD)%MOD)%MOD;
    if(ans<0)ans+=MOD;
  }
  ans%=MOD;
  for(ll i=1;i<=N;i++){
    ans=((ans%MOD+((M*M)%MOD*(sumN[N]-sumN[i-1])%MOD)%MOD)%MOD)%MOD;
    ans=(ans%MOD-((M*M)%MOD*((N+1-i)*i)%MOD)%MOD)%MOD;
    if(ans<0)ans+=MOD;
  }
  ans%=MOD;
  ans=(ans*comb.slove(N*M-2,K-2))%MOD;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 6528
#include <iostream>

int main(int argc, char **argv)
{
    std::string S;
    std::cin >> S;

    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD

using namespace std;

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

int main() {
  ll N, W, w0;
  vector<ll> V[4];

  cin >> N >> W;
  for (ll i = 0; i < N; i++) {
    ll w, v;
    cin >> w >> v;
    if (i == 0) {
      w0 = w;
    }
    V[w - w0].push_back(v);
  }

  for (ll i = 0; i < 4; i++) {
    sort(V[i].begin(), V[i].end(), greater<ll>());
  }


  vector<ll> sum[4];
  for (ll i = 0; i < 4; i++) {
    sum[i].push_back(0);
    for (ll j = 0; j < V[i].size(); j++) {
      sum[i].push_back(sum[i][j] + V[i][j]);
    }
  }

  ll max_v = -1;

  for (ll i = 0; i < sum[0].size(); i++) {
    for (ll j = 0; j < sum[1].size(); j++) {
      for (ll k = 0; k < sum[2].size(); k++) {
        for (ll l = 0; l < sum[3].size(); l++) {
          if (w0 * i + (w0+1) * j + (w0+2) * k + (w0+3) * l <= W) {
            max_v = max(max_v, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
          }
        }
      }
    }
  }

  cout << max_v << endl;

  return 0;
}


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

ll P=998244353;
ll binom[4010][4010];

ll ans1(ll N, ll K, int i) {
	int l=0, m=0;
	for(int j=1; j<=K; j++) {
		if(i-j<1 or i-j>K)
			l++;
		else
			m++;
	}
	m /= 2;
	//cout << "solving " << N << " " << K << " " << i << "\n";
	//cout << l << " " << m << endl;
	ll res = 0;
	ll pow_of_2 = 1;
	for(int j=0; j<=m; j++) {
		res += (((binom[m][j]*pow_of_2)%P)*binom[l+N-1][l+j-1])%P;
		pow_of_2 *= 2;
		pow_of_2 %= P;
	}
	return res%P;
}

ll ans2(ll N, ll K, int i) {
	if(i%2)
		return ans1(N, K, i);
	else
		return ans1(N, K, i) + ans1(N-1, K, i);
}

int main()
{
 	ios_base::sync_with_stdio(false);
	ll N, K;
 	cin >> K >> N;
 	for(int i=0; i<4010; i++) {
 		binom[i][0] = binom[i][i] = 1;
 		for(int j=1; j<i; j++) {
 			binom[i][j] = (binom[i-1][j] + binom[i-1][j-1])%P;
 		}
 	}
 	
 	//cout << ans1(3, 3, 2) << " " << ans1(2, 3, 2);
 	
 	for(int i=2; i<=2*K; i++) {
 		ll a = ans2(N, K, i);
 		cout << (a+P)%P << " ";
 	}
 	
}


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

string s;
bool m[1010101];

int main(){
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';
  int n = s.size();
  
  /* 訂正：945でダメ//これは446に対応できないのでダメ
  rep(i, n + 1) m[i] = false;
  bool flg = false;
  for(int i = n - 1; i >= 0; i--){
    int num = s.at(i) - '0';
    if(num >= 6){
      flg = true;
      continue;
    }
    if(flg && num == 5){
      m[i] = true;
      continue;
    }
    flg = false;
  }
  rep(i, n) cerr << m[i]; cerr << endl;
  */
  
  //rep(i, n) cerr << s.at(i); cerr << endl;
  
  int sum = 0;
  bool flag = false;
  rep(i, n){
    int num = s.at(i) - '0';
    if(flag){ //桁上がり
      flag = false;
      num++;
      /*例外扱いする必要無し
      if(num == 10){
        flag = true;
        num = 0;
      }*/
    }
    if(num >= 6){
      sum += 10 - num;
      flag = true;
    }else if(num == 5 && s.at(i + 1) - '0' >= 5){
      sum += 10 - num;
      flag = true;
    }else{
      sum += num;
    }
    //cerr << num;
  }
     
  cout << sum << endl;
  return 0;
}


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

using namespace std;

#define LEFT 1
#define RIGHT 0

int main(){

	string data = ("qwertasdfgzxcvb");
	int cnt;
	string inp;
	int f;

	while (1){

		cin >> inp;
		if (inp == "#") break;

		cnt = 0;
		if (data.find(inp[0]) != -1) f = LEFT;
		else f = RIGHT;

		for (int i = 1; i < inp.size(); i++){
			if (data.find(inp[i]) != -1){
				if (f == RIGHT){
					cnt++;
					f = LEFT;
				}
			}
			else if (f == LEFT){
				cnt++;
				f = RIGHT;
			}
		}

		cout << cnt << endl;

	}
}

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

int main(){
	int n;
	std::string s, t;
	std::cin >> n >> s >> t;
	for(int i=0; i<n; i++){
		std::cout << s[i];
		std::cout << t[i];
	}
	std::cout << std::endl;
}


Measured memory_bytes: 256
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

cnt = 0

def binary_search (a, key):
    left = 0
    right = len(a)
    while left < right:
        mid = (left + right) // 2
        if a[mid] == key:
            return True
        elif key < a[mid]:
            right = mid
        else:
            left = mid + 1
    return False

for i in range(q):
    if binary_search(s, t[i]):
        cnt += 1
print(cnt)


Measured memory_bytes: 16708
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

int main()
{
    string s, t;
    cin>>s>>t;
    int ans;
    for(int i=0;i<3;i++)
    {
    	if(s[i]==t[i])ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Vikash Kumar @ Codechef/codeforces 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define ll                    long long int
#define ll_MAX                LLONG_MAX
#define ll_MIN                LLONG_MIN
#define pi                    3.14159265358979323846
#define count_1(n)            __builtin_popcountll(n)
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define mid(s,e)              (s+(e-s)/2)
const int MX=10010896;
const int lmt=3164;
const int N=10000001;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

inline void solve(){
    /*_Start_*/
    int x,n;
    cin>>x>>n;
    int arr[n];
    unordered_map<int,int> mp;
    for(int i=0;i<n;i++){
      cin>>arr[i];
      mp[arr[i]]++;
    }
    int d1=x,d2=x;
    while(mp[d1]){
      d1--;
    }
    while(mp[d2]){
      d2++;
    }
    if(abs(d1-x)==abs(d2-x))
      cout<<min(d1,d2)<<"\n";
    else if(abs(d1-x)<abs(d2-x))
      cout<<d1<<"\n";
    else
      cout<<d2<<"\n";

    //cout<<min(d1,d2)<<"\n";

    /*_End_*/
   
}

int main()
{
	cout<<fixed<<setprecision(12);
	//freopen("input.txt", "r", stdin);
	fastio;ll  t=1,tc=1;
	//cin>>t;
	while(t--){solve();}return 0;
}

Measured memory_bytes: 3648
#n=int(input())
#n,m=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())

count1=s.count("1")
count0=s.count("0")

print(min(count1,count0)*2)


Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>

#define rep(i,s,N) for(int i=s;i<N;++i) 

template<typename T>
void swap(T& a, T& b) {
	T t = a;
	a = b;
	b = t;
}

template<typename T>
void print(std::vector<T> v) {
	for(int i=0;i<v.size();++i){
		if (i==0) std::cout << v[i];
		else std::cout << " " << v[i];
	}
}

template<typename T, typename U>
void print(std::vector<T> v, std::vector<U> iv ) {//index of v
	for(int i=0;i<v.size();++i){
		if (i==0) std::cout << v[iv[i]];
		else std::cout << " " << v[iv[i]];
	}
}

template<typename U>
std::vector<int> sort_bubble(std::vector<U> &x) {
	std::vector<int> ix(x.size());
	// init
	for (int i=0; i<x.size(); ++i) ix[i] = i;
	// sort
	for (int i=0; i<x.size(); ++i) {
		for (int j=x.size()-1; j>i; --j) {
			if (x[j] < x[j-1]) {
				swap(x[j], x[j-1]);
				swap(ix[j], ix[j-1]);
			}
		}
	}
	return ix;
}
template<typename T>
std::vector<int> sort_selection(std::vector<T> &x){
	std::vector<int> ix(x.size());
	// init
	for (int i=0; i<x.size(); ++i) ix[i] = i;
	// sort
	for (int i=0; i<x.size(); ++i) {
		int min_index = i;
		for (int j=i+1; j<x.size(); ++j) {
			if (x[j] < x[min_index]) min_index = j; 
		}
		if (x[i] == x[min_index]) {
			continue;
		}
		swap(x[i], x[min_index]);
		swap(ix[i], ix[min_index]);
	}
	return ix;
}

template<typename T, typename U>
bool check_stability(
	const std::vector<T> &x  // x: original values
	,const std::vector<U> &ix // ix: sorted indices
	)	
{
	for (int i=1; i<ix.size(); ++i) {
		// if consecutive 2 values are the same, check the order of corresponding x 
		// x, not ix
		if ((x[ix[i-1]] == x[ix[i]]) && (ix[i-1] > ix[i])) {
			return false;
		}
	}
	return true;
}

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<char> x(N);
	vector<string> x_str(N);
	rep(i,0,N) {
		char temp[2];
		scanf("%s", temp); 
		x[i] = temp[1];
		x_str[i] = temp;
	}
	{
		// replicate
		vector<char> xx(x);
		// bubble sort
		vector<int> ix_bubble = sort_bubble(xx);
		print(x_str, ix_bubble); cout << endl;
		string s = check_stability(x, ix_bubble) ? "Stable" : "Not stable";
		cout << s << endl;
	}
	{
		// replicate
		vector<char> xx(x);
		// selection sort
		vector<int> ix_selection = sort_selection(xx);
		print(x_str, ix_selection); cout << endl;
		string s = check_stability(x, ix_selection) ? "Stable" : "Not stable";
		cout << s << endl;
	}
	// check stability
	
	return 0;
}




Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;

    string res;
    while(N != 0) {
        int r = N % 2;
        if (r < 0) r += 2;

        res += static_cast<char>('0' + r);
        N = (N-r) / (-2);
    }

    reverse(res.begin(), res.end());
    if (res == "") res = "0";
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ll long long
int main(){
    int n; ll h; cin >>  n >> h;
    vector<ll> a(n),b(n);
    REP(i,n){
        cin >> a.at(i) >> b.at(i);
    }
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    ll maxa = a[0];
    ll ans = 0;
    vector<ll>::iterator it = b.begin();
    while(*it>maxa && it!=b.end()){
        ans++;
        h-=*it;
        if(h<=0){
            break;
        }else{
            it++;
        }
    }
    if(h>0){
        ans += (h+maxa-1)/maxa;
    }
    cout << ans << endl;




}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vll v;
  rep(i,n) {
    string t = "";
    t += s[i];
    int m = stoi(t);
    v.push_back(m);
  }
  ll ans = 0;
  rep(i,1<<n) {
    if(!((i>>(n-1))&1)) continue;
    ll num = 0;
    rep(j,n) {
      num *= 10;
      num += v[j];
      if(i>>j&1) {
        ans += num;
        num = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int a,b,c,k; cin >> a >> b >> c >> k;
    while(!(a<b)){
        --k;
        b*=2;
    }
    cerr << a << " " << b << " " << c << endl;
    while(!(b<c)){
        --k;
        c *= 2;
    }

    if(k >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

int solve(int a, int k) {
    if(a < k) return 0;
    if(a % k == 0) return a / k;

    int v = a / k + 1;
    int delta = std::max((a - (a / k) * k) / v, 1);

    return solve(a - v * delta, k);
}

int sg;
int n, a, k;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i <= n; ++i) {
        read(a), read(k);
        sg ^= solve(a, k);
    }
    puts(sg ? "Takahashi" : "Aoki");

    return 0;
}


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

#define ll long long
#define ar array
 
using namespace std;

int main() {

    int a, b, c, res, i = 0;
    
    cin >> a >> b >> c;
    
    res = b;
	
	if(a>b){
		cout << 0 << endl;
	}else if( a == b){
		cout << 1 << endl;
	}else if((a*c) >= b){
		cout << (b/a) << endl;
	}else{
		cout << c << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
	static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int M = sc.nextInt();
		int K = sc.nextInt();

		long x = 0;
		Combination c = new Combination(N * M, MOD);

		for (long dx = 0; dx < M; dx++) {
			x += dx * N * N * (M - dx);
			x %= MOD;
		}

		long y = 0;
		for (long dy = 0; dy < N; dy++) {
			y += dy * M * M * (N - dy);
			y %= MOD;
		}

		long answer = (x + y) % MOD;
		answer *= c.choose(N * M - 2, K - 2);
		answer %= MOD;
		System.out.println(answer);
	}

	private static class Combination {
		private final int M;
		private long[] fact;
		private long[] ifact;
		private long[] inv;

		public Combination(int n, int M) {
			this.M = M;
			fact = new long[n + 1];
			ifact = new long[n + 1];
			inv = new long[n + 1];

			fact[0] = fact[1] = 1;
			ifact[0] = ifact[1] = 1;
			inv[1] = 1;

			for (int i = 2; i <= n; i++) {
				fact[i] = fact[i - 1] * i % M;
				// p = (p / a * a) + (p % a)
				// 0 ≡ (p / a * a) + (p % a)          (mod p)
				// a^(-1) ≡ - (p % a)^(-1) * (p / a)  (mod p)
				inv[i] = M - inv[M % i] * (M / i) % M;
				ifact[i] = ifact[i - 1] * inv[i] % M;
			}
		}

		public long choose(int n, int k) {
			if (n < k) return 0;
			if (n < 0 || k < 0) return 0;
			return fact[n] * (ifact[k] * ifact[n - k] % M) % M;
		}
	}
}


Measured memory_bytes: 27348
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    map<ll, ll> mp;
    REP(i,N){
        ll a;
        cin >> a;
        mp[a]++;
    }
    REP(i,M){
        ll b, c;
        cin >> b >> c;
        mp[c] += b;
    }
    ll ans = 0;
    int cnt = N;
    for(auto itr = mp.rbegin();itr != mp.rend();itr++){
        ll key = itr -> first;
        ll value = itr -> second;
        if(value <= cnt){
            ans += key * value;
            cnt -= value;
        }
        else{
            ans += cnt * key;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLD;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(x);
	LL arr[n];
	rep(i, 0, n)	arr[i] = scanLong();
	sort(arr, arr+n);
	rep(i, 1, n)	arr[i] += arr[i-1];
	LL pos = upper_bound(arr, arr+n, x) - arr;
	if(pos == n && arr[n-1] != x)	pos--;
	pll(pos); nl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = []
c = []

for i in range(m):
    si, ci = map(int, input().split())
    s.append(si)
    c.append(ci)

if m == 0 and n == 1:
    print(0)
    exit()

ans = list("1" + "0" * (n-1))
kakutei = [False]*n
for i in range(m):
    if kakutei[s[i]-1] and ans[s[i]-1] != str(c[i]):
        print(-1)
        exit()
    if s[i] == 1 and c[i] == 0 and n > 1:
        print(-1)
        exit()
    ans[s[i]-1] = str(c[i])
    kakutei[s[i]-1] = True
print("".join(ans))

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

using namespace std;

int main()
{
    int d;
    cin >> d;
    string s;
    if(d == 25){
        s = "Christmas";
    }else if(d == 24){
        s = "Christmas Eve";
    }else if(d == 23){
        s = "Christmas Eve Eve";
    }else if(d == 22){
        s = "Christmas Eve Eve Eve";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount


int32_t main(){
	set<int> s;
	int n,t;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t;
		s.insert(t);
	}
	if(s.size()==n){
		cout<<"YES";
	}
	else {
		cout<<"NO";
	}
}


Measured memory_bytes: 9600
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize
    }
    println!("{}", n / 2 * ((n + 1) / 2));
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n,r;cin>>n>>r;

  if(n>=10){
    out(r);
  }
  else{
    out(r+100*(10-n));
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 2005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
ll Z,W;
ll a[SIZE];

ll A[SIZE][SIZE],B[SIZE][SIZE];

ll mx[SIZE],mn[SIZE];

int main(){
  cin >> N >> Z >> W;
  rep(i,1,N+1) cin >> a[i];

  A[0][N] = B[0][N] = abs(Z-a[N]);
  A[N][0] = B[N][0] = abs(W-a[N]);
  rep(i,1,N){
    A[i][N] = B[i][N] = abs(a[i]-a[N]);
    A[N][i] = B[N][i] = abs(a[i]-a[N]);
  }

  fill(mn,mn+N+2,INF);

  for(int i=N-1;i>=0;i--){
    for(int j=N-1;j>=0;j--){
      if(i==j)continue;
      if(i<j){
        mx[j] = max(mx[j],B[j+1][j]);
        A[i][j] = mx[j];
      }
      if(i>j){
        mn[i] = min(mn[i],A[i][i+1]);
        B[i][j] = mn[i];
      }
      /*
      if(i<j) rep(k,j+1,N+1){
        A[i][j] = max(A[i][j],B[k][j]);
      }
      ll u = INF;
      if(i>j) rep(k,i+1,N+1){
        u = min(u,A[i][k]);
        B[i][j] = u;
      }
      */
    }
  }
  rep(k,1,N+1){
    A[0][0] = max(A[0][0],B[k][0]);
  }
  cout << A[0][0] << endl;

  return 0;
}


Measured memory_bytes: 60672
<?php 
  list($n, $m) = explode(" ", trim(fgets(STDIN)));

  $mod = 1000000007;

  $now = 0;
  $a = [-1];
  $b = [];
  $dp = [];
  for($i=1; $i<=$m; $i++){
    list($ana) = explode(" ", trim(fgets(STDIN)));
    $a[] = $ana;
    $b[$ana] = 0;
    if($a[$i]-$a[$i-1] == 1){
      echo "0";
      exit;
    }
  }

  if(isset($b[1])){
    $dp = [1, 0];
  }else{
    $dp = [1, 1];
  }
  for($i=2; $i<=$n; $i++){
    if(isset($b[$i])){
      $dp[$i] = 0;
    }
    else{
      $dp[$i] = ($dp[$i-1] + $dp[$i-2]) % $mod;
    }
  }
//  var_dump($dp);
//exit;
  echo $dp[$n];
       
  

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

using namespace std;

const int inf = 1 << 29;

int main(){
  int N,M,R; cin >> N >> M >> R;
  vector<int> r(R);
  for(int i = 0; i < R; i++){ cin >> r[i];} 
  sort(r.begin(),r.end()); //sortしないとnext_permutation作動しない
  
  vector<vector<int>> dist( 2010,vector<int>(2010,inf));
  //distは1-indexed管理
  
  for(int i = 0; i < M; i++){
    int a,b,c; cin >> a >> b >> c; 
    dist[a][b] = c; dist[b][a] = c;}
  
  for(int j = 0; j < 2010; j++){
    dist[j][j] = 0;} //対角成分をあらかじめ0へ
  
  for(int k = 1; k <= N; k++){
    for(int i = 1; i <= N; i++){
      for(int j = 1; j <= N; j++){
        dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);}}}
  //warshall-floyd
  
  long long  ans = inf;
  
  do{ long long sum = 0;
  
    for(int i = 0; i < R - 1; i++){
      
      sum += (long long) dist[r[i]][r[i+1]];}
     
     ans = min(ans,sum);
  
  }while(next_permutation(r.begin(),r.end()));
  
  cout << ans << endl; return 0;}
          
  
  

Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

// AtCoder Beginner Contest 138
//オーバーフローに注意！！
//焦らずに！！
int main(){

    int a; cin >> a;
    string s; cin >> s;

    if(a >= 3200)cout << s << endl;
    else cout << "red" << 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 main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<int> p(n);
	rep(i, n) cin >> p[i];

	int mx = 0;
	int sm = 0;
	rep(i, n){
		mx = max(mx, p[i]);
		sm += p[i];
	}

	cout << sm - mx / 2 << endl;

}


Measured memory_bytes: 256
n, m=map(int, raw_input().split())
adj=[[] for i in range(n+1)]
for i in range(m):
	a, b=map(int, raw_input().split())
	adj[a].append(b)
	adj[b].append(a)
q=input()
bucket=[[] for i in range(11)]
for i in range(q):
	v, d, c=map(int, raw_input().split())
	bucket[d].append((v, c, i))
result=[0]*(n+1)
time=[-1]*(n+1)
for i in range(10, -1, -1):
	new_result=result[:]
	new_time=time[:]
	for cur in range(n+1):
		for to in adj[cur]:
			if new_time[to]<time[cur]:
				new_time[to]=time[cur]
				new_result[to]=result[cur]
	result=new_result
	time=new_time
	for cur, color, t in bucket[i]:
		if time[cur]<t:
			time[cur]=t
			result[cur]=color
for i in range(1, n+1):
	print result[i]
print


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

#define int long long
#define pb emplace_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	int a[n+1] , b[n+1] = {0} , c[n+1] = {0};
	f(i,1,n+1)    cin >> a[i];
	
	for(int i = n ; i >= 1 ; i--)
	{
		int temp = 0;
		for(int j = i*2 ; j<=n ; j+= i)
			temp += b[j];

		if(a[i] == 0)
		{
			if(temp % 2==0) b[i] = 0;
			else            b[i] = 1;
		}
		else
		{
			if(temp %2 == 0)    b[i] = 1;
			else                b[i] = 0;
		}
	}
	
	bool chk = false;
	for(int i=1 ; i<=n ; i++)
	{
		int temp = 0;
		for(int j = i ; j<= n ; j+= i)
			temp += b[j];
			
		if(temp % 2 != a[i])
		{
			chk  = true;
			break;
		}
	}

	
	if(chk) return cout << "-1" , 0;
	int cnt = 0;
	for(int i=1 ; i<=n ; i++)   if(b[i] == 1)   cnt++;
	
	cout << cnt << "\n";
	for(int i=1 ; i<=n ; i++)
	{
		if(b[i] == 1)   cout << i << " ";
	}
	
	
}







Measured memory_bytes: 5632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int kai[100010];

void setkai(int n) {
	kai[0] = 1;
	for (int i = 1; i <= n; i++) {
		kai[i] = kai[i - 1] * i;
		kai[i] %= MOD;
	}
}

int perm(int n, int r) {
	if (n < 0 || r < 0 || n < r) return 0;
	return kai[n] * modinv(kai[n - r], MOD) % MOD;
}

int comb(int n, int r) {
	if (n < 0 || r < 0 || n < r) return 0;
	return perm(n, r) * modinv(kai[r], MOD) % MOD;
}

int a[100005];

signed main() {
	setkai(100005);
	int n, a[100005], cnt = 0;
	cin >> n;
	n++;
	rep(i, n) {
		a[i] = -1;
	}
	rep(i, n) {
		int x;
		cin >> x;
		x--;
		if (a[x] != -1) {
			cnt = a[x] + (n - 1 - i);
		}
		a[x] = i;
	}
	rep(i, n) {
		int ans = comb(n, i + 1);
		if (i == 0) ans -= 1;
		else if (i <= cnt) ans -= comb(cnt, i);
		if (ans < 0) ans += MOD;
		cout << ans << endl;
	}

	return 0;
}


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

int main() {
  string s;
  int k;
  cin >> s >> k;
  int t0 = s.size();
  vector<string> v, u;
  for (int i = 0; i < t0; i++) {
    v.push_back(s.substr(i, t0 - i));
  }

  sort(begin(v), end(v));
  //   for (auto&& w : v) cerr << w << " ";
  //   cerr << endl;
  int t1 = v.size();
  bool flg;

  for (int i = 0; i < t1; i++) {
    flg = false;
    int t2 = v[i].size();
    for (int j = 1; j <= t2; j++) {
      u.push_back(v[i].substr(0, j));
    }
    sort(begin(u), end(u));
    u.erase(unique(begin(u), end(u)), u.end());
    // for (auto&& w : u) cerr << w << " ";
    // cerr << endl;
    if (u.size() >= k) {
      flg = true;
      break;
    }
    if (flg) break;
  }
  cout << u[k - 1] << endl;
}

Measured memory_bytes: 24960
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>

#define MOD 1000000007

int cp[70505],lcp;
int f[70505],sum[70505];

int main()
{
	int N,M;scanf("%d%d",&M,&N);
	for(register int l=1,r;l<=M;l=r+1)
		r=M/(M/l),cp[++lcp]=r;
	for(register int j=1;j<=lcp;j++)
		f[j]=cp[j]-cp[j-1],
		sum[j]=(sum[j-1]+f[j])%MOD;
	for(register int i=2;i<=N;i++)
	{
		for(register int j=1;j<=lcp;j++)
			f[j]=(long long)sum[lcp-j+1]*(cp[j]-cp[j-1])%MOD;
		for(register int j=1;j<=lcp;j++)
			sum[j]=(sum[j-1]+f[j])%MOD;
	}
	printf("%d\n",sum[lcp]);
	return 0;
}

Measured memory_bytes: 896