akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int check(int x){
    int sum=0;
    while(x!=0){
        sum+=x%10;
        x/=10;
    }
    return sum;
}

int main(void){
    int N;cin>>N;
    int ans=100000000;
    for(int i=1;i<=N/2;i++){
        int sum=0;
        sum+=check(i);
        sum+=check(N-i);
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> p(n), q(n);
	for(int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	
	for(int i = 0; i < n; ++i) {
		cin >> q[i];
	}
	
	vector<int> x(n);
	for(int i = 0; i < n; ++i) {
		x[i] = i + 1;
	}
	
	int a = 0, b = 0;
	int cnt = 0;
	
	do {
		if( p == x ) a = cnt;
		if( q == x ) b = cnt;
		
		cnt++;
		
	}while( next_permutation(x.begin(), x.end()) );
	
	cout << abs(a - b) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s,t;

int main(){
	cin>>s>>t;
	if(s==t.substr(0,s.size())) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############

def solve():
    [D, T, S] = inlt()
    return "Yes" if T * S >= D else "No" 
    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))


Measured memory_bytes: 68004
#include "bits/stdc++.h"
using namespace std;

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

	vector<vector<string>> str(5);
	
	for (int i = 0; i < n; i++)
	{
		string tmp;
		cin >> tmp; 

		if (tmp[0] == 'M')
			str[0].push_back(tmp);

		if (tmp[0] == 'A')
			str[1].push_back(tmp);

		if (tmp[0] == 'R')
			str[2].push_back(tmp);

		if (tmp[0] == 'C')
			str[3].push_back(tmp);

		if (tmp[0] == 'H')
			str[4].push_back(tmp);
	}

	int kind = str.size();

	for (int i = 0; i < 5; i++)
	{
		if (str[i].empty())
		{
			str.erase(str.begin() + i);
			kind--;
			break;
		}
	}

	int choicenum = 0;

	switch (kind)
	{
	case 3:
		choicenum = 1;
		break;
	case 4:
		choicenum = 4;
		break;
	case 5:
		choicenum = 10;
		break;
	default:
		break;
	}

	auto ans = 0ll;

	for (int i = 0; i < kind - 2; i++)
	{
		for (int l = i + 1; l < kind - 1; l++)
		{
			for (int j = l + 1; j < kind; j++)
			{
				ans += (long long)(str[i].size() * str[l].size() * str[j].size());
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<pair<string, pii>> A(N);
    rep(i, 0, N) {
        string s;
        cin >> s;
        int p;
        cin >> p;
        A[i] = {s, {-p, i}};
    }
    sort(all(A));
    rep(i, 0, N) {
        cout << A[i].second.second + 1<< endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int cnt = 0;
    long a, b, c;
    
    scanf("%ld %ld %ld", &a, &b, &c);
    
    if(a == b && b != c){
        cnt = 1;
    }else if(b == c && c != a){
        cnt = 1;
    }else if(c == a && a != b){
        cnt = 1;
    }
    if(cnt == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    
}


Measured memory_bytes: 1644
n=int(input())
a,b,c=0,0,0
count=0
for i in range(n):
  s=input()
  count+=s.count('AB')
  if s[0]=='B' and s[-1]=='A':
    a+=1
  elif s[0]=='B':
    b+=1
  elif s[-1]=='A':
    c+=1
if b==0 and c==0:
  print(count+max(0,a-1))
else:
  print(count+a+min(b,c))


Measured memory_bytes: 44008
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;


int main() {
  int a,b;
  cin >> a >> b;
  if(a<=0 && b>=0){
  	cout << "Zero" <<endl;
  }else if(a>0){
  	cout << "Positive" <<endl;
  }else if(((b-a)%2)==0){
  	cout << "Negative" <<endl;
  }else{
  	cout << "Positive" <<endl;
  }
  
}



Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200001

int n;
long a[MAXN];
long dp[MAXN][5];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) scanf("%ld", &a[i]);
	return 1;
}

void init() {
	memset(dp, 0, sizeof(dp));
}

long solve() {
	for (int i=1; i<=n; i++) {
		long x = a[i-1];
		long *z = dp[i-1];
		dp[i][0] = z[0] + x;
		dp[i][1] = *min_element(z, z+2) + (x? x%2: 2);
		dp[i][2] = *min_element(z, z+3) + 1-x%2;
		dp[i][3] = *min_element(z, z+4) + (x? x%2: 2);
		dp[i][4] = *min_element(z, z+5) + x;
		
	}
	/*
	for (int i=0; i<=n; i++) {
		for (int j=0; j<=4; j++)
			printf("%ld ", dp[i][j]);
		printf("\n");
	}
	*/
	return *min_element(dp[n], dp[n]+5);
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 9472
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

int main()
{
	int A[5];
	int ret;

	for (int i = 0; i < 5; ++i)
		std::cin >> A[i];
	std::sort(std::begin(A), std::end(A), [](auto a, auto b)->bool{return ((a+9)%10) < ((b+9)%10); });
	for (int i = 1; i < 5; ++i) {
		ret += (A[i]+9)/10*10;
	}
	ret += A[0];
	std::cout << ret << "\n";
}


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

const int N = 100 * 1000 + 5;

int a[N];
int main() {
	int n, mini = N, x = 0, y = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		mini = min(mini, a[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] == mini) {
			x++;
		}
		if (a[i] == mini + 1) {
			y++;
		}
		if (a[i] != mini && a[i] != mini + 1) {
			cout << "No";
			return 0;
			
		}
	}
	if (y == 0) {
		if (mini == n - 1 || mini * 2 <= n) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	else {
		if ((mini + 1 - x) * 2 <= n - x && (mini + 1 - x) > 0) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
bool d[111111];
int main(){
	int n,s=0,x;
	d[0] = 1;
	for(scanf("%d",&n); n--;){
		scanf("%d",&x);
		for(int i=s; i>=0; i--)
			if(d[i])d[i+x] = 1;
		s += x;
	}
	while(s > 0 && (s%10==0 || !d[s]))s--;
	printf("%d\n",s);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0,wak=0;
  bool allz = 1;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  while(1){
    allz = 1;
    wak = 0;
    for(int i=0; i<n; i++){
      if(i<n-1 && h[i] != 0 && h[i+1] == 0){
        wak++;
      }
      if(i == n-1 && h[i] != 0){
        wak++;
      }
      //cout << h[i] << " ";
    }
    //cout << endl;
    for(int i=0; i<n; i++){
      if(h[i] != 0){
        h[i]--;
        allz = false;
      }
    }
    cnt += wak;
    if(allz == 1){
      cout << cnt << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,m,i,l,j,k,q;
  int M[102],MM[102][102];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&M[i],&m);
  }
  M[n]=m;
  for(i=1;i<n+1;i++)MM[i][i]=0;

  for(l=2;l<n+1;l++){
    for(i=1;i<n-l+2;i++){
      j=i+l-1;
      MM[i][j]=10000000000;
      for(k=i;k<=j-1;k++){
	q=(MM[i][k]+MM[k+1][j]+M[i-1]*M[k]*M[j]);
        if(MM[i][j]>q){
	  MM[i][j]=q;
	}
      }
    }
  }
  printf("%d\n",MM[1][n]);
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a;
  cin>>n>>m;
  int d[10]={9,2,5,5,4,5,6,3,7,6};
  vector<bool> b(10,false),f(10010,false);
  for(int i=0;i<m;i++){
    cin>>a;
    b[a]=true;
  }
  vector<string> s(10010);
  f[0]=true;
  for(int i=0;i<=n;i++){
    for(int j=1;j<=9;j++){
      if(b[j]){
        if(d[j]<=i){
          if(f[i-d[j]]){
            string t=s[i-d[j]];
            t.push_back((char)('0'+j));
            if(t.size()>=s[i].size()){
              s[i]=t;
              f[i]=true;
            }
          }
        }
      }
    }
  }
  reverse(s[n].begin(),s[n].end());
  cout<<s[n];
}

Measured memory_bytes: 43008
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

template<typename Monoid>
struct SlidingWindowAggregation {
    using F = function< Monoid(Monoid, Monoid) >;

    stack< Monoid > front,back;
    stack< Monoid > sum_front;
    Monoid sum_back;
    const F f;
    const Monoid M1;
    SlidingWindowAggregation (const F f, const Monoid &M1) : f(f), M1(M1) {
        sum_front.push(M1);
        sum_back = M1;
    }

    void push(Monoid x) {
        back.push(x);
        sum_back = f(sum_back, x);
    }

    void pop() {
        if(front.empty()) {
            while(! back.empty()) {
                front.push(back.top());
                sum_front.push(f(front.top(), sum_front.top()));
                back.pop();
            }
            sum_back = M1;
        }
        assert(! front.empty());
        front.pop();
        sum_front.pop();
    }

    Monoid accumulate() const {
        return f(sum_front.top(), sum_back);
    }
    
    bool empty() const {
        return front.empty() && back.empty();
    }

    size_t size() const {
        return front.size() + back.size();
    }
};

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

int main(){
    ll n,m; cin >> n >> m;
    string s;cin >> s;
    vector<ll> step(n+1, INF);
    step[n] = 0;
    auto f = [](const auto &a, const auto &b){
        return min(a,b);
    };
    SlidingWindowAggregation<ll> swag(f, INF);
    swag.push(0);
    for(int i = n-1; 0 <= i; i--){
        if(s[i] == '0'){
            step[i] = swag.accumulate() + 1;
        }
        if(swag.size() > m-1)swag.pop();
        swag.push(step[i]);
    }
    if(step[0] >= INF){
        cout << -1 << endl;
        return 0;
    }
    vector<ll> ans;
    ll stemp = step[0];
    ll cnt = 0;
    ll pos = 1;
    while(stemp){
        cnt++;
        if(step[pos] < stemp){
            ans.emplace_back(cnt);
            cnt = 0;
            stemp = step[pos];
        }

        pos++;
    }

    for(auto v : ans)cout << v << " ";
    cout << endl;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main(){

  long long N,H,W;

  cin>>N>>H>>W;

  long long a,b;

  long long cnt=0;
  
  for(int i=0;i<N;i++){

    cin>>a>>b;

    if(a>=H&&b>=W){
      cnt++;
    }
  }

  cout<<cnt<<endl;

  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();

        if(a >= 3200){
            System.out.println(s);
        } else {
            System.out.println("red");
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    vec.at(i) = a;
  }
  
  int counter = 0;
  int b;
  b = vec.at(0);
  
  for (int i = 0; i < N + 1; i++) {
    if (b == 2) {
      counter++;
      cout << counter << endl;
      break;
    }
    else if (b == 1) {
      cout << -1 << endl;
      break;
    }
    else if (b != 2 && b != 1 && i < N) {
      counter++;
      b = vec.at(b-1);
      continue;
    }
    else if (b != 2 && i == N)
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();

            string[] sArr = line.Split(' ');
            int a = int.Parse(sArr[0]);
            int b = int.Parse(sArr[1]);
            
            Console.WriteLine("{0} {1} {2:0.00000}", a / b, a % b, a / (double)b);

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9316
#最大公約数
def gcd(m,n):
    from math import gcd as g
    return g(m,n)
        
def GCD(*X):
    from functools import reduce
    return reduce(gcd,X)

#最小公倍数
def lcm(m,n):
    return (m//gcd(m,n))*n

def LCM(*X):
    from functools import reduce
    return reduce(lcm,X)


N=int(input())
T=[]
for i in range(N):
    T.append(int(input()))
print(LCM(*T))


Measured memory_bytes: 68464
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  int p0 = 0, p1 = 0, p2 = 0;
  rep(i, n){
    int a;
    cin >> a;
    if(a % 4 == 0) p2++;
    else if(a % 2 == 0) p1++;
    else p0++;
  }
  if((p0 > p2+1) || ((p0 == p2+1) && (p1 != 0))){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    grid = [list(input().strip("\n")) for _ in range(H)]
    ans = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if grid[h][w] == "#":
                ans[h][w] = "#"
                continue
            count = 0
            if h > 0:
                if w > 0 and grid[h-1][w-1] == "#":
                    count += 1
                if grid[h-1][w] == "#":
                    count += 1
                if w < W - 1 and grid[h-1][w+1] == "#":
                    count += 1
            if w > 0 and grid[h][w-1] == "#":
                count += 1
            if w < W - 1 and grid[h][w+1] == "#":
                count += 1
            if h < H - 1:
                if w > 0 and grid[h+1][w-1] == "#":
                    count += 1
                if grid[h+1][w] == "#":
                    count += 1
                if w < W - 1 and grid[h+1][w+1] == "#":
                    count += 1
            ans[h][w] = count

    for h in range(H):
        print("".join(map(str, ans[h])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,Q;
int a[200010];
int front[200010];
int cover[200010];
int covered;
 
void add(int x){
	int n = front[x]-1;
	if(n>0){
		if(cover[n]==0) covered++;
		cover[n]++;
	}
	front[x]--;
}
void erase(int x){
	int n = front[x];
	if(n>0){
		cover[n]--;
		if(cover[n]==0) covered--;
	}
	front[x]++;
}
 
int main(){
	cin>>N>>Q;
	rep1(i,N) front[i] = i+1;
	rep(i,N){
		cin>>a[i];
		add(a[i]);
	}
	rep(t,Q){
		int x,v;
		cin>>x>>v;
		x--;
		int pv = a[x];
		erase(pv);
		add(v);
		a[x] = v;
                printf("%d\n", N-covered);
//		cout<<N-covered<<endl;
	}
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

const int M = 13;

string s;
ll t = 1, ans;
ll dp[2][13];
int ho = 0, ge = 1;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    dp[ho][0] = 1;
    for (int i = (int)s.size()-1; i >= 0; i--) {
        rep(j,M) dp[ge][j] = 0;
        if (s[i] != '?') {
            int x = s[i]-'0';
            rep(j,M) dp[ge][(t*x+j)%M] = dp[ho][j];
        } else {
            rep(j,10) {
                rep(k,M) dp[ge][(t*j+k)%M] += dp[ho][k];
            }
            rep(j,M) dp[ge][j] %= MOD;
        }
        t = t * 10 % M;
        swap(ho,ge);
    }
    cout << dp[ho][5] << endl;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

//ICPC: Intelligent Congruent Partition of Chocolate
public class Main{

	int w, h, si, sj, ti, tj, N, c;
	int[][] a;
	int[] sum;
	boolean[][] u;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};

	boolean cancel(int t){
		if(t<0)return false;
		int i = t/w, j = t%w;
		if(a[i][j]!=-1)return false;
		int cnt = 0;
		for(int k=0;k<4;k++){
			int ni = i+d[k][0], nj = j+d[k][1];
			if(0<=ni&&ni<h&&0<=nj&&nj<w&&a[ni][nj]==-1)cnt++;
		}
		return cnt==0;
	}
	
	boolean dfs(int i, int j, int rot, int rev, int num){
		if(num==(N>>1)){
			for(boolean[]v:u)Arrays.fill(v, false);
			c = 0;
			check(si, sj, -1);
			if(c!=(N>>1))return false;
			c = 0;
			check(ti, tj, -2);
			return c==(N>>1);
		}
		if(i==h || (N>>1)-num > sum[i*w+j] || cancel(i*w+j-w-1))return false;
		int cnt = 0;
		for(int k=0;k<4;k++){
			int ni = ti+d[k][0], nj = tj+d[k][1];
			if(0<=ni&&ni<h&&0<=nj&&nj<w&&(a[ni][nj]==1||a[ni][nj]==-2))cnt++;
		}
		if(cnt==0)return false;
		if(j==w)return dfs(i+1, 0, rot, rev, num);
		if(a[i][j]==1){
			a[i][j] = -1;
			int di = i-si, dj = j-sj;
			int ni, nj;
			if(rot==0){
				ni = di; nj = dj;
			}
			else if(rot==1){
				ni = dj; nj = -di;
			}
			else if(rot==2){
				ni = -di; nj = -dj;
			}
			else{
				ni = -dj; nj = di;
			}
			if(rev==1)nj*=-1;
			int ki = ti+ni, kj = tj+nj;
			if(0<=ki&&ki<h&&0<=kj&&kj<w&&a[ki][kj]==1){
				a[ki][kj] = -2;
				if(dfs(i, j+1, rot, rev, num+1))return true;
				a[ki][kj] = 1;
			}
			a[i][j] = 1;
		}
		return dfs(i, j+1, rot, rev, num);
	}
	
	void check(int i, int j, int x){
		if(u[i][j])return;
		u[i][j] = true;
		c++;
		for(int k=0;k<4;k++){
			int ni = i+d[k][0], nj = j+d[k][1];
			if(ni < 0 || h <= ni || nj < 0 || w <= nj || a[ni][nj]!=x)continue;
			check(ni, nj, x);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			N = 0;
			a = new int[h][w];
			u = new boolean[h][w];
			sum = new int[h*w+1];
			si = sj = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				a[i][j] = sc.nextInt();
				if(a[i][j]==1){
					N++;
					if(si==-1){
						si = i; sj = j;
					}
				}
			}
			if((N&1)==1){
				System.out.println("NO"); continue;
			}
			for(int i=h-1;i>=0;i--)for(int j=w-1;j>=0;j--)sum[i*w+j] = sum[i*w+j+1]+a[i][j];
			boolean res = false;
			a[si][sj] = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(a[i][j]==1){
				ti = i; tj = j;
				a[i][j] = -2;
				for(int rot=0;rot<4;rot++)for(int rev=0;rev<2;rev++){
					if(dfs(0, 0, rot, rev, 1)){
						res = true;
					}
					if(res)break;
				}
				a[i][j] = 1;
			}
			System.out.println(res?"YES":"NO");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
a = int(input())
b = int(input())
if a == 1 and b ==2:
    print(3)
elif a == 1 and b == 3:
    print(2)
elif a == 2 and b == 3:
    print(1)
elif a == 2 and b==1:
    print(3)
elif a == 3 and b==1:
    print(2)
elif a == 3 and b  == 2:
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t i64;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())

int digit_sum(int n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; i++) {
    int sum = digit_sum(i);
    if (A <= sum && sum <= B) {
      total += i;
    }
  }
  cout << total << endl;
}

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

int main() {
int N,A;
  cin>>N;
  A=N;
  int i,sum;
  sum=N%10;
  for(i=0;i<8;i++){
    N/=10;
    sum+=N%10;
  }  
  if(A%sum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

typedef long long ll;

#define reg register 
#define rep(a,b,c) for(reg int a=b,a##end=c;a<=a##end;++a)
#define drep(a,b,c) for(reg int a=b,a##end=c;a>=a##end;--a)

char IO;
int rd(){
	int s=0,f=0;
	while(IO=getchar(),IO<'0'||IO>'9')if(IO=='-')f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(IO=getchar(),IO>='0'&&IO<='9');
	return f?-s:s;
}

const int N=10000;

int n,m;
char s[5];

int main(){
	scanf("%s",s);
	int fl=0;
	rep(i,0,2) if(s[i]==s[i+1]) fl=1;
	puts(fl?"Bad":"Good");
}







Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,k;cin>>n>>k;

  ll mi=0,ma=n,ans=0;
  for(int i = 1;i <= n;++i){
    mi += i;
    ma += n-i;
    if(i >= k-1)ans += ma-mi+1;
    ans %= INF;
  }

  if(k == 1) ans = (ans + n + 1) % INF;
  print(ans);
  return 0; 
}


Measured memory_bytes: 3656
#include<stdio.h>
char s[8192],t[8192];
int wzs[16384],wzt[16384];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s%s",s,t);
	int nums=s[0]-'0';
	int numt=t[0]-'0';
	for(int i=1;i<n;i++)
	{
		if(s[i]!=s[i-1])
		{
			wzs[nums]=i;
			nums++;
		}
		if(t[i]!=t[i-1])
		{
			wzt[numt]=i;
			numt++;
		}
	}
	while(nums<6000)
	{
		wzs[nums]=n;
		nums++;
	}
	while(numt<6000)
	{
		wzt[numt]=n;
		numt++; 
	}
	int ans=1000000000;
	for(int i=-6000;i<=6000;i+=2)
	{
		int ans2=0;
		for(int j=-6000;j<=12000;j++)
		{
			int val0=j;
			int val1=i+j;
			if(val0<0)
			{
				val0=0;
			}
			else if(val0>=6000)
			{
				val0=n;
			}
			else
			{
				val0=wzs[val0];
			}
			if(val1<0)
			{
				val1=0;
			}
			else if(val1>=6000)
			{
				val1=n;
			}
			else
			{
				val1=wzt[val1];
			}
			if(val0<val1)
			{
				ans2+=val1-val0;
			}
			else
			{
				ans2+=val0-val1;
			}
		}
		if(ans2<ans)
		{
			ans=ans2;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

bool Hantei(int n){
    if(n==4){
        return true;
    }

}


int main (){
    int N;
    cin>>N;
    vector<bool> Vec(8);
    Vec={true, false, false, false, true, false, false, true};
    if(N>7){
        for(int i=8; i<N+1; i++){
            if(Vec.at(i-4)||Vec.at(i-7)){
                Vec.push_back(true);
            }
          	else{
              	Vec.push_back(false);
            }
        }
    }
    if(Vec.at(N)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

using namespace std;

int ArrayToInt(const int* arry, int ofs){
	int result;
	result = arry[ofs]*10000000
			+ arry[ofs+1]*1000000
			+ arry[ofs+2]*100000
			+ arry[ofs+3]*10000
			+ arry[ofs+4]*1000
			+ arry[ofs+5]*100
			+ arry[ofs+6]*10
			+ arry[ofs+7];
	return result;
}
 
//0082
int main(){
	const int merry[15] = {1,2,1,2,1,4,1,4,1,2,1,2,1,4,1};
	int human[8] = {0};
	
	while(1){
		int remain[8] = {0};

		for(int i=0; i<8; ++i){
			cin >> human[i];
			if(cin.eof())return 0;
		}

		int min_remain = INT_MAX;
		for(int start=0; start<8; ++start){
			for(int i=0; i<8; ++i){
				int t = human[i] - merry[start+i];
				if(t>0){
					remain[start] += t;
				}
			}
			min_remain = ((min_remain < remain[start]) ? min_remain : remain[start]);
		}

		int x;
		int prev = INT_MAX;
		for(int i=0; i<8; ++i){
			if(remain[i] == min_remain){
				int t = ArrayToInt(merry, i);
				if(prev > t){
					prev = t;
					x = i;
				}
			}
		}

		cout << merry[x+0] << " " 
			<< merry[x+1] << " "
			<< merry[x+2] << " "
			<< merry[x+3] << " "
			<< merry[x+4] << " "
			<< merry[x+5] << " "
			<< merry[x+6] << " "
			<< merry[x+7] << endl;

	}
	return 0; 
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s, t = "CODEFESTIVAL2016";
  cin >> s;
  cout << inner_product(s.begin(), s.end(), t.begin(), 16, minus<int>(), equal_to<char>()) << endl;
}


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

int main(){
  
  int N, L;
  cin >> N >> L;
  
  if (L >= 0) {
    int sum = 0;
    for (int i = 1; i < N; i++) {
      sum += L + i;
    }
    cout << sum << endl;
  } else if (L < 0 && L + N - 1 > 0) {
    int sum = 0;
    for (int i = 0; i < N; i++) {
      sum += L + i;
    }
    cout << sum << endl;
  } else {
    int sum = 0;
    for (int i = 0; i < N-1; i++) {
      sum += L + i;
    }
    cout << sum << endl;
  }
    
    
    
  return 0;
}
    
    
    

Measured memory_bytes: 256
O = input()
E = input()

if len(O) == len(E):
    for i in range(len(O)):
        print(O[i], end='')
        print(E[i], end='')
    print('')
else:
    for i in range(len(E)):
        print(O[i], end='')
        print(E[i], end='')
    print(O[-1])

Measured memory_bytes: 9032
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

const int MAX_E=200010;
struct edge{int u,v; ll cost;};
edge es[MAX_E];

int V, E;
int par[100009];
int height[100009];

void init(int n){
    for(int i=0; i<n; i++){
        par[i]=i;
        height[i]=0;
    }
}

int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}

void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(height[x]<height[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(height[x]==height[y]) height[x]++;
    }
}

bool same (int x, int y){
    return find(x) == find(y);
}

bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

int cruscal(){
    sort(es, es+E, comp);
    init(V);
    int res=0;
    rep(i,E){
        edge e=es[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    V=N,E=2*N-2;
    vector<pii> X,Y;
    rep(i,N){
        int x,y;cin>>x>>y;
        X.push_back({x,i});
        Y.push_back({y,i});
    }
    
    sort(all(X));
    sort(all(Y));
    rep(i,N-1){
        es[i]={X[i].second,X[i+1].second,X[i+1].first-X[i].first};
        es[N-1+i]={Y[i].second,Y[i+1].second,Y[i+1].first-Y[i].first};
    }
    cout1(cruscal())
}

Measured memory_bytes: 5996
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
 
int main() {
	ll a,ans,c;
	long double b;
    cin>>a>>b;
	c=b*100+0.5;
	ans=a*c;
	ans=ans/100;
	cout <<ans<<endl;
	return 0;
}


Measured memory_bytes: 3736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
}

Measured memory_bytes: 27000
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb; 

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

ll adjust(ll num){
    while (num % 10 != 0){
        num++;
    }
    return num;
}

int main() {
    vector<ll> ryouri(5);
    rep(i,5){
        cin >> ryouri[i];
    }
    sort(ryouri.begin(),ryouri.end());
    ll ans=LLONG_MAX;
    do{
        ll a = adjust(ryouri[0]);
        ll b = adjust(a+ryouri[1]);
        ll c = adjust(b+ryouri[2]);
        ll d = adjust(c+ryouri[3]);
        ll result = d + ryouri[4];
        ans = min(ans,result);

    }while(next_permutation(ryouri.begin(),ryouri.end()));//辞書順で次の順列が存在すれば真

    cout << ans << endl;

}


Measured memory_bytes: 3632
s = input()

a = int(s[0:2])
b = int(s[2:])

is_yymm = False
is_mmyy = False

if 1 <= b <= 12:
    is_yymm = True
if 1 <= a <= 12:
    is_mmyy = True

if is_yymm and is_mmyy:
    print("AMBIGUOUS")
elif is_yymm:
    print("YYMM")
elif is_mmyy:
    print("MMYY")
else:
    print("NA")    


Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define all(collection) (collection).begin(), (collection).end()
#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

class Abc103C
{
public:
	void Run(void)
	{
		int n; cin >> n;

		int x = 0;
		long sum = 0;
		loop(i, n)
		{
			cin >> x;
			sum += x;
		}

		cout << sum - n;
	}
};

int main()
{
	Abc103C abc103c;
	abc103c.Run();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>
#include<stack>
#include<math.h>
#include <utility>
#include <tuple>
 
#define rep(i,f,n) for(int i=f;i<(n);i++)
#define Rep(i,n) for(int i=1;i<=(n);i++)
#define LL long long int
 
 /* 
 greater<int>() 
 sortの第三因数に入れて降順 
sqrt(double) √を求める 
pair<int,int> x=make_pair(a,b)
x.first
tuple
get<番目>(変数名)
 */
using namespace std;
 
LL lcm(LL n, LL m)
{
	LL u;
	LL ansl = 0;
	for(u=m; u>=m; u++){
		if(u%n == 0){
			if(u%m == 0){
				ansl = u;
				break;
			}
		}
	}
	return ansl;
}
 
int main(){

    int n,k;
    cin>>n>>k;
    int h;
    int ans=0;
    rep(i,0,n){
        scanf("%d",&h);
        if(h>=k)ans++;
    }
    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  char c;
  cin>>c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
      cout<<"vowel"<<endl;
  }else{
      cout<<"consonant"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a,b,c,x;
  for(;cin>>n>>a>>b>>c>>x,n;)
    {
      int ans=0;
      int y;
      for(int i=0;i<n;i++)
	{
	  cin>>y;
	  for(int j=0;ans<=10000;j++)
	    {
	      if(x==y)
		{
		  if(i!=n-1)
		    {
		      x=(a*x+b)%c;
		      ans++;
		    }
		  break;
		}
	      x=(a*x+b)%c;
	      ans++;
	    }
	}
      if(ans>10000)
	cout<<"-1"<<endl;
      else
	cout<<ans<<endl;
    }

}

Measured memory_bytes: 1160
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    String S[][] = new String[H+2][W+2];
    String tmp = "";
    for(int i=0;i<W+2;i++){
      S[0][i]=".";
      S[H+1][i]=".";
    }
    for(int i=0;i<H+2;i++){
      S[i][0]=".";
      S[i][W+1]=".";
    }
    for(int i=1;i<H+1;i++){
      tmp=sc.next();
      for(int j=1;j<W+1;j++){
        S[i][j]=tmp.substring(j-1,j);
      }
    }
    for(int i=1;i<H+1;i++){
      for(int j=1;j<W+1;j++){
        if(S[i][j].equals(".")){
          S[i][j]=cntMine(S,i,j);
        }
      }
    }
    
    for(int i=1;i<H+1;i++){
      for(int j=1;j<W+1;j++){
        System.out.print(S[i][j]);
      }
      System.out.println("");
    }
  }
  
  public static String cntMine(String[][] S,int h,int w){
    int res =0;
    for(int i=0;i<3;i++){
      if(S[h-1][w-1+i].equals("#")){
        res=res+1;
      }
    }
    if(S[h][w-1].equals("#")){
      res++;
    }
    if(S[h][w+1].equals("#")){
      res++;
    }
    for(int i=0;i<3;i++){
      if(S[h+1][w-1+i].equals("#")){
        res++;
      }
    }
    return String.valueOf(res);
  }

  
}

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

int main()
{
  int n;
  double sum=0;
  cin>>n;
  double x[n],y[n],a[n][n];
  for(int i=0;i<n;i++)
  {
      cin>>x[i]>>y[i];
  }
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<n;j++)
      {
          if(i==j)
          a[i][j]=0;
          else
          a[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
          
          sum+=a[i][j];
      }
  }
  double b=(sum/n);
  cout<<fixed<<setprecision(10)<<b;
  return 0;
}
  

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

int str2bin(string s) {
    int res = 0;
    for(size_t i=0; i<s.size(); i++) {
        res = res * 2 + (s[i] == '1');
    }
    return res;
}

const int INF = 1 << 28;
int M, N;
int dp[(1 << 11) + 1][(1 << 11) + 1];

int solve(vector<int> &vec, int query, int yn) {
    // fprintf(stderr, "query = %d, yn = %d\n", query, yn);

    if(dp[query][yn] < INF) return dp[query][yn];
    int cnt = 0;
    for(int i=0; i<N; i++) {
        cnt += ((yn & query) == (vec[i] & query));
    }
    if(cnt < 2) return dp[query][yn] = 0;
    else {
        for(int i=0; i<M; i++) {
            if(query >> i & 1) continue;
            int nquery = query | (1 << i);
            int val = max(solve(vec, nquery, yn|(1<<i)), solve(vec, nquery, yn)) + 1;
            dp[query][yn] = min(dp[query][yn], val);
        }
        return dp[query][yn];
    }
}

int main() {
    while(cin >> M >> N, M || N) {
        fill(dp[0], dp[1 << M], INF);
        
        vector<int> vec(N);
        for(int i=0; i<N; i++) {
            string s; cin >> s;
            vec[i] = str2bin(s);
        }

        cout << solve(vec, 0, 0) << endl;
    }
    return 0;
}



Measured memory_bytes: 19432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  string s = "";
  if (n == 0) {
    s = "0";
  }
  while (n != 0) {
    if (n%2 == 0) {
      s = "0" + s;
    }
    else {
      s = "1" + s;
      n--;
    }
    n /= (-2);
  }
  dump(s);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}



const int mod = 1000000007;
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() {
    vector<bool> a(102,true);
    int x,n;
    cin >> x >> n;
    REP(i, n){
        IN(int, k);
        a[k] = false;
    }
    int ans = 0;
    REP(i, 102){
        if (a[i]&&abs(i-x)<abs(ans-x)) {
            ans = i;
        }
    }
    COUT(ans);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
//set<int>::iterator set_stater
//typedef pair<int,int> pii;
using namespace std;
typedef long long ll;
ll n,a,b,ans;
int main()
{
    scanf("%lld",&n);
    ff(i,1,n)
    {
        scanf("%lld%lld",&a,&b);
        int flag=0;
        if((ll)sqrt(a*b)*(ll)sqrt(a*b)==a*b)flag=1;
        if(flag)
        {
            if(a==b)
            printf("%lld\n",2*((ll)sqrt(a*b)-1));
            else
                printf("%lld\n",2*((ll)sqrt(a*b)-1)-1);
        }
        else
        {
            if((ll)sqrt(a*b)*((ll)sqrt(a*b)+1)<a*b)
            printf("%lld\n",2*((ll)sqrt(a*b)-1)+1);
            else
            printf("%lld\n",2*((ll)sqrt(a*b)-1));
        }
    }
    return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  string S;
  cin >> N >> S;
  int cnt = 1;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (size_t i = 0; i < S.size() - 1; ++i) {
    if (S[i] != S[i + 1]) {
      ++cnt;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 201000;
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int c1 = 1;
    int c2 = 1;
    for (int i = 1; i <= n; i++){
        c1 *= 3;
        int x;
        cin >> x;
        if (x % 2 == 0) c2 *= 2;
    }
    cout << c1 - c2;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[110];
    int count = 0;
    scanf("%s", s);
    int ans = (int)strlen(s);
    for(int i = 0; s[i] != '\0' || s[i+1] != '\0'; i += 2) {
        if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
            count++;
        }
    }
    for(int i = 1; s[i] != '\0' || s[i+1] != '\0'; i += 2) {
        if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
            count++;
        }
    }
    if(count == ans) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128