akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long int> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    long long int sa = 2e10;

    for(int i=0; i<=N-K; i++){
        sa = min(sa, vec[i+K-1]-vec[i]);
    }
    cout << sa << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1145141919810
int main(){
    int a,b,q;
    cin>>a>>b>>q;
    vector<ll>s(a),t(b);
    for(int i=0;i<a;i++)cin>>s[i];
    for(int i=0;i<b;i++)cin>>t[i];
    for(int i=0;i<q;i++){
        ll hoge;
        cin>>hoge;
        ll ans=INF;
        ll s1=lower_bound(s.begin(),s.end(),hoge)-s.begin();
        ll t1=lower_bound(t.begin(),t.end(),hoge)-t.begin();
        ll s2=s1-1,t2=t1-1;
        
        if(s2>=0&&t2>=0){
            ans=min(ans,abs(s[s2]-hoge)+abs(s[s2]-t[t2]));
            ans=min(ans,abs(t[t2]-hoge)+abs(s[s2]-t[t2]));
        }
        if(s2>=0&&t1<b){
            ans=min(ans,abs(s[s2]-hoge)+abs(s[s2]-t[t1]));
            ans=min(ans,abs(t[t1]-hoge)+abs(s[s2]-t[t1]));
        }
        if(s1<a&&t2>=0){
            ans=min(ans,abs(s[s1]-hoge)+abs(s[s1]-t[t2]));
            ans=min(ans,abs(t[t2]-hoge)+abs(s[s1]-t[t2]));
        }
        if(s1<a&&t1<b){
            ans=min(ans,abs(s[s1]-hoge)+abs(s[s1]-t[t1]));
            ans=min(ans,abs(t[t1]-hoge)+abs(s[s1]-t[t1]));
        }

        cout<<ans<<endl;

    }
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int k, s;
  cin >> k >> s;
  int rsl = 0;
  rep(x, 0, k + 1) rep(y, 0, k + 1) {
      int z = s - x - y;
      if(0 <= z && z <= k) rsl++;
  }
  cout << rsl << endl;
}


Measured memory_bytes: 256
//In the name of God
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second

ll n, x, cnt, a[maxn], dp[maxn];
bool f, vis[maxn];
vector<ll> vec;
vector<ll> g[maxn];

void dfs(ll v){
    vis[v] = 1;
    if(a[v] == -1) f = 1;
    x++;
    for(ll u : g[v]){
        if(!vis[u]) dfs(u);
    }
    return;
}

ll pw(ll pa, ll pb){
    ll pc = 1;
    while(pb){
        if(pb & 1) pc = (pc * pa) % mod;
        pa = (pa * pa) % mod;
        pb >>= 1;
    }
    return pc;
}

int main(){
    fast_io;

    cin >> n;
    for(ll i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == -1) continue;
        g[i].pb(a[i]);
        g[a[i]].pb(i);
    }
    for(ll i = 1; i <= n; i++){
        if(!vis[i]){
            f = 0;
            x = 0;
            dfs(i);
            if(f){
                vec.pb(x);
            }
            else cnt++;
        }
    }
    dp[0] = 1;
    for(ll i = 0; i < (ll)vec.size(); i++){
        for(ll j = i + 1; j > 0; j--){
            dp[j] = (dp[j] + dp[j - 1] * vec[i]) % mod;
        }
    }
    ll y = 1;
    ll z = pw(n - 1, mod - 2);
    ll ans = (dp[1] - vec.size()) * z % mod + cnt;
    x = z;
    for(ll i = 2; i <= (ll)vec.size(); i++){
        x = (x * z) % mod;
        ans = (ans + x * y % mod * dp[i] % mod) % mod;
        y = (y * i) % mod;
    }
    ans = (n - ans + mod) % mod;
    for(ll i = 0; i < (ll)vec.size(); i++){
        ans = ans * (n - 1) % mod;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 8536
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




vector<vector<ll>> g;
vector<pair<ll, ll>> a;
vector<bool> used;

pair<ll, ll> dfs(ll p){
    pair<ll, ll> res = {a[p].first, p};
    
    for(auto &x : g[p]){
        if(!used[x]){
            used[x] = true;
            auto a = dfs(x);
            if(res.first > a.first){
                res = a;
            }
        }
    }
    
    return res;
}

int main() {
    ll n, m;
    cin >> n >> m;
    if(n - 1 == m){
        cout << 0 << endl;
        return 0;
    }
    if(n < 2 * (n - m - 1)){
        cout << "Impossible" << endl;
        return 0;
    }
    a.resize(n);
    used.resize(n);
    REP(i, n){
        ll t;
        cin >> t;
        a[i] = {t, i};
    }
    g.resize(n);
    REP(i, m){
        ll x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    
    ll c = 0, ans = 0;
    vector<bool> used2(n);
    REP(i, n){
        if(!used[i]){
            auto x = dfs(i);
            ans += x.first;
            c++;
            used2[x.second] = true;
        }
    }
    
    sort(a.begin(), a.end());
    
    REP(i, 2 * (n - m - 1) - c){
        if(!used2[a[i].second]){
            ans += a[i].first;
        }
        else{
            c--;
        }
    }
    
    cout << ans << endl;
}


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

int main()
{
  int x, y;
  cin >> x >> y;
  
  for(int i = 0; i <= x; i++)
  {
    if((i*2) + ((x-i)*4) == y)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class DisjointSet
{
public:
    vector<int> rank, p;

    DisjointSet() {}
    DisjointSet(int size)
    : rank(vector<int>(size, 0)), p(vector<int>(size, 0))
    {
        for (int i = 0; i < size; ++i) makeSet(i);
    }

    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        if (rank[x] > rank[y])
        {
            p[y] = x;
        }
        else
        {
            p[x] = y;
            if (rank[x] == rank[y])
            {
                ++rank[y];
            }
        }
    }

    int findSet(int x)
    {
        if (p[x] != x)
        {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

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

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

    vector<int> p(N);
    rep (i, N) cin >> p[i];

    int x, y;
    DisjointSet ds{N + 1};
    rep (i, M)
    {
        cin >> x >> y;
        ds.unite(x, y);
    }

    int ans = 0;
    rep (i, N)
    {
        if (ds.same(p[i], i + 1))
        {
            ++ans;
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1408
use std::collections::VecDeque;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    let (_, v) = bfs(0, &graph);
    let (dist, _) = bfs(v, &graph);
    if dist == 0 {
        println!("First");
        return;
    }

    let mut grundy = vec![0; dist + 1];
    grundy[0] = 1;
    grundy[1] = 0;
    for i in 2..(dist + 1) {
        let next = [grundy[i - 1], grundy[i - 2]];
        grundy[i] = (0..).find(|i| !next.contains(i)).unwrap();
    }
    println!("{}", if grundy[dist] == 0 { "Second" } else { "First" });
}

fn bfs(start: usize, graph: &Vec<Vec<usize>>) -> (usize, usize) {
    let n = graph.len();
    let mut dist = vec![n; n];
    dist[start] = 0;
    let mut q = VecDeque::new();
    q.push_back(start);
    while let Some(v) = q.pop_front() {
        for &next in graph[v].iter() {
            if dist[next] > dist[v] + 1 {
                dist[next] = dist[v] + 1;
                q.push_back(next);
            }
        }
    }
    dist.into_iter()
        .enumerate()
        .map(|(i, d)| (d, i))
        .max()
        .unwrap()
}

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

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


Measured memory_bytes: 23024
// atcoder/abc153/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "("; each (i, s) os << i << ","; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "("; each (i, m) os << i << ","; os << ")"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> swap(pair<P, Q> p) { return make_pair(p.second, p.first); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, n;
  while (cin >> h >> n) {
    vector<pair<int, int>> v(n);
    cin >> v;
    const int N = 1e4 + 5;
    static int dp[N];
    const int inf = 1 << 29;
    fill(dp, dp + N, inf);
    dp[h] = 0;
    for (int hp = h; 0 <= hp; --hp) {
      each (spell, v) {
        int rem = max(0, hp - spell.first);
        setmin(dp[rem], dp[hp] + spell.second);
      }
    }
    cout << dp[0] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
_ = gets
l = gets.chomp.split(" ").map(&:to_i)
sorted = l.sort_by{ |e| e }
max = sorted[-1]

ct1 = Array.new(max+1){0}
ct2 = Array.new(max+1){0}
l.each do |e|
  ct1[e] += 1
  (0...e).each do |i|
    ct2[i] += 1
  end
end

sum = 0

sc = sorted.count
(0...sc-2).each do |i|
  (i+1...sc-1).each do |j|
    ssum = sc-1-j
    if sorted[i]+sorted[j] <= max
      ssum -= ct1[sorted[i]+sorted[j]]+ct2[sorted[i]+sorted[j]]
    end
    sum += ssum
  end
end

p sum


Measured memory_bytes: 1916
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_
}

fn main() {
    let q: Vec<u64> = read_line()
        .trim()
        .split_whitespace()
        .map(|x| x.parse().expect(""))
        .collect();
    let mut v: Vec<Vec<i64>> = vec![vec![]; q[0] as usize];
    let mut v_q: Vec<i64>;
    for _ in 0..q[1] {
        v_q = read_line()
            .trim()
            .split_whitespace()
            .map(|x| x.parse().expect(""))
            .collect();
        if v_q[0] == 0 {
            v[v_q[1] as usize].push(v_q[2]);
        } else if v_q[0] == 1 {
            if v[v_q[1] as usize].len() > 0 {
                println!("{}", v[v_q[1] as usize][v[v_q[1] as usize].len() - 1]);
            }
        } else if v_q[0] == 2 {
            if v[v_q[1] as usize].len() > 0 {
                v[v_q[1] as usize].pop();
            }
        }
    }
}



Measured memory_bytes: 7020
/* ABC115 */
/* A */
#include <iostream>
#include <string>
using namespace std;

int main(void){

    int D;
    cin >> D;
    int diff;
    diff = 25 -D;

    string EV="Christmas";

    for (int i=0; i<diff; ++i)
        EV += " Eve";
    cout << EV << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 10

int N;
int table[10];

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		table[i] = i;
	}

	do{

		printf("%d",table[0]+1);

		for(int i = 1; i <= N-1; i++){

			printf(" %d",table[i]+1);
		}
		printf("\n");

	}while(next_permutation(table,table+N));

	return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){


	ll n; cin >> n;
	string alp = "abcdefghijklmnopqrstuvwxyz";
	
	function<deque<pair<string,char>>(ll)> dfs = [&](ll n){
		deque<pair<string,char>> res;
		
		if(n==1){
			res.push_back(make_pair("a",'a'));
		}
		else{
			
			res = dfs(n-1);
			ll sz = res.size();
			rep(i,sz){
				pair<string,char> now = res[0];
				res.pop_front();
				
				char c = now.second;
				rep(j,c-'a'+2){
					res.push_back(make_pair(now.first + alp[j],alp[max(j,(ll)now.second-'a')]));
				}
				
			}

		}
		
		return res;
	};

	deque<pair<string,char>> res = dfs(n);
    sort(res.begin(), res.end());
	rep(i,res.size()){
		cout << res[i].first << endl;
	}
	
	return 0;

}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}


Measured memory_bytes: 8960
w, h, n = map(int, input().split())
min_x = 0
min_y = 0
max_x = w
max_y = h

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and min_x < x:
        min_x = x
    elif a == 2 and max_x > x:
        max_x = x
    elif a == 3 and min_y < y:
        min_y = y
    elif a == 4 and max_y > y:
        max_y = y

diff_x = max_x - min_x
diff_y = max_y - min_y

if diff_x < 0:
    diff_x = 0
if diff_y < 0:
    diff_y = 0
    
area = diff_x * diff_y
print(area)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

template<class V> class BIT {
private:
	int n; vector<V> bit;
public:
	void add(int i,V x){ i++; while(i < n) bit[i] += x, i += i & -i;}
	V sum(int i){i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;}
	BIT(int sz){ n = sz + 1, bit.resize(n,0);} //?????????????????????0?????´???
	BIT(vector<V> v){n = (int)v.size()+1; bit.resize(n); rep(i,n) add(i,v[i]);}
	void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
	void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1????????????
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    BIT<int> bt(n);
    rep(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == 0){
            bt.add(b-1,c);
        }else{
            cout << bt.sum(c-1) - bt.sum(b-2) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

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

  int cnt = 0;
  for(int i = 0; i < n-1; i++) {
    if(s[i] == s[i+1]) cnt++;
  }
  cout << n - cnt << endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 



int main() {
    int x, y, z, A;
    cin >> x >> y >> z;
    int a = y;
    int b = x;
    int c = y;
    a = z;
    cout << a << " " << b << " " << c << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main () {
	int nn[100]={0};
	ll k, d;
	int i, j, m,n;
	ll ret = 0;
	map<int, int> mp;
	
	cin >>n>>k;

	for (i=0;i<k;i++){
		cin >> d;
		for (j=0;j<d;j++) {
			cin >> m;
			nn[m-1]++;
		}
	}
	
	for (i=0;i<n;i++) {
		if (nn[i]==0) {
			ret++;
		}
	}
	
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final char ch = sc.next().toCharArray()[0];
			
			if(ch == 'A') {
				System.out.println('T');
			}else if(ch == 'C') {
				System.out.println('G');
			}else if(ch == 'G') {
				System.out.println('C');
			}else if(ch == 'T') {
				System.out.println('A');	
			}			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 20692
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;

    map<string, vector<P>> m;
    for (int i = 0; i < N; i++) {
        string str;
        int p;
        cin >> str >> p;
        m[str].push_back(P(p, i + 1));
    }

    vector<int> ans;
    for (auto it = m.begin(); it != m.end(); it++) {
        vector<P> vec = it->second;
        sort(vec.begin(), vec.end(), greater<>());
        for (P v : vec) ans.push_back(v.second);
    }

    for (int a: ans) cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
   ll n,k;
   cin >> n >> k;
   vector <ll> arr(n);
   for (int z=0;z<n;z++){
      cin >> arr[z];
   }
   sort(arr.begin(),arr.end());
   ll ans = 0;
   for (int z=0;z<k;z++){
      ans += arr[z];
   }
   cout << ans << endl;
} 

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 1e3+5;

int main()
{
    int N;
    string a,b,c;
    cin >> N >> a >> b;
    _for(i,0,N){
        c.PB(a[i]);
        c.PB(b[i]);
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	veci p(n);
	rep(i, n) cin >> p[i];
	sort(all(p));
	ll ans = 0;
	rep(i, n - 1)
	{
		ans += p[i];
	}
	cout << ans + p[n - 1] / 2 << endl;
	return 0;
}

Measured memory_bytes: 3580
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w = li()

grid = [list(lc()) for _ in range(h)]

dhs = [-1,0,1,0]
dws = [0,-1,0,1]

achive = True

for hi in range(h):
    for wj in range(w):
        ok = False
        if grid[hi][wj] == ".":
            continue
        
        for dh,dw in zip(dhs,dws):
            if 0 <= hi+dh < h and 0 <= wj+dw < w:
                if grid[hi+dh][wj+dw] == "#":
                    ok = True
                    
        if not ok:
            achive = False

print("Yes") if achive else print("No")

Measured memory_bytes: 3064
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector> //*max_element(all(変数))で最大値を獲得
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  ll a,b,n;  cin >> a >> b >>n;
  ll x = min(b-1,n);
  cout << (int)(a*(x%b)/b);
}


Measured memory_bytes: 3564
#include<iostream>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a > b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	if (b > c) {
		int tmp = b;
		b = c;
		c = tmp;
	}

	if (a > b) {
		swap(a, b);
	}

	cout << a << " " << b << " " << c << "\n";

	return 0;
}

Measured memory_bytes: 3096
<?php
$stdins = array();
    while(true)
    {
        $stdin = trim(fgets(STDIN));
        if ($stdin === '') 
        {
            break;
        }
        $stdins[] = $stdin;
    };
    //
    $N = $stdins[0];
    $a = explode(" ", $stdins[1]);
    //
    $cnt = 0;
    for ($i = 0; $i < $N; $i++)
    {
        $wk = $a[$i];
        $nextwk = 0;
        $mod = 0;
        $breaker = true;
        while($breaker)
        {
            $mod = $wk % 2;
            $nextwk = $wk / 2;
            if (($mod === 1) || ($nextwk === 0))
            {
                $breaker = false;
            }
            else
            {
                $cnt++;
                $wk = $nextwk;
            }
        }
    }
    echo $cnt;
?>

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

typedef struct node {
    char s[11];
    int point;
    int num;
} Node;

int compare(Node *a, Node *b) {
    int buf = strcmp(a->s, b->s);
    if (buf == 0) {
        return b->point - a->point;
    }
    else {
        return buf;
    }
}

int main() {
    int n = 0;
    scanf("%d\n", &n);
    Node lis[n];
    for (int i=0; i<n; i++) {
        for (int j=0; j<11; j++) lis[i].s[j] = '\0';
        scanf("%s%*[ ]%d\n", lis[i].s, &lis[i].point);
        lis[i].num = i+1;
    }
    qsort(lis, n, sizeof(Node), compare);
    for (int i=0; i<n; i++) {
        printf("%d\n", lis[i].num);
    }
    return 0;
}


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

int n; // 都市の数
ll k; // テレポート回数
int a[MAX]; // 都市iのテレポート先
bool visited[MAX]; // 訪問状況
int ans;

int main() {
// input
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
        a[i]--; // 0-indexed
    }
// solve
    int pos = 0;
    // visited[pos] = true;
    int cnt = 0; // テレポート回数
    rep(i, n) {
        cnt++;
        visited[pos] = true;
        pos = a[pos];
        if (visited[pos]) break; // 一度訪問した都市に戻ってきたら終了
    }
    // printf("テレポート回数%d\n", cnt);
    int loop_start = pos;
    // printf("テレポート始点%d\n", loop_start);
    if (cnt >= k) {
        pos = 0;
        rep(i, k) {
            pos = a[pos];
        }
        ans = pos;
    } else {
        pos = 0;
        rep(i, n) {
            if (pos == loop_start) break;
            pos = a[pos];
            cnt--;
            k--;
        }
        int loop_size = cnt;
        // printf("ループの大きさ%d\n", loop_size);
        pos = loop_start;
        rep(i, k%loop_size) {
            pos = a[pos];
        }
        ans = pos;
    }
// output
    ans++;
    cout << ans << "\n";
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	string s, t;
	cin>>s>>t;
	int a, b;
	cin>>a>>b;
	string ask;
	cin>>ask;
	if (ask == s) a--; else b--;
	cout<<a<<" "<<b<<"\n";
	
}


Measured memory_bytes: 256
S = input()
count = 0
if S[0] == "R" and S[1] == "R":
    if S[2] == "R":
        count = 3
    else:
        count = 2
if S[0] == "R" and S[1] == "S":
    count = 1
if S[0] == "S" and S[1] == "R":
    if S[2] == "R":
        count = 2
    else:
        count = 1
if S[0] == "S" and S[1] == "S":
    if S[2] == "R":
        count = 1
    else:
        count = 0
print(count)


Measured memory_bytes: 9124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var ds = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            ds.Sort();
            var centerIndex = N / 2 - 1;
            Console.WriteLine(ds[centerIndex + 1] - ds[centerIndex]);
        }
    }
}


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

int main(void) {
    int N;cin>>N;
    vector<int> vc(N);
    for (int i = 0; i < N; i++) cin>>vc[i];
    sort(vc.begin(), vc.end());
    int sum = 0;
    for (int i = 0; i < N - 1; i++) sum += vc[i];
    if (sum > vc[N - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

namespace CSharpSample01
{
    
    class Program
    {
      
        static void Main(string[] args)
        {
            
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            long X = long.Parse(str[1]);

            string[] input = Console.ReadLine().Split(' ');

            var point = new List<long>();

            point.Add(X);
            for(int i = 0; i < N; i++)
            {
                point.Add(long.Parse(input[i]));
            }

            point.Sort();

            var dif = new List<long>();
            //dif作り
            for(int i = 0; i < point.Count - 1; i++)
            {
                if(point[i] == X)
                {
                    dif.Add(point[i + 1] - point.First());
                }
                else
                {
                    dif.Add(point[i + 1] - point[i]);
                }
                
            }

            /*
            Console.WriteLine("dif");
            foreach(var s in dif)
            {
                Console.WriteLine(s);
            }
            */

            //dif.Sort();
            long a = 0;
            long b = 0;
            a = dif[0];
            long ans = a;

            for(int i = 1; i < dif.Count; i++)
            {
                if(a < dif[i])
                {
                    long t = a;
                    a = dif[i];
                    b = t;
                }
                else
                {
                    b = dif[i];
                }

                //Console.WriteLine($"a = {a} b = {b}");

                while (b != 0)
                {
                    long tmp = b;
                    ans = b;
                    b = a % b;
                    a = tmp;
                }

                //Console.WriteLine($"ans = {ans}");

            }

            Console.WriteLine(ans);

        }
    }
}


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

int main(void){
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>

class Bubble{
	int count = 0;
public:
	void bubble_sort(int *A, int N){
		int flag = 1;
		while(flag){
			flag = 0;
			for(int i = N-1; i > 0; --i){
				if(A[i] < A[i-1]){
					int tmp = A[i-1];
					A[i-1] = A[i];
					A[i] = tmp;
					flag = 1;
					++count;
				}
			}
		}
		for(int i = 0; i < N; ++i){
			if(i > 0) std::cout << " ";
			std::cout << A[i];
		}
		std::cout << std::endl;
		std::cout << count << std::endl;
		return;
	}
};

int main(){
	Bubble bub;
	int A[100];
	int N;

	std::cin >> N;

	for(int i = 0; i < N; ++i){
		std::cin >> A[i];
	}
	bub.bubble_sort(A, N);
	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<string.h>
int main(void)
{
        int n, ac=0, wa=0, tle=0, re=0, i, j;
        char s[100000][4];
        scanf("%d",&n);
        for(i=0;i<n;i++) scanf("%s",s[i]);

        for(i=0;i<n;i++){
                if(strcmp(s[i],"AC")==0) ac++;
                else if(strcmp(s[i],"WA")==0) wa++;
                else if(strcmp(s[i],"TLE")==0) tle++;
                else if(strcmp(s[i],"RE")==0) re++;
        }
        printf("AC x %d\n",ac);
        printf("WA x %d\n",wa);
        printf("TLE x %d\n",tle);
        printf("RE x %d\n",re);
        return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

vector<vector<bool>> FD(5000, vector<bool>(5000, false)), BD = FD;
vector<vector<int>> FC(5000), BC = FC;

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

	if (N == 1) {
		if (A[0] < K)cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}

	FD[0][0] = 1;
	if (A[0] < K) {
		FD[0][A[0]] = 1;
		FC[0] = { 0,A[0] };
	}
	else FC[0] = { 0 };
	for (int i = 1;i < N;i++) {
		for (int j = 0;j < K;j++) {
			if (FD[i - 1][j])FD[i][j] = 1;
			
			if (j - A[i] >= 0) {
				if (FD[i - 1][j - A[i]])FD[i][j] = 1;
			}
			if (FD[i][j])
				FC[i].push_back(j);
		}
	}

	BD[N - 1][0] = 1;
	if (A[N - 1] < K) {
		BD[N - 1][A[N - 1]] = 1;
		BC[N - 1] = { 0,A[N - 1] };
	}
	else BC[N - 1] = { 0 };
	for (int i = N - 2;i >= 0;i--) {
		for (int j = 0;j < K;j++) {
			if (BD[i + 1][j])BD[i][j] = 1;
			if (j - A[i] >= 0) {
				if (BD[i + 1][j - A[i]])BD[i][j] = 1;
			}
			if (BD[i][j])
				BC[i].push_back(j);
		}
	}

	int ans = 0;
	for (int j : BC[1]) {
		if (j >= K - A[0]) {
			ans++;
			break;
		}
	}
	for (int i = 1;i < N - 1;i++) {
		for (int j : FC[i - 1]) {
			auto it = lower_bound(all(BC[i + 1]), K - j - A[i]);
			if (it != BC[i + 1].end()) {
				if (*it + j < K) {
					ans++;
					break;
				}
			}
		}
	}
	for (int j : FC[N - 2]) {
		if (j >= K - A[N - 1]) {
			ans++;
			break;
		}
	}
	/*
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < 50;j++) {
			cout << FD[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < 50;j++) {
			cout << BD[i][j] << " ";
		}
		cout << endl;
	}
	*/
	cout << N - ans << endl;
}

Measured memory_bytes: 239744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; ++i)
inline constexpr int Inf = (1 << 30);

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N+1);
    rep(i,M) {
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<pair<int,int>> cf(N+1, {Inf,0});
    cf[1].first = 0;
    deque<int> m{1};
    while (m.size()) {
        const int room = m.front(); m.pop_front();
        const int nc = 1 + cf[room].first;
        for (auto to : g[room]) {
            if (nc < cf[to].first) {
                cf[to] = {nc, room};
                m.push_back(to);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i=2; i<=N; ++i)
        cout << cf[i].second << "\n";
}


Measured memory_bytes: 10556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll x;
  cin >> x;
  ll res = 0;
  for(int i = 1;i <= 40;i++){
    for(int j = 2;j <= 10;j++){
      if(pow(i,j) <= x){
        res = max(res,(ll)pow(i,j));
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 4020
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

using int64 = long long;

int64 R, C;
int N;

int64 calc(int64 x, int64 y) {
    if (y == 0) return x; 
    else if (x == R) return R + y;
    else if (y == C) return R + C + (R - x);
    else return R + C + R + (C - y);
}

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

    vector<pair<int64, int>> vec;
    for (int i = 0; i < N; i++) {
        int64 x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if ((x1 != 0) and (x1 != R) and (y1 != 0) and (y1 != C)) continue;
        if ((x2 != 0) and (x2 != R) and (y2 != 0) and (y2 != C)) continue;
        vec.emplace_back(calc(x1, y1), i);
        vec.emplace_back(calc(x2, y2), i);
    }

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

    stack<int> st;
    static bool used[200000] = {};
    for (auto& p : vec) {
        if (!used[p.second]) {
            used[p.second] = true;
            st.push(p.second);
        } else if (st.top() != p.second) {
            cout << "NO" << endl;
            return 0;
        } else {
            st.pop();
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 6512
import sys
from pprint import pprint


class UnionFind:
    def __init__(self):
        self._parent = {}
        self._rank = {}
        self._equiv = {}
    
    def _find(self, x):
        if self._parent[x] == x:
            return self._parent[x]
        else:
            p = self._find(self._parent[x])
            self._parent[x] = p
            return p
    
    def _set_parent(self, child, parent):
        self._parent[child] = parent
        self._equiv[parent].update(self._equiv.pop(child))
    
    def _union(self, x, y):
        x = self._find(x)
        y = self._find(y)
        if x == y: return
        if self._rank[x] > self._rank[y]:
            self._set_parent(y, x)
        elif  self._rank[x] < self._rank[y]:
            self._set_parent(x, y)
        else:
            self._set_parent(x, y)
            self._rank[x] += 1
    
    def _make_set(self, x):
        self._parent[x] = x
        self._rank[x] = 0
        self._equiv[x] = {x}
    
    def unite(self, *elements):
        if not elements: return
        for x in elements:
            if x in self._parent: continue
            self._make_set(x)
        x0 = elements[0]
        for x in elements[1:]:
            self._union(x0, x)
    
    def groups(self):
        return [set(e) for e in self._equiv.values()]


def pairs(ncol, nrow):
    # ?????????
    for x in range(ncol - 1):
        for y in range(nrow):
            yield [(x, y), (x + 1, y)]

    # ?????????
    for x in range(ncol):
        for y in range(nrow - 1):
            yield [(x, y), (x, y + 1)]

    # ???????????????
    for x in range(ncol - 1):
        for y in range(nrow - 1):
            yield [(x, y), (x + 1, y + 1)]

    # ???????????????
    for x in range(ncol - 1):
        for y in range(1, nrow):
            yield [(x, y), (x + 1, y - 1)]


def solve(ncol, nrow, rows):
 
    f = UnionFind()
    for x in range(ncol):
        for y in range(nrow):
            if rows[y][x]:
                f.unite((x, y))
    for (x1, y1), (x2, y2) in pairs(ncol, nrow):
        if rows[y1][x1] and rows[y2][x2]:
            f.unite((x1, y1), (x2, y2))
    return len(f.groups())


def main():
    while True:
        ncol, nrow = map(int, input().split())
        if ncol == 0 and nrow == 0:
            break
        rows = []
        for _ in range(nrow):
            row = list(map(int, input().split()))
            rows.append(row)
        print(solve(ncol, nrow, rows))

main()

Measured memory_bytes: 7840
// 2_nikkei2019_2qual_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (998244353)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> d(n);
    vector<ll> v(n);
    rep(i, n){
        v[i] = 0;
    }
    ll m = 0;
    rep(i, n){
        cin >> d[i];
        v[d[i]]++;
        m = max(m, d[i]);
    }
    if(d[0] != 0 || v[0] > 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for(int i = 1; i <= m; i++){
        if(v[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        rep(j, v[i]){
            ans = ans * v[i - 1] % MOD;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {

	int n;
	string s;
	map<string,int> mp;
	cin >> n;
	rep(i,n) {
		cin >> s;
		mp[s]++;
	}
	vector<string> sv;
	int maxi = 0;
	for(auto itr=mp.begin(); itr != mp.end(); ++itr) {
		//cout << itr->first << " " << itr->second << endl;
		if (maxi < itr->second) {
			//cout << maxi << " " << itr->first << " " << itr->second << endl;
			sv.clear();
			sv.shrink_to_fit();
			sv.pb(itr->first);
			maxi = itr->second;
			//cout << maxi << endl;
		}
		else if (maxi == itr->second) {
			sv.pb(itr->first);
		}
	}
	sort(sv.begin(), sv.end());
	for(auto itr=sv.begin(); itr != sv.end(); ++itr) {
		cout << *itr << endl;
	}
  return 0;
}


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

int ctoi(char c) {
    return c - '0';
}

char itoc(int i) {
    return '0' + i;
}

bool isMine(vector<vector<char>> &table, int i, int j) {
    if (table[i][j] == '#') {
        return true;
    } else {
        return false;
    }
}

void addNumber(vector<vector<char>> &table, int i, int j) {
    int H = table.size();
    int W = table[0].size();

    // 上の行の更新
    for(int dj=-1; dj<=1; dj++) {
        // 範囲外ならbreak
        if((i - 1) < 0) {
            break;
        }

        if(((j+dj) < 0) || ((j+dj) >= W)) {
            continue;
        } else {
            if (isMine(table, (i-1), (j+dj))) {
                continue;
            } else {
                int now = ctoi(table[i-1][j+dj]);
                table[i-1][j+dj] = itoc(now + 1);
            }
        }
    }

    // 左の更新
    if((j-1) >= 0) {
        if(isMine(table, i, (j-1)) == false) {
            int now = ctoi(table[i][j-1]);
            table[i][j-1] = itoc(now + 1);
        }
    }

    // 右の更新
    if((j+1) < W) {
        if(isMine(table, i, (j+1)) == false) {
            int now = ctoi(table[i][j+1]);
            table[i][j+1] = itoc(now + 1);
        }
    }

    // 自分の下の行の更新
    for(int dj=-1; dj<=1; dj++) {
        // 範囲外ならbreak
        if((i + 1) >= H) {
            break;
        }

        if(((j+dj)<0) || ((j+dj)>=W)) {
            continue;
        } else {
            if(isMine(table, (i+1), (j+dj))) {
                continue;
            } else {
                int now = ctoi(table[i+1][j+dj]);
                table[i+1][j+dj] = itoc(now + 1);
            }
        }
    }

}

int main() {
    int H, W;
    cin >> H >> W;

    vector<vector<char>> table(H, vector<char>(W));
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            table[i][j] = '0';
        }
    }

    for(int i=0; i<H; i++) {
        string S;
        cin >> S;

        for(int j=0; j<S.size(); j++) {
            if (S[j] == '#') {
                table[i][j] = '#';
                addNumber(table, i, j);
            }
        }
    }

    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cout << table[i][j];
        }
        cout << endl;
    }
}

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

using namespace std;

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

  long long A, B, K;
  cin >> A >> B >> K;

  pair<long long, long long> res;
  if (A >= K) res = {A-K, B};
  else if (A+B >= K) res = {0, A+B-K};
  else res = {0, 0};
  cout << res.first << " " << res.second << endl;

  return 0;
}



Measured memory_bytes: 256