akhauriyash/Code-Regression huggingface dataset:
let cnt = ref 0

let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> List.rev (s :: acc)
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  doit str []

let print_array a =
  Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) a;
  print_newline ()

let selection_sort a n =
  let rec select j minj =
    if j >= n then minj
    else select (j + 1) (if a.(j) < a.(minj) then j else minj)
  in
  let rec doit i =
    if i >= n then ()
    else begin
      let minj = select i i in
      if minj <> i then begin
        let tmp = a.(i) in a.(i) <- a.(minj); a.(minj) <- tmp;
        incr cnt
      end;
      doit (i + 1)
    end
  in
  doit 0

let () =
  let n = read_int () in
  let a = Array.of_list (List.map int_of_string (split (read_line ()) ' ')) in
  selection_sort a n;
  print_array a;
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 2304
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		for(int i=0;i<N;i++){
			int a=0,b=0,c=0;
			int x=sc.nextInt();
			int y=sc.nextInt();
			if(x>y){
				int t=x;
				x=y;
				y=t;
			}
			int z=sc.nextInt();
			if(z<x){
				a=z;
				b=x;
				c=y;
			}else if(z<y){
				a=x;
				b=z;
				c=y;
			}else{
				a=x;
				b=y;
				c=z;
			}
			if(a*a+b*b==c*c){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 33128
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Time {
  constructor(now = 0) {
    this.now = now;
  }
  getNow() {
    return ++this.now;
  }
}
const time = new Time();

class Node {
  constructor(id) {
    this.id = id;
    this.children = [];
  }
  add(node) {
    this.children.push(node);
  }
  inCalc() {
    return !!this.start;
  }
  calc() {
    this.start = time.getNow();
    this.children.sort((a, b) => a.id > b.id);
    this.children.forEach(child => child.inCalc() || child.calc());
    this.end = time.getNow();
  }
  toString() {
    return [this.id, this.start, this.end].join(' ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    this.map.has(id) || this.map.set(id, new Node(id));
    return this.map.get(id);
  }
  calc() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      node.inCalc() || node.calc();
    }
  }
  print() {
    for (let i = 1; i <= this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([u, k, ...vk]) => {
  const parent = tree.getNode(u);
  vk.forEach(v => {
    const node = tree.getNode(v);
    parent.add(node);
  });
});

tree.calc();
tree.print();



Measured memory_bytes: 16956
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

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

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

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

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

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

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

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  string s;
  int a;
  cin >> a >> s;
  if(a >= 3200){
    cout << s << endl;
  }else{
    cout << "red" << endl;
  }
  return 0;
}


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

int main(){
     int N;
     while(cin>>N,N){
	  int sum=0;
	  int i;
	  for(i=(int)sqrt(N);i>0;i--){
	       if(N%i==0){
		    //cout<<i<<" ";
		    sum+=i;
		    if(N!=i*i)sum+=N/i;
	       }
	       //if(sum>N)break;
	  }
	  sum-=N;
	  if(sum>N){
	       cout<<"abundant number"<<endl;
	  }else if(sum==N){
	       cout<<"perfect number"<<endl;
	  }else{
	       cout<<"deficient number"<<endl;
	  }
     }
     return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 1000000007
typedef long long ll;



int main(){
  int n,m;
  cin>>n>>m;
  ll ans=1;
  if(abs(n-m)>1){
    ans=0;
  }else{
    for(int i=1;i<=n;i++){
      ans*=i;
      ans%=MAX;
    }
    for(int i=1;i<=m;i++){
      ans*=i;
      ans%=MAX;
    }
    if(n==m) ans*=2;
    ans%=MAX;
    
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
data = []
for i in range(N):
  data.append(input())
input_data=[]
for i in range(M):
  input_data.append(input())
flag_1 = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    flag = True
    for k in range(M):
      for l in range(M):
        if data[i+k][j+l] != input_data[k][l]:
          flag = False
    if flag:
      flag_1 = True

if flag_1:
  print("Yes")
else:
  print("No")

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}


int main(){
    int m,d;
    int count = 0;
    cin >> m >> d;
    for (int i = 1; i < m + 1; i++){
        for (int j = 1; j < d + 1; j++){
            string k = to_string(j);
            if (k.size() == 2 && k[1] != '1' && k[0] != '1'){
                if (ctoi(k[0])*ctoi(k[1]) == i) count += 1;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define int long long int
#define ss size()

using namespace std;

const int M=1e9+7,maxn=3005;
std::vector<int> adj[30];
std::vector<int> v1;
std::vector<int> v;

int ans,n,k,m,x,y,q,par[maxn],h[maxn],mach[maxn];
bool mark[maxn];


int32_t main(){
    cin>>n>>m;
    cout<<(n-1)*(m-1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N;

ll q (ll* x, int i) {
        ll res = 1e18;
        for (i += N+5; i; i /= 2) res = min(res, x[i]);
        return res;
}

void u (ll* x, int l, int r, ll mn) {
        for (l += N+5, r += N+5; l<r; l /= 2, r /= 2) {
                if (l&1) x[l] = min(x[l], mn), l++;
                if (r&1) --r, x[r] = min(x[r], mn);
        }
}

ll E, T, x[100100], dp[100100], close[200200], far[200200];

int main () {
        scanf("%d %lld %lld", &N, &E, &T);
        fo(i, 0, N) scanf("%lld", &x[i]);
        x[N] = E;

        fo(i, 0, 200200) close[i] = far[i] = 1e18;

        dp[0] = x[0];
        fo(i, 0, N) {
                int lo = i, hi = N-1, mid, v = -1;
                while (lo <= hi) {
                        mid = (lo+hi)/2;
                        if (2*(x[mid]-x[i]) <= T) lo = mid+1, v = mid;
                        else hi = mid-1;
                }

                u(close, i+1, v+2, dp[i] + T - x[i]);
                u(far, v+2, N+1, dp[i] - 3*x[i]);

                dp[i+1] = min(q(close, i+1) + x[i], q(far, i+1) + 3*x[i]);
                dp[i+1] += x[i+1] - x[i];
        }

        printf("%lld\n", dp[N]);
        return 0;
}


Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;
vector<int>a;
int root(int c){
    int x = a[c];
    if (x == c)return x;
    return a[c] = root(a[c]);
    
}
void u(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)return;
    if (y > x)swap(y,x);
    a[x] = y;
}


int main()
{
    int n, m;
    cin >> n >> m;
    a.resize(n + 3);
    vector<int>t(n + 3);// , a(n + 3);
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        a[i] = i;
    }

    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        int x, y;
        x = root(a[c]); y = root(a[d]);
        //if (c > d)swap(c, d);
        if (x == y)continue;
        u(c, d);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        a[i] = root(a[i]);
    }
    for(int i=1;i<=n;i++){
        if (a[t[i]] == a[i])ans++;
      //  cout << a[i] <<" "<<a[t[i]]<< " " << ans << endl;;
    }
    cout << ans << endl;
    


    return 0;

}

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

int n,q;
void input();
ll sum;
map<ll,ll>mp;
void solve(){
    cin>>q;
    for(int i=0;i<q;i++){
        ll b,c;
        cin>>b>>c;
        sum-=mp[b]*b;
        sum+=c*mp[b];
        mp[c]+=mp[b];
        mp[b]=0;
        cout<<sum<<"\n";
    }
}

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

    input();solve();
}

void input(){
    cin>>n;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        sum+=a;
        mp[a]++;
    }
}


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

int main() {
  int n; cin>>n;
  vector<int> A(n);
  rep(i, n) cin>>A[i];

  ll ans=0;
  int right=0;
  int X=0;
  for (int left=0; left<n; left++) {
    while ((right<n)&&((X+A[right])==(X^A[right]))) {
      X+=A[right];
      right++;
    }
    ans+=right-left;
    if (right==left) right++;
    else X-=A[left];
  }
  cout<<ans<<endl;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){



}


void solve(){

    ll n,m;
    cin >> n >> m;
    if(n==m){
        cout << "Yes";
    }else{
        cout << "No";
    }

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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



int main() {
    
  
    int N;
    double summoney;
    
    cin >> N ;
 
    double x;
    string u;
    
    for (int i=0 ; i<N ; i++){
        cin >> x >> u ;
        if( u == "JPY"){
            summoney += x ;
        }
        else {
            summoney += x * 380000.0 ;
        }
    }
    
    cout << summoney << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
count = 0
flg = 1
while(1):
    for i in range(N):
        if A[i]%2 != 0:
            flg = 0
            break
        else:
            A[i] = A[i]/2
    if flg == 0:
        print(count)
        break
    count += 1

Measured memory_bytes: 38512
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
from collections import Counter
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def accumurate(l):
    ret = [0] * len(l)
    ret[0] = l[0]

    for i in range(1, len(l)):
        ret[i] = ret[i - 1] + l[i]

    return ret


def main():

    n, k = geta(int)
    p = [0] + list(geta(int))
    c = [0] + list(geta(int))

    inf = 1 << 32

    used = [False] * (n + 1)
    ans = -inf

    for i in range(1, n + 1):

        if used[i]:
            continue
        else:
            used[i] = True

        c_loop = []
        j = p[i]
        c_loop += [c[j]]

        while j != i:
            used[j] = True
            j = p[j]
            c_loop += [c[j]]

        n_loop = len(c_loop)
        cs_loop = accumurate(c_loop + c_loop)
        tot_loop = cs_loop[n_loop - 1]

        _jmax = min(k, n_loop)

        for _i in range(n_loop):
            for _j in range(1, _jmax + 1):
                _tmp = cs_loop[_j + _i] - cs_loop[_i]

                if tot_loop > 0 and k > _j:
                    _tmp += (k - _j) // n_loop * tot_loop

                if ans < _tmp:
                    ans = _tmp

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 71036
n=int(input())
A=[[int(0)]*10 for i in range(3)]
B=[[int(0)]*10 for i in range(3)]
C=[[int(0)]*10 for i in range(3)]
D=[[int(0)]*10 for i in range(3)]

for i in range(n):
  b,f,r,v=(int(x) for x in input().split())
  if b==1:
    A[f-1][r-1]+=v
  if b==2:
    B[f-1][r-1]+=v
  if b==3:
    C[f-1][r-1]+=v
  if b==4:
    D[f-1][r-1]+=v

for i in range(3):
  for j in range(10):
    print(" ",A[i][j],sep="",end="")
  print("")
print("####################")

for i in range(3):
  for j in range(10):
    print(" ",B[i][j],sep="",end="")
  print("")
print("####################")

for i in range(3):
  for j in range(10):
    print(" ",C[i][j],sep="",end="")
  print("")
print("####################")

for i in range(3):
  for j in range(10):
    print(" ",D[i][j],sep="",end="")
  print("")


Measured memory_bytes: 5644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main(void){
    int n;
    cin >> n;

    vector<vector<pair<int, int>>> XY(n);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        for(int j=0; j<a; j++){
            int x, y;
            cin >> x >> y;
            XY[i].push_back(make_pair(x-1, y));
        }
    }
    
    int ans = 0;
    for(int bit=0; bit < (1<<n); bit++){
        int flag = 0;
        for(int i=0; i<n; i++){
            int person = ((bit >> i) & 1);
            for(int j=0; j<XY[i].size(); j++){
                if(person == 1){
                    if(XY[i][j].second != (bit >> (XY[i][j].first) & 1) ){
                        flag = 1;
                    }
                }
            }
        }
        if(flag == 0){
            ans = max(ans, counter(bit));
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

int main(){
	migmig;
	int n;
	cin>>n;
	vector< pair <int,int> >v;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		v.push_back(make_pair(x,i+1));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		cout<<v[i].second<<" ";
	}
	return 0;
}



Measured memory_bytes: 1780
/*
 * ABC100_D.cpp
 *
 *  Created on: Jun 21, 2018
 *      Author: 13743
 */

#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

lng x[1000], y[1000], z[1000];
lng a[1000];

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

	int N, M;
	cin >> N >> M;
	REP(i, N) {
		cin >> x[i] >> y[i] >> z[i];
	}

	lng ans = 0;
	REP(i, 8) {
		int e = (i&1) ? 1 : -1;
		int f = ((i>>1)&1) ? 1 : -1;
		int g = ((i>>2)&1) ? 1 : -1;
		REP(j, N) {
			a[j] = e*x[j]+f*y[j]+g*z[j];
		}
		sort(a, a+N);
		lng tmp = 0;
		REP(j, M) {
			tmp += a[N-1-j];
		}
		ans = max(ans, tmp);
	}

	cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}


int main(){

    int n,m,x;
    cin >> n  >> m >> x;
    m ++;
    int a[n][m];
    REP(i,n){
        REP(j,m){
            cin >> a[i][j];
        }
    }
    int ins = 99999999;
    int ans = ins;
    REP(bit,1<<n){
        int b[m];
        REP(j,m){
            b[j] = 0;
        }
        REP(j,n){
            if(bit & (1<<j)){
                REP(k,m){
                    b[k] += a[j][k];
                }
            }
            bool fl = true;
        REP(k,m){
            if(k == 0) continue;
            if(b[k] < x){
                fl = false;
            }
        }
        
        if(fl){
            ans = min(ans, b[0]);
        }



        }
        
    }

    if(ans == ins){
        cout << "-1" <<endl;
    }else{
        cout << ans <<endl;
    }
}





Measured memory_bytes: 3592
#include<iostream>
#define mod 998244353
using namespace std;
int a, b, c, d, i, j;
int dp[3005][3005], e[3005][3005];
int main(){
    cin>> a >> b >> c >> d;
    dp[c][d] = 1;
    for(i = c; i > a; i--){
        for(j = d; j > b; j--){
            e[i][j] = (dp[i][j] + e[i][j + 1] * 1LL * i) % mod;
        }
        for(j = d; j >= b; j--){
            dp[i][j] = (dp[i][j] + e[i][j + 1]) % mod;
            dp[i - 1][j] = (dp[i - 1][j] + dp[i][j] * 1LL * j) % mod;
        }
    }
    for(j = d; j > b; j--){
        dp[a][j - 1] = (dp[a][j - 1] + dp[a][j] * 1LL * a) % mod;
    }
    cout<< dp[a][b];
}


Measured memory_bytes: 73940
#include<stdio.h>
int main()
{
    int a[101],b=0,j=0,i,s,e,o;
    scanf("%d",&e);
    for(i=0;i<e;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            j++;
    }
       for(i=0;i<e;i++)
       {
            if(a[i]%2==0 && (a[i]%3==0 || a[i]%5==0))
            b++;

        }

    if(j==b)
        printf("APPROVED\n");
    else
        printf("DENIED\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

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

    for (int i = 0; ; i++) {
      if (Math.pow(i,2) > n) {
        System.out.println((long)Math.pow(i-1,2));
        break;
      }
    }

  }

}


Measured memory_bytes: 23124
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();
            if(n == 0) break;
            int s = 0;
            int max = 0;
            int min = 1000;
            for(int i=0; i<n; i++) {
                int t = sc.nextInt();
                s += t;
                max = Math.max(t, max);
                min = Math.min(t, min);
            }
            System.out.println((s-max-min) / (n-2));
        }
    }
}



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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

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

    int idx = -1;

    for (int i = 0; i < s.size() - t.size() + 1; ++i) {
        bool ok = true;
        for (int j = 0; j < t.size(); ++j) {
            if (s.at(i+j) == '?' || s.at(i+j) == t.at(j)) continue;

            ok = false;
            break;
        }

        if (ok) idx = i;
    }

    if (idx != -1) {
        string tmp = s.substr(0, idx) + t + s.substr(idx + t.size());
        string ans = regex_replace(tmp, regex("\\?"), "a");
        MSG(ans)
    } else {
        MSG("UNRESTORABLE")
    }
}


Measured memory_bytes: 256
def make_divisors(n):
    lw, up = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lw.append(i)
        if i * i != n:
            up.append(n//i)
        i += 1
    return lw + up[::-1]

N = int(input())
ans = 0
li = make_divisors(N)
if N == 1 or N==2:
    print(0)
    exit()

for x in li:
    if x * (x+2) > N:
        break
    ans += N//x - 1
print(ans)


Measured memory_bytes: 63980
N,W = map(int,input().split())
a,b,c,d = [],[],[],[]
for i in range(N):
    w,v = map(int,input().split())
    if i == 0:
        w0 = w
    if w == w0:
        a.append(v)
    elif w == w0+1:
        b.append(v)
    elif w == w0+2:
        c.append(v)
    else:
        d.append(v)
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
d.sort(reverse=True)
A,B,C,D = len(a),len(b),len(c),len(d)
a1 = [0]*(A+1)
b1 = [0]*(B+1)
c1 = [0]*(C+1)
d1 = [0]*(D+1)
for i in range(1,A+1):
    a1[i] = a1[i-1] + a[i-1]
for i in range(1,B+1):
    b1[i] = b1[i-1] + b[i-1]
for i in range(1,C+1):
    c1[i] = c1[i-1] + c[i-1]
for i in range(1,D+1):
    d1[i] = d1[i-1] + d[i-1]
ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            for l in range(D+1):
                if w0*i + (w0+1)*j + (w0+2)*k + (w0+3)*l <= W:
                    ans = max(ans,a1[i]+b1[j]+c1[k]+d1[l])
                else:
                    break
print(ans)

Measured memory_bytes: 73808
MOD = 10**9+7
N = int(input())
C = [int(input()) for i in range(N)]

dp = [0 for i in range(N)]
dp[0] = 1

color = {}
for c in C:
    color[c] = 0
color[C[0]] = 1

for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i-1] != C[i]:
        dp[i] = (dp[i] + color[C[i]])%MOD
    color[C[i]] = dp[i]
print(dp[-1])


Measured memory_bytes: 31004
#!/usr/bin/env python3
#!/usr/bin/env pypy3

from math import *

def main():
    import sys
    sys.dont_write_bytecode = True
    sys.setrecursionlimit(10000000)

    input = sys.stdin.readline

    #import numpy as np
    #import scipy as sp

    # Python 3 modules: https://docs.python.org/3/library/

    import os
    import math, itertools, operator
    from math import factorial as fact
    from operator import itemgetter, attrgetter
    from itertools import permutations, combinations
    from functools import reduce, lru_cache
    # Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
    # Before Python 3.5.  Import from math after it.
    from fractions import gcd
    from fractions import Fraction as Frac

    inf = float('inf')
    pow = __builtins__.pow

    def lcm(a, b):
        return a * b // gcd(a,b)

    def perm(a, b):
        import scipy.special
        return scipy.special.perm(a, b, exact = True)

    def comb(a, b):
        import scipy.special
        return scipy.special.comb(a, b, exact = True)

    def dfact(n):
        import scipy.special
        return scipy.special.factorial2(n, exact = True)

    def prod(l):
        return reduce(operator.mul, l)

    def input_ints(func = input, sep = None, conv = int):
        return list(map(conv, func().split(sep = sep)))

    if os.environ.get('GOROOT') is None:
        def dprint(*args, **kwargs):
            kwargs['file'] = sys.stderr
            import inspect
            frame = inspect.currentframe().f_back
            print('[' + os.path.basename(frame.f_code.co_filename)
                    + ':' + str(frame.f_lineno) + ']', *args, **kwargs)
    else:
        def dprint(*args, **kwargs):
            pass


    ############################################################################


    #= list(map(int, input().split()))
    S = input()[:-1]
    N = len(S)
    dprint(S, N)

    dest = [None] * N

    r_start = 0
    for i in range(1, N):
        if S[i] == 'L':
            if r_start is not None:
                for j in range(r_start, i):
                    if (j - i) % 2 == 0:
                        dest[j] = i - 0
                    else:
                        dest[j] = i - 1
                r_start = None
        elif r_start is None:
            r_start = i
    #dprint(dest)

    l_start = N - 1
    for i in range(N - 2, -1, -1):
        if S[i] == 'R':
            if l_start is not None:
                for j in range(l_start, i, -1):
                    if (i - j) % 2 == 0:
                        dest[j] = i + 0
                    else:
                        dest[j] = i + 1
                l_start = None
        elif l_start is None:
            l_start = i
    #dprint(dest)

    cnt = [0] * N
    for d in dest:
        cnt[d] += 1
    print(*cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12504
def resolve():
    n = int(input())
    d1 = {}
    d2 = {}

    for i in range(n):
        x, y = map(int, input().split())
        if x+y not in d1:
            d1[x+y] = 1
        if x-y not in d2:
            d2[x-y] = 1
    d1key = d1.keys()
    d1key = sorted(d1key)
    d2key = d2.keys()
    d2key = sorted(d2key)
    print(max(abs(d1key[0]-d1key[-1]), abs(d2key[0]-d2key[-1])))
resolve()

Measured memory_bytes: 134704
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 109;
int n,m;
char mat[MAXN][MAXN];
int cnt[30];
int tot[5];

void solve(){
	int i,j;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cnt[mat[i][j]-'a'+1]++;
		}
	}
	for(i=1;i<=26;i++){
		if(cnt[i]==0)
			continue;
		tot[cnt[i]%4]++;
	}
	//case1
	if(n%2==0 && m%2==0){
		if((tot[1] | tot[2] | tot[3])>0){
			puts("No");
		}
		else{
			puts("Yes");
		}
	}
	//case2
	else if(n%2 + m%2==1){
		if(tot[1]>0 || tot[3]>0){
			puts("No");
			return;
		}
		if(n%2==1){
			if(tot[2]*2>m){
				puts("No");
				return;
			}
			else{
				puts("Yes");
			}
		}
		else{
			if(tot[2]*2>n){
				puts("No");
				return;
			}
			else{
				puts("Yes");
			}
		}
	}
	//case3
	else{
		bool center=false;
		bool center3=false;
		if(tot[1]>1){
			puts("No");
			return;
		}
		if(tot[1]==1){
			tot[1]=0;
			center=true;
		}
		if(tot[3]>1){
			puts("No");
			return;
		}
		if(tot[3]==1){
			if(center==true){
				puts("No");
				return;
			}
			center=true;
			center3=true;
			tot[3]--;
		}
		if(center==false){
			puts("No");
			return;
		}
		if((center3+tot[2])*2>n-1+m-1){
			puts("No");
		}
		else{
			puts("Yes");
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	int i;
	for(i=1;i<=n;i++)
		scanf("%s",mat[i]+1);
	solve();
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) 
#define X first
#define Y second 
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a) 
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f;
ll a[N]; 


int main()
{
	IOS;
	ll n;
	cin>>n;
	ll a1 = MAX, b1 = MAX, a2 = MIN, b2 = MIN;
	rep1(i, n)
	{
		ll x, y;
		cin>>x>>y;
		a1=min(a1,x+y),a2=max(a2,x+y);
        b1=min(b1,x-y),b2=max(b2,x-y);
	}
	ll ans=max(a2-a1,b2-b1);
	cout<<ans<<nl;
	AC;
} 

Measured memory_bytes: 3592
def cnt(n, x):
	if x==0:
		return 0
	elif n==0:
		return 1
	elif x<2**(n+1)-1:
		return cnt(n-1, x-1)
	elif x==2**(n+1)-1:
		return 2**n
	elif x<2**(n+2)-3:
		return cnt(n-1, 2**(n+1)-3) + 1 + cnt(n-1, x-2**(n+1)+1)
	else:
		return 2**(n+1)-1

n, x = map(int, input().split())
print(cnt(n, x))

Measured memory_bytes: 3064
n, m, x = map(int, input().split())
a = [int(x) for x in input().split()]
key1 = len(a)
key2 = 0
for i in range(key1):
    if a[i] <= x:
        key2 += 1
    else:
        break
print(min([key2, key1-key2]))

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

int main()
{
    char s[100001];
    int a[26] = {0};
    int i;
    scanf("%s", s);
    for (i=0; i<strlen(s); i++)
    {
        a[s[i] - 97] = 1;
    }
    int count = 0;
    for (i=0; i<26; i++)
    {
        if (a[i] == 0) {
            printf("%c\n", i + 97);
            break;
        }
        count ++;
    }
    if (count == 26) {
        printf("None\n");
    }
    return 0;
}


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

int N;
int K;
vector<int> a(100001);

bool check(int x) {
    vector<int> cnt(100001, 0);
    set<int> all;
    for ( int i = 0; i < x; i++ ) {
        if ( a[i] <= K ) all.insert(a[i]);
        cnt[a[i]]++;
    }

    if ( all.size() >= K ) return true;
    for ( int i = 0; i < N-x; i++ ) {
        cnt[a[i]]--;
        if ( !cnt[a[i]] ) all.erase(a[i]);
        if ( a[i+x] <= K ) {
            all.insert(a[i+x]);
            cnt[a[i+x]]++;
        }
        if ( all.size() >= K ) return true;
    }

    return false;
}

int main() {
    cin >> N >> K;
    set<int> all;
    for ( int i = 0; i < N; i++ ) {
        cin >> a[i];
        if ( a[i] <= K ) all.insert(a[i]);
    }

    if ( all.size() < K ) {
        cout << 0 << endl;
        return 0;
    }

    int l = 0, r = N;
    while ( r-l > 1 ) {
        int mid = (l+r) / 2;
        if ( check(mid) ) r = mid;
        else l = mid;
    }

    cout << r << endl;
}



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

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

ll dp[N];
vector <pair<pll, pll>> u;

int main () {
    ll n;
    scanf("%lld", &n);
    for (int i = 0; i < n; i++) {
        ll w, s, v;
        scanf("%lld%lld%lld", &w, &s, &v);
        u.pb({{s+w, w}, {s, v}});
    }

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

    for (int i = 0; i < n; i++) {
        ll w = u[i].st.nd;
        ll s = u[i].nd.st;
        ll v = u[i].nd.nd;
        for (int j = s; j >= 0; j--)
            dp[j+w] = max(dp[j+w], dp[j]+v);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) ans = max(ans, dp[i]);

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 512
# Q2
H, W = map(int, input().split())
a = [[c for c in input()] for _h in range(H)]


for h in range(H):
    if '#' not in a[h]:
        for w in range(W):
            a[h][w] = ''
for w in range(W):
    if '#' not in [p[w] for p in a]:
        for h in range(H):
            a[h][w] = ''

for h in range(H):
    line = ''.join(a[h])
    if line:
        print(''.join(a[h]))

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

bool isok(string &s)
{
    int bit = 0;
    for (auto c : s)
    {
        int flg = 1 << (c - '0');
        bit = bit | flg;
    }
    return __builtin_popcount(bit) == 1;
}

void solve()
{
    string S;
    cin >> S;
    map<char, int> mp;
    for (auto c : S)
    {
        mp[c]++;
    }

    int ans = INTINF;

    for (auto p : mp)
    {
        string T = S;
        int ops = 0;
        char c = p.first;
        while (!isok(T))
        {
            string R;
            for (int i = 0; i < T.length() - 1; i++)
            {
                if (T[i] == c)
                {
                    R.push_back(T[i]);
                }
                else if (T[i + 1] == c)
                {
                    R.push_back(T[i + 1]);
                }
                else
                {
                    R.push_back(T[i]);
                }
            }
            ops++;
            T = R;
        }
        ans = min(ans, ops);
    }

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

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    int s,w;
    cin>>s>>w;

    (w>=s)? cout<<"unsafe" : cout<<"safe";

    cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 3668
#include "bits/stdc++.h"
using namespace std;    

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
int gcd(int a, int b);    
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


int main() {    

    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for(int i=0; i<n; i++) {
        cin >> l[i];
    }

    vector<int> pt(n+1);
    pt[0] = 0;
    int cnt = 1;
    for(int i=1; i<n+1; i++) {
        pt[i] = pt[i-1] + l[i-1];
    }
    int ans=pt[n];
    for(int i=n; i>=0; i--) {
        if(pt[i] <= x) {
            ans = i+1;
            break;
        }
    }
    cout << ans << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

// ユークリウッドの互除法    
int gcd(int a, int b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 256
N, X = map(int, input().split(' '))
length = [1]
patty = [1]
p_before = 1
before = 1
for i in range(N):
    before = before*2+3
    length.append(before)
    p_before = 2*p_before+1
    patty.append(p_before)

def search(n,i):
    if i==0:
        return 1
    if 1<n<length[i-1]+2:
        return search(n-1, i-1)
    elif length[i-1]+2<n<2*length[i-1]+3:
        return patty[i-1]+1+search(n-2-length[i-1],i-1)
    elif n == 1:
        return 0
    elif n ==length[i-1]+2:
        return patty[i-1]+1
    elif n == 2*length[i-1]+3:
        return 2*patty[i-1]+1

print(search(X,N))


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

int h, w, k;
vector<vector<int> > d;

bool isIn(int i, int j){
    return i>=0 && i<h && j>=0 && j<w;
}

int solve(){
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    vector<vector<bool> > visited(h, vector<bool>(w));
    queue<P3> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='S'){
                visited[i][j] = true;
                que.push(P3(P(i,j),k));
            }
        }
    }
    while(!que.empty()){
        auto tmp = que.front();
        que.pop();
        int i = tmp.first.first, j = tmp.first.second, r = tmp.second;
        if(r == 0) continue;
        for(int l=0;l<4;l++){
            int ni = i+di[l], nj = j+dj[l];
            if(isIn(ni,nj) && s[ni][nj]=='.' && !visited[ni][nj]){
                visited[ni][nj] = true;
                que.push(P3(P(ni,nj),r-1));
            }
        }
    }
    int res = INF;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(visited[i][j]){
                res = min(res, (min(min(i,h-1-i),min(j,w-1-j))+k-1)/k+1);
            }
        }
    }
    return res;
}

int main(){
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1280
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
checkout = min(a)+min(b)

for i in range(M):
    tmp = list(map(int, input().split()))
    checkout = min(checkout, a[tmp[0]-1] + b[tmp[1]-1] - tmp[2])

print(checkout)



Measured memory_bytes: 18736
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200000
#define LL long long
int n;
LL pos[MAXN+5],X,sum[MAXN+5],ans;
LL get_sum(int l,int r){return sum[r]-sum[l-1];}
int main()
{
    scanf("%d%lld",&n,&X);
    for(int i=1;i<=n;i++)
    {scanf("%lld",&pos[i]);sum[i]=pos[i]+sum[i-1];}
    ans=0x3f3f3f3f3f3f3f3f;
    for(int k=1;k<=(n+1)/2;k++)
    {
        int l=0,r=n;
        LL sum=0;
        for(int i=1;r>=1;i++)
        {
            l=max(r-k+1,1);
            if(i==1)sum+=5*get_sum(l,r);
            else sum+=(2*i+1)*get_sum(l,r);
            r=l-1;
            if(sum+k*X>ans)break;
        }
        ans=min(ans,sum+k*X);
    }
    printf("%lld",ans+n*X);
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
using P = pair<ll, ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll X, N;
ll Main() {
    // しゃくとり法パターン
    cin >> X >> N;
    vl p(102, 0);
    
    rep(i,N) {
        ll tmp;
        cin >> tmp;
        p[tmp] = 1;
    }

    P ans(99999, -1);
    
    rep(i, 102) {
        if(p[i] == 1) continue;
        // 最もXに近いものを求める
        ll diff = abs(X-i);
        // そして近い数が複数存在する場合は、そのうち最も小さいものを取る
        ans = min(ans, P(diff, i));
    }
    
    cout << ans.second << endl;
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int k, t;
	cin >> k >> t;

	vector<int> a(t);
	for (int i = 0; i < t; ++i) {
		cin >> a[i];
	}

	sort(a.rbegin(), a.rend());

	int ans = 0;
	int i = 0;
	while (k) {
		if (a[i]) {
			--a[i];
			--k;
			int j = i + 1;
			for (; j < t; ++j) {
				if (a[j]) {
					--k;
					--a[j];
					break;
				}
			}

			if (j == t) {
				ans = a[i];
				break;
			}
		} else {
			++i;
		}
	}

	cout << ans << "\n";

	return 0;

}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n, m, x;
	cin >> n >> m >> x;

	vector<int> memo(101);
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		memo[a]++;
	}

	int ans1 = 0;
	for (int i = x; i < n; i++) {
		if (memo[i] != 0) {
			ans1++;
		}
	}

	int ans2 = 0;
	for (int i = x; i > 0; i--) {
		if (memo[i] != 0) {
			ans2++;
		}
	}

	cout << min(ans1, ans2) << endl;
	return 0;
}


Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
cm = Array.new(h + 2){'.' * (w + 2)}
que = []
1.upto(h) do |i|
  cm[i] = '.'.concat(gets.chomp).concat('.')
end
que << [1, 1]
while que.size > 0
  y, x = que.shift
  if (cm[y + 1][x] == '#' && cm[y][x + 1] == '#') || cm[y - 1][x + 1] == '#' || cm[y + 1][x - 1] == '#'
    puts 'Impossible'
    exit
  end
  if cm[y + 1][x] == '#'
    que << [y + 1, x]
  end
  if cm[y][x + 1] == '#'
    que << [y, x + 1]
  end
end
puts 'Possible'

Measured memory_bytes: 1788
#include<stdio.h>
int main(){
  int i, j, k, n, v;
  int A[100];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  /* Insertion Sort */
  for(i = 1; i <= n; i++){
    v = A[i];
    j = i - 1;
    for(k = 0; k < n; k++){
      printf("%d",A[k]);
      if(k != n - 1) printf(" ");
    }
    printf("\n");
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
      A[j + 1] = v;
    }
  }

  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>

int bubble_sort(int n, int *a)
{
	int i, f, x;
int ans = 0;

	do {
		f = 0;
		for (i = n-1; i > 0; i--) {
			if (a[i] < a[i-1]) {
				x = a[i], a[i] = a[i-1], a[i-1] = x;
ans++;
				f = 1;
			}
		}
	} while (f);
return ans;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int a[102];

int main()
{
	int N, i, k;

	N = in();
	for (i = 0; i < N; i++) a[i] = in();
	k = bubble_sort(N, a);
	printf("%d", a[0]);
	for (i = 1; i < N; i++) printf(" %d", a[i]);
	putchar('\n');
	printf("%d\n", k);
	return 0;
}




Measured memory_bytes: 2148