akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define max(p,q)((p)>(q)?(p):(q))

int dp[10010];//dp[i]=i本のマッチを使って作れる最大桁数
int a[10];
int c[10]={0,2,5,5,4,5,6,3,7,6};
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int t;
		scanf("%d",&t);
		a[t]++;
	}
	dp[0]=1;
	for(int i=0;i<n;i++)if(dp[i]){
		//配るDP
		for(int j=0;j<10;j++)if(a[j]){
			dp[i+c[j]]=max(dp[i+c[j]],dp[i]+1);
		}
	}
	while(n){
		for(int i=9;i>=1;i--)if(a[i]&&n>=c[i]){
			if(dp[n-c[i]]+1==dp[n]){
				putchar('0'+i);
				n-=c[i];
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
//#define int long long
#define INF 10000000
using namespace std;
int main(){
    int N,M;
    while(1){
        cin >> N >> M;
        int a[1010]={};
        int record[M+10][1300]={};
        if(N == 0 && M== 0) break;
        int r;
        cin >> r;
        rep(i,r){
            int t,n,m,s;
            cin >> t >> n >> m >> s;
            if(a[n] == 0) a[n] = t;
            else {
                for(int j=a[n]; j<t; j++) record[m][j] = 1;
                a[n] = 0;
            }
        }
        /*rep(i,10){
            cout << a[i] << " ";
        }
        cout << endl;
        rep(i,10){
            for(int j=770; j<=880; j++) cout << record[i][j] << " ";
            cout << endl;
        }*/
        int q;
        cin >> q;
        rep(i,q){
            int s,e,me;
            cin >> s >> e >> me;
            int cnt = 0;
            for(int j=s; j<e; j++) cnt += record[me][j];
            cout << cnt << endl;
        }
    }
    return 0;
}
/*int main(){
    int N,M;
    while(1){
        cin >> N >> M;
        if(N == 0 && M== 0) break;
        int r;
        cin >> r;
        int record[N][M][r]={};
        int t[r],n[r],m[r],s[r];
        rep(i,r){
            cin >> t[i] >> n[i] >> m[i] >> s[i];
        }
        int q,ts,te,me;
        cin >> q;
        rep(i,q){
            cin >> ts >> te >> me;
            int ans = 0,computer;
            int tmp = ts;
            bool first = false;
            rep(j,r){
                if(m[j] == me && t[j] >= ts && t[j] <= te) {
                    if(s[j] == 0 && first == false){
                        ans += t[j] - tmp;
                        tmp = t[j];
                    }
                    else if (s[j] == 1 && first == false) {
                        first == true;
                        computer = n[j];
                        tmp = t[j];
                    }
                    else if(s[j] == 0 && first == true && computer == n[j]){
                        if(comuputer == n[j]) {
                            ans += t[j] - tmp;
                            tmp = t[j];
                        }
                        else {
                            for(int k=j; k>=0; j--){

                            }
                        }
                    }
                    else if(s[j] == 1 && first == true){
                        computer = n[j];
                        tmp = t[j];
                    }
                }
                else if(first == false) {
                    tmpm = m[j];
                cout << computer << " " << ans << endl;
            }
            ans += te-tmp;
            cout << ans << endl;
        }
    }
    return 0;
}*/


Measured memory_bytes: 52328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

//Bellman-Fordをする。Gは<to, cost>の配列。dは結果。vは始点。true:負閉路の存在
bool BellmanFord(vector<vector<llll>> &G, vector<ll> &d, int v){
    fill(ALL(d), INF);
    d[v] = 0;
    
    bool check; //更新があったかの確認
    int times = 0; //回数
    int V = G.size();
    while(true){
        check = false;
        times++;
        for (int i = 0; i < V; i++) {
            for (auto edge : G[i]){
                auto to = edge.first;
                auto cost = edge.second;
                if(d[i] != INF && d[to] > d[i] + cost){
                    d[to] = d[i] + cost;
                    check = true;
                }
            }
        }
        if(!check) break;
        if(times >= V-1 && check){
            return true;
        }
    }
    return false;
}

void BellmanFord2(vector<vector<llll>> &G, vector<ll> &d, int v){
    fill(ALL(d), INF);
    d[v] = 0;
    
    int times = 0; //回数
    int V = G.size();
    while(true){
        times++;
        for (int i = 0; i < V; i++) {
            for (auto edge : G[i]){
                auto to = edge.first;
                auto cost = edge.second;
                if(d[i] != INF && d[to] > d[i] + cost){
                    d[to] = d[i] + cost;
                }
            }
        }
        if(times >= 2*V-1){
            break;
        }
    }
}


int main(){
    int N, M;
    cin >> N >> M;
    ll a, b, c;
    vector<vector<llll>> G(N);
    for (int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(make_pair(b, -c));
    }

    vector<ll> d(N);

    if(BellmanFord(G, d, 0)){
        vector<ll> dd(N);
        BellmanFord2(G, dd, 0);
        if(dd[N-1] != d[N-1]){
            printf("inf\n");
        }
        else{
            printf("%d\n", - d[N-1]);
        }
    }
    else{
        printf("%lld\n", - d[N-1]);
    }



}

Measured memory_bytes: 3708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		double r = Double.parseDouble(br.readLine());

		double s = r*r*Math.PI;
		double l = 2*r*Math.PI;
		System.out.printf("%6f %6f",s,l);
	}
}

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

using namespace std;

const int N = 123456;

int n, root, degree[N];
long long s[N];
vector<int> adj[N];

int dfs(int x, int f) {
  bool go = false;
  vector<long long> values;
  for (auto y : adj[x]) {
    if (y != f) {
      go = true;
      values.push_back(dfs(y, x));
    }
  }
  if (!go) {
    return s[x];
  }
  long long sum = 0, max_value = 0;
  for (auto v : values) {
    sum += v;
    max_value = max(max_value, v);
  }
  auto no_solution = [&] () {
    cout << "NO" << '\n';
    exit(0);
  };
  if (sum > s[x] * 2 || s[x] > sum) {
    no_solution();
  }
  long long diff = sum - s[x];
  if (max_value * 2 > sum) {
    if (sum - max_value < diff) {
      no_solution();
    }
  }
  s[x] -= diff;
  sum -= diff << 1;
  if (x != root && sum != s[x]) {
    no_solution();
  } else if (x == root && (s[x] > 0 || sum > 0)) {
    no_solution();
  }
  return sum;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  if (n == 2) {
    cout << (s[1] == s[2] ? "YES" : "NO") << '\n';
    exit(0);
  }
  for (int i = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    ++degree[x];
    ++degree[y];
  }
  for (int i = 1; i <= n; ++i) {
    if (degree[i] > 1) {
      root = i;
    }
  }
  dfs(root, 0);
  cout << "YES" << '\n';
  return 0;
}

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

int main() {
	int K, N;
	cin >> K >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	int max_dif = A.at(0) + (K - A.at(N - 1));
	for (int i = 1; i < N; i++) {
		int tmp = A.at(i) - A.at(i - 1);
		if (max_dif < tmp) max_dif = tmp;
	}
	cout << K - max_dif << endl;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

const int mod = 998244353, maxn = 2000;

int dp[2 * maxn + 1][2 * maxn + 1];
multiset<int> pos[2];

int solve(int i, int n0, int n1, int n) {
  if (i == 2 * n) {
    return 1;
  }

  int &res = dp[n0][n1];
  if (res != -1) return res;

  pair<int, int> range;
  if (i < n) {
    range = {0, i};
  } else {
    range = {0, n - 1};
  }

  res = 0;
  for (int val = 0; val < 2; ++val) {
    auto it = pos[val].lower_bound(range.first);
    if (it != pos[val].end() && *it <= range.second) {
      int this_pos = *it;
      pos[val].erase(it);
      res += solve(i + 1, n0 + (val == 0), n1 + (val == 1), n);
      if (res >= mod) res -= mod;
      pos[val].insert(this_pos);
    }
  }

  return res;
}

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

  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') {
      pos[0].insert(i);
      pos[0].insert(i);
    } else if (s[i] == '1') {
      pos[0].insert(i);
      pos[1].insert(i);
    } else {
      pos[1].insert(i);
      pos[1].insert(i);
    }
  }

  memset(dp, -1, sizeof(dp));
  int result = solve(0, 0, 0, n);
  printf("%d\n", result);

  return 0;
}


Measured memory_bytes: 63488
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  cout<<"ABC"<<S<<endl;
}



Measured memory_bytes: 3600
N,A,B = map(int,input().split())
L = []
def wa(x):
    s = 0
    while x > 0:
        s += x % 10
        x = int(x / 10)
    return s

for i in range(N + 1):
    if A <= wa(i) <= B:
        L.append(i)
        
print(sum(L))

Measured memory_bytes: 3300
H,W,D = map(int,input().split())

d = ['R','Y','G','B']

ans = [[] for i in range(H)]
for i in range(H):
    for j in range(W):
        x,y = i+j, i-j
        k = (x % (2*D)) // D
        k += ((y % (2*D)) // D) * 2
        ans[i].append(d[k])

for row in ans:
    print(''.join(row))


Measured memory_bytes: 5364
import sys
from collections import deque
input=sys.stdin.readline
h,w=map(int,input().split())
s=[]
for i in range(h):
    sub=input().rstrip()
    s.append(sub)
dire=[(1,0),(-1,0),(0,1),(0,-1)]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            l=[[-1]*w for _ in range(h)]
            q=[(i,j)]
            q=deque(q)
            l[i][j]=0
            while len(q)!=0:
                now=q.popleft()
                for d in dire:
                    x=now[0]+d[0]
                    y=now[1]+d[1]
                    if 0<=x<h and 0<=y<w:
                        if s[x][y]=='.':
                            if l[x][y]==-1:
                                l[x][y]=l[now[0]][now[1]]+1
                                ans=max(ans,l[x][y])
                                q.append((x,y))
print(ans)
                                


Measured memory_bytes: 43100
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    sort(A, A + N, greater<int>());
    if(N == 2) {
        cout << A[0] - A[1] << endl;
        cout << A[0] << " " << A[1] << endl;
        return 0;
    }
    int ans = A[0];
    int num1 = -INF, num2 = -INF;
    if(A[N - 1] >= 0) {
       
        num1 = A[N - 1];
        num2 = A[N - 2];
        A[N - 2] = A[N - 1] - A[N - 2];
        N--;
    }
    rep(i, N - 1) {
        ans += abs(A[i + 1]);
    }
    cout << ans << endl;
    if(num1 != -INF) {
        cout << num1 << " " << num2 << endl;
    }
    int x = A[0], y = A[N - 1];
    rep(i, N - 2) {
        if(A[i + 1] > 0) {
            cout << y << " " << A[i + 1] << endl;
            y -= A[i + 1];
        } else {
            cout << x << " " << A[i + 1] << endl;
            x -= A[i + 1];
        }
    }
    cout << x << " " << y << endl;


    return 0;
}
// -1 -2 -3
// 

Measured memory_bytes: 2304
N,M = map(int,input().split())
l=[]
r=[]
A=[]
for i in range(M):
        A.append(list(map(int,input().split())))

for i in range(M):
        l.append(A[i][0])
for i in range(M):
        r.append(A[i][1])

ans = min(r)-max(l)+1
if ans >= 0:
        print(ans)
else:
        print(0)

Measured memory_bytes: 67160
n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [-1]*(k+1)
dp[0] = 0

for i in range(1, k+1):
  temp = 1
  for j in range(n):
    if i - l[j] >= 0:
      temp *= dp[i-l[j]]
  dp[i] = 1-temp
      
if dp[k] == 0:
  print('Second')
else:
  print('First')

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

int main(){
  int n,a[101],sum=0;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  if(sum%10==0){
    for(int i=0;i<n;++i){
        if(a[i]%10!=0){
            sum-=a[i];
            cout << sum << endl;
            return 0;
        }
    }
    cout << 0 << endl;
  }else cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int N; cin >> N;
    vi v(N); rep (i, N) cin >> v[i];
    vi dp(N, INF); 

    rep (i, N) {

        if (i == 0) dp[i] = 0;
        else if (i == 1) dp[i] = abs(v[i] - v[i-1]);
        else dp[i] = min(abs(v[i] - v[i-1]) + dp[i-1], abs(v[i] - v[i-2]) + dp[i-2]);
    }
    cout << dp[N-1] << endl;

    return 0;
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    //my-code
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    int d = 0;
    while(d <= B) {
        if (A <= d) {
            print("OK");
            return 0;
        }
        d += K;
    }
    print("NG");

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

int main() {
	int a, b, c = 0;
	cin >> a >> b >> c;
	if ((a + b == c) || (b + c == a) || (c + a == b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
m = len(str(n))
ans = 0



for i in range(n + 1):
    A = str(i)
    first = A[0]
    end = A[-1]

    if end == '0':
        continue
    if first == end:
        ans += 1


    if m >= 3:
        for j in range(m - 2):
            ans += 10 ** (j)
    mini = int(end + '0' * (m - 2) + first)
    maxi = int(end + '9' * (m - 2) + first)
    # print(mini, maxi)
    if n < mini:
        continue
    elif mini <= n <= maxi:
        # print(i, mini, maxi)
        if int(str(n)[-1]) >= int(first):
            ans += int(str(n)[1:-1]) + 1
            # print('a')
        else:
            ans += int(str(n)[1:-1])
            # print('a')
    else:
        ans += (10 ** (m - 2))

print(ans)


Measured memory_bytes: 43372
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;

class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = {3, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
		int x = sc.nextInt();
    	int y = sc.nextInt();
    	if (a[x] == a[y]) {
    		System.out.println("Yes");
    	}  else {
    		System.out.println("No");
    	}
}
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;
int N,M,Q;
v<int> a,b,c,d;
int ans=0;
void dfs(v<int> A){
  if(SZ(A)>=N+1){
    int tmp=0;
    rep(i,Q){
      if(A[b[i]]-A[a[i]]==c[i]) tmp+=d[i];
    }
    chmax(ans,tmp);
    return;
  }
  A.push_back(A.back());
  while(A.back()<=M){
    dfs(A);
    A.back()++;
  }
}


signed _main(){
  cin >> N >> M >> Q;
  // グラフ入力受取 (ここでは無向グラフを想定)
  a = b = c = d = v<int>(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(v<int>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

int bfs(int x, int y, int t){
  int res = 1;
  queue<PII> q;
  q.push(MP(x,y));
  pos[y][x] = t;

  bool visit[200][200];
  fill((bool*)visit, (bool*)visit+200*200, false);
  visit[y][x] = true;
  
  while(!q.empty()){
	PII pii = q.front(); q.pop();
	x = pii.first, y = pii.second;
	if(pos[y][x] <= 0) continue;
	REP(i,6){
	  int tx = pii.first + dx[i], ty = pii.second + dy[i];
	  if(visit[ty][tx] || pos[ty][tx] == -1) continue;
	  visit[ty][tx] = true;
	  ++res;
	  pos[ty][tx] = pos[y][x] - 1;
	  q.push(MP(tx,ty));
	}
  }
  return res;
}

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

  int T, N;
  while(cin >> T >> N, T){
	fill((int*)pos, (int*)pos+200*200, 0);
	REP(i,N){
	  int x, y; cin >> x >> y;
	  pos[y+100][x+100] = -1;
	}
	int sx, sy; cin >> sx >> sy;
	cout << bfs(sx+100,sy+100,T) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1412
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var L = intShift() + intShift();
  var R = intShift() + intShift();
  
  if(L>R)return"Left";
  if(L==R)return"Balanced";
  if(L<R)return"Right";
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
3 8 7 1
`);

Measured memory_bytes: 7372
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

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

void Main() {
  string s;
  cin >> s;
  rep(i, 3) if(s[i] == s[i+1]) {
    cout << "Bad" << endl;
    return;
  }
  cout << "Good" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf = (char *)wmem;
  rd(buf);
  x = buf;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
string S[200000];
int main(){
  int i;
  wmem = memarr;
  int res = 1;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  sort(S,S+N);
  for(i=(1);i<(N);i++){
    if(S[i] != S[i-1]){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200430-1

// --- original code ---
// int N;
// string S[2d5];
// {
//   int res = 1;
//   rd(N,S(N));
//   sort(S,S+N);
//   rep(i,1,N) if(S[i] != S[i-1]) res++;
//   wt(res);
// }


Measured memory_bytes: 10904
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <map>

#define MY_SIZE_MAX 100001
#define MY_VALUE_MAX 100001

#define ULL unsigned long long

#define COUNTOF( a ) (sizeof(a)/sizeof(a[0]))
#define MIN(a,b) (((a)>(b))?(b):(a))
#define MAX(a,b) (((a)<(b))?(b):(a))

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	// 出現文字のカウント.
	ULL count[26] = {};
	for( int i = 0; i < static_cast< int >( s.size() ); i++ ){
		count[s[i]-'a']++;
	}

	// 同じ文字を選択するときの組み合わせ回数.
	ULL sameCharCount = 0;
	for( int i = 0; i < COUNTOF( count ); i++ ){
		sameCharCount += count[i] * (count[i]-1) / 2;
	}


	cout << ( ( s.size() * (s.size()-1) / 2 ) - sameCharCount ) + 1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
	ll n;
  	cin >> n;
  	for(int i=1;i<=9;i++)
    {
      ll x=n;
      if(n%i==0)
        x=n/i;
      for(int j=1;j<=9;j++)
      {
        ll y=x;
        if(x%j==0)
        {
          y=x/j;
		  if(y==1)
          {
            cout << "Yes";
            exit(0);
          }
        }
      }
    }
  cout << "No";
}

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

#define pb              push_back
#define pi              acos(-1.0)
#define loop(i,a,n)     for(int i=a;i<n;i++)
#define rloop(i,n,a)    for(int i=n;i>=a;i--)
#define ll              long long int
#define ff              first
#define ss              second
#define pii             pair<ll,ll>
#define sc1(a)          scanf("%d",&a)
#define sc2(a,b)        scanf("%d %d",&a,&b)
#define sc3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define all(v)          v.begin(),v.end()
#define ms(a,b)         memset(a,b,sizeof a)
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define fileout         freopen("output.txt","w",stdout)
#define filein          freopen("input.txt","r",stdin)
#define inf             2e9+5
#define Q               int q;cin>>q;while(q--)
#define check           cout<<"HI"<<endl;

//int x[]= {-1,0,0,1};
//int y[]= {0,-1,1,0};

using namespace std;

int main()
{
    
    int n;
    ll s=0,p;
    sc1(n);
    int a[n+5];
    int b[n+5];
    loop(i,0,n+1)sc1(a[i]);
    loop(i,0,n)sc1(b[i]);

    loop(i,0,n)
    {
        p = min(b[i],a[i]);
        s+=p;
        b[i]-=p;
        a[i]-=p;
        p = min(b[i],a[i+1]);
        s+=p;
        b[i]-=p;
        a[i+1]-=p;
       // cout<<b[i]<<endl;
    }
    //loop(i,0,n)

    cout<<s<<endl;
    
}













Measured memory_bytes: 4356
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,ans=0;
    cin >> n ;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
        if (i%2==0){
            if (a[i]%2)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<cstdio>
typedef long long ll;
int main()
{
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(b<a) printf("0\n");
	else if(n<1) printf("0\n");
	else if(n==1&&a!=b) printf("0\n");
	else printf("%lld\n",(n-2)*(b-a)+1);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	string s;
	cin >> s;
	int n = s.size();
	reverse(s.begin(), s.end());
	string d[4] = {"dream", "dreamer", "erase", "eraser"};
	rep(i,4) reverse(d[i].begin(), d[i].end());
	string t = "";
	rep(i,n) {
		rep(j,4) {
			if (t.size() + d[j].size() > n) continue;
			if (s.substr(i,d[j].size())==d[j]) {
				t += d[j];
				i += d[j].size()-1;
			}
		}
	}
	if (s == t) cout << "YES" << endl;
	else cout << "NO" << endl; 
	return 0;
}

Measured memory_bytes: 3764
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,K,i;cin>>n>>K;
	vector<llint>A(n);
	for(i=0;i<n;i++){cin>>A[i];}
	map<llint,int>mae;
	vector<int>syu(n);
	vector<int>tgi(n);
	for(i=0;i<n;i++){mae[A[i]]=i;}
	//cerr<<"de"<<__LINE__<<endl;
	for(i=0;i<n;i++){
		tgi[mae[A[i]]]=(i+1)%n;
		if(mae[A[i]]>=(i+1)%n-1){syu[mae[A[i]]]=1;}
		if(i==n-1&&mae[A[i]]==i){syu[mae[A[i]]]=2;}
		mae[A[i]]=i;
	}
	//cerr<<"de"<<__LINE__<<endl;
	vector<llint>kita(n,-1);
	llint rap=0,bas=0;
	while(kita[bas]==-1){
		kita[bas]=rap;
		rap+=syu[bas];
		bas=tgi[bas];
		//cerr<<"rap="<<rap<<"bas="<<bas<<endl;
	}
	//cerr<<"de"<<__LINE__<<endl;
	llint kaiten=rap-kita[bas];
	K%=kaiten;
	rap=0;bas=0;
	while(rap+syu[bas]<K){
		kita[bas]=rap;
		rap+=syu[bas];
		bas=tgi[bas];
	}
	
	//そこから普通
	vector<llint>ans;
	set<llint>aru;
	//cerr<<"rap="<<rap<<"bas="<<bas<<" "<<syu[bas]<<" "<<kaiten<<endl;
	for(i=bas;i<n;i++){
		if(aru.count(A[i])){
			while(aru.count(A[i])){
				aru.erase(ans.back());
				ans.pob();
			}
		}else{aru.ins(A[i]);ans.pub(A[i]);}
	}
	for(auto it:ans){cout<<it<<" ";}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 29680
import sys
def SI(): return sys.stdin.readline().strip()

def main():
    s = SI()
    t = SI()

    import collections
    d = collections.defaultdict(list)
    for i, c in enumerate(s):
        d[c].append(i)

    keys = d.keys()
    for c in set(t):
        if c not in keys:
            print(-1)
            return

    import bisect

    i_loop = 0
    currentidx = -1
    for c in t:
        # 次の文字を読む
        poslist = d[c]

        # とり切っていない場合
        posidx = bisect.bisect_right(poslist, currentidx)

        if posidx >= len(poslist):
            # とれないなら次のループでとったことにする
            i_loop += 1
            currentidx = poslist[0]
        else:
            # 同じループでとれるなら取って、現在位置を更新
            pos = poslist[posidx]
            currentidx = pos

    print(len(s)*i_loop + currentidx + 1)

main()

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let mut map: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let line: Vec<char> = iterator.next().unwrap().chars().collect();
        map.push(line);
    }

    for r in (0..h).rev() {
        let mut is_all_white = true;
        for c in 0..w {
            if map[r][c] == '#' {
                is_all_white = false;
                break;
            }
        }
        if is_all_white {
            map.remove(r);
        }
    }

    for c in (0..w).rev() {
        let mut is_all_white = true;
        for r in 0..map.len() {
            if map[r][c] == '#' {
                is_all_white = false;
                break;
            }
        }
        if is_all_white {
            for r in 0..map.len() {
                map[r].remove(c);
            }
        }
    }

    let mut result = String::new();
    for line in &map {
        for &c in line {
            result.push(c);
        }
        result.push('\n');
    }
    return result.trim().to_string();
}


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

using namespace std;

#define INF 1001001001  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

void p(int i,int n){
    cout <<i<<"::"<<n<<endl;
}



int main(){

    string s;
    ll ANS=0;

    cin >>s;

    int n = s.length();
    vector<int> ans(n+1);

    int i = 0;
    while (i < n){
        int c=0;

        if(s[i] == '<'){

            while(s[i+c] == '<'){
                ans[i+c] = c;
                //p(i+c,c);

                c++;

                if(i+c > n)break;
            }
            ans[i+c]=c;
        }else{

            while(s[i+c] == '>'){
                c++;
                if(i+c > n)break;
            }

            ans[i] = max(ans[i],c);
            //cout <<i<< " is now:: "<<ans[i]<<endl;

            for (int k = i+1; k <= i+c; k++){
                ans[k] = c - (k - i);
                //p(k,c-(k-i));
            }
        }

        i = i+c;
    }
    
    for(int a:ans){
        //cout << a;
        ANS += a;
    }
    cout <<endl<< ANS << endl;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 2820
#include<stdio.h>

int main(){
	int i,j,n,m,a[30];
	int d[]={0,1,2,3,5,7,8,9};
	
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		m=0;
		while(n>0){
			a[m++]=d[n%8];
			n/=8;
		}
		for(i=m-1;i>=0;i--)printf("%d",a[i]);
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <sys/time.h>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <chrono>

using namespace std;

// ---------- typedef ----------
typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t uint;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<double, double>> vpdd;
// ---------- define ----------
#define PI  3.1415926535
#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 = n >= m; i--)
#define FOREACH(it, v) for (it = v.begin(); it != v.end(); it++)

// ---------- template ----------
template < typename T > std::string to_string( const T& n ) {
	std::ostringstream stm;
	stm << n;
	return stm.str();
}
template< typename T > T sqr(const T& v) {
	return v * v;
}
// ---------- random ----------
uint xor128() {
	static uint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	uint t = x ^ (x << 11);
	x = y;
	y = z;
	z = w;
	return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
double sample() {
	return xor128() * 1.0 / numeric_limits<uint>::max();
}
//------------------------------
vector<ll> A;
ll S[1000000];
//#define LOCAL
int main() {
#ifdef LOCAL
	freopen("input1.txt", "r", stdin);
	//freopen("out1.txt", "w", stderr);
#endif
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		S[i] = A[i];
		if (i != 0) S[i] += S[i - 1];
	}
	int cnt = 1;
	REPR(i, N - 2) {
		if (S[i] * 2 >= A[i + 1]) cnt++;
		else break;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1908
//スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
typedef long long ll;
const int inf=1e9;
int n;
bool func(int s){
  if(s==n)return true;
  else if(s>n)return false;
  return (func(s+4)||func(s+7));
}
int main(){
  cin>>n;
  if(func(0))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		while(true) {
			int H =sc.nextInt();
			int W = sc.nextInt();
			if(H==0 && W==0) {
				break;
			}
			for(int i=0;i<H;i++) {
				for(int j=0;j<W;j++) {
					if((j+i)%2==0) {
						System.out.printf("#");
					}else {System.out.printf(".");
					}
				}System.out.printf("\n");
			}System.out.printf("\n");
		}sc.close();

	}

}



Measured memory_bytes: 62864
#include <stdio.h>

int main(void) {
	char c;
	int i;

	while((c = getchar()) != EOF) {
		if(c == '@') {
			char a, n;
			n = getchar();
			a = getchar();
			for(i = 0; i < n - '0'; i++) {
				putchar(a);
			}
		}

		else
			putchar(c);
	}

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

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

int check(int a, int b) {
	int res = INF;
	chmin(res, a);
	chmin(res, b);
	chmin(res, H - 1 - a);
	chmin(res, W - 1 - b);
	return res;
}

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

	cin >> H >> W >> K;
	VS S(H);
	REP(i, H)cin >> S[i];
	int sx, sy;
	REP(i, H)REP(j, W)if (S[i][j] == 'S') {
		sx = i, sy = j;
	}
	
	
	int ans = INF;
	bool vis[810][810] = { false };
	int dis[810][810];
	REP(i, 810)REP(j, 810)dis[i][j] = INF;
	queue<pii>Q;
	Q.push(pii(sx, sy));
	vis[sx][sy] = true;
	dis[sx][sy] = 0;

	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		
		REP(k, 4) {
			int nx = x + dx[k], ny = y + dy[k];
			if (nx >= 0 && nx < H&&ny >= 0 && ny < W) {
				if (S[nx][ny] != '#' && dis[x][y] + 1 <= K && dis[x][y] + 1 < dis[nx][ny]) {
					dis[nx][ny] = dis[x][y] + 1;
					vis[nx][ny] = true;
					Q.push(pii(nx, ny));
				}
			}
		}

	}
	REP(i, H) {
		REP(j, W) {
			if (dis[i][j] <= K) {
				int tmp = check(i, j);
				if (tmp != 0)tmp = (tmp - 1) / K + 1;
				chmin(ans, tmp);
			}
		}
	}


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



Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  int N;
  cin >> N;
  
  if(N%2 ==0){
    cout << N/2;
  }else{
    cout << N/2+1;
  }
  
}

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

using namespace std;

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

	long long L[87];

	L[0] = 2LL;
	L[1] = 1LL;


	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	cout << setprecision(18) << L[N] << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,a,kmp=1,cnt=0;
vector<int> v;
vector<pair<int,int> > p;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	for(int i=1;i<v.size();i++)
	{
		if(v[i]==v[i-1])
		{
			++kmp;
		}else
		{
			p.push_back(make_pair(v[i-1],kmp));
			kmp=1;
		}
	}
	p.push_back(make_pair(v[v.size()-1],kmp));
	for(int i=0;i<p.size();i++)
	{
		if(p[i].second<p[i].first)
		{
			cnt+=p[i].second;
		}else
		{
			cnt+=(p[i].second-p[i].first);
		}
	}
	printf("%d",cnt);
}

Measured memory_bytes: 4580
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define popb pop_back
# define pf push_front
# define popf pop_front
# define sll set<ll>
# define schar set<char>
//find()
//erase(x) removes element x
//erase(position,position)
# define qll queue<ll>
# define qstr queue<str>
//front(),back()
# define stll stack<ll>
# define ststr stack<str>
//top()
# define dll deque<ll>
//at()
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define mss map<str,str>
# define mci map<char,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define fr(x,y,z) for(int x=y;x<z;x++)
# define rr(x,y,z) for(int x=y;x>z;x--)
ll power(ll a , ll b){ll res=1;for(ll i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x,y;
    cin>>y>>x;
    
    ll a[x];
    f(i,x){
        cin>>a[i];
    }
    if(x==2){
        cout<<a[1]-a[0];
        return 0;
    }
    ll s=0;
   f(i,x-1){
       s+=a[i+1]-a[i];
   }
    ll k=a[0];
    ll k1=y-a[x-1];
    ll s2=s;
    s2+=k;
    s2+=k1;
    ll s3=1000000000;
    for(ll i=1;i<x-1;i++){
        ll s4=s2-(a[i+1]-a[i]);
        s3=min(s3,s4);
        s4=s2-(a[i]-a[i-1]);
        s3=min(s3,s4);
    }
    s3=min(s3,s);
    ll s4=s-(a[1]-a[0]);
    s4+=k;
    s4+=k1;
    s3=min(s3,s4);
    s4=s-(a[x-1]-a[x-2]);
    s4+=k;
    s4+=k1;
    s3=min(s3,s4);
    cout<<s3;
}




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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	vector<int> a(100005);
	for(int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a[t]++;
	}
	int ans = 0;
	for(int i = 0; i < a.size() - 3; i++) {
		ans = max(ans, a[i] + a[i + 1] + a[i + 2]);
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 640
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w,k=LI()
  field=[list(S()) for _ in range(h)]
  ans=[[0]*w for _ in range(h)]

  l=[]
  f=False
  y1=0
  x1=0
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        if f:
          l.append([y1,x1,i-1,w-1])
          y1=i
          x1=0
        f=True
        break
  l.append([y1,x1,h-1,w-1])
  # print(l)

  l2=[]
  while len(l)>0:
    y1,x1,y2,x2=l.pop()
    st=0
    f=False
    for j in range(x1,x2+1):
      for i in range(y1,y2+1):
        if field[i][j]=='#':
          if f:
            l2.append([y1,st,y2,j-1])
            st=j
          f=True
          break
    l2.append([y1,st,y2,x2])

  cnt=1
  while len(l2)>0:
    y1,x1,y2,x2=l2.pop()
    for i in range(y1,y2+1):
      for j in range(x1,x2+1):
        ans[i][j]=cnt
    cnt+=1

  for x in ans:
    print(' '.join([str(y) for y in x]))

main()
# print(main())


Measured memory_bytes: 18084