akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
int X , Y ;
int sum;
cin >> X >> Y;
for(int i = 0; i <= X;i++)
{
  sum = 2*i + 4*(X-i);
    if(sum == Y)
    {
      cout << "Yes" << endl;
      break;
    }
}
  if(sum != Y)
  {
     cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    int N,K; cin>>N>>K;
    int ans=0;
    for (int i = 0; i < N; ++i) {
        int tmp; cin>>tmp;
        if(tmp>=K) ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<bool> seen(N,false);
    vector<vector<int>> edge(N,vector<int>());
    vector<int> C(N);
    vector<int> D(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    ll M=0;
    rep(i,N){
        cin >> C[i];
        M += C[i];
    }
    sort(C.rbegin(),C.rend());
    cout << M - C[0] << endl;
    queue<int> q;
    q.push(0);
    seen[0]=true;
    int ix = 0;
    while(!q.empty()){
        int now = q.front();
        q.pop();
        D[now] = C[ix];
        ix++;
        for(auto nx:edge[now]){
            if(seen[nx]==false){
                q.push(nx);
                seen[nx]=true;
            }
        }
    }
    rep(i,N){
        cout << D[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4008
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int a,b,c,d;
	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
	if(a + b + c + d == 7)	printf("%d+%d+%d+%d=7\n", a,b,c,d);
	else if(a + b + c - d == 7)	printf("%d+%d+%d-%d=7\n", a,b,c,d);
	else if(a + b - c + d == 7)	printf("%d+%d-%d+%d=7\n", a,b,c,d);
	else if(a + b - c - d == 7)	printf("%d+%d-%d-%d=7\n", a,b,c,d);
	else if(a - b + c + d == 7)	printf("%d-%d+%d+%d=7\n", a,b,c,d);
	else if(a - b + c - d == 7)	printf("%d-%d+%d-%d=7\n", a,b,c,d);
	else if(a - b - c + d == 7)	printf("%d-%d-%d+%d=7\n", a,b,c,d);
	else if(a - b - c - d == 7)	printf("%d-%d-%d-%d=7\n", a,b,c,d);
	return 0;
}


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

int main(){
  int a, b, r = 0;
  cin >> a >> b;
  if(a < b) swap(a, b);
  
  rep(i, a, b){
    if(a - i == i - b){
      cout << i << endl;
      r = 1;
      break;
    }
  }
  if(r == 0) cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll InF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 200010;

ll n, L, X[maxn], ps[3][maxn];

// ps[0][i] = X[0] + ... + X[i]
// ps[1][i] = X[0] * 0 + X[1] * 1 + ... + X[i] * i
// ps[2][i] = X[0] * n + X[1] * (n-1) + ... + X[i] * (n-i)

// start of L to end of R

ll sum0(ll l, ll r) {
    return ps[0][r] - ps[0][l];
}

ll sum1(ll l, ll r) {
    return ps[1][r] - ps[1][l] - (ps[0][r] - ps[0][l]) * l;
}

ll sum2(ll l, ll r) {
    return ps[2][r] - ps[2][l] - (ps[0][r] - ps[0][l]) * (n - r);
}

ll calc() {
    fori (i, n) {
        ps[0][i + 1] = ps[0][i] + X[i + 1];
        ps[1][i + 1] = ps[1][i] + X[i + 1] * (i + 1);
        ps[2][i + 1] = ps[2][i] + X[i + 1] * (n - i);
    }
    ll mx = 0;
    fori (i, n - 1) {
        ll val;
        if (i % 2) {
            val = sum1(n - i / 2, n) * 2 + sum0(0, n - 1 - i) * (i + 1) + sum2(n - 1 - i, n - 2 - i / 2) * 2 + sum0(n - 1 - i / 2, n);
        } else {
            val = sum1(n - i / 2, n) * 2 + sum0(0, n - 1 - i) * (i + 1) + sum2(n - 1 - i, n - 1 - i / 2) * 2 - sum0(n - 1 - i, n - 1 - i / 2);
        }
        smax(mx, val);
    }
    return mx;
}

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

    cin >> L >> n;
    fori (i, n) cin >> X[i + 1];
    ++n;
    X[n] = L;
    forir (i, n) X[i + 1] -= X[i];
    ll ans = calc();
    reverse(X + 1, X + n + 1);
    smax(ans, calc());
    cout << ans << '\n';

}


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

signed main(void)
{
	long long n, m;
	long long ans;

	cin >> n >> m;
	ans = 0;
	if (n >= 2 && m >= 2)
		ans = (n - 2) * (m - 2);
	else if (n == 1 && m >= 2)
		ans = m - 2;
	else if (m == 1 && n >= 2)
		ans = n - 2;
	else if (n == 1 && m == 1)
		ans = 1;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int a, b;
    cin >> a >> b;

    char c[100][100];

    rep(i, 50) {

        rep(j, 100) {
            c[i][j] = '.';
            c[i + 50][j] = '#';
        }
    }

    int white = 1;
    int black = 1;

    int i = 0;
    int j = 0;

    while (black < b) {
        c[i][j] = '#';
        black++;
        if (j + 2 >= 100) {
            i += 2;
            j = 0;
        } else {
            j += 2;
        }
    }

    i = 99;
    j = 0;

    while (white < a) {
        c[i][j] = '.';
        white++;
        if (j + 2 >= 100) {
            i -= 2;
            j = 0;
        } else {
            j += 2;
        }
    }

    cout << "100 100" << endl;

    rep(i, 100) {
        rep(j, 100) cout << c[i][j];
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int mod=998244353,N=3010;
void Add(int &x,int y) { x=(x+y)%mod; }
int Pow(int x,int y) {
	int res=1;
	while(y) {
		if(y&1) res=res*(ll)x%mod;
		x=x*(ll)x%mod,y>>=1;
	}
	return res;
}
int fac[N],inv[N];
int C(int n,int m) {
	if(n<m) return 0;
	return fac[n]*(ll)inv[m]%mod*inv[n-m]%mod;
}
void get_fac(int n) {
	fac[0]=1; for(int i=1;i<=n;++i) fac[i]=fac[i-1]*(ll)i%mod;
	inv[n]=Pow(fac[n],mod-2); for(int i=n;i>=1;--i) inv[i-1]=inv[i]*(ll)i%mod;
}
int cal1(int m,int n) { // m¸öÎ»ÖÃ ÓÃ 1,2 ´Õ n 
	if(m>n) return 0;
	return C(m,n-m);
}
int solve(int n,int X) { // n ¸öÎ»ÖÃ  ²»³öÏÖ x
	int ans=0;
	for(int i=0;i<X;++i) Add(ans,cal1(n,i));
	if(2*n<X) return ans;
	
	for(int i=1;i*2<=X-1;++i) {
		Add(ans,cal1(n-i*2,X-1-2*i));
	}
	if(X%2==1&&X-1<n) Add(ans,1);
	return ans;
}
int main() {
	int n,X; rd(n),rd(X);
	get_fac(n);
	int ans=0;
	for(int i=0;i<=n;++i) {
//		cout<<solve(i,X)<<endl;
		Add(ans,C(n,i)*(ll)solve(i,X)%mod);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <iterator>
using namespace std;

set<string> char_cnt(string s) {
	set<string> st;
	for (int i = 0; i < s.size(); ++i) {
		string t = s.substr(i,1);
		st.insert(s.substr(i,1));
	}
	return st;
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int max_n = 0;
	for (int i = 1; i < s.size(); ++i) {
		auto x_s = char_cnt(s.substr(0,i));
		auto y_s = char_cnt(s.substr(i, s.size() - i));
		set<string> result;
		set_intersection(x_s.begin(), x_s.end(), y_s.begin(), y_s.end(), inserter(result, result.end()));
		int tmp_n = result.size();
		if (tmp_n > max_n) max_n = tmp_n;
	}
	cout << max_n << endl;
	
	return 0;
}

Measured memory_bytes: 256
// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);
const int maxm = 100001;

class Node
{
public:
    int end;
    map<char, Node *> al;

    Node() : end(0) {}
};

class Trie
{
public:
    Node *root;
    int ans;
    Trie() : ans(0), root(new Node()) {}

    void ins(string s)
    {
        Node *d = root;

        loop(i, 0, s.size())
        {
            if (d->al.find(s[i]) == d->al.end())
                d->al[s[i]] = new Node();

            if (d->end == 1)
                ans = 1;
            d = d->al[s[i]];
        }

        if (d->end == 1 || d->al.size())
            ans = 1;

        d->end = 1;
    }
};
void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    
    cout<<t*(n/x) + (n%x?t:0)<<"\n";
}
int main()
{
    io;

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    solve();

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

int main() {
    long long n, sum = 0, is1 = 0, a = 1;
    cin >> n;
    vector<int> as(n);
    vector<int> bs(n);
    map<long long, long long> cnt;
    for (int i = 0; i < n; i++){
        cin >> as[i];
        if (as[i] == 1){
            is1++;
        }
    }
    if (is1 == 0){
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++){
        if (as[i] == a){
            a++;
        }
    }
    cout << n - a + 1 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

int main()
{
    i64 n;
    int k;
    cin >> n >> k;

    int digits = 0;
    i64 power = 1;
    while (power <= n)
    {
        digits++;
        power *= k;
    }

    cout << digits << endl;

    return 0;
}

Measured memory_bytes: 256
# print('input >>')
N, M = map(int,(input().split()))
H = list(map(int,(input().split())))
ABs = []
for _ in range(M):
    ABs.append(tuple(map(int,(input().split()))))

lists = [[] for _ in range(N)]

for AB in ABs:
    A, B = AB
    lists[A-1] += [H[B-1]]
    lists[B-1] += [H[A-1]]

ans = 0

for i, list_ in enumerate(lists):
    if all([H[i] > h for h in list_]) or len(list_) == 0:
        ans += 1

# print('-----output-----')
print(ans)

Measured memory_bytes: 36996
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> c(n - 1), s(n - 1), f(n - 1);
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i] >> s[i] >> f[i];
    }
    vector<int> ans(n);
    for (int i = 0; i <= n - 2; i++)
    {
        ans[i] = 0;
        for (int j = i+1; j < n; j++)
        {
            if (ans[j - 1] == s[j - 1])
            {
                ans[j] = ans[j - 1] + c[j - 1];
            }
            else if (ans[j - 1] < s[j - 1])
            {
                ans[j] = s[j - 1] + c[j - 1];
            }
            else if (ans[j - 1] > s[j - 1])
            {
                int t = s[j - 1];
                while (t < ans[j - 1])
                {
                    t += f[j - 1];
                }
                ans[j] = t + c[j - 1];
            }
        }
        cout << ans[n-1] << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = 1
flg = 0
rev = 0 # 0:単調非増加、1:単調非減少
for c,n in zip(A, A[1:]):
    
    if not flg:
        if c < n:
            # 単調非増加を仮定する
            flg = 1
        elif c > n:
            # 単調非減少を仮定する
            flg = 1
            rev = 1
    else:
        if rev:
            c = -c
            n = -n

        if c > n:
            ans += 1
            flg = 0
            rev = 0
            
print(ans)

Measured memory_bytes: 20000
(let* ((n (read))
       (m (read))
       (arr (make-array n :initial-element 0 :element-type 'fixnum))
       (gatea (make-array m :initial-element 0 :element-type 'fixnum))
       (gateb (make-array m :initial-element 0 :element-type 'fixnum))
       (ans 0))
  (loop :for a :from 0 :upto (1- m) :do(setf (aref gatea a) (1- (read)))
        :do(setf (aref gateb a) (1- (read))))
  (setf ans (1+ (- (loop :for a :across gateb :minimize a) (loop :for a :across gatea :maximize a))))
  (princ (if (<= ans 0) 0 ans)))

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

using i64 = long long;

int f[256];

int main() {
#ifdef HOME
	freopen("agc09b.in", "r", stdin);
	freopen("agc09b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	string str;
	i64 ant, n;

	ant = 0;
	cin >> str, n = str.size();
	for (int i = 0; i < n; ++i)
		ant+= f[str[i]]++;

	ant = n * (n - 1) / 2 - ant;
	cout << ++ant << endl;

	return 0; }


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
    return os << "(" << P.fi << "," << P.se << ")";
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
    os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
template <typename T>
T power_mod(T base, int exp, int mod = MOD) {
    T res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
template <typename T>
T power(T base, int exp) {
    T res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, MOD - 2);
}

/******************************** template ********************************/
map<int, int> mp;

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

    int a;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a);
        ++mp[a];
    }

    if (mp.size() <= k) {
        cout << 0;
        return 0;
    }

    vector<int> vec;
    for (auto i : mp) {
        vec.pb(i.second);
    }
    sort(all(vec), greater<int>());
    int res = 0;
    for (int i = k; i < vec.size(); ++i) {
        res += vec[i];
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 10748
// https://atcoder.jp/contests/abc080/tasks/abc080_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int N, P[100][11], m, t, s;
bool F[100][10];
int main()
{
  cin >> N;
  REP(i, N)
  {
    REP(j, 10)
    {
      cin >> F[i][j];
    }
  }
  REP(i, N)
  {
    REP(j, 11)
    {
      cin >> P[i][j];
    }
  }

  m = -INF;
  FOR(i, 1, 1024)
  {
    s = 0;
    REP(j, N)
    {
      t = 0;
      REP(k, 10)
      {
        if (i >> k & 1 && F[j][k])
          t++;
      }
      s += P[j][t];
    }
    m = max(m, s);
  }

  cout << m << '\n';

  return 0;
}


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

const int MAX_N = 1e5 + 1;
const int MAX_M = 1e5 + 1;

int color[MAX_N];
vector<int> graph[MAX_N];

void dfs(int node, int c) {
    color[node] = c;
    for (int i = 0; i < graph[node].size(); i++) {
        if (color[graph[node][i]]) continue;
        dfs(graph[node][i], c);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int x, y, z;
    for (int i = 0; i < M; i++) {
        cin >> x >> y >> z;
        x--, y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int now_color = 1;
    for (int i = 0; i < N; i++) {
        if (color[i]) continue;
        dfs(i, now_color);
        now_color++;
    }
    cout << now_color - 1 << endl;
    return 0;
}

Measured memory_bytes: 10752
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        if (s.length() == 2){
            System.out.println(s);
        } else {
            StringBuffer sr = new StringBuffer(s);
            String sred = sr.reverse().toString();
            System.out.println(sred);
        }
    }
}

Measured memory_bytes: 21332
program main
  implicit none
  
  integer(8) :: l0=2,l1=1,l2=3,i,n
  
  read(*,*)n
  if (n == 1) then
    write(*,*)1
    stop
  else if (n == 2) then
    write(*,*)3
    stop
  end if
  
  do i = 3, n
  	l0 = l1
    l1 = l2
    l2 = l0 + l1
  end do
  
  write(*,*)l2
end program main

Measured memory_bytes: 256
//
// Created by Kiran Chavhan on 05/07/2020.
//

#include<bits/stdc++.h>

#define int long long
#define MOD 1000000007
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    map<string,int>mp;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        mp[s]++;
    }

        cout<<"AC x "<<mp["AC"]<<'\n';
        cout<<"WA x "<<mp["WA"]<<'\n';
        cout<<"TLE x "<<mp["TLE"]<<'\n';
        cout<<"RE x "<<mp["RE"]<<'\n';


}

Measured memory_bytes: 3660
#include <stdio.h>
int main(){
  int n,x[100],c=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
    for(int j=0;j<i;j++)if(x[i]==x[j]){
      c--;
      break;
    }
    c++;
  }
  printf("%d",c);
  return 0;
}

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

int main(void)
{
    double a, b, c, d, e, f;
    while(cin >>a >> b >> c >> d >> e >> f) {
        double g = a * e - b * d;
        double h = (e * c - b * f) / g + 0;
        double i = (-d * c + a * f) / g + 0;
        cout << fixed << setprecision(3) << h << " " << i << endl;
    }
    return 0;
}




Measured memory_bytes: 3196
using System;
using System.Collections.Generic;

class A
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        long count = 0;
        long d = 0;
       
        while (N != 1)
        {
            N /= 2;
            count += (long)Math.Pow(2, d++);
        }
        Console.WriteLine(count + (long)Math.Pow(2, d));
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;

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

  vector<vector<long long> > tab(n+1);
  vector<long long > temp(w+1); for(int i=1; i<=w; i++) temp[i]=-1;
  for(int i=0; i<=n; i++) tab[i]=temp;

  int val,wht;
  for(int i=0; i<n; i++){
    cin>>wht>>val; int lek=w-wht;
    for(int j=0; j<=lek; j++ ){
        if(tab[i][j]!=-1){
            tab[i+1][j+wht]=tab[i][j]+val;
        }
    }
    for(int j=0; j<=w; j++ ){
        if(tab[i][j]>tab[i+1][j]) tab[i+1][j]=tab[i][j];
    }
  }

  long long ans=-1;
  for(int j=w; j>=0; j--){
    if(tab[n][j]>ans){ ans=tab[n][j]; }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 80256
Tmp = []
Tmp = input().rstrip().split(' ')
 
Ans = []
 
for i in range(3):
  nTmp = int(Tmp[i])
  
  Ans.append(nTmp)
 
Ans.sort()
 
nAns = (Ans[1]-Ans[0])
nAns += Ans[2]-Ans[1]

print(nAns)



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

int main(){
    vector<int> data(3);
    cin >> data.at(0) >> data.at(1) >> data.at(2);
    sort(data.begin(),data.end());
    cout << data.at(0) << " " << data.at(1) << " " << data.at(2) << endl;
    return 0;
    
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

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;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, p;
string s;
map<int, int> mp;
int cnt, cnt2 = 1;
int ans;

signed main() {
	cin >> n >> p >> s;
	if (p == 2 || p == 5) {
		for (int i = 0; i < n; i++) {
			if (!((s[i] - '0') % p))ans += i + 1;
		}
		cout << ans << endl;
		return 0;
	}
	mp[0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		cnt = (cnt + (s[i] - '0') * cnt2) % p;
		ans += mp[cnt];
		mp[cnt]++;
		cnt2 *= 10;
		cnt2 %= p;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1028
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    FOR(i, 1, 10)
    {
        if (N <= i * 1000)
        {
            cout << i * 1000 - N << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3648
/**
 *    author:  Mohamad Milhem
 *    created: 2020-03-23-17.40.52
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)

bool pal(string s){
    string v = s;
    reverse(s.begin(),s.end());

    return (s == v ? true : false);



}



int main(){

    FAST;


    string s;
    cin >> s;

    string second = s.substr(0 , (s.size()-1)/2);
    string first = second;
    reverse(second.begin(), second.end());
    string re = first + s[(s.size()-1)/2]+ second;

    if ((s == re)&&(pal(first))){cout << "Yes" <<endl;}
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) {
				break;
			}
			int[] s = new int[n];
			int sum = 0;
			for(int i = 0; i < n; i++) {
				s[i] = sc.nextInt();
				sum += s[i];
			}
			double m = sum/(double)n;
			double a = 0.0;
			for(int i = 0; i < n; i++) {
				a += (s[i] - m) * (s[i] - m);
			}
			a = a / (double)n;
			
			System.out.println(Math.sqrt(a));
		}
	}
}



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


int solve(string s1, string s2){
  int ans = 0;
  for (int i=0; i<s1.length(); i++){
    if (s1[i] != s2[s2.length() - 1 - i]){
      ans++;
    }
  }
  return ans;
}

int main(){
  string S;
  cin >> S;

  int l = S.length();

  if (l % 2 == 0){
    cout << solve(S.substr(0, l / 2), S.substr(l / 2, l / 2)) << endl;
  } else{
    cout << solve(S.substr(0, (l-1) / 2), S.substr((l+1) / 2, (l-1) / 2)) << endl;
  }
  return 0;
}


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

ll gcd(ll a, ll b) {
  return b ? gcd(b,a%b):a; //三項演算子
}

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

ll f(ll x, int c,int d) {
  ll res=x;
  res-=x/c; res-=x/d; res+=x/lcm(c,d);
  return res;
} 

int main() {
    ll a,b; int c,d;
    cin>>a>>b>>c>>d;
    ll ans=f(b,c,d)-f(a-1,c,d);
    cout<<ans<<endl;
    return 0;
}

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

static const int N = 200000; 
vector<int> A(N); 
int n ; 

int main(){
    int num = 30 ; 
    int stan = 0 ; 
    cin >> n ; 
    rep(i,n) cin >> A[i]; 
    rep(i,num){
        int cnt = 0 ; 
        rep(j,n)if(A[j] & (1 << i)) cnt++ ; 
        if(cnt % 2 == 1) stan |= (1 << i);
    }
    vector<int> ans(n,0);  
    rep(i,n){
        rep(j,num){
            if((A[i] & (1 << j)) && !(stan & (1 << j))) ans[i]|= (1 << j) ;
            else if(!(A[i] & (1 << j)) && (stan & (1 << j))) ans[i] |= (1 << j) ;
        }
    }
    rep(i,n) cout << ans[i] << " "; 
    cout << endl ; 
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<pii> A;
void input() {
  int x, y, z;
  cin>>N>>M;
  A.resize(M);
  rep(i,0,M-1){
    cin>>A[i].first>>A[i].second;
  }
  ;
}
void solve() {
  map<int,int> mp;
  for(auto x : A){
    mp[x.first]++;mp[x.second]++;
  }
  rep(i,1,N){
    cout<<mp[i]<<endl;
  }
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
/*Always success does not build on success,success build on failure and hardwork*/
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vec         vector<int>
#define map         map<int,int>
#define scn(t)      scanf("%d",&t);
#define lscn(t)      scanf("%lld",&t);
#define mod         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define endl        "\n"
using namespace std;
const int N=1e5+5;
int main()
{
      int n;
      scn(n);

      int k;
      scn(k);

      set<int> s;

      for(int i=0;i<10;i++)
      {
          s.insert(i);
      }

      for(int i=0;i<k;i++)
      {
          int a;
          scn(a);

          s.erase(a);
      }

      

      while(1)
      {
          bool cp=1;

          int check=n;

          while(check)
          {
              if(s.find(check%10)==s.end())
              {
                  cp=0;
                  break;
              }
              check/=10;
          }

          if(cp)
          {
              cout<<n<<endl;
              return 0;
          }

          n++;
      }
}



Measured memory_bytes: 3724
s=input()
s="<"+s+"<"
n=len(s)-1
ans=0
cur=0
temp=0
for i in range(1,n+1):
  if s[i-1]=="<" and s[i]=="<":
    ans+=cur
    cur+=1
  elif s[i-1]=="<" and s[i]==">":
    temp=cur
    cur=1
  elif s[i-1]==">" and s[i]==">":
    cur+=1
  else:
    ans+=cur*(cur+1)//2+max(0,temp-cur)
    cur=1
print(ans)


Measured memory_bytes: 4212
N = int(input())
S = [x[:1] for x in input()]
ans = 0

#SL,SR = S[:3],S[3:]

#print(S,SL,SR)

for i in range(1,N+1):
    SL,SR = S[:i],S[i:]
    count = 0
 #   print(SL,SR,count)
    while SL != [] and SR != []:
        if SL[0] in SR:
            count += 1
            a = SL[0]
            while a in SL and a in SR:
                SL.remove(a)
                SR.remove(a)
 #               print(SL,SR)
        elif SL[0] not in SR:
            a = SL[0]
            while a in SL:
                SL.remove(a)

#    print(count)

    if count >= ans:
        ans = count


print(ans)

Measured memory_bytes: 3064
list1 = [int(a) for a in input().split()]
list1_0 = list1[0] #A1
list1_1 = list1[1] #A2
list1_2 = list1[2] #A3

list2 = [list1_0, list1_1, list1_2]
list2.sort()
b = max(list2) - list2[1]
c = list2[1] - min(list2)
print(b + c)

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(void){
 
    char S[3];
    int n = 0;

    scanf("%s", S);
    
    if(strcmp("SUN",S) == 0)
        n = 0;
    if(strcmp("MON",S) == 0)
        n = 1;
    if(strcmp("TUE",S) == 0)
        n = 2;
    if(strcmp("WED",S) == 0)
        n = 3;
    if(strcmp("THU",S) == 0)
        n = 4;
    if(strcmp("FRI",S) == 0)
        n = 5;
    if(strcmp("SAT",S) == 0)
        n = 6;

    n = 7 - n;
    printf("%d\n", n);
 
    return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BI18n solver = new BI18n();
        solver.solve(1, in, out);
        out.close();
    }

    static class BI18n {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String s = in.readLine();
            out.print(s.charAt(0) + "" + (s.length() - 2) + "" + s.charAt(s.length() - 1));
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

    }
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

int32_t main()
{
    IOS;
int n,x,prev,cur,ans=0;
cin>>n>>x;
    for (int i = 0; i < n; ++i) {
        cin>>cur;
        if(!i){prev=cur;
            continue;}
        if(cur>x)ans+=cur-x,cur=x;
         if(cur+prev>x){
            int t=cur+prev-x;
            ans+=t;
            if(t>cur)t-=cur,cur=0;
            else cur-=t;
        }
        prev=cur;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a[500][500],f[500],flag[500],ans;
bool fk[500],ff;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}
signed main(){
	n=read();m=read();for (int i=1;i<=n;i++)for (int j=1;j<=m;j++)a[i][j]=read();
	for (int i=1;i<=n;i++)f[i]=1,flag[a[i][1]]++;ff=1;ans=1e9;
	while (ff){
		int k=0;for (int i=1;i<=m;i++)if (flag[i]>flag[k])k=i;
		ans=min(ans,flag[k]);fk[k]=1;
		for (int i=1;i<=n;i++){
			while (fk[a[i][f[i]]])flag[a[i][f[i]]]--,f[i]++,flag[a[i][f[i]]]++;
			ff&=f[i]!=m+1;
		}
	}cout<<ans<<endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e15;
typedef pair<int,int> ii;
typedef vector<int> vi;
const int max_item_cnt=100+10;
const int max_value_possible=1e5+10;
ll W[max_item_cnt],V[max_item_cnt];
ll dp[2][max_value_possible];//dp[i][j]-min weight to get at least j space from 1-th to i-th element
bool sol[max_item_cnt];
int main(){
	ll n,w;
	cin>>n>>w;
	ll max_val=0;
	for(int i=1;i<=n;i++){
		cin>>W[i]>>V[i];
		max_val+=V[i];
 
	}
	for(int i=1;i<max_value_possible;i++){
			dp[0][i]=dp[1][i]=inf;
	}
	for(int i=1;i<=n;i++){
		int t = i%2;
		for(int j=0;j<=max_val;j++){
			if(j>=V[i]){
				dp[t][j]=min(dp[!t][j],dp[!t][j-V[i]]+W[i]);
			}else{
				dp[t][j]=dp[!t][j];
			}
			
		}
	}
	int ans=0;
	for(int v=max_val;v>=0 && !ans;v--){
		if(dp[n%2][v]<=w){
			ans=v;
		}
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<ll, ll> P;
#define fs first
#define sc second

ll dp[101][2][4];

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

    dp[0][1][0] = 1;
    for(int i = 0; i < (int)N.size(); i++){
        int n = N[i] - '0';

        dp[i + 1][0][0] = 1;
        dp[i + 1][1][0] = 0;

        if(n != 0){
            dp[i + 1][1][1] = dp[i][1][0];
            dp[i + 1][1][2] = dp[i][1][1];
            dp[i + 1][1][3] = dp[i][1][2];

            dp[i + 1][0][1] = dp[i][1][1] + dp[i][0][1] + 9 * dp[i][0][0] + (n - 1) * dp[i][1][0];
            dp[i + 1][0][2] = dp[i][1][2] + dp[i][0][2] + 9 * dp[i][0][1] + (n - 1) * dp[i][1][1];
            dp[i + 1][0][3] = dp[i][1][3] + dp[i][0][3] + 9 * dp[i][0][2] + (n - 1) * dp[i][1][2];
        }
        else {
            //n == 0
            dp[i + 1][1][1] = dp[i][1][1];
            dp[i + 1][1][2] = dp[i][1][2];
            dp[i + 1][1][3] = dp[i][1][3];

            dp[i + 1][0][1] = dp[i][0][1] + 9 * dp[i][0][0];
            dp[i + 1][0][2] = dp[i][0][2] + 9 * dp[i][0][1];
            dp[i + 1][0][3] = dp[i][0][3] + 9 * dp[i][0][2];
        }
    }



    cout << dp[(int)N.size()][1][K] + dp[(int)N.size()][0][K] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> v(N);
  FOR(i,0,N) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double ans = (v[0] + v[1]) / 2.0;
  FOR(i,2,N) {
    ans = (ans + v[i]) / 2.0;
  }
  cout << ans << endl;
}



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

int main() {
    int R, G;
    cin >> R >> G;
    cout << G * 2 - R << endl;
    return 0;
}


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

using namespace std;
using ll = long long;


int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }

    vector<bool> vb(n, false);
    vb[0] = true;
    int pos = 0;
    int loop = -1;
    while(true){
        int next = a[pos];
        if(vb[next]){
            loop = a[next];
            break;
        }
        vb[next] = true;
        pos = next;
    }

    int last = 0;
    for(ll i = 0; i < k; i++){
        if(last == loop){
            int c = 1;
            int d = a[last];
            while(d != loop){
                c++;
                d = a[d];
            }
            k -= ((k-i) / c) * c;
            if(i == k){
                cout << last + 1 << endl;
                return 0;
            }
        }
        last = a[last];
    }
    cout << last + 1 << endl;
}

Measured memory_bytes: 4052
class LinkedList

  attr_reader :first, :last
  
  Node = Struct.new("Node", :prev, :next, :key)
  
  def initialize(key)
    @first = @last = Node.new(nil, nil, key)
  end

  def insert(key)
    if @first.nil? and @last.nil?
      initialize(key)
    else
      @last.next = @last = Node.new(@last, nil, key)
    end
  end

  def delete(key)
    x = list_search(key)
    return if x.nil?
    unless x.prev.nil?
      x.prev.next = x.next
    else
      deleteLast
    end
    unless x.next.nil?
      x.next.prev = x.prev
    else
      deleteFirst
    end
  end

  def deleteLast
    if @first.next.nil?
      @first = @last = nil
    else
      @first.next.prev = nil
      @first = @first.next
    end
  end

  def deleteFirst
    if @last.prev.nil?
      @first = @last = nil
    else
      @last.prev.next = nil
      @last = @last.prev
    end
  end

  def list_search(key)
    value = @last
    until value.nil?
      if value.key == key
        return value
      end
      value = value.prev
    end
  end

  def reverse_print
    value = @last
    printable = ""
    until value.nil?
      printable <<= "#{value.key} "
      value = value.prev
    end
    puts printable.chop
  end
end

n = gets.chomp.to_i

a = LinkedList.new(gets.chomp.split(" ")[1].to_i)

(n-1).times do |i|
  x, y = gets.chomp.split(" ")
  if x == "insert"
    a.insert(y.to_i)
  elsif x == "delete"
    a.delete(y.to_i)
  elsif x == "deleteFirst"
    a.deleteFirst
  elsif x == "deleteLast"
    a.deleteLast
  end
end

a.reverse_print



Measured memory_bytes: 64152
x,y=map(int,input().split())

if (x+y)%3!=0:
    print(0)
    exit()
    
a=(2*y-x)//3
b=(2*x-y)//3

if a<0 or b<0:
    print(0)
    exit()

mod=10**9+7

F=[1]
for i in range(1,a+b+1):
    tmp=F[-1]*i
    F.append(tmp%mod)

Ia=pow(F[a],mod-2,mod)
Ib=pow(F[b],mod-2,mod)

ans=F[a+b]*Ia*Ib%mod
print(ans)


Measured memory_bytes: 66328
#include <iostream>

int main(){
	int K,S;
	std::cin>>K>>S;
	int count = 0,X,Y,Z;

	for(int i=0;i<=K;++i){
		X = i;
		for(int j=0;j<=K;++j){
			Y = j;
			Z = S - X - Y;
			if(0<=Z && Z<=K)count++;
		}
	}
	std::cout<<count;
	return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
A = [a-1 for a in A]

x -= 1
l = 0
for i in range(x+1):
    if i in A:
        l += 1
r = 0
for i in range(x, n):
    if i in A:
        r += 1
print(min(l, r))


Measured memory_bytes: 38384
H, W = [int(x) for x in input().split()]
pic = [list(input()) for _ in range(H)]
ans = [['#' for i in range(W+2)] for j in range(H+2)]
for i in range(H):
  for j in range(W):
    ans[i+1][j+1] = pic[i][j]
low = ''
for i in range(H+2):
  for j in range(W+2):
    low += ans[i][j]
  print(low)
  low = ''

Measured memory_bytes: 9104
a = input()
x = 0
y = 0
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "1":
        x = x+1
    if a[t] == "0" and t%2 == 1:
        x = x+1
        
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "0":
        y = y+1
    if  t%2 == 1 and a[t] == "1":
        y= y+1
        
print (min(y,x))
    


Measured memory_bytes: 3188
n,a,b,c,d = gets.chomp.split(' ').map(&:to_i)
s = gets.chomp

# 連続岩 = false
追い抜く必要性 = c > d
# 追い抜ける = false
連続岩 = s[(a-1)..(([c,d].max)-1)].include?('##')
if 追い抜く必要性
  追い抜ける = s[(b-2)..d].include?('...')
end
# s.split('').each_with_index do |char, i|
#   x = i + 1
#   if x > a && (x < c || x < d)
#     if char == '#' && s[i-1] == '#'
#       連続岩 = true
#       break
#     end
#   end
# 
#   if 追い抜く必要性 && x > b && x <= d
#     if char == '.' && s[i-1] == '.' && s[i-2] == '.'
#       追い抜ける = true
#     end
#   end
# end

if 連続岩
  puts 'No'
  exit
end

if 追い抜く必要性
  unless 追い抜ける
    puts 'No'
    exit
  end
end

puts 'Yes'

Measured memory_bytes: 2300