akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
    import java.util.Arrays;
    public class Main{
    public static void main(String args[]){
    int A = 0;
    int B = 0;
    int C = 0;
    int w = 0;

    Scanner scan = new Scanner(System.in);
    A = scan.nextInt();
    B = scan.nextInt();
    C = scan.nextInt();

    if(A==5 && B==5 && C==7){
    System.out.println("YES");
    w++;
    }
    if(A==5 && B==7 && C==5){
    System.out.println("YES");
    w++;
    }
    if(A==7 && B==5 && C==5){
    System.out.println("YES");
    w++;
    }
    if(w==0)System.out.println("NO");

    }
    }

Measured memory_bytes: 10064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)

#define rdi(i) ll i; scanf("%lld", &i)
#define rds(s) string s; cin >> s
#define rdc(c) char c; cin >> c

#define INF 10000000000

int main()
{
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }
    ll tmp = -1;
    rrep(i, 1, n) { tmp = max(tmp, a[i] - a[i - 1]); }
    tmp = max(tmp, a[0] + k - a[n - 1]);
    cout << k - tmp << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;

typedef long long ll;

int main(){
	ll n,tmp=1,ans=0;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]!=tmp){ans++;}
		else{tmp++;}
	}
	if(tmp==1){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll n;
    cin>>n;
    vector<ll>a(n,0);//正の数
    vector<ll>b(n,0);//負の数
    vector<ll>c(n,0);
    ll pos=0;
    ll neg=0;
    // cout<<a.size()<<endl;
    for(int i=0;i<n;i++){
        // cout<<123456<<endl;
        ll x;
        cin>>x;
        c.at(i)=x;
        if(x>=0){
            a.at(pos)=x;
            pos++;
            // cout<<123456<<endl;
        }
        else{
            b.at(neg)=x;
            neg++;
        }
        // cout<<123456<<endl;
    }
    // cout<<12344<<endl;
    if(pos!=0 && neg!=0){
        ll ans=0;
        for(int i=0;i<n;i++){
            ans+=abs(c.at(i));
        }
        cout<<ans<<endl;

        for(int i=0;i<pos-1;i++){
            cout<<b.at(0)<<" "<<a.at(i)<<endl;
            b.at(0)=b.at(0)-a.at(i);
        }
        for(int i=0;i<neg;i++){
            cout<<a.at(pos-1)<<" "<<b.at(i)<<endl;
            a.at(pos-1)=a.at(pos-1)-b.at(i);
        }
    }
    if(neg==0){
        ll ans=0;
        sort(a.begin(),a.end());
        for(int i=0;i<n-1;i++){
            ans+=a.at(i+1);
        }
        cout<<ans-a.at(0)<<endl;

        for(int i=0;i<n-2;i++){
            cout<<a.at(0)<<" "<<a.at(i+1)<<endl;
            a.at(0)=a.at(0)-a.at(i+1);
        }
        cout<<a.at(n-1)<<" "<<a.at(0)<<endl;

    }
    if(pos==0){
        ll ans=0;
        sort(b.begin(),b.end());
        for(int i=0;i<n-1;i++){
            ans+=b.at(i);
        }
        cout<<abs(ans)+b.at(n-1)<<endl;

        for(int i=0;i<n-1;i++){
            cout<<b.at(n-1)<<" "<<b.at(i)<<endl;
            b.at(n-1)=b.at(n-1)-b.at(i);
        }

    }

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll r,g,b,n;
ll dp[5000];
ll ds(int n) {
	if(n == 0) return 1;
	if(n < 0) return 0;
	if(dp[n] != -1) return dp[n];
	ll tot = 0;
	if(!(n%b)) {tot++;}
	return dp[n] = tot+ds(n-g);
}
int main() {
	memset(dp,-1,sizeof(dp));
	cin >> r >> g >> b >> n;
	ll tot = 0;
	for(int i=0;i<=n;i++) {
		tot += ds(n-r*i);
	}
	cout << tot << '\n';
}


Measured memory_bytes: 384
l = input().split()
n = int(l[0])
m = int(l[1])

#ベクトルの初期化
A = [[] for i in range(n)]
b = [0 for i in range(m)]
#答えのベクトル
ans = [0 for i in range(n)]

for i in range(n):
    A[i] = list(map(int,input().split()))

for i in range(m):
    b[i] = int(input())

for i in range(n):
    for j in range(m):
        ans[i] += A[i][j] * b[j]

for val in ans:
    print(val)







Measured memory_bytes: 6032
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
vector <int> g[100010];
int d[100010][2];
int inf=1e9;
void dfs(int x, int par)
{
    for (int i=0;i<g[x].size();i++)
    {
        if (g[x][i]==par) continue;
        dfs(g[x][i],x);
        d[x][1]+=d[g[x][i]][1];
        d[x][0]=max(d[x][0],d[g[x][i]][0]);
    }
    int y=d[x][1];
    for (int i=0;i<g[x].size();i++)
    {
        if (g[x][i]==par) continue;
        d[x][1]=min(d[x][1],y-d[g[x][i]][1]+d[g[x][i]][0]);
    }
    d[x][1]=max(1,d[x][1]);
    if (g[x].size()>2) d[x][0]=inf;
    if (g[x].size()==1)
    {
        d[x][0]=0;
        d[x][1]=1;
        return;
    }
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for (i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (i=0;i<n;i++) if (g[i].size()>2) break;
    if (i==n)
    {
        printf("1\n");
        return 0;
    }
    dfs(i,-1);
    printf("%d\n",d[i][1]);
    return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &x:v)
        cin>>x;
    sort(v.begin(),v.end());
    int cnt=0;
    for(int i=0;i<n-2;i++)
    {   
        for(int j = i+1;j<n-1;j++)
        {
            if(v[j] == v[i])
                continue;
            for(int k = j+1;k<n;k++)
            {
                if(v[k] == v[j])
                    continue;
                if(v[i]+v[j] > v[k])
                        cnt++;
            }
        }
    }
    cout<<cnt;
    
}

Measured memory_bytes: 3660
x, n = map(int, input().split())
p = list(map(int, input().split()))

b = [True for _ in range(0, 102)]

for i in range(n):
    b[p[i]] = False

for i in range(101):
    if 0 <= x-i <= 101:
        if b[x-i]:
            print(x-i)
            break
    if 0 <= x+i <= 101:
        if b[x+i]:
            print(x+i)
            break


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

typedef long long ll;
ll pat[55], total[55];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int n;
    ll x;
    pat[0] = total[0] = 1;
    for(int i = 1; i <= 50; i++){
        total[i] = total[i-1] * 2 + 3;
        pat[i] = pat[i-1] * 2 + 1;
    }

    cin>>n>>x;

    ll res = 0;
    for(int i = n; i >= 0; i--){
        if(x == 0)
            break;
        if(x == total[i]){
            res += pat[i];
            break;
        }
        if(x == 1)
            break;
        if(i){
            if(x <= 1 + total[i-1]){
                x--;
            }
            else{
                res += pat[i-1] + 1;
                x -= total[i-1] + 2;
            }
        }
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

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

    int A, B;
    cin >> A >> B;
    A--, B--;

    printf("%d %d\n", 100, 100);

    for (int i = 0; i < 50; ++i) {
        for (int j = 0; j < 100; ++j) {
            bool iswhite = (A > 0) & !((i | j) & 1);
            A -= iswhite;
            putchar(iswhite ? '.' : '#');
        }
        putchar('\n');
    }

    for (int i = 0; i < 50; ++i) {
        for (int j = 0; j < 100; ++j) {
            bool isblack = (B > 0) & (i & j & 1);
            B -= isblack;
            putchar(isblack ? '#' : '.');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 256
import math

def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
    
def Koch(n, x1,y1,x2,y2):
    if n == 0: 
        plot(x1,y1)        
        return
    sx = (2 * x1 + x2) / 3
    sy = (2 * y1 + y2) / 3
    tx = (x1 + 2 * x2) / 3
    ty = (y1 + 2 * y2) / 3
    ux = (tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy = (tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    Koch(n-1, x1, y1, sx, sy)
    Koch(n-1, sx, sy, ux, uy)
    Koch(n-1, ux, uy, tx, ty)
    Koch(n-1, tx, ty, x2, y2)

n = int(input())
Koch(n, 0, 0, 100, 0)
plot(100,0)


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

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

constexpr lint INF = 1LL << 60;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n), ys(n), ps(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> xs[i] >> ys[i] >> ps[i];
    }

    auto xds = vec(n, vec(1 << n, INF));
    auto yds = xds;

    for (int i = 0; i < n; ++i) {
        for (int b = 0; b < (1 << n); ++b) {
            {
                auto& cost = xds[i][b];
                cost = std::abs(xs[i]);
                for (int j = 0; j < n; ++j) {
                    if ((b >> j) & 1) cost = std::min(cost, std::abs(xs[i] - xs[j]));
                }
            }

            {
                auto& cost = yds[i][b];
                cost = std::abs(ys[i]);
                for (int j = 0; j < n; ++j) {
                    if ((b >> j) & 1) cost = std::min(cost, std::abs(ys[i] - ys[j]));
                }
            }
        }
    }

    std::vector<lint> ans(n + 1, INF);

    for (int b = 0; b < (1 << n); ++b) {
        std::vector<int> is;
        for (int i = 0; i < n; ++i) {
            if ((b >> i) & 1) is.push_back(i);
        }

        int k = is.size();
        for (int c = 0; c < (1 << k); ++c) {
            int xb = 0, yb = 0;
            for (int j = 0; j < k; ++j) {
                int i = is[j];
                if ((c >> j) & 1) {
                    xb |= (1 << i);
                } else {
                    yb |= (1 << i);
                }
            }

            lint cost = 0;
            for (int i = 0; i < n; ++i) {
                lint dist = std::min(xds[i][xb], yds[i][yb]);
                cost += dist * ps[i];
            }

            ans[k] = std::min(ans[k], cost);
        }
    }

    for (auto a : ans) std::cout << a << "\n";
}

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

    solve();

    return 0;
}


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

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

bool check(vl d,vl A){
    vl copy = d,yay(d.size(),0);
    ll N = d.size();
    ll MAX = *max_element(ALL(d));
    FOR(i,0,N)d[i] -= MAX;
    ll counter = 0;
    FOR(i,0,N){
        if(d[i]%N)return 0;
        counter += d[i]/N;
    }
    FOR(i,0,N){
        yay[i] -= counter;
        yay[i] += d[i];
    }
    ll sum = 0;
    FOR(i,0,N)sum += A[i];
    if(sum%((N)*(N+1)/2))return 0;
    return (sum/((N)*(N+1)/2)+counter)%N == 0 && sum/((N)*(N+1)/2)+counter >= 0 && copy == yay;
}

signed main(){
    ll N;
    cin >> N;
    vl A(N);
    FOR(i,0,N)cin >> A[i];
    vl d(N);
    d[0] = A[0] - A[N-1];
    FOR(i,1,N)d[i] = A[i] - A[i-1];
    YES(check(d,A));
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
 
int a,b,c,d;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>c>>d;
	cout<<c - (d - b)<<' '<<d + c - a<<' '<<a - (d - b)<<' '<<b + c - a;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
 
 
class UnionFind:
    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.sizes = [1] * n
        self.rank = [0] * n
    def find(self, i):
        if self.parents[i] == i:
            return i
        else:
            self.parents[i] = self.find(self.parents[i])
            return self.parents[i]
    def unite(self, i, j):
        pi = self.find(i)
        pj = self.find(j)
        if self.rank[pi] < self.rank[pj]:
            self.sizes[pj] += self.sizes[pi]
            self.parents[pi] = pj 
        else: 
            self.sizes[pi] += self.sizes[pj]
            self.parents[pj] = pi 
            if self.rank[pi] == self.rank[pj]:
                self.rank[pi] += 1
def main():
    uf = UnionFind(N)
    p = N * (N - 1) // 2
    ans = [p]
    for x, y in reversed(ab):
        px = uf.find(x)
        py = uf.find(y)
        if px != py:
            p -= uf.sizes[px] * uf.sizes[py]
            uf.unite(px, py)
        ans.append(p)
 
    for a in reversed(ans[:-1]):
        print(a)
 
 
main()


Measured memory_bytes: 24820
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++) cin >> A.at(i);
	for (int i = 0; i < N; i++) cin >> B.at(i);
	for (int i = 0; i < N; i++) cin >> C.at(i);

	sort(A.begin(), A.end());
	sort(C.begin(), C.end());

	int64_t ans = 0;
	for (int i = 0; i < N; i++) {
		int64_t n, m;
		n = lower_bound(A.begin(), A.end(), B.at(i)) - A.begin();
		m = C.end() - upper_bound(C.begin(), C.end(), B.at(i));
		ans += n * m;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4556
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline void upmax(int &x,int y){x<y?x=y:0;}
int n,m,s[190][190],f[190][190][190][9],g[190][190][190][9];
char c[190][190];
inline bool check(int x,int xx,int y,int yy)
{
	int res=s[xx][yy]-s[x-1][yy]-s[xx][y-1]+s[x-1][y-1];
	return !res||res==(xx-x+1)*(yy-y+1);
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf(" %s",c[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)s[i][j]=c[i][j]=='.',s[i][j]+=s[i][j-1];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)s[i][j]+=s[i-1][j];
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j)
			for(int k=m;k;--k)
				if(check(i,j,k,k))
				{
					if(c[i][k]==c[i][k+1])f[i][j][k][0]=f[i][j][k+1][0]+1;
					else f[i][j][k][0]=1;
				}
	for(int i=1;i<=m;++i)
		for(int j=i;j<=m;++j)
			for(int k=n;k;--k)
				if(check(k,k,i,j))
				{
					if(c[k][i]==c[k+1][i])g[i][j][k][0]=g[i][j][k+1][0]+1;
					else g[i][j][k][0]=1;
				}
	int t;
	for(t=0;;++t)
	{
	//	printf("%d %d %d %d %d ",t,g[11][11][1][t],g[11][11][2][t],g[11][11][3][t]);
	//	if(t)
	//	{
	//		for(int i=1;i<=n;++i)
	//			for(int j=i;j<=n;++j)
	//				for(int k=1;k<=m;++k)
	//					printf("%d %d %d %d\n",i,j,k,f[i][j][k][t]);			
	//	}
	/*	for(int i=1;i<=m;++i)
			for(int j=i;j<=m;++j)
				for(int k=1;k<=n;++k)
					printf("%d %d %d %d\n",i,j,k,g[i][j][k][t]);*/
		if(f[1][n][1][t]==m)break;
		for(int i=1;i<=n;++i)
			for(int j=i;j<=n;++j)
				for(int k=1;k<=m;++k)
				{
					f[i][j][k][t+1]=f[i][j][k][t]+f[i][j][k+f[i][j][k][t]][t];
					if(f[i][j][k][t+1])upmax(g[k][k+f[i][j][k][t+1]-1][i][t+1],j-i+1);
				//	if(i==1&&j==1&&k==1&&t==0)printf("%d %d %d %d %d\n",k,k+f[i][j][k][t+1]-1,i,t+1,g[1][7][1][1]);
				}
		for(int i=1;i<=m;++i)
			for(int j=i;j<=m;++j)
				for(int k=1;k<=n;++k)
				{
					upmax(g[i][j][k][t+1],g[i][j][k][t]+g[i][j][k+g[i][j][k][t]][t]);
					if(g[i][j][k][t+1])upmax(f[k][k+g[i][j][k][t+1]-1][i][t+1],j-i+1);
				}
	//	printf("%d %d ",g[11][11][1][t+1],f[1][4][11][t+1]);
		for(int i=1;i<=n;++i)
			for(int j=n;j>=i;--j)
				for(int k=1;k<=m;++k)
					upmax(f[i][j][k][t+1],f[i][j+1][k][t+1]);
	//	printf("%d\n",f[1][2][11][t+1]);
		for(int i=1;i<=m;++i)
			for(int j=m;j>=i;--j)
				for(int k=1;k<=n;++k)
					upmax(g[i][j][k][t+1],g[i][j+1][k][t+1]);
	/*	for(int len=m;len>=1;--len)
			for(int i=1,j=len;j<=m;++i,++j)
				for(int k=1;k<=n;++k)
					upmax(g[i][j][k][t+1],g[i][j+1][k][t+1]),upmax(g[i][j][k][t+1],g[i-1][j][k][t+1]);
		for(int i=1;i<=n;++i)
			for(int j=i;j<=n;++j)
				for(int k=1;k<=m;++k)
					upmax(f[i][j][k][t+1],f[i][j][k-1][t+1]-1);
		for(int i=1;i<=m;++i)
			for(int j=i;j<=m;++j)
				for(int k=1;k<=n;++k)
					upmax(g[i][j][k][t+1],g[i][j][k-1][t+1]-1);*/
	}
//	printf("%d %d %d\n",f[1][1][1][1],g[1][7][1][1],g[1][7][2][1]);
	printf("%d",t);
	return 0;
}


Measured memory_bytes: 474240
n=int(input())
s=input()
d={}
for i in range(10):
    x = s.find(str(i))
    if x<n-2 and x>=0:
        d[i]=s[x+1:]
    else:
        d[i]=""
dd={}
for i in range(10):
    ss = d[i]
    for j in range(10):
        x = ss.find(str(j))
        if x<n-1 and x>=0:
            dd[(i,j)]=ss[x+1:]
        else:
            dd[(i,j)]=""
cnt=0
for i in range(10):
    for j in range(10):
        ss = dd[(i,j)]
        for k in range(10):
            x = ss.find(str(k))
            if x<n and x>=0:
                cnt+=1
print(cnt)

Measured memory_bytes: 6260
#define _USE_MATH_DEFINES_
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MAX_A_LEN=2e3,INF=1e8;
int N;
string A,B;
int s[MAX_A_LEN],t[MAX_A_LEN];
bool iszero(string s){
	REP(i,(int)s.length()){
		if (s[i]=='1'){
			return false;
		}
	}
	return true;
}
int main(){
	cin>>A>>B;
	N=(int)A.size();
	if (iszero(B)){
		cout<<(iszero(A) ? 0 : -1)<<endl;
	}else{
		REP(i,N){
			if (B[i]=='1'){
				s[i]=i;
				for(int j=i-1;j>=0 && B[j]=='0';j--){
					s[j]=i;
				}
			}
		}
		for(int i=N-1;B[i]=='0';i--){
			s[i]=s[0];
		}
		REP(i,N){
			if (B[i]=='1'){
				t[i]=i;
				for(int j=i+1;j<N && B[j]=='0';j++){
					t[j]=i;
				}
			}
		}
		for(int i=0;B[i]=='0';i++){
			t[i]=t[N-1];
		}
		int ans=INF;
		REP(u,N){
			vector<P> vec;
			REP(i,N){
				if (A[i]!=B[(i+u)%N]){
					int a,b;
					if (t[i]<=i){
						a=i-t[i];
					}else{
						a=i+N-t[i];
					}
					if (i<=s[i]){
						b=s[i]-i;
					}else{
						b=s[i]+N-i;
					}
					vec.push_back(P(a,b));
				}
			}
			int temp;
			if (vec.size()!=0){
				set<P> st;
				for(auto p:vec){
					st.insert(P(p.second,p.first));
				}
				sort(vec.begin(),vec.end());
				for(auto ite:vec){
					st.erase(P(ite.second,ite.first));
					auto e=st.end();
					temp=(int)vec.size();
					if (e!=st.begin()){
						e--;
						temp+=ite.first*2+e->first;
						int a=min(u,e->first),b=max(u,e->first);
						temp+=min(b-a,a+N-b);
					}else{
						temp+=ite.first;
						int a=min(u,(N-ite.first)%N),b=max(u,(N-ite.first)%N);
						temp+=min(b-a,a+N-b);
					}
					ans=min(ans,temp);
				}
				for(auto &i:vec){
					swap(i.first,i.second);
				}
				st.clear();
				for(auto p:vec){
					st.insert(P(p.second,p.first));
				}
				sort(vec.begin(),vec.end());
				for(auto ite:vec){
					st.erase(P(ite.second,ite.first));
					auto e=st.end();
					temp=(int)vec.size();
					if (e!=st.begin()){
						e--;
						temp+=ite.first*2+e->first;
						int a=min(u,(N-e->first)%N),b=max(u,(N-e->first)%N);
						temp+=min(b-a,a+N-b);
					}else{
						temp+=ite.first;
						int a=min(u,ite.first),b=max(u,ite.first);
						temp+=min(b-a,a+N-b);
					}
					ans=min(ans,temp);
				}
			}else{
				ans=min(ans,min(u,N-u));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
max_a = a[-1]
is_True = [1]*(max_a + 1)
for i in a:
    if is_True[i]:
        for j in range(2*i, max_a + 1, i):
            is_True[j] = False
cnt = 0
from collections import Counter
c = Counter(a)
for i in a:
    if is_True[i] and c[i] == 1:
        cnt += 1
print(cnt)

Measured memory_bytes: 135048
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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 stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }


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

  ll h, m, h2, m2, k;
  cin >> h >> m >> h2 >> m2 >> k;

  ll t1 = 60*h+m;
  ll t2 = 60*h2+m2;

  cout << t2 - t1 - k << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

int k,t;
cin>>k>>t;

priority_queue<int> q;
rep(i,t){
    int a;
    cin>>a;
    q.push(a);
}


int pre = q.top();
pre--;
q.pop();

while(q.size()>0){
   // cout<<t<<endl;
    int t = q.top();
    q.pop();
    if(pre!=0) {
        q.push(pre);
    }
    pre=t;
    pre--;

}

int nokori = q.top();



cout<<nokori-1<<endl;


    return 0;
}


Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 3005;
const int mod = 998244353;
int a[N],n,s;
int dp[N][N];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> s;
	up(i,1,n) cin >> a[i];
	dp[0][0] = 1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=s;++j){
			dp[i][j] = (dp[i-1][j] * 2) % mod;
			if (j >= a[i]) dp[i][j] = (dp[i-1][j-a[i]] + dp[i][j]) % mod;
		}
	}
	cout << dp[n][s];
}

Measured memory_bytes: 38816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader f = new FastReader();
        String line = f.nextLine();
        StringBuilder sb = new StringBuilder();

        for (char ch : line.toCharArray()) {
            if (!Character.isAlphabetic(ch)) {
                sb.append(ch);
            } else if (ch < 97) {
                sb.append(Character.toChars(ch + 32));
            } else {
                sb.append(Character.toChars(ch - 32));
            }
        }
        System.out.println(sb);

    }

    // Helper class to speed up IO
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}



Measured memory_bytes: 24312
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

double deg2rad(double deg) {
	return deg * M_PI / 180.0;
}

int main() {
	cout << fixed << std::setprecision(6);
	double a, b, Cdeg;
	cin >> a >> b >> Cdeg;
	double C = deg2rad(Cdeg);
	double S, L, h;
	S = 0.5 * a * b * sin(C);
	double c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(C));
	L = a + b + c;
	h = 2 * S / a;
	cout << S << endl << L << endl << h << endl;
	return 0;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<char>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;


int main(){
  int i,j;
  int n;
  cin>>n;
  if(n==2){
      cout<<-1<<endl;
      return 0;
  }
  VVI a(n,VI(n,'.'));
  if(n==3){
    a[0][0]='a';
    a[1][0]='a';
    a[2][1]='b';
    a[2][2]='b';
  }
  else if(n==7){
    a[0][1]='a';
    a[0][2]='a';
    a[0][3]='b';
    a[0][4]='b';
    a[0][5]='c';
    a[0][6]='c';

    a[1][0]='a';
    a[2][0]='a';
    a[3][0]='b';
    a[4][0]='b';
    a[5][0]='c';
    a[6][0]='c';
    
    int y=1;
    int z=1;
    a[0+y][0+z]='d';
    a[1+y][0+z]='d';
    a[2+y][1+z]='e';
    a[2+y][2+z]='e';

    y=1;
    z=4;
    a[0+y][0+z]='d';
    a[1+y][0+z]='d';
    a[2+y][1+z]='e';
    a[2+y][2+z]='e';

    y=4;
    z=1;

    a[0+y][0+z]='d';
    a[1+y][0+z]='d';
    a[2+y][1+z]='e';
    a[2+y][2+z]='e';

    y=4;
    z=4;

    a[0+y][0+z]='d';
    a[1+y][0+z]='d';
    a[2+y][1+z]='e';
    a[2+y][2+z]='e';
  }
  else if(n%2==0){
      int u=0;
      for(i=0;i<n/2;i++){
          a[2*i][2*i]='a'+u;
          a[2*i][2*i+1]='a'+u;
          u++;
          u%=26;
          a[2*i+1][2*i]='a'+u;
          a[2*i+1][2*i+1]='a'+u;
          u++;
          u%=26;
          a[(2*i+2)%n][2*i]='a'+u;
          a[(2*i+3)%n][2*i]='a'+u;
          u++;
          u%=26;
          a[(2*i+2)%n][2*i+1]='a'+u;
          a[(2*i+3)%n][2*i+1]='a'+u;
          u++;
          u%=26;
      }
  }
  else{
      int m=n-5;
      int u=11;
      a[0][0]='a';
      a[1][0]='a';

      a[0][1]='b';
      a[0][2]='b';

      a[0][3]='c';
      a[0][4]='c';

      a[1][2]='d';
      a[1][3]='d';

      a[1][4]='e';
      a[2][4]='e';

      a[2][0]='f';
      a[2][1]='f';

      a[4][0]='g';
      a[4][1]='g';

      a[3][2]='h';
      a[4][2]='h';

      a[2][3]='i';
      a[3][3]='i';

      a[3][4]='j';
      a[4][4]='j';
      
      for(i=0;i<m/2;i++){
          a[2*i+5][2*i+5]='a'+u;
          a[2*i+5][2*i+1+5]='a'+u;
          u++;
          u%=26;
          a[2*i+1+5][2*i+5]='a'+u;
          a[2*i+1+5][2*i+1+5]='a'+u;
          u++;
          u%=26;
          a[(2*i+2)%m+5][2*i+5]='a'+u;
          a[(2*i+3)%m+5][2*i+5]='a'+u;
          u++;
          u%=26;
          a[(2*i+2)%m+5][2*i+1+5]='a'+u;
          a[(2*i+3)%m+5][2*i+1+5]='a'+u;
          u++;
          u%=26;
      }
      
  }


  for(i=0;i<n;i++){
      for(j=0;j<n;j++){
          cout<<a[i][j];
      }
      cout<<endl;
  }
 
  return 0;
}


Measured memory_bytes: 2176
END { load __FILE__ unless $stdin.eof? }

n = gets.to_i
a = gets.split.map!(&:to_i) << 0

k = 0
m = 1000

a.each_cons(2) do |x, y|
  if x < y
    s, t = m.divmod(x)
    k += s
    m = t
  else
    m += k * x
    k = 0
  end
end

puts m


Measured memory_bytes: 14316
#include<cstdio>

int main(){
    int A, B, K;
    scanf("%d%d%d",&A,&B,&K);
    for(int i=1;i<=K;i++){
        if(i&1){
            B+=A>>1;
            A>>=1;
        } else {
            A+=B>>1;
            B>>=1;
        }
    }
    printf("%d %d\n",A,B);
    return 0;
}


Measured memory_bytes: 128
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

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

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

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    int N;cin >> N;
    vector<int> retu(N);
    string ans = "second";
    for(int i = 0;i<N;i++) {
        cin >> retu.at(i);
        if(retu.at(i)%2 == 1) ans = "first";
    }
    cout << ans << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int A[111111],B[111111];

signed main(){
    cin>>N>>M;
    rep(i,N){
        cin>>A[i]>>B[i];
    }

    vpint lis;
    rep(i,N)lis.pb({A[i],i});
    sort(all(lis));

    int ans=0;
    rep(i,N){
        int k=lis[i].se;
        int x=min(M,B[k]);
        M-=x;
        ans+=A[k]*x;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3956
r=range
h,*s=open(0)
h,w,k=map(int,h.split())
m=9e9
for i in r(1<<h-1):
  t,v,l=[],-1,1
  for j in r(h):
    if i>>j&1:
      t+=j+1,
      l+=1
  t+=h,
  c=[0]*l
  for i in r(w):
    b=f=g=0
    u=[]
    for j in r(l):
      d,b=sum(s[j][i]=='1'for j in r(b,t[j])),t[j]
      u+=d,
      if d>k:
        g=1
        break
      c[j]+=d
      f|=c[j]>k
    else:
      v+=f
      if f:c=u
    if g:break
  else:m=min(m,v+l)
print(m)

Measured memory_bytes: 50904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int p = s.charAt(0) == s.charAt(s.length()-1) ? 0 : 1;
		boolean firstLost = (s.length() + p) % 2 == 1;
		System.out.println(firstLost ? "Second" : "First");
	}

}


Measured memory_bytes: 25708
a,b = map(int,input().split())
if int(str(a)*b) > int(str(b)*a):
    print(str(a)*b)
elif int(str(a)*b) < int(str(b)*a):
    print(str(b)*a)
elif int(str(a)*b) == int(str(b)*a):
    print(str(b)*a)

Measured memory_bytes: 3060
s = list(input())
toBeList1 = []
toBeList2 = []
ans1 = 0
ans2 = 0
for i in range(len(s)):
  toBeList1.append(str(i%2))
  toBeList2.append(str((i+1)%2))
  if s[i] != toBeList1[i]:
    ans1 += 1
  if s[i] != toBeList2[i]:
    ans2 += 1

print(min(ans1,ans2))



Measured memory_bytes: 16648
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
int main()
{
	stack<ll> q;
	int n;
	ll x,y,a[maxn],k,sum;
	scanf("%d",&n);
	k=0;
	sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(q.empty())
		{
			q.push(a[i]);
		}
		else
		{
			if(a[i]<=q.top())
			{
				sum++;
				k=max(k,sum);
				q.push(a[i]);
			}
			else
			{
				sum=0;
				q.push(a[i]);
			}
		}
	}
	printf("%lld\n",k);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
int main(){
    int r;
    cin >> r;
    double pi = 3.14159265359;
    double a = 2*pi*r;
    cout << a;
    return 0;
}







Measured memory_bytes: 3808
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
	int n,s=0,c=0; 
	double a,x[64],y[64];

	while(cin >> n, n)
	{
		c++;
		for(int i=0; i<n; i++)
		{
			cin >> x[i] >> y[i];
		}

		a=0;
		for(int i=0; i<n; i++)
		{
			a += x[i]*y[(i+1)%n] - x[(i+1)%n]*y[i];
		}

		printf("%d %.1lf\n",c,abs(a)/2);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  ll ans = 0;
  for (ll i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      a[i] = -1;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.time.temporal.TemporalUnit;
import java.util.*;

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

        String day = sc.next();

        if(day.equals("MON")){
            System.out.println(6);
        }
        else if(day.equals("TUE")){
            System.out.println(5);
        }
        else if(day.equals("WED")){
            System.out.println(4);
        }
        else if(day.equals("THU")){
            System.out.println(3);
        }
        else if(day.equals("FRI")){
            System.out.println(2);
        }
        else if(day.equals("SAT")){
            System.out.println(1);
        }
        else if(day.equals("SUN")){
            System.out.println(7);
        }
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}


int main(){
  string s;
  cin>>s;
  ll n=s.size();
  reverse(s.begin(),s.end());
  ll k=1;
  const ll MX=13;
  vector<ll> dp(MX,0);
  vector<ll> nx(MX,0);
  dp[0]=1;
  for(int i=0;i<n;i++){
    for(auto &I:nx){I=0;}
    if(s[i]>='0' && s[i]<='9'){
      s[i]-='0';
      for(int j=0;j<MX;j++){
        nx[(j+k*s[i])%MX]+=dp[j];
      }
    }
    else{
      for(int j=0;j<MX;j++){
        for(int l=0;l<10;l++){
          nx[(j+k*l)%MX]+=dp[j];
          nx[(j+k*l)%MX]%=MOD;
        }
      }
    }
    (k*=10)%=MX;
    swap(nx,dp);
    //cout<<i<<endl<<dp<<endl;
  }
  dp[5]%=MOD;
  if(dp[5]<0){dp[5]+=MOD;}
  cout<<dp[5]<<endl;
  
  return 0;
}


Measured memory_bytes: 512
n, k = map(int, input().split())
a = list(map(int, input().split()))

s = 1
place = [s]
first = set(place)

for i in range(1, k+1):
    s = a[s-1]
    if s in first:
        loops = place.index(s)
        loope = len(place)
        ans = loops + (k-loope) % (loope-loops)
        print(place[ans])
        exit()
    else:
        place.append(s)
        first.add(s)

print(s)

Measured memory_bytes: 32364
require 'set'
n, k = gets.split.map(&:to_i)
a    = gets.split.map(&:to_i)
sum  = a.inject(:+)
# (a,b,c)/g == 0
candidates = Set.new
(1 .. sum).each do |i|
  break if i * i >= sum
  if sum % i == 0
    candidates.add(i)
    candidates.add(sum / i)
  end
end
ans = 1
candidates.each do |x|
  r = Array.new(n)
  n.times do |i|
    r[i] = a[i] % x
  end
  r.sort!
  tot  = r.inject(:+)
  l    = n - tot / x
  need = 0
  l.times do |i|
    need += r[i]
  end
  ans = [ans, x].max if need <= k
end
puts ans


Measured memory_bytes: 5112
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main(){
	
	vector<bool> s(13,false), h(13,false), c(13,false), d(13,false);
	
	int n;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		char type;
		int num;
		cin >> type >> num;
		
		switch(type){
		case 'S':
			s.at(num - 1) = true;
			break;
		case 'H':
			h.at(num - 1) = true;
			break;
		case 'C':
			c.at(num - 1) = true;
			break;
		case 'D':
			d.at(num - 1) = true;
			break;
		}
		
	}
	
	
	for(int i = 0; i < 13; i++){
		if(!s.at(i)) cout << "S " << i+1 << endl;
	}
	
	for(int i = 0; i < 13; i++){
		if(!h.at(i)) cout << "H " << i+1 << endl;
	}
	
	for(int i = 0; i < 13; i++){
		if(!c.at(i)) cout << "C " << i+1 << endl;
	}
	
	for(int i = 0; i < 13; i++){
		if(!d.at(i)) cout << "D " << i+1 << endl;
	}
	
}





Measured memory_bytes: 3092
#include <iostream>
#include <array>
#include <string>
	
using namespace std;

int n;
array<short,2000001> A;
array<short,2000001> B;
array<int,10001> C;

void CountingSort(int k){
	
    for(int j=0;j<n;j++){
        C[A[j]]++;
    }
    for(int i=1;i<=k;i++){
	    C[i] = C[i] + C[i-1];
	}
    for(int j=n-1;j>=0;j--){
       B[C[A[j]]-1] = A[j];
       C[A[j]]--;
    }    
    for(int i=0;i<n-1;i++) cout<<B.at(i)<<" ";
    cout<<B.at(n-1)<<endl;
}


int main(){
	int k=-1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
		if(k<A[i]) k=A[i];
	}
	CountingSort(k);
	return 0;
}

Measured memory_bytes: 9012
# https://atcoder.jp/contests/abc107/tasks/arc101_a

n, k = map(int, input().split())

nums = [int(i) for i in input().split()]

ans = float('inf')
for i in range(n - k + 1):
    l = nums[i]
    r = nums[i + k - 1]
    if l >= 0:
        t = r
    elif r <= 0:
        t = abs(l)
    else:
        t = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r))
    ans = min(ans, t)

print(ans)

Measured memory_bytes: 62576
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<algorithm>
#include<functional>
#include<bitset>
#include<vector>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>

using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int  MOD = 998244353, OO = 2e9 + 100;
const int N = 1e5 + 500;
ll n;
ll ans = 0;
bool can(ll rem, ll mod) {
	if (rem == 0)
		return false;
	if ((rem + mod) % rem == 0)
		return false;
	ll left = 1, right = 1e12;
	while (left <= right) {
		ll mid = (left + right) / 2;
		if (mid*mod == rem) {
			ans += mid;
			return mid == rem;
		}
		if (mid*mod > rem)
			right = mid - 1;
		else {
			left = mid + 1;
		}
	}
	return false;
}
int main() {
	cin >> n;
	for (ll i = 1; i*i <= n; ++i) {
		if (i*i == n) {
			if (i >  1) {
				ll x = n / (i - 1);
				ll v = n % (i - 1);
				if (x == v)ans += (i - 1);
			}
		}
		else if (n%i == 0) {
			
			if (i >  1) {
				ll x = n / (i - 1);
				ll v = n % (i - 1);
				if (x == v)ans += (i - 1);
			}
			if (n/i > 1) {
				ll x = n / ((n / i) - 1);
				ll v = n % ((n / i) - 1);
				if (x == v)ans += ((n / i) - 1);
			}
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;
using namespace std;

vector<ll> dp;

int main(void) {
   ll N,K;
   cin>>N>>K;
   ll h[N];
   rep(i,N) cin>>h[i];
   dp.resize(N,(ll)1e16);
   dp[0] = 0;
   for (int i = 1; i < N;i++) {
      rep(j,K) {
         if (i-(j+1)<0) continue;
         dp[i] = min(dp[i-(j+1)]+abs(h[i-(j+1)]-h[i]),dp[i]);
      }
   }
   // rep(i,N) cout<<dp[i]<<endl;
   cout<<dp[N-1]<<endl;





   return 0;
}

Measured memory_bytes: 1792
def thirdRoot(xn, q):
    ans = xn - (x**3 - q)/(3 * (xn**2))
    return ans


while True:
    q = int(input())
    if q == -1:
        break

    x = q/2
    while abs(x**3 - q) >=0.00001*q:
        x = thirdRoot(x, q)

    print(x)


Measured memory_bytes: 5664
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func GCD(a, b int) int {
  if a < b { a, b = b, a }
  if b == 0 { return a }
  return GCD(b, a % b)
}

func Solve() {
  var K int
  NextInt(&K)
  S := 0
  var gcd int
  for i := 1; i <= K; i++ {
    for j := 1; j <= K; j++ {
      gcd = GCD(i, j)
      for k := 1; k <= K; k++ {
        S += GCD(gcd, k)
      }
    }
  }
  Write(S)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 1836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=1e5+10;
int n;
long long k,pre=0;
pair<int,int> p[maxn];
int main()
{
 	cin>>n>>k;
 	for(int i=0,a,b;i<n;i++)
 	{
 		cin>>a>>b;
 		p[i].first=a;
 		p[i].second=b;
	 }
	 sort(p+0,p+n);
	 int ans;
	 for(int i=0;i<n;i++)
	 {
	 	if(pre<k&&k<=p[i].second+pre)
	 	{
	 		ans=p[i].first;
	 		break;
		 }
		 pre+=p[i].second; 
	 }
	 cout<<ans;
}


Measured memory_bytes: 1024
initial = %w[M A R C H]
m = { 'M' => 0, 'A' => 0, 'R' => 0, 'C' => 0, 'H' => 0 }
count = 0

while line = gets
  m[line.chr] += 1 if initial.include?(line.chr)
end

0.upto(2) do |i|
  (i + 1).upto(3) do |j|
    (j + 1).upto(4) do |k|
      count += m[initial[i]] * m[initial[j]] * m[initial[k]]
    end
  end
end

puts count


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll a[405];
ll dp[405][405];
ll rui[405];
ll sum(int l,int r){
	if(l==0)return rui[r];
	else return rui[r]-rui[l-1];
}
ll rec(int l,int r){
	if(l==r)return 0;
	if(dp[l][r]!=-1ll)return dp[l][r];
	ll ret = LLINF;
	for(int i=l;i<r;i++){
		ret = min(ret,rec(l,i)+rec(i+1,r)+sum(l,r));
	}
	return dp[l][r]=ret;
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> a[i];
	rui[0]=a[0];
	for(int i=1;i<N;i++)rui[i]=rui[i-1]+a[i];
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++)dp[i][j]=-1ll;
	}
	cout << rec(0,N-1) << endl;
	return 0;
}

Measured memory_bytes: 1536