akhauriyash/Code-Regression huggingface dataset:
def Technique_often_used():    
    # enumerate: for i, a in enumerate(a_list):
    # q, mod = divmod(a, b)
    # Functional Programming: filter, map, reduce
    pass
def naming_conventions():
    # [s_1, s_2, s_3, ..., s_k] is named s_k
    # [[s_11, s_12, ..., s_1k], ..,[s_j1, s_j2, ..., s_jk] is named s_jk
    # [[b1,c1],[b2,c2],..,[bm,cm]] is named bc
    # if there is something strange in a list then I add _ to the list's name (ex:s_jk_)
    pass
def visual_studio_code_shortcut():    
    # visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
    # delete line: Ctrl+Shift+k
    # choose same words: Ctrl+Shift+l
    pass
import sys
from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers): #
    return reduce(lcm, numbers, 1)
    
# toggle test environment
is_test = False
def debug_print(value,comments="",is_test=is_test):
    # print() for test environment
    # debug_print([]) => []
    # debug_print("") => 
    # debug_print(a, "a is") => "a is:" print(a)
    if not is_test:
        pass
    elif not comments and value is None:
        print("")
    elif not comments:
        print(value)
    else:
        print(comments,":",value)

# set the inputs
if is_test:
    n,m = [3, 2]
    a = [5, 1, 4]
    bc = [[2,3],[1,5]]
else:
    # open(0).read() is a convenient method: 
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    R = lambda: map(int, input().split())
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]
    n,m = R()
    a = list(R())
    bc = [list(R()) for i in range(m)]

a = sorted(a,reverse=True)
bc = sorted(bc, key=lambda x:x[1],reverse=True)
count = 0
cs = []
for b,c in bc:
    cs.extend([c]*b)
    count += b
    if count >= n:
        break
a.extend(cs)
print(sum(sorted(a,reverse=True)[:n:]))

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    long long A, B, N;
    cin >> N >> A >> B;
    long long times = N / (A+B);
    long long amari = N % (A+B);
    if(amari > A){
        cout << times*A + A << endl;
    } else {
        cout << times*A + amari << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

/**
  辺
  to: 辺の行き先
  cost: 辺の重み
  T: 重みの型
*/
template <typename T = int>
struct Edge {
  int to;
  T cost;
  Edge(int to, T cost) : to(to), cost(cost) {}
};

/**
  n: 頂点数
  graph: グラフ本体
*/
template <typename T = int>
class Graph {
  public:
    int n;
    vector<vector<Edge<T>>> graph;

    Graph(int n) {
      this->n = n;
      this->graph.assign(n, vector<Edge<T>>());
    }

    void addEdge(int from, int to, T cost) {
      this->graph[from].push_back(Edge<T>(to, cost));
    }

    bool existEdge(int from, int to) {
      for(auto e : this->graph[from]) {
        if(e.to == to) return true;
      }
      return false;
    }

    void add() {
      rep1(i, this->n) rep1(j, this->n) {
        if(i >= j) continue;
        // i < j
        if(!this->existEdge(i, j)) {
          this->addEdge(i, j, 1);
          return;
        }
      }
    }

    int m() {
      int edges = 0;
      rep(i, this->n) {
        for(auto e : this->graph[i]) {
          edges++;
        }
      }
      return edges;
    }
};

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

  if((n-1)*(n-2)/2 < k) {
    cout << -1 << endl;
    return 0;
  }

  Graph<int> g = Graph<int>(n);
  rep1(i, n) {
    g.addEdge(0, i, 1);
  }

  for(int i=(n-1)*(n-2)/2; i>k; i--) {
    g.add();
  }

  cout << g.m() << endl;

  rep(i, n) {
    for(auto e : g.graph[i]) {
      cout << i+1 << " " << e.to+1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
//#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111




	void solve(){


		
		ins(morty);
		ins(morty1);
		if(morty1.size()!=morty.size()+1)return out("No");
		FOR(i,0,morty.size()){
			if(morty1[i]!=morty[i])return out("No");
		}
		out("Yes");
		









	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long long k;
    std::cin >> k;

    std::string s;
    std::cin >> s;

    if (s.length() <= k) {
        std::cout << s << std::endl;
    } else {
        std::cout << s.substr(0, k) << "..." << std::endl;
    }
}


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

int N;

int count_bound(vector<int> &L,int X) {
    vector<int> D(N + 1, 0);
    for (int i = 1; i < N + 1; i++) {
        D[i] = D[i - 1] + L[i - 1];
    }

    auto itr = lower_bound(D.begin(), D.end(), X);
    int count = distance(D.begin(), itr);
    if (*itr == X) {
        count++;
    }

    return count;
}

int main() {
    int X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &L[i]);
    }

    int ans = count_bound(L, X);

    cout << ans << endl;

    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] vs = new long[n];
		for (int i = 0; i < n; i++) {
			vs[i] = sc.nextLong();
		}

		long a = 0;
		for (int l = 0; l <= k; l++) {
			for (int r = 0; r <= k - l; r++) {
				if (l + r > n) continue;
				int d = k - l - r;
				int current = 0;
				List<Long> s = new ArrayList<>();

				for (int i = 0; i < l; i++) {
					current += vs[i];
					s.add(vs[i]);
				}

				for (int i = 0; i < r; i++) {
					current += vs[(n - 1 - i)];
					s.add(vs[(n - 1 - i)]);
				}

				if (d > 0) {
					Collections.sort(s);
				}
				for (int i = 0; i < d; i++) {
					if (i >= s.size()) break;
					if (s.get(i) >= 0) break;
					current -= s.get(i);
				}

				a = Math.max(a, current);
			}
		}

		System.out.println(a);
	}
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        vl A(n);
        rep(i,n)cin>>A[i];
        vl Ans(0);
        rep(i,n){
            ll check=-1;
            rep(j,Size(A)){
                if(A[Size(A)-1-j]==Size(A)-j){
                    Ans.pb(Size(A)-j);
                    check=Size(A)-1-j;
                    break;
                }
            }
            if(check==-1){
                cout<<-1<<endl;
                return 0;
            }
            A.erase(A.begin()+check);
        }
        reverse(all(Ans));
        rep(i,n)cout<<Ans[i]<<endl;
    }

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#include "string"
//#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)
const int N = 1e5 + 1;
int n,a,b,c;
vector<string>s;
int dp[N][4][4][4];

int go(int id,int a,int b,int c){
	if(a<0 or b<0 or c<0)
		return 0;
	a = min(a,3); b = min(b,3);c = min(c,3);
	if(id>=n){
		dp[id][a][b][c]=1;
		return 1;
	}

	int &tmp = dp[id][a][b][c];
	if(tmp !=-1)
		return tmp;
	tmp = 0;
	if(s[id] == "AB"){
		tmp |= go(id+1,a+1,b-1,c);
		tmp |= go(id+1,a-1,b+1,c);
	}
	else if(s[id] == "AC"){
		tmp |= go(id+1,a+1,b,c-1);
		tmp |= go(id+1,a-1,b,c+1);
	}
	else{
		tmp |= go(id+1,a,b+1,c-1);
		tmp |= go(id+1,a,b-1,c+1);
	}
	return tmp;
}

void trace(int id,int a,int b,int c){
	if(id>=n)
		return;
	a = min(a,3); b = min(b,3);c = min(c,3);
	if(s[id] == "AB"){
		if(a<3 && b>0 && dp[id+1][a+1][b-1][c]==1){
			cout<<'A'<<endl;
			trace(id+1,a+1,b-1,c);
		}
		else{
			cout<<'B'<<endl;
			trace(id+1,a-1,b+1,c);
		}
	}
	else if(s[id] == "AC"){
		if(a<3 && c>0 && dp[id+1][a+1][b][c-1] == 1){
			cout<<'A'<<endl;
			trace(id+1,a+1,b,c-1);
		}
		else{
			cout<<'C'<<endl;
			trace(id+1,a-1,b,c+1);
		}
	}
	else{
		if(b<3 && c>0 && dp[id+1][a][b+1][c-1] == 1){
			cout<<'B'<<endl;
			trace(id+1,a,b+1,c-1);
		}
		else{
			cout<<'C'<<endl;
			trace(id+1,a,b-1,c+1);
		}
	}
}

int32_t main(){ 
    boost;
    cin>>n>>a>>b>>c;
    s.resize(n);
    for(int i=0;i<n;i++)
    	cin>>s[i];
    memset(dp,-1,sizeof dp);
    if(go(0,a,b,c)){
    	cout<<"Yes"<<endl;
    	trace(0,a,b,c);
    }
    else
    	cout<<"No"<<endl;
}


Measured memory_bytes: 40712
/* Fairy dandy tickling the fancy of his lady friend */

#include <iostream>

#include <vector>

#include <algorithm>

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)

#define rep(i,a,b) for(int i=int(a); i<int(b); i++)

#define rip(i,a,b) for(int i=(int)a; i>=(int)b; i--)

#define pb push_back

#define mp make_pair

#define fst first

#define snd second

#define sz(x) int(x.size())

#define all(v) (v).begin(), (v).end()

#define trace(x) cerr << #x << ": " << x <<endl;



using namespace std;



typedef long long int lli;

typedef pair<lli, lli> ii;

typedef vector<int> vi;

typedef vector<ii> vii;



int main(){

    fastio;

	lli a, b; cin>>a>>b;
	lli k;
	if((a+b)%2==0) cout<<(a+b)/2;
	else cout<<"IMPOSSIBLE";
	cout<<endl;

    return 0;

}

Measured memory_bytes: 256
import Queue, sys
INF = 10**9+7
n = input()
p = []
for i in xrange(n):
    p.append(int(raw_input()))
dist = [10**7] * n
calc = [-1] * n
used = [False] * n
que = Queue.PriorityQueue()
que.put((0, 0))
dist[0] = 0
while not que.empty():
    co, v = que.get()
    if dist[v] < co:
        continue
    for k in xrange(1, 7):
        go = v+k
        if go>=n:
            break
        if p[go] != 0:
            if calc[go]==-1:
                path = []
                while True:
                    if p[go]==0:
                        break
                    if calc[go]!=-1:
                        go = calc[go]
                        break
                    if used[go]:
                        go = INF
                        break
                    used[go] = True
                    path.append(go)
                    go += p[go]
                for e in path:
                    calc[e] = go
            else:
                go = calc[go]
            if go==INF:
                continue
        if go==n-1:
            print dist[v]+1
            exit(0)
        if dist[v] + 1 < dist[go]:
            dist[go] = dist[v] + 1
            que.put((dist[go], go))

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

int main (int argc,char **argv)
{
	char s[4];
	char c;
	int i = 0;
	int j = 0;
	

	scanf("%s",s);

	for (i = 0;i < 3;i ++)
	{
		c = s[i];
		if (c == '1')
		{
			j++;
		}
	}

	printf("%d\n",j);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;


int main(void) {

	long long a;
	long long b;
	cin >> a >> b;


	if (a== 0) {
		cout << 0;
		return 0;
	}

	if ((a % b) == 0) {
		cout << 0;
		return 0;
	}

	long long amari = (a % b);
	long long amari2 = (amari - b) * -1;

	if (amari <= amari2) {
		cout << amari;
	}
	else {
		cout << amari2;
	}




}




Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int i,n,q,a,v,aaa=0,vvv=0,f[1000000];
	scanf("%d %d",&n,&q);
	for(i=n;i>0;i--)f[i-1]=0;
	for(;q>0;q--){
		scanf("%d %d",&a,&v);
		f[a-1]+=v;
		if(v>0){
			if(f[a-1]>vvv || (f[a-1]==vvv && a<aaa)){vvv=f[a-1];aaa=a;}
		}
		else{
			if(a==aaa){
				aaa=0;vvv=0;
				for(i=n-1;i>=0;i--){if(f[i]>=vvv){vvv=f[i];aaa=i+1;}}
			}
		}
		printf("%d %d\n",aaa,vvv);
	}
}

Measured memory_bytes: 4504
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 401;
const int logN = 19;

ll st[N<<1];
ll maxrange(int l,int r) {
    ll ret = 0;
    for(;l<r;l>>=1,r>>=1) {
        if(l&1) ret = max(ret,st[l++]);
        if(r&1) ret = max(ret,st[--r]);
    }
    return ret;
}
void update(int i,ll val) {
    for(st[i]=val,i>>=1;i>0;i>>=1) {
        st[i] = max(st[i<<1],st[i<<1|1]);
    }
}
void solve() {
    int n;
    cin>>n;
    vector<int> h(n+1), a(n+1);
    REP(i,1,n) {
        cin>>h[i];
    }
    REP(i,1,n) {
        cin>>a[i];
    }
    ll d, ans = 0;
    REP(i,1,n) {
        d = a[i] + maxrange(n,n+h[i]-1);
        update(n+h[i]-1,d);
        ans = max(ans,d);
    }
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

int main() {
  
  int n;
  cin >> n;
  
  vector<int> d(n);
  for ( int i = 0; i < n; i++){
    cin >> d[i];
  }
  
  sort(d.begin(),d.end());
  
  int mid = ( 1 + n ) / 2;
  
  cout << d[mid] - d[mid-1] << endl;
  
}

Measured memory_bytes: 640
//                          **********  YATIN KWATRA  ********** 

//AC bakshi Rabha

#include <bits/stdc++.h>
#define ll                      long long 
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795
// #define node                    Node

using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}


void solve()
{ 
        ll n;
        cin >> n;
        
        vll v1(n),v2(n);
        
        fo(i,0,n-1) cin >> v1[i] >> v2[i];

        sort(all(v1));
        sort(all(v2));


        ll Y,Z;

        if(n&1)
        {
            Y = v1[n/2];
            Z = v2[n/2];
        }
        else
        {
            Y = v1[n/2]+v1[(n-1)/2];
            Z = v2[n/2]+v2[(n-1)/2];
        }

        cout << (Z-Y+1) << endl;
        
       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
 //   cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 6368
#include <stdio.h>

int main(void)
{
	int S,T,inf,math,sci,en;
	scanf("%d %d %d %d",&inf,&math,&sci,&en);
	S=inf+math+sci+en;
	scanf("%d %d %d %d",&inf,&math,&sci,&en);
	T=inf+math+sci+en;
	if(S>=T) printf("%d\n",S);
	else printf("%d\n",T);
	return 0;
}

Measured memory_bytes: 592
//B-Increment_Decrement
#include <bits/stdc++.h>
using namespace std;

int main(){
  int saidai=0,x=0,n;
  char s;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=='I') x++;
    else x--;

    saidai=max(saidai,x);
  }

  cout<<saidai<<endl;
  return 0;
}


Measured memory_bytes: 256
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 23 Apr 2020
*/

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long

int DP[100005];
int fun(vector<int>&H, int ind){
	if(DP[ind] != -1){
		return DP[ind];
	}
	if(ind==0){
		return 0;
	}
	int pos1=INT_MAX, pos2 = INT_MAX;
	if(ind-1>=0){
		int val1 = abs(H[ind] - H[ind-1]);
		pos1 = val1 + fun(H,ind-1);
	}
	if(ind-2>=0){
		int val2 = abs(H[ind] - H[ind-2]);
		pos2 = val2 + fun(H,ind-2);
	}

	return DP[ind] = min(pos1, pos2);
}

/* MEMO

signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(--t>=0){
    	int n;
    	cin>>n;
    	vector<int>H(n);
    	memset(DP,-1,sizeof(DP));
    	for(int i=0;i<n;i++) cin>>H[i];
    	cout<<fun(H,n-1);
    }

    return 0;
}

*/

/* BOTTOM-UP */

signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(--t>=0){
    	int n;
    	cin>>n;
    	vector<int>H(n);
    	int dp[n];

    	for(int i=0;i<n;i++) cin>>H[i];
    		
    	dp[0] = 0;
    	dp[1] = abs(H[1] - H[0]);

    	for(int i=2;i<n;i++){
    		int val1 = INT_MAX;
    		int val2 = INT_MAX;
    		if(i-1>=0){
    			val1 = abs(H[i] - H[i-1]);
    		}
    		if(i-2>=0){
    			val2 = abs(H[i] - H[i-2]);
    		}
    		dp[i] = min(dp[i-1] + val1, dp[i-2] + val2);
    	}
    	cout<<dp[n-1];
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

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


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

int main(){
    string word;
    stack<int> s;
    int a,b;
    while(cin>>word){
        if(word=="+"){
            a=s.top();
            s.pop();
            b=s.top();
            s.pop();
            s.push(a+b);
        }
        else if(word=="-"){
            a=s.top();
            s.pop();
            b=s.top();
            s.pop();
            s.push(b-a);
        }
        else if(word=="*"){
            a=s.top();
            s.pop();
            b=s.top();
            s.pop();
            s.push(a*b);
        }
        else{
            a=atoi(word.c_str());
            s.push(a);
        }
    }
    cout<<s.top()<<endl;
}


Measured memory_bytes: 3176
#include<stdio.h>
int main()
{
    int a[3],i,j,count=0;
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    for(i=0;i<3;i++)
    {
        for(j=i;j<3;j++)
        {
            if(a[i]>a[j])
            {
                int temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    count=(a[2]-a[1])+(a[1]-a[0]);
    printf("%d\n",count);
    return 0;



}




Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        WriteLine(Min(GetC(ar, true), GetC(ar, false)));
    }

    private static long GetC(int[] ar,bool isP)
    {
        var result = 0L;
        var sum = 0L;
        for(var i = 0; i < ar.Length; i++)
        {
            sum += ar[i];
            if (isP)
            {
                if (sum <= 0) { result += 1 - sum; sum = 1; }
            }
            else
                if (sum >= 0) { result += 1 + sum; sum = -1; }
            isP = isP ? false : true;
        }
        return result;
    }
}


Measured memory_bytes: 28892
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll zer = 0;

//----------------------------------------------
ll mx;
vector<ll> fac(200005);
vector<ll> ifac(200005);

//modpow
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

//二項係数を求める
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a - b] * ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

//facとifacの前処理
void pre_comb(ll n){
    fac[0] = 1;
    ifac[0] = 1;
    rep(i, n){
        fac[i + 1] = fac[i] * (i + 1) % MOD;
        ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
    }
}
//----------------------------------------------

int main(){
    ll n, k;
    cin >> n >> k;
    ll l = 0, r = 0;
    ll res = 0;
    rep(i, k){
      l += i;
      r += (n - i);
    }
    REP(i, k, n + 1){
      res = (res + r - l + 1) % MOD;
      l += i;
      r += (n - i);
    }
  cout << res << endl;
}





Measured memory_bytes: 6228
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int i,n,k,d,m,ans;
    cin>>n>>k;
    int out[10];
    for(i=0; i<10; i++){
        out[i]=0;
    }
    
    for(i=0; i<k; i++){
        cin>>d;
        out[d]=1;
    }
    ans=n;
    while(1){
        m=ans;
        while(1){
            if(out[m%10]==1){
                break;
            }
            m/=10;
            if(m==0){
                cout<<ans<<endl;
                return 0;
            }
        }
        ans++;
    }
}

Measured memory_bytes: 256
import math

N = int(input())
p, q, r = 1, 1, N
if N % 2 == 0:
    p = 2
    q = 3
n = int(math.sqrt(N))
while q <= n:
    if N % q == 0:
        p = q
    q += 1
ans = len(str(N//p))

print(ans)

Measured memory_bytes: 3060
#import matplotlib.pyplot as plt

def main():
    a,b,n = map(int,input().split())
    x = min(b-1,n)



    print(int(a*x/b) - a * int(x/b))


    #plt.plot(list(range(len(right))),right,label="test")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61808
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    string s,t; cin>>s>>t;
    int ans = 0;
    if(s[0]==t[0]) ans++;
    if(s[1]==t[1]) ans++;
    if(s[2]==t[2]) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n= gets.to_i
a=gets.chomp.split(" ").map(&:to_i);
tmp = 0
c = 0
n.times do |i|
  if a[i] == tmp then
    if tmp != 1 && a[i+1] != 1 then
      a[i] = 1
    elsif a[i+1] != 2 then
      a[i] = 2
    else
      a[i] = 3
    end
    c += 1
  end
  tmp = a[i]
end
puts c


Measured memory_bytes: 1788
#include <stdio.h>
int main(void)
{
	int n,a[3001],i,m=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
		m=m+a[i];
	}
	printf("%d\n",m-n);
	return 0;
}

Measured memory_bytes: 128
from copy import copy
def solve():
    S = input()
    K = int(input())
    ans = 0
    seqs = []
    seq = 1
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
    seqs.append(seq)
    first_seq = seqs[0]
    last_seq = seqs[-1]
    seqs.pop(0)
    if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
    return ans
print(solve())

Measured memory_bytes: 9316
#include <stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    long long int a[n];
    int res=0,flag=1;
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    while(flag){
        for(int i=0;i<n;i++){
            if(a[i]%2==0){
                a[i]/=2;
            }else{
                flag=0;
            }
        }
        if(flag==0){
            break;
        }else{
            res++;
        }
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int d[100005], a[100005];
int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    d[1] = 0;
    for(int i = 2; i <= n; ++i) {
            d[i] = d[i - 1] + abs(a[i] - a[i - 1]);
            for(int j = 2; i - j >= 1 && j <= k; ++j) d[i] = min(d[i], d[i - j] + abs(a[i] - a[i - j]));
    }
    cout << d[n];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n,m,c;
    cin>>n>>m>>c;
    vin b(m);
    rep(i,m)cin>>b[i];
    vvin a(n,vin(m));
    rep(i,n){
        rep(j,m)cin>>a[i][j];
    }
    vin s(n);
    rep(i,n)s[i]=c;
    int sum=0;
    rep(i,n){
        rep(j,m)s[i]+=a[i][j]*b[j];
        if(s[i]>0)sum++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s ;
    int cntr=0;
    cin >> s;
    int j= s.size()-1;
    for(int i = 0 ; i < (s.size()/2) ;i++)
    {
        if(s[i]!=s[j])
        {
           cntr++;
        }
        j--;
    }
    cout << cntr ;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
SUM = sum(A)
MIN = min(A)
start = A.index(MIN)

dp = [0]*n
dp[start] = cnt = 0
for i in range(start+1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]
else:
    for i in range(start):
        dp[i] = 2*A[i-1]-dp[i-1]
        cnt += dp[i]

odd = SUM-cnt
dp = [0]*n
dp[start] = cnt = odd
for i in range(start+1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]
else:
    for i in range(start):
        dp[i] = 2*A[i-1]-dp[i-1]
        cnt += dp[i]

print(*dp)

Measured memory_bytes: 14032
#include<iostream>

using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;

	if (a >= b) {
		cout << "delicious";
	}
	else if (x >= b - a) {
		cout << "safe";
	}
	else {
		cout << "dangerous";
	}
}

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let _n = get!(usize);
    let mut cs = vec![0; 9];
    for s in get!(String).split_whitespace() {
        let a = s.parse::<i32>().unwrap();
        let i = cmp::min(8, a / 400) as usize;
        cs[i] += 1;
    }
    let min_c = cs.iter().take(8).fold(0, |a, &n| if n > 0 { a + 1 } else { a });
    let max_c = min_c + cs[8];
    println!("{} {}", cmp::max(1, min_c), max_c);
}

Measured memory_bytes: 4352
A,B,C,X = 4.times.map { gets.to_i }
c = 0
(0..A).each do |i|
  (0..B).each do |j|
    (0..C).each do |k|
      c += 1 if i*500 + j*100 + k*50 == X
    end
  end
end
p c

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define int long long

#define INF 1e+9
#define MAX_V 100008



int V;
int N;
vector<vector<int>> G;
int d[MAX_V];

signed main() {
    cin >> V;
    N = V;
    int E;
    cin >> E;
    G.resize(V);
    for (int i=0; i<E; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N, -1); 
    queue<int> que;
    vector<int> prever(N,-1);
    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            prever[nv] = v;
            que.push(nv);
        }
    }

    cout << "Yes" << endl;
    for (int v = 1; v < N; ++v)cout << prever[v] + 1 << endl;    
} 




Measured memory_bytes: 13772
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  int n;
  scanf("%d", &n);
  int r = 30;
  while(n--) {
    int t;
    scanf("%d", &t);
    int a = 0;
    while(t%2==0) {
      a++;
      t /= 2;
    }
    r = min(r, a);
  }
  printf("%d\n", r);
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    g = []
    for i in range(n):
        g.append([p[i], i])
    g.sort()  # p[i]でsort()している

    uf = UnionFind(n)
    for i in range(m):
        x, y = map(int, input().split())
        uf.unite(x - 1, y - 1)

    ans = 0
    for i in range(n):
        if uf.same(i, g[i][1]):  # インデックスと数の親が仁いい場合は+1
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22724
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(v) v.begin(),v.end()
#define mod 1000000007


int main(){
  ll n;
  cin  >> n;
  ll a[5]={0};
  ll small=10000000000000000;
  rep(i,5){
    cin >> a[i];
    if(a[i]<small){
      small=a[i];
    }
  }
  ll time=5;
  if(n%small!=0){
    time+=n/small;
  }
  else if(n%small==0){
    time+=n/small-1;
  }
  cout << time <<endl;
}


Measured memory_bytes: 384
// Created by Nikolay Budin

#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }

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

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> field(n, vector<int>(m));
	queue<pii> qu;
	vector<vector<int>> dist(n, vector<int>(m, INF));
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < m; ++j) {
			field[i][j] = s[j] == '#';
			if (field[i][j]) {
				dist[i][j] = 0;
				qu.push({i, j});
			}
		}
	}

	while (szof(qu)) {
		int x, y;
		tie(x, y) = qu.front();
		qu.pop();

		for (int d = 0; d < 4; ++d) {
			int nx = x + dx[d];
			int ny = y + dy[d];
			if (0 <= nx && nx < n && 0 <= ny && ny < m && dist[nx][ny] > dist[x][y] + 1) {
				dist[nx][ny] = dist[x][y] + 1;
				qu.push({nx, ny});
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = max(ans, *max_element(dist[i].begin(), dist[i].end()));
	}

	cout << ans << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 16400
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  
  vector<vector<int>> t(N);
  vector<P> e;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    
    t.at(a).push_back(b);
    t.at(b).push_back(a);
    e.push_back(make_pair(a, b));
  }
  
  int maxNum = -1;
  for (int i = 0; i < N; i++) {
    int num = t.at(i).size();
    if (num > maxNum) {
      maxNum = num;
    }
  }
  cout << maxNum << endl;
  
  queue<int> q;
  q.push(0);
  vector<bool> used(N, false);
  used.at(0) = true;
  vector<int> color(N, 0); // parent color
  map<P, int> m;
  
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    
    int c = 1;
    for (int to : t.at(v)) {
      if (used.at(to)) continue;
      if (color.at(v) == c) c++;
      color.at(to) = m[make_pair(to, v)] = m[make_pair(v, to)] = c;
      c++;
      used.at(to) = true;
      q.push(to);
    }
  }
  
  for (auto p : e) {
    cout << m[p] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 19700
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
d,e = list(map(int, input().split()))
if (d in a and e in a) or (d in b and e in b) or (d in c and e in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

    string s;
    cin >> s;

    ll ans = 0;
    rep(i, s.size()){
        char cpr;
        cpr = (i%2)?('0'):('1');
        if(s[i] != cpr) ans ++;
    }

    cout << min(ans, (ll)(s.size()-ans)) << endl;



    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void) {
  int h,w,i;
  char a[111];
  scanf("%d%d",&h,&w);
  for(i=0;i<=w+1;i++) {
    printf("#");
  }
  printf("\n");
  for(i=0;i<h;i++) {
    scanf("%s",a);
    printf("#%s#\n",a);
  }
  for(i=0;i<=w+1;i++) {
    printf("#");
  }
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func readStr() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	_, m := readInt(), readInt()
	ans := make(map[int]int)
	ac, pr := 0, 0
	for i := 0; i < m; i++ {
		p, s := readInt(), readStr()
		if _, ok := ans[p]; !ok {
			if s == "AC" {
				ans[p] = 0
				ac++
			} else {
				ans[p] = 1
			}
			continue
		}

		if ans[p] > 0 {
			if s == "AC" {
				pr += ans[p]
				ans[p] = 0
				ac++
				continue
			}
			ans[p]++
		}
	}
	fmt.Println(ac, pr)
}


Measured memory_bytes: 6912
import numpy as np
import sys

def debug(*args, **kwargs):
    sys.stderr.write(*args, **kwargs)

N,M = map(int,input().split())

A = np.zeros(N, dtype=np.int)
B = np.zeros(N, dtype=np.int)

for i in range(N):
    A[i],B[i] = list(map(int,input().split()))

all_sum = B.sum()

arg_sorted = np.argsort(A)

sum_amount = 0
sum_money = 0
to_break = False
# print(M)
for i in arg_sorted:
    if B[i] > M-sum_amount:
        to_break = True
    lot = min(B[i], M-sum_amount)

    sum_money += A[i]*lot
    sum_amount += lot
    # print(i, A[i], sum_amount, sum_money)

    if to_break:
        break


print(sum_money)

Measured memory_bytes: 14820
num = list(map(int, input().split()))

W = num[0]
H = num[1]
x = num[2]
y = num[3]
r = num[4]

if(( x + r <= W ) and ( x - r >= 0 ) and (y + r <= H) and (y - r >= 0)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7664
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int T = scanner.nextInt();
        double A = (double) scanner.nextInt();

        Map<Integer, Double> map = new TreeMap<>();

        for (int i = 0; i < N; i++) {
            map.put(i + 1, Math.abs(A - (T - (scanner.nextInt() * 0.006))));
        }

        System.out.println(map.entrySet().stream().sorted(Map.Entry.comparingByValue()).findFirst().get().getKey());
    }
}

Measured memory_bytes: 28880