akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long A, long long B, long long C){
  cout << ((A%2 == 0 || B%2 == 0 || C%2 == 0) ? 0 : min({A*B , B*C , C*A})) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,i,sum=0;
  scanf("%d",&n);
  int a[n];
  
	n--;
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  int c=0;
 
  for(i=0;i<n-1;i++)
  {
    c= a[i]<=a[i+1]?a[i]:a[i+1];
    sum+=c;
  }
  sum=sum+a[0]+a[n-1];
	printf("%d\n",sum);  


 return 0; 
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main (String[] args){
        Scanner sc = new Scanner (System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else if(a==b){
            System.out.println("a == b");
        }else{
            System.out.println("a > b");
        }
    }
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int N;
    cin >> N;
    if(N < 10){
        cout << "ABC00" << N << endl;
    }else if(N < 100){
        cout << "ABC00" << N << endl;
    }else{
        cout << "ABC" << N << endl;
    }
}

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

int main() {
    ll n,m;
    std::cin >> n>>m;
    
    vector<ll>    c(100010,0);
    vector<ll> oddc(100010,0);
    
    for (int i = 0; i < n; i++) {
        ll t;
        std::cin >> t;
        c[t]++;
    }
    ll mc = 0;
    
    for (int i = 0; i <= 100000; i++) {
        if(i%m==0){
            mc += c[i];
            continue;
        }
        if(c[i]%2==1){
            oddc[i%m]++;
            c[i]--;
        }
        
    }
    ll ans = 0;
    for (int i = 1; i < m; i++) {
        ll dif = min(oddc[i],oddc[m-i]);
        ans += dif;
        oddc[i]-=dif;
        oddc[m-i]-=dif;
    }
    // std::cout << ans << std::endl;
    for (int i = 0; i <= 100000; i++) {
        if(i%m==0)continue;
        ll dif = min(c[i],oddc[m-i%m]);
        ans += dif;
        c[i]-=dif;
        oddc[m-i%m]-=dif;
        ans += c[i]/2;
    }
    
    ans += mc/2;
    
    
    std::cout << ans << std::endl;
    
    
}


Measured memory_bytes: 1792
def main():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())
    a = A1 * T1 + A2 * T2
    b = B1 * T1 + B2 * T2
    if a == b:
        print("infinity")
        return
    if a < b:
        a, b = b, a
        A1, B1 = B1, A1
        A2, B2 = B2, A2
    if A1 > B1:
        print(0)
        return
    ans = (B1 - A1) * T1 // (a - b) * 2
    if (B1 - A1) * T1 % (a-b) != 0:
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int H, W;
	cin >> H >> W;
	char s[H][W];//H行W列の配列(型：文字)//ここは問題なし。
	char t[H+2][W+2];
	string ANSWER;
	ANSWER = "Yes";
	for (int i = 0; i < H; i++) {
	for (int k = 0; k < W; k++) cin >> s[i][k];//s[H][W]は正しく入力されている。
	}

	for (int i=0; i<H+2; i++){
		for (int k=0; k<W+2; k++){
			t[i][k] = '.'; //初期化
		}
	}
	for (int i=0; i<H; i++){
		for (int k=0; k<W; k++){
			t[i+1][k+1] = s[i][k]; 
		}
	}
	for (int i=0; i<H; i++){
		for (int k=0; k<W; k++){
			if (t[i+1][k+1]=='#' && t[i][k+1]!='#' && t[i+1][k]!='#' && t[i+2][k+1]!='#' && t[i+1][k+2]!='#')
				ANSWER = "No";
		}
	}
	//for (int i=0; i<H; i++){
		//for (int k=0; k<W; k++){
			//cout << s[i][k];
		//}
		//cout << endl;
	//}
//	for (int i=0; i<H+2; i++){
	//	for (int k=0; k<W+2; k++){
		//	cout << t[i][k];
		//}
		//cout << endl;
	//}

	
	

	cout << ANSWER << endl;
	//for (int i=0; i<H; i++){
		//for (int k=0; k<W; k++){
			//cout << s[i][k]; //文字の読み込み
		//}
	//}
  return 0;
}

 

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

int main() {

  int N, M;
  cin >> N >> M;

  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    que.push(A);
  }

  for (int i = 0; i < M; i++) {
    int a = que.top();
    que.pop();
    a /= 2;
    que.push(a);
  }

  long long answer = 0;
  while(!que.empty()) {
    answer += que.top();
    que.pop();
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 892
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:１つの整数 x を読み込んで、x の３乗を計算し結果を出力する	*/
int main( void )
{
	/* 内部変数宣言	*/
	int x;		/* 読み込む変数x	*/
	int ans;	/* 計算結果			*/
	
	scanf("%d",&x);	/* xを読み込む		*/
	
	ans = x * x * x;	/* xの3乗を計算する	*/
	
	printf("%d\n",ans);
	
	return 0;
}



Measured memory_bytes: 2032
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9 + 5;

int main()
{
  int n, k;
  int h[100010];

  cin >> n >> k;

  for (int i = 0; i < n; i++)
      cin >> h[i];

  vector <int> dp(n, INF);
  dp[0] = 0;

  for (int i = 0; i < n-1; i++)
  {
    for (int j = i+1; j <= i+k; j++)
    {
      if (j < n)
      {
        dp[j] = min(dp[j], dp[i] + abs(h[i]-h[j]));
      }
    }
  }
  cout << dp[n-1] << "\n";

  return 0;
}


Measured memory_bytes: 1024
import sys
 
string = str()
 
for line in sys.stdin:
    string += line.lower()

alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for letter in alph:
	sum = 0
	n = -1
	while True:
		n = string.find(letter, n + 1)
		if n == -1:
			break
		sum += 1
	print("{} : {}".format(letter, sum))

Measured memory_bytes: 7384
// ABC 110 C

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int gcd(int u, int v)
{
  return (v != 0) ? gcd(v, u % v) : u;
}

int main(int argc, char** argv) {
  string s, t;
  cin >> s >> t;

  std::map<char, char> ms;
  std::map<char, char> mt;

  rep(i, s.size()) {
    if (ms.find(s[i]) == ms.end()) {
      ms.insert(make_pair(s[i], t[i]));
    } else {
      if (ms.at(s[i]) != t[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (mt.find(t[i]) == mt.end()) {
      mt.insert(make_pair(t[i], s[i]));
    } else {
      if (mt.at(t[i]) != s[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 776
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

/** ワーシャル・フロイド法による全点対最短路探索

    経路を逐次最小化していく。

    頂点番号は0オリジン。

    知らないパスにはコスト大きめを設定しておくこと。
    その初期コストはすべての都市を回ってくるパスよりも大きくすべし。
    ただ、内部で加算するのでオーバーフローに注意。MAXダメ、絶対。
    std::fill(mat.data(), mat.data() + mat.num_elements(), MAXCOST+1);

    O(|V|^3)

    @note 反対方向もいれた？
    mat[a][b] = mat[b][a] = c;

    @note 自分自身へのルートはコスト0か？
    for (int i = 0; i < N; ++i) {
    mat[i][i] = 0;
    }

    @param[in] V  頂点数
    @param[in, out] distance[i][j]: 頂点i -> jのコスト
*/
template<typename T, typename M>
void warshall_floyd(T V, M& distance)
{
    for (T k = 0; k < V; ++k) {
        for (T i = 0; i < V; ++i) {
            for (T j = 0; j < V; ++j) {
                distance[i][j] = std::min(distance[i][j],
                                          distance[i][k] + distance[k][j]);
            }
        }
    }
}


int main()
{
    int64_t H, W;
    std::cin >> H >> W;

    boost::multi_array<int64_t, 2> c(boost::extents[10][10]);

    for (auto p = c.data(); p < (c.origin() + c.num_elements()); ++p) {
        std::cin >> *p;
    }


    boost::multi_array<int64_t, 2> A(boost::extents[H][W]);
    for (auto p = A.data(); p < (A.origin() + A.num_elements()); ++p) {
        std::cin >> *p;
    }

    warshall_floyd(10, c);

    int64_t ans = 0;

    for (auto p = A.data(); p < (A.origin() + A.num_elements()); ++p) {
        if (*p != -1) {
            ans += c[*p][1];
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

int ans,N;

void dfs(ll a, int cnt3,int cnt5, int cnt7){
    if(a > N) return;
    if(cnt3 > 0 && cnt5 >0 && cnt7 >0){
        ans++;
    }
    dfs(10*a + 3, cnt3 +1, cnt5, cnt7);
    dfs(10*a + 5, cnt3, cnt5+1, cnt7);
    dfs(10*a+7,cnt3,cnt5,cnt7+1);
}

int main(){
    
    cin>>N;
    dfs(0,0,0,0);
    cout << ans << endl;
}

    

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

bool isOK(const string& s) {
    for (int64_t i = 0; i < s.size(); i++) {
        if (s[i] != s[s.size() - 1 - i]) {
            return false;
        }
    }
    return true;
}

int main() {
    string S;
    cin >> S;
    const int64_t N = S.size();
    bool ans = (isOK(S) && isOK(S.substr(0, N / 2)) && isOK(S.substr(N / 2 + 1)));
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val r, g, b, n = sc.nextInt()
    
    var ans = 0L
    for (i <- 0 to (n / r)) {
      for (j <- 0 to (n / g)) {
        val m = i * r + j * g
        if ((n - m) % b == 0 && (n - m) / b >= 0) {
          ans += 1
        }
      }
    }
    
    println(ans)
  }
}

Measured memory_bytes: 27472
#include <stdio.h>

int main(){
  char c[5][5] = {};
  scanf("%s %s", c[0], c[1]);
  if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]){
    printf("YES\n");
  }
  else{
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
read wd2
if [ $wd2 = "7" ] 
then
    echo "YES"
else
    if [ $wd2 = "5" ]
    then
        echo "YES"
    else
        if [ $wd2 = "3" ]
        then
            echo "YES"
        else
            echo "NO"
        fi
    fi
fi


Measured memory_bytes: 376
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	int ans =0;
	cin>>n;
	while (n--)
	{
		int a;
		cin>>a;
		ans+=a;
		ans--;
	}
	printf("%d\n",ans );
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

#define INF 1000000007

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n; cin >> n;
  vector<ll> a(n);
  vector<ll> prod(n+1, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    prod[n-1 - i] = (prod[n - i] + a[n - i - 1]) % INF;
  }
  ll ans = 0;
  for(int i = 0; i < n; i++){
    ans = (ans + prod[i+1] * a[i]) % INF;
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 6340
# import itertools
import math
# import fractions
# import functools
# import copy
# from collections import deque
# from functools import reduce
# from decimal import Decimal


def main():
    n, x, t = map(int, input().split())
    print(math.ceil(n/x) * t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62092
#include<iostream>
#include<vector>

using namespace std;

int main() {
    while (1) {
        int n, r;
        cin >> n >> r;
        
        if (n * r == 0) break;
        vector<int> card;
        
        for (int i = 0; i < n; ++i) {
            card.push_back(n - i);
        }

        for (int i = 0; i < r; ++i) {
            int p, c;
            cin >> p >> c;
            for (int k = 0; k < c; ++k) {
                int temp = card[c + p - 2];
                card.erase(card.begin() + c + p - 2);
                card.insert(card.begin(), temp);
            }
        }

        cout << card[0] << endl;
    }
}

Measured memory_bytes: 3008
def main():
    n,y = map(int,input().split())
    max_yukiti = min(n,y//10000)
    for i in range(max_yukiti+1):
        nokori = y-10000*i
        for j in range(min(n-i,nokori//5000)+1):
            nnokori = nokori-5000*j
            k = nnokori/1000
            if i+j+k==n:
                print(i,j,int(k))
                exit()
    print(-1,-1,-1)
main()


Measured memory_bytes: 9164
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    a.erase(unique(all(a)), a.end());
    rep(i, a.size()) {
        if(i) cout << ' ';
        cout << a[i];
    }
    cout << endl;
}


Measured memory_bytes: 3372
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int k = int.Parse(Console.ReadLine());

            char[] cut = s.Substring(k - 1, 1).ToCharArray();

            string ans = "";

            for (int i = 0; i < n; i++)
            {
                if (s[i] == cut[0])
                {
                    ans += s[i];
                }
                else
                {
                    ans += "*";
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int dx[]={-1,0,1,1,1,0,-1,-1};
int dy[]={-1,-1,-1,0,1,1,1,0};
char s[55][55];
int check(int i,int j,int h,int w){
  int x,y,count=0;
  for(int a=0;a<8;++a){
    x = j+dx[a];
    y = i+dy[a];
    if(x>=0&&y>=0&&x<w&&y<h && s[y][x]=='#') count++;
  }
  return count;
}
int main(){
  int h,w;
  cin>>h>>w;
  char ans[h][w];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin>>s[i][j];
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(s[i][j]=='.'){
        ans[i][j]='0'+check(i,j,h,w);
      }
      else{ans[i][j]='#';}
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cout<<ans[i][j];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 99999999.
       01 B PIC 99999999.
       01 C PIC 9999999999.
       01 REN PIC 9999999999.
       01 RE PIC ZZZZZZZZZZ9.
       01 temp1 PIC 9999999.
       01 temp2 PIC 9999999.
       01 temp3 PIC 9999999.
       01 N PIC 9999999.
       PROCEDURE DIVISION.
       MAIN.
       	ACCEPT INP.
      	PERFORM VARYING temp1 FROM 1 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	SUBTRACT 1 FROM temp1.
      	MOVE INP(1:temp1) TO A.
      	ADD 2 TO temp1.
      	PERFORM VARYING temp2 FROM temp1 BY 1 UNTIL INP(temp2:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp2 - temp1.
      	MOVE INP(temp1:N) TO B.
      	ADD 1 TO temp2.
      	PERFORM VARYING temp1 FROM temp2 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp1 - temp2.
      	MOVE INP(temp2:N) TO C.
      	ADD 1 TO A.
      	MOVE 0 TO REN.
      	PERFORM VARYING N FROM 1 BY 1 UNTIL N = A
      		MOVE 0 TO temp1
      		MOVE N TO temp2
      		PERFORM MOD
      		IF temp1 >= B AND temp1 <= C THEN
      			ADD N TO REN
      		END-IF
      	END-PERFORM.
      	MOVE REN TO RE.
      	DISPLAY RE.
        STOP RUN.

      	MOD SECTION.
      	PERFORM 5 TIMES
      		COMPUTE temp3 = temp2 / 10
      		COMPUTE temp1 = temp1 + temp2 - temp3 * 10
      		COMPUTE temp2 = temp3
      	END-PERFORM.
   	   EXIT.



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define  pb push_back
#define  xx first
#define  yy second
//#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef vector<string> vi;
typedef pair<int,int> pi;
#define PI acos(-1)
int main()
{

      int t=1;

     while(t--){

        ll n,m;
         cin >> n >> m;
         if(n==1 || m==1){
            cout << 1<< endl;continue;
         }
       ll  ans = ((m+1)/2)*((n+1)/2)+(m/2)*(n/2);
         cout << ans << endl;

     }

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
int b[105];
int a[105][105],open[105][15];
int tmp,ans,sum,n;
void search(int floor){
	if(floor==11){
		sum=0;
		for(int i=1;i<=10;i++){
		    tmp+=b[i];	
		}
		if(tmp==0)return ;
		for(int i=1;i<=n;i++){
			tmp=0;
			for(int j=1;j<=10;j++){
				if(open[i][j]&&b[j])tmp++;
			}
			sum+=a[i][tmp];
		}
		ans=max(sum,ans);
		return ;
	}
	else {
		for(int i=0;i<=1;i++){
			b[floor]=i;
			search(floor+1);
		}
	}
}
int main(){
   cin>>n;
   for(int i=1;i<=n;i++){
   	  for(int j=1;j<=10;j++){
   	  	scanf("%d",&open[i][j]);
	  }
   }
   for(int i=1;i<=n;i++){
   	   for(int j=0;j<=10;j++){
   	   	  scanf("%d",&a[i][j]);
	   }
   }
   ans=-1111111111;
   search(1);
   cout<<ans;
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

void solve() {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    
    if (b - a <= 1) {cout << 2*a - 2 << "\n"; return;}
    
    int c = floor(sqrt(a*b + 0.1));
    if (c * c == a * b) --c;
    if (c * (c + 1) >= a * b) cout << 2*c - 2 << "\n";
    else cout << 2*c - 1 << "\n";
}

int32_t main() {
    fastIO();
    
    int q;
    cin >> q;
    while (q--) solve();
    
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
C=[list(map(int,input().split())) for _ in range(10)]
d=[0]*10
for _ in range(H):
  for i in list(map(int,input().split())):
    if i>=0: d[i]+=1
r=range(10)
for k in r:
  for i in r:
    for j in r:
      C[i][j]=min(C[i][j],C[i][k]+C[k][j])

print(sum(C[i][1]*d[i] for i in r))

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t,u;
    int ss,tt;
  cin >> s >> t;
  cin >> ss >> tt;
  cin >> u;

  if(s == u){
    cout << ss - 1 << ' ' <<tt;

  }else
    {
        /* code */
        cout << ss << ' ' <<tt - 1;
    }
    
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,x,l,ans=1;
	cin >> n;
	vpll a(n);
	queue<pair<ll,ll>> q;
	rep(i,n){
		cin >> x >> l;
		a[i]=m_p(x+l,x-l);
	}
	sort(all(a));
	cerr << a;
	rep(i,n) q.push(a[i]);
	pair<ll,ll> cur=q.front();
	q.pop();
	while(!q.empty()){
		if(cur.first<=q.front().second){
			ans++;
			cur=q.front();
		}
		q.pop();
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int c[3];

int main() {
	cin >> s;
	rep(i,s.length()) c[s[i]-'a']++;
	if (abs(c[0]-c[1])<=1 && abs(c[1]-c[2])<=1 && abs(c[2]-c[0])<=1) cout << "YES" << ln;
	else cout << "NO" << ln;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l),i##R=(r);i<=i##R;i++)
#define DOR(i,r,l) for(int i=(r),i##L=(l);i>=i##L;i--)
#define loop(i,n) for(int i=0,i##R=(n);i<i##R;i++)
#define sf scanf
#define pf printf
#define mms(a,x) memset(a,x,sizeof a)
using namespace std;
typedef long long ll;
template<typename A,typename B>inline void chkmax(A &x,const B y){if(x<y)x=y;}
template<typename A,typename B>inline void chkmin(A &x,const B y){if(x>y)x=y;}
int main(){
	int n,a,b;
	sf("%d%d%d",&n,&a,&b);
	pf("%d\n",min(a*n,b));
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import math
n=int(input())
a=list(map(int, input().split(" ")))
b=[i-(num+1) for num,i in enumerate(a)]
#print(np.mean(b))
#print(b)

b.sort()
#print(b)
if n%2==1:
    c1=[abs(i-(num+b[int((n-1)/2)]+1)) for num,i in enumerate(a)]
    print(np.sum(c1))
else:
    c1=[abs(i-(num+b[int(n/2)]+1)) for num,i in enumerate(a)]
    c2=[abs(i-(num+b[int(n/2+1)]+1)) for num,i in enumerate(a)]
    print(min(np.sum(c1),np.sum(c2)))

Measured memory_bytes: 45304
#include <bits/stdc++.h>
#define L long long
#define LL long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(x) memset(a,x,sizeof(L));
#define N 100005
using namespace std;
    L a[101][N];
    L n,w;
    L g[101][2];
L recursivedpKnapsackmaximum(L w , L i)
{
    if (a[i][w] != -1)
    return a[i][w];

if (w < g[i][0])
    a[i][w] = max(a[i][w],recursivedpKnapsackmaximum(w,i-1));
    else
    {
        a[i][w] = max(a[i][w],max(recursivedpKnapsackmaximum(w,i-1)
        ,recursivedpKnapsackmaximum(w-g[i][0],i-1)+g[i][1]));
    }
    return a[i][w];
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> w;
    L i;
    L j;
    // setE(-1);
    f(0,n,i)
    {
        f(0,N-1,j)
        a[i][j] = -1;
    }
    f(0, w, i)
    {   
        a[0][i] = 0;
    }
    f (0 , n, i)
    {
        a[i][0] = 0;
    }
    f(1 , n , i)
    {
        cin >> g[i][0] >> g[i][1];
    }
    cout << recursivedpKnapsackmaximum(w,n);
    return 0; 
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

struct mint{
    static const long long MOD = 998244353;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

struct S{
    mint a;
    ll size;
};
S op(S a, S b){ return S{a.a + b.a, a.size + b.size}; }
S e() { return S{0, 0}; }
using F = pair<mint, mint>;
S mapping(F f, S x){
    return S{f.first * x.a + f.second * x.size, x.size};
}
F composition(F f, F g){
    return F(f.first * g.first, f.first * g.second + f.second);
}
F id(){ return F(1, 0); }

int main(){
    ll n, q;
    cin >> n >> q;
    vector<S> a(n);
    REP(i, n){
        ll ai;
        cin >> ai;
        a.at(i) = S{ai, 1};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    REP(i, q){
        ll t;
        cin >> t;
        if(t == 0){
            ll l, r, b, c;
            cin >> l >> r >> b >> c;
            seg.apply(l, r, F(b, c));
        }else{
            ll l, r;
            cin >> l >> r;
            cout << seg.prod(l, r).a << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 35676
N = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(1, N-1):
    if P[i-1] < P[i] and P[i] < P[i+1] or P[i-1] > P[i] and P[i] > P[i+1]:
        ans += 1
print(ans)


Measured memory_bytes: 38256
n, m, k = map(int, input().split())

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[-1] + a[i])

for i in range(m):
    sum_b.append(sum_b[-1] + b[i])

ans = 0
j = m
for i in range(n + 1):
    while sum_a[i] + sum_b[j] > k and j >= 0:
        j -= 1

    if j < 0:
        break

    if sum_a[i] + sum_b[j] <= k:
        ans = max(ans, i + j)

print(ans)



Measured memory_bytes: 134004
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) {
		cout << "Bad" << endl;
	}
	else cout << "Good" << endl;
	return 0;
}

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

ans = 0
flg = False
for i in range(n):
    if flg:
        flg = False
        continue
    if a[i] == i+1:
        if i < n-1 and a[i+1] == i+2:
            ans += 1
            flg = True
        else:
            ans += 1
print(ans)


Measured memory_bytes: 20356
n = int(input())
ans = (n*(n+1))//2
mod3 = (((n//3) * ((n//3) + 1))//2 ) * 3
mod5 = (((n//5) * ((n//5) + 1))//2 ) * 5
mod15 = (((n//15) * ((n//15) + 1))//2 ) * 15
print(ans - mod3 - mod5 + mod15)

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  vector<vector<ll>> x(n, vector<ll>(2));
  for(int i = 0; i < n; i++) cin >> x.at(i).at(0) >> x.at(i).at(1);
  
  sort(x.begin(), x.end());
  
  for(int i = 1; i < n; i++) x.at(i).at(1) += x.at(i - 1).at(1);
  
  for(int i = 0; i < n; i++){
    if(x.at(i).at(1) >= k){
      cout << x.at(i).at(0) << "\n";
      return 0;
    }
  }
}

Measured memory_bytes: 5760
FLOORS = 3
ROOMS = 10
SEPARATOR = "####################"


def generate_empty_building():
    return [[0 for _ in range(ROOMS)] for _ in range(FLOORS)]


def output_building(single_building):
    for floor in single_building:
        print(" " + " ".join(str(room) for room in floor))


building_one = generate_empty_building()
building_two = generate_empty_building()
building_three = generate_empty_building()
building_four = generate_empty_building()

notices = int(input())

for _ in range(notices):
    building_num, floor_num, room_num, people = [int(x) for x in input().split()]

    if building_num == 1:
        building_one[floor_num - 1][room_num - 1] += people
    if building_num == 2:
        building_two[floor_num - 1][room_num - 1] += people
    if building_num == 3:
        building_three[floor_num - 1][room_num - 1] += people
    if building_num == 4:
        building_four[floor_num - 1][room_num - 1] += people

buildings = [building_one, building_two, building_three, building_four]

i = 0

for building in buildings:
    i += 1
    output_building(building)
    if i < 4:
        print(SEPARATOR)



Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			System.out.println("Possible ");
		} else {
			System.out.println("Impossible ");
		}


	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 ll INF = 1e18;
const ll MOD = 1e9 + 7;

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

    int n = s.size();
    int ans = 0;
    rep(i, n/2){
        if(s[i] != s[n-i-1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Practice AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut vs = vec![];
    for _ in 0 .. n {
        vs.push(get!());
    }
    vs.sort();
    let ans = vs[n / 2] - vs[n / 2 - 1];
    println!("{}", ans);
}

Measured memory_bytes: 6396
import re

def norm(s):
    s1 = list(map(len, re.split('0+', s)))
    s0 = list(map(len, re.split('1+', s)))
    if s0[0] == 0:
        s0.pop(0)
    if s0[-1] == 0:
        s0.pop(-1)
    return [s0,s1]

def solve(n, k, s):
    s0, s1 = norm(s)

    if len(s1) == 1:
        return(s1[0])

    if len(s0) <= k:
        return n
    
    s0_sum = sum(s0[0:k])
    s1_sum = sum(s1[0:k+1])

    v = s0_sum + s1_sum
    mv = v
    
    for last_idx in range(0, len(s0) - k):
        # update
        v = (v - s0[last_idx] + s0[last_idx + k] -
             s1[last_idx] + s1[last_idx + k + 1])
        if mv < v:
            mv = v

    return mv


n, k = map(int,input().split())
s = input()
print(solve(n, k, s))



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

// @author: pashka

int k;
vector<int> a;

void bt(int len) {
    if (k == 0) return;
    if (a.size() == len) {
        k--;
        if (k == 0) {
            for (int x : a) cout << x;
        }
        return;
    }
    int l = a.empty() ? 1 : max(a.back() - 1, 0);
    int r = a.empty() ? 9 : min(a.back() + 1, 9);
    for (int x = l; x <= r; x++) {
        a.push_back(x);
        bt(len);
        a.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);

    cin >> k;
    for (int len = 1; k > 0; len++) {
        bt(len);
    }    
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//#define int long long
long long inf = 1e18;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, q;
  cin >> a >> b >> q;
  vector<long long> s(a + 2), t(b + 2), x(q);

  for (int i = 1; i <= a; i++) {
    cin >> s[i];
  }

  for (int i = 1; i <= b; i++) {
    cin >> t[i];
  }
  s[0] = t[0] = -1 * inf;
  s[a + 1] = t[b + 1] = inf;
  for (auto &&w : x) {
    cin >> w;
  }
  //   sort(s.begin(), s.end());
  //   sort(t.begin(), t.end());

  for (auto &&w : x) {
    long long res = inf;
    int ls = lower_bound(s.begin(), s.end(), w) - s.begin();
    int lt = lower_bound(t.begin(), t.end(), w) - t.begin();
    for (int is : {ls - 1, ls})
      for (int it : {lt - 1, lt}) {
        res = min(res, abs(w - s[is]) + abs(s[is] - t[it]));
        res = min(res, abs(w - t[it]) + abs(s[is] - t[it]));
      }
    cout << res << endl;
  }
}


Measured memory_bytes: 3712
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"debug.hpp"
#include"print.hpp"
#endif
// }}}

vector<vector<int> > dir = {{0,1},{1,0},{0,-1},{-1,0}};

Int H;
Int W;
vector<string> A;

Int dist[1010][1010];
bool vis[1010][1010];

void solve(){
	memset(vis,false,sizeof(vis));
	queue<pii> q;
	REP(i,H)REP(j,W){
		if(A[i][j]=='#')dist[i][j] = 0,q.push({i,j});
		else dist[i][j] = inf<Int>();
	}
	Int ans = 0;
	for(;!q.empty();){
		int x = q.front().first, y = q.front().second;
		q.pop();
		if(vis[x][y])continue;
		vis[x][y] = true;
		ans = max(ans,dist[x][y]);
		for(auto &&p:dir){
			int x2 = x + p[0], y2 = y + p[1];
			if(x2<0 or H<=x2 or y2<0 or W<=y2)continue;
			if(dist[x2][y2]>dist[x][y]+1){
				dist[x2][y2] = dist[x][y] + 1;
				q.push({x2,y2});
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> H;
    cin >> W;
    A.assign(H,string());
    for(int i = 0 ; i < H ; i++){
        cin >> A[i];
    }
	solve();
	return 0;
}


Measured memory_bytes: 18448
import java.util.Scanner;

//Unreliable Message
public class Main{

	String J(String s){
		return s.charAt(s.length()-1)+s.substring(0, s.length()-1);
	}
	String C(String s){
		return s.substring(1)+s.charAt(0);
	}
	String E(String s){
		return s.length()%2==0?s.substring(s.length()/2, s.length())+s.substring(0, s.length()/2):
			s.substring(s.length()/2+1, s.length())+s.charAt(s.length()/2)+s.substring(0, s.length()/2);
	}
	String A(String s){
		return new StringBuilder(s).reverse().toString();
	}
	String P(String s){
		String res = "";
		for(char c:s.toCharArray()){
			if(!Character.isDigit(c))res+=c;
			else res += (char)((c-'0'+9)%10+'0');
		}
		return res;
	}
	String M(String s){
		String res = "";
		for(char c:s.toCharArray()){
			if(!Character.isDigit(c))res+=c;
			else res += (char)((c-'0'+1)%10+'0');
		}
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			char[] c = sc.next().toCharArray();
			String s = sc.next();
			for(int i=c.length-1;i>=0;i--)s=c[i]=='J'?J(s):c[i]=='C'?C(s):c[i]=='E'?E(s):c[i]=='A'?A(s):c[i]=='P'?P(s):M(s);
			System.out.println(s);
		}
	}

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

Measured memory_bytes: 12000
towers = [
    [[0 for i in range(10)] for j in range(3)] for k in range(4)
]
floor = 3

n = int(input())
for i in range(n):
    b,f,r,v = list(map(int,input().split()))
    towers[b-1][f-1][r-1] += v

for b in towers:
    for f in b:
        for r in f:
            print(' ' + str(r), end='')
        print('')
    if floor:
        print('#'*20)
        floor -= 1

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	int x;
	cin >> x;

	cout << !x << '\n';

	return 0;
}


Measured memory_bytes: 3600
#include "stdio.h"

int main(void){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
	long long a,b,c;
	int n,p;
	cin>>n;
	a=2;
	b=1;
	if(n==0){
	cout<<a;
	return 0;
	}
	if(n==1){
	cout<<b;
	return 0;
	}
	c=a+b;
	for(p=3;p<=n;p++){
		a=b;
		b=c;
		c=a+b;
	} 
	cout<<c;
	return 0;
}

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

int main() {
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    printf("%s\n", y > 2019 || (y == 2019 && m > 4) ? "TBD" : "Heisei");

    return 0;
}

Measured memory_bytes: 128
//package atcoderdp;
import java.util.*;
class Main {
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int a[][]= new int[n][3];
        for (int i = 0; i <n ; i++) {
            for (int j = 0; j <3 ; j++) {
                a[i][j]=s.nextInt();
            }
        }
        System.out.println(find(a,n));
    }
    public static int find(int a[][],int n){
        int dp[][]= new int[n][3];
        dp[0][0] = a[0][0];
        dp[0][1] = a[0][1];
        dp[0][2] = a[0][2];
        for (int i = 1; i <n ; i++) {
            dp[i][0] = Math.max(dp[i-1][1],dp[i-1][2])+a[i][0];
            dp[i][1] = Math.max(dp[i-1][0],dp[i-1][2])+a[i][1];
            dp[i][2] = Math.max(dp[i-1][0],dp[i-1][1])+a[i][2];
        }
        return Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    }

}


Measured memory_bytes: 63544
#include<bits/stdc++.h>
using namespace std;
long long n,w,x,y;
long long dp[100005];
int main()
{
    cin>>n>>w;
    for(int i=1;i<=100001;i++)
    dp[i]=2000000000;
    dp[0]=0;
    for(int i=0;i<n;++i)
    {
        cin>>x>>y;
        for(int j=100000;j>=y;j--)
            dp[j]=min(dp[j],dp[j-y]+x);
    }
    for(int i=100000;i>=0;--i)
    {
        if(dp[i]<=w)
        {
            printf("%d\n",i);
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	//ans= (2^(n+m) - 2^(n+m-rank))/2
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,i,j,n,m;cin>>n>>m;
	vector<vector<int>>mat(n,vector<int>(m));
	int x=0;//rank
	vector<int>kara(m);
	for(h=0;h<n;h++){
		for(j=0;j<m;j++){cin>>mat[x][j];}
		for(i=0;i<x;i++){
			int ifp=0;
			while(ifp<m&&mat[i][ifp]==0){ifp++;}
			if(ifp!=m&&mat[x][ifp]){
				for(j=0;j<m;j++){mat[x][j]^=mat[i][j];}
			}
		}
		if(mat[x]==kara){continue;}
		
		int bas=x;
		while(bas>0&&mat[bas]>mat[bas-1]){swap(mat[bas],mat[bas-1]);bas--;}
		x++;
		/*cerr<<"de"<<endl;
		for(i=0;i<x;i++){
			for(j=0;j<m;j++){
				cerr<<mat[i][j];
			}cerr<<endl;
		}*/
	}
	llint ans=1;
	for(i=0;i<x;i++){ans*=2;ans%=mod;}
	ans--;
	for(i=1;i<n+m-x;i++){ans*=2;ans%=mod;}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-1
	vector<int> Parent;
	
	//作る時はParentの値をすべて-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N){
		Parent = vector<int>(N,-1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A){
		if(Parent[A]<0)return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A){
		return Parent[root(A)];//親をとってきたい
	}
	
	//AとBをくっつける
	bool connect(int A,int B){
		//AとBを直接つなぐのではなく,root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if(A==B){
			//すでにくっついているからくっつけない
			return false;
		}
		
		//大きい方(A)に小さいaとき(B)をくっつけたい
		//大小が逆だったらひっくり返す
		if(size(A)<size(B))swap(A,B);
		
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		Parent[B] = A;
		return true;
	}
};

int main(void){
	long long N,M;
	cin >> N >> M;
	vector<int> A(M),B(M);
	for(int i=0;i<M;i++){
		cin >> A[i] >> B[i];
		A[i]--;B[i]--;
	}
	vector<long long> ans(M);
	ans[M-1] = (long long)(N*(N-1))/2;
	UnionFind Uni(N);
	
	for(int i= M-1;i>=1;i--){
		ans [i-1] = ans[i];
		//繋がっていないのがつながったとき
		if(Uni.root(A[i]) != Uni.root(B[i])){
			ans[i-1] -=(long long)Uni.size(A[i])*Uni.size(B[i]);
			Uni.connect(A[i],B[i]);
		}
	}
	for(int i=0;i<M;i++){
		cout << ans[i] << endl;
	}
}



Measured memory_bytes: 3328