akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long[] Arr = cin.ReadLongArray(2);
            long N = Arr[0];
            long K = Arr[1];
            long[] H = cin.ReadLongArray(N);
            long count = 0;
            Array.Sort(H);
            for (long i = 0; i < N - K; i++)
            {
                count += H[i];
            }
            
            Console.WriteLine(count);
            
        }   

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 37504
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 	int n ;
 	cin >> n  ; 
 	vt<int> a(n) ; 
 	rep(i,0,n) cin >> a[i] ; 
 	ll res = 0 ; 
 	set<int> ans ; 
 	for(int i = 0 ; i< n ; ++i) {
 		ans.insert(a[i]) ; 
 		if(*ans.begin() == a[i])
 			res++;
 	}
 	cout << res ; 
	return 0 ; 
}

Measured memory_bytes: 13480
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> hs(n+1), dp(n+1);
    for(int i=1; i<=n; ++i){
        cin >> hs[i];
    }
    dp[0]=0;
    dp[1]=0;
    for(int i=2; i<=n; ++i){
        if(i==2){
            dp[i]=dp[i-1]+abs(hs[i-1]-hs[i]);
            continue;
        }
        dp[i]=min(dp[i-2]+abs(hs[i-2]-hs[i]), dp[i-1]+abs(hs[i-1]-hs[i]));
    }
    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const ll mod = 1e9+7;
ll n;
ll dp[2020][2020];
struct A
{
    ll  num,avl;
} a[5005];
int cmp(A a,A b)
{
    return a.avl>b.avl;
}
ll work(ll l,ll r,ll now)
{
    if(l>r)
        return a[now].avl;
    if(dp[l][r]!=-1)
        return dp[l][r];
    ll fist=work(l,r-1,now+1)+a[now].avl*abs(a[now].num-r);
    ll second=work(l+1,r,now+1)+a[now].avl*abs(a[now].num-l);
    dp[l][r]=max(dp[l][r],max(fist,second));
    return dp[l][r];
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=n; i++)
    {
        cin>>a[i].avl;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    cout<<work(1,n,1)<<endl;
    return 0;
}


Measured memory_bytes: 35568
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

void solve(int n) {
  vector<int> ps;
  for (int x = 1; x * x <= n; x++) {
    if (n % x) continue;
    ps.push_back(x);
    if (n / x != x) ps.push_back(n / x);
  }
  int ans = 0;
  for (int x: ps) {
    if ((n - x) % x == 0 && (n - x) / x > 1 && (n - x) / x > x) {
      ans += (n - x) / x;
    }
  }
  cout << ans << endl;
}
signed main() {
  int n; cin >> n;
  solve(n);
  // REPI (i, 1, 100) {
  //   cout << i << " "; solve(i);
  // }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){

    int n,k;
    I2(n,k);

    set<int>st;

    for(int i = 1;i<=k;i++){
        int d;
        I(d);
        for(int j = 1;j<=d;j++){
            int x;
            I(x);
            st.insert(x);
        }
    }
    cout<<(n-(int)st.size())<<endl;
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define LOOP(i,x,n) for(int i=(x);i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;


signed main(){
  int n;cin>>n;
  vector<int> a(n);
  int sum=0;

  REP(i,n){
    cin>>a[i];
    if(i==0)sum+=abs(a[i]);
    else sum+=abs(a[i]-a[i-1]);
  }
  sum+=abs(a[n-1]);
  
  REP(i,n){
    if(i==0)cout<<sum-abs(a[i])-abs(a[i]-a[i+1])+abs(a[i+1])<<endl;
    else if(i==n-1)cout<<sum-abs(a[i])-abs(a[i]-a[i-1])+abs(a[i-1])<<endl;
    else cout<<sum+abs(a[i+1]-a[i-1])-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])<<endl;
  }

  return 0;
}


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

int main()
{
  std::vector<ll> vec(100010);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> vec.at(i);
  int zero = 0;
  for (int i = 0; i < n; i++) if (vec.at(i) == 0) zero++;
  if (zero > 0) {
    cout << 0 << endl;
    return 0;
  }
  ll prod = 1;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) <= 1000000000000000000 / prod) {
      prod *= vec.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << prod << endl;
}


Measured memory_bytes: 3860
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    ll K;
    cin >> S >> K;
    vector<ll> V;
    int cnt = 1;
    rep(i,1,S.size()){
        if(S[i] != S[i-1]){
            V.push_back(cnt);
            cnt = 1;
        }else{
            cnt++;
        }
    }
    V.push_back(cnt);
    ll ans = 0;
    if(V.size() == 1){
        ans += (V[0] * K) / 2;
    }else if(S[0] == S.back()){
        rep(i,0,V.size()-1){
            ans += V[i] / 2;
        }
        ans += (V[0] + V.back()) / 2 * (K-1);
        rep(i,1,V.size()-1){
            if(K >= 3)ans += V[i] / 2 * (K-2);
        }  
        rep(i,1,V.size()){
            ans += V[i] / 2;
        }
    }else{
        for(auto i:V){
            ans += (i/2) * K;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,a,ans;
int main(void){
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>a;
        if(i%2==1&&a%2==1)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (a <= 5) cout << 0 << endl;
	else cout << b / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{ ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
  int h,a,n,s=0;
  cin>>h>>n;
  while(n--)
  {
    cin>>a;
    s+=a;
  }
  if(s>=h)
    cout<<"Yes";
  else cout<<"No";
  return 0;
}
  


Measured memory_bytes: 256
#include <stdio.h>
void f(int s){
  int a,b,c,d,m,n;
  a=s/1000;
  s=s%1000;
  b=s/100;
  s=s%100;
  c=s/10;
  d=s%10;
  m=10*a+b;
  n=10*c+d;
  if(m>0 && m<=12 && n>0&& n<=12){
    printf("AMBIGUOUS");
  }
  else if(0<m && m<=12)printf("MMYY");
  else if(0<n && n<=12)printf("YYMM");
  else printf("NA");
}
int main(){
  int s;
  scanf("%d",&s);
  f(s);
  return 0;
}
  
  


Measured memory_bytes: 128
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		int count;
		for(int i = 3;i <= n; i += 2){
			count = 0;
			for(int j = 1;j <= n/2+1; j++){
				if(i%j==0) count++;
			}
			count++;
			if(count == 8) ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip> // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <bits/stdc++.h>
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(void){

    int N;
    cin >> N;
    
    int a[N];

    REP(i,N){
        cin >> a[i];
    }

    int ans = 1e+9;

    FOR(i,-100,101){
        
		int sum = 0;
        
		REP(j,N){
            sum += (a[j] - i) * (a[j] - i);
        }
		ans = min(ans, sum);
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

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

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

string s, t;

int main () {
    to_pray();

    cin >> s >> t;
    
    if (s == t)
    	return cout << "Yes", 0;
    
    int cnt = 0;
    
    while(true) {
    	++cnt;
    	rotate(s.begin(), s.begin() + 1, s.end());
    	if (s == t)
    		return cout << "Yes", 0;
    	if (cnt == sz(s))
    		return cout << "No", 0;
    }
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

leader = S[0]
right = 0
left = 0

for i in range(1,N):
    right += 1 if (S[i]=="W") else 0

result = right

for i in range(1,N):
    if (S[i-1]=="E"):
        left += 1
    if (S[i]=="W"):
        right -= 1
    result = max(result, right+left)

print(N-result-1)


    

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] words = sc.nextLine().toCharArray();
        int[] ans = new int['z'-'a'+1];
        for (int i = 'a'; i <= 'z'; i++) {
            int max = Integer.MIN_VALUE;
            int current = -1;
            for (int j = 0; j < words.length; j++) {
                if (words[j] == i) {
                    int tmp = j - current - 1;
                    max = max < tmp ? tmp : max;
                    current = j;
                }
            }
            int last = words.length - 1 - current;
            max = max < last ? last : max;
            ans[i - 'a'] = max;
        }
        int ret = Integer.MAX_VALUE;
        for (int n: ans) {
            ret = ret < n ? ret : n;
        }
        System.out.println(ret);
    }
}


Measured memory_bytes: 23508
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int x,y,sum;
void clac(int x)
{
	if(x==3)
		sum+=100000;
	if(x==2)
		sum+=200000;
	if(x==1)
		sum+=300000;
}
int main()
{
	scanf("%d%d",&x,&y);
	clac(x);
	clac(y);
	if(x==1&&y==1)
		sum+=400000;
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]

L.sort()

tmp = 0
num = 0
for i in range(N):
    if num +  L[i][1] <= M:
        tmp += L[i][0] * L[i][1]
        num += L[i][1] 
    else:
        tmp += (M - num) * L[i][0]
        num = M
        
    if num == M:
        break


print(tmp)



Measured memory_bytes: 27760
// https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll H, W;
  cin >> H >> W;

  if (H == 1 || W == 1) drop(1);
  if (H % 2 == 1 && W % 2 == 1) drop((H * W + 1) / 2);
  drop(H * W / 2);
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll n, k, ans = 1;
	cin >> n >> k;
	rep(i, n) {
		if (ans * 2 <= ans + k) {
			ans *= 2;
		}
		else ans += k;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
# 深さdの上限を先に決める
N = int(input())
# Aは，葉として残す必要があるものの数
A = list(map(int, input().split()))

# 深さdのノード数の上限
limit = [1]
for i in range(1, N+1):
    if i == N:  # 一番深いところの上限はA[N]
        limit.append(A[i])
    else:
        limit.append((limit[-1]-A[i-1])*2)
        if limit[-1] < 0:
            print(-1)
            exit()

# Nが0の時の処理
if N == 0:
    if A[0] != 1:
        print(-1)
        exit()

# 一番深いところから構築して最後にsumをとる
ans = [A[-1]]
now_leaf = A[-1]  # 一番深いところから構築しており，今現在の葉の数
for i in range(N-1, -1, -1):
    # print(A[i])
    ans.append(min(now_leaf+A[i], limit[i]))
    now_leaf = ans[-1]
# 構築したものに対してジャッジする, 葉を確保できているかどうか
for i in range(N):
    # ans[N-i]とすることで，今は一番浅いところから見ている
    if (ans[N-i]-A[i])*2 < A[i+1]:  # 葉が確保できているか
        print(-1)
        exit()
print(sum(ans))


Measured memory_bytes: 680076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[88];
void func()
{
    a[0]=2;
    a[1]=1;
    for(int i=2;i<=86;i++)
        a[i]=a[i-1]+a[i-2];
}
int main()
{
    int i,j,m;
    func();
    while(cin>>m)
    {
        cout<<a[m]<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline void chmin(T &a, T b){if(a>=b)a=b;}
template<class T> inline void chmax(T &a, T b){if(a<=b)a=b;}
typedef long long ll;
const int INF = 1e9;

string S;

int main(){
    cin >> S;
    int ans = 0;
    int state = S[0] - '0';
    for(int i = 1; i < S.size(); ++i){
        int temp = S[i] - '0';
        if(state == temp){ // 前の値と同じなら色を変える
            ++ans;
            state = (temp ? 0 : 1); // 現在の値が0なら1を、0なら1に色変え
        } else {
            state = temp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
    char inputS[101] = {'\0'};
    int flag = 1;
    scanf("%s", inputS);
    for (int count = 0; count < 101; count++)
    {
        if (count % 2 != 0)
        {
            if (inputS[count] == 'R')
            {
                flag = 0;
                break;
            }
        }
        else
        {
            if (inputS[count] == 'L')
            {
                flag = 0;
                break;
            }
        }
        
    }
    if (flag)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    
    return 0;
}

Measured memory_bytes: 128
s=input()
a="AC"
if s[0] != "A":
	a="WA"

cnt=0
for i in range(2, len(s)-1):
	if s[i]=="C":
		cnt+=1

if cnt!=1:
	a="WA"

for i in range(1, len(s)):
	if s[i]!="C" and ord(s[i]) < ord("a"):
		a="WA"

print(a)


Measured memory_bytes: 3060
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

// lib/join.hpp
#ifndef JOIN_HPP
#define JOIN_HPP


namespace tools {
  template <typename Iterator>
  std::string join(const Iterator begin, const Iterator end, const std::string delimiter) {
    std::ostringstream ss;
    std::string current_delimiter = "";
    for (Iterator it = begin; it != end; ++it) {
      ss << current_delimiter << *it;
      current_delimiter = delimiter;
    }
    return ss.str();
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, K, S;
  std::cin >> N >> K >> S;

  std::vector<i64> A;
  A.reserve(N);
  for (i64 i = 0; i < K; ++i) {
    A.push_back(S);
  }
  for (i64 i = 0; i < N - K; ++i) {
    A.push_back(S < 1000000000 ? 1000000000 : 999999999);
  }

  std::cout << tools::join(A.begin(), A.end(), " ") << std::endl;
  return 0;
}

Measured memory_bytes: 3332
N = int(input())
A = [[0] * N for _ in range(2)]
for i in range(2):
	A[i] = list(map(int,input().split()))

cum_sum = [[0] * (N+1) for _ in range(2+1)]
for i in range(2):
	for j in range(N):
		if j == 0:
			cum_sum[i+1][j+1] = A[i][j]
		else:
			cum_sum[i+1][j+1] = A[i][j] + cum_sum[i+1][j]

#for i in range(1,3):
#	print(cum_sum[i])

res = 0
for i in range(1,N+1):
	curr = 0
	curr += cum_sum[1][i]
	curr += cum_sum[2][N] - cum_sum[2][i-1]
	res = max(res, curr)

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll INF = 1e6;

void solve()
{
    vector<ll> v,t;
    ll a,b ,c , temp;
    cin>>a>>b>>c;
    temp=b;
    b=a;
    a=temp;
    temp=c;
    c=a;
    a=temp;
    cout<<a<<" "<<b<<" "<<c;

}

 
int main()
{
    SPEED;
    ll t = 1;
    //cin>>t;
    while(t--) solve();
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+10;
int n,m,H[M];
vector<int>g[M];
bool cv[M],mark[M];
int dfs(int v,int par,int h)
{
  int up=h,cnt=0;
  mark[v]=true;
  H[v]=h;
  if(g[v].size()==1 && v!=1)return h;
  for(auto u:g[v])
    if(!mark[u])
      {
	cnt++;
	int d=dfs(u,v,h+1);
	//cout<<v<<" "<<u<<" "<<d<<endl;
	up=min(up,d);
	if(d>=h)cv[v]=true;
      }
    else if(u!=par)
      up=min(up,H[u]);
  if(v==1)
    if(cnt>1)cv[v]=true;
    else cv[v]=false;
  return up;
}
int main()
{
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      int u,v;
      cin>>u>>v;
      u++;v++;
      g[u].push_back(v);
      g[v].push_back(u);
    }
  dfs(1,1,0);
  for(int i=1;i<=n;i++)
    if(cv[i])cout<<i-1<<endl;
  return 0;
}

Measured memory_bytes: 6940
# debug
debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if debugFlag

# util functions
def find_posmin(arr)
  m = arr.max
  arr.each do |e_i|
    m = e_i if e_i > 0 and m > e_i
  end
  return m
end

# input
a, b, q = $stdin.gets.chomp.split(" ").map(&:to_i)
shrs = []
a.times do
  shrs << $stdin.gets.chomp.to_i
end

tmps = []
b.times do
  tmps << $stdin.gets.chomp.to_i
end

xs = []
q.times do
  xs << $stdin.gets.chomp.to_i
end

# input check
if debugFlag
  p "--- INPUT (begin) ---"
  p shrs
  p tmps
  p xs
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if debugFlag
end

xs.each do |x_i|
  sw = nil
  se = nil
  tw = nil
  te = nil
  # shrs.size.times do |j|
  #   if x_i <= shrs[j]
  #     sw = shrs[j - 1]  # can be nil
  #     se = shrs[j]
  #     break
  #   end
  # end
  j = shrs.bsearch_index { |s| x_i < s }
  if j
    sw = shrs[j - 1]  # can be nil
    se = shrs[j]
  end
  if se == nil
    sw = shrs[-1]
  elsif se == shrs[0]
    sw = nil
  end

  # tmps.size.times do |j|
  #   if x_i <= tmps[j]
  #     tw = tmps[j - 1]  # can be nil
  #     te = tmps[j]
  #     break
  #   end
  # end
  j = tmps.bsearch_index { |t| x_i < t }
  if j
     tw = tmps[j - 1]  # can be nil
     te = tmps[j]
  end
  if te == nil
    tw = tmps[-1]
  elsif te == tmps[0]
    tw = nil
  end

  if debugFlag
    p x_i
    print "sw:"  
    p sw
    print "se:"    
    p se
    print "tw:"      
    p tw
    print "te:"        
    p te
  end

  cur = x_i
  costs = []
  [te, tw].each do |t|
    tmp_cost = 0
    next if t == nil
    tmp_cost += (cur - t).abs
    [se, sw].each do |s|
      next if s == nil
      costs << (t - s).abs + tmp_cost
    end
  end
  if te != nil and se != nil and te >= se
    costs << (cur - te).abs
  end
  if tw != nil and sw != nil and tw <= sw
    costs << (cur - tw).abs
  end

  cur = x_i
  [se, sw].each do |s|
    tmp_cost = 0
    next if s == nil
    tmp_cost += (cur - s).abs
    [te, tw].each do |t|
      next if t == nil
      costs << (s - t).abs + tmp_cost
    end
  end
  if te != nil and se != nil and se >= te
    costs << (cur - se).abs
  end
  if sw != nil and tw != nil and sw <= tw
    costs << (cur - sw).abs
  end
  #p costs
  #print "---"
  p costs.min
end


Measured memory_bytes: 5940
using System;

class MainClass {
    static void Main() {
        int ans = 0;
        int n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++) {
            int a = int.Parse(s[i]);
            while (a % 2 == 0) {
                a /= 2;
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11744
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string s;
    cin >> s;
    int n = s.length();
    s += "R";
    int l;
    int r;
    int now=0;
    int a[n];
    fr(i,n){
      a[i]=0;
    }
	fr(i,n){
      if(s[i]=='R'&&s[i+1]=='L'){
        r=i-now+1;
      }
      if((s[i]=='L'&&s[i+1]=='R')){
        l=i-now-r+1;
        a[r+now-1]=r/2+l/2+r%2;
        a[r+now]=r/2+l/2+l%2;
        now=i+1;
      }
    }
    fr(i,n){
      cout << a[i] <<" ";
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(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 INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> D;
    REP(i, N) {
        cin >> X >> Y;
        if (X * X + Y * Y <= D * D)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]
s = input()
ac_list = []
ac_number = 0
for i in range(n - 1):
    if s[i : i+2] == "AC":
        ac_number += 1
    ac_list.append(ac_number)
ac_list.append(0)
for i in range(q):
    lr = list(map(int, input().split()))
    l = lr[0]
    r = lr[1]
    print(ac_list[r - 2] - ac_list[l - 2])


Measured memory_bytes: 6120
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int main()
{
    int n;
    double k, res = 0.0;
    cin >> n >> k;

    for (int i = 1; i <= n; i++)
    {
        int ct = 0;
        double score = (double)i, p = 1;
        while (score < k)
        {
            p = p / 2.0;
            score = score * 2.0;
        }

        res += (1.0 / (double)n) * p;
    }

    printf("%.16f", res);
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace NIKKEI2019D
{
    public class Node
    {
        public int Index;
        public List<int> Parents = new List<int>();
        public List<int> Children = new List<int>();
    }

    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var M = ss.Next(int.Parse);

            var nodes = new Node[N + 1];
            for (var i = 1; i <= N; i++)
            {
                nodes[i] = new Node {Index = i};
            }

            for (var i = 0; i < N + M - 1; i++)
            {
                var A = ss.Next(int.Parse);
                var B = ss.Next(int.Parse);
                nodes[A].Children.Add(B);
                nodes[B].Parents.Add(A);
            }

            var que = new Queue<Node>();
            que.Enqueue(nodes.Skip(1).Single(node => node.Parents.Count == 0));

            while (que.Count > 0)
            {
                var node = que.Dequeue();
                foreach (var child in node.Children.Select(i => nodes[i]))
                {
                    if (child.Parents.Count > 1) child.Parents.Remove(node.Index);
                    else que.Enqueue(child);
                }
            }

            foreach (var node in nodes.Skip(1))
            {
                sw.WriteLine(node.Parents.SingleOrDefault());
            }
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 38576
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;
constexpr ll MOD = 1e9+7;

int main(void) {
    ll N;
    cin >> N;
    vector <int>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll s = 0;
    ll x = 0;
    for (int i = N-2; i >= 0 ; i--) {
        // s += A[i+1];
        s = (s + A[i+1]) % MOD;
        // x = x + s * A[i];
        x = (x + ((s * A[i]) % MOD)) % MOD;
    }
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 3676
#include<stdio.h>
#include<string.h>
#define N 100000000 
 
char c[14];
int x[N];
int n;
  
int a(void);
int b(char);
void insert(void);
int find(void);
  
int main(){
char str[7];
int i;
  
 scanf("%d",&n);
 for(i=0;i<n;i++){
   scanf("%s%s",str,c);
   if(str[0]=='i'){
     insert();
   }
   else if(str[0]=='f'){
     if(find())printf("yes\n");
     else printf("no\n");
   }
 } 
 return 0;
}
 
int a(void){
  int x=0,i,p=1;
  for(i=0;i<strlen(c);i++){
    x+=p*(b(c[i]));
    p*=5;
  }
  return x;
}
  
int b(char c){
  
  if(c=='A'){
    return 1;
  }
  else if(c=='C'){
    return 2;
  }
  else if(c=='G'){
    return 3;
  }
  else return 4;
  
}
 
void insert(){
  x[a()]=1;
}
int find(){
    int key =a();
      
    if(x[key]){
   return 1;
    }
    else return 0;
} 

Measured memory_bytes: 38628
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    cs
    int n,a,b,c;cin>>n;
    vector<int> v(3);
    vector<string> ins(n);
    vector<char> ans(n);
    for(auto &i:v) cin>>i;
    for(auto &i:ins) cin>>i;
    repp(i,0,n-1) {
        int t=ins[i][0]-'A',tt=ins[i][1]-'A';
        if(v[t]==0&&v[tt]==0) bye("No")
        if((v[t]>v[tt])||
        (v[t]==v[tt]&&i!=n-1&&(ins[i][1]==ins[i+1][0]
        ||ins[i][1]==ins[i+1][1]))) swap(t,tt);
        v[t]++;v[tt]--;
        ans[i]=char(t+'A');
    }
    cout<<"Yes\n";
    for(auto i:ans) cout<<i<<'\n';
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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


int h,w;
string s[50];
int cnt[50][50];

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

	cin>>h>>w;
	REP(i,h) {
		cin>>s[i];
	}
	REP(i,h) {
		REP(j,w) {
			if(s[i][j]=='#') continue;
			FOR(x,-1,2) {
				FOR(y,-1,2) {
					int nx=j+x,ny=i+y;
					if(nx<0||ny<0||nx>=w||ny>=h) continue;
					if(s[ny][nx]=='#') cnt[i][j]++;
				}
			}
		}
	}
	REP(i,h) {
		REP(j,w) {
			if(s[i][j]=='#') cout<<'#'<<flush;
			else cout<<cnt[i][j]<<flush;
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, m, a[N];
char s[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%s",s + 1);
	n = strlen(s + 1);
	if(s[n] == '1' or s[1] == '0'){
		puts("-1");
		return 0;
	}
	for(int i = 1; i <= n - 1; i++)
		if(s[i] != s[n - i]){
			puts("-1");
			return 0;
		}
	for(int i = 1; i <= n; i++)
		if(s[i] == '1')
			a[++m] = i;
	a[++m] = n;
	// for(int i = 1; i < m; i++)
	// 	printf("%d %d\n", a[i], a[i + 1]);
	// for(int i = 1; i <= m; i++)
	// 	cout << a[i] << " ";
	for(int i = 2; i <= m; i++)
		for(int j = a[i - 1]; j < a[i]; j++)
			printf("%d %d\n", a[i], j);
	return 0;
}

Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,p,k,now,A[N],B[N],Ans[N];
long long n; 
int main()
{
	scanf("%lld",&n); n++; 
	for (;n;n>>=1) A[++A[0]]=n&1;
	for (i=1;i<A[0];++i) B[i]=i; now=A[0]-1;
	for (i=1;i<A[0];++i) if(A[i]) ++now;
	int gg=now;
	for (i=1;i<A[0];++i)
	{
			if (A[i]) Ans[++Ans[0]]=now--;
			Ans[++Ans[0]]=B[i];
	}
	for (i=1;i<=gg;++i) Ans[++Ans[0]]=i;
	printf("%d\n",Ans[0]);
	for (i=1;i<=Ans[0];++i) printf("%d ",Ans[i]); 
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int main(){

	int N, M, X, Y;
	int mx = -100, my = 100;

	cin >> N >> M >> X >> Y;

	for(int i = 0; i < N; i++){
		int x;
		cin >> x;
		if( x >= mx) mx = x;
	}

	for(int i = 0; i < M; i++){
		int y;
		cin >> y;
		if( y <= my) my = y;
	}

	if( mx < my && mx < Y && X < my){
		cout << "No War" << endl;
	} else {
		cout << "War" << endl;
	}
		
	return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 + 7;
const int M = 100 * 1000 + 13;

int n, w;
pt a[N];

bool read () {
	if (scanf("%d%d", &n, &w) != 2)
		return false;
	forn(i, n)
		scanf("%d%d", &a[i].x, &a[i].y);
	return true;
}

li dp[2][M];

void solve() {	
	int tot = 0;
	forn(i, n) tot += a[i].y;
	
	forn(i, 2) forn(j, tot + 1) dp[i][j] = INF64;
	dp[0][0] = 0;
	forn(ii, n){
		int i = ii & 1;
		int ni = i ^ 1;
		forn(j, tot + 1)
			dp[ni][j] = INF64;
		forn(j, tot + 1){
			dp[ni][j] = min(dp[ni][j], dp[i][j]);
			if (j + a[ii].y <= tot)
				dp[ni][j + a[ii].y] = min(dp[ni][j + a[ii].y], dp[i][j] + a[ii].x);
		}
	}
	
	int ans = 0;
	forn(i, tot + 1) if (dp[n & 1][i] <= w)
		ans = i;
	
	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
///////////////////////___combination___////////////////////
vector<ll> fac, finv, inv;
void COMinit(const int MAX = 5000000, const ll &MOD = MOD){
  fac.resize(MAX);finv.resize(MAX);inv.resize(MAX);
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  repd(i,2,MAX){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
ll COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

int n,k,ans,a[110000];
signed main(){
  cin>>n>>k;rep(i,n)cin>>a[i];
  int o;
  rep(i,n)if(a[i] == 1)o = i;
  int x = 1, ans = 0;
  while(x < n)x += (k-1), ans++;
  cout << ans << endl;
}



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

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

    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<long long> abs_a = a;

    for (int i = 0; i < n; i++) {
        if (abs_a[i] < 0) {
            abs_a[i] = -abs_a[i];
        }
    }

    long long ans = 0;
    long long min = abs_a[0];
    for (auto e : abs_a) {
        ans += e;
        if (min > e) {
            min = e;
        }
    }
    int num_negative = 0;
    for (auto e : a) {
        if (e < 0) {
            num_negative++;
        }
    }

    if (num_negative % 2) {
        ans -= min * 2;
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1792