akhauriyash/Code-Regression huggingface dataset:
import sys

dish_list = [input() for i in range(5)]
ans = 0

for i in range(len(dish_list)):
    if int(dish_list[i][-1]) == 0:
        dish_list.insert(0, dish_list[i])
        del dish_list[i+1]
        continue
    for j in range(len(dish_list) - 1):
        if int(dish_list[j][-1]) < int(dish_list[j+1][-1]):
            dish_list[j], dish_list[j+1] = dish_list[j+1], dish_list[j]

#print(dish_list)

for i in range(len(dish_list)):
    tmp = int(dish_list[i])
    if i == len(dish_list) - 1 or tmp % 10 == 0:
        ans += tmp
    else:
        ans += tmp
        ans += 10 - tmp % 10

print(ans)


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

int main()
{
  long N;
  cin >> N;
  int count0=0,count1=0,count2=0;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a%4==0) count2++;
    else if(a%2==0) count1++;
    else count0++;
  }
  
  if(count0 <= count2) cout << "Yes" << endl ;
  else if((count0 == 1+count2) && count1 == 0) cout << "Yes" << endl ;
  else cout << "No" << endl ;
  
  return 0;
}

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

using namespace std;

int main(){
 vector<vector<char>> c(3,vector<char>(3));
  
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  
  cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string S;
	cin >>S;
	long W=0;
	long SS=0;
	for (int i=0; i<S.size(); i++) {
		if ('B'==S.at(i))
			W++;
		else
			SS+=W;
	}
	cout <<SS <<endl;
	return 0;
}



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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h), red(h), blue(h);
    for(int i=0;i<h;i++) cin >> s[i];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            red[i].push_back(((i%2==0 && j!=w-1) || j==0 ? '#' : '.'));
            blue[i].push_back(((i%2==1 && j!=0) || j==w-1 ? '#' : '.'));
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                red[i][j] = '#';
                blue[i][j] = '#';
            }
        }
    }
    for(int i=0;i<h;i++) cout << red[i] << endl;
    cout << endl;
    for(int i=0;i<h;i++) cout << blue[i] << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;

int main() {
  map<int, bool> n;
  
  for (int i = 0; i < 4; i++) {
    int a;
    cin >> a;
    n[a] = true;
  }

  if (n[1] && n[9] && n[7] && n[4]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
S = list(input())
S1 = int(S[0] + S[1])
S2 = int(S[2] + S[3])
if S1>12 and S2>12:
    print("NA")
elif  S1 == 0 or S2 == 0:
    if 1 <= S2 <= 12:
        print("YYMM")
    elif 1<= S1 <= 12:
        print("MMYY")
    else:
        print("NA")
elif S2 <= 12 and S1 <= 12:
    print("AMBIGUOUS")
elif S2 <= 12:
    print("YYMM")
else:
    print("MMYY")


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int n;
    int i, j, k;
    int b, f, r, v;
    int house[4][3][10] = {0};

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        house[b-1][f-1][r-1] += v;
    }
    for(i = 0; i < 4; i++){
        for(j = 0; j < 3; j++){
            for(k = 0; k < 10; k++){
                printf(" %d", house[i][j][k]);
            }
            puts("");
        }
        if(i != 3)
        puts("####################");
    }
    return 0;
}

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

using namespace std;

const int N = 105;

int a[N];

int main() {
    int n;
    cin >> n;
    n += n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    int ans = 0;
    for (int i = n-2; i >= 0; i-=2) ans += a[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
fld = [list(map(int, input().split())) for _ in range(h)]

ans = []
for i in range(h):
    for j in range(w):
        if fld[i][j] % 2 == 0:
            continue

        if j < w-1:
            if fld[i][j+1] % 2 == 1:
                ans.append((i+1, j+1, i+1, j+2))
                fld[i][j] -= 1
                fld[i][j+1] += 1
                continue

        if i < h-1:
            if fld[i+1][j] % 2 == 1:
                ans.append((i+1, j+1, i+2, j+1))
                fld[i][j] -= 1
                fld[i+1][j] += 1
                continue

        if j < w-1:
            ans.append((i+1, j+1, i+1, j+2))
            fld[i][j] -= 1
            fld[i][j+1] += 1
            continue

        if i < h-1:
            ans.append((i+1, j+1, i+2, j+1))
            fld[i][j] -= 1
            fld[i+1][j] += 1
            continue


print(len(ans))
for row in ans:
    print(*row)


Measured memory_bytes: 26568
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,m;
  cin >>n >> m;
  vec a(n),b(m);
  for(ll i=0;i<n;i++)cin >> a[i];
  for(ll i=0;i<m;i++)cin >> b[i];

  vector<ll> c=convolution<998244353>(a,b);

  for(ll i=0;i<c.size();i++)cout << c[i] << endl;

}

Measured memory_bytes: 27240
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;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>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int D, T, S;
    cin >> D >> T >> S;
    cout << (S * T >= D ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3596
N, M = gets.split.map(&:to_i)
hash = Hash.new{|h , k| h[k] = []}
M.times do
  l = gets.split
  p = l[0].to_i
  s = l[1]
  if hash[p].last == 'AC'
    next
  else
    hash[p] << s
  end
end

a = 0
pe = 0
hash.each do |h, k|
  if k.last == 'AC'
    a += 1
    pe += k.size - 1
  end
end

puts "#{a} #{pe}"

Measured memory_bytes: 20604
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int a, int b, int c){
    int result;
    int init = a<b?(a<c?a:c):(b<c?b:c);
    for(int i = init; i >= 1; i--){
            if(a%i == 0 && b%i == 0 && c%i == 0){
                result = i;
                break;
            }
    }
    return result;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int k;
    int sum = 0;
    cin >> k;
 
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++)
            for(int l=1;l<=k;l++)
                sum += gcd(i, j, l);

    cout << sum << '\n';
 
    return 0;
}

Measured memory_bytes: 3640
import math


def koch(n, p1x, p1y, p2x, p2y):
    if n == 0:
        return

    sx = (2*p1x + 1*p2x)/3
    sy = (2*p1y + 1*p2y)/3
    tx = (1*p1x + 2*p2x)/3
    ty = (1*p1y + 2*p2y)/3
    theta = math.pi/3
    ux = math.cos(theta)*(tx-sx) - math.sin(theta)*(ty-sy) + sx
    uy = math.sin(theta)*(tx-sx) + math.cos(theta)*(ty-sy) + sy

    koch(n-1, p1x, p1y, sx, sy)
    print("{:.5f} {:.5f}".format(sx, sy))
    koch(n-1, sx, sy, ux, uy)
    print("{:.5f} {:.5f}".format(ux, uy))
    koch(n-1, ux, uy, tx, ty)
    print("{:.5f} {:.5f}".format(tx, ty))
    koch(n-1, tx, ty, p2x, p2y)

n = int(input())

p1x, p1y = 0.0, 0.0
p2x, p2y = 100.0, 0.0

print("{:.5f} {:.5f}".format(p1x, p1y))
koch(n, p1x, p1y, p2x, p2y)
print("{:.5f} {:.5f}".format(p2x, p2y))

Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[5];
ll ans;
int main(){
    cin >> n;
    for(int i = 0; i < 5; ++i){
        cin >> a[i];
    }
    sort(a,a+5);
    
    if(a[0] == 1){
        ans = n - 1 + 5;
    }else if(n == a[0]){
        ans = 5;
    }else{
        ans = n / a[0] + 5;
    }
    cout << ans << endl;
    
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		array<int, 3> edge;
		for (int i = 0; i < 3; i++){
			cin >> edge[i];
		}
		sort(edge.begin(), edge.end());
		if (pow(edge[0], 2) + pow(edge[1], 2) == pow(edge[2], 2)){
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
from bisect import bisect_right
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[0]*(n+1)
sb=[0]*(m+1)
for i in range(1,n+1):
    sa[i]=sa[i-1]+a[i-1]
for j in range(1,m+1):
    sb[j]=sb[j-1]+b[j-1]
ans=0
for x in range(n+1):
    if k-sa[x]>=0:
        k2=k-sa[x]
        l=bisect_right(sb,k2)-1
        if x+l>ans:
            ans=x+l
for y in range(m+1):
    if k-sb[y]>=0:
        k2=k-sb[y]
        l=bisect_right(sa,k2)-1
        if y+l>ans:
            ans=y+l
print(ans)


Measured memory_bytes: 110824
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
c = collections.Counter(prime_factorize(int(input())))
# c = prime_factorize(int(input()))
a = 0
# print(c)
for i in c.values():
    # print(i)
    x = 1
    while i > 0:
        i -= x
        a += 1
        x += 1
        # print(i,x,a)
        if i < 0 :
            a -= 1

# a,z = 0,0
# for i in c:
#     if z == i :
#         z = 0
#     else :
#         z = i
#         a += 1
print(a)

Measured memory_bytes: 9468
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

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;
}

#define MOD 1000000007


long long n, s;
long long best_b;

void test(long long b)
{
	if (b <= 1)
		return;
	long long tmp_sum = 0;
	long long tmp = n;
	while (tmp > 0)
	{
		tmp_sum += tmp % b;
		tmp /= b;
	}

	if (tmp_sum == s)
		best_b = min(best_b, b);
}

int main() {

#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n >> s;

	best_b = 1e15;
	test(n + 1);

	for (long long x = 1; x * x < (n - s); x++)
	{
		if ((n - s) % x != 0)
			continue;
		long long y = (n - s) / x;
		test(x);
		test(x + 1);
		test(y);
		test(y + 1);
	}

	test(n - s);
	test(n - s + 1);
	test(n);
	test(s);
	test(n + 1);
	test(s + 1);

	for (long long i = 2; i <= min(best_b, 1000000LL); i++)
	{
		test(i);
	}

	if (best_b >= 1e14)
	{
		cout << "-1";
	}
	else
		cout << best_b;

	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll n, a, b, c, d, e; read(n, a, b, c, d, e);
	ll g = min({a, b, c, d, e});

	write((n + g - 1) / g + 4);
}


Measured memory_bytes: 256
import re
import sys
import itertools

if __name__ == '__main__':
    N = input()
    S = list()
    c = 0
    d = {'M':0,'A':0,'R':0,'C':0,'H':0}
    for i in xrange(N):
        a = raw_input()[0]
        if a in d.keys():
            d[a] += 1
    if d['M'] > 0 and d['A'] > 0 and d['R'] > 0:
        c += d['M']*d['A']*d['R']
    if d['M'] > 0 and d['A'] > 0 and d['C'] > 0:
        c += d['M']*d['A']*d['C']
    if d['M'] > 0 and d['A'] > 0 and d['H'] > 0:
        c += d['M']*d['A']*d['H']
    if d['M'] > 0 and d['R'] > 0 and d['C'] > 0:
        c += d['M']*d['R']*d['C']
    if d['M'] > 0 and d['R'] > 0 and d['H'] > 0:
        c += d['M']*d['R']*d['H']
    if d['M'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['M']*d['C']*d['H']
    if d['A'] > 0 and d['R'] > 0 and d['C'] > 0:
        c += d['A']*d['R']*d['C']
    if d['A'] > 0 and d['R'] > 0 and d['H'] > 0:
        c += d['A']*d['R']*d['H']
    if d['A'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['A']*d['C']*d['H']
    if d['R'] > 0 and d['C'] > 0 and d['H'] > 0:
        c += d['R']*d['C']*d['H']
    print c


Measured memory_bytes: 2876
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int h, w;
    String[][] map;
    boolean[][] visit;
    int y, x;

    void run(){
	while(sc.hasNext()){
	    h = sc.nextInt();
	    w = sc.nextInt();
	    if(h==0 && w==0) break;

	    map = new String[h][w];
	    visit = new boolean[h][w];

	    for(int i=0; i<h; i++){
		String s = sc.next();
		for(int k=0; k<w; k++)
		    map[i][k] = s.substring(k, k+1);
	    }

	    x = 0; y = 0;
	    visit[0][0] = true;
	    boolean con = true;

	    while(!map[y][x].equals(".") && con){
		visit[y][x] = true;
		if(map[y][x].equals(">"))  x++;
		else if(map[y][x].equals("v")) y++;
		else if(map[y][x].equals("^")) y--;
		else x--;

		if(visit[y][x]) con = false;
	    }

	    System.out.println(!con ? "LOOP":(x+" "+y));
	}
    }
}

Measured memory_bytes: 24820
#include<iostream>
using namespace std;
int main()
{
	long long a, b, k;
	cin >> a >> b >> k;
	
	if (a > k)
	{
		cout << (a - k) <<" "<< b;
	}
	else if ((a + b) > k)
	{
		cout << 0 <<" "<< b - (k - a) ;
	}
	else
		cout << 0 <<" "<< 0 ;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	int ans=0,x=0,y=0;
	cin>>s;
	for(int i=0; i<s.size(); i++) {
		if (x==y) {
			x++;
			if(s[i]=='p')ans--;
		} else {
			y++;
			if(s[i]=='g')ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
/******Old_school_@23******/
/******Why_would_a_compiler_lie?******/
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma") 
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back 
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1000005
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}
vector<lld> sv;
void sieve(lld N) {
        bool isPrime[N+1];
       itr(i,3,N){
if(i%2!=0)
isPrime[i]=true;
else
isPrime[i]=false;
}
        isPrime[0] = false;
        isPrime[1] = false;
        isPrime[2]=true;  
      for(lld i = 2; i <= N;i++) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(lld j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
        
   iot(N) if(isPrime[i]) sv.pb(i);
} 

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
    sieve(tod);        
    lld n; cin>>n;
    pls(n,a);
    lld hash[tod]={0};
    lld fg=1;
    iot(n) {hash[a[i]]++; if(hash[a[i]]>1&&a[i]!=1) {fg=-1; break;}}
    if(fg==-1){
       lld g=a[0];
    iot(n) g=__gcd(g,a[i]);
    if(g==1)  cout<<"setwise coprime";
    else  cout<<"not coprime";
    return 0;
    }
    for(auto &i:sv){
        lld cc=0;
        lld p=i;
        while(p<tod){
            if(hash[p])  cc++;
            
            p+=i;
            if(cc>1) break;
        }
        if(cc>1) {fg=-1; break;}
    }
    if(fg==1){
        cout<<"pairwise coprime";
        return 0;
    }
    lld g=a[0];
    iot(n) g=__gcd(g,a[i]);
    if(g==1)  cout<<"setwise coprime";
    else  cout<<"not coprime";
    
}



Measured memory_bytes: 19412
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(lcm(sc.nextInt(), sc.nextInt()));
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        if(a < b) return gcd(b, a);
        if(b == 0) return a;
        return gcd(b, a % b);
    }
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int range = 2 * d + 1;
    cout << (n + range - 1) / range << ln;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int a, b;

int main(){
    scanf("%d%d", &a, &b);

    int p = a + b;
    int q = a - b;
    int r = a * b;

    int m = max(p, q);
    m = max(m, r);

    printf("%d", m);

	return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        /// <summary>
        /// プログラムのエントリポイント
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            int[] val = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            // 駒番号と現在位置を
            Dictionary<int, int> field = new Dictionary<int, int>();
            for (int i = 1; i <= count; i++)
                field.Add(i, val[i - 1]);

            Console.ReadLine();
            foreach(var v in Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse))
            {
                if (!field.ContainsValue(field[v] + 1) && field[v] < 2019)
                    field[v]++;
            }

            foreach (var v in field.Values)
                Console.WriteLine(v);
        }
    }
}


Measured memory_bytes: 19836
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

int main() {
    int N, M; cin >> N >> M;
    set<PII> Q;
    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        Q.insert(PII(b, a));
    }
    
    int cuted = 0;
    int ans = 0;
    for(auto q:Q){
        if(cuted <= q.second){
            ans++;
            cuted = q.first;
        }
    }
    
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 4992
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, k) = in.readLine().split("\\s+").map(_.toInt)
    val MOD = 1000000000L + 7

    var sum = 0L

    for(i <- k to (n + 1)) {
      val min = 1L * (i - 1) * i / 2L
      val max = 1L * (n + (n - i + 1)) * i / 2L
      sum = (sum + (max - min + 1)) % MOD
    }

    out.println(sum)

    out.flush()
  }
}


Measured memory_bytes: 54776
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	long long a[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	if(k>n){
		cout<<0;
		return 0;
	}
	long long ans=0;
	sort(a,a+n);
	for(int i=n-k-1;i>=0;--i){
		ans+=a[i];		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pair pair<int,int>
#define ll long long

int main(){
	int n,g;cin >> n >> g;
	vector<pair> a(n);
	for(int i=0;i<n;++i) cin >> a.at(i).first >> a.at(i).second;
	int ans=1000000000;
	for(int i=0;i<(1<<n);++i){
		int sum=0,cnt=0;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				sum+=a.at(j).first*(j+1)*100 + a.at(j).second;
				cnt+=a.at(j).first;
			}
		}
		for(int j=n-1;j>=0;--j){
			if(sum>=g) break;
			if((i>>j)&1) continue;
			for(int k=1;k<=a.at(j).first;++k){
				if(sum>=g) break;
				sum+=(j+1)*100;
				cnt++;
				if(k==a.at(j).first) sum+=a.at(j).second;
			}
		}
		ans=min(ans,cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
list_size = 1001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size-1):
	f_list[i+1] = (f_list[i] * (i+1)) % MOD

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(list_size-2, -1, -1):
	f_r_list[i] = (f_r_list[i+1] * (i+1)) % MOD

def comb(n, r):
	if n < r or r < 0:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (f_list[n] * f_r_list[n-r] * f_r_list[r]) % MOD 

n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [[0 for _ in range(n+1)] for _ in range(k+1)]
dp[0][0] = f_list[n]
for i in range(1, k+1):
	for j in range(n+1):
		for x in range(j+1):
			dp[i][j] += dp[i-1][j-x] * comb(n-x, a[i-1]-x) * f_r_list[x]
			dp[i][j] %= MOD

print(dp[k][n])

Measured memory_bytes: 46908
s = input()

n = len(s)
half = (n-1)//2
flag = True
l = 0
r = n - 1
while l <= r:
  if s[l] != s[r]:
    flag = False
    break
  l += 1
  r -= 1
  
l = 0
r = half - 1
while l <= r:
  if s[l] != s[r]:
    flag = False
    break
  l += 1
  r -= 1

l = half + 1
r = n - 1
while l <= r:
  if s[l] != s[r]:
    flag = False
    break
  l += 1
  r -= 1
  
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38384
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = LI2()
print('Yes' if sum(N) % 9 == 0 else 'No')


Measured memory_bytes: 76164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=998244353;

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double ar[n];
    double pro=1.0;
    for(int i=0;i<n;i++){cin>>ar[i];pro*=ar[i];}
    double deno=0.0;
    for(int i=0;i<n;i++){
        double pro1=1.0;
        for(int j=0;j<n;j++){
            if(j==i)continue;
            pro1*=ar[j];
        }
        deno+=pro1;
    }
    deno=pro/deno;
    cout << std::fixed;
	cout<<std::setprecision(6)<<deno<<endl;
    return 0;
}


Measured memory_bytes: 256
program main
implicit none
character(100) ::S
integer :: count = 0
integer :: n

read *,S
n = len_trim(S)

if(S(1:1)=="k")      count = count + 1
if(S(1:2)=="ke")     count = count + 1
if(S(1:3)=="key")    count = count + 1
if(S(1:4)=="keye")   count = count + 1
if(S(1:5)=="keyen")  count = count + 1
if(S(1:6)=="keyenc") count = count + 1
if(S(1:7)=="keyence")count = count + 1

if(S(n-0:n)==      "e")count = count + 1
if(S(n-1:n)==     "ce")count = count + 1
if(S(n-2:n)==    "nce")count = count + 1
if(S(n-3:n)==   "ence")count = count + 1
if(S(n-4:n)==  "yence")count = count + 1
if(S(n-5:n)== "eyence")count = count + 1
if(S(n-6:n)=="keyence")count = count + 1

if ( count > 6 ) then
print *, "YES"
else
print *, "NO"
end if

end program main

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

ll gcd(ll a, ll b);

int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N, M;
	cin >> N >> M;

	string S, T;
	cin >> S >> T;

	if (S[0] != T[0]) {
		cout << -1;
		return 0;
	}

	ll L = gcd(M, N);
	L *= (N / L) * (M / L);
	for (ll i = 0; i < L; i+= L/min(N, M)) {

		if ( i % (L / N) == 0 && i % (L/ M)==0 && S[i / (L / N)] != T[i / (L / M)]) {
			cout << -1;
			return 0;
		}
	}



	cout << L;

}

ll gcd(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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

int main() {
    int n, fir = 0, sec = 0;
    int max_count = 0;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        fir = std::max(fir, a[i]);
    }
    for (int i = 0; i < n; i++) {
        if (fir == a[i]) max_count++;
        else sec = std::max(sec, a[i]);
    }
    if (max_count > 1) {
        for (int i = 0; i < n; i++) 
            std::cout << fir << std::endl;
    } else {
        for (int i = 0; i < n; i++) {
            if (fir != a[i]) {
                std::cout << fir << std::endl;
            } else {
                std::cout << sec << std::endl;
            }
        }
    }
}

Measured memory_bytes: 2432
def inpl(): return list(map(int, input().split()))

N, C, K = inpl()
T = sorted([int(input()) for _ in range(N)])

B = []
ans = 0
for i in range(N):
    t = T[i]
    if len(B) == 0:
        B.append(t)
    elif t <= B[0] + K:
        B.append(t)
    else:
        B = [t]
        ans +=1
    
    if len(B) == C:
        B = []
        ans += 1

ans += len(B) > 0

print(ans)

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

#define ll long long
struct node {
	ll a, b, c;
};

node point[100005], dp[100005];
ll n;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> point[i].a >> point[i].b >> point[i].c;
	}

	dp[0].a = point[0].a;
	dp[0].b = point[0].b;
	dp[0].c = point[0].c;

	for (ll i = 1; i < n; i++) {
		dp[i].a = max(dp[i - 1].b, dp[i - 1].c) + point[i].a;
		dp[i].b = max(dp[i - 1].a, dp[i - 1].c) + point[i].b;
		dp[i].c = max(dp[i - 1].a, dp[i - 1].b) + point[i].c;
	}

	cout << max( max (dp[n - 1].a, dp[n - 1].b), dp[n - 1].c);
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(){
  int a,b,k;
  scanf("%d %d %d",&a,&b,&k);

  int i;
  for(i = a;i <= b;i++){
    if(i <= a+k-1 || b-k < i){
      printf("%d\n",i);
    }
  }
  return(0);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		for (int i = 0; i < n; i++) {
			w[i] = sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n - 1; i++) {
			int sum1 = 0;
			for (int j = 0; j <= i; j++) {
				sum1 += w[j];
			}
			int sum2 = 0;
			for (int j = i + 1; j < n; j++) {
				sum2 += w[j];
			}
			if (Math.abs(sum1 - sum2) < min) {
				min = Math.abs(sum1 - sum2);
			}
		}
		System.out.println(min);
	}
}


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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=998244353; //1000000007
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int n;
ld memo[305][305][305];

ld dp(int a,int b,int c){
	//printf("%d %d %d\n",a,b,c);
	if(a==0&&b==0&&c==0)return 0;
	if(memo[a][b][c])return memo[a][b][c];
	if(a>=305||b>=305||c>=305||a<0||b<0||c<0)return 0;
	ld res=0;
	if(a)res+=dp(a-1,b,c)*(ld)(a)/(ld)(a+b+c);
	if(b)res+=dp(a+1,b-1,c)*(ld)(b)/(ld)(a+b+c);
	if(c)res+=dp(a,b+1,c-1)*(ld)(c)/(ld)(a+b+c);
	return memo[a][b][c]=res+(ld)(n)/(ld)(a+b+c);
}

int main(){
	scanf("%d",&n);
	int arr[n];
	for(int i=0;i<n;i++)scanf("%d",&arr[i]);
	int c[4];memset(c,0,sizeof(c));
	for(int i=0;i<n;i++){
		c[arr[i]]++;
	}
	printf("%.12Lf",dp(c[1],c[2],c[3]));
}


Measured memory_bytes: 436480
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<pair<ll, ll>>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N, H, a_max = 0, atk = 0; cin >> N >> H;
  vector<pair<ll, ll>> sword(N);
  rep(i, 0, N) {
  	ll a, b; cin >> a >> b;
    sword[i] = make_pair(b, a);
    if (a_max < a) a_max = a;
  }
  rvsort(sword);
  rep(i, 0, N) {
  	if (sword[i].first > a_max) {
    	H -= sword[i].first;
      	atk++;
      	if (H <= 0) {
        	cout << atk << endl;
          return 0;
        }
    }
  }
  atk += H / a_max;
  if (H % a_max) atk++;
  cout << atk << endl;
}

Measured memory_bytes: 1792
#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define ri(x) i64 x; cin >> x
#define rii(x, y) i64 x, y; cin >> x >> y
#define ri3(x, y, z) i64 x, y, z; cin >> x >> y >> z
#define ri4(x, y, z, u) i64 x, y, z, u; cin >> x >> y >> z >> u
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x
#define rx(x, t) t x; cin >> x

#define ws(x) cout << x << ' '
#define wl(x) cout << x << '\n'
#define wln cout << '\n'

#define dbg(x) cerr << '[' << #x << "]: " << x << '\n'

#define fa(x, v) for (auto &x : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(x) ri(_x); fi(x, _x)

#define l first
#define r second
#define all(x) x.begin(), x.end()
#define bit(x) ((u64) 1 << (u32) (x))

using namespace std;

typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t i32;
typedef int64_t i64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) ws(x);
    wln;
    return out;
}


int main() {
    fio;

    ri(n);
    rvi(a, n);
    i64 total = 1000;
    fp(i, n) {
        if (a[i] > a[i - 1]) {
            total += (a[i] - a[i - 1]) * (total / a[i - 1]);
        }
    }
    wl(total);

    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
int a[200010];
long n,i,k,j,l,c,d;
int main(){
  scanf("%ld",&n);
  k=0;
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);}
c=n%2; d=n/2;
  //printf("%d\n",c);
  if (c==1){
    for(i=d+1;i>=1;i--){printf("%d ",a[i*2-1]);}
    for(i=1;i<=d;i++){printf("%d ",a[i*2]);
  }}
  else if (c==0){
    for(i=d;i>=1;i--){printf("%d ",a[i*2]);}
    for(i=1;i<=d;i++){printf("%d ",a[i*2-1]);
  }
  }
}




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

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

	string ans;
	if (0 < s / 100 && s / 100 < 13 && 0 < s % 100 && s % 100 < 13) {
		ans = "AMBIGUOUS";
	} else if (0 < s % 100 && s % 100 < 13) {
		ans = "YYMM";
	} else if (0 < s / 100 && s / 100 < 13) {
		ans = "MMYY";
	} else {
		ans = "NA";
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, L;
int dp[1 << 16][2];

signed main() {
    while(cin >> N, N) {
        memset(dp, -1, sizeof(dp));
        dp[0][0] = 0;

        int ans = 0;
        rep(p,0,N) {
            int mo = p%2, info = 0;
            cin >> M >> L;
            rep(i,0,M) {
                int S, E; cin >> S >> E;
                S -= 6, E -= 6;

                int val = 0;
                rep(j,S,E) val += (1 << j);
                info += val;
            }

            rep(bit,0,1<<16) {
                chmax(dp[bit][mo^1], dp[bit][mo]);
                if(bit & info) continue;
                if(dp[bit][mo] == -1) continue;
                chmax(dp[bit | info][mo^1], dp[bit][mo] + L);
                dp[bit][mo] = -1;
            }
        }
        rep(i,0,1<<16) {
            if(dp[i][N%2] != -1) {
                // printf("value of %lld: %lld\n", i, dp[i][N%2]);
                chmax(ans, dp[i][N%2]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> d(n-1);
    for(int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int root1 = abs(j - i);
            int root2 = abs(i - x) + 1 + abs(y - j);
            int root3 = abs(i - y) + 1 + abs(x - j);
            int di = min({root1, root2, root3});
            d[di-1] += 1;
        }
    }

    rep(i, d.size()) cout << d[i] << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
S = ["."*(W+2)]+["."+input()+"." for _ in range(H)]+["."*(W+2)]
dx = [0, -1, -1, -1, 0, 1, 1 ,1]
dy = [1, 1, 0, -1, -1, -1, 0, 1]

ans = [[""]*W for _ in range(H)]

for i in range(1, H+1):
	for j in range(1, W+1):
		if S[i][j] == "#":
			ans[i-1][j-1] = "#"
			continue
		cnt = 0
		for k in range(8):
			ny = i+dy[k]
			nx = j+dx[k]
			if S[ny][nx] == "#":
				cnt += 1
		ans[i-1][j-1] = str(cnt)


for x in ans:
	print("".join(x), sep="")


Measured memory_bytes: 5216
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

vector<int> range_mod_inverse(int n, const int mod){
	vector<int> ret(n+1);
	ret[1] = 1;
	for(int i = 2; i <= n; i++)
		ret[i] = (long long) (mod - mod/i) * ret[mod%i] % mod;
	return ret;
}

vector<int> getFactorials(int n, const int mod) {
	vector<int> ret(1,1);
	for (int i = 1; i <= n; i++) ret.push_back((long long)ret.back()*i%mod);
	return ret;
}

vector<int> getInverseFactorials(int n, const int mod) {
	vector<int> invmod(range_mod_inverse(n, mod));
	vector<int> ret(1,1);
	for (int i = 1; i <= n; i++) ret.push_back((long long)ret.back()*invmod[i]%mod);
	return ret;
}

tuple<long long, long long, long long> extended_gcd(long long a, long long b) {
	long long s = 1, t = 0;
	long long u = 0, v = 1;
	// loop invariant: (A,B) = (input a, input b), a = s*A + t*B, b = u*A + v*B
	while (b != 0) {
		long long q = a / b;
		tie(a, b) = make_pair(b, a % b);
		// b' = A(s-uq) + B(t-vq)
		tie(s, t, u, v) = make_tuple(u, v, s - u * q, t - v * q);
	}
	return make_tuple(a, s, t);
}

long long modinverse(long long a, long long m) {
	a = a % m;
	if (a < 0) a += m;
	long long value = get<1>(extended_gcd(a, m)) % m;
	return (value < 0) ? value + m : value;
}

long long power(long long n, long long k, long long m) {
	if (m < 0) m = -m;
	n %= m;
	if (k < 0) {
		n = modinverse(n, m);
		k = -k;
	}
	long long ret = 1;
	while (k) {
		if (k & 1) ret = (ret * n % m);
		n = (n * n % m);
		k >>= 1;
	}
	return ret;
}

const int mod = 1'000'000'007;

vector<int> fact;
vector<int> ifact;

long long binom(int a, int b) {
  if (a < 0 || b < 0 || b > a) return 0;
  return (long long)fact[a] * ifact[b] % mod * ifact[a - b] % mod;
}

int main() {
  fact = getFactorials(200'005, mod);
  ifact = getInverseFactorials(200'005, mod);
  int B, W;
  scanf("%d%d", &B, &W);
  long long Badd = 0, Wadd = 0;
  for (int i = 0; i < B + W; i++) {
    long long ans = 1;
    if (i >= B) {
      long long curB = binom(i, B) * power(2, -i, mod) % mod;
      ans -= Badd + curB;
      Badd += modinverse(2, mod) * curB; Badd %= mod;
    }
    if (i >= W) {
      long long curW = binom(i, W) * power(2, -i, mod) % mod;
      ans += Wadd + curW;
      Wadd += modinverse(2, mod) * curW; Wadd %= mod;
    }
    ans %= mod;
    ans *= modinverse(2, mod); ans %= mod;
    ans += mod;
    ans %= mod;
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 3940
//#pragma GCC target("avx")
#pragma GCC optimize ("Ofast")
#include <iostream>
#include <cmath>

template<typename T> void fastscan(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) { 
    putchar('0');
    putchar('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
  putchar('\n');
}
 
int main(){    
    int N; fastscan(N);
    int v[N];
    for (int i = 0; i < N; ++i) fastscan(v[i]);
    int sum = 0;
 
    for (int i = 1; i < N; ++i) sum += abs(v[i - 1] - v[i]);
    sum += abs(0 - v[0]) + abs(v[N - 1]);
    int diff[N]; 
    diff[0] = abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]);
    for (int i = 1; i < N - 1; ++i){
        diff[i] = abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]);
    }
    diff[N - 1] = abs(v[N - 2] - v[N - 1]) + abs(v[N - 1]) - abs(v[N - 2]);
 
    for (int i = 0; i < N; ++i){
        int ans = sum - diff[i];
        fastout(ans);
    }
    return 0;
}


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

int main()
{
	int S;
	cin >> S;
	int h = S / 3600;
	int m = (S % 3600) / 60;
	int s = (S % 3600) % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3100
/*  Bismillahir Rahmanir Rahim
    Author  :  Md. Sajjat Hosen
    Created :  Friday, 05 June, 2020 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long               ll;
typedef long double             ld;
typedef unsigned long long      ull;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds_multiset;

inline int Int() { int x; scanf("%d", &x); return x; }
inline ll Long() { ll x; scanf("%lld", &x); return x; }

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

const int N       = (int) 2e5 + 5;
const int maxN    = (int) 1e6 + 6;
const int Mod     = (int) 1e9 + 7;

#define     debug(x)    cerr << #x << " = " << x << '\n';
#define     all(x)      x.begin(), x.end()
#define     szof(x)     (int) x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     mp          make_pair
#define     PI          acos(-1.0)
#define     TN          typename
#define     nl          '\n'
#define     Fast_IO     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

inline int add(int a, int b) { a += b; return a >= Mod ? a - Mod : a < 0 ? a + Mod : a; }
inline int mult(int a, int b) { return (ll) a * b % Mod; }

template <TN T> T gcd(T a, T b) { return !b ? a : gcd(b, a % b); }
template <TN T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }

int main() {
    //Fast_IO
    //clock_t tStart = clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int test = 1, tc = 0;
    while (test--) {
        int a = Int();
        ll ans = a + a * a + a * a * a;
        printf("%lld\n", ans);
    }
    //fprintf(stderr, "\nRuntime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3820
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>

using namespace std;

int p_amount(bool persimmon_at[][100], int start_x, int start_y, int w, int h) {
    int cnt = 0;
    for (int i = start_x; i < start_x + w; i++) {
        for (int j = start_y; j < start_y + h; j++) {
            if (persimmon_at[i][j])
                cnt++;
        }
    }

    return cnt;
}

int main(int argc, char const *argv[])
{
    int n, width, height;

    while (true) {
        cin >> n;
        if (n == 0) break;

        cin >> width >> height;
        bool persimmon_at[100][100] = {{false}};

        int pw, ph;
        for (int i = 0; i < n; i++) {
            cin >> pw >> ph;
            persimmon_at[pw-1][ph-1] = true;
        }

        int given_w, given_h;
        cin >> given_w >> given_h;

        int max = 0;
        int tmp = 0;
        for (int i = 0; i < width - given_w + 1; i++) {
            for (int j = 0; j < height - given_h + 1; j++) {
                tmp = p_amount(persimmon_at, i, j, given_w, given_h);
                if (tmp > max)
                    max = tmp;
            }
        }

        cout << max << endl;
    }

    return 0;
}

Measured memory_bytes: 1176