akhauriyash/Code-Regression huggingface dataset:
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int d;
  cin >> d;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(d, vector<int>(26));
  rep(i, d) rep(j, 26) cin >> s[i][j];

  vector<int> last(26, 0);
  rep(i, d) {
    int res = -inf, idx = -1;
    rep(j, 26) {
      if (s[i][j] > res) {
        res = s[i][j], idx = j;
      }
      else if (s[i][j] == res) {
        if (last[idx] > last[j]) {
          res = s[i][j], idx = j;
        }
      }
    }
    cout << idx + 1 << '\n';
  }

  




  
  return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    
    int n_b[N + 1];
    n_b[0] = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '#') n_b[i + 1] = n_b[i] + 1;
        else n_b[i + 1] = n_b[i];
    }
    
    vector<int> v = {};
    for (int i = 0; i < N + 1; i++) {
        v.push_back(n_b[i] + N - i - (n_b[N] - n_b[i]));
    }
    
    sort(v.begin(), v.end());
    cout << v[0] << endl;
}

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

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

int main()
{
    ull M, D;
    cin >> M >> D;
    
    ll ans = 0;
    for (ull m = 1; m <= M; ++m){
        for(ull d = 1; d <= D; ++d){
            auto d10 = d / 10;
            auto d1 = d % 10;
            if(d1 >= 2 && d10 >= 2 && d1 * d10 == m){
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

//#define DEBUG

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a, b, c;
	cin >> a >> b >> c;
	cout << a*b/2;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int k ;
    cin >> k ;
    if (k%2==0)
    {
        cout<<(k/2)*(k/2);
    }
    else
    {
        cout<<(k/2)*(k/2+1);
    }




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  long long int K;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  vector<int> point(N);
  for (int i = 0; i < Q; i++){
    cin >> A.at(i);
    point.at(A.at(i)-1)++;
  }
  for (int i = 0; i < N; i++){
    if(K + point.at(i) - Q > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>

int main(int argc, char** argv)
{
    int N, D;
    std::cin >> N >> D;

    int a = 2 * D + 1;
    int ans = N / a;
    if (N%a!=0) {
        ans++;
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0)break;
		int ans=0;
		vector<int> a,sum;
		a.push_back(0);
		for(int i=1;i<=n;i++){
			int s;
			cin>>s;
			a.push_back(s);
		}
		sort(a.begin(),a.end());
		for(int i=0;i<=n;i++){
			for(int j=i;j<=n;j++){
				if(a[i]+a[j]<=m)sum.push_back(a[i]+a[j]);
			}
		}
		sort(sum.begin(),sum.end());
		int suml=sum.size()-1;
		for(int i=0;i<=suml;i++){
			while(sum[i]+sum[suml]>m)suml--;
			if(ans<sum[i]+sum[suml])ans=sum[i]+sum[suml];
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 5040
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> x(n);
	for(int i = 0; i < n; ++i){ cin >> x[i]; }
	vector<ll> t(n);
	for(int i = 0; i < n; ++i){ cin >> t[i]; }
	vector<bool> open(n, false), close(n, false);
	ll answer = 2 * m;
	for(int i = 0; i < n; ++i){
		const ll left = x[i], right = m - x[i];
		const ll k = (t[i] + 2 * m - 1) / (2 * m);
		answer += k * (2 * m);
		const ll rem = t[i] % (2 * m);
		if(0 < rem && rem <= left * 2){ open[i] = true; }
		if(0 < rem && rem <= right * 2){ close[i] = true; }
	}
	int depth = 0, selectable = 0;
	for(int i = 0; i + 1 < n; ++i){
		if(depth > 0 && close[i]){
			if(open[i]){ ++selectable; }
			answer -= 2 * m;
			--depth;
		}else if(!open[i] && close[i]){
			if(selectable > 0){
				--selectable;
				++depth;
			}
		}else if(open[i]){
			++depth;
		}
	}
	if(close.back()){
		answer -= 2 * m;
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 5088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> vvc;
  vvc=vector<vector<char>>(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>vvc[i][j];
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<W;k++){
        cout<<vvc.at(i).at(k);
      }
      cout<<endl;
    } 
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    i64 K, S = 0;
    cin >> N >> K;
    vector<i64> A(N);
    for(auto &x : A) {
        cin >> x;
        S += x;
    }
    vector<i64> factor;
    for(i64 x = 1; x <= sqrt(S) + 100; x++) {
        if(S % x == 0) {
            factor.push_back(x);
            factor.push_back(S / x);
        }
    }
    i64 ans = -1;
    for(auto x : factor) {
        vector<i64> R;
        for (int i = 0; i < N; i++) {
            i64 tmp = A[i] % x;
            if(tmp) R.push_back(tmp);
        }
        i64 M = R.size();
        vector<i64> acc_p(M, 0), acc_n(M, 0);
        sort(WHOLE(R));
        for(int i = 0; i < M; i++) {
            acc_p[i] = (x - R[i]) % x;
            acc_n[i] = R[i];
            if(i) {
                acc_p[i] += acc_p[i - 1];
                acc_n[i] += acc_n[i - 1];
            }
        }
        for(int i = -1; i < M; i++) {
            i64 p = 0, n = 0;
            if(M > 0) n += acc_p[M - 1];
            if(i >= 0) {
                p += acc_n[i];
                n -= acc_p[i];
            }
            if((p - n) % x == 0 && p <= K && n <= K) {
                ans = max(ans, x);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int K,X;
    cin>>K>>X;
    if(K*500>=X){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll n, ma, mb;
  cin >> n >> ma >> mb;
  vll as(n), bs(n), cs(n);

  rep(i, n) cin >> as[i] >> bs[i] >> cs[i];

  ll n1 = n / 2;
  ll n2 = n - n1;

  vll lol, clol;
  rep(s, 1 << n1){
    if (s == 0) continue;
    ll sig = 0, tau = 0, csum = 0;
    rep(j, n1) { if (s >> j & 1) {
        sig += as[j], tau += bs[j], csum += cs[j];
      }
    }
    lol.push_back(mb*sig - ma*tau);
    clol.push_back(csum);
  }

  map<ll, ll> mp;
  rep(s, 1 << n2) {
    if (s == 0) continue;
    ll sig = 0, tau = 0, csum = 0;
    rep(j, n2) { if (s >> j & 1) {
        sig += as[n1 + j], tau += bs[n1 + j], csum += cs[n1 + j];
      }
    }
    ll etry = mb * sig - ma * tau;
    if (mp.count(etry) == 0) {
      mp[etry] = csum;
    } else {
      chmin(mp[etry], csum);
    }
  }

  ll ans = INF;
  ll ncan = lol.size();
  rep(i,ncan){
    if(lol[i] == 0) chmin(ans, clol[i]);
    if(mp.count(-lol[i]) != 0) {
      chmin(ans, clol[i] + mp[-lol[i]]);
    }
  }
  if (mp.count(0) != 0) chmin(ans, mp[0]);

  if (ans == INF) ans = -1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16852
#include <iostream>
#include <cstdint>

int N;
int64_t ans = 0;

int digits(int N) {
    int ans = 1;
    while (N/10 != 0) {
        ans++;
        N /= 10;
    }
    return ans;
}

bool check(int N) {
    int digit = digits(N);
    bool seven = false;
    bool five = false;
    bool three = false;
    for (int i=0; i<digit; ++i) {
        int temp = N % 10;
        if (temp==3) three = true;
        else if (temp==5) five = true;
        else if (temp==7) seven = true;
        else return false;
        N /= 10;
    }
    return seven && five && three;
}

void dfs(int64_t n) {
    //std::cout << n << std::endl;
    if (n > N) return;
    
    if (check(n)) ans++;
    
    dfs(10*n + 3);
    dfs(10*n + 5);
    dfs(10*n + 7);
    return;
}

int main() {
    std::cin >> N;
    
    dfs(0);
    
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

bool coprime(int a,int b){
	for(int t;b;t=a,a=b,b=t)	a%=b;
	return a==1;
}

int capa[1002][1002],flow[1002][1002],src,snk,sz;

bool findAugPath(int u,int *path,int &len,bool *visited,int i=0){
	path[i]=u;
	visited[u]=true;
	if(u==snk){ len=i+1; return true; }
	for(int v=0;v<sz;v++){
		if(!visited[v] && capa[u][v]-flow[u][v]>0){
			bool b=findAugPath(v,path,len,visited,i+1);
			if(b)	return true;
		}
	}
	return false;
}

int main(){
	for(int m,n;scanf("%d%d",&m,&n),m;){
		static int blue[500],red[500];
		for(int i=0;i<m;i++)	scanf("%d",blue+i);
		for(int j=0;j<n;j++)	scanf("%d",red+j);

		src=0,snk=m+n+1,sz=m+n+2;
		for(int i=0;i<sz;i++)for(int j=0;j<sz;j++){
			capa[i][j]=0;
			flow[i][j]=0;
		}

		for(int i=0;i<m;i++)	capa[src][1+i]=1;
		for(int i=0;i<m;i++)for(int j=0;j<n;j++){
			if(!coprime(blue[i],red[j]))	capa[1+i][1+m+j]=1;
		}
		for(int j=0;j<n;j++)	capa[1+m+j][snk]=1;

		static int path[1002],len;
		static bool visited[1002];
		while(1){
			for(int u=0;u<sz;u++)	visited[u]=false;
			if(!findAugPath(src,path,len,visited))	break;
			for(int i=1,u=path[0];i<len;i++){
				int v=path[i];
				flow[u][v]++;
				flow[v][u]--;
				u=v;
			}
		}

		int maxmatch=0;
		for(int i=0;i<m;i++)for(int j=0;j<n;j++){
			if(flow[1+i][1+m+j]==1)	maxmatch++;
		}
		printf("%d\n",maxmatch);
	}

	return 0;
}

Measured memory_bytes: 8640
#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 reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
vector<int> memo;
vector<ll> vec;
ll n;

ll M = 1e6+5;
int main()
{
  
  cin >> n;
  vec.resize(n);
  memo.resize(M, 0);
  for(ll i = 0; i < n; i++) {
    cin >> vec.at(i);
    memo.at(vec.at(i))++;
  }

  bool is_pairwise = true;
  for (int i = 2; i < M; i++) {
    int cnt = 0;
    for (int j = i; j < M; j += i) {
      if (memo.at(j)) cnt += memo.at(j);
    }
    if (cnt > 1) {
      is_pairwise = false;
      break;
    }
  }
  if (is_pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll g = 0;
  rep(i,n) g = gcd(g, vec.at(i));
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;

  return 0;
}

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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int A,B,C,D,E,K;

bool solve(){
    if(abs(A-B) > K) return false;
    else if(abs(A-B) > K) return false;
    else if(abs(A-C) > K) return false;
    else if(abs(A-D) > K) return false;
    else if(abs(A-E) > K) return false;
    else if(abs(B-C) > K) return false;
    else if(abs(B-D) > K) return false;
    else if(abs(B-E) > K) return false;
    else if(abs(C-D) > K) return false;
    else if(abs(C-E) > K) return false;
    else if(abs(D-E) > K) return false;

    return true;
}

int main(){
    cin >> A >> B >> C >> D >> E >> K;

    if(solve()) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


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

int main() {
	vector<int> v;
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		int curr;
		cin >> curr;
		v.push_back(curr);
	}
	sort(v.begin(), v.end());
	int minDiff = 1000000000;
	for(int i = 0; i < n-k+1; i++) {
		int diff = v[i+(k-1)] - v[i];
		minDiff = min(minDiff, diff);
	}

	cout << minDiff;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  long long int N;
  long long int T[111];
  long long int i;
  long long int g,l;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> T[i];
  if(N>1){
  g = __gcd(T[0],T[1]);
  l = T[0] / g *T[1];
  for(i=0;i<=N-2;i++){
    g = __gcd(l,T[i+1]);
    l =  T[i+1] / g * l;
    }
  cout << l << endl;
  }
  else cout << T[0] << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000000
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

ll max(ll a, ll b){
  if(a > b) return a;
  return b;
}

int main(){
  ll N;
  cin >> N;
  ll A[N];
  REP(i, N) cin >> A[i];
  ll cnt_sel[N][3], cnt_skip[N][3];
  cnt_sel[0][0] = A[0];
  cnt_sel[0][1] = -INF;
  cnt_sel[0][2] = -INF;
  cnt_skip[0][0] = -INF;
  cnt_skip[0][1] = 0;
  cnt_skip[0][2] = -INF;
  REP(i, N - 1){
    cnt_sel[i + 1][0] = cnt_skip[i][0] + A[i + 1];
    cnt_sel[i + 1][1] = cnt_skip[i][1] + A[i + 1];
    cnt_sel[i + 1][2] = cnt_skip[i][2] + A[i + 1];
    cnt_skip[i + 1][0] = cnt_sel[i][0];
    cnt_skip[i + 1][1] = max(cnt_sel[i][1], cnt_skip[i][0]);
    cnt_skip[i + 1][2] = max(cnt_sel[i][2], cnt_skip[i][1]);
    // cout << cnt_sel[i + 1][0] << " "
    // 	 << cnt_sel[i + 1][1] << " "
    // 	 << cnt_sel[i + 1][2] << " "
    // 	 << cnt_skip[i + 1][0] << " "
    // 	 << cnt_skip[i + 1][1] << " "
    // 	 << cnt_skip[i + 1][2] << endl;
  }
  if(N % 2){ // 奇数
    cout << max(cnt_sel[N - 1][2], cnt_skip[N - 1][1]) << endl;
  }else{
    cout << max(cnt_sel[N - 1][1], cnt_skip[N - 1][0]) << endl;
  }
  return 0;
}


Measured memory_bytes: 14088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  if(a%2 == 0 || b%2 == 0) {
    cout << "Even" << endl;
  }
  
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;

int dist[1001][1001];

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

int main(){
  
  
  
  int H, W;cin>>H>>W;
  char A[H][W];
  queue<ii> que;
  
  for (int i=0;i<H;++i){
    for (int j=0;j<W;++j){
      dist[i][j]=2001;
    }
  }
  
  for (int i=0;i<H;++i){
    for (int j=0;j<W;++j){
      cin>>A[i][j];
      if (A[i][j]=='#') {que.push({i,j});dist[i][j]=0;}
    }
  }
  
  
  while(!que.empty()){
    ii q=que.front();que.pop();
    int y=q.first, x=q.second;
    for (int k=0;k<4;++k){
      int ny=y+dy[k], nx=x+dx[k];
      if(nx>=0&&nx<W&&ny>=0&&ny<H){
        if (A[ny][nx]!='#'){que.push({ny, nx}); A[ny][nx]='#';}
        dist[ny][nx]=min(dist[ny][nx], dist[y][x]+1);
      }
    }
  }
  
  
  int ans=0;

  for (int i=0;i<H;++i){
    for (int j=0;j<W;++j){
      ans=max(ans, dist[i][j]);
    }
  }

  cout << ans << endl;
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



ll n,k;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>k;

    if (n%k==0) out(0);

    n%=k;
    ll ans=min(n,k-n);
    out(ans);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

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

    vector<int> r;
    r.push_back(0);
    for(int i = 1; i < n; i++){
        if (s[i] != s[i-1]) r.push_back(i);
    }

    // rep(i, r.size()) cout << r[i] << endl;
    int ans = 0;
    int m = r.size();
    // rep(i, m) cout << r[i] << " ";
    // cout << endl;
    rep(i, r.size()){
        int tmp, cnt;
        if (s[r[i]] == '0'){
            if (2 * k + i > m - 1) tmp = n;
            else tmp = r[2 * k + i];
            cnt = tmp - r[i];
            // cout << cnt << endl;
        }
        else {
            if (2 * k + i + 1 > m - 1) tmp = n;
            else tmp = r[2 * k + i + 1];
            cnt = tmp - r[i];
            // cout << cnt << endl;
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>

int main(void)
{
	int i = 1;
	int x = 0;

	while (1){

		scanf("%d", &x);
		if (x == 0)
		{
			break;
		}
		printf("Case %d: %d", i++, x);
		putchar('\n');
	}


	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n, k; scanf("%d%d", &n, &k);
	std::string s; cin >> s;

	int ans = 0;
	for(int loop = 0; loop < 2; loop++) {
		std::vector<std::pair<char, int>> vec;
		for(int i = 0; i < s.size(); i++) {
			if(vec.empty() or s[i] != vec.back().first) vec.push_back({s[i], 1});
			else vec.back().second++;
		}

		if(vec.size() == 1) {
			ans = std::max(ans, vec[0].second - 1);
			continue;
		}

		int tmp = 0;
		std::vector<int> latte;
		for(int i = 0; i < vec.size(); i++) tmp += vec[i].second - 1;
		for(int i = 0; i < vec.size(); i++) {
			if(vec[i].first == 'L') continue;

			if(i == vec.size() - 1 or i == 0) latte.push_back(1);
			else latte.push_back(2);
		}
		sort(begin(latte), end(latte)); reverse(begin(latte), end(latte));

		for(int i = 0; i < std::min(k, (int)latte.size()); i++) tmp += latte[i];
		ans = std::max(ans, tmp);

		for(auto& c: s) {
			if(c == 'L') c = 'R';
			else c = 'L';
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2276
import itertools
N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

X = list(range(1, N + 1))
Y = list(itertools.permutations(X))

a = Y.index(tuple(P)) + 1

b = Y.index(tuple(Q)) + 1

if a > b:
    print(a - b)
else:
    print(b - a)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	a = -1000<=a<=1000;
	b = -1000<=b<=1000;
	cin>>a>>b;
	if(a>b)
		cout<<"a > b"<<endl;
		else 
		{
		if(a == b)
		cout<<"a == b"<<endl;
		else
		cout<<"a < b"<<endl;	
		}
		return 0;	
}


Measured memory_bytes: 3108
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int c=1000000;
bool prime[c+1];
void makeprime(){
	rep1(i,c) prime[i]=1;
	prime[1]=0;
	for(int i=2;i*i<=c;i++) if(prime[i]) for(int j=2;j*i<=c;j++) prime[j*i]=0;
}
int main(){
	makeprime();
	while(true){
		int a,d,n;
		scanf("%d%d%d",&a,&d,&n);
		if(n==0) break;
		for(;;a+=d){
			if(prime[a]) n--;
			if(n==0){
				printf("%d\n",a);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1988
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <functional>
#include <cassert>
#define MOD 1000000007
#define SIZE 1005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

bool pr[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	ll ret=1;
	for(int i=2;i<=n;i++)
	{
		if(!pr[i])
		{
			for(int j=2*i;j<=n;j+=i) pr[j]=true;
			int sum=0,now=n;
			while(now>0)
			{
				sum+=now/i;
				now/=i;
			}
			ret=ret*(ll) (sum+1)%MOD;
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int N;
long M,dp[6003][12001];
main()
{
	cin>>N>>M;
	dp[0][3*N]=1;
	for(int i=0;i<3*N;i++)for(int j=0;j<=6*N;j++)
	{
		if(dp[i][j]==0)continue;
		(dp[i+1][j-1]+=dp[i][j])%=M;
		(dp[i+2][j+1]+=dp[i][j]*(i+1))%=M;
		(dp[i+3][j]+=dp[i][j]*(i+1)%M*(i+2))%=M;
	}
	long ans=0;
	for(int j=0;j<=3*N;j++)ans+=dp[3*N][j];
	cout<<ans%M<<endl;
}

Measured memory_bytes: 560768
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if (i + j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7004
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	string a, b, c;
	cin>>a>>b>>c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll dp[210][100010];

int main(){
    int N,X; cin >> N >> X;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    sort(a.rbegin(),a.rend());
    dp[0][X] = 1;
    rep(i,N)rep(j,X+1){
        dp[i+1][j%a[i]] += dp[i][j];
        dp[i+1][j%a[i]] %= MOD;
        dp[i+1][j] += (N-i-1)*dp[i][j]%MOD;
        dp[i+1][j] %= MOD;
    }
    ll ans = 0;
    rep(i,X+1){
        ans += dp[N][i]*i%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 157184
N=int(input())
A=0
list=[]
for i in range(N):
    date=input().split(" ")
    if date[0]==date[1]:
        A += 1
    else:
        list.append(A)
        A=0
list.append(A)
list=sorted(list)
if list[-1]>=3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)

int n, m;
int ike[11][11];

int main() {
	for (; cin >> n >> m && n;) {
		rep(i, 0, n)rep(j, 0, m) {
			cin >> ike[i][j];
		}
		int ans = 0;
		using P = pair<int, int>;
		rep(k, 0, 10) {
			vector<set<P>> st(n);
			vector<map<P, int>> area(n);
			rep(i, 0, n) {
				int l, r;
				l = 0, r = 0;
				int a = 0;
				rep(j, 0, m) {
					if (ike[i][j] <= k) {
						r++;
						a += k + 1 - ike[i][j];
					}
					else {
						if (ike[i][l] <= k) {
							st[i].emplace(l, r);
							area[i][P(l, r)] = a;
						}
						a = 0;
						l = j + 1;
						r = j + 1;
					}
				}
				if (l != m) {
					st[i].emplace(l, r);
					area[i][P(l, r)] = a;
				}
			}
			rep(i, 1, n - 1) {
				//cout << " i " << i << endl;
				for (auto it = st[i].begin(); it != st[i].end(); it++) {
					int l, r; tie(l, r) = *it;
					P p = *it;
					if (l == 0 || r == m)continue;
					int tmp = area[i][p];
					// ???????????????
					{
						int ni = i - 1;
						if (st[ni].size() != 0) {
							auto nit = st[ni].lower_bound(p);

							// end ?????´???
							if (nit == st[ni].end()) {
								auto npit = nit; npit--;

								int nl, nr;
								tie(nl, nr) = *npit;
								if (nr < l) {
								}
								else {
									continue;
								}
							}
							else {
								P np = *nit;
								int nl, nr;
								tie(nl, nr) = np;

								if (p == np)
									continue;
								else if (nl <= r) {
									continue;
								}
								else if (r < nl) {
									if (nit == st[ni].begin()) {
									}
									else {
										auto npit = nit; npit--;
										tie(nl, nr) = *npit;
										if (nr < l) {
										}
										else {
											continue;
										}
									}
								}
							}
						}

					}
					rep(ni, i + 1, n) {
						if (st[ni].size() == 0) {
							break;
						}

						auto nit = st[ni].lower_bound(p);

						// end ?????´???
						if (nit == st[ni].end()) {
							auto npit = nit; npit--;

							int nl, nr;
							tie(nl, nr) = *npit;
							if (nr < l) {
								break;
							}
							else {
								tmp = 0;
								break;
							}
						}
						else {
							P np = *nit;
							int nl, nr;
							tie(nl, nr) = np;

							if (p == np) {
								if (ni == n - 1) {
									tmp = 0;
									break;
								}
								tmp += area[ni][np];
							}
							else if (nl <= r) {
								tmp = 0;
								break;
							}
							else if (r < nl) {
								if (nit == st[ni].begin()) {
									// ok
									break;
								}
								auto npit = nit; npit--;
								tie(nl, nr) = *npit;
								if (nr < l) {
									// ok
									break;
								}
								else {
									tmp = 0;
									break;
								}
							}
						}
					}
					ans = max(ans, tmp);
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main() {
    int i, j, cnt;
    string s, p;

    cin >> s >> p;
    for(i=0; i<s.length(); ++i) {
        cnt = 0;
        for(j=0; j<p.length(); ++j) {
            if(s[(i+j)%s.length()] == p[j]) ++cnt;
        }
        if(cnt == p.length()) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  long long N, A, B, C, D, E, F;
  cin >> N >> A >> B >> C >> D >> E;

  F = min({A, B, C, D, E});

  cout << (N + F - 1) / F + 4 << endl;
}

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

int main(){
    int r, g, b, n; cin >> r >> g >> b >> n;
    int max_r = n / r + 1;
    int max_g = n / g + 1;
    int ans = 0;
    for(int i=0; i<max_r; i++){
        for(int j=0; j<max_g; j++){
            int lest = n - r * i - g * j;
            if(lest >= 0 && lest%b == 0){
                ans++;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
//Sha3ban_El-Bay
#include<bits/stdc++.h>
using namespace std ;
//======================================================
#define El_Bay ios_base::sync_with_stdio(false);cin.tie(NULL);
#define forn(i,n)  for (int i = 0; i < (int)(n); ++i)
#define for1(i,n)  for (int i = 1; i <=(int)(n); ++i)
#define all(v)     (v).begin(),(v).end()
#define ull        unsigned long long
#define PI         3.14159265359
#define ll         long long
#define sz(v)	   v.size()
#define pb         push_back
#define pp         pop_back
#define S          second
#define bgn        begin
#define F          first
#define N          int(2e5+5)
#define	MOD        int(1e9+7)
#define inf        int(1e18)
//======================================================
int dx[] = { 0,  0, 1, -1 ,  1,  -1,  1,  -1 };
int dy[] = { 1, -1, 0,  0 , -1,   1,  1,  -1 };
//======================================================
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll a, ll b, ll ret = 1LL) {
	while (b--) ret = (ret * a);
	return ret;}
//======================================================
int n,m;
string grid[1005];
int dp[1005][1005];

bool valid(int x , int y)
{ return x<n && x>=0 && y>=0 && y<=m && grid[x][y]!='#';}

int solve(int x , int y)
{
	if(!valid(x , y)) return 0;
	if(x==n-1 && y==m-1) return 1;
	if(dp[x][y]!=-1) return dp[x][y];
	return dp[x][y] = (solve(x,y+1) + solve(x+1,y)) % MOD;

}

int main()
{
	El_Bay

	cin >> n >> m ;
	for(int i=0 ; i<n ; i++)
		cin >> grid[i];

	memset(dp,-1,sizeof dp);

	cout << solve(0,0);

	return 0;
}


Measured memory_bytes: 8748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			String text = "";
			int mul = 0;
			int i = 0;
			for (i = 0; i < b; i++) {
				mul = mul + a;
				if (mul % b == c) {
					text = "YES";
					break;
				}else {
					text = "NO";
				}
			}
			System.out.println(text);
		}
	}
}

Measured memory_bytes: 21844
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int C = line[2];
            int D = line[3];
            Console.WriteLine(A * B == C * D ? A * B : Math.Max(A * B, C * D));
        }
    }
}

Measured memory_bytes: 13140
function Main(input) {
    var S = parseInt(input);
    var h = parseInt(S / 3600); //秒を時間へ　1時間=60分　60分=3600秒
    var x = S % 3600;
    var m = parseInt( x / 60);
    var z = x % 60;
    var s = z; 

    var answer = h + ":" + m + ":" + s;
    console.log(answer);
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug() {
    var input = document.getElementById("input").value;
    Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15132
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	if(n<=k){
		cout << n*x << endl;
	}
	else{
		cout << k*x+(n-k)*y << endl;
	}

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if  ((x - r >= 0) && (x + r <= W)&& (y - r >= 0) && (y + r <= H))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}


Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  int H, W, K, count = 0, totalb = 0;
  string s;
  cin >> H >> W >> K;
  vector<vector<int>> data(H, vector<int>(W));
  for(int i = 0; i<H; i++){
    cin >> s;
    for(int j  = 0; j<W; j++){
      if (s[j] == '.') data.at(i).at(j) = 0;
      if (s[j] == '#') {
        data.at(i).at(j) = 1;
        totalb++;
      }
    }
  }
  vector<vector<int>> c(pow(2, H), vector<int>(pow(2, W)));
  for (int a = 0; a<pow(2, H); a++){
    vector<vector<int>> v = data;
    int t = a, countt = 0;
    for (int x = 0; x<H; x++){
      if (t % 2 == 1) {
        for (int y = 0; y<W; y++){
          if (v.at(x).at(y) == 1) countt++;
          v.at(x).at(y) = 0;
        }
      }
      t = t/2;
    }
    
    for (int b = 0; b<pow(2, W); b++){
      vector<vector<int>> vt = v;
      int t = b, counttt = countt;
      for (int y = 0; y<W; y++){
        if (t % 2 == 1) {
          for (int x = 0; x<H; x++){
            if (vt.at(x).at(y) == 1) counttt++;
            vt.at(x).at(y) = 0;
          }
        }
        t = t/2;
      }
    if (totalb - K == counttt) count++;
    }
  }


  cout << count << endl;

  return 0;
}

Measured memory_bytes: 4068
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define PAIR(a,b) if(c==a) cout << b << endl


int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin

  char c;
  cin >> c;

  PAIR('A','T');
  PAIR('T','A');
  PAIR('G','C');
  PAIR('C','G');
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn f(x: i64) -> i64 {
    if x <= 0 {
        return 0;
    }
    if x == 1 {
        return 1;
    }
    if x == 2 {
        return 3;
    }
    if x == 3 {
        return 0;
    }
    let mut res: i64 = 0;
    let mut y: i64 = x;
    let mut base: i64 = 1;
    while 2 * base <= x {
        base *= 2;
    }

    if (x - base) % 2 == 0 {
        return base ^ f(x - base);
    }
    return f(x - base);
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let A: i64 = iter.next().unwrap().parse().unwrap();
    let B: i64 = iter.next().unwrap().parse().unwrap();
    let mut result: i64 = 0;
    result = f(B) ^ f(A - 1);
    println!("{}", result);
}


Measured memory_bytes: 4352
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

@SuppressWarnings("unchecked")
public class Main {
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[] in = new int[26];
			int[] out = new int[26];
			List<Integer>[] node = new List[26];
			for (int i = 0; i < node.length; i++) {
				node[i]=new LinkedList<Integer>();
			}
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				out[s.charAt(0)-'a']++;
				in[s.charAt(s.length()-1)-'a']++;
				node[s.charAt(0)-'a'].add(s.charAt(s.length()-1)-'a');
			}
			boolean f = true;
			int s = 0,t=0,same=0;
			for (int i = 0; i < in.length; i++) {
				if(in[i]!=out[i]){
					f=false;
				}
			}
			boolean connected = true;
			isVisited=new boolean[26];
			for (int i = 0; i < node.length; i++) {
				if(in[i]>=1){
					isConnected(i,node);
					break;
				}
			}
			
			for (int i = 0; i < node.length; i++) {
				if(in[i]>=1 && isVisited[i]==false){
					connected=false;
				}
			}
			if(f&&connected){
				System.out.println("OK");
			} else {
				System.out.println("NG");
			}
		}
	}
	static boolean[] isVisited;
	static void isConnected(int cur,List<Integer>[]node){
		if(isVisited[cur])return ;
		isVisited[cur]=true;
		for(Integer next:node[cur]){
			if(isVisited[next])continue;
			isConnected(next,node);
		}
		
	}
}

Measured memory_bytes: 49576
n,m = map(int,input().split())
a = [0]*(n+2)
for _ in range(m):
    a[int(input())] = -1

if n == 1:
    print(1)
elif n == 2:
    if a[1] == -1:
        print(1)
    else:
        print(2)
else:
    if a[1] == -1:
        b1 = 0
    else:
        b1 = 1
    if a[2] == -1:
        b2 = 0
    else:
        b2 = b1+1

    b3 = b1 + b2

    for i in range(3,n+1):
        if a[i] == -1:
            b3 = 0
        else:
            b3 = b1+b2
        if b3 > 1000000007:
            b3 = b3 % 1000000007
        b1 = b2
        b2 = b3
        if b1==b2==0:
            break

    print(b3)

Measured memory_bytes: 3956
# coding: utf-8
def match(ofs_x, ofs_y, li_A, li_B):
    for a, b in zip(li_A[ofs_y:], li_B):
        if a[ofs_x:ofs_x + M] != b:
            return False
    return True

N, M = map(int, input().split())
li_A = [input() for _ in range(N)]
li_B = [input() for _ in range(M)]

for y in range(N-M+1):
    for x in range(N-M+1):
        if match(x, y, li_A, li_B):
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;


int main() {
	int n; cin >> n;
	vector<double> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i, n - 1) {
		a[i + 1] = (a[i] + a[i + 1]) / 2;
	}
	cout << setprecision(10) << fixed << a[n - 1] << endl;

}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

bool dfs(int from, int to, int prev, vector<vector<int>> &tos, vector<int> &route) {

    if (from == to) {
        route.push_back(from);
        return true;
    }
    for (int i : tos[from]) {
        if (i == prev) continue;
        bool b = dfs(i, to, from, tos, route);
        if (b) {
            route.push_back(from);
            return true;
        }
    }
    return false;
}

int dfs2(int from, int prev, vector<vector<int>> &tos, int depth) {

    int ma = depth;
    for (int i : tos[from]) {
        if (i == prev) continue;
        int d = dfs2(i, from, tos, depth + 1);
        cmax(ma, d);
    }
    return ma;
}

int main() {

    int n, u, v;
    cin >> n >> u >> v;
    u--;
    v--;
    vector<vector<int>> tos(n);

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tos[a].push_back(b);
        tos[b].push_back(a);
    }
    vector<int> route;
    dfs(v, u, -1, tos, route);

    int border = route.size() / 2 - 1;
    int root = route[border];
    int prev = route[border + 1];
    int depth = dfs2(root, prev, tos, 0);
    int oe = route.size() % 2 == 0 ? 0 : 1;
    cout << depth + border + oe << endl;

}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	if(n%1000==0){
		cout<<0<<endl;
	}
	
	else{
		cout<<((n/1000)+1)*1000-n<<endl;
	}
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 + 10, MOD = 1e9 + 7;



int main()
{
    fastInp;

    ll n;
    cin >> n;
    vector<ll> vec(n);
    ll cnt = 0;
    for (int i= 0; i < n; i++) {
        cin >> vec[i];
        if (i % 2 == 0 && vec[i] % 2 == 1) cnt++;
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 998244353;
array<Int, 1000001> INV;
int main() {
    INV[1] = 1;
    for (int i = 2; i <= 1000000; i++) {
        INV[i] = MOD - INV[MOD % i] * (MOD / i) % MOD;
    }
    int N; cin >> N;
    vector<Int> B(1000001), C(1000001);
    for (int i = 0; i < N; i++) {
        int A; cin >> A; B[A]++;
    }
    Int ans = 0;
    for (Int i = 1; i <= 1000000; i++) {
        C[i] = (C[i] + INV[i]) % MOD;
        Int t1 = i * B[i], t2 = i * i % MOD * B[i];
        for (Int j = i + i; j <= 1000000; j += i) {
            t1 += j * B[j], t2 += j * j % MOD * B[j];
            C[j] = (C[j] + MOD - C[i]) % MOD;
        }
        t1 %= MOD, t2 %= MOD;
        ans += C[i] * (t1 * t1 % MOD - t2 + MOD) % MOD * INV[2];
        ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 23680
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
s=0
amari=[a%10,b%10,c%10,d%10,e%10]
nokori=list((10-amari[i])%10 for i in range(5))
maxi=max(nokori)
dish=[a,b,c,d,e]
for i in range(5):
  if dish[i]%10==0:
    s=s+dish[i]
  else:
    s=s+dish[i]+10-dish[i]%10
if maxi==0:
  print(s)
else:
  print(s-maxi)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
signed main() {
	int n;
	cin >> n;
	cout << (n + 1) / 2 << endl;
	ggr
}


Measured memory_bytes: 256
n, m = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) >= 2:
    ans = 0
elif abs(n - m) == 1:
    if m > n:
        m, n = n, m
    c = 1
    for i in range(1, n):
        c *= i
        c %= mod
    l = (c * n) % mod
    ans = c * l % mod
else:
    c = 1
    for i in range(1, n + 1):
        c *= i
        c %= mod
    ans = (c * c * 2) % mod
print(ans)

Measured memory_bytes: 3064