akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
const double PI = acos(-1);
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string t;
  cin >> t;
  FOR(i, 0, sz(t)) cout << (t[i]=='P'?'P':'D');
  cout << endl;
}

Measured memory_bytes: 3736
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return


# inputs
N = 0


def set_inputs():
    global N
    N = get_int()
    return


def find(n):
    bits = []
    for i in range(2**(n*(n-1)//2)):
        bits = [(i >> j) % 2 for j in range(n*(n-1)//2)]
        cnt = Counter()
        for j in range(1, n+1):
            cnt[j] = 0
        edges = []
        for x, y in itertools.compress(
                itertools.combinations(range(1, n+1), 2),
                bits
        ):
            cnt[x] += y
            cnt[y] += x
            edges.append((x, y))
        counts = list(cnt.values())
        if len(edges) > 0 and all(v == counts[0] for v in counts):
            print(i, bits, edges)


def solve(n):
    s = n
    if n % 2 == 0:
        s = n + 1
    print(n * (n - 1) // 2 - (n // 2))
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i + j == s:
                continue
            print(i, j)


def main():
    setrecursionlimit(100000)
    set_inputs()
    solve(N)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 44528
#include <iostream>
#include <algorithm>
#include<iomanip>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int a, b, c, d, p, x, y;
	cin >> a >> b >> c >> d >> p;
	x = p * a;
	if (p > c)y = (p - c) *d + b;
	else y = b;
	cout << min(x, y) << endl;
	return 0;
}

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

using namespace std;

int main() {
    int s;
    cin >> s;
    int L = s / 100;
    int R = s % 100;
    if (1 <= L && L <= 12) {
        if (1 <= R && R <= 12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    } else {
        if (1 <= R && R <= 12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
a=input()
if 'hi'*5==a:
    print('Yes')
elif 'hi'*4==a:
    print('Yes')
elif 'hi'*3==a:
    print('Yes')
elif 'hi'*2==a:
    print('Yes')
elif 'hi' == a:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N)
  {
    cin >> P[i];
  }
  int ans = 0;
  int curMin = 1e9; // 10の9乗
  rep(i, N)
  {
    curMin = min(curMin, P[i]);
    if (curMin == P[i]) // 最小値は自分でなければならない
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	deque<int> b;
	for(int i = 0; i < n; i++)
	{
		if(i % 2 == 0) b.push_back(a[i]);
		if(i % 2 != 0) b.push_front(a[i]);
	}
	if(n % 2 == 0)
	{
		for(int i = 0; i < n - 1; i++)
		{
			cout << b[i] << " ";
		}
		cout << b[n - 1] << endl;
	}
	else
	{
		for(int i = n - 1; i >= 1; i--)
		{
			cout << b[i] << " ";
		}
		cout << b[0] << endl;
	}
}

Measured memory_bytes: 3840
import sys
import numpy as np
import numba

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


@numba.njit("(i8, i2[:], i4[:,:], i2[:])", cache=True)
def optimize(D, C, S, sol):
    def calc_score(sol):
        last = -np.ones((26, D + 1))
        score = 0
        for d in range(D):
            ct = sol[d]
            score += S[d, ct]
            for i in range(26):
                last[i, d + 1] = last[i, d]
            last[ct, d + 1] = d
            for i in range(26):
                score -= C[i] * (d - last[i, d + 1])
        return score, last

    sol_bak = sol.copy()
    max_score, last = calc_score(sol)
    last_bak = last.copy()

    def update(d, before, after):
        score = max_score
        score -= S[d, before]
        score += S[d, after]
        lb = last[before, d]
        la = last[after, d]
        da = db = 0
        for x in range(d, D):
            if x > d and sol[x] == before:
                break
            last[before, x + 1] = lb
            db += 1
        score -= C[before] * (d - lb) * db
        for x in range(d, D):
            if x > d and sol[x] == after:
                break
            last[after, x + 1] = d
            da += 1
        score += C[after] * (d - la) * da
        sol[d] = after
        return score

    tried = numba.typed.Dict.empty(
        key_type=numba.types.int64, value_type=numba.types.boolean
    )
    for i in range(60000):
        new_d = np.random.randint(0, D)
        c_before = sol[new_d]
        c_after = np.random.randint(0, 26)
        if c_before == c_after:
            continue
        candidate = new_d * 26 + c_after
        if candidate in tried:
            continue
        tried[candidate] = True
        new_score = update(new_d, c_before, c_after)
        if max_score < new_score:
            max_score = new_score
            sol_bak = sol.copy()
            last_bak[c_before, :] = last[c_before, :].copy()
            last_bak[c_after, :] = last[c_after, :].copy()
            tried.clear()
        else:
            sol = sol_bak.copy()
            last[c_before, :] = last_bak[c_before, :].copy()
            last[c_after, :] = last_bak[c_after, :].copy()
    return sol


def main():
    D = ini()
    C = np.array(inl(), dtype="int16")
    assert len(C) == 26
    S = np.zeros((D, 26), dtype="int32")
    for i in range(D):
        S[i, :] = inl()

    sol = np.zeros(D, dtype="int16")
    last = -np.ones(26, dtype="int16")
    for d in range(D):
        score = 0
        mi = -1
        for i in range(26):
            s = S[d, i] - C[i] * (d - last[i])
            if score < s:
                score = s
                mi = i
        sol[d] = mi
        last[mi] = d
    sol = optimize(D, C, S, sol)

    print(*(sol + 1), sep="\n")


main()


Measured memory_bytes: 108188
#include <iostream>

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	if (s.length() <= 10 && s.length() >= 1) {
		if (t.length() == s.length() + 1) {
			if(t.substr(0, t.length() - 1) == s) {
				cout << "Yes";
			}
			else cout << "No";
		}
		else cout << "No";
	}
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N,K = map(int,sys.stdin.readline().split())

a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
print(sum(sorted(a)[:K]))


Measured memory_bytes: 9196
#include <iostream>
#include <string>

using namespace std;

#define BASE1 124248592
#define BASE2 163282852
#define MOD 197436252

long long hash_temp[1000][1000], hash_field[1000][1000], hash_pattern[1000][1000];

void gen_hash(string str[], int H, int W, int R, int C, long long hash[][1000]) {
    for (int i = 0; i < H; i++) {
        long long temp = 0, multi = 1;
        for (int j = 0; j < W; j++) {
            temp = (temp * BASE1 + str[i][j]) % MOD;
            if (j < C) {
                multi = multi * BASE1 % MOD;
            }
            else {
                temp = ((temp - str[i][j - C] * multi) % MOD + MOD) % MOD;
            }
            hash_temp[i][j] = temp;
        }
    }
    for (int j = 0; j < W; j++) {
        long long temp = 0, multi = 1;
        for (int i = 0; i < H; i++) {
            temp = (temp * BASE2 + hash_temp[i][j]) % MOD;
            if (i < R) {
                multi = multi * BASE2 % MOD;
            }
            else {
                temp = ((temp -hash_temp[i - R][j] * multi) % MOD + MOD) % MOD;
            }
            hash[i][j] = temp;
        }
    }
}

int main() {
    int H, W, R, C;
    string field[1000], pattern[1000];

    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> field[i];
    }
    cin >> R >> C;
    for (int i = 0; i < R; i++) {
        cin >> pattern[i];
    }

    gen_hash(field, H, W, R, C, hash_field);
    gen_hash(pattern, R, C, R, C, hash_pattern);
    
    for (int i = R - 1; i < H; i++) {
        for (int j = C - 1; j < W; j++) {
            if (hash_field[i][j] == hash_pattern[R - 1][C - 1]) {
                cout << i - R + 1 << " " << j - C + 1 << "\n";
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 26740
# https://atcoder.jp/contests/abc051/tasks/abc051_d
# 3 3
# 1 2 1
# 1 3 1
# 2 3 3

# 1

# 3 2
# 1 2 1
# 2 3 1

# 0
# N(頂点) M(辺)
# (a,b) 長さc

INF = (10 ** 5) # 辺上限1000, ノード100なので直列につながっている時,99000ぐらいの長さになりうる
N, M = gets.split.map(&:to_i)
dist = Array.new(N) { Array.new(N, 999_999_999) }
edges = []
M.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  dist[a][b] = dist[b][a] = c
  edges << [a, b, c]
end

N.times do |i|
  dist[i][i] = 0
end

N.times do |i|
  N.times do |j|
    N.times do  |k|
      next if j == k
      if dist[j][k] > dist[j][i] + dist[i][k]
        dist[j][k] = dist[k][j] = dist[j][i] + dist[i][k]
      end
    end
  end
end

count = 0
flag = false
edges.count do |a, b, c|
  flag = false
  N.times do |i|
    N.times do |j|
      if dist[i][j] == (dist[i][a] + c + dist[b][j])
        flag = true
        break
      end
    end
    break if flag
  end
  count += 1 unless flag
end

p count

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

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;

int main(){

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

	int A; cin >> A;
	int B; cin >> B;
	if(A==1){
		if(B==2) cout << "3";
		else cout << "2";
	}else if (A==2){
		if(B==1) cout << "3";
		else cout << "1";
	}else {
		if(B==1) cout << "2";
		else cout << "1";
	}


	return 0;
}



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

int main(){
  int i,n;
  set<string> st;
  cin>>n;
  for(i=0;i<n;i++){
    string s;
    cin>>s;
    st.insert(s);
  }
  cout<<st.size()<<endl;
}
    

Measured memory_bytes: 19184
n = input().split(" ")
a = input().split(" ")
n[0] = int(n[0])
sum_HomeworkDays = 0

for i in a:
	sum_HomeworkDays += int(i)
    
if n[0]-sum_HomeworkDays >= 0:
  print(n[0]-sum_HomeworkDays)
else:
  print("-1")

Measured memory_bytes: 9496
#include<iostream>
#include<stack>

using namespace std;

const int weight[] = {1,2,4,8,16,32,64,128,256,512};

int main(){
  int req,i,n;
  stack<int> st;
  while(cin >> req) {
    n=0;
    for(i=9;i>=0;i--){
      if(req >= n + weight[i]) {
	n += weight[i];
	st.push(weight[i]);
      }
    }
    while(st.size()){
      n = st.top(); st.pop();
      cout << n;
      if(st.size()) cout << ' ';
    }
    cout << endl;
  }
  return 0;
}
      
      

Measured memory_bytes: 1200
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  ll ans=1;
  FOR(i,1,N+1){
    ans*=i;
    ans=ans%mod;
  }
  cout<<ans<<endl;
}
     










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

using namespace std;

int main(){
int n,a[110],s=0;
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        s+=a[i]*a[j];
    }
}
cout<<s;

return 0;
}


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

class Program
{
    private int N,K;
    private bool[]D=new bool[10];
    private void Scan()
    {
        var l=Console.ReadLine().Split(' ');
        N=int.Parse(l[0]);
        K=int.Parse(l[1]);
        l=Console.ReadLine().Split();
        foreach(var i in l)
        {
            D[int.Parse(i)]=true;
        }
        
    }
    
    private bool Y(int n)
    {
        var s=n.ToString();
        foreach(var c in s)
        {
            if(D[c-'0'])return false;
        }
        return true;
    }
    
    public void Solve()
    {
        Scan();
        for(int i=N;true;i++)
        {
            if(Y(i))
            {
                Console.WriteLine(i);
                return;
            }
        }
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 13140
# Problem C - Tax Increase

import math

# input process
A, B = map(int, input().split())
ans_list = []

for i in range(1, 1500):
    if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
        ans_list.append(i)

if len(ans_list)>0:
    ans = min(ans_list)
    print(ans)
else:
    print(-1)


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

int main(){
	int n;
	cin >> n;
	map<string, int> dic;
	for(int i=0; i < n; i++){
		string s;
		cin >> s;
		if(dic.count(s)) dic[s]++;
		else dic[s] = 1;
	}
	int max=0;
	for(auto p: dic){
		auto key = p.first;
		auto value = p.second;
		if(value > max) max = value;
	}
	for(auto p: dic){
		auto key = p.first;
		auto value = p.second;
		if(max == value) cout << key << endl;
	}
	return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li a[333][333];
li table[333][333];

int main() {
    cin >> n;
    rin{
        rep(j, n) {
            cin >> a[i][j];
            table[i][j] = a[i][j];
        }
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                table[i][j] = min(table[i][j], table[i][k] + table[k][j]);
            }
        }
    }


    rin{
        rep(j, n) {
            if (a[i][j] != table[i][j]) {
                puts("-1");
                return 0;
            }
        }
    }


    li res = 0;
    rin{
        repp(j, i + 1, n) {
            li tmp = INF;
            rep(k, n) {
                if (k == j || k == i)continue;
                tmp = min(tmp, a[i][k] + a[k][j]);
            }
            //p4(i, j, tmp, a[i][j]);
            if (tmp > a[i][j]) {
                res += a[i][j];
            }
        }
    }
    cout << res << endl;



    return 0;
}

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


void cc_env(){
	#ifndef ONLINE_JUDGE
		freopen("input", "r", stdin);
		freopen("output", "w", stdout);
		// 
	#endif
}


void self_max(int &a, int b){
	a = max(a, b);
}

int main(){
	// cc_env();
	// input part
	string s, t;
	cin>>s;
	cin>>t;

	//processing part
	vector<vector<int> > dp(s.length()+1, vector<int>(t.length()+1, 0));
	for(int i=1;i<=s.length();i++){
		for(int j=1;j<=t.length();j++){
			if(s[i-1] == t[j-1])
				dp[i][j] = dp[i-1][j-1] +1;
			else{
				self_max(dp[i][j], dp[i-1][j]);
				self_max(dp[i][j], dp[i][j-1]);
			}
		}
	}

	string ans = "";
	int i = s.length(), j = t.length();
	// cout<<dp[i][j]<<endl;
	while(i > 0 && j > 0){
		if(dp[i][j] == dp[i-1][j]) i--;

		else if(dp[i][j] == dp[i][j-1]) j--;

		else{
			ans = s[i-1]+ans;
			i--;
			j--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35584
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar[4] = {{0,1},{0,-1},{1,0},{-1,0}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int dp[10000001][2];//i番目を0個払う場合、ss[i]個払う場合
int main(){
  string ss;cin>>ss;
  reverse(ss.begin(),ss.end());
  dp[0][0] = 10-(ss[0]-'0');
  dp[0][1] = ss[0]-'0';
  
  for(int i = 1; ss.size() > i; i++){
    //(ss[i]-'0'+1)
    dp[i][0] = min((10-(ss[i]-'0'+1))+dp[i-1][0],10-(ss[i]-'0')+dp[i-1][1]);
    dp[i][1] = min((ss[i]-'0'+1)+dp[i-1][0],(ss[i]-'0'+dp[i-1][1]));
  }
  cout << min(dp[ss.size()-1][0]+1,dp[ss.size()-1][1]) << endl;
}

Measured memory_bytes: 9628
a = list(map(str, input()))
a_r = [a[len(a)-1-i] for i in range(len(a))]

m = len(a) // 2
count = 0
for i in range(m):
	if(a[i] != a_r[i]):
		a[len(a)-1-i] = a[i]
		count = count + 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int INF = 1e+8;

// 変数 'a' - 'k' を value に置き換え
void change(string& s, char x, char value){
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == x ) s[i] = value;
	}
}

// 式の評価
int eval(const string& s, int& k){
	if( s[k] == 'T' ){
		k++;
		return 1;
	}else if( s[k] == 'F' ){
		k++;
		return 0;
	}else if( s[k] == '-' ){
		k++;
		int r = eval(s, k);
		return (1 - r);
	}else if( s[k] == '(' ){
		++k;
		int a = eval(s, k);
		char op = s[k++];
		int b = eval(s, k);
		++k;
		int r;
		if( op == '+' ){
			r = max(a, b);
		}else if( op == '*' ){
			r = (a == 1 && b == 1)? 1 : 0 ;
		}else if( op == '>' ){
			r = (a == 1 && b == 0)? 0 : 1 ;
		}
		return r;
	}
}

int main(){
	string str;
	while( cin >> str ){
		if( str == "#" ) break;
		
		// "->" を ">" に置き換えておく
		string s;
		for(int i=0 ; i < str.size() ; i++ ){
			if( i+1 < str.size() && str[i] == '-' && str[i+1] == '>' ){
				s.push_back( '>' );
				i++;
			}else{
				s.push_back( str[i] );
			}
		}
		
		// '=' の左側を ex1, 右側を ex2 とする
		string ex1, ex2;
		bool flag = false;
		for(int i=0 ; i < s.size() ; i++ ){
			if( s[i] == '=' ){
				flag = true;
			}else if( flag ){
				ex2.push_back( s[i] );
			}else{
				ex1.push_back( s[i] );
			}
		}
		
		// 登場する変数('a' - 'k')をチェック
		int f[256] = {0};
		for(int i= 0 ; i < s.size() ; i++ ){
			f[ s[i] ] = 1;
		}
		vector<char> vc;
		for(char c = 'a' ; c <= 'k' ; c++ ){
			if( f[c] ) vc.push_back( c );
		}
		// N := 登場する変数の種類.
		int N = vc.size();
		
		// 変数の置き換えを 2^N 通り試し すべての式の評価で右辺と左辺が等しいか調べる.
		bool ans = true;
		for(int bits = 0 ; bits < (1<<N) ; bits++ ){
			string ex1_ = ex1;
			string ex2_ = ex2;
			// 変数を "T" or "F" に置き換えておく
			for(int i=0 ; i < N ; i++ ){
				// i 番目の文字を'T' か 'F'にしておく
				if( bits & (1<<i) ){
					change( ex1_ , vc[i] , 'T' );
					change( ex2_ , vc[i] , 'T' );
				}else{
					change( ex1_ , vc[i] , 'F' );
					change( ex2_ , vc[i] , 'F' );
				}
			}
			// 式の評価
			int t=0;
			int a = eval(ex1_, t);
			t = 0;
			int b = eval(ex2_, t);
			if( a != b ){
				ans = false;
				break;
			}
		}
		// 出力 
		if( ans ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1216
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		StringWriter result = new StringWriter();
		PrintWriter out = new PrintWriter(result);

		while(true){
			int members = sc.nextInt();
			int kinds = sc.nextInt();
			if(members == 0 && kinds == 0){
				break;
			}
			int[] keeps = new int[kinds];
			boolean flag = true;

			for(int i = 0;i < kinds;i++){
				keeps[i] = sc.nextInt();
			}

			for(int i = members;i > 0;i--){
				for(int j = 0;j < kinds;j++){
					keeps[j]-=sc.nextInt();
				}
			}

			for(int i : keeps){
				if(i < 0){
					flag = false;
				}
			}

			out.println(flag?"Yes":"No");
		}

		System.out.print(result.toString());
	}
}

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> f[n];
  for(int i=0; i<n; i++){
    for(int j=0, x; j<10; j++){
      cin >> x;
      f[i].push_back(x);
    }
    reverse(f[i].begin(), f[i].end());
  }
  vector<int> p[n];
  for(int i=0; i<n; i++){
    for(int j=0, x; j<=10; j++){
      cin >> x;
      p[i].push_back(x);
    }
  }
  long long ans = -1e9;
  for(int i=1; i< 1<<10; i++){
    long long tmp = 0;
    for(int j=0; j<n; j++){
      int cnt = 0;
      for(int k=0; k<10; k++){
        if(i >> k & f[j][k]) cnt++;
      }
      tmp += p[j][cnt];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct edge {int to,cost;};

int v;
vector<edge> g[100];
int d[100];
int i,j;

void dijkstra(int s){
  priority_queue<pii, vector<pii>, greater<pii> > q;
  fill(d,d+v,INF);

  d[s]=0;
  q.push(pii(0,s));

  while(q.size()){
    pii p=q.top();
    q.pop();
    int t=p.second,i;
    if(d[t]<p.first)continue;
    rep(i,g[t].size()){
      edge e=g[t][i];
      if(d[e.to]>d[t]+e.cost){
	d[e.to]=d[t]+e.cost;
	q.push(pii(d[e.to],e.to));
      }
    }
  }
}


void solve(int n, int k) {
    rep(i,100)d[i] = 0;
    rep(i,100)g[i].clear();
  v=n;
  rep(i,k){
    int q;
    cin>>q;
    if(q==0){
      int a,b;
      cin>>a>>b;
      a--;b--;
      dijkstra(a);
      int ans=d[b];
      if(ans==INF)
	cout<<-1<<endl;
      else 
	cout<<ans<<endl;
    }else{
      int c,d,e;
      cin>>c>>d>>e;
      c--;d--;
      edge x;
      x.to=d;
      x.cost=e;
      g[c].push_back(x);
      x.to=c;
      g[d].push_back(x);
    }
  }

}
int main(){
    int n,k;
    while(cin >> n >> k, n){
        solve(n,k);
    }
}


Measured memory_bytes: 3172
# Acceptance of input
import sys

file_input = sys.stdin

n = file_input.readline()

EP = []
l = -1000000001
u = 1000000001
vs_x = set()

for line in file_input:
    x1, y1, x2, y2 = (map(int, line.split()))
    if x1 == x2:
        if y1 < y2:
            EP.append((y1, l, x1))
            EP.append((y2, u, x1))
        else:
            EP.append((y1, u, x1))
            EP.append((y2, l, x1))
        vs_x.add(x1)
    else:
        if x1 < x2:
            EP.append((y1, x1, x2))
        else:
            EP.append((y1, x2, x1))

vs_x = sorted(vs_x)

# Binary Indexed Tree
class BinaryIndexedTree:
    def __init__(self, n):
        self.data = [0] * (n + 1)
        self.num = n

    def switch(self, i, d):
        while  i <= self.num:
            self.data[i] += d
            i += i & -i

    def _sum(self, i):
        s = 0
        while i:
            s += self.data[i]
            i -= i & -i
        return s

    def seg_sum(self, a, b):
        return self._sum(b) - self._sum(a - 1)

# Sweep
import bisect

EP.sort()
BIT = BinaryIndexedTree(len(vs_x))
cnt = 0

for p in EP:
    e = p[1]
    if e == l:
        vx = bisect.bisect(vs_x, p[2])
        BIT.switch(vx, 1)
    elif e == u:
        vx = bisect.bisect(vs_x, p[2])
        BIT.switch(vx, -1)
    else:
        l_x = bisect.bisect_left(vs_x, e) + 1
        r_x = bisect.bisect(vs_x, p[2])
        cnt += BIT.seg_sum(l_x, r_x)

# Output
print(cnt)

Measured memory_bytes: 28952
#include <stdio.h>
#include <string.h>
 
#define SENTINEL 100000000
#define N 100000
 
typedef struct{
    char c;
    int num;
} Card;
 
Card card1[N];
Card card2[N];
 
void merge(int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    Card L[n1], R[n2];
    int i, j, k;
 
    for (i = 0; i <= n1 - 1; i++)
        L[i] = card2[left + i];
    for (i = 0; i <= n2 - 1; i++)
        R[i] = card2[mid + i];
 
    L[n1].num = R[n2].num = SENTINEL;
    L[n1].c = R[n2].c = ' ';
    i = j = 0;
 
    for (k = left; k <= right - 1; k++) {
        if (L[i].num <= R[j].num) {
            card2[k] = L[i];
            i++;
        } else {
            card2[k] = R[j];
            j++;
        }
    }
}
 
void mergeSort(int left, int right) {
    int mid;
 
    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
 
}
 
void swapOfInt(int *a, int *b) {
    int tmp;
 
    tmp = *a;
    *a = *b;
    *b = tmp;
}
 
void swapOfChar(char *a, char *b) {
    char tmp;
 
    tmp = *a;
    *a = *b;
    *b = tmp;
}
 
int partition(int p, int r) {
    int x, i, j;
 
    x = card1[r].num;
    i = p - 1;
 
    for (j = p; j < r; ++j) {
        if (card1[j].num <= x) {
            i++;
            swapOfInt(&card1[i].num, &card1[j].num);
            swapOfChar(&card1[i].c, &card1[j].c);
        }
    }
    swapOfInt(&card1[i + 1].num, &card1[r].num);
    swapOfChar(&card1[i + 1].c, &card1[r].c);
    return i + 1;
}
 
void quickSort(int p, int r) {
    int q;
 
    if (p < r) {
        q = partition(p, r);
        quickSort(p, q - 1);
        quickSort(q + 1, r);
    }
}
 
int main() {
    int i, n, flag = 0;
    char ch;
 
    scanf("%d%c", &n, &ch);
 
    for (i = 0; i < n; ++i) {
        scanf("%c%d%c", &card1[i].c, &card1[i].num, &ch);
        card2[i] = card1[i];
    }
 
    quickSort(0, n - 1);
    mergeSort(0, n);
 
    for (i = 0; i < n; i++) {
        if (strcmp(&card1[i].c, &card2[i].c)) flag = 1;
    }
 
    if (flag) printf("Not stable\n");
    else printf("Stable\n");
 
    for (i = 0; i < n; ++i) {
        printf("%c %d\n", card1[i].c, card1[i].num);
    }
 
    return 0;
}

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

#define ANS  //for answer
#define CMP  //for compe

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x,(x)
#define ncv(x) #x,":",(x)
#define ncvc(x) #x,":",(x),","
using ll = long long;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>void pPRINT(std::ostream& ost,const T t,const U... u) {ost<<t<<" ";pPRINT(ost, u...);}
template <class... T>void PRINT(const T... t) {pPRINT(std::cout, t...);}
template <class... T>void PRINTl(const T... t){pPRINT(std::cout,t...);std::cout<<"\n";}
template <class T>void PRINTa(const T* const t,const ll size){REP(i,size)PRINT(t[i]);PRINTl();}
template <class T>void PRINTal(const T* const t,const ll size){REP(i,size)PRINTl(i,":",t[i]);}
#ifdef CMP
using namespace std;
#else
#endif
#ifdef ANS
#define DEBUG(...)
void init(){}
#else
#define DEBUG(...) PRINT("##DEBUG##","file :",__FILE__,", line :",__LINE__,"[");PRINT(__VA_ARGS__);PRINTl("]");
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif

void solve();

int main(int argc, char *argv[]) {

  init();
  DEBUG();
  solve();

  return 0;
}

void dps(vector<vector<pair<ll,ll>>>& vv,bool* c,ll pnt,ll node){
  auto& v = vv[node];
  for_each(v.begin(),v.end(),[&](pair<ll,ll> p){
    if(p.first==pnt)return;
    else{
      if(p.second%2==0)c[p.first]=c[node];
      else c[p.first]=(c[node]==0?1:0);
    }
    DEBUG(ncv(pnt),ncv(node),ncv(c[p.first]));
    dps(vv,c,node,p.first);
  });
}

void solve(){

  DEBUG("SOLVE START");
  ll n;cin>>n;
  DEBUG();
  vector<vector<pair<ll,ll>>> vv(n);
  DEBUG();
  // vector<bool> c(n);
  // bool c[n];
  bool* c = new bool[n];
  DEBUG();
  REP(i,n-1){
    ll u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    DEBUG("emplace_back",ncv(u),ncv(v),ncv(w));
    vv[u].emplace_back(v,w);
    vv[v].emplace_back(u,w);
  }
  c[0]=0;
  dps(vv,c,-1,0);
  REP(i,n)PRINTl(c[i]);
  delete c;
}

Measured memory_bytes: 10240
#include <iostream>

int main() {
    int i, j;
    std::cin >> i >> j;
    if (i + j == 15) {
        std::cout << "+";
    } else if (i * j == 15) {
        std::cout << "*";
    } else {
        std::cout << "x";
    }
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N, D, result;

    scanf("%d %d", &D, &N);

    if (D <= 2 && D >= 0 && N <= 100 && N >= 1)
    {
        if (D != 0 && N < 100)
        {
            result = (N * 100);
            if (D == 2)
            {
                result = (result * 100);
            }
        }
        else if (N == 100)
        {
            N++;
            if (D == 0)
            {
                result = N;
            }
            if (D == 1)
            {
                result = N * 100;
            }
            if (D == 2)
            {
                result = N * 10000;
            }
        }
        else
        {
            result = N;
        }
        printf("%d\n", result);
    }
    else
    {
        printf("D is 0, 1 or 2 and N is between 1 and 100.\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
vector<ll> node[100005];
bool matched[100005],used[100005];
void dfs(ll pos){
  for(int i=0;i<node[pos].size();i++){
    ll son=node[pos][i];
    if(!used[son]){
      used[son]=true;
      dfs(son);
      if(!matched[pos]&&!matched[son]){
        matched[pos]=true;
        matched[son]=true;
      }
    }
  }
}
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<n;i++){
    ll s,t;
    cin>>s>>t;
    node[s].push_back(t);
    node[t].push_back(s);
  }
  for(int i=1;i<=n;i++) {
    used[i]=false;
    matched[i]=false;
  }
  used[1]=true;
  dfs(1);
  for(int i=1;i<=n;i++){
    if(!matched[i]){
      cout<<"First"<<endl;
      return 0;
    }
  }
  cout<<"Second"<<endl;
  return 0;
}


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


int main()
{
    int N, K;
    cin >> N >> K;
    ll a = 1;
    rep(i, N) {
        if (a < K) {
            a *= 2;
        } else {
            a += K;
        }
    }
    cout << a << endl;
    return 0;
}

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

const int MAX_V=1000005;
int V;
vector<pair<int,ll>> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s){
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que;
  rep(i,V) d[i]=1e18;
  d[s]=0;
  que.emplace(0,s);

  while (!que.empty()) {
    pair<ll,int> p=que.top(); que.pop();
    int v=p.second;
    if (d[v]<p.first) continue;
    for (auto e: G[v]) {
      if (d[e.first]>d[v]+e.second) {
	d[e.first]=d[v]+e.second;
	que.emplace(d[e.first],e.first);
      }
    }
  }
}

int main(){
  int h,w,ch,cw,dh,dw;
  cin>>h>>w>>ch>>cw>>dh>>dw;
  ch--,cw--,dh--,dw--;
  V=h*w;
  char s[1005][1005];
  rep(i,h) rep(j,w) cin>>s[i][j];

  int di[4] = {1,0,-1,0};
  int dj[4] = {0,1,0,-1};
  rep(i,h) rep(j,w){
    rep(k,4){
      int ni=i+di[k],nj=j+dj[k];
      if(ni<0||nj<0||ni>=h||nj>=w) continue;
      if(s[ni][nj]=='#') continue;
      G[i*w+j].push_back({ni*w+nj,0});
    }
    for(int ni=i-2; ni<=i+2; ni++){
      for(int nj=j-2; nj<=j+2; nj++){
	if(ni<0||nj<0||ni>=h||nj>=w) continue;
	if(s[ni][nj]=='#') continue;
	G[i*w+j].push_back({ni*w+nj,1});
      }
    }
  }

  dijkstra(ch*w+cw);
  ll ans=d[dh*w+dw];
  if(ans==1e18) ans=-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 361876
#include <bits/stdc++.h>
using namespace std;
	 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)
#define endl '\n'	
#define largest(a,b,c) (a>b?(a>c? a:c):(b>c? b:c))
#define smallest(a,b,c) (a<b?(a<c? a:c):(b<c? b:c))	

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

 
int main(){
	fast_io; cout_precision;
	double n,x,t;	cin >> n >> x >> t;
	cout << (int)(ceil(n/x)*t) <<endl;

	return 0;
}
	

Measured memory_bytes: 3732
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
	int dx[4]={1,0,-1,0};
	int dy[4]={0,1,0,-1};
	int h,w;
	cin>>h>>w;
	vector<vector<int>> b=vector<vector<int>>(h+3,vector<int>(w+3,0));
	FOR(i,0,h+2){
		b[i][0]=1;
		b[i][w+1]=1;
	}
	FOR(i,0,w+1){
		b[0][i]=1;
		b[h+1][i]=1;
	}
	queue<pii> q;
	int cnt=0,ans=1;
	FOR(i,0,h){
		string s;
		cin>>s;
		FOR(j,0,w){
			if(s[j]=='#'){
				b[i+1][j+1]=1;
				q.push(MP(i+1,j+1));
			}
		}
	}
	while(q.size()){
		pii pr=q.front();
		q.pop();
		int x=pr.ST;
		int y=pr.ND;
		int nn=b[x][y]+1;
		FOR(d,0,4){
			int nx=x+dx[d];
			int ny=y+dy[d];
			if(b[nx][ny]==0){
				ans=max(ans,nn);
				b[nx][ny]=nn;
				q.push(MP(nx,ny));
			}
		}
	}

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


Measured memory_bytes: 12432
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const int INF = 1000000000;

int h, w, x, y, a, b;
string s[1010];
int d[1010][1010];
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> h >> w >> x >> y >> a >> b; x--; y--; a--; b--;
	for (int i = 0; i < h; i++)cin >> s[i];
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)d[i][j] = INF;
	d[x][y] = 0;
	priority_queue < pair<int, pair<int, int>>, vector < pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> que;
	que.push(make_pair(0, make_pair(x, y)));
	while (!que.empty()) {
		int xx = que.top().second.first, yy = que.top().second.second, p = que.top().first; que.pop();
		if (d[xx][yy] < p)continue;
		for (int i = 0; i < 4; i++) {
			int tx = xx + dx[i], ty = yy + dy[i];
			if (tx < 0 || h <= tx || ty < 0 || w <= ty || s[tx][ty] == '#')continue;
			if (d[xx][yy] < d[tx][ty]) {
				d[tx][ty] = d[xx][yy];
				que.push(make_pair(d[tx][ty], make_pair(tx, ty)));
			}
		}
		for (int i = -2; i <= 2; i++)for (int j = -2; j <= 2; j++) {
			int tx = xx + i, ty = yy + j;
			if (tx < 0 || h <= tx || ty < 0 || w <= ty || s[tx][ty] == '#')continue;
			if (d[xx][yy] + 1 < d[tx][ty]) {
				d[tx][ty] = d[xx][yy] + 1;
				que.push(make_pair(d[tx][ty], make_pair(tx, ty)));
			}
		}
	}
	if (d[a][b] == INF)cout << -1 << endl;
	else cout << d[a][b] << endl;
}


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

N, M = MAP()
XYZ = [LIST() for _ in range(M)]

uf = union_find.UnionFind(range(1, N+1))

for X, Y, Z in XYZ:
	uf.union(X, Y)

print(len(list(uf.to_sets())))


Measured memory_bytes: 121960
fn main() {
    proconio::input! {
        x: i32,
    }

    let ub = (2.0 * (x as f64).sqrt().sqrt()) as i32;

    let mut ans = (0, 0);
    for a in -ub..ub {
        let mut b = -ub;
        let mut ok = false;
        while b < ub {
            if a.pow(5) - b.pow(5) == x {
                ok = true;
                break;
            }
            b += 1;
        }
        if ok {
            ans = (a,b);
            break;
        }
    }

    println!("{} {}", ans.0, ans.1);

}


Measured memory_bytes: 2060
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 200005
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string K; cin>>K;
    ll D; cin>>D;
    ll N = K.length();
    
    ll dp[N + 1][D][2];
    memset(dp,0,sizeof(dp));
    
    dp[0][0][1] = 1;
    
    for(ll i=0;i<N;++i)
    {
        for(ll j=0;j<D;++j)
        {
            for(ll d=0;d<=9;++d)
            {
                if(K[i] - '0' == d)
                {
                    //cout<<i + 1<<" "<<d<<endl;
                    dp[i + 1][(j + d) % D][1] += dp[i][j][1];
                    dp[i + 1][(j + d) % D][1] %= MOD;
                }
                else if(K[i] - '0' > d)
                {
                    dp[i + 1][(j + d) % D][0] += dp[i][j][1];
                    dp[i + 1][(j + d) % D][0] %= MOD;
                }

                dp[i + 1][(j + d) % D][0] += dp[i][j][0];
                dp[i + 1][(j + d) % D][0] %= MOD;
            }
        }
    }
    
    //cout<<dp[1][3][1]<<endl;
    
    cout<<(dp[N][0][0] + dp[N][0][1] - 1 + MOD) % MOD<<endl;
}

Measured memory_bytes: 19192
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    auto nc2 = [](ll x){return mod(x * (x-1) / 2);};

    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    vector<ll> t1(n), t2(n);
    REP(i,n) {
        REP(j,n) {
            if (v[i] < v[j]) {
                t1[i]++;
                if (i > j) t2[i]++;
            }
        }
        //cerr<< t1[i] << " " << t2[i] << endl;
    }
    ll ans = 0;
    REP(i,n) {
        ans = mod(ans + t1[i] * nc2(k) + t2[i]*k);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
int arr[N];
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
        int k,x;
        cin>>k>>x;
        if(k*500>=x)
            cout<<"Yes"<<el;
        else
            cout<<"No"<<el;
    }
   return 0;
}


Measured memory_bytes: 256