akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;
inline int muln(int x, int y) { return 1LL * x * y % MOD; }
inline int qpow(int x, int y) {
    int ret = 1;
    for(; y; y >>= 1, x = muln(x, x))
        if(y & 1) ret = muln(ret, x);
    return ret;
}

inline int inv(int x) { return qpow(x, MOD - 2); }
int n, s, a[202], dp[202][102000], fac[222] = {1}, ifac[222] = {1};
vector<int> valid[202];
bitset<102000> vis[202];

inline int P(int N, int M) { return muln(fac[N], ifac[N-M]); }

int main() {
    #ifdef FREOPEN
        freopen("in.txt", "r", stdin);
        // freopen("out.txt", "w", stdout);
    #endif
    scanf("%d%d", &n, &s);

    for(int i = 1; i <= 200; ++i) {
        fac[i] = muln(fac[i - 1], i);
        ifac[i] = inv(fac[i]);
    }
    rep(i, n) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1, greater<int>());
    dp[0][s] = 1;
    valid[0].push_back(s);
    for(int i = 0; i < n; ++i) {
        for(auto j : valid[i]) {
            // printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
            for(int k = i + 1; k <= n; ++k) {
                dp[k][j % a[k]] += muln(dp[i][j], P(n-i-1, k-i-1));
                dp[k][j % a[k]] %= MOD;
                if(!vis[k][j%a[k]]) {
                    vis[k][j%a[k]] = true;
                    valid[k].push_back(j % a[k]);
                }
            }
        }
    }
    ll res = 0;
    for(int i = 1; i <= s; ++i) res = (res + 1LL * i * dp[n][i] % MOD) % MOD;
    cout << res << '\n';


    return 0;
}

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

using namespace std;

int bills[] = {5, 500};
int s = sizeof(bills) / sizeof(bills[0]);
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, ans=0;
	cin >> n;	
	for(int i = s - 1; i >= 0; i--)
	{
		while(n >= bills[i])
		{
			n -= bills[i];
			if (bills[i] == 500)
				ans += 1000;
			else if (bills[i] == 5)
				ans += 5;
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;	cin>>N;
	vector<ll> data(N);
	ll sum = 0;
	mint ans = 0;
	FOR(i,0,N){
		cin>>data.at(i);
		sum+=data.at(i);
	}

	FOR(i,0,N){
		mint sumc=sum-data.at(i);
		ans+=(sumc*data.at(i));
		sum-=data.at(i);
	}

	cout<<ans<<endl;




    return 0;
}



Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, m; cin >> n >> m;
    vector<deque<int>> lane(n);
    while (m--) {
        int t, x; cin >> t >> x;
        if (t == 0) {
            print(lane[x - 1][0]);
            lane[x - 1].pop_front();
        }
        else {
            int res = INF, num = -1;
            FOR(i, 0, n)if (chmin(res, (int)lane[i].size()))
                num = i;
            lane[num].push_back(x);
        }
    }

    return 0;
}


Measured memory_bytes: 3188
NTEST = 26

D=int(input())

C=list(map(int,input().split()))
lastDay = [0 for i in range(NTEST)]

SL=list()
SL.append([0 for i in range(NTEST)])
for d in range(D):
    S=list(map(int,input().split()))
    SL.append(S)

tests=list()
tests.append(0)
for d in range(D):
    tests.append(int(input()))

sat = 0
for d in range(1,D+1):
    tst = tests[d] - 1
    lastDay[tst] = d
    sat += SL[d][tst]
    for itst in range(NTEST):
        sat -= C[itst] * (d-lastDay[itst])
    
    print(sat)




Measured memory_bytes: 9404
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		int res = 0;
		for (int i = 0; i < A.length(); i++) {
			if (A.charAt(i) == B.charAt(i)) {
				res++;
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 35644
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;

int main(){
  char c;

  while(1){
    if(scanf("%c",&c)==EOF)
        return 0;
    if(islower(c))
      c=toupper(c);
    else if(isupper(c))
      c=tolower(c);
    putchar(c);
  }

}


Measured memory_bytes: 3132
//
//  main.cpp
//  ITP1_8-C
//
//  Created by ?????¶??? on 15/8/15.
//  Copyright (c) 2015??´ ?????¶???. All rights reserved.
//

#include <iostream>
#include <ctype.h>
#include <vector>

using namespace std;

int main() {
    
    char ch;
    
    int count[26] = {};
    
    while (cin >> ch) {
        
        ch = tolower(ch);
        
        int num = ch - 'a';
        
        count[num]++;
        
//        cout << ch << " " << count[num] << endl;
    }
    
    // ??????
    
    cout << "a : " << count[0] << endl;
    cout << "b : " << count[1] << endl;
    cout << "c : " << count[2] << endl;
    cout << "d : " << count[3] << endl;
    cout << "e : " << count[4] << endl;
    cout << "f : " << count[5] << endl;
    cout << "g : " << count[6] << endl;
    cout << "h : " << count[7] << endl;
    cout << "i : " << count[8] << endl;
    cout << "j : " << count[9] << endl;
    cout << "k : " << count[10] << endl;
    cout << "l : " << count[11] << endl;
    cout << "m : " << count[12] << endl;
    cout << "n : " << count[13] << endl;
    cout << "o : " << count[14] << endl;
    cout << "p : " << count[15] << endl;
    cout << "q : " << count[16] << endl;
    cout << "r : " << count[17] << endl;
    cout << "s : " << count[18] << endl;
    cout << "t : " << count[19] << endl;
    cout << "u : " << count[20] << endl;
    cout << "v : " << count[21] << endl;
    cout << "w : " << count[22] << endl;
    cout << "x : " << count[23] << endl;
    cout << "y : " << count[24] << endl;
    cout << "z : " << count[25] << endl;
    
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>

using namespace std;

int main()
{
	int prnum[50022] = { 0 }, n;

	for (int i = 2; i < 50022; i++) {
		if (!(prnum[i])) {
			for (int j = i*2; j < 50022; j+=i) {
				prnum[j] = 1;
			}
		}
	}

	while (1) {
		cin >> n;
		if (cin.eof()) break;

		for (int i = n-1;; i--) {
			if (!(prnum[i])) {
				cout << i << " ";
				break;
			}
		}
		for (int i = n+1;; i++) {
			if (!(prnum[i])) {
				cout << i << endl;
				break;
			}
		}
	}

}

Measured memory_bytes: 1364
use ::proconio::input;

fn main() {
    input! {
        s: String,
        t: String
    }
    let mut res = "Yes";
    for (s_i, t_i) in s.chars().zip(t.chars()) {
        if s_i != t_i {
            res = "No";
            break;
        }
    }
    println!("{}", res);
}

Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

// int main(){
//     int L;
//     cin >> L;
//     double l = L/3.l;
//     printf("%.12f\n.",pow(l,3));
//     return 0;
// }

int main() {
    int L;
    cin >> L;
 
    double d = L / 3.l;
    double ans = pow(d,3);
 
    printf("%.12f", ans);
 
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;

template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return halfpower*halfpower;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (halfpower*halfpower)*a;
      }
  }
};


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        cout << s[0] << s[1] << s[2] << endl;

    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#define N 105
using namespace std;

int n, m, s1, s2, s3, s[30], cnt[10];
char a[105];
int main()
{
	int i, j;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf ("%s", a);
		for (j = 0; j < m; j++) {
			s[a[j] - 'a']++;
		}
	}
	for (i = 0; i < 26; i++) {
			if (s[i] == 0) continue;
		if (s[i] % 4 == 3) {
			cout << "No";
			return 0;
		}
		if (s[i] % 4 > 0) cnt[s[i] % 4]++;
		cnt[0] += s[i] / 4;
	}
	if (n % 2 == 0) {
		if (m % 2 == 0) {
			s1 = 0;
			s2 = 0;
			s3 = (n / 2) * (m / 2);
		} else {
			s1 = 0;
			s2 = n / 2;
			s3 = (n / 2) * (m / 2);
		}
	} else {
		if (m % 2 == 0) {
			s1 = 0;
			s2 = m / 2;
			s3 = (n / 2) * (m / 2);
		} else {
			s1 = 1;
			s3 = (n / 2) * (m / 2);
			s2 = ((n + 1) / 2) * ((m + 1) / 2) - s1 - s3;
		}
	}
	while (cnt[0] >= 0) {
		if (s1 == cnt[1] && s2 == cnt[2] && s3 == cnt[0]) {
			cout << "Yes";
			return 0;
		}
		cnt[0]--;
		cnt[2] += 2;
	}
		cout << "No";

    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    M=13
    S=input()
    n=len(S)
    dp=[0]*M
    dp[0]=1
    for i in range(n):
        ndp=[0]*M
        s=S[i]
        if(s=='?'):
            for j in range(10):
                for m in range(M):
                    ndp[(m*10+j)%M]+=dp[m]
                    ndp[(m*10+j)%M]%=MOD
        else:
            s=int(s)
            for m in range(M):
                ndp[(m*10+s)%M]+=dp[m]
        dp=ndp
    print(dp[5])
resolve()

Measured memory_bytes: 44968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
    long long  w, h;
    long long eda = 0;
    cin >> w >> h;
    vector<ll> p;
    vector<ll> q;
    for(ll i = 0; i < w; i++){
        ll in;
        cin >> in;
        p.push_back(in);
    }
    for(ll i = 0; i < h; i++){
        ll in;
        cin >> in;
        q.push_back(in);
    }
    p.push_back(INF);
    q.push_back(INF);
    ll cost = 0;
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    ll need = (w + 1) * (h + 1) - 1;
    while(eda < need){
        if((p.back()) > (q.back())){
            eda += (w + 1);
            cost += (w + 1) * q.back();
            h--;
            //cout << q.back() << endl;
            q.pop_back();
        } else {
            eda += (h + 1);
            cost += (h + 1) * p.back();
            w--;
            //cout << p.back() << endl;
            p.pop_back();
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
string s,t;
vector<string> v;
int main(){
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    for(int i{};i<=s.size()-t.size();++i){
        string x;
        for(int j{};j<i;++j)
            x+=s[j]!='?'?s[j]:'a';
        bool f{};
        for(int j{};j<t.size();++j){
            if(s[j+i]!='?')
                if(s[j+i]!=t[j]){
                    f=1;break;
                }
            x+=t[j];
        }
        if(f)continue;
        for(int j{i+t.size()};j<s.size();++j)
            x+=s[j]!='?'?s[j]:'a';
        v.push_back(x);
    }
    if(v.size())
        cout<<*min_element(v.begin(),v.end())<<endl;
    else
        cout<<"UNRESTORABLE"<<endl;
}


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

// ----- MP algorithm -----

template <typename Type = string>
class MP
{
  int N;
  Type S;
  vector<int> A;

public:
  MP() {}
  MP(Type const &S) : N(S.size()), S{S}, A(N + 1, -1)
  {
    int j{-1};
    for (auto i{0}; i < N; i++)
    {
      while (j != -1 && S[j] != S[i])
      {
        j = A[j];
      }
      ++j;
      A[i + 1] = j;
    }
  }

  int operator[](int i) const { return A[i]; }

  int period(int i) const { return i - A[i]; }

  vector<int> place(Type const &T) const
  {
    vector<int> res;
    int j{0};
    for (auto i{size_t{0}}; i < T.size(); i++)
    {
      while (j != -1 && S[j] != T[i])
      {
        j = A[j];
      }
      ++j;
      if (j == N)
      {
        res.push_back(i - j + 1);
        j = A[j];
      }
    }
    return res;
  }

  vector<bool> table(Type const &T) const
  {
    vector<bool> res(T.size(), false);
    for (auto e : place(T))
    {
      res[e] = true;
    }
    return res;
  }
};

int main()
{
  string t, p;
  cin >> t >> p;
  MP<string> mp{p};
  for (auto e : mp.place(t))
  {
    cout << e << endl;
  }
}



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

int main() {
  long long n;
  cin >> n;
  vector<long long> list(n);
  for (int i=0;i<n;i++) {
    cin >> list.at(i);
  }
  long long count=0;
  long long temp_num=1;
  for(int i=0;i<n;i++) {
    if(list.at(i)==temp_num) {
      temp_num++;
    }
    else {
      count++;
    }
  }
  if(temp_num==1) {
    cout << -1 << endl;
  }
  else {
    cout << count << endl;
  }
}

Measured memory_bytes: 1792
/**
 *      ABC 110 B
 *      author  : kyomukyomupurin
 *      created : 
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    int x[N] = {}; int y[M] = {};
    for (auto i = 0; i < N; ++i) {
        cin >> x[i];
    }
    for (auto i = 0; i < M; ++i) {
        cin >> y[i];
    }

    int xx = -101; int yy = 101;

    for (auto i = 0; i < N; ++i) {
        if (x[i] > xx){
            xx = x[i];
        }
    }

    for (auto i = 0; i < M; ++i) {
        if (y[i] < yy){
            yy = y[i];
        }
    }

    if (max(xx, X) < min(yy, Y)){
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void Do(int N, int M, int C){
  int i, j, A, c, n;
  int B[M];
  c = 0;
  for(i = 0;i < M;i++) scanf("%d", &B[i]);
  for(i = 0;i < N;i++){
    n = C;
    for(j = 0;j < M;j++){
      scanf("%d", &A);
      n += A * B[j];
    }
    if(n > 0) c++;
  }
  printf("%d\n", c);
}
  

int main(void){
  int N, M, C;
  scanf("%d %d %d", &N, &M, &C);
  Do(N, M, C);
  return 0;
}


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

int checkOorE( int i );

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

  int countO = 0;

  for( int i = 1; i <= N; i++ ) {
    countO += checkOorE( i );
  }
  cout << countO << endl;
}

int checkOorE( int i )
{
  int count = 0;
  
  while( i ) {
    i /= 10;
    count++;
  }
  if( count % 2 == 0 )
    return 0;
  else
    return 1;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> eng(N);
    for(auto& i : eng)cin >> i.first >> i.second;
    auto d = static_cast<unsigned long>(partition(eng.begin(), eng.end(), [](auto i){return i.first == 0 ? i.second < 0 : i.first > 0;}) - eng.begin());
    for(unsigned long i = 0; i < N; ++i)eng.emplace_back(-eng[i].first, -eng[i].second);
    for(unsigned long i = 0; i < d; ++i)eng.emplace_back(eng[i].first, eng[i].second);
    auto cmp = [](auto i, auto j){return atan2(static_cast<long double>(i.first), static_cast<long double>(i.second)) < atan2(static_cast<long double>(j.first), static_cast<long double>(j.second));};
    sort(eng.begin(), eng.begin() + d, cmp);
    sort(eng.begin() + d, eng.begin() + d + N, cmp);
    sort(eng.begin() + d + N, eng.end(), cmp);
    long a{0}, b{0};
    unsigned long ans{0};
    for(unsigned long i = 0; i < 2 * N + d; ++i){
        a += eng[i].first;
        b += eng[i].second;
        ans = max<unsigned long>(ans, a * a + b * b);
    }
    printf("%.12Lf", sqrt(static_cast<long double>(ans)));
    return 0;
}

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

int main(){
	int n;
	bool s[32];
	for(int i=0;i<32;i++)s[i]=false;
	for(int i=0;i<28;i++){
		scanf("%d",&n);
		s[n]=true;
	}
	for(int i=1;i<31;i++){
		if(!s[i])printf("%d\n",i);
	}
}

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

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

	if((a==b&&a!=c)|| (a == c && a != b) || (c == b && a != c))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include<cstring>
#include <math.h>
typedef long long ll;
using namespace std;
using namespace std;
const int MAXN = 2e5+7;

int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    for(int i=1; i<a; i++)
    {
        sum+=i;
    }
    if(b>=2)
    {
        for(int i=1; i<b; i++)
        {
            sum+=i;
        }
    }

    cout<<sum;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[][] br = new int[n][n];
    int ans = 0;
    int[] al = new int[m];
    int[] bl = new int[m];
    for(int i = 0; i < m; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      br[a][b] = 1;
      br[b][a] = 1;
      al[i] = a; 
      bl[i] = b;
    }
    for(int s = 0; s < m; s++) {
      int[][] dp = new int[n][n];
      for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
          if(i != j) dp[i][j] = 100; 
        }
      }
      for(int i = 0; i < m; i++) {
        if(i != s) {
          dp[al[i]][bl[i]] = 1;
          dp[bl[i]][al[i]] = 1; 
        }
      }
      for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
          for(int j = 0; j < n; j++) {
            dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k][j]);
          }
        }
      }
      int flg = 0;
      for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
          if(dp[i][j] > 60) flg++;
        }
      }
      if(flg > 0) ans++;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 25164
import math
#from collections import deque

n = int(input())
# if n == 1:
#     print("0")
#     exit()

# flag = True
# for k in range(2, int(math.sqrt(n)) + 1):
#     if n % k == 0:
#         flag = False
#
# if flag:
#     print("素数！！")
#     print(n - 1)
#     exit()

# s = [[1,2,1]]
# s = [[1,2]]
# q = deque(s)
#
# count = 0
# num = 0
# while True:
#     ans = q.popleft()
#     # if (ans[0]+1)*(ans[1]) == n or (ans[0])*(ans[1]+1) == n:
#     if (ans[0]+1)*(ans[1]) == n or (ans[0])*(ans[1]+1) == n:
#         # print(ans[2] + 1)
#         print(ans[0] + ans[1] - 1)
#         exit()
#
#     else:
#         if ans[0] == ans[1]:
#             if (ans[0]+1)*(ans[1]) == n or (ans[0])*(ans[1]+1) == n:
#                 print(ans[0] + ans[1] - 1)
#                 exit()
#
#         else:
#             if ([ans[0]+1, ans[1]]) not in q:
#                 q.append([ans[0]+1, ans[1]])
#             if ([ans[0], ans[1]+1]) not in q:
#                 q.append([ans[0], ans[1]+1])
ansMax = 1000000000000
num = int(math.sqrt(n))
for i in range(1, num + 1):
    if n % i == 0:
        b = (n // i)
        if i + b - 2 < ansMax:
            ansMax = i + b - 2

print(ansMax)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cstring>
#define ll long long int 
using namespace std;

double dp[3003][3003];

int main()
{
   ll n;
   cin>>n;
   vector<double> p(n+3);
   
   for(ll i=1;i<=n;i++)
      cin>>p[i];
      
    memset(dp,0,sizeof (dp));
    dp[0][0]=1;
    for(ll i=1;i<=n;i++){
     for(ll j=0;j<=n;j++)
     {  dp[i][j]=dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*(p[i]);
       
     }
    } 
      
      double sum=0;
      
      
     for(ll j=(n/2 + 1);j<=n;j++)
          sum+=dp[n][j];
     
     cout<<setprecision(10)<<sum;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/
int main(){
    int n;
    cin >> n;
    int l[2*n];
    rep(i,2*n)cin >> l[i];
    int ans=0;
    sort(l,l+2*n);
    rep(i,n)ans+=l[i*2];
    cout << ans;
}

Measured memory_bytes: 256
import sys
from collections import Counter

import sys
sys.setrecursionlimit(10**6)
table = dict()
def choose(n, r, mod=None): # not mod, or mod ≠ prime
  if r > n or r < 0: return 0
  if r == 0: return 1
  if (n, r) in table: return table[(n, r)] 
  table[(n, r)] = (choose(n - 1, r) + choose(n - 1, r - 1))
  # table[(n, r)] = (choose(n - 1, r, mod) + choose(n - 1, r - 1, mod)) % mod
  return table[(n,r)]

n = int(sys.stdin.readline().rstrip())
s = [''.join(sorted(s)) for s in sys.stdin.read().split()]

def main():
    tot = 0
    for c in Counter(s).values():
        tot += choose(c, 2)
    print(tot)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 157628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main()
{
    IOS;
 
    ll n;
    cin>>n;
    if(n%1000==0){
        cout<<n%1000;
        return 0;
    }
    cout<<1000-(n%1000);
        
    return 0;
}






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

#A
def A():
    a, b, c = LI()
    if b < a:
        a,b = b,a
    if a <= c <= b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()-1
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    a, b = 0, 0
    for num,i in enumerate(s):
        if i == "#":
            dp[num] += 1
    for i in range(1, n):
        dp[i] += dp[i - 1]
    ans = min(s.count("#"),s.count("."))
    shap = s.count("#")
    for i in range(n):
        a = dp[i] + (n - (i+1) - dp[-1] + dp[i])
        ans = min(ans, a)
    print(ans)


    """
    dp = []
    bf = s[0]
    del s[0]
    a = 
    flg = False
    if bf == ".":
        flg = True
    for i in s:
        if i == bf:
            a += 1
        else:
            dp.append(a)
            a = 1
            bf = i
    dp.append(a)
    a, b = 0, 0
    if flg:
        dp[0] = 0
    if len(s) and s[-1] == "#":
        dp[-1] = 0
    for d in range(len(dp) - 2, -1, -2):
        a += dp[d]
    for d in range(len(dp) - 1, -1, -2):
        b += dp[d]
    print(dp)
    print(min(a,b))
    """
    return

#D
def D():
    n = II()
    ai = IR(n)
    ai.sort()
    ruiseki = [0 for i in range(n)]
    for num, a in enumerate(ai):
        ruiseki[num] = a + ruiseki[num-1]
    select = list(itertools.combinations(range(n), 3))
    ans = 0
    for a,b,c in select:
        A = ruiseki[a]
        B = ruiseki[b] - ruiseki[a]
        C = ruiseki[c] - ruiseki[b]
        if A + B > C and B + C > A and A + C > B:
            ans += 6
            ans = ans % mod
    print(ans)
    
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> as(a);
    for(int i=0; i<a; i++) cin >> as.at(i);
    vector<int> bs(b);
    for(int i=0; i<b; i++) cin >> bs.at(i);
    vector<vector<int>> xycs(m);
    for(int i=0; i<m; i++)
    {
        vector<int> xyc(3);
        for(int i=0; i<3; i++) cin >> xyc.at(i);
        xycs.at(i) = xyc;
    }

    int ma = *min_element(as.begin(), as.end());
    int mb = *min_element(bs.begin(), bs.end());
    int mcos = ma + mb;
    for(auto xyc : xycs)
    {
        chmin(mcos, as.at(xyc.at(0)-1) + bs.at(xyc.at(1)-1) - xyc.at(2));
    }
    cout << mcos << '\n';

    return 0;
}


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

using namespace std;

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define in insert
#define sz(x) (int) x.size()
#define sqr(x) ((x) * (x))
#define fi first
#define se second

template<typename T>
void vout(T x) {
    cout << x << endl;
    exit(0);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;

const int inf = 1e9 + 1;
const ll INF = 1e18 + 1e2;
const int mod = 1e9 + 7;

int main() {
    fast_io

    int k; cin >> k;
    string s; cin >> s;
    int n = sz(s);
    if(n <= k) {
        cout << s;
        return 0;
    }
    forn(i, k) cout << s[i];
    cout << string(3, '.');
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		int out = 0;
		int num_runner = 0;
		int points = 0;

		while(true){
#if INPUT_FROM_FILE
			ifs >> buf;
#else
			std::cin >> buf;
#endif
			if(buf == "HIT"){
				if(num_runner == 3){
					points++;
				}
				else{
					num_runner++;
				}
			}
			else if(buf == "HOMERUN"){
				points += num_runner + 1;
				num_runner = 0;
			}
			else{
				out++;
				if(out == 3){
					std::cout << points << std::endl;
					break;
				}
			}
		}
	}

#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}



Measured memory_bytes: 3184
/***************************************** START OF TEMPLATE *********************************************/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define  SPEED           ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT      mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)      for(ll i = (a); i >= n; i--)
#define  fo(i,n)         for(ll i = 0; i < n; i++)
#define  newl            cout<<"\n";
#define  f               first
#define  s               second
#define  pb              push_back
#define  mp              make_pair
#define  sym(s)          s="#"+s+"#";
#define  sqr(v)          v*v;
#define  all(x)          (x).begin(),(x).end()
#define  alll(x,n)       x+1, x+n+1
#define  uniq(a)         a.resize(unique(a.begin(), a.end()) - a.begin());
#define  mset(x,val)     memset(x,val,sizeof(x))
#define  mset1d(a,n,v)   foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v) foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    

template <typename T> 
using  ordered_set =  tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
using  ll          =  long long;
using  ull         =  unsigned long long;
using  ld          =  long double;
using  pll         =  pair<ll,ll>;
using  vll         =  vector<ll>;
using  vpll        =  vector<pll>;

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, a[N];

/***************************************** FUNCTION IMPLEMENTATIONS **************************************/


/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    ll x, k, d;
    cin>>x>>k>>d;
    x = abs(x);
    ll r = x/d;
    x -= min(r,k)*d;
    k -= min(r,k);
    if(k&1) x = abs(x-d);
    deb1(x);
}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
        MAIN(i);
    }
}

Measured memory_bytes: 8324
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    M = I()

    print(48 - M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5068
import numpy as np
X = int(input())

def hantei(X, N):
    if X != 1:
        X_new = np.floor(X/2)
        flag = True
    else:
        X_new = 0
        flag = False
    return X_new, N*2, flag

flag = True
N = 1
count = 0
while flag:
    count += N
    X, N, flag = hantei(X, N)     
print(count)

Measured memory_bytes: 12504
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	ans := 0
	for i := 0; i <= n; i++ {
		strI := strconv.Itoa(i)
		digitSum := 0
		for j := 0; j < len(strI); j++ {
			num, _ := strconv.Atoi(string(strI[j]))
			digitSum += num
		}
		if digitSum >= a && digitSum <= b {
			ans += i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define ll long long
#define vi vector<long long>
#define pi pair<long long, long long>
#define mp make_pair
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9;
const ll N = (1<<5);
const double PI = 3.1415926535897;

int n, m;
string s;
vector<int> ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> m >> s;
    int cur = n;
    while(cur>0){
        for(int i=m; i>=0; i--){
            if(!i){
                cout << -1;
                return 0;
            }
            if(cur-i<0) i = cur;
            if(s[cur-i]=='0'){
                cur = cur - i;
                ans.pb(i);
                break;
            }
        }
    }
    reverse(all(ans));
    for(int i : ans) cout << i _;
}




Measured memory_bytes: 1096
#include<cstdio>

int n,a,l;
long long cnt;

int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&a);
		if(!a)
		{
			l=0;
			continue;
		}
		cnt+=a/2;
		if(l && a&1) cnt++,l=0;
		else if(a&1) l=1;
	}
	printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 128
fun main(args:Array<String>) {
    val n = readLine()!!.trim().toInt()
    when(n){
        in 1..3-> println("No")
        in 5..6-> println("No")
        4,7-> println("Yes")
        else->{
            for(i in 0..n/7){
                val dif = n - 7*i
                if(dif%4 == 0){
                    println("Yes")
                    return
                }
            }
            println("No")
        }
    }
}

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

using namespace std;

int n, k, h[100003], memo[100003] = {0};
int dp(int a)
{
    int best = 1000000000;
    if (memo[a] > 0)
        return memo[a] - 1;
    if (a >= n - k - 1)
    {
        return abs(h[a] - h[n - 1]);
    }
    for (int i = 1; i <= k; i++)
        best = min(best, abs(h[a] - h[a + i]) + dp(a + i));
    memo[a] = best + 1;
    return best;
}

int main(void)
{
    scanf("%d", &n);
    scanf("%d", &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
    }
    int m;
    m = dp(0);
    printf("%d\n", m);
    
}


Measured memory_bytes: 12392
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int n;
			Map <Integer,Integer> mapV = new HashMap<Integer,Integer> ();
			Map <Integer,Integer> mapC = new HashMap<Integer,Integer> ();
			Map <Integer,Integer> mapR = new HashMap<Integer,Integer> ();
			int v,c,index;
			int result;
			n = sc.nextInt();
			for(index=0;index<n;index++) {
				v = sc.nextInt();
				mapV.put(index,v);
			}
			result=0;
			for(index=0;index<n;index++) {
				c = sc.nextInt();
				mapC.put(index,c);
				v=mapV.get(index);
				if(v-c>0) {
					result=result+v-c;
				}
			}
			// 出力
			System.out.println(result);
	}
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 1000000007;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::string K, ll D) {
  ll N = K.size();
  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(2, vector<ll>(D + 1)));
  dp[0][0][0] = 1;
  FOR(i, 0, N) {
    ll k = K.at(i) - '0';
    FOR(j, 0, D) {
      FOR(dig, 0, 10) { (dp[i + 1][1][(j + dig) % D] += dp[i][1][j]) %= MOD; }
      FOR(dig, 0, k) { (dp[i + 1][1][(j + dig) % D] += dp[i][0][j]) %= MOD; }
      (dp[i + 1][0][(j + k) % D] += dp[i][0][j]) %= MOD;
    }
  }
  ll ans = (dp[N][0][0] + dp[N][1][0] - 1 + MOD) % MOD;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::string K;
  std::cin >> K;
  ll D;
  cin >> D;
  solve(K, D);
  return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  map<int, int> ma;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ma[a]++;
  }

  int ans = 0;
  for (auto m : ma) {
    if (m.second > m.first) {
      ans += m.second - m.first;
    } else if (m.second < m.first) {
      ans += m.second;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int k[100000];

int main() {
	int n, m; scanf("%d%d", &n, &m);
	int cnt = 0;
	rep(i, n - 1) {
		k[i] = cnt;
		int a; scanf("%d", &a);
		cnt += a;
	}
	k[n - 1] = cnt;
	cnt = 0;
	int g = 0;
	rep(i, m) {
		int a; scanf("%d", &a);
		(cnt += k[max(g, g + a)] - k[min(g, g + a)]) %= MOD;
		g += a;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    string s;
    cin>>s;
    int flag=0;
    for (int i=0;i<s.length();i++)
    {
        if (i%2==1 && s.at(i)=='R')
        flag=1;
        if (i%2==0 && s.at(i)=='L')
        flag=1;
    }
    if (flag==0)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}

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

void dfs(string now,int cou,int before);
int n,k;
vector<string> data;
map<string,int> used;
bool flg[15];


int main(){
  while(cin >> n >> k && n && k){
    data.clear();
    used.clear();
    for(int i=0;i<n;i++){
      string str; cin >> str;
      data.push_back(str);
    }
    for(int i=0;i<n;i++){
      memset(flg,true,n+1);
      dfs(data[i],0,i);
    }
    cout << used.size() << endl;
  }
}

void dfs(string now,int cou,int before){
  if(cou == k-1) {
    if(used[now]==0){
      used[now] = 1;
    }
  }
  else {
    flg[before] = false;
    for(int i=0;i<n;i++){
      if(flg[i]){
	string tmp=now;
	tmp += data[i];
	dfs(tmp,cou+1,i);
	tmp = data[i];
	tmp += now;
	dfs(tmp,cou+1,i);
      }
    }
  }
  flg[before] = true;
  return;
}

Measured memory_bytes: 1512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,x; cin>>N>>x;
    vector<ll> A(N*2);
    rep(i,N) cin>>A[i];
    rep(i,N) A[i+N]=A[i];
    ll B[N][N]; //i番目をj回までひだりをみる
    rep(i,N) B[i][0]=A[i]; 
    rep(i,N){
        reps(j,1,N){
            B[i][j]=min(B[i][j-1],A[i+N-j]);
        }
    }
    ll ans=INF2;
    rep(j,N){
        ll buf=0;
        buf+=j*x;
        rep(i,N){
            buf+=B[i][j];
        }
        mini(ans,buf);
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200000];
int n,k;

int B(int d){
	int cnt=0;
	while(d>0){
		cnt++;
		d=d-k+1;
	}
	return cnt;
}
int C(int d){
	int cnt=0;
	while(d<n-1){
		cnt++;
		d=d+k-1;
	}
	return cnt;
}
signed main(){
	cin>>n>>k;
	if(n==k){
		cout<<1<<endl;
		return 0;
	}
	rep(i,n)scanf("%d",&a[i]);
	int id=0;
	rep(i,n){
		if(a[i]==1)id=i;
	}
	int Min=B(id)+C(id);
	rep(i,k){
		Min=min(Min,B(id-i)+C(id+k-1-i)+1);
	}
	cout<<Min<<endl;
}

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

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

    int n;
    cin >> n;

    vector<multiset<char> > c(n);
    REP(i, n) {
        string s;
        cin >> s;
        REP(j, s.size())
            c[i].insert(s[j]);
    }

    multiset<char> res = c[0];
    REP(i, n) {
        multiset<char> tmp;
        set_intersection(res.begin(), res.end(),
                c[i].begin(), c[i].end(),
                inserter(tmp, tmp.end()));
        res = tmp;
    }

    for_each(res.begin(), res.end(), [](char c) {
            cout << c;
            });
    cout << '\n';
    return 0;
}


Measured memory_bytes: 384