akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair                                                     
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main()
{
   ll x;
   cin>>x;
   ll ans=1000*(x/500);
   ll y=x%500;
   ans+=5*(y/5);
   cout<<ans;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	r := getInt()
	fmt.Println(3 * r * r)
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
uses Math;
var
	N,K,i,j:Longint;
	x,y,c:Array[1..60]of Longint;
	rr:Array[1..60]of double;
	L,R,M,a,t,d,ri,rj,yy:double;
	flag:Boolean;
function count(tx,ty:double):Boolean;
var i,cnt:Longint;
begin
	cnt:=0;
	for i:=1 to N do if sqr(X[i]-tx)+sqr(Y[i]-ty)<sqr(rr[i])+0.000000001 then inc(cnt);
	count:=cnt>=K;
end;
begin
	read(N,K);
	for i:=1 to N do read(x[i],y[i],c[i]);
	L:=0;
	R:=1000000;
	while R-L>0.000000001 do begin
		M:=(L+R)/2;
		for i:=1 to N do rr[i]:=M/c[i];
		flag:=False;
		for i:=1 to N do begin
			if count(X[i],Y[i])then begin
				flag:=True;
				break;
			end;
		end;
		if not flag then begin
			for i:=2 to N do begin
				for j:=1 to i-1 do begin
					d:=sqr(X[i]-X[j])+sqr(Y[i]-Y[j]);
					ri:=rr[i];
					rj:=rr[j];
					yy:=4*sqr(ri)*d-sqr(sqr(ri)+d-sqr(rj));
					if yy<0 then continue;
					a:=arctan2(sqrt(yy),sqr(ri)+d-sqr(rj));
					t:=arctan2(Y[j]-Y[i],X[j]-X[i]);
					if count(X[i]+ri*cos(t+a),Y[i]+ri*sin(t+a)) then flag:=True
					else if count(X[i]+ri*cos(t-a),Y[i]+ri*sin(t-a))then flag:=True;
					if flag then break;
				end;
				if flag then break;
			end;
		end;
		if flag then R:=M else L:=M;
	end;
	writeln(R:0:9);
end.


Measured memory_bytes: 256
def egcd(a, b):
    aa = 1; ab = 0
    ba = 0; bb = 1
    while b:
        q = a // b
        r = a % b
        ra = aa - ba * q
        rb = ab - bb * q
        a, b = b, r
        aa, ab = ba, bb
        ba, bb = ra, rb
    return a, aa, ab


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b): return a // gcd(a, b) * b


def phi(n):
    r = 1
    i = 1
    while n > 1:
        i += 1
        if i*i > n: i = n
        x = 1
        while n % i == 0: n //= i; r *= i - x; x = 0
    return r


def inftowermod(n, m):
    if m == 1: return 0
    if n == 1: return 1
    phim = phi(m)
    return pow(n, inftowermod(n, phim) + phim, m)


def solve_congruence(a1, m1, a2, m2):
    if m2 % m1 == 0: return a2
    if m1 % m2 == 0: return a1
    g, p, q = egcd(m1, m2)
    lm = m1 // g * m2
    w1 = m2 // g * q % lm
    w2 = m1 // g * p % lm
    return ((a1 // g * w1 + a2 // g * w2) * g + a1 % g) % lm


def solve(a, m):
    if a == 0: return m
    phim = phi(m)
    kphim = inftowermod(a, phim)
    km = pow(a, phim + kphim, m)


    ans = solve_congruence(km, m, kphim, phim)
    if ans < phim: ans += lcm(m, phim)
    return ans


for __ in range(int(raw_input())):
    print solve(*map(int, raw_input().split()))


Measured memory_bytes: 35180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#include <string.h>

int main(void) {
    int N;
    int i;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> R(N);
    
    for (i = 0; i < N; i ++) {
        cin >> P[i];
    }
    
    for (i = 0; i < N; i ++) {
        cin >> Q[i];
    }
    
    for (i = 0; i < N; i ++) {
        R[i] = i + 1;
    }
    int cnt = 1;
    int pCnt = 1;
    int rCnt = 1;
    do {
        if (R == P) {
            pCnt = cnt;
        }
        if (R == Q) {
            rCnt = cnt;
        }
        cnt ++;
    } while (next_permutation(R.begin(), R.end()));
    
    cout << abs(pCnt - rCnt) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;

int main(void)
{
	int x;

	cin >> x;

	if (x < 1200)
	{
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ARC" << endl;
	}

	return 0;
}

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

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

    int ret =   (num / 500) *1000;
    ret += (num % 500) /5 *5;

    cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
	string S;
	while (cin >> S) {
		long long res = 0;
		for (auto c : S) res += c - '0';
		if (res % 9 == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}
















Measured memory_bytes: 3724
#include<iostream>
#include<queue>
#include<stack>
#include<numeric>
#include<cstring>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#include<climits>
#include<cmath>

using namespace std;
#define ll long long
#define pp pair<int,int>
#define ppl pair<ll,ll> 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin>>n;

	int one=0,two=0;
	int*arr=new int[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];

	vector<int> dp(n,0);
	dp[1]=abs(arr[1]-arr[0]);
	two=dp[0];
	one=dp[1];

	for(int i=2;i<n;i++)
	{
		dp[i]=min(one+abs(arr[i]-arr[i-1]),two+abs(arr[i]-arr[i-2]));
		one=dp[i];
		two=dp[i-1];
	}

	cout<<dp[n-1];

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while (true) {
                        int N = sc.nextInt(), Q = sc.nextInt();
                        if (N == 0 && Q == 0) {
                                break;
                        }
                        String[] SS = new String[N];
                        int[] base = new int[N];
                        int[] now = new int[N];
                        for (int i = 0; i < N; i++) {
                                SS[i] = sc.next();
                                base[i] = sc.nextInt();
                                now[i] = sc.nextInt();
                        }
                        for (int i = 0; i < Q; i++) {
                                int num = sc.nextInt();
                                boolean f = true;
                                for (int j = 0; j < N; j++) {
                                        if (now[j] - base[j] < num && num <= now[j]) {
                                                System.out.println(SS[j] + " " + ( num - now[j] + base[j]));
                                                f = false;
                                                break;
                                        }
                                }
                                if (f) {
                                        System.out.println("Unknown");
                                }
                        }
                }
        }
}

Measured memory_bytes: 76928
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
#define N 200005
int a[N],b[N]={0};
struct node
{
    int num,x;
    bool operator < (const node& b)const
    {
        return num<b.num;
    }
};
priority_queue<node>q;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[a[i]]++;

     for(int i=1;i<=N-5;i++)
     {
         if(b[i])
         q.push({i,b[i]});
     }

     for(int i=1;i<=n;i++)
     {
         int flag=0;
         while(q.size())
         {
             node p=q.top();q.pop();
             if(p.num==a[i] && p.x==1){flag=1;continue;}
             else
             {
                 printf("%d\n",p.num);
                 q.push({p.num,p.x});
                 if(flag)
                 {
                     q.push({a[i],1});
                 }
                 break;
             }
         }
     }
    return 0;
}


Measured memory_bytes: 4084
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

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

int main(){
int N ;
cin >> N ;
map<int,int> mp ;
rep(i,N){
    int A ;
    cin >> A ;
    mp[A] = mp[A] + 1 ;
}
for( auto p : mp ){
    int B = p.second ;
    if(B == 0 || B == 1 ) continue ;
    else{
        cout << "NO" << endl;
        return 0 ;
    }
  }
  cout << "YES" << endl ;
}

Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll r,d,x;
    cin >> r >> d >> x;
    REP(i,10){
        x = r*x-d;
        cout << x << endl;;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    string s; cin >> s;
    int pattern1 = 0;
    int pattern2 = 0;
    rep(i,s.length()){
        bool is_white = s[i]=='1';
        if(is_white==(i%2)){
            pattern1++;
        }else{
            pattern2++;
        }
    }
    cout << min(pattern1,pattern2) << endl;
    return 0;
}

Measured memory_bytes: 512
open Printf
open Scanf

let id x = x

let solve q1 b c1 c2 q2 =
  let rec loop noj =
    if noj = 0 then "NA"
    else let non = (b - noj * c1) / c2 in
         if noj + non >= q1 then sprintf "%d %d" noj non
         else loop (noj - 1)
  in loop @@ min q2 @@ b / c1
  
let () =
  let rec loop () =
    let q1 = scanf "%d " id in
    if q1 = 0 then ()
    else begin
        scanf "%d %d %d %d " @@ fun b c1 c2 q2 -> solve q1 b c1 c2 q2 |> printf "%s\n";
        loop ()
      end
  in loop ()



Measured memory_bytes: 2388
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	as := make([]string, h)
	for i := range as {
		fmt.Scan(&as[i])
	}

	rowOfHash(w)
	for i := range as {
		fmt.Printf("%s%s%s\n", "#", as[i], "#")
	}
	rowOfHash(w)
}

func rowOfHash(w int) {
	for i := 0; i < w+2; i++ {
		fmt.Printf("%s", "#")
	}
	fmt.Println("")
}


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

int num[200005];
int main() {
    // freopen("boss.in", "r", stdin);
    // freopen("boss.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int x;
        cin >> x;
        num[x]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << num[i] << endl;
    }
    return 0;
}


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

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

  // mはRL判別用、nは生徒数
  vector<int> m(str.size()), n(str.size());
  
  // 配列の初期化(省略できるといいんだけど)
  for( int i = 0; i < str.size(); i++ ) {
    m[i] = 9;
    n[i] = 1;
  }
  
  // RLの並びに対応する要素に0を代入
  for( int i = 0; i < ( str.size() - 1 ); i++ ) {
    if( str[i] == 'R' && str[i+1] == 'L' ) {
      m[i] = 0;
      m[i+1] = 0;
    }
  }
  
  // 要素が0でないとき、L=-1, R=1を代入
  for( int i = 0; i < str.size(); i++ ) {
    if( m[i] != 0 ) {
      if( str[i] == 'R' ) {
        m[i] = 1;
      }
      else {
        m[i] = -1;
      }
    }
  }
  
  // mをチェックしながらnに人数を代入していく
  for( int i = 0; i < str.size(); i++ ) {

    if( m[i] == 0 ){
      for( int j = 1; ( (i-j) > -1 && m[i-j] == 1 ); j++ ) {
        if( j % 2 == 1 ) {
          n[i-j]--;
          n[i+1]++;
        }
        else {
          n[i-j]--;
          n[i]++;
        }
      }
    
      for( int j = 2; ( (i+j) < str.size() && m[i+j] == -1 ); j++ ) {
        if( j % 2 == 1 ) {
          n[i+j]--;
          n[i+1]++;
        }
        else {
          n[i+j]--;
          n[i]++;
        }
      }
      
      i++;
    }
  }
  
  // 出力用
  for( int i = 0; i < ( str.size() - 1 ); i++ ) {
    cout << n[i] << " ";
  }
  cout << n[(str.size() - 1)] << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<cstdlib>
#include<iostream>

using namespace std;

int main(){
    long long int n, m, loop, nk, nk1;
    cin >> n >> m ;
    loop = n / m;
    nk = n - loop*m;
    nk1 = n - (loop + 1) * m;

    if (abs(nk) < abs(nk1)) cout << abs(nk) << endl;
    else if(abs(nk) > abs(nk1)) cout << abs(nk1) << endl;
    return 0;
}

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

void solve(std::string S)
{
    S = "X" + S + "X";
    string S0 = "ATGC";

    vector<int> l(0), r(0);
    for (int i = 1; i < S.length(); i++)
    {
        if (S0.find(S[i]) != string::npos && S0.find(S[i - 1]) == string::npos)
        {
            l.push_back(i);
        }
        else if (S0.find(S[i]) == string::npos && S0.find(S[i - 1]) != string::npos)
        {
            r.push_back(i);
        }
    }

    int m = 0;
    for (int i = 0; i < l.size(); i++)
    {
        // cout << l[i] << " " << r[i] << endl;
        m = max(m, r[i] - l[i]);
    }
    cout << m << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

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

  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  for (int i = 0; i < n; ++i)
    h -= a[i];

  if (h <= 0)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi
#define se second
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0) 
 
using namespace std;
 
 
int main(){
//	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	if (s[2]==s[3] && s[4] == s[5])
	{
		cout << "Yes"<<endl;
	}
	else
	{
		cout << "No" <<endl;
	}
	return 0;

}

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;
const int INF=1000000000;

int main(){
  int N, C;
  cin >> N >> C;
  int D[35][35], c[510][510];
  rep(i,C){
    rep(j,C) cin >> D[i][j];
  }
  rep(i,N){
    rep(j,N) cin >> c[i][j];
  }
  int sum[3][35]={0};
  rep(col,C){
    rep(i,N){
      rep(j,N){
        int k=(i+j)%3;
        sum[k][col]+=D[c[i][j]-1][col];
      }
    }
  }
  int ans=INF;
  rep(i,C){
    rep(j,C){
      if(j==i) continue;
      rep(k,C){
        if(k==i||k==j) continue;
        int res=sum[0][i]+sum[1][j]+sum[2][k];
        ans=min(ans,res);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // ll INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;
 
// const int N = 2e5 + 5;


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      // ifstream cin("input.txt");

      int n;
      cin>>n;
      lld d;
      cin>>d;
      int cnt = 0;
      while(n--){
        ll x,y;
        cin>>x>>y;
        lld dist = sqrt(x*x+y*y);
        if (dist<=d) cnt++;
      }
cout<<cnt<<"\n";
}

Measured memory_bytes: 3236
#include <stdio.h>
#include <string.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int i, t, c;
   
    char s[100001];

    char k[100001];
   
      
    scanf("%s", s );
   

    for( i = 0 ; 2 * i < strlen(s) ; i = i + 1 ){

        k[i] = s[2 * i];

        }


    printf("%s\n", k );


    return 0;
                                                          
}

Measured memory_bytes: 384
m,d = map(int,input().split())
count = 0
for i in range(m):
    for j in range(d):
        if ((j+1)%10)>=2 and (j+1)//10>=2 and i+1 == ((j+1)%10)*((j+1)//10):
            count += 1
print(count)


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0 ; i < s.length() ; i++)
        ans += (s[i] != t[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3804
N = int(input())

nums = list(map(int,input().split(" ")))
s = 1
limit = 10**18
flag = False
for num in nums:
    s = s * num
    if s > limit:
        flag = True
        break

if flag:
    if 0 not in nums:
        print(-1)
    else:
        print(0)
else:
    print(s)
    


Measured memory_bytes: 21620
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;

int ar[N];
int dp[10010][100][2];
inline int add(int x, int y, int mod) {
   if (y >= mod) y %= mod;
   if (x >= mod) x %= mod;
   x  += y;
   return (x >= mod ? x - mod : x);
} 
inline int mul(int x, int y, int mod) {
  if (x >= mod) x %= mod;
  if (y >= mod) y %= mod;
  return (x*y) % mod;
}
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
  x %= mod;
  }
  return (x < 0 ? x+mod : x);
}
vector<int>v;
int k;
int solve(int pos ,int curMod , int f , int n){
  if(pos==n){
    return curMod==0;
  }
  if(dp[pos][curMod][f]!=-1)return dp[pos][curMod][f];
  int lim = (f==0 ? v[pos] : 9);
  int ans =0 ;
  for(int i =0 ;i<=lim;i++){
    int nf=f;
    int newMod =0;
    newMod+=(curMod+i%k)%k;
    if(i < lim && !f)nf =1;
    ans =add(ans, solve(pos+1,newMod,nf,n),MOD);
  }
  return dp[pos][curMod][f]=ans;
}
int go(string &s){
  v.clear();
  memset(dp,-1,sizeof(dp));
  int n = s.size();
  for(auto i : s){
    v.pb(i-'0');
  }
  int ans = solve(0,0,0,n);
  ans = sub(ans,1,MOD);
  return ans;
}
signed main(){
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  IOS;
  int T=1;
  // cin >> T;
  while(T--){
    string s;
    cin >> s>> k;
    cout << go(s);
  
  }
 // cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
  return 0;
}

Measured memory_bytes: 17536
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,m,p;
map<int,int> dict, ac;
string s;

signed main(){
    I(n); I(m);
    REP(i,m){
        cin >> p >> s;
        if (s == "WA" && !ac[p]) dict[p]++;
        if (s == "AC") ac[p] = 1;
    }
    int ans = 0;
    int pen = 0;
    for(auto pr: ac){
        if (!pr.second) continue;
        ans++;
        pen += dict[pr.first];
    }
    cout << ans << " " << pen << endl;
}

Measured memory_bytes: 12800
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin); i < (end); i++)
#define _irep3(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  ll N;
  cin >> N;
  vector<ll> a(N);
  cin >> a;

  ll exp = 1;
  rep(i, N) {
    if (a[i] == exp) {
      exp++;
    }
  }
  ll ans = exp > 1 ? N - (exp - 1) : -1;
  out(ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

bool z[3005];
vector<int> v;

int main(){
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);a*=100;b*=100;
	z[0]=true;
	fore(i,1,3005){
		if(i>=c)z[i]=z[i]||z[i-c];
		if(i>=d)z[i]=z[i]||z[i-d];
		if(z[i])v.pb(i);
	}
	int r0=a,r1=0;
	fore(i,0,32)fore(j,0,32){
		int w=i*a+j*b;
		if(w>=f)continue;
		int ms=min(f-w,w/100*e);
		auto it=upper_bound(v.begin(),v.end(),ms);
		if(it==v.begin())continue;
		int s=*(--it);
		if(r1*(w+s)<s*r0)r0=w+s,r1=s;
	}
	printf("%d %d\n",r0,r1);
	return 0;
}

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

using namespace std;

void SwapingTwoData(vector<vector <int>> Data){
    for (int i = 0; i >= 0; i++){
        if (Data[i][0] == 0 && Data[i][1] == 0)
            break;
        if (Data[i][0] > Data[i][1]){
            int temp = Data[i][0];
            Data[i][0] = Data[i][1];
            Data[i][1] = temp;
        }
        cout << Data[i][0] << " " << Data[i][1] << endl;
    }
}

int main(){
    // ---------------------------
    // ITP_1_3_A: Many Hello World
//    HelloWorldloop(1000);
    // ---------------------------

    // ---------------------------
    // ITP_1_3_B: Print Test Case
//    std::vector<int> data;
//    int in;
//    for (int i = 0; i >= 0; i++){
//        std::cin >> in;
//        data.push_back(in);
//        if (data[i] == 0) {
//            PrintTestCase(data);
//            break;
//        }
//    }
    // ---------------------------

    // ---------------------------
    // ITP_1_3_C: Swapping Two Data
    std::vector<vector<int>> data;
    int x, y;
    for (int i = 0; i >= 0; i++){
        std::cin >> x >> y;
        data.push_back({x, y});
        if (x == 0 && y == 0) {
            SwapingTwoData(data);
            break;
        }
    }
    // ---------------------------

    // ---------------------------
    // ITP_1_3_D: Small, Large, or Equal
    // ---------------------------

    return 0;
}


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
class Test
{
    public static void Main()
    {

        var n = long.Parse(Console.ReadLine());
        long sum = 0;
        if (n == 1)
        {
            sum = 0;

        }
        else if (n == 2)
        {
            sum = 1;
        }
        else
            sum = (n - 1) * (n) / 2;


        Console.Write(sum);
    }
}



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

int dp[3050][3050];
/*
	dp[i][j] : i番目「未満」の商品を食う時の、
		時刻jまでに食べきれる時の最大合計スコア
*/

int main(){
	int n,t;	cin>>n>>t;
	vector< pair<int,int> >data(n);
	for(int i=0; i<n; i++)cin>>data[i].first>>data[i].second;
	sort(data.begin(), data.end());

	for(int i=0; i<n; i++){
		int A=data[i].first, B=data[i].second;
		for(int j=0; j<t; j++){

			if(j<A)dp[i+1][j]=dp[i][j];
			else dp[i+1][j]=max(dp[i][j], dp[i][j-A]+B);

		}
	}

	int ans=0;
	for(int i=0;i<n;i++){
		ans=max(ans, dp[i][t-1] + data[i].second);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main(){
    int n=100010;
    set<int> s;
    vector<int> a(n,0);
    for (int i=2;i<n;i++){
        int k=2;
        while (true){
            if (k*k>i) {s.insert(i);break;}
            if (i%k==0) break;
            k++;
        }
    }
    for (int i=2;i<n;i++){
        a.at(i)=a.at(i-1);
        if (i%2==0) continue;
        auto it=s.find(i);
        auto itt=s.find((i+1)/2);
        if (it!=s.end() && itt!=s.end()) a.at(i)++;
    }
    int q;
    cin >> q;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << a.at(r)-a.at(l-1) << endl;
    }
}

Measured memory_bytes: 1536
from itertools import*
n=int(input())
a=[[s for s in input().split()]for _ in range(n)]
for b in a:
 b[3:5]=b[4],b[3]
t=0
for d,e in combinations(a,2):
 for p in('012345','152043','215304','302541','410352','514320'):
  f=[d[int(i)]for i in p]
  if f[0]==e[0]and f[5]==e[5]:
   f=f[1:5]*2
   for k in range(4):
    if f[k:k+4]==e[1:5]:t=1
print(['Yes','No'][t])


Measured memory_bytes: 5656
n=int(input())
a=list(map(int, input().split()))
count=0
ans=0
a.sort()
a.append(0)
for i in range(n):
    count+=1
    if a[i+1]!=a[i]:
        if count-a[i]>=0:
            ans+=count-a[i]
        else:
            ans+=count
        count=0
print(ans)

Measured memory_bytes: 14268
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353; //1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e6+100;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,a,b;
      cin>>n>>a>>b;
      if(abs(b-a)%2==0)
      {
        cout<<abs(b-a)/2;
      }
      else{
        if(b<a) swap(a,b);
        int ans1=(a+abs(b-a-1)/2);
        // if(b<a) swap(a,b);
        int ans2=((n-b+1)+abs(n-(a+(n-b+1)))/2);
        // cout<<ans2<<" ";
        cout<<min(ans1,ans2);
      }
}
// 2 5
// 3 5
// 4 4
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void)
{
    int ans = 0;
    int n;
    
    cin >> n;
    
    int* d = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    
    for (int i = 0; i < n-1; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a,b,c;
  cin >> N;
  a = N % 1110; //aはn/1110の余り
  b = N % 1000; //bはn/1000の余り
  c = b % 111;  //cはb/111の余り
  
  if (a < 10) {
    cout << "Yes" << endl;
  }
  /*aが10未満ならYes*/
  else if (c == 0) {
    cout << "Yes" << endl;
  }
  /*cが0ならYes*/
  else {
    cout << "No" << endl;
  }
  /*あとはNo*/
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

void solve(){
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    ans = N / K;
    ans = ans*ans*ans;

    if (K % 2 == 0) {
        ll m = N / (K / 2) - N / K;
        ans += m*m*m;
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;


string s = "CODEFESTIVAL2016";
string t;

void read() {
  cin >> t;
}


void kill() {
  int ans = 0;
  for (int i = 0; i < (int) s.length(); ++i)
    if (s[i] != t[i])
      ++ans;
  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MOD      = 998244353;
const int MAXVALUE = (int)1e6 + 4321;

int add(int x, int y) {
	return (x + y >= MOD ? x + y - MOD : x + y);
}

int sub(int x, int y) {
	return (x - y < 0 ? x - y + MOD : x - y);
}

int mult(int x, int y) {
	return (x * 1LL * y) % MOD;
}

int binpow(int x, int y) {
	if(y == 0 || x == 1) {
		return 1;
	}

	if(x == 0) {
		return 0;
	}

	int rez = binpow(x, y / 2);
	rez = mult(rez, rez);

	if(y & 1) {
		rez = mult(rez, x);
	}

	return rez;
}

int divide(int x, int y) {
	return mult(x, binpow(y, MOD - 2));
}

int sum[MAXVALUE], n;

void solve() {
	cin >> n;
	int full_sum = 0;

	for(int i = 0; i < n; ++i) {
		int value;
		cin >> value;
		full_sum = add(full_sum, value);

		/*for(auto& i: divs[value]) {
			sum[i] = add(sum[i], value);
		}*/

		for(int i = 1; i * i <= value; ++i) {
			if(value % i == 0) {
				sum[i] = add(sum[i], value);

				if(i * i != value) {
					sum[value / i] = add(sum[value / i], value);
				}
			}
		}
	}

	for(int i = 1; i < MAXVALUE; ++i) {
		sum[i] = mult(sum[i], sum[i]);
	}

	for(int i = MAXVALUE - 1; i > 0; --i) {
		for(int j = 2 * i; j < MAXVALUE; j += i) {
			sum[i] = sub(sum[i], sum[j]);
		}
	}

	int answ = 0;

	for(int i = 1; i < MAXVALUE; ++i) {
		int cur = sum[i];
		cur = divide(cur, i);

		answ = add(answ, cur);
	}

	answ = sub(answ, full_sum);
	answ = divide(answ, 2);

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 4224
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() { 
  int M[101][101];
  int P[100];
  rep(i,101){
    rep(j,101) M[i][j]=1e9;
  }
  
  int n;
  cin>>n;
  
  rep(i,n) cin>>P[i]>>P[i+1];
  for(int i=1;i<=n;i++) M[i][i]=0;
  
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      for(int k=i;k<j;k++){
        M[i][j]=min(M[i][j],M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j]);
      }
    }
  }
  
  cout<<M[1][n]<<endl;
  
  return 0;
}


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


#define MAX 200000
int L[MAX/2 + 2], R[MAX/2 + 2];


long long merge(int arr[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    long long cnt = 0;

    for (int i = 0; i < n1; i++)
        L[i] = arr[left+i];

    for (int i = 0; i < n2; i++)
        R[i] = arr[mid+i];

    L[n1] = R[n2] = INT_MAX;

    int i = 0; int j = 0;

    for (int k = left; k < right; k++) {
        if (L[i] <= R[j])
            arr[k] = L[i++];
        else {
            arr[k] = R[j++];
            cnt += n1 - i; //= mid + j - k - 1
        }
    }
    return cnt;
}


long long mergeSort(int arr[], int n, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) /2;
        long long v1 = mergeSort(arr, n, left, mid);
        long long v2 = mergeSort(arr, n, mid, right);
        long long v3 = merge(arr, left, mid, right);
        return v1 + v2 + v3;
    }
    return 0;
}

int main()
{
    int N;
    std::scanf("%d", &N);
    int arr[N];
    for (int i = 0; i < N; i++) std::scanf("%d", &arr[i]);
    long long cnt = mergeSort(arr, N, 0, N);
    std::cout << cnt << std::endl;



    return 0;
}



Measured memory_bytes: 4724
#include <stdio.h>
#include <string.h>
int main(void){
    char s[101];
    scanf("%s",s);
    int i,cnt=0,len=strlen(s);
    for(int i=0;i<len/2;i++){
        if(s[i]!=s[len-i-1]) cnt++;
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
P, A = [2], [2]
for i in range(3, 55556, 2):
    for p in P:
        if i % p == 0: break
    else:
        P.append(i)
        if i % 5 == 2: A.append(i)
    if len(A) == n: break
print(*A)

Measured memory_bytes: 39152
from operator import itemgetter

N = int(input())

SP = []
for i in range(1, N + 1):
    S, P = input().split()
    SP.append((S, int(P), i))

SP.sort(key=itemgetter(1), reverse=True)
SP.sort(key=itemgetter(0))
for sp in SP:
    print(sp[2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
ll p[MAX_N],q[MAX_N],r[MAX_N];
vector<ll> s;

int main()
{
	int X,Y,A,B,C;
	cin >> X >> Y >> A >> B >> C;
	rep(i,A)
	{
		cin >> p[i];
	}
	sort(p,p+A);
	rep(i,X)
	{
		s.push_back(p[A-1-i]);
	}
	rep(i,B)
	{
		cin >> q[i];
	}
	sort(q,q+B);
	rep(i,Y)
	{
		s.push_back(q[B-1-i]);
	}
	rep(i,C)
	{
		cin >> r[i];
		s.push_back(r[i]);
	}
	sort(s.begin(), s.end());
	reverse(s.begin(), s.end());
	ll ans = 0;
	rep(i,X+Y)
	{
		ans += s[i];
	}
	cout << ans << endl;
	return 0;
}

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

long long int a, b;

map<long long int, int > prime_factor(long long int n) {
  map<long long int , int > ret;
  for(long long int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  cin >> a >> b;
  long long int g = __gcd(a, b);
  map<long long int , int> fac;
  fac = prime_factor(g);
  
  /*
  cerr << g << endl;
  for(pair<long long int, int> x : fac){
    cerr << x.first << " " << x.second<<endl;
  }
  */
  
  cout << fac.size() + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let h = read![[usize]];

    let mut count = 0;
    let mut t = vec![0; N];
    let mut l = 0;

    loop {
        while l < N && t[l] == h[l] {
            l += 1;
        }

        if l == N {
            break;
        }

        let mut r = l + 1;
        while r < N && t[r] < h[r] {
            r += 1;
        }

        for i in l..r {
            t[i] += 1;
        }
        count += 1;
    }

    println!("{}", count)
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,i,j,m,temp,x;
    scanf("%d %d",&a,&b);
    m=0;
    for(i=a;i<=b;i++)
    {
        temp=0;x=i;
        for(j=1;j<=5;j++)
        {
            temp=temp*10+x%10;
            x=x/10;
        }
        if(temp==i)
            m++;
    }
    printf("%d",m);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////

ll n;
ll a[MAX_10p5 * 2], b, c[MAX_10p5 * 2], ans = 0;

int main() {
	rd(n);
	repi(i, 0, n) {
		rd(a[i]);
		c[i] = a[i] - (i + 1);
	}
	sort(c, c + n);
	b = c[(n + 1) / 2 - 1];
	repi(i, 0, n) {
		ans += abs(a[i] - (i + 1 + b));
	}
	wrln(ans);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, H, M;
  double pi = acos(-1);
  cin >> A >> B >> H >> M;
  
  double s, l;
  l = (double)6 * (double)M;
  s = (double)30 * (double)H + (double)0.5 * (double)M;
  
  double deg;
  if(l>s) deg = l-s;
  else deg = s-l;
  
  double c;
  c = A*A + B*B -2*A*B*cos(deg*pi/(double)180);
  
  cout << fixed << setprecision(10);
  cout << sqrt(c) << endl;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lld n,i;
    cin>>n;
    lld a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<lld>v;
    lld s=0,k=0;
    for(i=n-1;i>0;i--)
    {
        s=(s%mod+a[i])%mod;
        v.push_back(s);
    }
    lld j=0;
    for(i=n-2;i>=0;i--)
    {
        k=(k%mod+(v[j]*a[i])%mod)%mod;
        j++;
    }
    cout<<k;
	return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 998244353;


void bad() {
    cout << -1;
    exit(0);
}

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    ll s1 = 0, s2 = 0;
    set<pair<int, int>> st;
    for (int i = 0; i < n; i++)
        cin >> a[i], s1 += a[i];
    for (int i = 0; i < n; i++) {
        cin >> b[i], s2 += b[i];
        if (a[i] != b[i])
            st.emplace(b[i], i);
    }
    ll ans = 0;
    while (s1 < s2) {
        int ind = st.rbegin()->second;
        st.erase(--st.end());
        int pre = (ind - 1 + n) % n;
        int next = (ind + 1) % n;
        ll sm = b[pre] + b[next];
        if (b[ind] - a[ind] < sm)
            bad();
        ll k = (b[ind] - a[ind]) / sm;
        ans += k;
        b[ind] -= k * sm;
        s2 -= k * sm;
        if (b[ind] != a[ind])
            st.emplace(b[ind], ind);
    }
    for (int i = 0; i < n; i++)
        if (a[i] != b[i])
            bad();
    cout << ans;
}

Measured memory_bytes: 11136
// g++ -std=gnu++1y -O2 -I/opt/boost/gcc/include -L/opt/boost/gcc/lib -o ./a.out ./X.cpp & a.out //
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long


using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);	
    cin.tie(NULL); cout.tie(NULL);
    
    int n, k; cin >> n >> k;
    
    vector<int> h(n);
    for(int &t: h) cin >> t;
    
    vector<int> dp(n, INT_MAX);
    
    dp[0] = 0;
	//dp[1] = dp[0] + abs(h[0] - h[1]);
	for(int i = 0; i < n-1; i++)
	{
		//dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
		for(int x = i+1; x <= i+k; x++) 
		{
			dp[x] = min(dp[x], dp[i] + abs(h[i]-h[x]));
			if(x >= n-1) break;
		}
	}

	cout << dp[n-1] << endl;
    
    
    return 0;
}



Measured memory_bytes: 1024