akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,M;
  cin >> N >> M;
  v(ll) a(N);
  v(ll) b(N);
  v(ll) c(N);
  rep(i,N) {
    cin >> a[i] >> b[i] >> c[i];
  }
    
  ll tmp = 0;
  v(v(ll)) cost(8,v(ll)(N));
  rep(i,N) {
    cost[0][i] = a[i] + b[i] + c[i];
    cost[1][i] = a[i] + b[i] - c[i];
    cost[2][i] = a[i] - b[i] + c[i];
    cost[3][i] = a[i] - b[i] - c[i];
    cost[4][i] =-a[i] + b[i] + c[i];
    cost[5][i] =-a[i] + b[i] - c[i];
    cost[6][i] =-a[i] - b[i] + c[i];
    cost[7][i] =-a[i] - b[i] - c[i];
  }
  rep(i,8) {
    sort(rng(cost[i]));
    reverse(rng(cost[i]));
  }
  ll ans = 0;
  rep(i,8) {
    ll tmp = 0;
    rep(j,M) {
      tmp += cost[i][j];
    }
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import heapq


def solve(N, Vs):
    h = []
    for v in Vs:
        heapq.heappush(h, v)
    while len(h) >= 2:
        a = heapq.heappop(h)
        b = heapq.heappop(h)
        c = (a + b) / 2
        heapq.heappush(h, c)
    return h[0]


if __name__ == "__main__":
    N = int(input())
    Vs = list(map(int, input().split(" ")))
    print(solve(N, Vs))


Measured memory_bytes: 3060
#include<iostream>
#include<math.h> 
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<climits>
using namespace std;
typedef long long int lli;
lli mod=1000000007;
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    lli n,k;
    cin>>n>>k;
    lli ans=0;
    for(lli i=0;i<n;++i)
    {
        lli ele;
        cin>>ele;
        if(ele>=k)
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const double eps = 1e-8;

bool ok(double l, const vector<pair<int, int> > &xr)
{
	vector<pair<double, double> > sec;
	sec.reserve(xr.size());

	for(auto temp : xr) {

		const double x = temp.first;
		const double r = temp.second;

		if(l + eps > r)
			continue;

		double d = sqrt(r * r - l * l);
		sec.push_back({x - d, x + d});
	}

	sort(sec.begin(), sec.end());

	if(sec.size() == 0)
		return false;

	double len = l * 2;
	int lit = 0, rit = 0;
	double left = sec[0].first, right = sec[0].second;

	while(lit < sec.size()) {

		if(rit < sec.size() - 1 && right + eps > sec[rit+1].first) {
			rit += 1;
			right = max(right, sec[rit].second);
			continue;
		}

		if(right - left + eps > len)
			return true;
		lit = rit + 1;
		rit = lit;
		left = sec[lit].first;
		right = sec[rit].second;
	}

	return false;
}

int main()
{
	while(true) {

		int n;
		vector<pair<int, int> > xr;

		scanf("%d", &n);
		if(n == 0)
			break;
		xr.resize(n);
		for(int i = 0; i < n; ++i)
			scanf("%d%d", &xr[i].first, &xr[i].second);

		double lb = 0, ub = 100000;

		for(int step = 0; step < 100; ++step) {

			double mid = (lb + ub) / 2;

			if(ok(mid, xr))
				lb = mid;
			else
				ub = mid;
		}

		double ans = lb * 2;

		printf("%.10lf\n", ans);
	}

	return 0;
}

Measured memory_bytes: 2228
ns=input()

for i in range(2**(len(ns))):
    ops=["+"]*(len(ns)-1)
    for j in range(len(ops)):
        if((i>>j)&1):
            ops[j]="-"
            
    siki=""
    for x,y in zip(ns,ops+[""]):
        siki+=x+y
        
    if eval(siki)==7:
        print(siki+"=7")
        break

Measured memory_bytes: 38256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll m;
	cin >> m;
	vl x(m);
	vl y(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
	}
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (j != x[i]-1) {
				ans += a[j];
			}
			else ans += y[i];
		}
		cout << ans << endl;
		ans = 0;
	}
}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;
int main()
{
	int n;
	int p[20];
	int ans = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	for (int i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
			p[i - 1] > p[i] && p[i] > p[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  int n,k,t[100010]={},S=0,q,kari=0,ans=0;
  cin>>n>>k;
  string s;
  cin>>s;
  q=s[0]-'0';
  fr(i,n){
    if(s[i]-'0'==q) t[S]++;
    else{t[++S]++;q=s[i]-'0';}
  }
  S++;
  if(2*k>=S){cout<<n<<endl;return 0;}
  //cout<<S<<endl;
if(s[0]=='0'){
  fr(i,2*k){
    kari+=t[i];
  }
  ans=kari;/*
  for(int i=0;i+2*k+1<S;i+=2){
    kari-=t[i];
    kari-=t[i+1];
    kari+=t[i+2*k];
    kari+=t[i+2*k+1];
    ans=max(ans,kari);
  }*/
  kari=0;
  if(s[n-1]=='0') fr(i,2*k) kari+=t[S-1-i];
  ans=max(ans,kari);
  kari=0;
  if(S==2*k+1){cout<<ans<<endl;return 0;}
  Fr(i,2*k+1){
    kari+=t[i];
  }
  ans=max(ans,kari);
  for(int i=1;i+2*k+2<S;i+=2){
    kari-=t[i];
    kari-=t[i+1];
    kari+=t[i+2*k+1];
    kari+=t[i+2*k+2];
    ans=max(ans,kari);
  }
  cout<<ans<<endl;
}
else{
  if(2*k+1==S){cout<<n<<endl;return 0;}
  fr(i,2*k+1) kari+=t[i];
  ans=kari;
  for(int i=0;i+2*k+2<S;i+=2){
    kari-=t[i];
    kari-=t[i+1];
    kari+=t[i+2*k+1];
    kari+=t[i+2*k+2];
    ans=max(ans,kari);
  }
  kari=0;
  if(s[n-1]=='0') fr(i,2*k) kari+=t[S-1-i];
  ans=max(ans,kari);/*
  Fr(i,2*k) kari+=t[i];
  ans=max(ans,kari);
  for(int i=1;i+2*k+1<S;i+=2){
    kari-=t[i];
    kari-=t[i+1];
    kari+=t[i+2*k];
    kari+=t[i+2*k+1];
    ans=max(ans,kari);
  }*/
  cout<<ans<<endl;
}
}

Measured memory_bytes: 896
n,p = map(int,input().split())
l = [0,0]
for i in map(int,input().split()):
  l[i%2] += 1
if p:
  if l[1] == 0:
    print(0)
  else:
    #l[1]C(range(1,l[1]+1,2))は2項定理より2**(l[1]-1)
    print(2**l[0]*2**(l[1]-1))
else:
  if l[1] == 0:
    print(2**l[0])
  else:
    #l[1]C(range(0,l[1]+1,2))は2項定理より2**(l[1]-1)
    print(2**l[0]*2**(l[1]-1))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,m,n,x,i,j,res=0,ans=0;
   cin>>n>>b>>c;

   for(i=1;i<=n;i++)
   {
       m=i;
       res=0;
       while(m!=0)
       {
           x=m%10;
           res+=x;
           m=m/10;

       }
       if(res>=b&&res<=c)
        ans+=i;


   }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt(), b = scanner.nextInt();
        TreeMap<Integer, Integer> result = new TreeMap<>();

        IntStream.range(0,1000)
                .boxed()
                .reduce(0, (accumulator, val)->{
                    int ac = accumulator+val;
                    result.put(val,ac);
                    return ac;
                });

        OptionalInt answer = result.entrySet().stream()
                .filter(ent -> ent.getValue()-a==result.get(ent.getKey()+1)-b)
                .mapToInt(ent -> ent.getValue()-a)
                .findFirst();

        /*
        int accumulator = 0;
        int ans = 0;
        for (int i = 0; i < 1000; i++) {
            int nextAccumulator = accumulator + i;
            if (accumulator - a == nextAccumulator - b){
                ans = accumulator -a;
                break;
            }
            accumulator = nextAccumulator;
        }
        */
        System.out.println(answer.orElse(0));
        scanner.close();
    }
}

Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
ll Max=INT_MIN;
ll n,k;
ll a[10000000];
ll dis,now;
int main(){
    cin>>k>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int now=a[n-1];
    for(int i=n-2;i>=0;i--){
      dis=abs(now-a[i]);
      now=a[i];
      Max=max(Max,dis);
      //cout<<Max<<endl;
    }
    ll last=a[0]+abs(k-a[n-1]);
    Max=max(Max,last);
    cout<<k-Max;
    return 0;
}


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

int mem[5000][5000], A[5000], B[5000], N, T, S;
int main()
{
  int ans = 0;
  cin >> N >> T >> S;
  for(int i = 1; i <= N; i++)
    cin >> A[i] >> B[i];
    
  for(int n = 1; n <= N; n++)
  {
    for(int t = 1; t <= T; t++)
    {
      mem[n][t] = max(mem[n - 1][t], mem[n][t - 1]);
      if(!(t - B[n] < S && t > S) && t >= B[n])
        mem[n][t] = max(mem[n - 1][t - B[n]] + A[n], mem[n][t]);
    }
  }
  cout << mem[N][T] << endl;
}

Measured memory_bytes: 60140
#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 all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}
int main()
{
    ll x; cin >> x;
    ll n = 100, cnt = 0;
    while(n < x){
        cnt++;
        n *= 1.01;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    double n,m,d;cin >> n >> m >> d;
    double ans;
    if(d != 0)ans = (2*(n-d)*(m-1)) / (n*n);
    else ans = (m-1)/n;



    cout << std::fixed << std::setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
long long int dp[100020] = {};
int main() {
	int m;
	cin >> m;
	cout << 24 + (24 - m);
}

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
l=[b[a[0]-1]]
for i in range(1,n):
    l.append(b[a[i]-1])
    if a[i]==a[i-1]+1:
        l.append(c[a[i]-2])

print(sum(l))

Measured memory_bytes: 3064
for e in iter(input,'0 0'):
 r,_=map(int,e.split())
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=[r-c,c][c>r//2]
  if b>a:a=b
 print(a)


Measured memory_bytes: 6912
#include <stdio.h>

#define N 101

int M[N][N];
int n;
int d[N], v[N], visited[N], time;

void DFS();
void visit(int);

int main(){
  int i, j, x, y, z;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      M[i][j] = 0;
    }
  }

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d %d", &x, &y);

    for(j = 0; j < y; j++){
      scanf("%d", &z);
      M[x-1][z-1] = 1;
    }
  }

  DFS();

  for(i = 0; i < n; i++)
    printf("%d %d %d\n", i+1, d[i], v[i]);

  return 0;
}

void DFS(){
  int i;
  for(i = 0;i < n; i++){
    if(visited[i] == 0)
      visit(i);
  }
}

void visit(int r){
  int i;
  visited[r] = 1;
  d[r] = ++time;

  for(i = 0; i < n; i++){
    if(M[r][i] == 1 && visited[i] == 0)
      visit(i);
  }
  visited[r] = 2;
  v[r] = ++time;
}

Measured memory_bytes: 640
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_K 2501
#define MAX_S 3 * MAX_K

Int K, S;

void input() {
  cin >> K >> S;
}

void solve() {
  Int count = 0;
  loop(x,0,K+1) {
    loop(y,0,K+1) {
      Int z = S - x - y;
      if (0 <= z && z <= K) count++;
    }
  }
  cout << count << endl;
}

int main(void) {
  input();
  solve();
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			if(n%2 != 0) {
				System.out.println("NO");
			}else {
				List<String> list = new ArrayList<>();
				Aun:
				for(int i=0; i<n; i++) {
					String aun = sc.next();
					
					if(aun.equals("A"))	{
						list.add("A");
					}if(aun.equals("Un")) {
						if(list.isEmpty()) {
							System.out.println("NO");
							break Aun;
						}else {
							list.remove(0);
						}
					}
					if(i == n-1 && list.isEmpty()) {
						System.out.println("YES");
					}else if(i == n-1){
						System.out.println("NO");
					}
					
				}
			}
			
			
				
		}
	}
}


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

int main(void) {
  int N;
  cin >>N;
  for(int i=0;i<N;i++){
    string S;
    cin >>S;
    if(S=="Y"){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
  return 0;
}    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

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

  cout<<(n+a+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
def d_face_produces_unhappiness():
    N, K = [int(i) for i in input().split()]
    S = input()
    before_char = S[0]
    t = []
    v = 0
    for s in S + '*':
        if s != before_char:
            t.append(v)
            v = 1
        else:
            v += 1
        before_char = s
    t.sort(reverse=True)
    for i in range(min(K, len(t))):
        t[i] += 2
    return min(sum([e - 1 for e in t]), N - 1)

print(d_face_produces_unhappiness())

Measured memory_bytes: 4728
#include<bits/stdc++.h>
#define ll long long int
#define pi pair<int,int>
#define eps 0.000000001
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second 
#define endl '\n'
#define dbg(x) cout<<#x<<" "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int mod = 1e9+7;
const double PI = acos(-1.0);
const int MAXN = 1e6+5;

void cp()
{
	long double a,b;
	cin>>a>>b;
	ll ans = a*b;
	cout<<ans;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 3744
alp=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
s=list(input())
s_ = list(set(s))
#print(s)
#print(s_)
s.sort()
s_.sort()
#print(s)
#print(s_)
        
l=[]
cnt=0
for i in range(len(alp)):
            if s.count(alp[i]):
                        pass
            else:
                        l.append(alp[i])
                        cnt+=1
#print(l)
if cnt==0:
            print('None')
else:
            print(min(l))
exit()


Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int m,n;
string board[60];string pattern[60];
bool match(int x,int y){
	int i,j;
	for(i=0;i<m;i++)
	for(j=0;j<m;j++)
	if(board[x+i][y+j]!=pattern[i][j])
	return false;
	return true;
}
int main(){
	cin>>n>>m;
	rep(i,n)cin>>board[i];
	rep(i,m)cin>>pattern[i];
	bool found=false;
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)if(match(i,j))found=true;
	cout<<(found?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,n,A[10000+1],q,key,sum = 0;
    
    scanf("%d",&n);
    for(i = 0;i < n;i++) scanf("%d",&A[i]);
    
    scanf("%d",&q);
    for(i = 0;i < q;i++){
        scanf("%d",&key);
        if(search(A,n,key)) sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}


int search(int A[],int n,int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i != n;
}




Measured memory_bytes: 2096
n, k = gets.split(" ").map!{|i| i.to_i}
#puts n
#puts k
nn = gets.split(" ").map!{|i| i.to_i}.sort!
#p nn
#p nn.length

nh = nn.group_by(&:itself).map{ |k, v| [k, v.count] }.to_h

#p nh

ans = 0

if nh.length <= k
  puts 0
else
  narray = nh.values
  narray.sort!
#  p narray
  for i in 0...nh.length - k do
    ans += narray[i]
  end
  puts ans
end


Measured memory_bytes: 64996
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll N,P;
    cin >>N>>P;
    ll ans=1;
    if(N==1){    cout<<P<<endl;return 0;}
      
    FOR(i,2,100000){
      ll count=0;
      while(1){
        if(P%i==0){
          count++;
          P=P/i;
          //cout<<P<<" "<<i<<endl;
        }else{
          break;
        }
      }
      ans=ans*myPow(i,(count/N),MOD);
    }


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


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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};

int main()
{
	f();
	int a,b;cin>>a>>b;
	cout<<(a<=5?0:(a>=13?b:b/2))<<'\n';
	return 0;
}


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

int main(){
    int N;
    char c;
    char alpha[10]={'.','.','a','d','g','j','m','p','t','w'};
    char alpha1[5]={' ','.',',','!','?'};
    cin>>N;
    getchar();
    while(N--){
        int cnt=0,before,now=0;
        while(c=getchar(),c!='\n'){
            before = now;
            now = c-'0';
            if(now!=0)cnt++;
            else if(before==1){
                printf("%c",alpha1[cnt%5]);
                cnt=0;
            }else if(before!=0){
                printf("%c",alpha[before]+(cnt-1)%(before==7||before==9 ? 4 : 3));
                cnt=0;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1144
#!/usr/bin/env python

import sys

n=int( sys.stdin.readline().strip() )
v=[ int(x) for x in sys.stdin.readline().strip().split() ]
v.sort()
ans= v[0]
for i in range(1,n):
    ans= ( ans + v[i] ) / 2.0
#
print( ans )


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

int H, W, K;

int main(){
    int ans = 0;
    char buf;
    cin >> H >> W >> K;
    int N = 0;
    vector<vector<int>> C(H, vector<int>(W, 0));
    for(int h = 0; h < H; ++h){
        for(int w = 0; w < W; ++w){
            cin >> buf;
            if(buf == '#'){
                C[h][w] = 1;
                ++N;
            }
        }
    }
    for(int i = 0; i < pow(2,H); ++i){
        for(int j = 0; j < pow(2,W); ++j){
            int n = N;
            for(int h = 0; h < H; ++h){
                for(int w = 0; w < W; ++w){
                    if( C[h][w] && ( ((i>>h) & 1) || ((j>>w) & 1) ) ) --n; //(i,j)成分は赤色。
                }
            }
            if(n == K) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve()
{
    int l;int r;int d;cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        ans++;
    }
    cout<<ans<<endl;
}
int32_t main()
{
    rapido;
   int t=1;
   while(t--)
   solve();
}

Measured memory_bytes: 3608
operator fun Pair<Int, Int>.plus(pair: Pair<Int, Int>) = Pair(first + pair.first, second + pair.second)
operator fun Pair<Int, Int>.minus(pair: Pair<Int, Int>) = Pair(first - pair.first, second - pair.second)
fun Pair<Int, Int>.manhattanTo(pair: Pair<Int, Int>) = (this - pair).manhattanLength()
fun Pair<Int, Int>.manhattanLength() = Math.abs(first) + Math.abs(second)

private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

private fun List<IntRange>.zipWithIndices() =
        mapIndexed { first, range ->
            range.map { second -> Pair(first, second) }
        }.flatten()

fun main(args: Array<String>) {
    val (H, W, D) = readInts()
    val A = (0 until H).map { readInts() }

    val numberCache = {
        val result = mutableMapOf<Int, Pair<Int, Int>>()
        (0 until H).map { (0 until W) }.zipWithIndices().forEach { pair ->
            val (h, w) = pair
            result[A[h][w]] = Pair(h, w)
        }
        result
    }()

    val mpCache = {
        val result = mutableMapOf<Int, Int>()
        (1 until H * W + 1).forEach { index ->
            val prevIndex = index - D

            result[index] = result[prevIndex]?.let { previous ->
                val diff = numberCache[prevIndex]!!.manhattanTo(numberCache[index]!!)
                previous + diff
            } ?: 0
        }
        result
    }()

    val Q = readLine()!!.toInt()
    (0 until Q).forEach {
        val (L, R) = readInts()
        println(mpCache[R]!! - mpCache[L]!!)
    }
}

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

bool solve();

int main()
{
	if (solve()) puts("YES");
	else puts("NO");

	return 0;
}

bool solve()
{
	int road[4]{};
	for (int i{}; i < 3; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		road[a - 1]++;
		road[b - 1]++;
	}
	for (int i{}; i < 4; i++)
		if (road[i] >= 3)
			return false;
	return true;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
  typedef Point P;
  T x, y;
  explicit Point(T x=0, T y=0) : x(x), y(y) {}
  bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
  bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
  P operator+(P p) const { return P(x+p.x, y+p.y); }
  P operator-(P p) const { return P(x-p.x, y-p.y); }
  P operator*(T d) const { return P(x*d, y*d); }
  P operator/(T d) const { return P(x/d, y/d); }
  T dot(P p) const { return x*p.x + y*p.y; }
  T cross(P p) const { return x*p.y - y*p.x; }
  T cross(P a, P b) const { return (a-*this).cross(b-*this); }
  T dist2() const { return x*x + y*y; }
  double dist() const { return sqrt((double)dist2()); }
  // angle to x-axis in interval [-pi, pi]
  double angle() const { return atan2(y, x); }
  P unit() const { return *this/dist(); } // makes dist()=1
  P perp() const { return P(-y, x); } // rotates +90 degrees
  P normal() const { return perp().unit(); }
  // returns point rotated 'a' radians ccw around the origin
  P rotate(double a) const {
    return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
  friend ostream& operator<<(ostream& os, P p) {
    return os << "(" << p.x << "," << p.y << ")"; }
};

typedef Point<double> P;

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

  int x;
  cin >> x; 

  double rad = x * acos(-1) / 180;
  double eps = 1e-4;
  P p(0, 0), dir(0, 1);
  p = p+dir;
  dir = dir.rotate(rad);

  int ans = 1;
  while (p.dist() > eps) {
    p = p+dir;
    dir = dir.rotate(rad);
    ++ans;
  }

  cout << ans << '\n';



}

Measured memory_bytes: 3948
n = int(input())

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

odd_flg = False
count = 0

while True:
    for i in range(n):
        if a[i] % 2 != 0:
            odd_flg = True

    if odd_flg == True:
        break

    for i in range(n):
        a[i] //= 2

    count += 1

print(count)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();

		List<Integer> list = new ArrayList<Integer>();

		int resultCount = 0;

		for (int i = 0; i < n; i++) {
			final int num = sc.nextInt();
			if (num % 2 == 0) {
				list.add(num);
			} else {
				break;
			}
		}

		if (list.size() != n) {
			System.out.print(resultCount);
			return;
		}

		boolean continueFlag = true;
		while (continueFlag) {
			int count = 0;
			for (int j = 0; j < n; j++) {
				int num = list.get(j);
				if (num % 2 == 0) {
					list.set(j, num / 2);
					count++;
				} else {
					continueFlag = false;
					break;
				}
			}

			if (count == n) {
				resultCount++;
			}
		}

		System.out.print(resultCount);

		sc.close();

	}

}


Measured memory_bytes: 21844
import static java.lang.System.in;
import static java.lang.System.out;

import java.io.*;
import java.util.*;

public class Main {
	static final double EPS = 1e-10;
	static final double INF = 1L << 31;
	static final double PI = Math.PI;

	public static Scanner sc = new Scanner(in);
	StringBuilder sb = new StringBuilder();
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public void run() throws IOException {
		String input;
		String[] inputArray;
		input = br.readLine();
		inputArray = input.split(" ");
		int n = Integer.valueOf(inputArray[0]);
		int m = Integer.valueOf(inputArray[1]);
		int [] mods = new int[m];

		input = br.readLine();
		inputArray = input.split(" ");
		int ans = 0;
		HashSet<Integer> set = new HashSet<Integer>();
		int [] pairs = new int[m];
		for (int i=0; i<n; i++){	
			int x = Integer.valueOf(inputArray[i]);
			if (set.contains(x)){
				set.remove(x);
				pairs[x%m]++;				
			} else{
				set.add(x);
			}
			mods[x%m]++;
		}	
		ans += mods[0]/2;
		for (int i=1; i<(m+1)/2; i++){
			ans += Math.min(mods[i],mods[m-i]);
			if (mods[i]>mods[m-i]){
				ans += Math.min((mods[i]-mods[m-i])/2, pairs[i]);
			} else{
				ans += Math.min((mods[m-i]-mods[i])/2, pairs[m-i]);
			}
		}
		if (m%2==0){
			ans+=mods[m/2]/2;
		}
//		for (int i=0; i<m; i++)
//			sb.append(mods[i] + " ");
//		ln(sb);
		ln(ans);

	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	public static void ln(Object obj) {
		out.println(obj);
	}
}


Measured memory_bytes: 36944
#include<stdio.h>
int n, i;
int a, b;
int r, c, t, j;
int main(){
	scanf("%d%d%d", &n, &a, &b);
	r = 0;
	for(i=1; i<=n; i++){
		c=0; t=i;
		for(j=0; j<5; j++){
			c += t % 10;
			t /= 10;
		}
		if(a<=c && c<=b){r+=i;}
	}
	printf("%d\n", r);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    cout.precision(10);
    std::vector<double>  vt(N,0);
    for(int i=0;i<N;i++){
        cin>>vt[i];
    }
    sort(vt.begin(),vt.end());
    double num=2;
    double sum=0;
    for(int i=N-1;i>=0;i--){
        sum+=(vt[i]/num);
        num=2*num;
    }
    num=num/2;
    sum+=(vt[0]/num);
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back
 
const int MOD = 1000000007;
const int INF = 1e9;
 
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};
 
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a <= 0 && 0 <= b) cout << "Zero" << endl;
    else {
        if(a > 0) cout << "Positive" << endl;
        else if(b < 0) {
            if((a - b) & 1) cout << "Positive" << endl;
            else cout << "Negative" << endl;
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int x,y;
    cin >> x >> y;
    ll sum = 0;
    if(x < 4)sum += (4-x)*100000;
    if(y < 4)sum += (4-y)*100000;
    if(x == y && x == 1)sum += 400000;
    cout << sum << endl;
    return 0;
}

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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

const int MOD = 1e9+7;

pair<int,int> v[3005];
int dp[3005][3005];
bool mark[3005][3005];
int n,t;

int f(int i, int j) {
	if(i == n or j <= 0) return 0;
	if(mark[i][j]) return dp[i][j];
	mark[i][j] = true;
	int ret = f(i+1, j);
	ret = max(f(i+1, j-v[i].ff) + v[i].ss, ret);

	return dp[i][j] = ret;
}

int main() {

	scanf("%d%d", &n, &t);

	for(int i = 0; i < n; i++)
		scanf("%d%d", &v[i].ff, &v[i].ss);

	sort(v, v+n);

	printf("%d\n", f(0,t));


    return 0;
}

Measured memory_bytes: 44544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h,w;
    cin >> h >> w;
    char maze[h][w];
    rep(i,h)rep(j,w) cin >> maze[i][j];

//    dx = [-1,0,1,0];
//    dy = [0,1,0,-1];
    rep(i, h)
    {
		rep(j,w)
		{

			int tmp = 0;
			if (maze[i][j] == '#') continue;
			for (int dx=-1;dx<=1;dx++)
			{
				for (int dy=-1;dy<=1;dy++)
				{
					if (i+dx >= 0 && i+dx < h && j+dy >= 0 && j+dy < w)
					{
						if (maze[i+dx][j+dy] == '#')
						{
							tmp ++;
						}
					}
				}
			}
			maze[i][j] = '0' + tmp;
			// cout << tmp << endl;
		}
    }

    rep(i,h)
	{
		rep(j,w)
		{
			cout << maze[i][j];
		}
		cout << endl;
    }

}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            int min = i;
            for (int k = i; k < n; ++k) {
                if (a[k] < a[min]) min = k;
            }
            if (min != i) {
                int temp = a[i];
                a[i] = a[min];
                a[min] = temp;
                ++swaps;
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");
        System.out.println(swaps);
    }            
}

Measured memory_bytes: 19088
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
long long ans,k,g;
string s;
vector<int> v; 
int main(){
	cin>>s>>k;
	int now=1;
	for(int i=1;i<sz(s);i++){
		if(s[i]!=s[i-1]){
			v.pb(now);
			now=1;
		}else
		now++;
	}
	v.pb(now);
	if(v.size()==1){
		ans=(long long)(sz(s))*k/2;
		cout<<ans;
		re 0;
	}
	for(int i=0;i<sz(v);i++){
		g+=v[i]/2;
	}
	if(s[0]!=s[sz(s)-1]){
		ans=g*k;
		cout<<ans;
	}else{
		v[0]+=v[sz(v)-1];
		ans=g;
		g=0;
		for(int i=0;i<sz(v)-1;i++)
		g+=v[i]/2;
		ans+=g*(k-1ll);
		cout<<ans;
	}
	re 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    long long x[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&x[i]);
    }
    
    long long tmp,ans=LLONG_MAX;
    for (int i=0; i+k-1<n; i++){
        
        if (x[i]*x[i+k-1]>=0){
            tmp=fmax(llabs(x[i]),llabs(x[i+k-1]));
            
            
            
            
        } else if (x[i]*x[i+k-1]<0){
            if ( x[i]*-2+ x[i+k-1] > x[i]*-1+ x[i+k-1]*2 ){
                tmp=x[i]*-1+ x[i+k-1]*2;
            } else {
                tmp=x[i]*-2+ x[i+k-1];
            }
        }
        
        
        
        
        
        if (ans>tmp){
            ans=tmp;
        }
    }
    printf("%lld\n",ans);
	return 0 ;
}

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

using namespace std;
int N,L,Q;
int x[100001];
int dp[100001][18];
int main() {
  cin >> N;

  for(int i = 0; i < N; i++) cin >> x[i];

  cin >> L;

  for(int i = 0; i < N; i++) {
    dp[i][0] = (upper_bound(x,x+N,x[i]+L) - x) - 1;
  }

  for(int j = 1; j < 18; j++) {
    for(int i = 0; i < N; i++) {
      dp[i][j] = dp[dp[i][j-1]][j-1];
    }
  }

  cin >> Q;

  for(int i = 0; i < Q; i++) {
   
    int a,b;
    int ans = 0;
    cin >> a >> b;
    a--;b--;
    if(a > b) swap(a,b);

    for(int i = 17; i >= 0; i--) {
      if(dp[a][i] < b) {
	a = dp[a][i];
	ans += (1 << i);
      }
    }
    cout << ans + 1 <<endl;
  }
}
    
  


Measured memory_bytes: 8192
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define rforn(a, n) for(int a = (n)-1; a>=0; --a)
using namespace std;
const int N = 6e5+20;

int main()
{
    int n, a, b;
    cin>>n>>a;
    b=n;
    if (a<b)b--;
    cout<<b<<endl;

}

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

bool is_PrimeNumber(int x){
    bool Prime=true;
    rep(i,(int)sqrt(x)){
        if((i+2)!=x&&x%(i+2)==0)Prime=false;
    }
    return Prime;
}


int main(){
    int Q;
    cin>>Q;
    int ans[100001];
    ans[0]=0;
    ans[1]=0;
    ans[2]=0;
    rep(i,99998){
        if(is_PrimeNumber(i+3)&&is_PrimeNumber((i+4)/2))ans[i+3]=ans[i+2]+1;
        else ans[i+3]=ans[i+2];
    }
    rep(i,Q){
        int l,r;
        cin>>l>>r;
        cout<<ans[r]-ans[l-1]<<endl;
    }
    return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double ans = 0;
    x /= a;
    if (x >= a*b/2.0) {
        ans = atan2(b-x/a, a/2);
    }
    else {
        ans = atan2(b, x/b*2.0);
    }
    ans = ans / PI * 180.0;
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 4112
'use strict'
const main = (input) => {
    input = input.split('\n')
    let temp = input[0].split(' ').map(i => parseInt(i))
    const N = temp[0]
    const M = temp[1]
    temp = input.slice(1, M + 1)
    let arr = []
    let aMap = new Map
    temp.forEach((v) => {
        let tmp = v.split(' ').map(i => parseInt(i))
        aMap.set(tmp[1], 0)
        if(arr[tmp[0]] === undefined){
            arr[tmp[0]] = []
        }
        arr[tmp[0]].push(tmp[1])
    })

    arr.forEach((v, i) => {
        v.sort((a, b) => a - b)
        v.forEach((num, j) => {
            let def = ('000000' + i.toString(10)).slice(-6) + ('000000' + (j + 1).toString(10)).slice(-6)
            aMap.set(num, def)
        })
    })
    aMap.forEach(val => console.log(val))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 77552
N=int(input())
S=input()
ans=0

first={}
last={}

def dfs(r,b,num):
    if num==N:
        if (r,b) not in first:
            first[(r,b)]=0
        first[(r,b)]+=1
        return 0

    if len(r)<N:
        dfs(r+S[num],b,num+1)

    if len(b)<N:
        dfs(r,S[num]+b,num+1)

dfs("","",0)

def dfs2(r,b,num):
    if num==2*N:
        if (r,b) not in last:
            last[(r,b)]=0
        last[(r,b)]+=1
        return 0

    if len(r)<N:
        dfs2(r+S[num],b,num+1)

    if len(b)<N:
        dfs2(r,S[num]+b,num+1)

dfs2("","",N)

for r,b in first:
    if (b,r) in last:
        ans+=first[(r,b)]*last[(b,r)]
        
print(ans)


Measured memory_bytes: 174456