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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;F f;T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){
    build(v);
  }
  void build(std::vector<T> const& v){
    int sz=v.size();
    n=1;while(n<sz)n<<=1;
    data.resize(2*n,identity);
    for(int i=0;i<sz;++i)data[i+n]=v[i];
    for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  void set(int i,T x){
    i+=n;data[i]=x;
    while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);
  }
  T fold(int l,int r)const{
    l+=n,r+=n;
    T x=identity;
    while(l<r){
      if(l&1)x=f(x,data[l++]);
      if(r&1)x=f(x,data[--r]);
      l>>=1,r>>=1;
    }
    return x;
  }
  T operator[](int i)const{return data[i+n];}
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}
template<class T,class F>
auto make_segtree(std::vector<T>const& v,T ide,F f){
  return segment_tree<T,F>(v,ide,f);
}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  auto seg = make_segtree<ll>(a,0,[](auto a,auto b){return a^b;});

  rep(i,n){
    cout<<(seg.fold(0,i)^seg.fold(i+1,n))<<" ";
  }
  cout<<endl;


}

Measured memory_bytes: 8800
import qualified Control.Monad as C
import qualified Data.List as L

main = do
    n <- read <$> getLine :: IO Int
    (s:ss) <- map L.sort <$> C.replicateM n getLine :: IO [String]
    putStrLn $ foldr merge s ss

merge [] _ = []
merge _ [] = []
merge (s:ss) (s':ss') = case (s == s', s < s') of
    (True, _) -> s:merge ss ss'
    (_, True) -> merge ss (s':ss')
    (_,False) -> merge (s:ss) ss'


Measured memory_bytes: 1148
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto s = RD!string;

	long cnt;
	foreach (i; 0..N)
	{
		if (s[i] == 'R')
			++cnt;
	}

	writeln(cnt > N / 2 ? "Yes" : "No");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int main(void){
    int N, a;
    cin >> N;
    map<int, int> all;
    for(int i = 0; i < N; i++){
        cin >> a;
        all[a]++;
    }
    
    int ans = 0;
    
    for(auto iter: all){
        int x = iter.first, y = iter.second;
        if(y < x) ans += y;
        else ans += y - x;
    }
    
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,a) FOR(i,0,a)
typedef vector<int> vi; typedef vector<vi> vvi;

vi ht;
vi dp;

int solve(int n) {
    if(n == 1) return 0;
    if(n == 2) return abs(ht[2] - ht[1]);
    if(dp[n] != -1) return dp[n];
    else {
        return dp[n] = min(
            abs(ht[n] - ht[n-1]) + solve(n-1), 
            abs(ht[n] - ht[n-2]) + solve(n-2)
        );
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    ht.resize(n + 1, 0);
    dp.resize(n + 1, -1);
    REP(i, n) cin >> ht[i + 1];
    cout << solve(n) << endl;
    return 0;
}

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

int main(){
  int n; cin >> n;
  int h[n];
  
  int max=0; int count=0;
  for(int i=0; i<n; i++){
    cin >> h[i];
    if(h[i]>=max){
      count++;
      max = h[i];
    }
  }
  
  cout << count;
  
  return 0;
}

Measured memory_bytes: 256
S=list(input())

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

S1=set(S)
ans1=set(ans)

ans_S=list(ans1-S1)
ans_S.sort()

if len(ans_S)>0:
    print(ans_S[0])
else:
    print("None")


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

const ll mo = 1000000007;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };
auto modmul = [](auto... modx)
{
  ll res = 1;
  for (auto modx_ : {modx...})
  {
    res *= modx_;
    res %= mo;
    res += mo;
    res %= mo;
  }
  return res;
};
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
vector<ll> fac;
vector<ll> factorial(ll n)
{
  vector<ll> fc;
  fc.push_back(1);
  for (ll i = 1; i < n + 10; i++)
  {
    fc.push_back((fc[i - 1] * i) % mo);
  }
  return fc;
}

void dfs(ll x, vector<vector<ll>> &g, vector<bool> &see, vector<ll> &par, vector<ll> &siz, vector<ll> &childdp)
{
  see[x] = 1;
  ll num = 1, dp = 1;
  for (auto p : g[x])
  {
    if (see[p])continue;
    par[p] = x;
    dfs(p, g, see, par, siz, childdp);
    num += siz[p];
    dp = modmul(dp, childdp[p], mypow(fac[siz[p]], mo - 2));
  }
  siz[x] = num;
  childdp[x] = mod(dp * fac[num - 1]);
}

int main()
{
ll n;
cin >> n;
fac = factorial(n);
vector<ll> ans(n, 0);
vector<vector<ll>> g(n);
rep(i, n - 1)
{
  ll a, b;
  cin >> a >> b;
  g[a - 1].push_back(b - 1);
  g[b - 1].push_back(a - 1);
}

//木dp root=0
vector<bool> see(n, 0);
vector<ll> par(n, -1);
vector<ll> siz(n, 0);
vector<ll> childdp(n, 0);
dfs(0, g, see, par, siz, childdp);
ans[0] = childdp[0];

//bfs順にrerooting
//root=0の時のsizなどは書き換わる
queue<ll> q;
for(auto i:g[0])q.push(i);
while (!q.empty())
{
  auto p = q.front();
  q.pop();
  ll num = 1, dp = 1;
  for (auto r : g[p])
  {
    if(r==par[p]){
      num+=siz[r]-siz[p];
      dp = modmul(dp,childdp[r], mypow(fac[siz[r]-1], mo - 2),fac[siz[p]],mypow(childdp[p],mo-2),mypow(siz[r]-siz[p],mo-2));
    }
    else{
      num += siz[r];
      dp = modmul(dp, childdp[r], mypow(fac[siz[r]], mo - 2));
      q.push(r);
    }
  }
  siz[p] = num;
  childdp[p] = mod(dp * fac[num - 1]);
  ans[p]=childdp[p];
}
for(auto r:ans)cout << r << endl;

return 0;
}

Measured memory_bytes: 24176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef deque<int> di;
typedef pair<int,int> pi;
#define pb push_back
#define mp make_pair
#define mh make_heap
#define pf push_front
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define FOR(i,a,b) for(ll i=a;i<b;i++)


int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    int n;
    cin>>n;
    int tem=n%1000;
        if(tem>0)
            cout<<1000-tem<<endl;
        else
            cout<<tem<<endl;



    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
#define N 200
using namespace std;
vector<pair<int,int> >v;
int main()
{
    int n,m,k;
    scanf("%d%d",&n,&k);
    m=(n-1)*(n-2)/2;
    if(k>m)
        puts("-1");
    else
    {
        for(int i=1;i<n;i++)
        v.push_back({i,n});
        int i=1,j=2;
        while(m!=k)
        {
            m--;
            v.push_back({i,j});
            j++;
            if(j==n)
                i++,j=i+1;
        }
        printf("%d\n",v.size());
        for(auto i:v)
        {
            printf("%d %d\n",i.first,i.second);
        }
    }
    return 0;
}


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

int main(){
	int n; cin >> n;
	vector<pair<int, int> > v(n/2);
	vector<pair<int, int> > kindf, kinds;
	vector<int> tmpf(100010, 0), tmps(100010, 0);

	for(int i = 0; i < n/2; ++i) cin >> v[i].first >> v[i].second;

	for(int i = 0; i < v.size(); ++i){
		tmpf[v[i].first]++;
		tmps[v[i].second]++;
	}

	for(int i = 0; i < tmpf.size(); ++i){
		if(tmpf[i] != 0) kindf.push_back(make_pair(tmpf[i], i));
		if(tmps[i] != 0) kinds.push_back(make_pair(tmps[i], i));
	}

	sort(kindf.begin(), kindf.end(), greater<pair<int, int> >());
	sort(kinds.begin(), kinds.end(), greater<pair<int, int> >());

	int sumf = 0, sums = 0;	

	for(int i = 0; i < kindf.size(); ++i){
		sumf += kindf[i].first;
	}
	for(int i = 0; i < kinds.size(); ++i){
		sums += kinds[i].first;
	}

	if(kindf[0].second == kinds[0].second){
		if(kindf[0].first < kinds[0].first){
			sumf -= kinds[1].first;
			sums -= kinds[0].first;
		}else if(kindf[0].first > kinds[0].first){
			sumf -= kinds[0].first;
			sums -= kinds[1].first;
		}else{
			if(kindf.size() == 1) sumf = 0;
			else if(kindf[1].first < kinds[1].first){
				sumf -= kindf[0].first;
				sums -= kinds[1].first;
			}else{
				sumf -= kindf[1].first;
				sums -= kinds[0].first;
			}
		}
	}else{
		sumf -= kindf[0].first;
		sums -= kinds[0].first;
	}

	cout << sumf + sums << endl;


	return 0;
}


Measured memory_bytes: 2428
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    int X, Y;

    scanf("%d %d", &X, &Y);

    for (int i = 0; i <= X; i++) {
        if (Y == 2 * i + (X - i) * 4) {
            printf("Yes");
            return 0;
        }
    }
    printf("No");

    return 0;
}

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

using namespace std;

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

	long long s = 0;
	for (long long i = 1; i < N; i++) {
		if (A[i - 1] > A[i]) {
			s += A[i - 1] - A[i];
			A[i] = A[i - 1];
		}
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(void){
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	vector<int> b[h];
	for(int i = 0; i < h; ++i){
		b[i].resize(w);
		cin >> a[i];
		for(int j = 0; j < w; ++j){
			b[i][j] = MOD;
		}
	}
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(a[i][j]=='#'){
				b[i][j] = 0;
			}else{
				if(j!=0){
					b[i][j] = b[i][j-1] +1;
				}
			}
		}
		for(int j = w-1; j >=0; --j){
			if(a[i][j]=='#'){
				b[i][j] = 0;
			}else{
				if(j!=w-1){
					b[i][j] = min(b[i][j], b[i][j+1]+1);
				}
			}
		}
	}
	for(int j = 0; j < w; ++j){
		for(int i = 0; i < h; ++i){
			if(a[i][j]=='#'){
				b[i][j] = 0;
			}else{
				if(i!=0){
					b[i][j] = min(b[i][j], b[i-1][j]+1);
				}
			}
		}
		for(int i = h-1; i >= 0; --i){
			if(a[i][j]=='#'){
				b[i][j] = 0;
			}else{
				if(i!=h-1){
					b[i][j] = min(b[i][j], b[i+1][j]+1);
				}
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			//cout << b[i][j] << " ";
			cnt = max(cnt, b[i][j]);
		}
		//cout << endl;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 5248
#include<cstdio>
#include<cmath>
double Heron(double a, double b, double c){
  double z = (a + b + c) / 2;
  return sqrt(z * (z - a) * (z - b) * (z - c));
}
double Pythagoras(double a, double b, double c, double d, double e, double f){
  double x, y, z;
  x = sqrt((c - a) * (c - a) + (d - b) * (d - b));
  y = sqrt((e - c) * (e - c) + (f - d) * (f - d));
  z = sqrt((a - e) * (a - e) + (b - f) * (b - f));
  return Heron(x, y, z);
}
int main(void){
  double x[25], y[25], ans = 0;
  int i = 3;
  scanf("%lf,%lf %lf,%lf %lf,%lf",&x[0] , &y[0], &x[1], &y[1], &x[2], &y[2]);
  ans = Pythagoras(x[0], y[0], x[1], y[1], x[2], y[2]);
  while(scanf("%lf,%lf",&x[i], &y[i]) != EOF){
    ans += Pythagoras(x[0], y[0], x[i-1], y[i-1], x[i], y[i]);
    i++;
  }
  printf("%.6f\n",ans);
}


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

struct Problem {

    UL N, M;
    vector<UL> E[100000];
    UL P[100000];

    void Solve() {
        scanf("%d%d", &N, &M);
        rep(i, M) {
            UL u, v; scanf("%d%d", &u, &v); u--; v--;
            E[u].push_back(v);
            E[v].push_back(u);
        }
        rep(i, N) P[i] = ~0u;
        P[0] = 0;
        queue<UL> Q; Q.push(0);
        while (Q.size()) {
            UL p = Q.front(); Q.pop();
            for (UL e : E[p]) {
                if (P[e] != ~0u) continue;
                P[e] = p;
                Q.push(e);
            }
        }
        printf("Yes\n");
        for (UL i = 1; i < N; i++) {
            printf("%d\n", P[i] + 1);
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}


Measured memory_bytes: 10308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	int cost[n][n];
	bool a[n][n];
	for (int i = 0;i < n;i++)
		for (int j = 0;j < n;j++) {
			cost[i][j] = min(min(i, j), min(n - 1 - i, n - 1 - j));
			a[i][j] = 1;
		}
	int ans = 0;
	for (int i = 0, p;i < n * n;i++) {
		cin >> p;
		int r = (p - 1) / n;
		int c = (p - 1) % n;
		ans += cost[r][c];
		a[r][c] = 0;
		queue<pii> Q;
		Q.push({r, c});
		while (!Q.empty()) {
			int x = Q.front().fi;
			int y = Q.front().se;
			Q.pop();
			if (x > 0 && cost[x - 1][y] > cost[x][y] + a[x][y]) {
				cost[x - 1][y] = cost[x][y] + a[x][y];
				Q.push({x - 1, y});
			}
			if (x < n - 1 && cost[x + 1][y] > cost[x][y] + a[x][y]) {
				cost[x + 1][y] = cost[x][y] + a[x][y];
				Q.push({x + 1, y});
			}
			if (y > 0 && cost[x][y - 1] > cost[x][y] + a[x][y]) {
				cost[x][y - 1] = cost[x][y] + a[x][y];
				Q.push({x, y - 1});
			}
			if (y < n - 1 && cost[x][y + 1] > cost[x][y] + a[x][y]) {
				cost[x][y + 1] = cost[x][y] + a[x][y];
				Q.push({x, y + 1});
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 4832
from sys import stdin

def output(st1, st2, num):
    st = ''
    for j in range(num):
        if j%2 == 1:
            st += st1
        elif j%2 == 0:
            st += st2

    return st

while True:
    H,W = map(int, stdin.readline().split())
    str = ''
    
    if W == 0 and H == 0:
        break
    
    for i in range(H):
        if i%2 == 1:
            str += output('#', '.', W) + '\n'
        elif i%2 == 0:
            str += output('.', '#', W) + '\n'
    print(str)


Measured memory_bytes: 5648
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

int main(){
  long int n,c = 0,b = 0,min;
  cin >> n;

  for(int i = 0; i < n; ++i){
    long int a;
    cin >> a;
    if(i == 0)
      min = abs(a);
    if(a < 0)
      c++;
    b += abs(a);
    if(abs(a) < abs(min)){
      min = abs(a);
    }
  }

  cout << (c % 2 == 0 ? b : b - min*2) << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
k = sum(b)-sum(a)
if k<0:
  print("No")
  exit()
ansa=0
ansb=0
for i in range(n):
  if b[i]<a[i]:
    ansb+=a[i]-b[i]
  else:
    re = b[i]-a[i]
    if re%2==0:
      ansa+=(b[i]-a[i])//2
    else:
      ansa+=(b[i]+1-a[i])//2
      ansb+=1
if (k-ansa)*2==k-ansb and 0<=k-ansa and 0<=k-ansb:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 4600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    string s;
    cin>>s;
    int sum=0;
    REP(i,s.size()/2){
        if(s[i]!=s[s.size()-i-1])sum++;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
def solve():

    N, K = [int(i) for i in input().split()]
    xlist = [int(i) for i in input().split()]

    cost = float("inf")
    # 連続する組み合わせの数
    for i in range(N-K+1):
        # iが左端でjが右端
        j = i + K - 1
        cost = min(
            cost,
            # 左から進んだ場合
            abs(xlist[i]) + abs(xlist[j] - xlist[i]),
            # 右から進んだ場合
            abs(xlist[j]) + abs(xlist[i] - xlist[j])
        )
    print(cost)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 62576
#include <iostream>
using namespace std;
int main() {
    int n, x;
    int i, j, k;
    int count;
    while (1) {
        count = 0;
        cin >> n >> x;
        if (n==0 && x==0) break;
        for (i=1;i<=n;i++) {
            for (j=1;j<=n&&j!=i;j++) {
                for (k=1;k<=n&&k!=i&&k!=j;k++) {
                    if (i+j+k==x) {
                        count += 1;
                    }
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    string s;
    cin >> s;

    if (s[0] == '7' or s[1] == '7' or s[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> a >> n >> m){
        ans = 0;
        rep(i, 1, 72){
            ll powered = pow(i + a, n), tmp = powered;
            cnt = 0;
            while(tmp){
                cnt += tmp % 10, tmp /= 10;
            }
            if(powered <= m && cnt == i){
                ans++;
            }
        }
        print(ans);
    }
}



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

int main() {
	int N,i,count=0,temp,j;
	cin>>N;
	vector<int> vec(N);
	vector<int> cou(N);
	for(i=0;i<N;i++){
		cin>>vec.at(i);
	}
	
	for(i=0;i<N;i++){
		cou.at(i)=0;
		while(vec.at(i)%2==0){
			temp=vec.at(i);
			temp=temp/2;
			vec.at(i)=temp;
			cou.at(i)+=1;
		}
		
	}
	sort(cou.begin(),cou.end());
	cout<<cou.at(0)<<endl;
	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
t = [int(input()) for i in range(n)]
print(lcm_list(t))

Measured memory_bytes: 5304
#include<stdio.h>

int main(void){
  int N,M,n,m;
  scanf("%d %d",&N,&M);
  if(N>M){
    n=M;
    m=N;
  }else{
    n=N;
    m=M;
  }
  
  int f[11];
  f[0]=1;
  int i,j;
  for(i=1;i<=10;i++){
    f[i]=f[i-1]*2;
  }
  
  if(m==1){
    if(N>M){
      for(i=1;i<=f[N]-1;i++){
        printf("1\n");
      }
    }else{
      for(i=1;i<=f[M]-1;i++){
        printf("1");
      }
    }
    return 0;
  }
  
  int x[1024][1024];
  for(j=0;j<=f[m]-1;j++){
    x[0][j]=0;
    x[1][j]=j%2;
  }
  int k=1;
  for(i=2;i<=f[n]-1;i++){
    if(i==k*2){
      for(j=0;j<=f[m]-1;j++){
        x[i][j]=(j/i)%2;
      }
      k=k*2;
    }else{
      for(j=0;j<=f[m]-1;j++){
        x[i][j]=(x[0][j]+x[i-k][j]+x[k][j])%2;
      }
    }
  }
  
  if(M>N){
    for(i=1;i<=f[n]-1;i++){
      for(j=1;j<=f[m]-1;j++){
        printf("%d",(x[i-1][j-1]+x[i-1][j]+x[i][j-1]+x[i][j])%2);
      }
      printf("\n");
    }
  }else{
    for(j=1;j<=f[m]-1;j++){
      for(i=1;i<=f[n]-1;i++){
        printf("%d",(x[i-1][j-1]+x[i-1][j]+x[i][j-1]+x[i][j])%2);
      }
      printf("\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 5248
K = int(input())
cnt = 0
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        if (j <= i-2 or j >= i+2) and i != 0:
            continue
        for k in range(0, 10):
            if (k <= j-2 or k >= j+2) and i+j != 0:
                continue
            for l in range(0, 10):
                if (l <= k-2 or l >= k+2) and i+j+k != 0:
                    continue
                for m in range(0, 10):
                    if (m <= l-2 or m >= l+2) and i+j+k+l != 0:
                        continue
                    for n in range(0, 10):
                        if (n <= m-2 or n >= m+2) and i+j+k+l+m != 0:
                            continue
                        for o in range(0, 10):
                            if (o <= n-2 or o >= n+2) and i+j+k+l+m+n != 0:
                                continue
                            for p in range(0, 10):
                                if (p <= o-2 or p >= o+2) and i+j+k+l+m+n+o != 0:
                                    continue
                                for q in range(0, 10):
                                    if (q <= p-2 or q >= p+2) and i+j+k+l+m+n+o+p != 0:
                                        continue
                                    for r in range(0, 10):
                                        if ((r <= q-2 or r >= q+2) and i+j+k+l+m+n+o+p+q != 0) or i+j+k+l+m+n+o+p+q+r == 0:
                                            continue
                                        cnt += 1
                                        if cnt == K:
                                            ans = r + 10 * q + 100 * p + 1000 * o + 10000 * n + 100000 * m + 1000000 * l + 10000000 * k + 100000000 * j + 1000000000 * i
print(ans)


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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<pair<int, int>> x(n);
  for(int i = 0; i < n; i++){
    int in;
    cin >> in;
    x[i] = make_pair(in, i);
  }
  
  sort(x.begin(), x.end());
  vector<int> median(n);
  
  int m0 = x[n / 2 - 1].first;
  int m1 = x[n / 2].first;
  for(int i = 0; i < n; i++){
    median[x[i].second] = i < n / 2 ? m1 : m0;
  }
  
  for(int i = 0; i < n; i++) cout << median[i] << '\n';
  
  return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,d,x;
    cin>>n>>d>>x;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=d;j+=a[i])cnt++;
    }
    cout<<cnt+x<<endl;
    return 0;
}


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

#define endl "\n"
#define ar array
#define INF 1e18;
#define ll long long
const int N=2e5+5;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,d;
    cin>>n>>d;
    int ans=0;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
         double val=pow((a*a+b*b),0.5);
        //cout<<val<<endl;
        if(val<=d)
            ans++;

    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 4312
import queue

h,w = map(int, input().split())
a = [input() for i in range(h)]

ans = 0

move = [[1,0],[-1,0],[0,1],[0,-1]]

for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            d = [[-1 for j in range(w)] for i in range(h)]
            q = queue.Queue()
            q.put([i,j])
            d[i][j]=0
            while 1:
                y,x = q.get()
                for dy,dx in move:
                    if 0<=y+dy<h and 0<=x+dx<w:
                        if a[y+dy][x+dx]=='.' and d[y+dy][x+dx]==-1:
                            q.put([y+dy,x+dx])
                            d[y+dy][x+dx]=d[y][x]+1
                if q.empty():
                    ans = max(ans,d[y][x])
                    break

print(ans)





Measured memory_bytes: 63316
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
int n,S,x[N];
long long ans,p[N];
int main(){
    cin>>n>>S;
    for (int i=1; i<=n; ++i)
	scanf("%d%lld",&x[i],&p[i]);
    int l=1,r=n,dir=0;
    for (;;){
	if (x[l]>=S) { ans+=x[r]-S; break; }
	if (x[r]<=S) { ans+=S-x[l]; break; }
	if (p[l]>=p[r]){
	    if (dir!=1) dir=1,ans+=x[r]-x[l];
	    p[l]+=p[r],--r;
	}
	else{
	    if (dir!=2) dir=2,ans+=x[r]-x[l];
	    p[r]+=p[l],++l;
	}
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1408
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def count_a(A, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if A[m] < b:
            l = m
        else:
            r = m
    return l + 1


def count_c(C, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if C[m] > b:
            r = m
        else:
            l = m
    return N - r


A.sort()
B.sort()
C.sort()

ans = 0
A_min = A[0]
C_max = C[-1]

for b in B:
    if A_min < b < C_max:
        ans += count_a(A, b) * count_c(C, b)

print(ans)


Measured memory_bytes: 23472
//优先队列priority_queue<int>j
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
using namespace std;
#define O2 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
	O2;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b)*c/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;

int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	int a;
	cin>>a;
	int ans = a + a*a + a*a*a;
	cout<<ans<<"\n";	
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define N 100100
#define mo 1000000007
using namespace std;
int n,ap[17][N],t[N],pr[N],f[N],a[N];
char s[N];
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=2;i<=n;++i)t[i]=t[i-1]+(s[i]==s[i-1]);
	for(int i=1;i<=n;++i){
		pr[i]=(pr[i-1]+(a[i]=s[i]-96))%3;
		ap[0][i]=1<<pr[i];
	}
	for(int j=1;j<=16;++j)for(int i=1,_E_=n+1-(1<<j);i<=_E_;++i)ap[j][i]=ap[j-1][i]|ap[j-1][i+(1<<j-1)];
	f[0]=1;
	for(int i=0;i<n;++i){
		f[i+1]=(f[i+1]+f[i])%mo;
		int l=i+1,r=n,m,s=n+1;
		while(l<=r)if(t[m=l+r>>1]!=t[i+1])r=m-1,s=m;else l=m+1;
		if(s>n)continue;
		for(int j=16;j+1;--j)if(s+(1<<j)<=n+1&&!(ap[j][s]&1<<(3+pr[i]-a[i+1])%3))s+=1<<j;
		if(s>n)continue;
		f[s]=(f[s]+f[i])%mo;
	}int ans=f[n]%mo;
	if(t[n])for(int i=n-1;i;--i)if(pr[n]==pr[i])ans=(ans+f[i])%mo;
	printf("%d",ans);
}

Measured memory_bytes: 8448
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <ctime>


#ifndef _USEFUL_MACROS_
#define _USEFUL_MACROS_
#define INF 999999999
#define N_PRIME 1000000007
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define OUTPUT_DEBUG
#ifdef OUTPUT_DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x) do{}while(false)
#endif
#endif 

using namespace std;

typedef struct {
    int cost;
    int to;
} Edge;

typedef pair<int,int> p;// first: ????????????second: ????´???????


int main(void){
    
    int n_vertex;
    int n_edge;
    int start;
    priority_queue<p , vector<p> , greater<p> > costs;
    
    cin >> n_vertex >> n_edge >> start;
    
    int now_cost[n_vertex];
    vector<Edge> G[n_vertex];
    
    REP(i,n_edge){
        int f,t,c;
        cin >> f>>t>>c;
        G[f].push_back((Edge){c,t});
    }
    
    
    REP(i,n_vertex)now_cost[i] = INF;
    
    now_cost[start] = 0;
    costs.push(p(0,start));
    
    while( costs.size() ){
        p pp = costs.top();costs.pop();
        if( now_cost[pp.second] < pp.first ) continue;
        
        int f = pp.second;
        
        REP(i,G[f].size()){
            int t = G[f][i].cost + pp.first;
            if( t < now_cost[G[f][i].to] ){
                now_cost[G[f][i].to] =t ;
                costs.push(p(t,G[f][i].to));
            }
        }
    }
    
    REP(i,n_vertex){
        if( now_cost[i] == INF )
            cout << ("INF") << endl;
        else
            cout << now_cost[i] << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 12932
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N;
  int A[200000];
  cin>>N;
  rep(i,N){
    cin>>A[i];
  }
  sort(A,A+N);
  rep(i,N-1){
    if(A[i]==A[i+1]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


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

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

  vector<int> a(N);
  int min = 100;
  int max = 1;

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) < min) {
      min = a.at(i);
    }
    if (a.at(i) > max) {
      max = a.at(i);
    }
  }

  bool is_alices = true;
  int alice = 0;
  int bob = 0;

  for (int p = max; p >= min; p--) {
    for (int i = 0; i < N; i++) {
      if (a.at(i) == p) {
        if (is_alices) {
          alice += p;
        } else {
          bob += p;
        }
        is_alices = !is_alices;
      }
    }
  }

  cout << alice - bob << endl;
}

Measured memory_bytes: 3572
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    long long K,X;
    cin >> K >> X;
    X=X-K+1;
    for(int i=0;i<2*K-1;++i){
        cout << X+i << " ";
    }
    }

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[""]*w for _ in range(h)]

if h == 1 and w == 1:
    if s[0][0] == "#":
        print("#")
    else:
        print(0)

elif h == 1:
    for j in range(w):
        if s[0][j] == ".":
            ans[0][j] = s[0][max(0, j - 1):min(w + 1, j + 2)].count("#")
        else:
            ans[0][j] = "#"

elif w == 1:
    for i in range(h):
        if i == 0:
            if s[i][0] == ".":
                ans[i][0] = s[i + 1][0].count("#")
            else:
                ans[i][0] = "#"
        elif i == h - 1:
            if s[i][0] == ".":
                ans[i][0] = s[i - 1][0].count("#")
            else:
                ans[i][0] = "#"
        else:
            if s[i][0] == ".":
                ans[i][0] = s[i - 1][0].count("#") + s[i+1][0].count("#")
            else:
                ans[i][0] = "#"

else:
    for i in range(h):
        for j in range(w):
            if i == 0:
                if s[i][j] == ".":
                    ans[i][j] = s[i][max(0, j - 1):min(w + 1, j + 2)].count("#") + s[i + 1][
                                                                                   max(0, j - 1):min(w + 1, j + 2)].count(
                        "#")
                else:
                    ans[i][j] = "#"
            elif i == h-1:
                if s[i][j] == ".":
                    ans[i][j] = s[i - 1][max(0, j - 1):min(w + 1, j + 2)].count("#") + s[i][max(0, j - 1):min(w + 1,
                                                                                                              j + 2)].count(
                        "#")
                else:
                    ans[i][j] = "#"
            else:
                if s[i][j] == ".":
                    ans[i][j] = s[i - 1][max(0, j - 1):min(w + 1, j + 2)].count("#") + s[i][max(0, j - 1):min(w + 1,
                                                                                                              j + 2)].count(
                        "#") + s[i + 1][max(0, j - 1):min(w + 1, j + 2)].count("#")
                else:
                    ans[i][j] = "#"

[print(*k,sep="") for k in ans]

Measured memory_bytes: 9256
import java.util.*;

public class Main{
  static int H, W;
  static int max = 0;
  static int[] ih = {1,0,-1,0};
  static int[] iw = {0,1,0,-1};
  static int[][] route;
  static char[][] maze;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    H = Integer.parseInt(S[0]);
    W = Integer.parseInt(S[1]);
    route = new int[H][W];
    maze = new char[H][W];
    for(int i = 0; i < H; i++){
      String T = sc.nextLine();
      for(int j = 0; j < W; j++){
        maze[i][j] = T.charAt(j);
      }
    }
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(maze[i][j] == '#'){
          continue;
        }
        func(i,j);
      }
    }
    System.out.println(max);
  }
  public static void func(int sh, int sw){
    for(int i = 0; i < H; i++){
      Arrays.fill(route[i], 0);
    }
    Queue<Integer> qh = new ArrayDeque<>();
    Queue<Integer> qw = new ArrayDeque<>();
    qh.add(sh);
    qw.add(sw);
    
    while(!qh.isEmpty()){
      int nh = qh.poll();
      int nw = qw.poll();
      
      if(route[nh][nw] > max){
        max = route[nh][nw];
      }
      
      for(int i = 0; i < 4; i++){
        int fh = nh+ih[i];
        int fw = nw+iw[i];
        
        if(fh < 0 || fh >= H || fw < 0 || fw >= W){
          continue;
        }
        if(maze[fh][fw] == '#' || route[fh][fw] > 0 || (fh == sh && fw == sw)){
          continue;
        }
        
        qh.add(fh);
        qw.add(fw);
        route[fh][fw] = route[nh][nw]+1;
      }
    }
  }
}


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

int main()
{
    char input;
    cin >> input;

    if (input == 'A' || input == 'T')
    {
        cout << (char)('A' + 'T' - input) << endl;
    }
    else
    {
        cout << (char)('C' + 'G' - input) << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

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);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

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

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

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


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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[] b=cin.ArrayInt(N,-1);

        List<int> L=new List<int>(b);
        List<int> ans=new List<int>();
        while(L.Count>0){
          bool flag=false;
          for(int i=L.Count-1;i>=0;i--){
            if(L[i]==i){
              ans.Add(i+1);
              L.RemoveAt(i);
              flag=true;
              break;
            }
          }
          if(!flag){
            Console.WriteLine(-1);
            return;
          }
        }
        ans.Reverse();
        Console.WriteLine(String.Join("\n",ans));
    }

}


Measured memory_bytes: 13268
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)


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

int x, n;
vector<int> p(102, 0);

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

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        p.at(a) = 1;
    }

    pair<int, int> ans(10000, 10000);

    for (int i = 0; i <= 101; i++) {
        if (p.at(i) == 0) {
            int dif = abs(i - x);
            ans = min(ans, make_pair(dif, i));
        }
    }

    cout << ans.second << endl;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	static class TaskF {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int H = in.nextInt();
			int W = in.nextInt();
			int d = in.nextInt();
			String mode = "RYGB";
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					int v = (i + j) / d % 2 + (i + W - 1 - j) / d % 2 * 2;
					out.print(mode.charAt(v % 4) + (j == W - 1 ? "\n" : ""));
				}
			}

		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

	}

}

Measured memory_bytes: 41044
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  ll k;
  cin >> s >> k;
  int n = s.size();  
  
  if(n<k){
    rep(i,n){
      if(s[i]!='1'){
        cout << s[i] << endl;
        return 0;
      }
    }
  }
  
  else {
    rep(i,k){
      if(s[i]!='1'){
       cout << s[i] << endl;
       return 0;
      }
      else  if(i==k-1) cout << 1 << endl;
    }
  }
    
}


Measured memory_bytes: 256