akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using R = double;
using P = complex<R>;
#define x real()
#define y imag()
const R eps = 1e-9,PI = acos(-1);

bool equal(R a,R b){return abs(b-a)<eps;}
bool equal0(R a){return equal(a,0.0);}

P operator*(const P& p,const R& d){
    return P(p.x*d,p.y*d);
}

istream &operator>>(istream& is,P& p){
    R a,b;
    is >> a >> b;
    p = P(a,b);
    return is;
}

ostream &operator<<(ostream& os,P& p){
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}
//内積
double dot(P a,P b) {return (conj(a)*b).real();}
//外積
double cross(P a,P b) {return (conj(a)*b).imag();}

struct L{
    P a,b;
    L(P a,P b):a(a),b(b){}
    L(R A,R B,R C){
        if(equal(A,0)) a = P(0,C/B),b = P(1,C/B);
        else if(equal(B,0)) b = P(C/A,0),b = P(C/A,1);
        else a = P(0,C/B),b = P(C/A,0);
    }
};

//pをbに射影
P projection(P p,P b) {return b*dot(p,b)/norm(b);}

//pとp1 to p2 に射影
P projection(L l,P p){
    p -= l.a; l.b -= l.a;
    P proj = projection(p,l.b);
    return l.a+proj;
}

struct S:L{
    S(P a,P b):L(a,b){}
};

//点の回転方向を判定
int ccw(P& p0,P p1,P p2){
    p1 -= p0,p2 -= p0;
    if(cross(p1,p2)>eps) return 1; //"COUNTER_CLOCKWISE"
    if(cross(p1,p2)<-eps) return -1; //"CLOCKWISE"
    if(dot(p1,p2)<0) return 2; //"ONLINE_BACK"
    if(norm(p1)<norm(p2)) return -2; //"ONLINE_FRONT"
    return 0; //"ON_SEGMENT"
}

bool is_parallel(L& l1,L& l2){
    return equal0(cross(l1.b-l1.a,l2.b-l2.a));
}

bool is_orthogonal(L& l1,L& l2){
    return equal0(dot(l1.a-l1.a,l2.b-l2.a));
}

//pをlに関して対称移動
P reflection(L l,P p){
    P pj = projection(l,p);
    return 2.0*pj-p;
}

//pがl上にあるか
bool is_online(L& l,P& p){
    return abs(ccw(l.a,l.b,p))!=1;
}

bool is_onsegment(S& s,P& p){
    return ccw(s.a,s.b,p)==0;
}

int main(){
    P p1,p2;
    cin >> p1;
    cin >> p2;
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        P p;
        cin >> p;
        P res = reflection(L(p1,p2),p);
        cout << res << endl;
    }
}


Measured memory_bytes: 3356
#include <iostream>
#include <string>
#include <vector>
#include <list>
//#include <cmath>
#include <random>
#include <algorithm>

using std::cout;
using std::cerr;
using std::cin;
using std::endl;

using std::vector;
using std::list;
using std::string;

void func()
{
	int N;
	cin >> N;

	long long x = 0;
	for (int i = 1; i < N; ++i) {
		x += (long long)i;
	}
	cout << x << endl;
}
int main() {
	func();

}




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

using namespace std;
typedef long long ll;

int main(){
    int n,m;
    cin>>n>>m;
    int k[m],p[m],s[m][n];
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]) cin>>s[i][j];
    }
    rep(i,m) cin>>p[i];
    int ans = 0;
    for(int bit=0;bit<(1<<n);++bit){
        int flag = 1;
        rep(i,m){
            int count = 0;
            rep(j,k[i]){
                if(bit & (1<<(s[i][j]-1))) count++;
            }
            if(count%2!=p[i]){
                flag = 0;
                break;
            }
        }
        if(flag) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string s,t;
 cin>>s>>t;
 string ans="";
 int sl=s.length();
 int tl=t.length();
 int dp[sl+1][tl+1];
 memset(dp,0,sizeof(dp));
 int i,j;
 for(i=1;i<=sl;i++)
 {
 	for(j=1;j<=tl;j++)
 	{
 	 if(s[i-1]==t[j-1])
 	 {
 	    dp[i][j]=dp[i-1][j-1]+1;
	  }
	  else
	  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);	
	  //cout<<dp[i][j]<<" ";
	}
	//cout<<endl;
 }
 i=sl;
 j=tl;
 while(i>0 && j>0)
 {
 	if(s[i-1]==t[j-1])
 	{
 		ans=s[i-1]+ans;
 		i--;
 		j--;
	}
	else
	{
		if(dp[i][j]==dp[i-1][j])
		i--;
		else
		j--;
	}
 }
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 35456
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed main(){
	int N, i, sum = 0;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
		sum += A[i];
	}
	if(sum % ((N * (N + 1)) / 2) != 0){
		printf("NO\n");
		return 0;
	}
	int K = sum / ((N * (N + 1)) / 2);
	int now = 0;
	for(i = 0; i < N; i++){
		int d = A[(i + 1) % N] - A[i];
		if(K < d || (K - d) % N != 0){
//			printf("i = %lld\n", i);
			printf("NO\n");
			return 0;
		}
		now += (K - d) / N;
	}
	if(now == K){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 896
# frozen_string_literal: true

# Generated by AtcoderGreedy on 2018-04-28
# AGC023 A
# Your code here
$N = gets.chomp.to_i

$A = gets.chomp.split(' ').map(&:to_i)

count = 0
sum_list = {}
tmp = 0
$N.times do |i|
  tmp += $A[i]
  count += 1 if tmp == 0
  sum_list[tmp] ||= 0
  sum_list[tmp] += 1
end

sum_list.each do |_, v|
  count += v * (v - 1) / 2
end
puts count


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

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

  vector<set<int>> G(N + 1);
  int a, b;
  rep(i, M) {
    cin >> a >> b;
    G.at(a).insert(b);
    G.at(b).insert(a);
  }
  vector<int> H(N + 1, 0);
  int ans = 1;

  rep(i, N + 1) {
    if (i == 0 || H.at(i) != 0) continue;
    queue<int> que;
    que.push(i);

    int cnt = 0;
    while (!que.empty()) {
      auto q = que.front();
      que.pop();
      if (H.at(q) != 0) continue;
      H.at(q) = 1;
      cnt++;
      for (auto g : G.at(q)) {
        if (H.at(g) == 0) que.push(g);
      }
    }
    ans = max(ans, cnt);
  }

  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  
  int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    int x = s.at(i) - 48;
    sum += x;
  }
  
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  
}


Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#define N 1234
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
int h[N][N];
int n, m;
void Constr(int U, int D, int L, int R) {
	if (U == D && L == R)	return h[U][L] = 1, void();
	int m1 = (U + D)>>1, m2 = (L + R) >> 1;
	Constr(U, m1 - 1, L, m2 - 1);
	Constr(U, m1 - 1, m2 + 1, R);
	Constr(m1 + 1, D, L, m2 - 1);
	Constr(m1 + 1, D, m2 + 1, R);
	h[m1][m2] = 1;
}
int main() {
	read(n), read(m);
	n = (1 << n) - 1, m = (1 << m) - 1;
	int mx = max(n, m);
	Constr(1, mx, 1, mx);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			printf("%d", h[i][j]);
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 8160
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, r, t;
    cin >> n >> r >> t;
    vector<int> p(n);
    for(int i=0; i<n; ++i)
        cin >> p[i];

    vector<int> x = p;
    vector<int> v(r, 0);
    while(--t > 0){
        vector<int> v2(r, 0);
        for(int i=0; i<n; ++i){
            x[i] += p[i];
            x[i] %= r;
            ++ v2[x[i]];
            -- v[x[i]];
        }
        for(int i=0; i<r; ++i)
            v2[i] += max(0, v[i]);
        v.swap(v2);
    }

    int ans = accumulate(v.begin(), v.end(), n);
    cout << ans << endl;

    return 0;
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL N;

LL dfs(LL sum, LL n, LL a0) {
    if (sum == N) return 1;
    if (sum > N) return 0;
    if (n == 4) return 0;

    LL res = 0;
    for (LL i = a0; i * i + sum <= N; i++) {
        res += dfs(i * i + sum, n + 1, i);
    }

    return res;
}

LL solve() {
    return dfs(0, 0, 1);
}

int main(void) {
    while (cin >> N, N) {
        cout << solve() << endl;
    }

	return 0;
}

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


int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  string t;
  rep(i,q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      swap(s,t);
    } 
    else {
      int f; char c;
      cin >> f >> c;
      if (f == 1) {
        t += c;
      } 
      else {
        s += c;
      }
    }
  }
  reverse(t.begin(), t.end());
  t += s;
  cout << t << endl;
  return 0;
}


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

using namespace std;

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

    multiset< int> st;
    vector< int> v(n);
    for (int &e : v) {
        scanf("%d", &e);
        st.insert(e);
    }

    for (const int &e : v) {
        st.erase(st.find(e));
        printf("%d\n", *(--st.end()));
        st.insert(e);
    }

}

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



int main(){

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
                    ans++;
            }
        }
    }
    cout<<ans;



return 0;
}


Measured memory_bytes: 3648
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = II()
sp = [LS() for i in range(n)]
for i, s in enumerate(sp):
    s.append(i+1)
sp = sorted(sp, key=lambda x: (x[0], -int(x[1])))
for i in sp:
    print(i[2])


Measured memory_bytes: 67308
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <cassert>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll x1 = a1-b1, x2 = a2-b2;
    if(t1*x1+t2*x2 == 0){
        puts("infinity");
        return 0;
    }
    if(x1 < 0){
        x1 *= -1; x2 *= -1;
    }
    if(t1*x1+t2*x2 > 0){
        puts("0");
        return 0;
    }
    ll heru = -(t1*x1+t2*x2);
    ll ans = (t1*x1)/heru+(-t2*x2)/heru;
    if(t1*x1%heru == 0) ans--;
    cout << ans << "\n";
    return 0;
}

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

const ll MOD = 1e+9 + 7;


ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll modinv(ll x, ll n){
    return modpow(x, n - 2);
}

int main(){
    ll n;
    cin >> n;
    vector<ll> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];
    ll ans = 0;
    ll r = 0;
    for(int i = 1; i < n; i++){
        r = (r + modinv(i, MOD)) % MOD;
        ans = (ans + r * (x[i] - x[i - 1]) % MOD) % MOD;
    }
    for(int i = 1; i < n; i++) ans = (ans * i) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007

int main(){
    int n,m;
    cin>>n>>m;
    if(n==1){//1桁
        if(!m){
            cout<<"0\n";
        }else if(m==1){
            int s,c;
            cin>>s>>c;
            cout<<c<<"\n";
        }else{
            int s,c;
            cin>>s>>c;
            bool f=true;
            rep(i,1,m){
                int s1,c1;
                cin>>s1>>c1;
                if(c1!=c)f=false;
            }
            if(f)cout<<c<<"\n";
            else cout<<"-1\n";
        }
    }else{//2,3桁
        char num[n];
        bool f=true;
        rep(i,0,n)num[i]=-1;
        rep(i,0,m){
            int s,c;
            cin>>s>>c;s--;
            if(s==0&&c==0){
                f=false;
                break;
            }else{
                if(num[s]==-1)num[s]=c;
                else if(num[s]!=c){
                    f=false;
                    break;
                }
            }
        }
        if(f){
            if(num[0]==-1)printf("1");
            else{
                printf("%d",num[0]);
            }
            rep(i,1,n){
                if(num[i]==-1)printf("0");
                else printf("%d",num[i]);
            }
            puts("");
        }else{
            printf("-1\n");
        }
    }
}


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

using namespace std;


inline int read() {
	int out = 0;
	bool flag = false;
	register char cc = getchar();
	while (cc < '0' || cc > '9') {
		if (cc == '-') flag = true;
		cc = getchar();
	}
	while (cc >= '0' && cc <= '9') {
		out = (out << 3) + (out << 1) + (cc ^ 48);
		cc = getchar();
	}
	return flag ? -out : out;
} 

int x, y, z, A, B, C, a[100010], b[100010], c[100010];

long long sum;

int main() {
	cin >> x >> y >> A >> B >> C;
	for (int i = 1; i <= A; i++) a[i] = read();
	for (int i = 1; i <= B; i++) b[i] = read();
	for (int i = 1; i <= C; i++) c[i] = read();
	sort(a + 1, a + A + 1); a[A + 1] = INT_MAX;
	sort(b + 1, b + B + 1); b[B + 1] = INT_MAX;
	sort(c + 1, c + C + 1);
	x = A - x + 1, y = B - y + 1, z = C + 1;
	for (int i = x; i <= A; i++) sum += a[i];
	for (int i = y; i <= B; i++) sum += b[i];
	while (c[z - 1] > min(a[x], b[y]) && z > 1) {
		z--;
		if (a[x] < b[y]) sum += c[z] - a[x], x++;
		else sum += c[z] - b[y], y++;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
import java.io.*;
import java.math.BigInteger; 

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................

static long rec(long[][] dp, int i, int j,long[] pre){
	if(i>=j){return 0;}
	if(dp[i][j]!=0){return dp[i][j];}
	long res=pre[j]-pre[i-1],tmp=Long.MAX_VALUE;
	for(int k=i;k<j;k++){
		tmp=Math.min(tmp,rec(dp,i,k,pre)+rec(dp,k+1,j,pre));
	}
	 dp[i][j]=(res+tmp);
	 return dp[i][j];
}
   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  int n=int_v(read());
	        		  int[] a=int_arr();
	        		  long[] pre=new long[n+1];
	        		  for(int i=1;i<=n;i++){pre[i]=a[i-1]+pre[i-1];}
	        		  long[][] dp=new long[n+1][n+1];
	        		  out.write(rec(dp,1,n,pre)+"");
                      out.flush();
	        		 
	}
}
	       
	          



	
  





Measured memory_bytes: 24148
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <limits>
#include <random>
#include <utility>
#include <vector>

namespace procon {
class UnionFind {
private:
  struct nodeinfo {
    int par;
    int rank;
    nodeinfo(int par) : par(par), rank(0) {}
  };
  std::vector<nodeinfo> node;

public:
  UnionFind(int n) : node() {
    node.reserve(n);
    for (int i = 0; i < n; ++i) {
      node.push_back(nodeinfo(i));
    }
  }
  int root(int x) {
    if (node[x].par == x) {
      return x;
    }
    return node[x].par = root(node[x].par);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (node[x].rank < node[y].rank) {
      node[x].par = y;
    } else {
      node[y].par = x;
      if (node[x].rank == node[y].rank) {
        ++node[x].rank;
      }
    }
  }
  bool is_same_set(int x, int y) { return root(x) == root(y); }
};
}
  
int main(void) {
  int size, n_query;
  std::cin.read((char *)&size, sizeof(int));
  std::cin.read((char *)&n_query, sizeof(int));

  std::vector<uint64_t> query(n_query);
  std::cin.read((char *)query.data(), sizeof(uint64_t) * n_query);

  const int mask = (1 << 30) - 1;

  uint64_t res = 123456789;
  procon::UnionFind uf(size);
  for (uint64_t q : query) {
    const int com = q >> 60;
    const int x = (q >> 30) & mask;
    const int y = (q >> 0) & mask;
    assert(0 <= x && x < size);
    assert(0 <= y && y < size);
    if (com) {
      res = res * 17 + (uf.is_same_set(x, y) ? 1 : 0);
    } else {
      uf.unite(x, y);
    }
  }
  std::cout << res << std::endl;
  return 0;
}



Measured memory_bytes: 88824
def f_takahashi_basics_in_education_and_learning(L, A, B, M, DIGIT_MAX=18):
    import numpy

    # https://github.com/numpy/numpy/blob/master/numpy/linalg/linalg.py L560から
    def matrix_power(a, n):
        a = numpy.core.asanyarray(a)
        fmatmul = numpy.core.dot

        z = result = None
        while n > 0:
            z = a % M if z is None else fmatmul(z, z) % M
            n, bit = divmod(n, 2)
            if bit:
                result = z if result is None else fmatmul(result, z) % M
        return result

    # 数列に対して、d桁の要素の個数を求める
    num_pow_d = [0] * (DIGIT_MAX + 1)
    for d in range(DIGIT_MAX + 1):
        if 10**d - 1 >= A:
            # dに対してA + B*n <= 10**d - 1 となる最大のn(L以下しか取りえない)
            num_pow_d[d] = min(((10**d - 1 - A) // B) + 1, L)  # +1はnが0スタートのため

    ans = numpy.array([0, A, 1])
    for d in range(1, DIGIT_MAX + 1):
        c_d = num_pow_d[d] - num_pow_d[d - 1]
        matrix = numpy.array([[(10**d) % M, 0, 0], [1, 1, 0], [0, B, 1]], dtype='object')
        m = numpy.eye(3, dtype='object') if c_d == 0 else matrix_power(matrix, c_d)
        ans = ans.dot(m) % M
    return ans[0]

L, A, B, M = [int(i) for i in input().split()]
print(f_takahashi_basics_in_education_and_learning(L, A, B, M))

Measured memory_bytes: 12480
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    int k; string S;
    cin >> k >> S;
    int n = S.size();

    if (n <= k) cout << S;
    else {
        string ss = S.substr(0,k);
        ss += "...";
        cout << ss;
    }

    
    return 0;
}

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

using namespace std;

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

    vector<long long> arr(3 * n);

    for(int i = 0; i < 3 * n; i++){
        cin >> arr[i];
    }

    sort(arr.begin(), arr.end());

    long long ans = 0;

    for(int i = 3 * n - 2; i >= n; i -= 2){
        ans += arr[i];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
	int a,b[55],i,c=0;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b[i]);
		if(b[i]!=i+1) c++;
	}
	printf(c>2?"NO":"YES");
	return 0;
}

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

count = 0
for i in range(n - 2):
    # print(i)
    if p[i] < p[i + 1] < p[i + 2]:
        count += 1
    if p[i] > p[i + 1] > p[i + 2]:
        count += 1
print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

int main(){

  long long N, sum=0, tmp;
  cin >> N;

  for(int i=0; i<N+1; i++){
    tmp = 1;
    if (i%3 == 0) tmp = 0;
    if (i%5 == 0) tmp = 0;
    sum += i * tmp;
  }
  cout << sum;
}


Measured memory_bytes: 3636
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  int n;
  cin >> n;
  vector<LL> v(n);
  REP(i,n){
    cin >> v[i];
  }

  SORT(v);

  LL sum = 0;

  LL a = v[0];
  LL b = v[0];

  int front = 1;
  int back = n-1;

  while(front<=back){
    LL num = max({abs(a - v[front]), abs(a - v[back]), abs(b - v[front]), abs(b - v[back])});
    if(abs(a - v[front])==num){
      sum += abs(a - v[front]);
      a = v[front];
      front++;
      continue;
    }
    if(abs(a - v[back])==num){
      sum += abs(a - v[back]);
      a = v[back];
      back--;
      continue;
    }
    if(abs(b - v[front])==num){
      sum += abs(b - v[front]);
      b = v[front];
      front++;
      continue;
    }
    if(abs(b - v[back])==num){
      sum += abs(b - v[back]);
      b = v[back];
      back--;
      continue;
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long gcd(long long a,long long b){if(b==0)return a;return gcd(b,a%b);}
long long lcm(long long a,long long b){return a*b/gcd(a,b);}
int mod_pow(long long a,long long n,long long p){if(n == 1){return a%p;}if(n%2==1){return(a*mod_pow(a,n-1,p))%p;}long long t=mod_pow(a,n/2,p);return (t*t)%p;}
long long mod(long long v,long long p){long long res=v%p;if(res<0){res+=p;}return res;}

template < typename T > void coutVector(vector<T> v){for(int i=0;i<int(v.size());++i){if(i>0)cout<<" "<<v[i];else cout<<v[i];}cout<<endl;}
template < typename T > void coutVectorWithEndl(vector<T> v){for(int i=0;i<int(v.size());++i){cout<<v[i]<<endl;}}
template < typename T > vector<T> cinVector(int n) {vector<T> res(n);for(int i=0;i<n;++i){cin>>res[i];}return res;}
const int MAX = 510000;
const ll MOD = 1e9+7;

/*
                       4 / N = 1 / i + 1 / j + 1 / k
               4 * i * j * k = j * k * N + k * i * N + i * j * N
k(4 * i * j - j * N - i * N) = i * j * N
                           k = i * j * N / (4 * i * j - j * N - i * N)
*/

int main() {
    int N; cin >> N;
    int maxAns = 3500;
    for (long long i = 1; i <= maxAns; ++i) {
        for (long long j = 1; j <= maxAns; ++j) {
            long long p = i * j * N;
            long long q = (4 * i * j - j * N - i * N);
            if (q <= 0 || p % q != 0) continue;
            long long k = p / q;
            cout << i << " " << j << " " << k;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a ;cin>>a;
    vector<int>v;
    for(int i=0;i<a;i++){
        int  t;cin>>t;
        v.push_back(t);
    }
  //  sort(v.begin(),v.end());
    int sum1 = 0 , sum2 = 0;
    int i=0,j=a-1;
    while(i<=j){
        if(sum1 <= sum2){
            sum1+=v[i];
            i++;
        }
        else{
            sum2+=v[j];
            j--;
        }
    }
   cout<<abs(sum1-sum2)<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll L, A, B, M;

//x^nをmodのもとで計算する
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow((x*x) % mod, n/2, mod);
  if (n & 1) res = (res*x) % mod;
  return res;
}

ll my_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = pow(x*x, n/2);
  if (n & 1) res *= x;
  return res;
}

ll binary_search(ll d) {
  ll pd = my_pow(10ll, d)-1;
  if (pd < A) return -1;
  ll lb = 0, ub = L, mid;
  while ((ub-lb)>1) {
    mid = (ub+lb)/2;

    if (A+mid*B <= pd) {
      lb = mid;
    } else {
      ub = mid;
    }
  }

  return lb;
}

typedef vector<ll> vec;
typedef vector<vec> mat;

// A*Bの計算(mod M)
mat mul(mat &A, mat &B, ll M) {
  mat C(A.size(), vec(B[0].size(), 0));
  for (int i = 0; i < A.size(); ++i) {
    for (int k = 0; k < B.size(); ++k) {
      for (int j = 0; j < B[0].size(); ++j) {
        C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % M;
      }
    }
  }
  return C;
}

// A^nの計算(mod M)
mat mat_pow(mat A, ll n, ll M) {
  mat B(A.size(), vec(A.size(), 0));
  for (int i = 0; i < A.size(); ++i) B[i][i] = 1;
  while (n > 0) {
    if (n & 1) B = mul(B, A, M);
    A = mul(A, A, M);
    n >>= 1;
  }
  return B;
}

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

  cin >> L >> A >> B >> M;

  vector<Pll> v;
  ll pre = -1;
  for (int i = 1; i <= 18; ++i) {
    ll num = binary_search(i);
    if (num < 0) continue;
    v.push_back(Pll(i, num - pre));
    pre = num;
  }

  mat ans(3, vec(3, 0));
  for (int i = 0; i < 3; ++i) ans[i][i] = 1;
  for (int i = 0; i < len(v); ++i) {
    mat mt(3, vec(3, 0));
    mt[0][0] = mod_pow(10ll, v[i].fi, M);
    mt[1][0] = mt[1][1] = 1;
    mt[2][1] = B % M;
    mt[2][2] = 1;

    mat tmp = mat_pow(mt, v[i].sc, M);
    ans = mul(ans, tmp, M);
  }

  mat ini(1, vec(3, 0));
  ini[0][1] = A % M;
  ini[0][2] = 1;

  ans = mul(ini, ans, M);

  cout << mod(ans[0][0], M) << endl;

  return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int A, B;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B;

  int ans = A + B;
  if (ans >= 10) {
    cout << "error" << endl;
  }
  else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        if(s=="SSR" || s=="SRS" || s== "RSS"|| s=="RSR")
            cout<<1<<endl;
        else if( s=="RRS" || s=="SRR")
            cout<<2<<endl;
        else if(s=="RRR")
            cout<<3<<endl;
        else
            cout<<0<<endl;
    }

}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long
#define inf (llint)1e18

using namespace std;
typedef pair<llint, llint> P;

int n;
llint a[100005];
P dp[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i] *= -1;
	
	for(llint i = 1; i <= n; i++) dp[i] = make_pair(inf, inf);
	dp[0] = make_pair(-inf, -inf);
	for(llint i = 1; i <= n; i++){
		*lower_bound(dp, dp+n+1, make_pair(a[i], i)) = make_pair(a[i], i);
	}
	cout << lower_bound(dp, dp+n+1, make_pair(inf, 0LL)) - dp - 1 << endl;
	//for(int i = 0; i <= n; i++) cout << dp[i] << " "; cout << endl;
	
	return 0;
}

Measured memory_bytes: 2560
a = gets.split
a[0]=a[0].to_i
a[2]=a[2].to_i
until  a[1] == "?" 
if a[1] == "+" then
 puts "#{a[0]+a[2]}"
end
if a[1] == "-" then
 puts "#{a[0]-a[2]}"
end
if a[1] == "*" then
 puts "#{a[0]*a[2]}"
end
if a[1] == "/" then
 puts "#{a[0]/a[2]}"
end
a = gets.split
a[0]=a[0].to_i
a[2]=a[2].to_i
end

Measured memory_bytes: 6108
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  if(n<10){
    printf("%d",n);
  }else if(n<100){
    printf("%d",9);
  }else if(n<1000){
    printf("%d",n-90);
  }else if(n<10000){
    printf("%d",909);
  }else if(n<100000){
    printf("%d",n-9090);
  }else{
    printf("%d",90909);
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main() {
	int n, k, s, cnt = 0;
	scanf("%d%d%d", &n, &k, &s);
	for (int i = 0; i < k; i++) {
		printf("%d ", s);
	}
	for (int i = k; i < n; i++) {
		if (s == 1) {
			printf("%d ", 2);
		} else {
			if (cnt == s - 1) {
				printf("%d ", (int)1e9);
				cnt = 0;
			} else {
				printf("%d ", 1);
			}
			cnt++;
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main()
{

    long int a,b;

    scanf("%ld %ld",&a,&b);
    long int t;

    if(a>b)
    {
        t = a;a=b;b=t;
    }

    if((a+b)%2 == 1)
    {
        printf("IMPOSSIBLE\n");
    }
    else 
    {
        t = b-a;
        t = t/2;
        printf("%ld",b-t);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
const int N=3e5+10;
int dp[N];
int mx[N<<2];
void update(int l,int r,int x,int val,int rt){
    if(l==r){mx[rt]=val;return ;}
    int mid=l+r>>1;
    if(x<=mid)update(l,mid,x,val,rt<<1);
    else update(mid+1,r,x,val,rt<<1|1);
    mx[rt]=max(mx[rt<<1],mx[rt<<1|1]);
}
int query(int l,int r,int L,int R,int rt){
    if(L<=l&&r<=R)return mx[rt];
    int mid=l+r>>1;int ans=0;
    if(L<=mid)ans=max(ans,query(l,mid,L,R,rt<<1));
    if(mid<R)ans=max(ans,query(mid+1,r,L,R,rt<<1|1));
    return ans;
}
int main(){
    int n,k;scanf("%d %d",&n,&k);int ans=0;
    int m=300001;
    for(int i=1;i<=n;i++){
        int a;scanf("%d",&a);a++;
        int l=max(1,a-k),r=min(m,a+k);
        int res=query(1,m,l,r,1);
        ans=max(ans,res+1);
        update(1,m,a,res+1,1);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 7936
n,k=map(int,input().split())
a=list(map(int,input().split()))
pl=1
visit=[-1]*n
visit[0]=0
loop=0
cnt=0

while 1:
    cnt+=1
    pl=a[pl-1]
    if visit[pl-1]!=-1:
        loop=visit[pl-1]
        break
    visit[pl-1]=cnt
    if cnt==k:
        print(pl)
        exit()

loop_len=cnt-loop
q=True
k=(k-loop)%loop_len+loop
print(visit.index(k)+1)

Measured memory_bytes: 32380
#include <iostream>

using namespace std;

int main(){
	string s;
	while(getline(cin,s),s[0] != '#'){
		for(int i = 0; i < s.size(); i++){
			switch(s[i]){
				case '1':
				case '4':
				case '7':
					s[i] = 1;
					break;
				case '2':
				case '8':
					s[i] = 2;
					break;
				default:
					s[i] = 3;
			}
		}
		int m[2] = {};
		bool fr[2] = {0,1};
		for(int i = 1; i < s.size(); i++){
			for(int j = 0; j < 2; j++){
				if(s[i-1] < s[i]){
					if(fr[j]) ++m[j];
					fr[j] = 1;
				}else if(s[i-1] > s[i]){
					if(!fr[j]) ++m[j];
					fr[j] = 0;
				} else fr[j] = !fr[j];
			}
		}
		cout << min(m[0],m[1]) << endl;
	}
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007

typedef vector<ll> Array;
typedef vector<Array> matrix;

int main(){
  Array v(200000);
  ll n; cin >> n;
  ll sum = 0;
  rep(i,n){
    cin >> v[i];
    sum += v[i];
  }
  
  ll ans = LLINF;
  
  ll now = 0;
  
  for(int i = 0; i < n - 1; i++){
    now += v[i];
    ans = min(ans,llabs(now - (sum-now)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

	int a;
	cin >> a;

	for (int i=1;i<=9;i++)
	{
		for (int j=1;j<=9;j++)
		{
			if (i*j==a)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
	return 0;
}

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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v = {a, b, c};
    sort(v.begin(), v.end());
    cout << v.at(2) * 10 + v.at(1) + v.at(0) << endl;
}

Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
3
acornistnt
peanutbomb
constraint
'''

def solve(l):
	n = len(l)
	L = []
	for s in l:
		a = [0]*26
		for i in s:
			a[ord(i)-97] += 1
		L.append(a)
	d = defaultdict(int)
	for i in L:
		d[str(i)] += 1
	# print(d)
	ans = 0
	for i in d:
		ans += d[i]*(d[i]-1)//2
	return ans
	

N = int(stdin.readline())
l = []
for nn in range(N):
	l.append(input())
ans = solve(l)
print(ans)


Measured memory_bytes: 125572
while io = gets
  break if io.strip == ""
  t = /([0-9X]+)\+([0-9X]+)=([0-9X]+)/.match(io)
  first, second, right = t[1], t[2], t[3]

  start = (first != "X" && first[0] == "X") || (second != "X" && second[0] == "X") || (right != "X" && right[0] == "X") ? 1 : 0

  answer = nil

  start.upto(9) do |i|
    x  = first.gsub(/X/,i.to_s).to_i
    y = second.gsub(/X/,i.to_s).to_i
    z  = right.gsub(/X/,i.to_s).to_i
    x, y, z = [first, second, right].map {|s| s.gsub(/X/, i.to_s).to_i}
    if x + y == z
      answer =  i.to_s
      break
    end
  end

  puts answer ? answer : "NA"
end

Measured memory_bytes: 9276
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double tax_8 = sc.nextDouble();
		double tax_10 = sc.nextDouble();
		for(int i = 0; i <= 1250; i++) {
			if((int)(i * 0.08) == tax_8 && (int)(i * 0.1) == tax_10) {
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println("-1");
	}
}

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define max(a,b) (a)>=(b)? (a) : (b) 
#define fileio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const double pi = 3.14159265358979323846;



#define F first
#define S second
const int MX = 1e5 + 10, MD = 1e9 + 7;
long long n, m, a[MX], ans, tmp, mx, t1, t2, ind, res;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > mx) {
			mx = a[i];
			ind = i;
		}
	}
	ans = mx + 1;
	ll t = 50000000000000;
	for (ll i = 0; i < pow(10, 13); )
	{
		i++; t /= abs(t-i);
	}
	if (mx % 2 == 0) {
		t1 = mx / 2;
		for (int i = 0; i < n; i++) {
			if (ind == i)continue;
			if (abs(a[i] - t1) < ans) {
				ans = abs(a[i] - t1);
				res = a[i];
			}
		}
	}
	else {
		t1 = mx / 2;
		t2 = mx / 2 + 1;
		for (int i = 0; i < n; i++) {
			if (ind == i)continue;
			if (abs(a[i] - t1) < ans) {
				ans = abs(a[i] - t1);
				res = a[i];
			}
			else if (abs(a[i] - t2) < ans) {
				ans = abs(a[i] - t2);
				res = a[i];
			}
		}
	}
	cout << mx << " " << res;

}






Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

int n,a,b,c,x,y,aa[100010],ba[100010];
bool r=false;
string s;
char ca,cb;


int main(){
    cin>>a>>b;
    cout<<max(0,a-b)<<endl;
    
}


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

int main() {
    
    long int h,n=0;
    int i=1;
    
    cin>>h;
    
    while(h>0)
    {
        if(h==1)
        {
         n++;
         h=0; 
        }
        else 
        {
            n=n+pow(2,i);
            h=h/2;
            i++;
        }
        
    }
    
	cout<<n;
	return 0;
}


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

int main(){
	string a,b;
	while(cin >> a >> b){
		int ans = 0;
		for(int x = 0 ; x < 2 ; x++){
			for(int i = 0 ; i < a.size() ; i++){
				int len = 0;
				for(int j = 0 ; j < b.size() ; j++){
					if(a[i+len] == b[j])len++;
					else len = a[i] == b[j];
					ans = max(len,ans);
				}
			}
			swap(a,b);
		}
		cout << ans << endl;
	}
}
// a b c d e
// abcdef
// def

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

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

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int n, m;
  cin>>n>>m;
  pair<ll, ll> pn[n];
  pair<ll, ll> pm[m];
  rep(i, 0, n)
  {
    cin>>pn[i].f>>pn[i].s;
  }
  rep(i, 0, m)
  {
    cin>>pm[i].f>>pm[i].s;
  }
  rep(i, 0, n)
  {
    int ans;
    ll curr = LONG_MAX;
    rep(j, 0, m)
    {
      ll dist = abs(pn[i].f - pm[j].f) + abs(pn[i].s - pm[j].s);
      if(dist < curr)
      {
        ans = j+1;
        curr = dist;
      }
      //cout<<dist<<endl;
    }
    //cout<<endl;
    cout<<ans<<endl;
    //cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 12160
#include<cstdio>
#include<cstring>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int temp[maxn];
int main()
{
	int n, k = 0, l = 1;
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		if(a[i] == i) temp[l++] = i;
	}
	for(int i = 2; i <= n; i++){
		if(temp[i] - temp[i-1] == 1){
			k++;
			i++;
		}
	}
	cout<<l-k-1<<endl;
}

Measured memory_bytes: 1024
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("pyramid.in", "r", stdin);
#endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e6 + 15;
int dx[8] = { -1, 0, 0, 1, 1, -1, 1, -1 };
int dy[8] = { 0, -1, 1, 0, 1, -1, -1, 1 };


int main()
{
	fast();
	string s;
	cin >> s;
	string res = "";
	for (int i = 0; i < sz(s); i++)
	{
		if (s[i] == '0' || s[i] == '1')
			res.push_back(s[i]);
		else
		{
			if (sz(res))
				res.pop_back();
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#!python3


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = list(map(int, input()))
    K = int(input())
    size = len(N)

    if size < K:
        print(0)
        return

    dp = [[[0]*(size+1) for j in range(2)] for i in range(size+1)]

    dp[0][0][0] = 1
    for i in range(size):
        for k in range(i+1):
            dp0, dp1 = dp[i], dp[i+1]

            dp1[1][k+1] += 9 * dp0[1][k]
            dp1[1][k]   +=     dp0[1][k]

            x, y = N[i], dp0[0][k]
            if x == 0:
                dp1[0][k] += y
            else:
                dp1[1][k] += y
                dp1[0][k+1] += y
                dp1[1][k+1] += (x-1) * y
        #print(dp1)

    print(dp[-1][0][K] + dp[-1][1][K])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3440