akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    ll n,m;
    scanf("%lld%lld",&n,&m);


    ll ans = 0;

    if(n==m){
        ans = 2;
        srep(i,1,n+1){
            ans *= i;
            ans %= 1000000007;
            ans *= i;
            ans %= 1000000007;
        }
    }else if(abs(n-m)==1){
        ans = 1;
        srep(i,1,n+1){
            ans *= i;
            ans %= 1000000007;
        }
        srep(i,1,m+1){
            ans *= i;
            ans %= 1000000007;
        }
    }
    
    cout << ans << endl;
    return 0;
}
 
 


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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b)a=b;};

const int MAX = 11514;
signed main(){
  int n,m,R;
  while(scanf("%d %d %d",&n,&m,&R),n||m){
    R*=4;
    vector<int> ax(n),ay(n);
    vector<int> bx(m),by(m);
    for(int i=0;i<n;i++) scanf("%d %d",&ax[i],&ay[i]);
    for(int i=0;i<m;i++) scanf("%d %d",&bx[i],&by[i]);

    vector<vector<int> > ps(MAX);
    for(int i=0;i<m;i++) ps[bx[i]].emplace_back(by[i]);
    for(int i=0;i<MAX;i++) sort(ps[i].begin(),ps[i].end());

    auto calc=[&](vector<int> &v,int l,int r)->int{
      return upper_bound(v.begin(),v.end(),r)-lower_bound(v.begin(),v.end(),l);
    };
    
    long long ans=0;
    for(int i=0;i<n;i++){
      int dy=0;
      for(int dx=-R;dx<=R;dx++){
	int x=ax[i]+dx;
	if(x<0||x>=MAX||ps[x].empty()) continue;
	while(dx*dx+(dy+1)*(dy+1)<=R*R) dy++;
	while(dx*dx+dy*dy>R*R) dy--;
	ans+=calc(ps[x],ay[i]-dy,ay[i]+dy);
      }      
    }
    printf("%lld\n",ans);
  }  
  
}



Measured memory_bytes: 5180
#include <iostream>
#include <cmath>
using namespace std;
int main() {
  int n, a;
  int max = 33;
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a;
    for (int j=32;j>=0;j--) {
      if (a % (int)pow(2, j) == 0) {
        max = min(max, j);
        break;
      }
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 512
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto N = readln.split[0].to!int;
	
	// p = 10^^k <= N < 10^^(k+1)
	int p = 1, k = 0;
	foreach (i; 0 .. 10) {
		if (p <= N && N < p*10) break;
		p *= 10; k += 1;
	} 
	
	int result;
	foreach (num; all(k+1)) {
		if (num > N) break;
		if (has(num, 3) && has(num, 5) && has(num, 7)) result++;
	}
	
	result.writeln;
}

// does n has m in its digit
bool has(int n, int m) {
	if (n < 10) return n == m;
	int n_ = n/10;
	return m == n - n_*10 || has(n_, m);
}

int[] generate(int n) {
	if (n == 1) return [3, 5, 7];
	auto next = generate(n-1);
	int[] result;
	foreach (num; next) { result ~= [num*10+3, num*10+5, num*10+7]; }
	return result;
}

int[] all(int n) {
	if (n == 1) return generate(1);
	else return all(n-1) ~ generate(n);
}

Measured memory_bytes: 892
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;

struct Node{
  int key;
  Node *prev,*next;
};

Node *nil;

void init(){
  nil=(Node *)malloc(sizeof(Node));
  nil->next=nil;
  nil->prev=nil;
}

void insert(int key){
  Node *x=(Node *)malloc(sizeof(Node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  x->prev=nil;
  nil->next=x;
}

Node* listSearch(int key){
  Node *cur=nil->next;
  while(cur != nil && cur->key != key){
    cur=cur->next;
  }
  return cur;
}

void deleteNode(Node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

int main(){
  int n,key;
  char com[15];
  init();

  cin >> n;
  for(int i=0;i<n;i++){
    scanf("%s %d",com,&key);
    if(com[0]=='i'){
      insert(key);
    }
    else if(strlen(com)<7){
      deleteKey(key);
    }
    else if(com[6]=='F'){
      deleteFirst();
    }
    else if(com[6]=='L'){
      deleteLast();
    }
  }
  Node *x=nil->next;
  int j=0;
  while(x!=nil){
    if(j++>0) printf(" ");
    printf("%d",x->key);
    x=x->next;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 32420
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b;a>=c;a--)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))
#define ctz(x) __builtin_ctz(x)
#define clz(x) __builtin_clz(x)
#define popcount(x) __builtin_popcount(x)
#define parity(x) __builtin_parity(x)

#define mod 1000000


int main(){
   
   int a,b;

   cin>>a>>b;
 if(a%b==0){
 	cout<<0<<endl;
 }else{
 	cout<<1<<endl;
 }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 101
#define act dp[l][r][u][d]

int n, m, i, j, ex, ey;
char s[maxN][maxN];
short dp[maxN][maxN][maxN][maxN];
int sum[maxN][maxN];
int l, r, u, d;
short ans;

inline short get_sum(int x1, int y1, int x2, int y2) {
    return max(0, sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1]);
}

void upd(short& dest, short sour) {
    if (sour > dest) dest = sour;
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d%d\n", &n, &m);
    for (i = 1; i <= n; i++) {
        scanf("%s\n", s[i] + 1);
        for (j = 1; j <= m; j++) {
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
            if (s[i][j] == 'o') sum[i][j]++;
            if (s[i][j] == 'E') ex = i, ey = j;
        }
    }

    for (l = 0; l < ey; l++) {
        for (r = 0; ey + r <= m; r++) {
            for (u = 0; u < ex; u++) {
                for (d = 0; ex + d <= n; d++) {

                    ans = max(ans, act);

                    // go right
                    if (ey + r + 1 <= m - l) {
                        upd(dp[l][r + 1][u][d], act + get_sum(max(d + 1, ex - u), ey + r + 1,
                                                              min(n - u, ex + d), ey + r + 1));
                    }

                    // go left
                    if (ey - l - 1 > r) {
                        upd(dp[l + 1][r][u][d], act + get_sum(max(d + 1, ex - u), ey - l - 1,
                                                              min(n - u, ex + d), ey - l - 1));
                    }

                    // go up
                    if (ex - u - 1 > d) {
                        upd(dp[l][r][u + 1][d], act + get_sum(ex - u - 1, max(r + 1, ey - l),
                                                              ex - u - 1, min(m - l, ey + r)));
                    }

                    // go down
                    if (ex + d + 1 <= n - u) {
                        upd(dp[l][r][u][d + 1], act + get_sum(ex + d + 1, max(r + 1, ey - l),
                                                              ex + d + 1, min(m - l, ey + r)));
                    }
                }
            }
        }
    }

    printf("%d", ans);


    return 0;
}


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

using namespace std;
using nagai = long long;
using ll = long long;

const int N = 1e6 + 100;
vector<int> g[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    vector<nagai> d(n);
    for (auto& x : d)
        cin >> x;
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b)
            {
             return d[a] > d[b];
            });
    map<nagai, int> mp;
    for (int i = 0; i < n; ++i)
        mp[d[i]] = i;
    vector<int> sz(n, 1);
    vector<pair<int, int>> edg;
    vector<bool> used(n);
    ord.pop_back();
    for (int x : ord)
    {
        used[x] = true;
        nagai dp = d[x] + sz[x] - (n - sz[x]);
        if (!mp.count(dp) || used[mp[dp]])
        {
             cout << -1 << '\n';
             return 0;
        }
        edg.emplace_back(mp[dp], x);
        sz[mp[dp]] += sz[x];
    }
    for (auto& p : edg)
    {
        int x = p.first, y = p.second;
        g[x].push_back(y), g[y].push_back(x);
    }
    vector<nagai> d1(n, -1);
    d1[0] = 0;
    vector<int> q = {0};
    for (int i = 0; i < q.size(); ++i)
    {
         int x = q[i];
         for (int y : g[x])
             if (d1[y] == -1)
                 d1[y] = d1[x] + 1, q.emplace_back(y);
    }
    if (d[0] != accumulate(d1.begin(), d1.end(), 0LL))
    {
        cout << -1 << '\n';
        return 0;
    }
    for (auto& x : edg)
        cout << x.first + 1 << ' ' << x.second + 1 << '\n';
	return 0;
}



Measured memory_bytes: 38264
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;;
    for(int i=0;i<t;i++)
    {
        char c;
        cin>>c;
        if(c>=97 && c<=122)
        {
            cout<<'a';
        }
        else
        {
            cout<<'A';
        }
    }
    return 0;
}    

Measured memory_bytes: 3620
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

ll power_ll_p(ll a, ll b, ll p)	//F_pでのべき
{
  if (b > p)
  {
    b %= (p - 1);//位数p-1
  }
  if (b == 0)
  {
    return 1;
  }
  if (b % 2 == 0)
  {
    ll t = power_ll_p(a, b / 2, p);
    return t * t % p;
  }
  else
  {
    return a * power_ll_p(a, b - 1, p) % p;
  }
}

ll combination_p(ll n, ll r, ll p)	//コンビネーション
{
  if (r > n - r)
  {
    r = n - r;
  }
  ll ans = 1;
  for (ll i = 0; i < r; i++)
  {
    ans *= n - i;
    ans %= p;
  }
  ll subans = 1;
  for (ll i = 0; i < r; i++)
  {
    subans *= i + 1;
    subans %= p;
  }
  ans *= power_ll_p(subans, p - 2, p);		//逆元は^(p-2)
  ans %= p;
  return ans;
}

ll extgcd(ll a, ll b, ll&x, ll&y)
{
  if (b == 0)
  {
    x = 1;
    y = 0;
    return a;
  }
  else
  {
    ll q = a / b;
    ll g = extgcd(b, a - q * b, x, y);
    ll z = x - q * y;
    x = y;
    y = z;
    return g;
  }
}

//modp逆元
ll inversemod(ll a, ll p)
{
  ll x, y;
  extgcd(a, p, x, y);
  x %= p;
  if (x < 0)
  {
    x += p;
  }
  return x;
}

const ll mod = 1e9 + 7;

int main()
{
  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  ll ans = 0;
  ll check = combination_p(a + w - b - 1, a, mod) * combination_p(b + h - a - 1, b, mod);
  check %= mod;
  ll i = a;
  ll j = b;
  while (i <= h && j <= w)
  {
    ans += check;
    ans %= mod;
    i++;
    j++;
    check *= a + w - b - i;
    check %= mod;
    check *= b + h - a - j;
    check %= mod;
    check *= inversemod(i, mod);
    check %= mod;
    check *= inversemod(j, mod);
    check %= mod;
  }
  cout << (ans + mod) % mod << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,W,k,v[100005],w[100005],j,dp[100005],ans,fix[100005];
int main(){
	cin>>n>>W;
	for(k=1;k<=n;k++){
		cin>>w[k]>>v[k];
		
	}
	for(k=1;k<=100001;k++)
   dp[k]=1e10;
   
   fix[0]=1;
	for(k=1;k<=n;k++){
		for(j=100001;j>=v[k];j--){
	dp[j]=min(dp[j],dp[j-v[k]]+w[k]);
			//cout<<j-w[k]<<" "<<dp[j-w[k]]+v[k]<<endl;
		}
	}
	for(k=1;k<=100001;k++){
		if(dp[k]<=W) ans=k;
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, m;
    cin>>n>>m;
    vector<pair<int, int> > v(m);
    rep(i, m) cin>>v[i].first>>v[i].second;
    string ans = "-1";
    for(int i=999;i>=0;i--){
        string s=to_string(i);
        if(s.size() != n) continue;
        bool ok=true;
        rep(i, m){
            if(s[v[i].first-1]-'0' != v[i].second) ok=false;
        }
        if(ok) ans = s;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF (1LL<<60)
#define MOD 1000000007

int N, T;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> T;
  long long s = 0, f = -INF;
  rep(i, N) {
    long long t;
    cin >> t;
    s += T;
    if (f > t) {
      s -= f-t;
    }
    f = t + T;
  }
  cout << s << "\n";
  return 0;
}


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

int main(void){
 
  	int A,B,C,X;
  
  	cin >> A >> B >> C >> X;
  
   	int count = 0; 
  	int total = 0;
  
  	for(int i = 0; i <= A; i++){
      for(int j = 0; j <= B; j++){
        for(int k = 0; k <= C; k++){
          total = 500 * i + 100 * j + 50 * k;
          if(total == X) count++;
        }
      }
    }
  
  	cout << count << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin >> p[i];
  int ans = 0;
  vector<int> m(n);
  m[0] = p[0];
  for(int i=1;i<n;i++){
    m[i] = m[i-1];
    if(m[i] > p[i]) m[i] = p[i];
  }
  for(int i=0;i<n;i++){
    if(m[i] == p[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;

}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int a, b;
	cin >> a >> b;

	int ans = 0;
	for(int i = 1; i <= 12; i++)
	{
		for(int j = 0; j <= 31; j++)
		{
			if(i == j) ans++;
			if(i == a && j == b)
			{
				cout << ans << endl;
				return 0;
			}
		}
	}
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    vector<int> xs, ys;
    bool flag = false;
    bool first = false;
    for(int i=0;i<s.size();++i){
        if(i == 0 && s[i] == 'F')first = true;
        if(s[i] == 'T'){
            flag = !flag;
            continue;
        }
        int cnt=0;
        while(i < s.size() && s[i] == 'F'){
            cnt++;
            i++;
        }
        if(flag)ys.push_back(cnt);
        else xs.push_back(cnt);
        i--;
    }

    set<int> xst, yst;
    if(first) xst.insert(xs[0]);
    else xst.insert(0);
    for(int i=(first?1:0);i<xs.size();++i){
        set<int> ns;
        for(int a : xst){
            ns.insert(a+xs[i]);
            ns.insert(a-xs[i]);
        }
        xst = ns;
    }
    yst.insert(0);
    for(int i=0;i<ys.size();++i){
        set<int> ns;
        for(int a: yst){
            ns.insert(a+ys[i]);
            ns.insert(a-ys[i]);
        }
        yst = ns;
    }

    if(xst.count(x) && yst.count(y))cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>

int main(){
  int N,c=-1;
  int X;
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
    X=(i*108)/100;
    if(X==N){
      c=i;
      break;
    }else if(X>N){
      break;
    }
  }
  if(c==-1) printf(":(\n");
  else printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 1716
n=int(input())
a=list(map(int,input().split()))
a_odd=[]
for i in range(n):
  if i%2==0:
    a_odd.append(a[i])
    
a_oddsub=[]
for i in a_odd:
  if i%2==1:
    a_oddsub.append(i)
print(len(a_oddsub))

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	vi dp[3],a[3];
	for(int i=0;i<n;i++){
		int a1, a2, a3;
		sd(a1);sd(a2);sd(a3);
		a[0].pb(a1);
		a[1].pb(a2);
		a[2].pb(a3);
		if(i==0){
			dp[0].pb(a1);
			dp[1].pb(a2);
			dp[2].pb(a3);
		}else{
			dp[0].pb(a1+max(dp[1][i-1], dp[2][i-1]));
			dp[1].pb(a2+max(dp[0][i-1], dp[2][i-1]));
			dp[2].pb(a3+max(dp[0][i-1], dp[1][i-1]));
		}
		//cout<<dp[0].back()<<" "<< dp[1].back()<<" "<< dp[2].back()<<endl;
	}
	pd(max(dp[0].back(), dp[1].back(), dp[2].back()));
}

Measured memory_bytes: 2920
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll cnt=1;
    ll sum=a[0];
    int i=1;
    while(cnt<n-1){
        sum+=a[i];cnt++;
        if(cnt==n-1)break;
        sum+=a[i];cnt++;
        if(cnt==n-1)break;

        i++;
    }

    cout<<sum;


    return 0;
}


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

using namespace std;

complex<double> naive(vector<double> angles) {
    int n = (int) angles.size();
    complex<double> total_sum(0);
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                total_sum += polar(1., (angles[i]+angles[j])/2) + polar(1., (angles[j]+angles[k])/2) - polar(1., (angles[i]+angles[k])/2);
            }
        }
    }
    return total_sum / ((double) n * (n-1) * (n-2) / 6);
}

complex<double> smart(vector<double> angles) {
    int n = (int) angles.size();
    complex<double> ij_sum;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            ij_sum += polar(1., (angles[i]+angles[j])/2) * ((double) (n-j-1));
        }
    }
    complex<double> jk_sum;
    for (int j = 0; j < n; ++j) {
        for (int k = j + 1; k < n; ++k) {
            jk_sum += polar(1., (angles[j]+angles[k])/2) * ((double) j);
        }
    }
    complex<double> ik_sum;
    for (int i = 0; i < n; ++i) {
        for (int k = i + 1; k < n; ++k) {
            ik_sum += polar(1., (angles[i]+angles[k])/2) * ((double) k-i-1);
        }
    }
    complex<double> total_sum = ij_sum + jk_sum - ik_sum;
    return total_sum / ((double) n * (n-1) * (n-2) / 6);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, L;
    cin >> n >> L;
    double pi = atan(1)*4;
    vector<double> angles(n);
    for (auto& angle : angles) {
        cin >> angle;
        angle *= 2*pi/L;
    }
    complex<double> result = smart(angles);
    cout << setprecision(20) << real(result) << " " << imag(result) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
#define double long double
const int mod=1000000007,MAX=35,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    N--;
    ll left=0,right=1000000000000000000;
    while(right-left>1){
        ll mid=(left+right)/2;
        
        ll sum=0;
        sum+=mid/3*4+mid/5*4;
        
        int k=1;
        for(ll i=9;;i=i*10+9,k++){
            ll cnt=0;
            ll j=i/10;
            if(i>=mid) i=mid;
            cnt+=(i-i/3-i/5+i/15);
            cnt-=(j-j/3-j/5+j/15);
            sum+=cnt*k;
            
            if(i==mid) break;
        }
        
        if(sum>N) right=mid;
        else left=mid;
    }
    
    ll mid=left;
    
    ll sum=0;
    sum+=mid/3*4+mid/5*4;
    
    int k=1;
    for(ll i=9;;i=i*10+9,k++){
        ll cnt=0;
        ll j=i/10;
        if(i>=mid) i=mid;
        cnt+=(i-i/3-i/5+i/15);
        cnt-=(j-j/3-j/5+j/15);
        sum+=cnt*k;
        
        if(i==mid) break;
    }
    
    N-=sum;
    
    string S;
    ll now=mid+1;
    while(S.size()<=100){
        if(now%3==0){
            S+="Fizz";
            if(now%5==0) S+="Buzz";
        }
        else if(now%5==0) S+="Buzz";
        else S+=to_string(now);
        now++;
    }
    
    cout<<S.substr(N,20)<<endl;
}





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

typedef long long ll;
#define DEBUG

void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll res = 0;
    for(auto b: B){
        // bより小さいAの個数をもとめる
        ll bb = -1;
        ll uu = N;
        // f(-)は増加。減少なら不等式は>か>=にする。
        while(uu - bb > 1){
            ll piv = (uu + bb)/2;
            if(A[piv] < b){ // 必要なら不等号はとりかえる
                bb = piv;
            }else{
                uu = piv;
            }
        }
        // bbはfがK未満(条件が真)の位置のうち一番右、uuはfがK以上(条件が偽)の位置のうち一番左
        ll numA = bb + 1;


        // bより大きいCの個数をもとめる
        bb = -1;
        uu = N;
        // f(-)は増加。減少なら不等式は>か>=にする。
        while(uu - bb > 1){
            ll piv = (uu + bb)/2;
            if(C[piv] <= b){ // 必要なら不等号はとりかえる
                bb = piv;
            }else{
                uu = piv;
            }
        }
        // bbはfがK未満(条件が真)の位置のうち一番右、uuはfがK以上(条件が偽)の位置のうち一番左
        ll numC = N - uu;

        // かける
        res += numA*numC;
    }
    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 2688
a=-1,A=65,d;
char
*N="GKSOCNWLDFVTBRXHAJUPEMQI",
*E="PHLTIDOXQAGWECSUMBKVJFNR",
*R="BCDAFGHEJKLINOPMRSTQVWXU",
s[9];
main(c)
{
for(;c-48&&scanf("%s",s);a+=d/4+1)
{
(c=*s)<A?~a&&printf("%d\n",a),a=d=0:0;
d=c==78?d=N[d]-A:d;
if(c==69)d=E[d]-A;
if(c==82)d=R[d]-A;
if(c==83)d=N[N[N[d]-A]-A]-A;
if(c==87)d=E[E[E[d]-A]-A]-A;
if(c==76)d=R[R[R[d]-A]-A]-A;
}}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    int[] result = {a, b, c};
    Arrays.sort(result);
    System.out.println(result[0] + " " + result[1] + " " + result[2]);
  }
}



Measured memory_bytes: 26336
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int K,T;
	int A[100];
	cin>>K>>T;
	int M=0,S=0;
	FOR(i,0,T){
		cin>>A[i];
		S+=A[i];
		M=max(M,A[i]);
	}
	if(S-M>=M){
		cout<<0<<endl;
	}else{
		cout<<M-(S-M)-1<<endl;
	}
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<endl;

#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};


int w,h;
int sx,sy,gx,gy;
int G[25][25] = {};
int mi = inf;

int dfs(int x,int y,int depth){
    if(depth>10) return 11;
    rep(i,4){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(G[ny][nx] == 1) continue;
        if(nx == gx && ny == gy) return depth+1;
        if(ny+dy[i] < 0 || h <= ny+dy[i] || nx+dx[i] < 0 || w <= nx+dx[i]) continue;
        while(G[ny+dy[i]][nx+dx[i]] != 1){
            nx += dx[i];
            ny += dy[i];
            if(nx == gx && ny == gy) return depth+1;
            if(ny+dy[i] < 0 || h <= ny+dy[i] || nx+dx[i] < 0 || w <= nx+dx[i]) break;
        }
        if(ny+dy[i] < 0 || h <= ny+dy[i] || nx+dx[i] < 0 || w <= nx+dx[i]) continue;
        G[ny+dy[i]][nx+dx[i]] = 0;
        mi = min(mi,dfs(nx,ny,depth+1));
        G[ny+dy[i]][nx+dx[i]] = 1;
    }
    return mi;
}

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


    while(cin >> w >> h,w){
        memset(G,0,sizeof(G));
        mi = inf;

        rep(y,h)rep(x,w) {
            cin >> G[y][x];
            if(G[y][x] == 2) sx = x,sy=y;
            if(G[y][x] == 3) gx = x,gy=y;
        }
        int ans = dfs(sx,sy,0);
        if(ans>10) ans = -1;
        cout << ans << endl;

    }

    return 0;
}


Measured memory_bytes: 3132
use std::cmp;

const INF: u32 = 1e7 as u32;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc
        .chars()
        .into_iter()
        .map(|c| c as usize - 'a' as usize)
        .collect::<Vec<_>>();
    let n = s.len();

    let mut dp = 0;
    let mut min = vec![INF; 1 << 26];
    min[0] = 0;
    let mut hash = 0;
    for i in 0..n {
        dp = INF;
        hash ^= 1 << s[i];
        let split_min = (0..26)
            .map(|i| {
                let palindrome_prefix = 1 << i;
                let suffix = hash ^ palindrome_prefix;
                min[suffix] + 1
            })
            .min()
            .unwrap();

        dp = cmp::min(dp, split_min);
        dp = cmp::min(dp, min[hash] + 1);
        min[hash] = cmp::min(min[hash], dp);
    }

    println!("{}", dp);
}

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: 268540
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

std::vector<std::string> split(std::string str, string del) {
    int first = 0;
    int last = str.find_first_of(del);
 
    std::vector<std::string> result;
 
    while (first < str.size()) {
        std::string subStr(str, first, last - first);
 
        result.push_back(subStr);
 
        first = last + 1;
        last = str.find_first_of(del, first);
 
        if (last == std::string::npos) {
            last = str.size();
        }
    }
 
    return result;
}

int main() {
  int K, M;
  int ans = 0;
  string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  string str;
  cin >> K;

  if(K == 1) {
    cout << 1 << endl;
    return 0;
  }
  int cnt = 0;
      for (const auto subStr : split(s, ", ")) {
        if(cnt == (K*2-2)) {
          str = subStr;
          // cout << "!!";
         }
        // std::cout << cnt << "=" << subStr << ",";
        cnt++;
    }
        // cout << endl;
  cout << str << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int max(int a,int b,int c,int n){
	if(a == 0 && b == 0 && c > 0) return c - 1;
	if(a > b) return b + c;
	else return a + c;
}

int main()
{
	int sums = 0,suma = 0,sumb = 0,both = 0;
	int n;
	char c[10005][11];
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%s",c[i]);
		for(int j = 0;j < strlen(c[i]) - 1;j++){
			if(c[i][j] == 'A' && c[i][j + 1] == 'B') sums++;
		}
		if(c[i][0] == 'B') sumb++;
		if(c[i][strlen(c[i]) - 1] == 'A') suma++;
		if(c[i][0]=='B' && c[i][strlen(c[i])-1]=='A'){
			suma--;
			sumb--;
			both++;
		}
	}
	sums += max(suma,sumb,both,n);
	printf("%d",sums);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
	char in[10];
	char s1[10],s2[10];
	int b1,b2;
	
	scanf("%s",s1);
	scanf("%s",s2);
	
	scanf("%d %d",&b1,&b2);
	
	scanf("%s",in);
	
	if(strcmp(s1,in) == 0)b1--;
	else if(strcmp(s2,in) == 0)b2--;
	
	printf("%d %d\n",b1,b2);
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#define PI acos(-1)
int limit;
void koch(double*, double*, int);
main()
{
        int count = 1;
        double start[2] = {0, 0}, end[2] = {100, 0};
        scanf("%d", &limit);
        printf("%.5f %.5f\n", start[0], start[1]);
        if(limit){
            koch(start, end, count);
        }
        printf("%.5f %.5f\n", end[0], end[1]);
}
void koch(double *start, double *end, int count)
{
        int i;
        double mid[3][2];
        for(i = 0; i < 2; i++){
                mid[0][i] = (2 * start[i] + end[i]) / 3;
                mid[2][i] = (start[i] + 2 * end[i]) / 3;
        }
        mid[1][0] = mid[0][0] + ((mid[2][0] - mid[0][0]) * cos(PI / 3)
                                                         - (mid[2][1] - mid[0][1]) * sin(PI / 3));
        mid[1][1] = mid[0][1] + ((mid[2][0] - mid[0][0]) * sin(PI / 3)
                             + (mid[2][1] - mid[0][1]) * cos(PI / 3));
        if(count == limit){
                for(i = 0; i < 3; i++){
                        printf("%.5f %.5f\n", mid[i][0], mid[i][1]);
                }
        }else{
                count++;
                koch(start, mid[0],count);
                printf("%.5f %.5f\n", mid[0][0], mid[0][1]);
                koch(mid[0], mid[1], count);
                printf("%.5f %.5f\n", mid[1][0], mid[1][1]);
                koch(mid[1], mid[2], count);
                printf("%.5f %.5f\n", mid[2][0], mid[2][1]);
                koch(mid[2], end, count);
        }
}

Measured memory_bytes: 1856
S = input()
K = int(input())

ss = []
seq = 1
for a,b in zip(S,S[1:]):
    if a==b:
        seq += 1
    else:
        ss.append(seq)
        seq = 1
ss.append(seq)

if len(ss)==1:
    print(len(S)*K//2)
    exit()

if S[0] != S[-1]:
    ans = sum([v//2 for v in ss]) * K
    print(ans)
else:
    ans = sum([v//2 for v in ss[1:-1]]) * K
    ans += (ss[0]+ss[-1])//2 * (K-1)
    ans += ss[0]//2 + ss[-1]//2
    print(ans)

Measured memory_bytes: 9116
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans=0;
    vint c(n);
    vint v(n);
    REP(i,n){
       cin >> v[i];
    }
    REP(i,n){
        cin >> c[i];
    }
    REP(i,n){
        int xy = v[i]-c[i];
        if(xy>0){
            ans+=xy;
        } 
    }
    cout << ans << endl;
    return 0;
}

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

bool prime(int k)
{
  for(int t=2;t<k;t++)
  {
    if(k%t==0)
    return 0;
  }
  return 1;
}

int main()
{
 int a;
 cin>>a;
 for(int t=a;t<=1000000;t++)
 {
   if(prime(t))
   {
     cout<<t;
     break;
   }
 }
}


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

int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll c = n/(a+b);
	ll d = n%(a+b);
	if( d>a )
		d = a;
	cout << (a*c)+d<<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector <int> d(N);
  for (int i=0; i<N; i++) {
    cin >> d.at(i);
  }
  int S1,S2,S3;
  S1 = 0;
  S2 = 0;
  for (int i=0; i<N; i++) {
    S1 = S1 + d.at(i);
    S2 = S2 + (d.at(i))*(d.at(i));
  }
  S3 = (S1*S1 - S2) / 2;
  cout << S3;
}


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

using namespace std;

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

int h, w;
char s[N][N];
queue<pair<int, pair<int, int>>> q;

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

int main() {
  scanf("%d %d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') q.push({0, {i, j}});
    }
  }
  int ans = 0;
  while (!q.empty()) {
    pair<int, pair<int, int>> u = q.front();
    q.pop();
    bool ok = false;
    for (int i = 0; i < 4; i++) {
      int x = u.second.first + dx[i];
      int y = u.second.second + dy[i];
      if (valid(x, y)) {
        if (s[x][y] == '.') {
          ok = true;
          q.push({u.first + 1, {x, y}});
          ans = max(u.first + 1, ans);
          s[x][y] = '#';
        }
      }
    }
    //cout << "OK: " << ok << " " << ans << endl;
  }
  printf("%d\n", ans);
  return 0;
}


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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

int A[N], mark[N], loop_start, loop_end, cnt;

void solve() {
        LL n, k; cin >> n >> k;
        for (int i = 0; i < n; i++) {
                cin >> A[i];
                --A[i];
        }
        if (k < 1LL * N) {
                int ans = 0;
                int i = 0;
                while(k--) {
                        i = A[i];
                }
                cout << i + 1 << endl;
                return;
        }
        loop_end = loop_start = -1;
        int i = 0;
        memset(mark, 0, sizeof mark);
        while(1) {
                int where_next = A[i];
                //cout << i << " " << where_next << endl;
                if (mark[where_next]) {
                        loop_end = i;
                        loop_start = where_next;
                        break;
                }
                mark[i] = 1;
                i = A[i];
               // cout << "hi";
        }
       // cout << loop_start << " " << loop_end << endl;
        i = loop_start;
        ++cnt;
        while(i != loop_end) {
              cnt++;
              i = A[i];
        }
        //cout << cnt << " ";
        i = 0;
        int before_loop = 0;
        while(i != loop_start) {
                i = A[i];
                before_loop++;
        }
        //cout << before_loop << endl;
        k -= 1LL * before_loop;
        k %= 1LL * cnt;
        i = loop_start;
        while(k --) {
                i = A[i];
        }
        cout << i + 1 << endl;
}

int main(){

        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

        solve();
        return 0;
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if (n % 2 == 0) {
        ll mn = a[n / 2] + a[n / 2 - 1];
        ll mx = b[n / 2] + b[n / 2 - 1];

        cout << mx - mn + 1 << endl;
    } else {
        ll mn = a[n / 2];
        ll mx = b[n / 2];

        cout << mx - mn + 1 << endl;
    }
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n+2, 0);
    rep(i, n) cin >> a[i+1];
    ll d = 0LL;
    rep(i, n+1) {
        d += abs(a[i] - a[i+1]);
    }
    rep(i, n) {
        int tmp = abs(a[i+2] - a[i]) - abs(a[i+1] - a[i]) - abs(a[i+2] - a[i+1]);
        cout << tmp + d << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define NumberOfOnes __builtin_popcount
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twoll pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
int n;
int a[100];
ll x,m=1000;
int main(){FAST;xRand;
cin>>n;
for(int i=1;i<=n;i++){
	cin>>a[i];
}
for(int i=1;i<n;i++){
	x=0;
	if(a[i]<a[i+1]) x=m/a[i];
	m+=(a[i+1]-a[i])*x;
}
cout<<m<<endl;
	// you should actually read the stuff at the bottom
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?), slow multiset operations
	* do smth instead of nothing and stay organized
	* unordered_map, hash_map, scanf, calculate answer instead of ans*K
*/
/*


                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/




Measured memory_bytes: 3592
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
V<int> dy={0,-1,0,1},dx={-1,0,1,0};
int main(){
  while(1){
    int w,h;
    cin>>w>>h;
    if(h==0)return 0;
    V<V<bool>> hh(h,V<bool>(w-1,true)),ww(h-1,V<bool>(w,true));
    for(int i=0;i<2*h-1;i++){
      if(i%2==0){
        for(int j=0;j<w-1;j++){
          int c;cin>>c;
          if(c)hh[i/2][j]=false;
        }
      }else{
          for(int j=0;j<w;j++){
          int c;cin>>c;
          if(c)ww[i/2][j]=false;
        }
      }
    }
    V<V<int>> a(h,V<int>(w,1e4));
    a[0][0]=1;
    queue<P> q;
    q.emplace(0,0);
    while(q.size()){
      int y=q.front().fi,x=q.front().se;
      q.pop();
      for(int i=0;i<4;i++){
        int ny=dy[i]+y,nx=dx[i]+x;
        if(ny<0||ny>=h||nx<0||nx>=w)continue;
        if(dy[i]==-1&&!ww[ny][nx])continue;
        if(dy[i]==1&&!ww[ny-1][nx])continue;
        if(dx[i]==-1&&!hh[ny][nx])continue;
        if(dx[i]==1&&!hh[ny][nx-1])continue;
        if(a[ny][nx]>a[y][x]+1){
          a[ny][nx]=a[y][x]+1;
          q.emplace(ny,nx);
        }
      }
    }
    if(a[h-1][w-1]==1e4)cout<<0<<"\n";
    else cout<<a[h-1][w-1]<<"\n";
  }
}


Measured memory_bytes: 3132