akhauriyash/Code-Regression huggingface dataset:
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)

int main() {
	ul q, h, s, d;
	ul n;
	cin >> q >> h >> s >> d;
	cin >> n;

	ul best1l = min({ 4*q, 2*h, s });
	ul best2l = 0;
	if (n >= 2) {
		best2l = min({ d, 2 * best1l });
	}
	else {
		best2l = 2 * best1l;
	}

	ul money = 0;
	if (best2l == 2 * best1l) {
		money = best1l*n;
	}
	else {
		money = (ul)(n / 2)*best2l + best1l*(n % 2);
	}
	cout << money << endl;
	return 0;
}





Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    string s;
    cin >> s;
    ll ans = 0;
    rep(i, s.size())if(s[i] == '1')ans++;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)1e9+7
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll


int a[1000][100]={};
int H,w,m;

void f(int h,bool b[],int k){

  if(k==w){
    FOR(i,1,w+1){
      if(b[i]){
        a[h][i]+=a[h-1][i+1];
        a[h][i]%=M;        
        a[h][i+1]+=a[h-1][i];
        a[h][i+1]%=M;
        
      }
      else if(!b[i-1]&&!b[i]){
        a[h][i]+=a[h-1][i];
        a[h][i]%=M;
      }
    }
    
    return;
  }

  f(h,b,k+1);

  if(!b[k-1]){
    b[k]=true;
    f(h,b,k+1);
    b[k]=false;
  }

}

signed main(){
  cin>>H>>w>>m;

  a[0][1]=1;

  FOR(i,1,H+1){
    bool b[100]={};
    f(i,b,1);
  }

  if(w==1&&m==1){
    cout<<1<<endl;
  }
  else{
    cout<<a[H][m]<<endl;
  }

  
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf=1e8;
int f[1<<26],a[200011],dp[200011];
char s[200011];
int main(){
	memset(f,127,sizeof(f));
	memset(dp,127,sizeof(dp));
	f[0]=0;
	scanf("%s",s);
	int len=strlen(s);
	a[0]=(1<<(s[0]-'a'));
	for(int i=1;i<len;i++) a[i]=a[i-1]^(1<<(s[i]-'a'));
	for(int i=0;i<len;i++){
		for(int j=0;j<26;j++) if(f[a[i]^(1<<j)]<inf) dp[i]=min(dp[i],f[a[i]^(1<<j)]+1);
		if(!a[i]) dp[i]=min(dp[i],1);
		if(dp[i]<inf) f[a[i]]=min(f[a[i]],dp[i]);
	}
	printf("%d\n",dp[len-1]);
	return 0;
}

Measured memory_bytes: 264192
A, B = map(int, input().split())
count = 0
for a in range(A // 10000, B // 10000 + 1):
  for b in range(10):
    for c in range(10):
      p = a * 10001 + b * 1010 + c * 100
      if p >= A and p <= B:
        count += 1
print(count)

Measured memory_bytes: 2940
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	k := nextInt()
	x := nextInt()

	for i := -100000; i <= 100000; i++ {
		if (x-k+1 <= i) && (i <= x+k-1) {
			fmt.Printf("%d ", i)
		}

	}

}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
n=int(input())
l_s=[str(input()) for _ in range(n)]
m=int(input())
l_t=[str(input()) for _ in range(m)]
s=set(l_s)
ans=0
for i in s:
    ans=max(ans,l_s.count(i)-l_t.count(i))
print(ans)

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class AServalVsMonster {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int H, A;
	    in >> H >> A;
	    out << (H + A - 1) / A << '\n';
	}
};


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

	AServalVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
s+="6"
c=0
l=[]
zcnt=0
for i in range(n):
  if s[i]!=s[i+1]:
    if s[i]=="0":zcnt+=1
    l.append((s[i],i+1-c))
    c=i+1
L=len(l)
sl=[0]*(L+1)
for i in range(L):
    sl[i+1]=sl[i]+l[i][1]
if k>=zcnt:print(n);exit()
ans=0
if s[0]=="0":
    for i in range(zcnt-k+1):
        ans=max(ans,sl[min(L,2*k+i*2)]-sl[max(0,i*2-1)])
    print(ans)
else:
    for i in range(zcnt-k+1):
        ans=max(ans,sl[min(L,2*k+i*2+1)]-sl[i*2])
    print(ans)

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, r, n) for (int i = (r); i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); i--) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define MOD 1000000007
#define PI (acos(-1))

bool IsPrime(int);

/***** MAIN *****/
int main() {
  string s;
  cin >> s;
  int stringLength = s.size();
  int numerical_sequence[stringLength+1];
  numerical_sequence[0] = 0;
  
  int count = 0;
  ll ans = 0;
  REP(i, stringLength) {
    if(s[i] == '>') count = 0;
    else count++;
    numerical_sequence[i+1] = count;
  }
  count = 0;
 
  ans += numerical_sequence[stringLength];
  REPR(i, stringLength-1) {
    if(s[i] == '<') count = 0;
    else count++;
    ans += max(numerical_sequence[i], count);
  }

  cout << ans;

  cout << "\n";
  return 0;
}
/***** MAIN *****/

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

Measured memory_bytes: 2820
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <queue>
using namespace std;



long long f(long long n) {
  stringstream ss;
  ss << n;
  return ss.str().size();
}

int main() {
  long long N;
  while (cin >> N) {
	long long res = 1000000;
	for (long long a = 1; a * a <= N; ++a) {
	  if (N % a != 0) continue;
	  long long b = N/a;
	  long long tmp = max(f(a), f(b));

	  //cout << a << ", " << b << ": " << tmp << endl;
	  
	  if (res > tmp) res = tmp;
	}
	cout << res << endl;
  }
}


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

int main(){
  int w,h,n,now_x = 0,now_y = 0;
  cin >> w >> h >> n;
  int x[n] = {0},y[n] = {0}, a[n] = {0};
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i] >> a[i];
  }
  for(int i=0;i<n;i++){
    switch(a[i]){
      case 1: if(now_x < x[i]) now_x = x[i];
              break;
      case 2: if(w > x[i]) w = x[i];
              break;
      
      case 3: if(now_y < y[i]) now_y = y[i];
              break;
      case 4: if(h > y[i]) h = y[i];
              break;
     }
  }
  int ans=0;
  if((w-now_x) > 0 && (h-now_y) > 0)ans =  (w-now_x)*(h-now_y);
  else ans = 0;
   cout << ans << endl;
  

}


Measured memory_bytes: 256
// AOJ 1230: Nim
// 2017.10.14 bal4u@uu

#include <stdio.h>
#include <string.h>

int m[22];
char dp[22][9000];

int main()
{
	int n, s, i, j, k, p, n2;

	while (scanf("%d", &n) && n > 0) {
		scanf("%d", &s);
		for (i = 0, n2 = n << 1; i < n2; i++) scanf("%d", m+i);
		memset(dp, 0, sizeof(dp));
		for (j = 2; j <= s; j++) for (i = 0; i < n2; i++) {
			k = 0;
			for (k = 0, p = 1; p <= m[i]; p++) {
				if (j <= p) break;
				if(!dp[(i+1)%n2][j-p]) k = 1;
			}
			dp[i][j] = k;
		}
		puts(dp[0][s] ? "1" : "0");
	}
    return 0;
}

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

int N;
int A[200];
const int INF = 10000000;

int main() {
	cin >> N;
	for (int i = 0;i < N;i++) cin >> A[i];
	int res = INF;
	for (int i = 0;i < N;i++) {
		int count = 0;	//割れる回数
		while (A[i] % 2 == 0) {
			A[i] = A[i] / 2;
			count++;
		}
		if (res > count) res = count;
	}
	cout << res;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=100010;
const ll INF=0x3f3f3f3f3f3f3f3f;
struct node{
	int v,next;
}edge[N<<1];
int last[N],le;
void add(int u,int v){
	edge[++le].v=v,edge[le].next=last[u],last[u]=le;
	edge[++le].v=u,edge[le].next=last[v],last[v]=le;
}
ll a[N],b[N],dp[N],sum[N];
int f[N],fa[N],pos[N],rt;
inline int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
inline bool cmp(int t1,int t2){
	return a[t1]<a[t2];
}
vector<int> G[N];
void dfs(int u){
	sum[u]=b[u];
	if (!G[u].size()){
		dp[u]=a[u]+b[u];
		return;
	}
	for (int i=G[u].size()-1;~i;--i){
		int v=G[u][i];
		dfs(v);
		sum[u]+=sum[v];
	}
	dp[u]=INF;
	for (int i=G[u].size()-1;~i;--i){
		int v=G[u][i];
		dp[u]=min(dp[u],max(dp[v],a[u])+sum[u]-sum[v]);
	}
}
int main(){
	int n=read(),m=read();
	for (int i=1;i<=n;++i){
		a[i]=read(),b[i]=read();
		a[i]=max(a[i]-b[i],0ll);
		pos[i]=f[i]=i,fa[i]=-1;
	}
	for (int i=1;i<=m;++i){
		int u=read(),v=read();
		add(u,v);
	}
	sort(pos+1,pos+n+1,cmp);
	for (int j=1;j<=n;++j){
		int u=pos[j];
		for (int i=last[u];i;i=edge[i].next){
			int v=edge[i].v;
			if (fa[find(v)]==0) fa[find(v)]=f[find(v)]=u;
		}
		fa[u]=0;
	}
	for (int i=1;i<=n;++i){
		if (!fa[i]) rt=i;
		else G[fa[i]].push_back(i);
	}
	dfs(rt);
	printf("%lld\n",dp[rt]);
	return 0;
}

Measured memory_bytes: 14464
def main():
    from collections import deque
    s = deque(list(input()))
    while deque:
        t = s.pop()
        if len(s)%2 != 0:
            continue
        l = list(s)
        if l[:len(l)//2] == l[len(l)//2:]:
            print(len(l))
            return 0

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, k) {
        vector<ll> b(n + 1, 0);
        rep(j, n) {
            ll l = max(0LL, j - a[j]);
            ll r = min(n, j + a[j] + 1);
            b[l]++;
            b[r]--;
        }
        ll cnt = 0;
        rep(j, n) {
            b[j + 1] += b[j];
            a[j] = b[j];
            if (a[j] == n) cnt++;
        }
        if (cnt == n) break;
    }
    rep(i, n) printf("%lld%s", a[i], (i == (n - 1)) ? "\n" : " ");
    return 0;
}


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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();++i){
        if(i==s.size()-1){
            if(s[i]=='3'){
                cout<<"bon"<<endl;
            }
            else if(s[i]=='0'||s[i]=='1'||s[i]=='6'||s[i]=='8'){
                cout<<"pon"<<endl;
            }
            else cout<<"hon"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
num_file = {}
for i in a_list:
    num_file[i] = 0
for i in a_list:
    num_file[i] += 1
if len(num_file) <= k:
    print(0)
else:
    new_list = sorted(num_file.items(), key = lambda x: x[1])
    ans = 0
    count = 0
    for key, value in new_list:
        ans += value
        count += 1
        if len(new_list)- count == k:
            print(ans)

Measured memory_bytes: 38964
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,tmp[5],ans=0;
    string s;
    cin >> n;
    rep(i,5) tmp[i]=0;
    rep(i,n){
        cin >> s;
        if(s[0]=='M') tmp[0]++;
        if(s[0]=='A') tmp[1]++;
        if(s[0]=='R') tmp[2]++;
        if(s[0]=='C') tmp[3]++;
        if(s[0]=='H') tmp[4]++;
    }
    for(ll i=0;i<3;i++){
        for(ll j=i+1;j<4;j++){
            for(ll k=j+1;k<5;k++) ans+=tmp[i]*tmp[j]*tmp[k];
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    auto first_c = numeric_limits<int>::max();
    auto last_f = numeric_limits<int>::min();
    for (auto i = 0; i < int(s.length()); i++)
    {
        if (s[i] == 'C') first_c = min(first_c, i);
        if (s[i] == 'F') last_f = max(last_f, i);
    }

    cout << (first_c < last_f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    s = readline().rstrip().decode()
    if s.isupper():
        print('A')
    else:
        print('a')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9028
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int n; cin>>n;
	int a[n];
	forn(i,n) cin>>a[i];	

	int ans = 0;
	forn(i,n){
		if(i%2 == 0 && a[i]%2 == 1) ans++;
	}
	cout<<ans<<ln;

	return 0;
}

Measured memory_bytes: 3656
import collections

ORD_A = ord("a")


def count_chars(s):
    counter = [0 for _ in range(26)]
    for c in s:
        counter[ord(c) - ORD_A] += 1

    return counter


def main():
    n = int(input())
    anagram_counter = collections.Counter(tuple(count_chars(input())) for _ in range(n))

    combinations = sum(v * (v - 1) // 2 for v in anagram_counter.values())
    print(combinations)


if __name__ == "__main__":
    main()


Measured memory_bytes: 36184
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		String [] s = new String[n];
		int[] t = new int[n];
		
		for(int i = 0; i < n; i++) {
			s[i] = stdIn.next();
			t[i] = stdIn.nextInt();
		}
		String x = stdIn.next();
		
		int index = 0;
		for(int i = 0; i < n; i++) {
			if(x.equals(s[i])) {
				index = i;
			}
		}
		int sum = 0;
		for(int i = index+1; i < n; i++) {
			sum += t[i];
		}
		System.out.println(sum);
		
		
	}

}


Measured memory_bytes: 23764
import java.util.*; 
            class Main{ 
                public static void main(String[] args){ 
                    Scanner sc = new Scanner(System.in); 
                    int n = sc.nextInt(); 
                    int k = sc.nextInt(); 
                    int w[] = new int[n]; 
                    int i, nSum=0, nMax=0; 
                    for(i=0; i<n; i++){ 
                        w[i] = sc.nextInt(); 
                        nSum+=w[i]; 
                        if(nMax<w[i]){ 
                            nMax=w[i]; 
                        } 
                    } 
                    int kMin, kMinIni, kMinWok, kZan=k, nSumZan=nSum, kSho=0; 
                    kMinIni=nSum%k==0?nSum/k:nSum/k+1; 
                    if(kMinIni<nMax) 
                        kMinIni=nMax; 
                    kMin=kMinIni; 
                    while(true){ 
                        for(i=0; i<n; i++){ 
                            if(kMin>kSho+w[i]){ 
                                kSho+=w[i]; 
                            } 
                            else if(kMin==kSho+w[i]){ 
                                if(kZan==1){ 
                                    for(i++; i<n; i++){ 
                                        kMin+=w[i]; 
                                    } 
                                    break; 
                                } 
                                kZan--; 
                                nSumZan-=(kSho+w[i]); 
                                kSho=0; 
                            } 
                            else { 
                                if(kZan==1){ 
                                    kMin=kSho+w[i]; 
                                    for(i++; i<n; i++){ 
                                        kMin+=w[i]; 
                                    } 
                                    break; 
                                } 
                                kMinWok=(nSumZan-kSho)%(kZan-1)==0? (nSumZan-kSho)/(kZan-1): (nSumZan-kSho)/(kZan-1)+1; 
                                if(kMinWok>=kSho+w[i]){ 
                                    kMin=kSho+w[i]; 
                                    kZan--; 
                                    nSumZan-=(kSho+w[i]); 
                                    kSho=0; 
                                } 
                                else{ 
                                    kZan--; 
                                    nSumZan-=kSho; 
                                    kSho=w[i]; 
                                } 
                            } 
                        } 
                        if(kMinIni==kMin) 
                            break; 
                        kMinIni++; 
                        kMin=kMinIni; 
                        kZan=k; 
                        nSumZan=nSum; 
                        kSho=0; 
                    } 
                    System.out.println(kMin); 
                } 
            }


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;

  if(n == 3) {
    cout << "2 5 63" << endl;
    return 0;
  }
  if(n == 4) {
    cout << "2 5 20 63" << endl;
    return 0;
  }


  int t = min(10000LL, (n - 3) / 3 * 2 + 2);
  int u = min(5000LL, n - t);
  if(u%2) u--;
  int v = n - t - u;

  // if(u == 0) cout << n << endl;
  // cout << t << " " << u << " " << v << endl;

  VI ans;
  int a = 2;
  int d = 0;
  REP(i, t) {
    ans.PB(a);
    d += a;
    a += 2;
    if(a % 6 == 0) a += 2;
  }
  // cout << a << endl;
  // cout << d << " " << d%3 << endl;

  a = 3;
  REP(i, u) {
    ans.PB(a);
    a += 6;
  }
  // cout << a << endl;

  a = 6;
  REP(i, v) {
    ans.PB(a);
    a += 6;
  }
  // cout << a << endl;

  int sum = 0;
  REP(i, ans.size()) {
    sum += ans[i];
    cout << ans[i] << (i==ans.size()-1?"\n":" ");
  }

  return 0;
}


Measured memory_bytes: 640
<?php
  fscanf(STDIN, "%d", $n);
  fscanf(STDIN, "%d %d", $d, $x);

  $ans = $x;
  for ($i=0; $i<$n; $i++) {
    fscanf(STDIN, "%d", $a);
    $ans += ceil($d/$a);
  }

  echo (int)$ans . "\n";
?>


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n =  sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		int ans = 0;
		int i = 0;
		while(x > 0 && n - 1 >= i) {
			if(x < a[i] || (i == n - 1 && a[i] != x)) {
				i++;
				break;
			} else {
				x -= a[i];
				ans++;
				i++;
			}
		}
		System.out.println(ans);
	}
}


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

int N,A,B,C,D,F,Z,L,P;

int main(){
cin>>N>>A>>B>>C>>D;

int x;
int y;

if( N % A == 0)
F= N / A ; //FはXの個数
else
F= N / A + 1 ; 

if( N % C == 0)
L= N / C ; //LはYの個数
else
L= N / C + 1; //LはYの個数

Z=B*F; //ZはXで揃えた場合の合計金額
P=L*D; //PはYで揃えた場合の合計金額
 //set x   F=N/A+1 Z=B*F
 //set y   L=N/C+1 P=L*D

 if (Z<P)
cout<<Z<<endl;
 else
cout<<P<<endl;

return 0;
}



Measured memory_bytes: 3136
from statistics import mean
import sys
N = int(input())
d = list(map(int,input().split()))

d.sort()

d1 = [d[i] for i in range(N//2) if i <= N]
d2 = [d[i] for i in range(N//2,N)]

a = d2[0] - d1[-1]

if len(d1) == len(d2):
    print(a)
    sys.exit()
print(0)


Measured memory_bytes: 15984
import java.util.*;
public class Main {
    public static void main(String[] args) {	
	Main main = new Main();
    	main.solveA();
    }
    
    private void solveA() {
	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
	String s;
	if (A>=9 || B>=9){
	    s = ":(";
	}
	else{
	    s = "Yay!";
	}
    	System.out.println(s);
    }
}

Measured memory_bytes: 21844
package main
import (
    "bufio"
    "fmt"
    "os"
)
func main(){
   a := bufio.NewReader(os.Stdin)
   var W, H, x, y, r int
   fmt.Fscan(a, &W, &H, &x, &y, &r)
   if x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H{
       fmt.Println("Yes")
   } else{
       fmt.Println("No")
   }
}



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

int main (){
  long long n, i, j, k, res = 0;
  cin >> n;
  //int r = n
  for (i = 1; i < n; i++){
    for (j = 1 ; j < n; j++){
      if ( n - (i *j) < n && n - (i *j) > 0)
        res++;
      else 
        break;
    //  r--;
    }
  }
  cout << res;
}

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

int main() {
  int x, y;
  cin >> x >> y;
  int W = -1;
  vector<vector<char>> G(x,vector<char>(y));
  for (auto &v : G) {
    for (auto &c : v) {
      cin >> c;
      if (c == '.') W += 1;
    }
  }
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  queue<pair<int,int>> Q;
  vector<vector<int>> dist(x,vector<int>(y,-1));
  dist[0][0] = 0;
  Q.push({0,0});
  while (!Q.empty()) {
    auto p = Q.front();
    Q.pop();
    if (p == make_pair(x-1,y-1)) break;
    for (int i = 0; i < 4; i++) {
      int X = p.first+dx[i];
      int Y = p.second+dy[i];
      if (X < 0 || X >= x || Y < 0 || Y >= y) continue;
      if (G[X][Y] == '#') continue;
      if (dist[X][Y] != -1) continue;
      Q.push({X,Y});
      dist[X][Y] = dist[p.first][p.second] + 1;
    }
  }
  if (dist[x-1][y-1] == -1) cout << -1 << endl;
  else cout << W - dist[x-1][y-1] << endl;
}

Measured memory_bytes: 3648
N, K, Q = map(int, input().split())
score = {}
for i in range(Q):
	a = int(input())
	a = a-1
	if(a not in score):
		score[a] = 0
	score[a] = score[a] + 1


for i in range(N):
	if(i not in score):
		score[i] = 0
	if(K + score[i] - Q > 0):
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 15856
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}


int N, a[111], cnt[111];

void impossible() { puts("Impossible"); exit(0); }
void possible() { puts("Possible"); exit(0); }

void solve() {
	int mx_a = *max_element(a, a + N);
	
	if (mx_a == 1 && N > 2) impossible();
	
	int hlf = mx_a / 2;
	
	bool flag = true;
	for_(i,0,N) flag &= (a[i] >= hlf);
	
	if (cnt[mx_a] < 2 || !flag) impossible();
		
	if (mx_a % 2 == 0 && cnt[hlf] != 1) impossible();
	if (mx_a % 2 == 1 && cnt[hlf] > 0) impossible();
	if (mx_a % 2 == 1 && cnt[hlf + 1] != 2) impossible();
	
	for_rev(x,mx_a-1,hlf+1) {
		if (cnt[x] < 2) impossible();
	}
	
	possible();	
}

int main() {
	cin >> N;
	
	minit(cnt, 0);
	
	for_(i,0,N) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	
	solve();
}

Measured memory_bytes: 256
n = int(input())
data = list(map(int, input().split()))
datb = list(map(int, input().split()))
datc = [data[i] - datb[i] for i in range(n)]
datc.sort(reverse=True)
#print(datc)
if sum(datc) < 0:
    print(-1)
else:
    l, r = 0, n-1
    res = 0
    total = 0
    import collections
    dat = collections.deque(datc)
    while len(dat) > 0:
        if total >= 0:
            v = dat.pop()
            if v >= 0:
                break
            res += 1
            total += v
        else:
            total += dat.popleft()
            res += 1
    print(res)


Measured memory_bytes: 84656
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>

using namespace std;

struct pkt
{
    double x, y;
};

const double INF = 100000000000;

double Dl(pkt a, pkt b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

pkt Sr(pkt a, pkt b)
{
    return {(a.x + b.x) / 2.0, (a.y + b.y) / 2.0};
}

pkt Sr(vector<pkt> a)
{
    double A1 = (-a[0].x + a[1].x) / (a[0].y - a[1].y);
    double B1 = 0.5 * (a[0].y * a[0].y - a[1].y * a[1].y + a[0].x * a[0].x - a[1].x * a[1].x) / (a[0].y - a[1].y);
    double A2 = (-a[1].x + a[2].x) / (a[1].y - a[2].y);
    double B2 = 0.5 * (a[1].y * a[1].y - a[2].y * a[2].y + a[1].x * a[1].x - a[2].x * a[2].x) / (a[1].y - a[2].y);
    pkt O;
    O.x = (B2 - B1) / (A1 - A2);
    O.y = A1 * O.x + B1;
    return O;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<pkt> p(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y;
    double odp = INF;
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            for (int k = j + 1; k < n; ++k)
            {
                vector<pkt> a(3);
                a[0] = p[i];
                a[1] = p[j];
                a[2] = p[k];
                pkt O = Sr(a);
                double R = Dl(O, p[i]);
                bool ok = true;
                for (int l = 0; l < n; ++l)
                    if (Dl(p[l], O) > R + 1e-4)
                        ok = false;
                if (ok)
                    odp = min(odp, R);
            }
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            pkt S = Sr(p[i], p[j]);
            double R = Dl(p[i], p[j]) / 2.0;
            bool ok = true;
            for (int k = 0; k < n; ++k)
                if (Dl(p[k], S) > R + 1e-4)
                    ok = false;
            if (ok)
                odp = min(odp, R);
        }
    }
    cout << fixed << setprecision(7);
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  long long sum = 0;
  vector<long long> a(n + 1);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    a[i + 1] = sum;
  }
  map<long long, long long> mp;
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += mp[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14336
n = int(input())
a = list(map(int,input().split()))

i = int(0)
ans = int(0)
f = True


while i+1 < n:

    if a[i] < a[i+1] :
        while a[i] <= a[i+1] :
            if i+1 >= n-1:
                f=False
                break
            i += 1
        
        if f :
            ans += 1

    elif a[i] == a[i+1] :
        if i+1 >= n-1:
            break

    else:
        while a[i] >= a[i+1] :
            if i+1 >= n-1:
                f = False
                break
            i+=1
        
        if f :
            ans += 1
    
    i += 1

    
print(ans+1)
        

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

void exchange(int &A, int &B){
  if(A%2==1){
      A--;
    }
    B += A / 2;
    A /= 2;
}

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = 0; i < K; i++){
    if(i%2==0){
      exchange(A, B);
    }else{
      exchange(B, A);
    }
  }
  cout << A << " " << B;
  return 0;
}



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

using namespace std;

typedef long long int llint;

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

//#define DEBUG

#ifdef DEBUG
#define dump(i) cout << "[*] " #i ": " << i << endl
#define line cout << "[*] --------- [*]" << endl
#else
#define dump(i)
#define line
#endif

int n, a;

inline void input() {
	cin >> n;
}

inline void solve() {
	a += n / 100;
	a += ((n / 10) % 10) * 10;
	a += (n % 10) * 100;
	cout << (n == a ? "Yes" : "No") << endl;
}

int main() {
	input();
	line;
	solve();
	return 0;
}


Measured memory_bytes: 256
case class pos(val x: Int, val y: Int)

object Main extends App {
	val n = scala.io.StdIn.readInt
	var red = new Array[pos](n)
	var blue = new Array[pos](n)

	for(i<-0 until n){
		val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		red(i) = pos(temp(0),temp(1))
	}

	for(i<-0 until n){
		val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		blue(i) = pos(temp(0),temp(1))
	}

	red = red.sortBy(_.x)
	blue = blue.sortBy(_.x)

	var ans = 0
	for(x <- blue){
		var idx = -1
		var max = -1

		for(i<-0 until n){
			if(red(i).x != -1){
				if(red(i).x <= x.x){
					if(red(i).y > max && red(i).y < x.y){
					idx = i
					max = red(i).y
				}
				}
			}
		}

		if(idx != -1){
			red(idx) = pos(-1,-1)
			ans += 1
		}
	}

	println(ans)

}

Measured memory_bytes: 25408
H,W=map(int,input().split())
C=[[int(i) for i in input().split()] for j in range(10)]
for i in range(10):
    C[i][i]=0
for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j]=min(C[i][j],C[i][k]+C[k][j])
ans=0
for _ in range(H):
    for a in input().split():
        a=int(a)
        if a!=-1:
            ans+=C[a][1]
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class D {
    static void Main(string[] args) {
        long H = long.Parse(Console.ReadLine());

        long ruijou = (long)(Math.Log10(H) / Math.Log10(2));

        Console.WriteLine(Math.Pow(2, ruijou + 1) - 1);

    }
}

Measured memory_bytes: 11220
#include<stdio.h>
int main(void){
	
	int N;
	scanf("%d",&N);
	
	int p[10];
	int i;
	for(i = 0;i < N;i++){
		scanf("%d",&p[i]);
	}
	int minnum,minp = p[0];
	
	for(i = 0;i < N;i++){
		if(p[i] >= minp){
			minp = p[i];
			minnum = i;
		}
	}
	
	int sum = 0;
	for(i=0;i<N;i++){
		if(i == minnum){
			sum = sum +( p[i]/2 );
		}else{
			sum = sum + p[i];
		}
	}
	
	printf("%d",sum);
	return 0;
}
	

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

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

  int sumtime = 1900 * m + 100 * (n - m);

  ll kakuritu = pow(2,m);
  ll answer = sumtime * kakuritu;

  cout << answer << endl;
}



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

int main() {
	int N;
	string S;
	cin >> N;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < N - 2; i++) {
		if (S.substr(i, 3) == "ABC") {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, m;
llong x, y;
vector<vector<llong> > g;
llong mem[100005];

llong dfs(int u) {
    if (mem[u] != -1) return mem[u];

    llong rec = 0;
    for (int i = 0; i < g[u].size(); i++) {
        rec = max(rec, dfs(g[u][i]) + 1);
    }

    return mem[u] = rec;
}

int main() {
    for (int i = 0; i < 100005; i++) mem[i] = -1;
    
    cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y);
    }

    llong ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dfs(i));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8576
using System;

namespace AtCoderBeginnerContest148
{
	class Program
	{
		static void Main(string[] args)
		{
			var input1 = int.Parse(Console.ReadLine());
			var input2 = int.Parse(Console.ReadLine());
			if(input1 != 1 && input2 != 1)
			{
				Console.WriteLine(1);
			}
			if (input1 != 2 && input2 != 2)
			{
				Console.WriteLine(2);
			}
			if (input1 != 3 && input2 != 3)
			{
				Console.WriteLine(3);
			}
		}
	}
}


Measured memory_bytes: 11092
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
P = list(map(int,input().split()))
Q = sorted(P)
cnt = 0
for i in range(N):
    if P[i] != Q[i]:
        cnt += 1

if cnt == 2 or cnt ==0:
    print('YES')
else:
    print('NO')


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

using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const int INF = (1LL<<30);
#else
const ll INF = (1LL<<60);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

string s[100];
signed main(void)
{
  int h, w;
  cin >> h >> w;
  REP(i, h) cin >> s[i];

  REP(i, h) REP(j, w) {
    if(s[i][j] == '.') {
      int cnt = 0;
      REP(k, 8) {
        int nx = j + dx[k], ny = i + dy[k];
        if(IN(0, w, nx) && IN(0, h, ny) && s[ny][nx] == '#') cnt++;
      }
      s[i][j] = '0'+cnt;
    }
  }

  REP(i, h) cout << s[i] << endl;

  return 0;
}


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

int main(){
  string S ;
  int N, block = 0, ans = 1, check;
  cin >> S ;
  if(S[2] != S[3]) ans = 0 ;
  if(S[4] != S[5]) ans = 0 ;
  if(ans){
    cout << "Yes" << endl ;
  }  
  else{
    cout << "No" << endl ;
  }  
  return 0 ;
}  

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int w = -1,h = -1;
    int i,j;
    
    while (w != 0 && h != 0)
    {
        if (w != -1 && h != -1)
        {
            putchar('\n');
        }
        scanf("%d %d", &h, &w);
        for (i = 0; i < h; i++)
        {
            for (j = 0; j < w; j++)
            {
                if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                {
                    putchar('#');
                }
                else
                {
                    putchar('.');
                }
            }
            putchar('\n');
        }
    }

    return 0;
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int n = s.size();
    s.push_back('R');
    int cntR = 0;
    int cntL = 0;
    int b = 0;
    int ans[n] = {};
    rep(i, 0, n) {
        if (s[i] == 'R') {
            cntR++;
            if (s[i + 1] == 'L') {
                b = i;
            }
        } else {
            cntL++;
            if (s[i + 1] == 'R') {
                ans[b] += (cntR + 1) / 2 + cntL / 2;
                ans[b + 1] += cntR / 2 + (cntL + 1) / 2;
                cntR = cntL = 0;
            }
        }
    }
    rep(i, 0, n) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


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

int main(){
  char x,y;cin>>x>>y;
  if(x>y)cout << ">" << endl;
  if(x<y)cout << "<" << endl;
  if(x==y)cout << "=" << endl;
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> xs(5);
    for(int i=0; i<5; i++) cin >> xs.at(i);
    for(int i=0; i<5; i++)
    {
        if(xs.at(i) == 0) cout << i+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3608
n,m = list(map(int, input().split()))

problems = [0]*n
accurate = 0
penalty = 0

for i in range(m):
    p,s = input().split()
    p = int(p)

    if s == "AC" and problems[p-1] != -1:
         #初めて正解
         penalty += problems[p-1]
         accurate += 1
         problems[p-1] = -1
    elif s == "WA" and problems[p-1] != -1:
        #正解してない問題を不正解
        problems[p-1] += 1

print(accurate,penalty)

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

#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll mod=1000000007;
const ll inf=1e15;
const ll N=2e5+10;

int main()
{
  boost;
  max_heap ma;
  min_heap mi;
  bool flag=0;
  ll b=0,mid=0,left=0,right=0;
  ll q;
  cin>>q;
  //debug(q);
  while(q--)
  {
  	ll d;
  	cin>>d;
  	if(d==1)
  	{
  		ll x,y;
  		cin>>x>>y;
  		if(flag)
  		{
  			b+=y;
  			ma.push(min(mid,x));
  			left+=min(mid,x);
  			mi.push(max(mid,x));
  			right+=max(mid,x);
  			flag=0;

  		}
  		else
  		{
  			b+=y;
  			mid=x;
  			//debug(x);debug(y);
  			flag=1;
  			if(mi.empty()) continue;
  			//cout<<"fdsa"<<endl;
  			if(ma.top() > x)
  			{
  				mid=ma.top();
  				ma.pop();
  				ma.push(x);
  				left-=mid;
  				left+=x;

  			}
  			else if(mi.top() < x  )
  			{
  				mid=mi.top();
  				mi.pop();
  				mi.push(x);
  				right-=mid;
  				right+=x;
  			}
  			
  		}
  	}
  	else
  	{
  		if(flag)
  		{
  			cout<<mid<<" "<<b+right-left<<endl;
  		}
  		else
  		{
  			cout<<ma.top()<<" "<<b+right-left<<endl;
  		}
  	}
  }
  return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

int checkNum(string);
int checkUpper(string);
int checkLower(string);

int main(){
    string pass;
    int judge = 0;

    cin>>pass;
    
    if(pass.length() < 6){
        cout<<"INVALID"<<endl;
        return 0;
    }
    

    judge = checkNum(pass);
    if(judge == 1){
        cout<<"INVALID"<<endl;
        return 0;
    }


    judge = checkUpper(pass);
    if(judge == 1){
        cout<<"INVALID"<<endl;
        return 0;
    }
  

    judge = checkLower(pass);
    if(judge == 1){
        cout<<"INVALID"<<endl;
        return 0;
    }
    

    cout<<"VALID"<<endl;
    
    return 0;
}

int checkNum(string pass){
    
    for(int i=0;i!=pass.length();i++){
        if(pass[i] >= '0' && pass[i]<='9') return 0;
    }

    return 1;
}

int checkUpper(string pass){

    for(int i=0;i!=pass.length();i++){
        if(pass[i]>='A' && pass[i]<='Z') return 0;
    }

    return 1;
}

int checkLower(string pass){

    for(int i=0;i!=pass.length();i++){
        if(pass[i]>='a' && pass[i]<='z') return 0;
    }

    return 1;
}


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

int main() {
  //Alchemist
  int n; cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i,n-1) {
    v[i+1] = (v[i] + v[i+1]) / 2;
  }
  cout << fixed << setprecision(6);
  cout << v[n-1] << endl;

  return 0;
}

Measured memory_bytes: 3820
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void){
   int N,M;
   int ans = 0;
   int tmp_L,tmp_R;
   int array[100000+10] = {0};
   scanf("%d %d", &N, &M);
   for (int i = 0; i < M; i++) {
      scanf("%d %d", &tmp_L, &tmp_R);
      array[tmp_L - 1]++;
      array[tmp_R]--;
   }
   for (int i = 0; i < N; i++) {
      array[i+1] += array[i];
   }
   for (int i = 0; i < N ; i++) {
      if (M == array[i]) {
         ans ++;
      }
   }
   printf("%d\n",ans);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int A,B,C,D,E,F,G,H,I;
    cin>>A>>B>>C>>D>>E>>F>>G>>H>>I;
    bool ans=true;
    if(B-A==E-D&&E-D==H-G){
    }
    else{
        ans=false;
    }
    if(C-B==F-E&&F-E==I-H){
    }
    else{
        ans=false;
    }
    if(D-A==E-B&&E-B==F-C){
    }
    else{
        ans=false;
    }
    if(G-D==H-E&&H-E==I-F){
       
    }
  else{
    ans=false;
  }
    if(ans==true){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3652
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}

	return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int n, k;
    cin >> n >> k;

    vector<int> tree(n, 0);
    for (int i=0; i<n; i++) cin >> tree[i];
    sort(tree.begin(), tree.end());

    int ans = 2000000000;
    for (int i=0; i<n-k+1; i++) {
        ans = min(ans, abs(tree[i]-tree[i+k-1]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640