akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

long long int N,M,K,L,R,H,W;
//long long int N,M,K,L,R,H,W;

//const long long int MOD=1000000007;
const int MOD=1000000007;
//const long long int MOD=998244353;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N>>M;
	for(int i=0;i<N;i++){
		long long int st=i+M;
		long long int a=st/N;
		st%=N;
		a+=st;
		st=i+M;
		long long int b=st/M;
		st%=M;
		b+=st;
		//cout<<i+M<<" "<<a<<" "<<b<<endl;
		if(a<b){
			cout<<i+M<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>

int main()
{
    int a;
    int b;
    scanf("%d",&a);
    scanf("%d",&b);
    int ans=0;
    int soket=1;
    for(ans=0;soket<b;ans++)
    {
        soket+=a-1;
    }
    printf("%d\n",ans);
}

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

int main() {
  int N;
  int sum = 0;
  cin >> N;
  for (int i = 0;i < N;i++){
    int a,b;
    cin >> a >> b;
    sum = sum + (b-a+1);
  }
  cout << sum << endl;
}

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


int main() {
	int n;
	cin >> n;
	cout << n << ":";
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			n /= i;
			cout << " " << i;
		}
	}
	if (n != 1) cout << " " << n;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    int A, B;
    cin >> A >> B;
    if (A >= 13) cout << B << endl;
    else if (A >= 6) cout << B / 2 << endl;
    else cout << 0 << endl;

}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
fact = math.factorial
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N,K = I()
A = l()
div = A[0]
if K > max(A):
    print('IMPOSSIBLE')
    exit()
for i in range(1,N):
    div = math.gcd(div,A[i])
if K%div == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

const ll MOD = 1000000007;

struct mint {
    ll x;  // cout << ans.x << endl; で出力する
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    combination nCk(n);
    mint ans = 0;
    rep(i, min(k + 1, n)) {
        ans += nCk(n, i) * nCk(n - 1, i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	vector<pair<ll, int>> v;
	rep(i, n)
	{
		ll a; cin >> a;
		v.push_back(make_pair(a, 1));
	}
	rep(i, m)
	{
		int b; ll c;
		cin >> b >> c;
		v.push_back(make_pair(c, b));
	}
	sort(all(v));
	reverse(all(v));
	ll res = 0;
	int cnt = 0;
	int i = 0;
	while (cnt < n)
	{
		res += v[i].first*min(n - cnt, v[i].second);
		cnt += v[i].second;
		++i;
	}
	cout << res << endl;
}

Measured memory_bytes: 7440
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x) memset(x,0,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 110000
/*------------------------------------------------------------*/
int u[maxn];
int main(){
	int n;
	int ans=0;
	cin>>n;
	FOR(i,1,n){
		int c1,c2;
		in2(c1,c2);
		FOR(j,c1,c2){
			if(!u[j]){
				u[j]=true;
				ans++;
			}
		}
	}
	out(ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	int N;
	cin >> N;
	if (N % 10 == 9 || N / 10 == 9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main()
{
	int a,b,k,t=1;
	scanf("%d%d%d",&a,&b,&k);
	for (int i=min(a,b);i>0;i--)
		if (a%i==0&&b%i==0)
		{
			t=i;
			k--;
		//	cout<<k<<endl;
			if(k==0)
				break;
}
	cout<<t;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/

    //ABC089 - D

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int h,w,d; cin >> h >> w >> d;
    vii a(h, vi(w));
    vec<PII> id(h*w+1);
    rep(i,h) {
        rep(j,w) {
            cin >> a[i][j];
            id[a[i][j]] = make_pair(i,j);
        }
    }
    
    //前処理
    //x -> x+dの遷移しかないことを利用して累積和をとる。"特殊な取り方!"
    vi dist(h*w+1);
    for(int i = 0; i < h*w+1-d; ++i) {
        dist[i+d] = dist[i] + abs(id[i].first-id[i+d].first) + abs(id[i].second-id[i+d].second);
    }

    //query
    int q; cin >> q;
    vi l(q), r(q);
    rep(i,q) cin >> l[i] >> r[i];
    for(int i = 0; i < q; ++i) {
        cout << dist[r[i]] - dist[l[i]] << '\n';
    }
}

Measured memory_bytes: 3328
s = input()
for i in range(0, len(s)):
    if i%2 == 0:
        if s[i] is 'L':
            print('No')
            exit(0)
    if i%2 == 1:
        if s[i] is 'R':
            print('No')
            exit(0)
print('Yes')


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

using namespace std;

int main() {
  long long h, n;
  cin >> h >> n;
  vector<long long> nums(n);
  long long sum = 0;
  for(int i=0; i<n; ++i){
    long long a;
    cin >> a;
    sum += a;
  }
  
  if (h > sum) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1e9)
#define LINF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second
#define MOD (1e9 + 7)

int main() {
	int n;
	cin >> n;
	vector<int> divisor;
	vector<int> prime;
	FOR(i, 2, n + 1) {
		bool divisible = false;
		FOR(j, 2, i) {
			if (i % j == 0) divisible = true;
		}
		if (!divisible) {
			prime.push_back(i);
			divisor.push_back(0);
		}
	}
	prime.push_back(101);
	for (int i = 0; n >= prime[i]; i++) {
		int q = prime[i];
		for (int j = 0; n / q > 0; j++) {
			divisor[i] += n / q;
			q *= prime[i];
		}
	}
	int ans = 0;
	int a1 = 0, a2 = 0;
	//4こと4こと2このやつ
	for (auto e : divisor) {
		if (e >= 2) {
			a1++;
			if (e >= 4) {
				a2++;
			}
		}
	}
	if (a2 >= 2 && a1 >= 3) {
		ans += a2 * (a2 - 1) / 2 * (a1 - 2);
	}
	//2こと24このやつ
	a1 = 0;
	a2 = 0;
	for (auto e : divisor) {
		if (e >= 2) {
			a1++;
			if (e >= 24) {
				a2++;
			}
		}
	}
	if (a2 >= 1 && a1 >= 2) {
		ans += a2 * (a1 - 1);
	}
	//4こと14このやつ
	a1 = 0;
	a2 = 0;
	for (auto e : divisor) {
		if (e >= 4) {
			a1++;
			if (e >= 14) {
				a2++;
			}
		}
	}
	if (a2 >= 1 && a1 >= 2) {
		ans += a2 * (a1 - 1);
	}
	//74このやつ
	a1 = 0;
	a2 = 0;
	for (auto e : divisor) {
		if (e >= 74) {
			a1++;
		}
	}
	ans += a1;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int n=s.size()-1;
    while(n!=-1){
        if(n>=5&&s[n]=='r'&&s[n-1]=='e'&&s[n-2]=='s'&&s[n-3]=='a'&&s[n-4]=='r'&&s[n-5]=='e'){
            n-=6;
        }
        else if(n>=6&&s[n]=='r'&&s[n-1]=='e'&&s[n-2]=='m'&&s[n-3]=='a'&&s[n-4]=='e'&&s[n-5]=='r'&&s[n-6]=='d'){
            n-=7;
        }
        else if(n>=4&&s[n]=='e'&&s[n-1]=='s'&&s[n-2]=='a'&&s[n-3]=='r'&&s[n-4]=='e'){
            n-=5;
        }
        else if(n>=4&&s[n]=='m'&&s[n-1]=='a'&&s[n-2]=='e'&&s[n-3]=='r'&&s[n-4]=='d'){
            n-=5;
        }
        else{
            break;
        }
    }
    if(n==-1){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}


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

typedef long long int ll;
using ii= pair<ll,ll>;
#define F first
#define S second
#define MP make_pair
#define PB push_back
//using min_of_3=min({ll a,ll b,ll c});

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll n;
	cin>>n;
	
	vector<ll> v(n+1,0);
	
	for(ll i=1;i<=n;i++)
	{
	    for(ll j=i;j<=n;j+=i)
	    {
	        v[j]++;
	    }
	}
	
	
	ll sum=0;
	
	for(ll i=1;i<=n;i++)
	{
	    sum+=(i*v[i]);
	}
	
	cout<<sum<<"\n";
	
}


Measured memory_bytes: 81340
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char const* argv[])
{
	int w,h,x,y,r;
	std::cin >> w>> h>> x>> y>> r;
	if (x - r >= 0 &&
		x + r <= w &&
		y - r >= 0 &&
		y + r <= h   ) {
		std::cout << "Yes" ;
	} else {
		std::cout << "No" ;
	}
	std::cout << std::endl ;
	return 0;
}

Measured memory_bytes: 1160
# 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 rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

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

    int tot = 0;

    rep(i,m){
        tot+=a[i];
    }

    if(tot > n) cout << -1 << endl;
    else cout << n - tot << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
#define mp make_pair
const int inf = 1e8;
signed main(){
  int n,u,v;
  cin>>n>>u>>v;
  --u;--v;
  vector<vector<int>> G(n);
  for(int i=0;i<n-1;++i){
    int a,b;
    cin>>a>>b;
    --a;--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> dista(n,inf),distb(n,inf);
  dista[u]=distb[v]=0;
  vector<bool> vis(n,false);
  queue<pi> que;
  que.push(mp(u,0));
  while(!que.empty()){
    pi q=que.front();que.pop();
    vis[q.first]=true;
    dista[q.first]=q.second;
    for(auto i:G[q.first])if(!vis[i])que.push(mp(i,q.second+1));
  }
  vis=vector<bool>(n,false);
  que.push(mp(v,0));
  while(!que.empty()){
    pi q=que.front();que.pop();
    vis[q.first]=true;
    distb[q.first]=q.second;
    for(auto i:G[q.first])if(!vis[i])que.push(mp(i,q.second+1));
  }
  vis=vector<bool>(n,false);
  for(int i=0;i<n;++i)if(dista[i]>=distb[i])vis[i]=true;
  queue<int> que2;
  for(int i=0;i<n;++i)if(!vis[i]){
    que2.push(i);
    break;
  }
  int maxd=0,maxp=-1;
  while(!que2.empty()){
    int q=que2.front();que2.pop();
    if(maxd<distb[q])maxd=distb[q],maxp=q;
    vis[q]=true;
    for(auto i:G[q])if(!vis[i])que2.push(i);
  }
  cerr<<"maxd="<<maxd<<"\n";
  cerr<<"("<<dista[maxp]<<","<<distb[maxp]<<")\n";
  cout<<maxd-1;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define MAX 100

typedef struct{
  int width;
  int height;
}CAKE;

bool operator<( const CAKE& left, const CAKE& right ) {
  return left.width * left.height< right.width * right.height;
}

int main() {
  int n,w,d;

  while( cin >> n >> w >> d, n || w || d ) {

    vector< CAKE > cake;
    CAKE tmp = {w,d};
    cake.push_back(tmp);
    int p,s;
    while( n-- ){
      cin >> p >> s;
      p--;

      int cnt = 0;
      while( true ){
	assert( s!=cake[p].width);
        if ( s-cake[p].width <= 0) break;
        s -= cake[p].width;
        cnt++;

	assert( s!=cake[p].height);
        if ( s-cake[p].height <= 0) break;
        s -= cake[p].height;
        cnt++;
      }


      cnt %= 4;
      pair < CAKE,CAKE > P;
      if ( cnt % 2 == 0 ) {

        CAKE tmp = {s,cake[p].height};
        P.first = tmp;
        tmp.width = cake[p].width - s;
        P.second = tmp;

      } else {
        CAKE tmp = {cake[p].width,s};
        P.first = tmp;
        tmp.height = cake[p].height - s;
        P.second = tmp;
      }

      if (  P.first.width * P.first.height > P.second.width * P.second.height ) {
        cake.push_back(P.second);
        cake.push_back(P.first);
	cake.erase(cake.begin()+p);
      }else{
        cake.push_back(P.first);
        cake.push_back(P.second);
	cake.erase(cake.begin()+p);
      }

    }

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

    for ( int i = 0; i < cake.size()-1; i++ ) {
      cout << cake[i].width * cake[i].height << " ";
    }
    cout << cake[cake.size()-1].width * cake[cake.size()-1].height << endl;


  }

  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;

int main(void)
{
	vector <string> image;
	string s;
	int h, w;
	string temp;
	cin >> h >> w;
	
	for (int i = 0; i < w+2; i++)
	{
		temp += '#';
	}
	image.push_back(temp);
	for (int i = 0; i < h; i++)
	{
		cin >> s;
		s = '#' + s + '#';
		image.push_back(s);
	}
	image.push_back(temp);

	for (int i = 0; i < image.size(); i++)
	{
		cout << image[i] << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
int n,a[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cout << fixed << setprecision(12);
	cin >> n;
	rep(n) cin >> a[i];
	rep(n){
		if(i==0) a[i]--;
		else if(a[i]<a[i-1]){
			print1("No");
			return 0;
		}
		else if(a[i]>a[i-1]) a[i]--;
	}
	print1("Yes");
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int a,b;
    while(cin>>a>>b){
        a+=b;
        for(int i=1;i<1000;i++){
            if(!(a/10)){
                a=i;
                break;
            }
            else a/=10;
        }
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long n,x;
    cin>>n;
    map<long,long> m;
    for(long i=0;i<n;i++)
    {
        cin>>x;
        m[x]++;
    }
    vector<long long> v;
    v.push_back(0);
    v.push_back(0);
    for(map<long,long>::iterator it=m.begin();it!=m.end();it++)
        if(it->second>3){
            v.push_back(it->first);
            v.push_back(it->first);
        }
        else if(it->second>1)
            v.push_back(it->first);
    sort(v.rbegin(),v.rend());
    cout<<v[0]*v[1];
}

Measured memory_bytes: 6528
from math import degrees, cos,sqrt ,radians

A, B, H, M = map(int, input().split())

if H == 6 and M == 0:
    print(A+B)
    exit()


kaku = abs((6*M-(0.5*M+H*30)))
if kaku > 180:
    kaku = 360 - kaku
# print(kaku)
# if kaku > 90:
#     kaku = 180-kaku
# print(kaku)
# print(cos(radians(kaku)))
print(sqrt(A**2 + B**2 -2*A*B*cos(radians(kaku))))

# print(-A*B*cos(kaku))
# 3 4 7 0

Measured memory_bytes: 9512
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;


int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for (int i=0;i<10;i++) {
            for (int j=0;j<10;j++) {
                for (int k=0;k<10;k++) {
                    for (int l=0;l<10;l++) {
                        if (i+j+k+l==n) ans++;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;
using ll = long long;
const ll md = 998244353;

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

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

  ll ans = 0;
  vector<vector<ll>> memo(n + 1, vector<ll>(s + 1, 0));
  memo[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= s; ++j) {
      memo[i][j] += memo[i - 1][j] * 2;
      memo[i][j] %= md;
      if (j - va[i - 1] >= 0) {
        memo[i][j] += memo[i - 1][j - va[i - 1]];
        memo[i][j] %= md;
      }
    }
  }

  cout << memo.back().back() << '\n';
}

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

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
          int N = int.Parse(Console.ReadLine());
          string[] s = Console.ReadLine().Split(' ');
          int p = 0;
          int w = 0;
          int g = 0;
          int y = 0;
          for (int i = 0; i <N ; i++)
          {
              if(s[i]=="P"){
                  p++;
              }else if(s[i]=="W"){
                  w++;
              }else if (s[i]=="G")
              {
                  g++;
              }else if (s[i]=="Y"){
                  y++;
              }
          }
          int ans = 0;
              if(p>0){
                  ans++;
              }
              if (w>0){
                  ans++;
              }
              if(g>0){
                  ans++;
              }
              if (y>0){
                  ans++;
              }
              Console.WriteLine(ans>3?"Four":"Three");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef long long ll;
#define PI 3.1415926535

int main(){
    int a,b,h,m,time;
    long double w_hour = 0.5,w_min = 6.0;
    long double theta_a,theta_b,theta;
    long double sq_ans,ans;
    cin >> a >> b >> h >> m;
    time = h*60 + m;
    theta_a = (long double)time*0.5;
    theta_b = (time*6) - ((time*6)/360)*360;
    theta = fabs(theta_a - theta_b);
    sq_ans = (long double)(a*a) + (long double)(b*b) - (long double)2.0*(long double)a*(long double)b*cos(2.0*PI*theta/360.0);
    ans = sqrt(sq_ans);
    //cout << ans << endl;
    //printf("%-10Lf\n",ans);
    cout << fixed << setprecision(20) << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4160
import sys
sys.setrecursionlimit(4100000)

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

#繰り返し2乗法
def  mod_pow(a:int, b:int, mod:int)->int:
    if b % 2 == 0:
        return (mod_pow(a, b//2, mod) ** 2) % mod
    elif b == 1:
        return a % mod
    else:
        return ((mod_pow(a, b//2, mod) ** 2) * a) % mod

#逆元を求める関数
def mod_inverse(mod:int, b:int)->int:
    return mod_pow(b, mod-2, mod)

#aCbをmodで割った余りを求める関数(bが小さい)
def nCr_mod(n:int, r:int, mod:int)->int:
    num, den = 1, 1 #numerator, denominator

    for i in range(r):
        num = (num * (n-i)) % mod
        den = (den * (i+1)) % mod

    return (num * mod_inverse(mod, den)) % mod
    
ans = (mod_pow(2, n, mod) - 1 - nCr_mod(n, a, mod) - nCr_mod(n, b, mod)) % mod
print(ans)

Measured memory_bytes: 3064
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    cin >> N;
    while (N > 0) {
        if (N % 10 == 7) {
            cout << "Yes" << endl;
            exit(0);
        }
        N /= 10;
    }
    cout << "No" << endl;

	return 0;
}


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

using namespace std;

int main() {

	int A, B, K;
	cin >> A >> B >> K;

	int big, small;

	vector<int> dividers, common_dividers;
	dividers.reserve(100);
	common_dividers.reserve(100);
	if (A > B) {
		big = A;
		small = B;
	}
	else {
		big = B;
		small = A;
	}
	
	int max_divider = sqrt(small);

	for (int i = 1; i <= max_divider; i++) {
		if (small%i == 0) {
			dividers.push_back(i);
			if (small / i != i)dividers.push_back(small / i);
		}
	}
	sort(dividers.begin(), dividers.end());

	for (int i = 0; i < dividers.size(); i++) {
		if (big % dividers[i] == 0) {
			common_dividers.push_back(dividers[i]);
		}
	}

	cout << common_dividers[common_dividers.size() - K] << endl;

	return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  int D[n];
  for (int i = 0; i < n; i++)
    cin >> D[i];

  x -= accumulate(D, D + n, 0);
  cout << n + x / *min_element(D, D + n) << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N, M;
    cin >> N >> M;
    struct Cake {
        ll x;
        ll y;
        ll z;
        ll value(ll sign) {
            auto bool_to_sign = [](bool is_neg){
                if (is_neg) {
                    return -1;
                } else {
                    return 1;
                }
            };
            return bool_to_sign((sign & (1 << 0)) != 0) * x
                    + bool_to_sign((sign & (1 << 1)) != 0) * y
                    + bool_to_sign((sign & (1 << 2)) != 0) * z;
        }
    };
    vector<Cake> cakes(N);
    for (ll i = 0; i < N; i++) {
        cin >> cakes[i].x;
        cin >> cakes[i].y;
        cin >> cakes[i].z;
    }
    auto dp = make_vec_nd(numeric_limits<ll>::min(), 8, N+1, N+1);
    for (ll sign = 0; sign < 8; sign++) {
        for (ll n = 0; n <= N; n++) {
            for (ll m = 0; m <= n; m++) {
                if (n == 0) {
                    if (m == 0) {
                        dp[sign][n][m] = 0;
                    } else {
                        dp[sign][n][m] = numeric_limits<ll>::min();
                    }
                    continue;
                }
                dp[sign][n][m] = dp[sign][n-1][m];
                if (m > 0) {
                    dp[sign][n][m] = max(dp[sign][n][m],
                                         dp[sign][n-1][m-1] + cakes[n-1].value(sign));
                }
            }
        }
    }
    ll ans = numeric_limits<ll>::min();
    for (ll sign = 0; sign < 8; sign++) {
        ans = max(ans, dp[sign][N][M]);
    }
    cout << ans << endl;
}



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

typedef long long ll;

ll gcd (ll x, ll y) {
    if (x < y) {
        swap(x, y);
    }
    x = x - (x / y) * y;
    if (x == 0) {
        return y;
    }
    else {
        return gcd (x, y);
    }
}

int main () {
    ll x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,X=0;
  cin >> A >> B >> C >> D;
  X += min(B,D)-max(A,C);
  if(X < 0){
    cout << 0 << endl;
    return 0;
  }
  cout << X << endl;
}


Measured memory_bytes: 3588
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
const ll INF = 1001001001;

int main() {
  ll n;
  cin >> n;
  vector<ll> tm(5);
  ll mi = 1001001001001001;

  rep(i, 5) {
    cin >> tm[i];
    mi = min(mi, tm[i]);
  }
  long double n2 = static_cast<long double>(n);
  long double mi2 = static_cast<long double>(mi);

  long double d = n2 / mi2;
  ll ans = 4 + ceil(d);
  cout << ans;
  return 0;
}


Measured memory_bytes: 3612
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359

string a, b;
int n, m, memo[3010][3010];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    memset(memo, 0, sizeof(memo));
    cin >> a >> b;
    n = a.size(), m = b.size();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            memo[i][j] = max(memo[i][j - 1], memo[i - 1][j]);
            if (a[i - 1] == b[j - 1]) memo[i][j] = max(memo[i][j], memo[i - 1][j - 1] + 1);
        }
    }
    string ans = "";
    int x = n, y = m;
    while (x > 0 && y > 0) {
        if (memo[x][y] == memo[x - 1][y]) {
            x--;
        }
        else if (memo[x][y] == memo[x][y - 1]) {
            y--;
        }
        else {
            ans += a[x - 1];
            x--;
            y--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c;
  cin >> a >> b >> c;
  if((a==b&&b==c)){
    cout << (a%2==0 ? -1 : 0) << '\n';
    return 0;
  }
  
  ll cnt = 0;
  while((a%2)+(b%2)+(c%2)==0){
    int a_half = a/2;
    int b_half = b/2;
    int c_half = c/2;
    a = b_half + c_half;
    b = c_half + a_half;
    c = a_half + b_half;
    cnt++;
  }
  
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
def f(v,i):s,n=4*2**v-3,2*2**v-1;m=s/2+1;return 0 if i<1 or i>s else[0,f(v-1,i-1),n/2+1,f(v-1,i-m)+n/2+1,n,1][(i>1)+(i>=m)+(i>m)+(i>=s)+(v==0)*3]
print f(*map(int,raw_input().split()))

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

int main(){
  int N,X,result=1,count=0;
  cin >> N >> X;
  int L[N];
  for(int i=0;i<N;i++){
    cin >> L[i];
  }

  for(int i=0; i<N;i++){
    count += L[i];
    if(count<=X){
      result += 1;
    }
  }

  cout << result << endl;
}


Measured memory_bytes: 256
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    R, S, P = read_ints()
    A = []
    for _ in range(P):
        i, j = read_ints()
        i -= 1
        j -= 1
        A.append((i, j))

    print(solve(R, S, P, A))


def solve(R, S, P, A):
    q = [0] * (R + S + 1)
    for i, j in A:
        x = S - j if j < S else j - S + 1
        q[R - 1 - i + x] += 1

    of = 0
    for i in range(R + S + 1):
        c = q[i] + of
        if c > 0:
            q[i] = 1
            of = c - 1
    if of > 0:
        return R + S + 1 + of
    while q and q[-1] == 0:
        del q[-1]
    return len(q)


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 62128
n, a, b, c = map(int, input().split())

nums = {"A": a, "B": b, "C": c}

s = []
for i in range(n):
    line = input()
    s.append(line)

def add(a, b):
    nums[a] += 1
    nums[b] -= 1
    ans.append(a)

flag = True

ans = []

for i in range(n):
    a = s[i][0]
    b = s[i][1]

    if nums[a] == 0 and nums[b] == 0:
        print("No")
        flag = False
        break

    if nums[a] == 0:
        add(a, b)
        
    elif nums[b] == 0:
        add(b, a)
        
    else:
        if i != n - 1:
            na = s[i + 1][0]
            nb = s[i + 1][1]

            if (a == na or a == nb):
                add(a, b)

            else:
                add(b, a)

        else:
            add(a, b)
if flag:
    print("Yes")

    for i in ans:
        print(i)


Measured memory_bytes: 16912
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Derangement
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &ps[i]), ps[i]--;

  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (ps[i] == i) {
      if (i < n - 1) swap(ps[i], ps[i + 1]);
      else swap(ps[i - 1], ps[i]);
      cnt++;
    }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;
int main(){
    string s;
    int cnt=700;
    cin>>s;
    if(s[0]=='o')cnt+=100;
    if(s[1]=='o')cnt+=100;
    if(s[2]=='o')cnt+=100;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
// solv_D.cpp :
//

#include <iostream>
#include <map>

using namespace std;

int A[200000];
map <int, long> nA, cA;

int main()
{
	int i, j, k;
	int N;
	long long sum = 0, ans;
	cin >> N;

	for (i = 0; i < N; i++) {
		cin >> A[i];
		nA[A[i]] += 1;
	}

	for (auto itr = nA.begin(); itr != nA.end(); itr++) {
		k = itr->first;
		long n = itr->second;
		if (n > 1) {
			cA[k] = long(n * (n - 1) / 2);
		}
		else {
			cA[k] = 0;
		}
		sum += cA[k];
	}

	for (k = 0; k < N; k++) {
		if (nA[A[k]] > 1) {
			ans = sum - (nA[A[k]] - 1);
		}
		else {
			ans = sum;
		}
		cout << ans << endl;
	}


}


Measured memory_bytes: 18176
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <utility>
#include <algorithm>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <numeric>
#include <list>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
using namespace std;

int cnt[1000000 + 10];

int main(void) {
    int s;
    cin >> s;
    
    rep(i, 1000000 + 10) {
        cnt[i] = 0;
    }
    
    cnt[s]++;
    int ans=1;
    while (1) {
        ans++;
        if (s % 2 == 0) {
            s = s / 2;
        } else {
            s = s * 3 + 1;
        }
        // cout << s << endl;
        if (cnt[s] > 0) {
            break;
        } else {
            cnt[s]++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
using namespace std;

int main()
{
    int n, k;
    int ans = INF;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h), greater<int>());
    rep(i, n - k + 1)
    {
        ans = min(ans, h[i] - h[i + k - 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import deque

INF = float('inf')

H,W=map(int,input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

## '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for i in range(H):
    for j in range(W):
        if grid[i][j]=="#":
            dist[i][j]=0
            black_cells.append((i,j))

while black_cells:
    y,x=black_cells.popleft()#黒マスのスタート地点
    d=dist[y][x]#スタート地点からの距離
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        new_x=x+dx
        new_y=y+dy
        if new_y < 0 or H <= new_y or new_x < 0 or W <= new_x:#範囲からはみ出すとき
            continue
        if dist[new_y][new_x]==-1:
            dist[new_y][new_x]=d+1
            black_cells.append((new_y,new_x))
print(d)


Measured memory_bytes: 87900
using System;
class Program
{
	static void Main(string[] args)
	{
		String[] s = Console.ReadLine().Split(' ');
		int N = int.Parse(s[0]);
		int A = int.Parse(s[1]);
		int B = int.Parse(s[2]);
		
		int total = 0;
		int sum = 0;

		for (int i = 1; i <= N; i++)
		{
			sum = FindSumOfDigits(i);
			if (A <= sum && sum <= B) total = total + i;
		}

		//出力
		Console.WriteLine(total);
	}

　　private static int FindSumOfDigits(int n)
	{
		int sum = 0;

		while (n > 0)
		{
			sum = sum + (n % 10);
			n = n / 10;
		}

		return sum;
	}
}

Measured memory_bytes: 11092
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

type Work = (i64, i64); // A, B

fn main() {
    let n = read::<usize>();
    let mut works: Vec<Work> = Vec::with_capacity(n);
    for _i in 0..n {
        let ab: Vec<i64> = read_vec();
        let a = ab[0];
        let b = ab[1];
        let w: Work = (a, b);
        works.push(w);
    }


    let answer = solve(&mut works);
    let msg = if answer {
        "Yes"
    } else {
        "No"
    };
    println!("{}", msg);
}

fn solve(works: &mut [Work]) -> bool {
    // 1. Sort
    works.sort_by_key(|w|w.1);

    // 2. Check
    let mut total : i64 = 0;
    for w in works {
        total += w.0;
        if total > w.1 {
            return false;
        }
    }
    return true;
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long x=a*c,y=b*d,z=max(a*d,b*c);
  cout<<max(x,max(y,z));
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}

const int N = 200000 + 5;
vector<int> G[N];
int n, c[N], sz[N];
long long T[N], ans[N];

void dfs (int u, int f) {
	long long tmp = T[c[u]]; T[c[u]] = 0;
	sz[u] = 1;
	for (int i = 0; i < (signed)G[u].size(); ++i) if (G[u][i] != f) {
		int v = G[u][i];
		dfs (v, u);
		ans[c[u]] -= 1LL * (sz[v] - T[c[u]]) * ((sz[v] - T[c[u]]) + 1) / 2;
		sz[u] += sz[v];
		T[c[u]] = 0;
	}
	T[c[u]] = tmp + sz[u];
}

int main ()
{
	read (n);
	for (int i = 1; i <= n; ++i) read (c[i]);
	for (int i = 1; i < n; ++i) {
		int x, y; read (x), read (y);
		G[x].push_back (y),
		G[y].push_back (x);
	}
	dfs (1, 0);
	long long alter = 1LL * n * (n + 1) / 2;
	for (int i = 1; i <= n; ++i) printf ("%lld\n", alter + ans[i] - 1LL * (n - T[i]) * (n - T[i] + 1) / 2);
	return 0;
}

















Measured memory_bytes: 38072
//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
#define db double
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
const int maxn=2000+7;
const ll mod=924844033;
ll n,K,sum[maxn],mi[maxn],ans;
ll f[2][maxn][maxn][4],dp[maxn][maxn];

template<typename T>void read(T& aa) {
	aa=0;char cc=getchar();T ff=1;
	while((cc!='-')&&(cc<'0'||cc>'9')) cc=getchar();
	if(cc=='-') ff=-1,cc=getchar();
	while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
	aa*=ff;
}

void get_dp(int n,int o) {
	f[o][0][0][1]=1;
	For(i,0,n-1) For(j,0,i) For(k,0,3) {
		if(!f[o][i][j][k]) continue;
		f[o][i][j][k]%=mod;
		f[o][i+1][j][k>>1]+=f[o][i][j][k];
		if((k&1)==0) f[o][i+1][j+1][k>>1]+=f[o][i][j][k];
		if(i!=n-1) f[o][i+1][j+1][(k>>1)+2]+=f[o][i][j][k];
	}
	For(i,0,n) {
		For(j,1,3) f[o][n][i][0]+=f[o][n][i][j];
		f[o][n][i][0]%=mod;
	}
}

int main() {
	read(n); read(K); int x,y;
	mi[0]=1; For(i,1,n) mi[i]=mi[i-1]*(ll)i%mod;
	For(i,1,K) sum[i]=(n-i)/K+1;
	get_dp(sum[K],0);
	if(sum[1]>sum[K]) get_dp(sum[1],1);
	dp[0][0]=1;
	For(i,1,K) {
		For(j,0,sum[i-1]) if(dp[i-1][j]) {
			x=sum[i]; y=x-sum[K];
			For(k,0,x) dp[i][j+k]+=dp[i-1][j]*f[y][x][k][0]%mod;
		}
		sum[i]+=sum[i-1];
		For(j,0,sum[i]) dp[i][j]%=mod;
	}
	For(i,0,n) dp[K][i]=dp[K][i]*mi[n-i]%mod;
	For(i,0,n) {
		if(i&1) ans+=mod-dp[K][i];
		else ans+=dp[K][i];
	}
	printf("%lld\n",ans%mod);
	return 0;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int h, w; cin >> h >> w;
  char c[h][w];

  rep(i, h) rep(j, w) cin >> c[i][j];

  int ans = 0;

  rep(i, h) rep(j, w) {
    if (c[i][j] == '#') continue;

    int vs[h][w];
    rep(k, h) rep(l, w) vs[k][l] = -1;
    vs[i][j] = 0;

    queue<pii> que;
    que.em(j, i);

    while (!que.empty()) {
      pii v = que.front(); que.pop();
      int x = v.fi, y = v.se;

      rep(k, 4) {
        int nx = x + dx[k], ny = y + dy[k];
        
        if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
        if (vs[ny][nx] != -1 || c[ny][nx] == '#') continue;

        que.em(nx, ny);
        vs[ny][nx] = vs[y][x] + 1;
      }
    }

    rep(k, h) rep(l, w) if (c[k][l] != '#') chmax(ans, vs[k][l]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3664
#include <iostream>
using namespace std;
long long b[3001][3001];

int main() 
{
	int n;
	cin >> n;
	long long a[n + 1];
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	for (int i = 1; i <= n; i++)
	{
		b[i][i] = a[i];
		for (int j = i - 1; j >= 1; j--)
			b[j][i] = max(a[i] - b[j][i - 1], a[j] - b[j + 1][i]);
	}
	
	cout << b[1][n];
}

Measured memory_bytes: 70016
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	long long int c = 1;
	for (int i = 0; i < a; i++)
	{
		c = (c * b)%1000000007;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 3136
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int r, D, x[20];
	cin >>r >> D>>x[0];
	
	for (int i = 1; i <=10; i++) {
		x[i] = r * x[i - 1] - D;
		cout << x[i] << endl;
	}

	
}



Measured memory_bytes: 256