akhauriyash/Code-Regression huggingface dataset:
"use strict";
function Main(input) {
  const args = input.split('\n');
  const NM = args.shift().split(' ').map(m => parseInt(m));
  const N = NM.shift();
  const M = NM.shift();
  const s = [];
  let idx = 0;
  while (args.length > 2) {
    const ks = args.shift().split(' ').map(m => parseInt(m));
    ks.shift();
    ks.map(m => m - 1).forEach(f => {
      s[f] = !!s[f] ? s[f] : [];
      s[f].push(idx);
    });
    idx++;
  }
  const p = args.shift().split(' ').map(m => parseInt(m));
  let count = calc(true, s, p, emptyArray(M), N - 1);
  count += calc(false, s, p, emptyArray(M), N - 1);
  console.log(count);
}

function calc(bool, s, p, Ms, i) {
  if (bool && !!s[i]) {
    s[i].forEach(bulb => Ms[bulb]+= 1);
  }
  if (i > 0) {
    let count = calc(true, s, p, [].concat(Ms), i - 1);
    count += calc(false, s, p, [].concat(Ms), i - 1);
    return count;
  }
  return Ms.filter((f, i) => f % 2 === p[i]).length === Ms.length ? 1 : 0;
}

function emptyArray(M) {
  const arr = [];
  for(let i = 0; i < M; i++) {
    arr[i] = 0;
  }
  return arr;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9868
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int a, b;
    cin >> a >> b;
    if (a >= 13)
        cout << b;
    else if (a >= 6)
        cout << b / 2;
    else
        cout << 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;

int A[200001];

int main() {
    int N, K;
    cin >> N >> K;

    int k = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (A[a] == 0) k++;
        A[a]++;
    };

    vector<int> AA;
    rep(i, 200001) if (A[i]) AA.push_back(A[i]);
    sort(AA.begin(), AA.end());
    int ans = 0;
    rep(i, max(0, k - K)) {
        ans += AA[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 2168
using System;
using static System.Console;
using static System.Math;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            var tmp = new decimal[4];
            for (int i = 0; i < 4; i++) tmp[i] = int.Parse(ReadLine());
            WriteLine(Min(tmp[0],tmp[1]) + Min(tmp[2], tmp[3]));
        }
    }
}

Measured memory_bytes: 13140
using System;
using System.Text;

namespace ALDS_1_9_C
{
    class Program
    {
        static int H;
        static int[] A;
        static int parent(int i) { return i / 2; }
        static int left(int i) { return 2 * i; }
        static int right(int i) { return 2 * i + 1; }
        static StringBuilder sb = new StringBuilder();
        static void Main(string[] args)
        {
            A = new int[2000001];
            while (true)
            {
                var a = Console.ReadLine().Split(' ');
                if (a[0][0] == 'i') insert(int.Parse(a[1]));
                else if (a[0] == "extract")
                    sb.AppendLine(extract().ToString());
                else break;
            }
            Console.Write(sb);
        }
        static int extract()
        {
            int maxv;
            if (H < 1) return int.MinValue;
            maxv = A[1];
            A[1] = A[H--];
            maxheapify(1);
            return maxv;

        }
        static void increasekey(int i, int key)
        {
            if (key < A[i]) return;
            A[i] = key;
            while (i > 1 && A[i / 2] < A[i])
            {
                int temp = A[i];
                A[i] = A[i / 2];
                A[i / 2] = temp;
                i /= 2;
            }
        }
        static void insert(int key)
        {
            H++;
            A[H] = int.MinValue;
            increasekey(H, key);
        }
        static void maxheapify(int i)
        {
            int l = left(i);
            int r = right(i);
            //?????????????????????????????????§??????§????????????
            int largest;
            if (l <= H && A[l] > A[i]) largest = l;
            else largest = i;
            if (r <= H && A[r] > A[largest]) largest = r;

            if (largest != i)
            {
                int tmp = A[i];
                A[i] = A[largest];
                A[largest] = tmp;
                maxheapify(largest);
            }
        }
    }
}

Measured memory_bytes: 38916
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Control.Monad

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

main :: IO ()
main = do
    [n, m] <- getIntList
    putStrLn $ if n == m then "Yes" else "No"


Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int n[4];

signed main() {
    rep(i, 6) {
        int x;
        cin >> x;
        n[x - 1]++;
    }
    int ki = 0;
    rep(i, 4) {
        if (n[i] % 2 == 1) {
            ki++;
        }
    }
    if (ki == 0 || ki == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())

answer = []
for i in range(1, N + 1):
  for j in range(i + 1, N + 1):
    if N % 2 and i + j != N:
      answer.append((i, j))
    if N % 2 == 0 and i + j != N + 1:
      answer.append((i, j))

print(len(answer))
for a in answer:
  print(*a)

Measured memory_bytes: 43120
#pragma comment(linker, "/STACK:36777216")

#include <bits/stdc++.h>
using namespace std;
#define LSON            id << 1 , l , mid
#define RSON            id << 1 | 1 , mid + 1 , r
#define ROOT            1 , 1 , n
#define CLR(x , y)      memset(x , y , sizeof(x))
#define LOWBIT(x)       x & (-x)
#define FORN(i , a , n)  for(int i = (a) ; i <= (n) ; ++i)
#define FORP(i , n , a)  for(int i = (n) ; i >= (a) ; --i)
#define CASE(x)		printf("Case %d: ", x)
#define SFD(x)      scanf("%lf" , &x)
#define SFC(x)      scanf(" %c" , &x)
#define SFS(x)      scanf(" %s" , x)
#define SFI(x)      scanf("%d" , &x)
#define SFL(x)      scanf("%lld" , &x)
#define SFI64(x)    scanf("%I64d" , &x)
#define PFF(x)         printf("%f" , x)
#define PFD(x)         printf("%lf" , x)
#define PFI(x)         printf("%d" , x)
#define PFC(x)         printf("%c" , x)
#define PFS(x)         printf("%s" , x)
#define PFI64(x)       printf("%I64d" , x)
#define PFL(x)         printf("%lld" , x)
#define SPACE          printf(" ")
#define PUT            puts("")
#define LPUP(i , j , k) for(int i = j ; i <= k ; ++i)
#define LPDW(i , j , k) for(int i = j ; i >= k ; --i)
#define PB(x)          push_back(x)
#define ALL(A)         A.begin(), A.end()
#define SZ(A)          int((A).size())
#define LBD(A, x)      (lower_bound(ALL(A), x) - A.begin())
#define UBD(A, x)      (upper_bound(ALL(A), x) - A.begin())
#define LOCAL
static const double PI = acos(-1.0);
static const double EPS = 1e-8;
static const int INF = 0X3fffffff;
typedef long long LL;
typedef double DB;
template<class T> inline
T read(T &x)
{
    x = 0;
    int f = 1 ; char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

/************************Little Pea****************************/


int main()
{
#ifndef ONLINE_JUDGE
    //freopen("D:\\系统优化\\Desktop\\littlepea\\in.data" , "r" , stdin);
#endif
    int a , b , c;
    read(a);read(b);read(c);
    int mx = b * 2 + 5;
    int i = 1;
    while(i < mx)
    {
        int p = a * i;
        if(p % b == c)
        {
            puts("YES");
            return 0;
        }
        ++i;
    }
    puts("NO");

#ifndef ONLINE_JUDGE
    fclose(stdin), fclose(stdout);
#endif
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#define inf (1e10) + 2
typedef long long ll;
using namespace std;
//const ll inf = 10000000000000000002ll;
ll A, B;
ll get_max(ll l1, ll l2, ll r1, ll r2) {
	//cout<<l1<<' '<<l2<<' '<<r1<<' '<<r2<<"******"<<endl;
	//if(r2 - r1 != l2 - l1) cout<<"****"<<endl;
	if(l1 > l2 || r1 > r2) return 0;
	if(l1 > r1) swap(l1, r1), swap(l2, r2);
	ll mid = (r2 - l1) / 2;
	ll maxx = max(l1 * r2, l2 * r1);
	for(ll i = mid - 10; i <= mid + 10; ++i) {
		ll num1 = l1 + i, num2 = r2 - i;
		if(num1 < l1 || num1 > l2 || num2 < r1 || num2 > r2) continue;
		maxx = max(maxx, num1 * num2); 
	} 
	mid = (l2 - r1) / 2;
	for(ll i = mid - 10; i <= mid + 10; ++i) {
		ll num1 = l2 - i, num2 = r1 + i;
		if(num1 < l1 || num1 > l2 || num2 < r1 || num2 > r2) continue;
		maxx = max(maxx, num1 * num2); 
	} 	
//	cout<<maxx<<endl;
	return maxx;
}
bool check(ll k) {
	//cout <<k<<"*****************"<<endl; 
	if(k < A && k < B) return get_max(1, k, 1, k) < A * B;
	//cout<<"__________________"<<endl;
	if(k < A && k >= B) 
	return get_max(1, B - 1, k - B + 2, k) < A * B &&
	get_max(1, k - B + 1, B + 1, k + 1) < A * B;
	if(B - 1 == k + 1 - A) return get_max(1, A - 1, B + 1, k + 1) < A * B &&
	get_max(A + 1, k + 1, 1, B - 1) < A * B;
	//cout<<"***************"<<endl;
	if(B - 1 > k + 1 - A) return get_max(A + 1, k + 1, 1, k - A + 1) < A * B &&
	get_max(k - B + 2, A - 1, k - A + 2, B - 1) < A * B && get_max(1, k - B + 1, B + 1, k + 1) < A * B;
	//cout<<"******************"<<endl;
	return get_max(k - B + 3, k + 1, 1, B - 1) < A * B && get_max(A + 1, k - B + 2, B + 1, k - A + 2) < A * B
	&& get_max(1, A - 1, k - A + 3, k + 1) < A * B; 
}
int main() {
	int Q;
	//A = 11, B = 4;
	//cout<<check(12)<<endl;
	//cout<<get_max(1, 3, 4, 6)<<endl; 
	scanf("%d", &Q);
	while(Q--) {
		scanf("%lld%lld", &A, &B);
		if(A < B) swap(A, B);
		ll l = 0, r = inf;
		ll ans = 0;
		while(l <= r) {
			//cout<<l <<' '<<r<<"^^^^^^^^^^^^^"<<endl;
			ll mid = (l + r) >> 1;
			if(check(mid)) l = mid + 1, ans = mid;
			else r = mid - 1;
		}
		printf("%lld\n", ans);
	}	
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

#define MAXN 200
#define INF 1000000000

// WarshallFloyd 法によりグラフにおける任意の2頂点間の最短距離を求める
// n : |V|
// dist : 距離行列

void WarshallFloyd(int n, int dist[MAXN][MAXN])
{
    for (int k = 0; k < n; ++k)
    {
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main()
{
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    REP(i, R)
    {
        cin >> r[i];
        r[i]--;
    }
    sort(ALL(r));
    int dist[MAXN][MAXN];
    REP(i, N) REP(j, N) dist[i][j] = INF;
    REP(i, N) dist[i][i] = 0;
    REP(i, M)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    WarshallFloyd(N, dist);
    int minCost = INT32_MAX;
    do{
        int cost = 0;
        REP(i, R - 1)
        {
            int src = r[i], dst = r[i + 1];
            cost += dist[src][dst];
        } 
        minCost = min(minCost, cost);
    } while(next_permutation(ALL(r)));

    cout << minCost << endl;
}


Measured memory_bytes: 384
main=do
    (n:m:_)<-map read.words<$>getLine::IO[Int]
    print $ sol n m
sol n m = div m $ minimum $ filter (>=n) $ divs m
divs = d 1 where
    d k m
        | k^2>m = []
        | mod m k ==0 = k : div m k : d (k+1) m
        | otherwise   = d (k+1) m

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
///////////////////////////////////////////////////////////////////////////////////

ll n;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    bool lm,rm;
    lm = false,rm = false;
    if(n/100 > 0 && n/100 < 13)lm = true;
    if(n%100 > 0 && n%100 < 13)rm = true;
    if(lm && (!rm)){
        cout<<"MMYY"<<endl;
    }else if(lm && rm){
        cout<<"AMBIGUOUS"<<endl;
    }else if((!lm)&&rm){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
    return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<a*2-1<<endl;
  }
  else if(a<b){
    cout<<b*2-1<<endl;
  }
  else{
    cout<<a*2<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int H,W,i,j;
  while(1){
 cin >> H >> W;
 if (H == 0 && W == 0) break;
  for(i=0;i<H;i++){
     
    
    for(j=0;j<W;j++){
      if(i == 0 || i == H-1 || j == 0 || j == W-1){
	cout << "#";
      }
	else cout << ".";
    }
    cout << endl;
  }
  cout << endl;


  }
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")


def trial_division_sqrt(n):
    prime_count = collections.Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def num_divisors(prime_count):
    num = 1

    for prime, count in prime_count.items():
        num *= (count + 1)

    return num


def solve(N: int):

    count = 0
    for i in range(1, N+1, 2):
        prime_count = trial_division_sqrt(i)
        if num_divisors(prime_count) == 8:
            count += 1
    print(count)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4192
#include<bits/stdc++.h>
#define M   1000000007
#define lli long long int
using namespace std;

class Query
{
public:
    int l,r,id;
    inline Query(int a,int b,int i)
    {
        l=a,r=b,id=i;
    }
};
const int block=sqrt(500007)+1;
int unik;
bool cmp(const Query a,const Query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block < b.l/block;
    return (a.l/block)&1?a.r < b.r:a.r>b.r ;
}

int arr[500007];
int freq[500007];
vector<Query>all;
int ans[500007];

void add(int d){ freq[arr[d]]++; if(freq[arr[d]]==1) unik++; }
void del(int d){ freq[arr[d]]--; if(freq[arr[d]]==0) unik--; }

int main()
{
    int n,i,j,k,p,q,l,r;

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

    for(i=1;i<=n;i++) scanf("%d",&arr[i]);

    for(i=1;i<=q;i++)
    {
        scanf("%d %d",&l,&r);
        all.push_back(Query(l,r,i));
    }

   // block=sqrt(n)+1;
    sort(all.begin(),all.end(),cmp);

    int cur_l=1,cur_r=0;
    for(i=0;i<q;i++)
    {
        l=all[i].l,r=all[i].r;
        while(cur_l>l) { cur_l--; add(cur_l); }
        while(cur_l<l) { cur_l++; del(cur_l-1); }
        while(cur_r>r) { cur_r--; del(cur_r+1); }
        while(cur_r<r) { cur_r++; add(cur_r); }

        ans[all[i].id]=unik;
    }

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

    return 0;
}



Measured memory_bytes: 15608
s=input()
s="L"+s+"R"
N=len(s)
a=[1]*N
for i in range(1,N-1):
    if s[i]=="R" and s[i+1]=="R":
        a[i+2]+=a[i]
        a[i]=0
for i in range(N-1,1,-1):
    if s[i]=="L" and s[i-1]=="L":
        a[i-2]+=a[i]
        a[i]=0
print(*a[1:-1])


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

int main(){
  int N;
  double d;
  cin >> N;
  for (int i = 1; i < 50000; i++){
    d = i * 1.08;
    if((int)d == N){
      cout << i;
      return 0;
    }
  }
  cout << ":(";
  return 0;
}

Measured memory_bytes: 3628
open Printf
open Scanf
       
module IntSet = Set.Make(struct
                          type t = int
                          let compare x y = x - y
                        end)

let () =
  let rec loop () =
    begin
      match scanf "%d %d %d %d " (fun w x y z -> [w; x; y; z]) with
        a -> let b = scanf "%d %d %d %d " (fun w x y z -> [w; x; y; z]) in
             let sa = IntSet.of_list a
             and sb = IntSet.of_list b in
             let hitn = List.fold_left (+) 0 (List.map2 (fun x y -> if x = y then 1 else 0) a b) in
             let blown = IntSet.cardinal (IntSet.inter sa sb) - hitn in
             printf "%d %d\n" hitn blown;
             loop ()
      | exception End_of_file -> ()
    end
  in
  loop ()

Measured memory_bytes: 2424
n = (int)(input())
s = sorted([sorted(list(input())) for i in range(n)])
 
ans = 0
temp = 1
for i in range(n - 1):
  if s[i] == s[i + 1]:
    temp += 1
  else:
    if temp != 1:
      ans += temp * (temp - 1) // 2
      temp = 1
else:
  if temp != 1:
    ans += temp * (temp - 1) // 2
    temp = 1
print(ans)

Measured memory_bytes: 26240
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
string a, b;
int main() {
  cin>>a>>b;
  if ((a == "H" && b == "H") || (a == "D" && b == "D")) {
  	cout<<"H"<<endl;
  } else {
  	cout<<"D"<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    A, B, C = read_h()

    m3 = max(A, B, C) * 3
    sm = sum((A, B, C))
    if m3 % 2 == sm % 2:
        print((m3 - sm) // 2)
    else:
        print((m3 + 3 - sm) // 2)


if __name__ == '__main__':
    main()


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

int N, Y;

int main(){
    int a=-1;
    int b=-1;
    int c=-1;
    cin>>N>>Y;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            if(i*10000+j*5000+(N-i-j)*1000==Y) {
                a = i;
                b = j;
                c = N-i-j;
            }
        }
    }
cout<<a<<" "<<b<<" "<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    // 先に相手にくっついた方が勝ち
    // （くっついた状態で手番が回ってきたほうが負け）
    ll n, a, b;
    cin >> n >> a >> b;
    cout << (abs(a-b)%2 == 0 ? "Alice" : "Borys") << endl;
}

Measured memory_bytes: 3676
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int INF = Integer.MAX_VALUE / 10;
	int N;
	int[] num, dist, cnt;
	Res[][] memo;

	void run() {
		N = sc.nextInt();
		memo = new Res[N][1 << N];
		num = new int[N];
		dist = new int[N];
		cnt = new int[N];
		for (int i = 0; i < N; i++) {
			num[i] = sc.nextInt();
			dist[i] = sc.nextInt();
			cnt[i] = sc.nextInt() * 20;
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 1 << N; j++) {
				memo[i][j] = new Res(INF, -1);
			}
		}
		int minIndex = 0;
		double min = INF;
		for (int i = 0; i < N; i++) {
			double tmp = bitDp(i, 1 << i, cnt[i]);
			if (tmp < min) {
				min = tmp;
				minIndex = i;
			}
		}
		ArrayList<Integer> l = new ArrayList<Integer>();
		int mask = 1 << minIndex;
		l.add(minIndex);
		while (mask != (1 << N) - 1) {
			int next = memo[minIndex][mask].next;
			l.add(next);
			mask |= 1 << next;
			minIndex = next;
		}
		StringBuilder out = new StringBuilder();
		for (int i = 0; i < N; i++) out.append((i == 0 ? "" : " ") + num[l.get(i)]);
		System.out.println(out);
	}

	double bitDp(int v, int mask, int gather) {
		if (memo[v][mask].min != INF) return memo[v][mask].min;
		if (mask == (1 << N) - 1) return 0;
		double res = INF;
		for (int i = 0; i < N; i++) {
			if ((mask & (1 << i)) == 0) {
				double tmp = bitDp(i, mask | 1 << i, gather + cnt[i]) + Math.abs(dist[v] - dist[i]) / (2000.0 / (70.0 + gather));
				if (tmp < res) {
					res = tmp;
					memo[v][mask].next = i;
				}
			}
		}
		return memo[v][mask].min = res;
	}

	class Res {
		double min;
		int next;

		/**
		 * @param min
		 * @param next
		 */
		public Res(double min, int next) {
			super();
			this.min = min;
			this.next = next;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<ll>> a(8, vector<ll>(n));
	rep(i, n){
		ll ai, bi, ci;
		cin >> ai >> bi >> ci;
		a.at(0).at(i) = +ai+bi+ci;
		a.at(1).at(i) = +ai+bi-ci;
		a.at(2).at(i) = +ai-bi+ci;
		a.at(3).at(i) = +ai-bi-ci;
		a.at(4).at(i) = -ai+bi+ci;
		a.at(5).at(i) = -ai+bi-ci;
		a.at(6).at(i) = -ai-bi+ci;
		a.at(7).at(i) = -ai-bi-ci;
	}
	rep(i, 8){
		sort(a.at(i).begin(), a.at(i).end());
		reverse(a.at(i).begin(), a.at(i).end());
	}
	vector<ll> sum(8);
	rep(i, 8) sum.at(i) = 0;
	rep(i, 8) rep(j, m) sum.at(i) += a.at(i).at(j);
	ll ans = -100000000000000;
	rep(i, 8) ans = max(ans, sum.at(i));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
if s[0]!='A' or s[2:-1].count('C')!=1:
    print('WA')    
else:
    cnt = 0
    for i in s:
        if i<'a' or 'z'<i:
            cnt += 1
    if cnt==2:
        print('AC')
    else:
        print('WA')

Measured memory_bytes: 2940
d = gets.to_i

four = d/1000
three = (d-four*1000)/100
two = (d-four*1000-three*100)/10
one = d-four*1000-three*100-two*10

first = four*10 + three
second = two*10 + one

if 0 < first && first < 13 && 0 < second && second < 13
	puts 'AMBIGUOUS'
elsif 0 < first && first < 13
	puts 'MMYY'
elsif 0 < second && second < 13
	puts 'YYMM'
else
	puts 'NA'
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<vector<int>> S(H+1,vector<int>(W+1,0));

  for(int i=1;i<=H;i++){
    string s;
    cin >> s;
    int sum=0;
    for(int j=1;j<=W;j++){
      if(s[j-1]=='1') ++sum;
      S[i][j]=sum+S[i-1][j];
    }
  }

  /*
  for(int i=0;i<=H;i++){
    for(int j=0;j<=W;j++){
      cout << S[i][j] << " ";
    }
    cout << endl;
    }*/

  int ans=5000;

  int f=0;
  for(int i=(1<<H);i<(1<<(H+1));i+=2){
    int tmp=0;
    for(int j=0;j<(H);j++){
      tmp+=((i>>j)&1);
      //      cout << ((i>>j)&1);
    }//cout << " " << tmp << endl;
    
    int l=0,r=1,u=0,d=1;
    int f=0;
    while(r<W+1){
      u=0; d=1;
      f=0;
      for(d=1;d<(H+1);d++){
	if((i>>d)&1){
	  if(S[d][r]+S[u][l]-S[d][l]-S[u][r]>K){
	    f=1;
	  }
	  u=d;
	}
      }

      if(f==1){
	if(r==l+1) {
	  //cout << "b" << l << " ";
	  break;
	}else{
	  l=r-1; tmp++;
	  //cout << l << " ";
	}
      }else{
	r++;
      }
    }
    if(f==0) ans=min(ans,tmp);
    //cout << " : " << tmp << endl;
  }
      
  cout << ans << endl;    
  
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from bisect import bisect_right, bisect_left

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
a = sorted(C.keys())
dp = [1]*(a[-1]+1)
for x in a:
    if C[x] > 1:
        dp[x] = 0
    y = x+x
    while y <= a[-1]:
        dp[y] = 0
        y += x
ans = 0
for x in a:
    ans += dp[x]
print(ans)

Measured memory_bytes: 118508
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  cin >> N;
  map<int,int> mp;
  rep(i,N){
    int x; cin >> x;
    mp[x]++;
  }

  int a=0, b=0;
  for(auto itr=mp.rbegin(); itr!=mp.rend(); itr++){
    if(a==0 && itr->second > 3){ a = itr->first; b = a; break;} 
    if(a==0 && itr->second > 1){ a = itr->first; continue;}
    if(a!=0 && itr->second > 1){ b = itr->first; break;}
  }
  cout << a * b << endl; 
  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int oo = numeric_limits<int>::max();
int di[] = {-1,0,0,1};
int dj[] = {0,-1,1,0};
int N,M,K;

int can(int i,int j){
	if(i < 0 || i >= N || j < 0 || j >= M)return 0;
	return 1;
}
struct estado{
	int i,j,dir,d,cnt;
	estado(int _i,int _j,int _dir,int _d,int _cnt){
		i = _i;
		j = _j;
		dir = _dir;
		d = _d;
		cnt = _cnt;
	}
	bool operator<(const estado &tmp)const{
		if(d == tmp.d)return cnt > tmp.cnt;
		return d > tmp.d;
	}	
};
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M >> K;
	int i0,j0,i1,j1; cin >> i0 >> j0 >> i1 >> j1; i0--; j0--; i1--; j1--;
	vector<vector<char>> A(N,vector<char>(M,'.'));
	vector<vector<vector<int>>> dist(N,vector<vector<int>>(M,vector<int>(10,oo)));
	forn(i,0,N)forn(j,0,M)cin >> A[i][j];
	priority_queue<estado> pq;
	dist[i0][j0][5] = 0; pq.push(estado(i0,j0,5,0,0));	
	while(pq.size()){
		auto act = pq.top(); pq.pop();
		int d = act.d;
		if(d > dist[act.i][act.j][act.dir])continue;
		forn(k,0,4){
			int inuevo = act.i+di[k];
			int jnuevo = act.j+dj[k];
			if(!can(inuevo,jnuevo))continue;
			if(A[inuevo][jnuevo] != '.')continue;
			if(k == act.dir){
				int cntNuevo = act.cnt+1;
				if(cntNuevo <= K){
					if(dist[act.i][act.j][act.dir] < dist[inuevo][jnuevo][act.dir]){
						dist[inuevo][jnuevo][act.dir] = dist[act.i][act.j][act.dir];
						pq.push(estado(inuevo,jnuevo,k,dist[inuevo][jnuevo][act.dir],cntNuevo));
						continue;
					}
				}else{
					if(dist[act.i][act.j][act.dir]+1 < dist[inuevo][jnuevo][act.dir]){
						dist[inuevo][jnuevo][act.dir] = dist[act.i][act.j][act.dir]+1;
						pq.push(estado(inuevo,jnuevo,k,dist[inuevo][jnuevo][act.dir],1));
						continue;
					}
				}
			}else{
				if(dist[act.i][act.j][act.dir]+1 < dist[inuevo][jnuevo][k]){
					dist[inuevo][jnuevo][k] = dist[act.i][act.j][act.dir]+1;
					pq.push(estado(inuevo,jnuevo,k,dist[inuevo][jnuevo][k],1));
					continue;
				}
			}
		}
	}
	//forn(i,0,N){
		//forn(j,0,M)cout << dist[i][j] << ' ';
		//cout << '\n';
	//}
	int res = oo;
	forn(i,0,4)res = min(res,dist[i1][j1][i]);
	if(res == oo)res = -1;
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

#define false 0
#define true (!false)
#define STRMAX (300000)

char S[STRMAX];
char pre[STRMAX];
char post[STRMAX];

int revf = false;
int Q;

void revers( char *s )
{
    int i;
    int len = strlen( s );
    char buf[STRMAX];

    strcpy( buf, s );
    for( i=0; i<len; i++ ) s[i] = buf[len - i-1];
}

int main( int argc, char *argv[] )
{
    int i;
    int t, f, c;
    char buf[128];
    char *p1 = pre;
    char *p2 = post;

    scanf( "%s", S );
    scanf( "%d", &Q );

    for( i=0; i<Q; i++ ) {

//printf( "*** %d\n", i );

        scanf( "%d", &t );
//        int n = scanf( "%d%d %c", &t, &f, &c );
//printf( "n = %d\n", n );
        if( t == 1 ) {
            revf = ! revf;
        } else if( t == 2 ) {
            scanf( "%d %c", &f, &c );
            if( f == 1 ) {
                if( ! revf ) *p1 ++ = c;
                else         *p2 ++ = c;
            } else if( f == 2 ) {
                if( ! revf ) *p2 ++ = c;
                else         *p1 ++ = c;
            }
        }
    }

    *p1 = 0;
    *p2 = 0;

    if( ! revf ) {
        revers( pre );
        strcat( pre, S );
        strcpy( S, pre );
        strcat( S, post );
    } else {
        revers( S );
        revers( post );
        strcat( post, S );
        strcpy( S, post );
        strcat( S, pre );
    }

    puts( S );
}


Measured memory_bytes: 1152
const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let m = sc.read();
    let a: Vec<Vec<i64>> = (0..n).map(|_| sc.vec(m)).collect();
    let rank = f2_gauss_jordan(a);

    let dim_kernel = n - rank;
    let kernel_size = pow(2, dim_kernel);
    let ans = (pow(2, n) + MOD - kernel_size) % MOD * pow(2, m - 1);
    println!("{}", ans % MOD);
}

fn f2_gauss_jordan(mut a: Vec<Vec<i64>>) -> usize {
    let n = a.len();
    let m = a[0].len();
    let mut rank = 0;
    let mut row = 0;
    for col in 0..m {
        match (row..n).filter(|&i| a[i][col] == 1).next() {
            Some(pivot) => {
                a.swap(row, pivot);
                rank += 1;
                for k in (row + 1)..n {
                    if a[k][col] == 1 {
                        for i in 0..m {
                            a[k][i] ^= a[row][i];
                        }
                    }
                }

                row += 1;
            }
            None => {}
        }

        if row >= n {
            break;
        }
    }
    rank
}

fn pow(mut x: usize, mut e: usize) -> usize {
    let mut result = 1;
    while e > 0 {
        if e & 1 == 1 {
            result *= x;
            result %= MOD;
        }
        e >>= 1;
        x *= x;
        x %= MOD;
    }
    result
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	int n, x, t;
	cin >> n >> x >> t;
	cout << int(ceil((double)n / x) * t);
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a,b,c) push_back(make_pair(a,make_pair(b,c)))
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 303;
int N;
int A[MC][MC];
int B[MC][MC];
LL ans;

int main(){
	cin >> N;
	repp(i,0,N){
		repp(j,0,N){
			cin >> A[i][j];
			B[i][j] = A[i][j];
		}
	}
	repp(k,0,N) repp(i,0,N) repp(j,0,N) B[i][j] = min(B[i][j] , B[i][k] + B[k][j]);
	repp(i,0,N){
		repp(j,0,N){
			if(A[i][j] != B[i][j]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	repp(i,0,N){
		repp(j,i+1,N){
			ans += A[i][j];
		}
	}
	repp(i,0,N) repp(j,i+1,N) repp(k,0,N){
		if(k == i || k == j) continue;
		if(A[i][j] == A[i][k] + A[k][j]){
			ans -= A[i][j];
			k = N;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s;
stack<int> st;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	int len = s.length(), ans = 0;
	for (int i = 0; i < len; i++) {
		if (!st.empty() && st.top() != s[i]) {
			ans++;
			st.pop();
		}
		else st.push(s[i]);
	}
	cout << ans + ans << "\n";
	//system("pause");
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i,n-1) cin >> b[i];
  ll ans = 0;
  ans += b[n-2];
  for(int i=n-1; i>0; i--) {
    ans += min(b[i],b[i-1]);
  }
  ans += b[0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
//#include<fstream>

using namespace std;

int main() {
	int num, minv, prof;
	int* prate;
	cin >> num;
	prate = new int[num];
	cin >> prate[0] >> prate[1];
	minv = prate[0];
	prof = prate[1] - minv;
	minv = min(minv, prate[1]);
	for (int i = 2; i < num; i++) {
		cin >> prate[i];
		prof = max(prof, prate[i] - minv);
		minv = min(minv, prate[i]);
	}
	cout << prof << endl;
	return 0;
}

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

typedef long long ll;

const ll MOD = 1e9+7;

ll ModPow(ll base,ll exp,ll mod){
  ll ret = 1;
  base %= mod;
  while(exp>0){
    if(exp&1) ret = (ret*base)%mod;
    base = (base*base)%mod;
    exp >>= 1;
  }
  return ret;
}

ll ModInv(ll base,ll mod){
  return ModPow(base,mod-2,mod);
}

ll Comb(ll n, ll r,ll *fct,ll *fct_inv){
  return fct[n]*(fct_inv[r]*fct_inv[n-r]%MOD)%MOD;
}

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

  ll fct[10001];
  fct[0] = fct[1] = 1;
  for(ll i=2; i<=n*4; fct[i]%=MOD,i++)
    fct[i] = fct[i-1]*(i%MOD);

  ll fct_inv[10001];
  for(ll i=0; i<=n*4; i++)
    fct_inv[i] = ModPow(fct[i],MOD-2,MOD);

  for(ll i=0; i<k; i++)
    cout << (Comb(k-1,i,fct,fct_inv)*Comb(n-k+1,i+1,fct,fct_inv))%MOD << endl;
  return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
A = list(map(int, input().split()))
import sys
import math

if sum(A) <= N+K:
  print(1)
  sys.exit()

lt = 1
rt = 10**9

def det(x):
  if sum([math.ceil(A[i]/x) for i in range(N)]) <= N+K:
    return True
  else:
    return False
  
while rt - lt > 1:
  ct = (lt + rt) // 2
  if det(ct):
    rt = ct
  else:
    lt = ct
  
  
print(rt)

Measured memory_bytes: 30968
;

import java.util.Scanner;

import static java.lang.Math.min;

public class Main {
    static final int INF = 2147483647;
    static int n;
    static int[] D;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int l = scanner.nextInt();
        initRMQ(N);

        for(int i = 0; i < N; i++){
            int x = scanner.nextInt();
            update(i, x);
        }

        
        for(int i = 0; i <= N - l; i++){
            System.out.print(query(i, i + l, 0, 0, n));
            if(i < N - l) System.out.print(" ");
        }

        System.out.println();


    }

    public static String deleteColon(String str){
        StringBuilder sb = new StringBuilder(str);
        sb.deleteCharAt(sb.lastIndexOf(" "));
        return sb.toString();
    }

    public static void initRMQ(int l){
        n = 1;

        while (n < l){
            n *= 2;
        }

        D = new int[2 * n - 1];

        for(int i = 0; i < 2 * n - 1; i++){
            D[i] = INF;
        }

    }

    public static void update(int k, int a){
        k += n - 1;
        D[k] = a;
        while (k > 0){
            k = (k - 1) / 2;
            D[k] = min(D[k * 2 + 1], D[k * 2 + 2]);
        }
    }

    public static int findMin(int a, int b){
        return query(a, b + 1, 0, 0, n);
    }

    public static int query(int a, int b, int k, int l, int r){

        if(r <= a || b <= l) return INF;

        if(a <= l && r <= b) return D[k];


        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2 );
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);

    }
}



Measured memory_bytes: 300980
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}

int main(){
	int n, x, k, mx = 0, g = -1;
	scanf("%d %d", &n, &k);
	while(n--){
		scanf("%d", &x);
		if(g == -1) g = x;
		else g = gcd(g, x);
		mx = max(mx, x);
	}
	if(k <= mx && k % g == 0) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (99999999)
int main(){

  //-------データの入力------------
  int n;
  cin >> n;
  int row[n];
  int column[n];
  for(int i = 0; i < n; i++){
    cin >> row[i] >> column[i];
  }
  //-----------------------------

  //[始点][終点（始点+幅）]の最小コスト
  int dp[n][n];

  //INFで初期化
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      dp[i][j] = INF;
    }
  }

  //幅0はコスト0
  //dp[i][i+0] = 0
  for(int i = 0; i < n; i++){
    dp[i][i] = 0;
  }

  //幅:j = 0 から n-1 まで
  for(int j = 0; j < n; j++){
    //始点: i から n -j まで
    for(int i = 0; i < n - j; i++){
      //仕切りを置く位置: k
      // (M_0, M_1, M_2, M_3) | (M_4, M_5)
      for(int k = i + 1; k <= i + j; k++){
        //現在のdp[i][i+j]より小さければ更新
        dp[i][i+j] = min(dp[i][i+j], dp[i][k-1] + dp[k][i+j] + row[i] * column[k-1] * column[i+j]);
      }
    }
  }
  /*
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  //始点０、幅n-1の最小コスト=> n個の行列の連鎖の計算に最低限必要な乗算の回数　を出力
  cout << dp[0][n-1] << endl;
  return 0;
}

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

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

const int MAXN = 1234;
int H, W;
char A[MAXN][MAXN];
int dist[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> A[i];
	}

	vector<pair<int, int>> q;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				q.emplace_back(i, j);
				dist[i][j] = 0;
			} else {
				dist[i][j] = -1;
			}
		}
	}
	for (size_t i = 0; i < q.size(); i++) {
		int x, y; tie(x, y) = q[i];
		for (int dir = 0; dir < 4; dir++) {
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			if (nx < 0 || nx >= H || ny < 0 || ny >= W || dist[nx][ny] != -1) {
				continue;
			}
			dist[nx][ny] = dist[x][y] + 1;
			q.emplace_back(nx, ny);
		}
	}

	int x, y; tie(x, y) = q.back();
	int ans = dist[x][y];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 17388
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a[10];
	char op[10];	
	for(int i=0;i<=3;i++)a[i]=s[i]-'0';
	int ed=7;
	for(int i=0;i<=7;i++)
	{
		int tt=a[0];
		for(int j=0;j<=2;j++)
		{
		
			if(i&(1<<j))
			{
				tt+=a[j+1];
				op[j]='+';
			}
			else
			{
				tt-=a[j+1];
				op[j]='-';
			}
		}
		

		if(tt==7)
		{
			for(int i=0;i<=2;i++)printf("%d%c",a[i],op[i]);
			printf("%d=7\n",a[3]);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int judgment(char *text, char *word)
{
    int sum = 0;
    int j = -1;
    do{
        if(*(word + j) == '\n')
            break;
        j++;
        if(isupper(*(text + j))){
            *(text + j) = tolower(*(text + j));
        }
    }while(*(word + j) == *(text + j));
    
    if(*(word + j) == '\n'){
        if(!isalpha(*(text + j)))
            sum = 1;
    }
    return  sum;
}

int main(void){
    char word[15];
    char text[1010];
    int j, q, k, a = 0;
    int x, y, z;
    
    fgets(word, 15, stdin);
    while(fgets(text, 1005, stdin) != NULL){
        x = 0;
        while(text[x] != '\n'){
            if(isalpha(text[x])){
                a += judgment(&text[x], word);
            }
            while(isalpha(text[x])){
                x++;
            }
            while(!isalpha(text[x])){
                if(text[x] == '\n')
                    break;
                x++;
            }
        }
    }
    printf("%d\n", a);
    return 0;
}


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

int main( void ) {
    int s[3];
    cin >> s[0] >> s[1] >> s[2];
    sort( s, s + 3 );
    cout << s[0] << ' ' << s[1] << ' ' << s[2] << '\n';
    return 0;
}


Measured memory_bytes: 3132
p=998244353

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

LR=[]
for i in range(k):
    Li,Ri=map(int,input().split())
    LR.append([Li,Ri])

U=[0,1]

cnt=[1]
for i in range(1,n):#i:=position
    cnti=0
    for Li,Ri in LR:
        scopeL=i-Ri
        scopeR=i-Li
        if scopeR>=0:
            cnti+=U[scopeR+1]-U[max(0,scopeL)]#sum[max(0,scopeL),scopeR+1]
    cnt.append(cnti%p)
    U.append((U[i]+cnti)%p)

print(cnt[n-1])

Measured memory_bytes: 96492
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int
int digitSum(int b, int n)
{
    if (n < b)
        return n;
    else
        return digitSum(b, n / b) + n % b;
}

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

    int n, s;
    cin >> n >> s;
    if (n < s){
        cout << "-1" << endl;
        return 0;
    } else if (s == n) {
        cout << n+1 << endl;
        return 0;
    }
    if (n < 1000000) {
        REP(i,2,n) {
            if (digitSum(i, n) == s) {
                cout << i << endl;
                return 0;
            }
        }
        cout << "-1" << endl;
        return 0;
    }
    int N = sqrt(n) + 1;
    REP(i,2,N) {
        if (digitSum(i, n) == s) {
            cout << i << endl;
            return 0;
        }
    }
    for(int i = N; i >= 0; i--) {
        int b = max((n-s)/(i+1)-2,(int)2);
        dump(b);
        rep(j, 5){
            if (digitSum(b+j, n) == s) {
                cout << b+j << endl;
                return 0;
            }
        }
    }
    cout << "-1" << endl;


    return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> H(N);
    bool jud = true;
    int maxi = 0;

    rep(i,N){
        cin >> H[i];
    }

    rep(i,N-1){
        if(H[i] <= H[i+1]){
            maxi = max(maxi,H[i+1]);
            continue;
        }
        else if(H[i] > H[i+1]){
            if(maxi - 1 == H[i+1]){
                continue;
            }
            else{
                jud = false;
            }
        }
    }
    if(jud){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 640
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)

hash = {}
max = 0
a_arr.each do |a|
  hash[a] ||= 0
  hash[a] += 1
  max = a if a > max
end

hash.each do |a, count|
  from_i = count > 1 ? 1 : 2
  to_i = max / a
  from_i.upto(to_i) do |i|
    hash.delete(a * i)
  end
end

puts hash.size

Measured memory_bytes: 38436
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
vl bitList(ll n, ll k, ll f) {
	vl bitList(k);
	for (ll i = 0; i < k; i++) {
		bitList[i] = f % n;
		f /= n;
	}
	return bitList;
}
int main() {
	cin >> N >> K;
	vl one(48);
	for (j = 0; j < 48; j++) {
		one[j] = 0;
	}
	for (i = 0; i < N; i++) {
		ll a;
		cin >> a;
		vl B = bitList(2, 48, a);
		for (j = 0; j < 48; j++) {
			if (B[j]) one[j]++;
		}
	}
	//デフォルトでは「1以上N以下で0でない数字がちょうどK個ある」の桁DP
	vl P = bitList(2, 48, K);

	// dp[i][smaller][j]
	// 今調べている桁をi, 未満フラグをsmaller, 0が出た回数をjとする
	vector<vl> dp(49, vl(2, 0));
	// 0桁目は便宜上0であると考える
	// 0桁目は0しかありえないがこれはsmallerが確定していないのでsmaller=0しかありえない
	// 結局dp[0][0][0]=1, それ以外は全て0で初期化すればよい
	reverse(P.begin(), P.end());
	reverse(one.begin(), one.end());
	for (i = 0; i < 49; i++) {
		for (j = 0; j < 2; j++) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for (i = 0; i < 48; i++) {
		//cout << P[i] << " ";
	}
	//cout << endl;
	for (i = 0; i < 48; i++) {
		//cout << one[i] << " ";
	}
	//cout << endl;
	for (i = 0; i < 48; i++) {
		for (ll smaller = 0; smaller < 2; smaller++) {
			if (dp[i][smaller] == -1) continue;
			ll X = pow(2, 47 - i);
			//0を選んだ場合
			dp[i + 1][smaller ||P[i]] = max(dp[i + 1][smaller || P[i]], dp[i][smaller] + X * one[i]);
			//1を選んだ場合
			if(smaller) dp[i + 1][1] = max(dp[i + 1][1], dp[i][smaller] + X * (N-one[i]));
			else if(P[i]) dp[i + 1][0] = max(dp[i + 1][0], dp[i][smaller] + X * (N - one[i]));
		}
	}
	// [smaller || x < A[i]]は以下の寄与条件を反映させたものである。
	// smaller=0 から smaller=0 → x = A[i] のとき寄与
	// smaller=0 から smaller=1 → x < A[i] のとき寄与
	// smaller = 1 から smaller = 0 → 常に寄与なし
	// smaller=1 から smaller=1 → 常に寄与
	// [j + (x > 0)]は以下の寄与条件を反映させたものである。(但しj==Kのときのみ例外処理アリ)
	// j=p から j=p → x=0のとき寄与
	// j=p から j=p+1 → x!=0のとき寄与
	for (i = 0; i <= 48; i++) {
		//cout << dp[i][0] << " " << dp[i][1] << endl;
	}
	cout << max(dp[48][0],dp[48][1]);
}
	


Measured memory_bytes: 256