akhauriyash/Code-Regression huggingface dataset:
address = $<.gets.to_i.times.map do
  r, k, *t = $<.gets.split.map(&:to_i)
  [r, t]
end.to_h

$<.gets.to_i.times do
  s, d, v = $<.gets.split.map(&:to_i)
  queue = [s]
  dist = {}
  dist[s] = 1
  until !(now = queue.shift) or now == d
    address[now].each do |nxt|
      unless dist[nxt]
        dist[nxt] = dist[now] + 1
        queue << nxt
      end
    end
  end
  d = dist[now]
  puts d && (d <= v) ? d : "NA"
end


Measured memory_bytes: 9300
AE = [int(input()) for _ in range(5)]
Ans = 0
mini = 10
for f in AE:
    if f%10 == 0:
        Ans += f
    elif f%10 < mini:
        Ans += f + (10-mini)
        mini = f%10
    else:
        Ans += f + (10-f%10)
        
print(Ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  vector<int> light(N);
  for (int i = 0; i < N; i++) {
    
    cin >>light.at(i);
    
  } 
  int next = 1;
  int count, check = 0;
  
  for (int i = 0; i < N; i++){
  
    
    count++;
    
    if (light.at(next - 1) == 2) {
      
      
      check = 1;
      break;
      
    }else{
      
      next = light.at(next - 1);
      
      
    }
    
  }
  if (check == 0){
      
      cout << -1 << endl;
      
      
    }else{
    
      cout << count << endl;
      
    }
  
  
}
 
  
  


Measured memory_bytes: 3756
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long a,b;
    cin>>a>>b;
    long long cnt=0;
    
    for(long long i=1;i<=a;i+=2) cnt++;
    
    if(cnt>=b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <queue>

using namespace std;

typedef long long ll;

class Elem {
    public:
        int vertex;
        ll distance;

        bool operator < (const Elem &other) const {
            return distance < other.distance;
        }

        bool operator > (const Elem &other) const {
            return distance > other.distance;
        }
};

const int INF = 1001001001;

typedef vector<vector<Elem> > Edges;
Edges edges;

typedef priority_queue<Elem, vector<Elem>, greater<Elem> > PriorityQueue;

/*
 * ref. https://ja.wikipedia.org/wiki/%E3%83%80%E3%82%A4%E3%82%AF%E3%82%B9%E3%83%88%E3%83%A9%E6%B3%95
 *
 * usage:
 *
 * int main(void) {
 *     int V, E, start; // vertices, edges, start
 *     cin >> V >> E >> start;
 *     Graph g(V, E, edges);
 *     g.dijkstra(start);
 *     // do something with d.d_list and d.prev_list
 * }
 */
class Graph {
    public:
        const int V; // num of vertices
        const int E; // num of edges
        const Edges &edges;
        vector<int> prev_list; // previous vertex on the shortest path from start (calculated after dijkstra())
        vector<ll> d_list; // distance from start (calculated after dijkstra())

        Graph(int V, int E, Edges &edges) : V(V), E(E), edges(edges) {
        }

        void dijkstra(const int start) {
            PriorityQueue q;

            init();
            d_list[start] = 0;
            for (int i = 0; i < V; i++) {
                q.push({i, d_list[i]});
            }

            while (q.size() > 0) {
                Elem elem = q.top();
                q.pop();

                for (int i = 0; i < edges[elem.vertex].size(); i++) {
                    Elem next = edges[elem.vertex][i];
                    ll alt = d_list[elem.vertex] + next.distance;
                    if (d_list[next.vertex] > alt) {
                        d_list[next.vertex] = alt;
                        prev_list[next.vertex] = elem.vertex;

                        Elem e;
                        e.vertex = next.vertex;
                        e.distance = d_list[next.vertex];
                        q.push(e);
                    }
                }
            }
        }

    private:
        void init() {
            prev_list.clear();
            prev_list.resize(V, -1);

            d_list.clear();
            d_list.resize(V, INF);
        }
};

// ref. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
int main(void) {
    int V, E, r; // vertices, edges, start
    cin >> V >> E >> r;

    edges.resize(V, vector<Elem>());

    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        edges[s].push_back({t, d});
    }

    Graph g(V, E, edges);
    g.dijkstra(r);

    for (int i = 0; i < V; i++) {
        if (g.d_list[i] != INF) {
            cout << g.d_list[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 21852
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N;
int main(){
  cin >> N;
  vector<int> L(2*N);
  for(int i=0;i<2*N;i++){
    cin >> L[i];
  }
  sort(L.begin(),L.end());
  int ans = 0;
  for(int i=0;i<2*N-1;i++){
    if(i%2==0){
      ans += min(L[i],L[i+1]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;
auto dcomp = [](const string& a, const string& b){
    if(a.size() != b.size())    return a.size() < b.size();
    return a < b;
};


string maximize(int i, int j, vector<vector<string>>& dp, const vector<vector<char>>& c){
    if(i >= dp.size()) return "";
    if(j >= dp[0].size()) return "";
    if(c[i][j] == '!')  return "";

    if(dp[i][j].empty()){
        const string l = maximize(i+1, j, dp, c);
        const string r = maximize(i, j+1, dp, c);

        return dp[i][j] = c[i][j] + (dcomp(l, r) ? r : l);
    }
    else return dp[i][j];
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, h;
    while(cin >> w >> h){
        if(w == 0 && h == 0) break;
        vector<vector<char>> c;
        for (int i = 0; i < h; ++i) {
            c.push_back({});
            for (int j = 0; j < w; ++j) {
                char tmp;
                std::cin >> tmp;
                if('A' <= tmp && tmp <= 'Z'){
                    tmp = '!';
                }
                c[i].push_back(tmp);
            }
        }
        vector<vector<string>> dp(h, vector<string>(w));
        string maxim = "";
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if(c[i][j] != '!' && c[i][j] != '0' && dp[i][j].empty()){
                    string st = maximize(i, j, dp, c);
                    maxim = max(maxim, st, dcomp);
                }
            }
        }
        cout << maxim << '\n';

    }
}



Measured memory_bytes: 3236
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    6月で水色になるぞ〜!!!
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{one, zero, One, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

pub const MOD: usize = 1000000007;
pub const MAX: usize = 1usize << 63usize;
pub const MIN: i64 = i64::MIN;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 'A' as u8;

// code...
// #[fastout]
fn main() {
    input! {
        mut n: i64,
    }

    let mut ans = Vec::new();

    if n == 0 {
        println!("0");
        return;
    }

    for d in 1.. {
        if n == 0 {
            break;
        }
        let p = 1 << d;
        dbg!(n, p, n % p,);
        if n % p != 0 {
            ans.push('1');
            n -= (-2i64).pow(d - 1);
        } else {
            ans.push('0');
        }
        println!();
    }

    ans.reverse();
    let ans = ans.into_iter().collect::<String>();
    println!("{}", ans);
}


Measured memory_bytes: 2092
#include <iostream>
using namespace std;
int n,ans;
string s[300],t[300];
bool solve(void){
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            if(t[i][j]!=t[j][i])return false;
        }
    }
    return true;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        t[i]=s[i];
    }
    ans+=solve();
    for(int i=1;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                t[(j+i)%n][k]=s[j][k];
            }
        }
        ans+=solve();
    }
    cout<<ans*n<<endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    int i;
    long int sum = 0;
    for (i = 1; i <= N; i++) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        sum += (long int)i;
    }

    cout << sum;

    return 0;
}

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

int MinIndex(vector <int> A){
  int i = 0;
  int m = 1;
  for (int j = 0; j < A.size(); j++){
    if (A[j] < m)
      m = A[j];
      i = j;
  }
  return i;
}

int HowMany(vector <int> A, int K, int N){
  if (N == K)
    return 1;
  int i = 0;
  int x = N - MinIndex(A), y = MinIndex(A);
  while (x > 0){
    i++;
    x -= K;
    x++;
  }
  while (y > 0){
    i++;
    y -= K;
    y++;
  }
  return i-1;
}

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

  int N, K;
  cin >> N >> K;
  vector <int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  cout << HowMany(A, K, N) << endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
    long long n = 0, k = 0;
    cin >> n >> k;
    n = n%k;
  	if(n > k - n)
      cout << k - n << endl;
  	else
      cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

vec v;
void dfs(int x, int d = 1){
    v.pb(x);
    if(d == 10) return;
    int y = x % 10;
    if(y > 0) dfs(x * 10 + y - 1, d + 1);
    dfs(x * 10 + y, d + 1);
    if(y < 9) dfs(x * 10 + y + 1, d + 1);
}

signed main(){

    int K; cin >> K;
    FOR(i, 1, 10) dfs(i);
    Sort(v);
    
    Out(v[K - 1]);

    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL t(n+1,0), x(n+1,0), y(n+1,0);
	for (int i = 0; i < n; i++) {
		cin >> t[i+1] >> x[i+1] >> y[i+1];
	}
	for (int i = 0; i < n; i++) {
		int dt = t[i+1] - t[i];
		int dx = abs(x[i+1] - x[i]);
		int dy = abs(y[i+1] - y[i]);
		if (dx + dy > dt) {
			cout << "No" << endl;
			return 0;
		}
		if ((dx + dy) % 2 != dt % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
const ll INF = 1e15;
const ld eps = 1e-6;

int main() {
	ll N;
	cin >> N;
	ld ans = 0;
	for (int i = 0;i < N;i++) {
		ld x;
		string s;
		cin >> x >> s;
		if (s == "JPY")
			ans += x;
		else
			ans += x * 380000;
	}
	printf("%.10llf\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

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

  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  ll start = 0;
  int ans = 0;
  while(true) {
    if (ans > K) {
      cout << -1 << endl;
      return 0;
    }
    start = (10 * start + 7) % K;
    ans++;
    if (start == 0) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Set<Integer> a = new HashSet<>();
        for (int i = 0; i < m; i++) {
            a.add(sc.nextInt());
        }

        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 1;
        if (a.contains(1)) {
            dp[1] = 0;
        }
        for (int i = 2; i <= n; i++) {
            if (a.contains(i)) {
                dp[i] = 0;
                continue;
            }
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        }
        System.out.println(dp[n]);
    }

}


Measured memory_bytes: 65084
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int MAX = 100100;
const int NIL = -1;

vector<int> G[2*MAX];
int color[2*MAX];
int N,M;

void bfs(int s, int c){
    color[s] = c;
    queue<int> Q;
    Q.push(s);

    while(!Q.empty()){
        int u = Q.front(); Q.pop();
        for(auto v : G[u]){
            if(color[v] != NIL) continue;
            color[v] = c;
            Q.push(v);
        }
    }
}

void solve(){
    for(int i=0;i<N+M;i++) color[i] = NIL;
    int id = 1;
    for(int i=0;i<N+M;i++){
        if(color[i] == NIL){
            bfs(i, id++);
        }
    }
}

int main(){
    cin >> N >> M;
    int K,L;
    for(int i=0;i<N;i++){
        scanf("%d", &K);
        for(int j=0;j<K;j++){
            scanf("%d", &L);
            L--;
            G[i].push_back(N+L);
            G[N+L].push_back(i);
        }
    }
    solve();
    int id = color[0];
    for(int i=1;i<N;i++){
        if(color[i] != id){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 9592
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long num = 0;
		int index = 1;
		while (num < N) {
			num += Math.pow(26, index);
			index++;
		}
		int[] alp = new int[index-1];
		for (int i = index-2; -1 < i; i--) {
			for (int j = 26; -1 < j; j--) {
				if (Math.pow(26, i)*j <= N) {
					if (j == 0) {
						alp[index-2-i] = 26;
						alp[index-2-i-1]--;
						break;
					}
					alp[index-2-i] = j;
					N -= Math.pow(26, i)*j;
					break;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = alp.length-1; -1< i; i--) {
			int a = alp[i];
			if (a == 0) {
				a = 26;
				alp[i-1]--;
			}
			sb.append((char) ('a'-1+a));
		}
		System.out.println(sb.reverse());
	}
}

Measured memory_bytes: 35856
#include <stdio.h>
#include <limits.h>

#define ARRAY_SIZE 500000
#define DIV_SIZE 250001

int A[ARRAY_SIZE];
int L[DIV_SIZE];
int R[DIV_SIZE];
int count;

void merge(int left, int mid, int right)
{
	int i, j, k, n1, n2;
	n1 = mid - left;
	n2 = right - mid;
	count += right - left;
	
	for (i = 0; i < n1; i++) L[i] = A[left + i];
	for (i = 0; i < n2; i++) R[i] = A[mid + i];

	L[n1] = R[n2] = INT_MAX;

	i = j = 0;
	for (k = left; k < right; k++)
	{
		if (L[i] <= R[j]) A[k] = L[i++];
		else A[k] = R[j++];
	}
}

void mergeSort(int left, int right)
{
	int mid;
	if (left + 1 >= right) return;

	mid = (left + right) / 2;
	mergeSort(left, mid);
	mergeSort(mid, right);
	merge(left, mid, right);
}

int main(void)
{
	int i, n;

	scanf("%d", &n);

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

	count = 0;
	mergeSort(0, n);

	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if ((i + 1) < n) printf(" ");
	}
	printf("\n%d\n", count);

	return 0;
}

Measured memory_bytes: 5624
// https://atcoder.jp/contests/

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n;

  cin >> n;

  cout << "ABC" + to_string(n) << '\n';

  return 0;
}


Measured memory_bytes: 256
int n,a,b,M[1<<20]={1},i,k;
main(){
    scanf("%d%d%d",&n,&a,&b);
    if(n>1L*a*b||n<a+b-1) puts("-1");
    else{
        int N=b,C=n;
        while(1){
            for(i=N;i>N-b;--i) {
                if(a==C){
                    for(k=0;k<=n;++k) if(!M[k]) printf("%d ",k);
                    exit(0);
                }
                C--;printf("%d ",i);M[i]=1;
            }
            a--;
            N=n<N+b?n:N+b;
        }
    }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
long long n,l,mx;
char a[1001];
int main(){
	cin>>n>>a;
	for(int i=0;i<n;i++){
		if(a[i]=='I')
			l++;
		else
			l--;
		mx=max(mx,l);
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	ms := make([]int, max(n, k))
	for i := 1; i <= n; i++ {
		ms[i%k]++
	}

	ans := 0
	if k%2 == 1 {
		x := ms[0]
		ans = x * x * x
	} else {
		x := ms[0]
		y := ms[k/2]
		ans = x*x*x + y*y*y
	}

	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

int main(){
    int a[4];
    for(int i = 0; i < 4; i++) cin >> a[i];
    int aStart = a[0];
    int aEnd = a[1];
    int bStart = a[2];
    int bEnd = a[3];

    if(max(aStart,bStart) > min(aEnd,bEnd)) {
        cout << 0 << endl;
    }
    else {
        sort(a,a+4);
        cout << a[2] - a[1] << endl;
    }
}

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

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//




int main()
{
	IOS

	int n,m,c;
	cin >> n >> m >> c;
	vector<int> b(m);
	for(int i = 0; i < m; ++i){
		cin >> b[i];
	}
	ll count = 0;
	for(int i = 0;i < n; ++i){
		ll sum = 0;
		ll a;
		for(int j = 0;j < m; ++j){
			cin >> a;
			sum += a * b[j];
		}
		sum += c;
		if(sum > 0)
			++count;
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

#define data etokek

//#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int N = 2e6 + 32;
//const int M = 1e9 + 7;
const int mod = 998244353;
const int rx[4] = {-1, -1, 1, 1};
const int ry[4] = {-1, 1, -1, 1};
const lld eps = 1e-11;
const double pi = acos(-1.0);
const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};

int ans[N];

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("mushrooms.in", "r", stdin);
//    freopen("mushrooms.out", "w", stdout);
#endif
    int n;
    cin >> n;
    int x;
    for (int i = 1; i < n; ++i) {
        cin >> x;
        ++ans[x];
    }
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 4412
import java.util.Scanner;

/**
 * https://arc090.contest.atcoder.jp/tasks/arc090_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] a = new int[2][N];
		for(int i=0; i<N; i++) a[0][i] = sc.nextInt();
		for(int i=0; i<N; i++) a[1][i] = sc.nextInt();
		sc.close();
		
		int[] dp1 = new int[N];
		int[] dp2 = new int[N];
		dp1[0] = a[0][0];
		dp2[0] = a[1][0];
		for(int i=1; i<N; i++){
			dp1[i] = a[0][i]+dp1[i-1];
			dp2[i] = a[1][i]+dp2[i-1];
		}
		
		int max = 0;
		for(int i=0; i<N; i++){
			int target = i==0 ? dp1[i]+dp2[N-1] : dp1[i]+dp2[N-1]-dp2[i-1];
			max = Math.max(max, target);
		}
		System.out.println(max);
		

	}

}

Measured memory_bytes: 21844
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        int[,] A = new int[N, M];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < M; j++)
            {
                A[i, j] = cin.nextInt() - 1;
            }
        }

        bool[] dead = new bool[M];
        int[] cnt = new int[N];
        int ans = N;
        for (int t = 0; t < M; t++)
        {
            int[] sum = new int[M];
            for (int i = 0; i < N; i++)
            {
                while (dead[A[i, cnt[i]]]) cnt[i]++;
                sum[A[i, cnt[i]]]++;
            }
            int num = -1;
            int best = -1;
            for (int i = 0; i < M; i++)
            {
                if(sum[i] > best)
                {
                    num = i;
                    best = sum[i];
                }
            }
            ans = Math.Min(ans, best);
            dead[num] = true;
        }
        Console.WriteLine(ans);
    }




}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();

        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 17384
# source: http://drken1215.hatenablog.com/entry/2019/04/27/224100_1
# verify: https://atcoder.jp/contests/abc125/tasks/abc125_c
class SegmentTree
  # n is the size of array or array itself
  def initialize(n, unity, &func)
    raise ArgumentError if !n || !unity || !block_given?
    @size_r = 1
    @n = (n.is_a?(Array) ? n.size : n)
    while @size_r < @n
      @size_r <<= 2
    end
    @func = func
    @unity = unity
    @data = Array.new(@size_r * 2, @unity)
    if n.is_a?(Array)
      @n.times { |i| @data[i + @size_r] = n[i] }
      self.build()
    end
  end

  # set value at index, index is 0-indexed
  def set(index, value)
    raise IndexError if index >= @n
    @data[index + @size_r] = value
  end

  def build
    (@size_r - 1).downto(1) do |k|
      @data[k] = @func.call(@data[k * 2], @data[k * 2 + 1])
    end
  end

  # update the previous value at index to value, index is 0-indexed
  def update(index, value)
    raise IndexError if index >= @n
    index += @size_r
    @data[index] = value
    index >>= 1
    while index > 0
      @data[index] = @func.call(@data[index * 2], @data[index * 2 + 1])
      index >>= 1
    end
    true
  end

  # get [a, b), a and b are 0-indexed
  def get(a, b)
    raise IndexError if a > @n || b > @n || a > b
    vleft = vright = @unity
    left = a + @size_r
    right = b + @size_r
    while (left < right)
      if (left & 1) == 1
        vleft = @func.call(vleft, @data[left])
        left += 1
      end
      if (right & 1) == 1
        right -= 1
        vright = @func.call(@data[right], vright)
      end
      left >>= 1
      right >>= 1
    end
    return @func.call(vleft, vright)
  end

  def [](k)
    @data[@size_r + k]
  end
end

# __END__
N = gets.to_i
a = gets.split.map(&:to_i)

seg = SegmentTree.new(N, 0) { |x, y| x.gcd(y) }

N.times do |i|
  seg.set(i, a[i])
end
seg.build
ans = 0
N.times do |i|
  left = seg.get(0, i)
  right = seg.get(i + 1, N)
  ans = [ans, left.gcd(right)].max
end

puts ans


Measured memory_bytes: 15252
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

int main(){
	ll a, b, c, x, y;
	cin>>a>>b>>c>>x>>y;
	ll r = 1e18;
	rep(i, 200010){
		ll s = 2*i*c+max(x-i,0LL)*a+max(y-i,0LL)*b;
		chmin(r, s);
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=200000;
int main()
{
  int n,m,i;
  long long res,a[N_MAX],b[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> a[i] >> b[i];
  sort(a,a+n);
  sort(b,b+n);
  m=n/2;
  if(n%2==1){
    res=b[m]-a[m]+1;
  }else{
    res=b[m]+b[m-1]-a[m]-a[m-1]+1;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 6288
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  int xi;
  for (int i=0; i<5; i++){
    scanf("%d", &xi);
    if(xi == 0){
      printf("%d\n",i+1);
      break;
    }
  }
}

Measured memory_bytes: 2112
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int main() {
    int N,K;cin >> N >> K;
    vector<int> retu(K);
    int ans = 0;
    for(int i = 0;i<K;i++){
        cin >> retu.at(i);
        ans += retu.at(i);
    }
    if(ans > N){
        cout << -1 << endl;
        return 0;
    }
    cout << N-ans << endl;

    // PLEASE GIVE ME THE "ACCEPTED" !
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,x,y,maxx,miny;
int read(){
	int x=0;
	bool flag=true;
	char k=getchar();
	while(k<'0'||k>'9'){
		if(k=='-') flag=false;
		k=getchar();
	}
	while(k>='0'&&k<='9'){
		x=x*10+k-'0';
		k=getchar();
	}
	return flag?x:-x;
}
int main(){
	n=read();m=read();
	x=read();y=read();
	maxx=x;miny=y;
	for(int i=1;i<=n;i++){
		int k;
		k=read();
		maxx=max(maxx,k);
	}
	for(int i=1;i<=m;i++){
		int k;
		k=read();
		miny=min(miny,k);
	}
	if(maxx<miny&&x<y){
		printf("No War");
		return 0;
	}
	printf("War");
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
l = [0] * 101
for i in range(k):
    d = int(input())
    t = list(map(int, input().split()))
    for j in t:
        l[j] = 1
ans = 0
for i in range(1, n + 1):
    if l[i] == 0: ans -= -1
print(ans)

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


const int D = 10;

bool dis[D];
int n , k;


bool reject(int n){
  while(n){
    if(dis[n%10])
      return true;
    n /= 10;
  }
  return false;
}

int main(){
  cin >> n >> k;
  int x;
  for(int i = 0;i < k ; ++i){
    cin >> x;
    dis[x] = 1;
  }
  int mn = n;
  while(true){
    if(reject(mn))
      ++mn;
    else
      break;
  }
  cout << mn << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [0]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            
    
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()

Measured memory_bytes: 51520
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    vector<int> l(200);
    cin>>n;
    for(int i=0;i<2*n;i++)
        cin>>l[i];
    sort(l.begin(),l.begin()+2*n);
    int x=0;
    for(int i=0;i<2*n;i+=2)
        x+=min(l[i],l[i+1]);
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
houses = [
    [[0]*10,[0]*10,[0]*10],
    [[0]*10,[0]*10,[0]*10],
    [[0]*10,[0]*10,[0]*10],
    [[0]*10,[0]*10,[0]*10]
]
n = int(input())
for a in range(n):
    b,f,r,v = [int(i) for i in input().split()]
    houses[b-1][f-1][r-1] += v

for i,house in enumerate(houses):
    for floor in house:
        print(" "+ " ".join(map(str, floor)))
    if i != len(houses)-1:
        print("#"*20)


Measured memory_bytes: 5612
n,m=map(int,input().split())
h=list(map(int,input().split()))
x=[i for i in range(1,n+1)]
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:
    x[b-1]=0
  elif h[a-1]<h[b-1]:
    x[a-1]=0
  else:
    x[a-1]=0
    x[b-1]=0
print(n-x.count(0))


Measured memory_bytes: 19828
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] x = new int[N];
	int[] y = new int[N];
	int[] h = new int[N];
	int startIndex = 0;
	for(int i = 0; i<N; i++) {
	    x[i] = sc.nextInt();
	    y[i] = sc.nextInt();
	    h[i] = sc.nextInt();
	    if(h[i]>0) {
		startIndex = i;
	    }
	}
	if(N == 1) {
	    System.out.println(x[0] + " " + y[0] + " " + h[0]);
	    return;
	}
	for(int i = 0; i<=100; i++) {
	    for(int j = 0; j<=100; j++) {
		int cx = i;
		int cy = j;
		int ch = h[startIndex] + (int)(Math.abs(cx-x[startIndex])) + (int)(Math.abs(cy-y[startIndex]));
		for(int k = 0; k<N; k++) {
		    if(Math.max((ch - (int)(Math.abs(cx-x[k])) - (int)(Math.abs(cy-y[k]))),0) != h[k]) {
			break;
		    }
		    if(k==N-1) {
			System.out.println(cx + " " + cy + " " + ch);
			return;
		    }
		}
	    }
	}
    }

}

Measured memory_bytes: 23636
H, W = map(int, input().split())
S = [''] * (H + 2)
S[0] = [''] * (W + 2)
for i in range(1, H + 1):
    S[i] = ['']
    S[i].extend(list(input()))
    S[i].extend([''])
S[H + 1] = [''] * (W + 2)

ans = [0] * H
for i in range(H):
    ans[i] = [0] * W

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == '.':
            ans[i - 1][j - 1] += S[i - 1][j - 1 : j + 2].count('#')
            ans[i - 1][j - 1] += S[i][j - 1 : j + 2].count('#')
            ans[i - 1][j - 1] += S[i + 1][j - 1 : j + 2].count('#')
        else:
            ans[i - 1][j - 1] = '#'

for i in range(H):
    for j in range(W):
        print(ans[i][j], end = '')
    print()

Measured memory_bytes: 3572
/*
---------author:O7Oo7oO7O-------------
*/

#include <bits/stdc++.h>

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

using namespace std;

using ll = long long int;



int main()
{
	IOS

	int s,w;
	cin>>s>>w;
	if(w>=s)
		cout<<"unsafe\n";
	else
		cout<<"safe\n";

	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n, m=0,tmp=0,ax=0,k=0,t[5000],p[5000],x[500000],res[5000];
	string str, str2[5000];
	cin >> n ;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		x[i] -= i;
	}
	sort(x + 1, x + n + 1);
	tmp =n/2;
	for (int i = 1; i <= n; i++) {
		m += abs(x[i] - x[tmp - 1]);
		ax += abs(x[i] - x[tmp]);
		k+= abs(x[i] - x[tmp + 1]);
	}
	cout << min(m,min(ax,k));
}


Measured memory_bytes: 3840
a, b, c = gets.split.map(&:to_f)

s = 0.5 * (a * b) * (Math.sin(c * (Math::PI / 180)))
l = a + b + Math.sqrt(a**2 + b**2 - (2 * a * b * Math.cos(c * (Math::PI / 180))))
h = b * Math.sin(c * (Math::PI / 180))
puts s
puts l
puts h

Measured memory_bytes: 6192
//
//  main.cpp
//  A - Dividing a String
//
//  Created by Hashizo on 2019/08/17.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef LONG_MAX
#undef LONG_MIN

#define LONG_MAX	9223372036854775807
#define LONG_MIN	(-LONG_MAX  -1)

#define ll long long

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

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

	ll ans = 0;
	ll cnt = s.size();
	
	string save="";
	string save2="";

	REP(i, cnt) {
		FOR(j, 1, (cnt+1)-(i)) {
			
			
//			cout << s.substr(i,j) << endl;
			if (save == s.substr(i,j)) {
				continue;
			}
			else {
				ans++;
				save = s.substr(i,j);
				break;
			}
		}
		
//		cout << (save.size()-1) << endl;
		i += (save.size()-1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
ll used[114514];
vector< pair<ll,ll> > pat[114514];
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll tl,tr,td;
		cin>>tl>>tr>>td;
		pat[tl].pb(mp(tr,td));
		pat[tr].pb(mp(tl,-td));
	}
	for(int i=1;i<=n;i++){
		if(used[i]==0){
			queue<ll> que;
			map<ll,ll> mp;
			que.push(i);
			mp[i] = mod;
			while(!que.empty()){
				ll cf = que.front();que.pop();
				if(used[cf]==0){
					//cout<<cf<<endl;
					used[cf]=1;
					for(int j=0;j<pat[cf].size();j++){
						ll cto = pat[cf][j].first;
						ll cdis = pat[cf][j].second;
						if( mp[cto] != 0 && mp[cto]!= mp[cf]+cdis){
							cout<<"No"<<endl;
							return 0;
						}
						else{
							mp[cto] = mp[cf]+cdis;
							que.push(cto);
						}
					}
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 21616
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

int main(){
    int n; cin>>n;
    int oddnum=0;
    FOR(i,0,n){
        int a; cin>>a;
        if(a%2) oddnum++;
    }
    YES(!(oddnum%2));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n);
    for(int64_t i=0LL;i<n;i++){
        cin>>a.at(i);
    }
    int64_t leng=0LL;
    for(int64_t i=0;i<n;i++){
        leng+=a.at(i);
    }
    int64_t hal=a.at(0LL);
    int64_t def;
    
    for(int64_t i=1LL;i<n;i++){
        hal+=a.at(i);
        if(fabs(2LL*hal-leng)>fabs(2LL*(hal-a.at(i))-leng)){
            def=fabs(2LL*(hal-a.at(i))-leng);
            break;
        }
        
    }
    cout<<def;
}

Measured memory_bytes: 1792
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int i,n,x,y,map=-1e9,mip=1e9,mam=-1e9,mim=1e9;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    map=MAX(map,x+y);
    mam=MAX(mam,x-y);
    mip=MIN(mip,x+y);
    mim=MIN(mim,x-y);
  }
  printf("%d\n",MAX(map-mip,mam-mim));
  return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {

	int n = 0;
	string s;
	cin >> s ;
	
	rep(i, 4) {
		if (s.at(i) == '+') {
			n++;
		}
		else {
			n--;
		}
	}
	cout << n << endl;


}


Measured memory_bytes: 256