akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

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

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  vector<ll> dp1(3, LLONG_MIN/2);
  vector<ll> dp2(3, LLONG_MIN/2);

  cin >> dp1[0];

  n--;
  rep(i, n) {
    char op; cin >> op;
    ll a; cin >> a;
    if (op == '+') {
      dp2[0] = dp1[0] + a;
      dp2[1] = dp1[1] - a;
      dp2[2] = dp1[2] + a;
    } else {
      dp2[0] = dp1[0] - a;
      dp2[1] = max(dp1[0]-a, dp1[1]+a);
      dp2[2] = max(dp1[1]+a, dp1[2]+a);
    }
    swap(dp1, dp2);
  }

  ll ma = LLONG_MIN;
  rep(i, 3) {
    chmax(ma, dp1[i]);
  }
  cout << ma << endl;
}

Measured memory_bytes: 256
h,w=list(map(int,input().split()))
m=[]
for i in range(h):
    m.append(input())

for hi in range(h):
    for wi in range(w):
        if m[hi][wi]=="#":
            if not ((hi!=0 and m[hi-1][wi]=="#") or
                    (wi!=0 and m[hi][wi-1]=="#") or
                    (hi!=h-1 and m[hi+1][wi]=="#") or
                    (wi!=w-1 and m[hi][wi+1]=="#")):
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int n;
	int l;
	scanf("%d %d", &n, &l);
	int sum = (l + l + n - 1) * n / 2;
	if(l >= 0){
		sum -= l;
	}else{
		if(-l >= n){
			sum -= l + n - 1;
		}
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF  0x3f3f3f3f
#define mod 20191117
#define PI acos(-1)
using namespace std;
typedef long long ll ;

struct node{
    string s ;
    int t ;
}a[59];

int main()
{
    int n ;
    scanf("%d" , &n);
    set<pair<int , string> >s;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i].s >> a[i].t ;
    }
    string b ;
    cin >> b ;
    int sum = 0 ;
    int flag = 0 ;
    for(int i = 0 ; i < n ; i++)
    {
        if(flag)
        {
            sum += a[i].t ;
        }
        if(a[i].s == b)
        {
            flag = 1 ;
        }
    }
    cout << sum << endl ;


    return 0;
}


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

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
#pragma endregion

int main() {
  IN(int, N);
  IN(string, S);
  int count = 0;
  REP(i, N) {
    if (S.at(i) == 'A') {
      if (S.substr(i, 3) == "ABC") {
        count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3640
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=100023};

int main(){
	int n=ci(), k=ci(), s=ci();
	int lim= s==1e9 ? 1:1e9;
	rep(i,1,k) printf("%d ",s);
	rep(i,1,n-k) printf("%d ",lim); pt('\n');
	return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,s[3];
	cin>>a>>b;
for(int i=b-a+1;i<=b+a-1;i++)
 {
 printf("%d",i);
 if(i!=b+a-1)
 printf(" ");}

	return 0;
}

Measured memory_bytes: 888
h,n = map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(n)]
# ありえない値にしたいと仮定すると、最大値が10**7取りうるので10**7+1にする？
dp = [10**8] * (h+1)
dp[0] = 0

for i in range(1,h+1):
    for a,b in ab:
        if i >= a:
            # HPより小さいとき、減らした後のHPに対して消費するMPを足す
            atk = b + dp[i-a]
            if atk < dp[i]:
                dp[i] = atk
        elif b < dp[i]:
            # どの攻撃よりも小さいHPであれば、一番MP消費が少ない攻撃のMPを記録する
            dp[i] = b
# 配列の最後が、求めたいHP
print(dp[-1])

Measured memory_bytes: 42348
<>;
$_=<>;
$x=y/R//*y/G//*y/B//;
for$i(1..(@_=/./g)/2){
	for($i..@_-$i){
		$x-=($_[$_-$i]^$_[$_]^$_[$_+$i])eq W
	}
}
print$x


Measured memory_bytes: 5080
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define repi(i,a) for(auto i = a.begin(); i!= a.end() ;++i) 
#define repdi(i,a) for(auto i = a.rbegin(); i!=a.rend();++i) 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) (int)a.size() 
#define all(a) a.begin(),a.end()
#define mod 998244353
#define limit 1000
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;   

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int h,w, dp[1000][1000];
string s[1000];

int ans(int i,int j) {
	if(i==h-1 and j==w-1) return 1;
	if(i>=h or j>=w ) return 0 ;
	if(dp[i][j]!=-1) return dp[i][j];
	if(s[i][j]=='#') return dp[i][j] = 0 ;
	return dp[i][j] = (ans(i+1,j) + ans(i,j+1)) % MOD;
}

void solve() {
	cin >> h >> w;
	rep(i,0,h) cin >> s[i] ;
	fl(dp,-1);
	cout << ans(0,0) ;
}

int32_t main() {

    fast; 
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve() ;
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

using namespace std;

typedef long long ll;

ll adjmat[305][305], n;
int main(){
	//freopen("restoringroadnetwork.in", "r", stdin);
	cin >> n;
	for(ll i = 1; i<=n; i++){	
		for(ll j = 1; j<=n; j++){
			cin >> adjmat[i][j];
		}
	}
	ll ans = 0;
	for(ll i = 1; i<=n; i++){	
		for(ll j = 1; j<i; j++){
			bool magic = true;
			for(ll k = 1; k<=n; k++){
				if(k == i or k == j) continue;
				if(adjmat[i][j] == adjmat[i][k]+adjmat[k][j]){
					magic = false;
					break;
				}else if(adjmat[i][j] > adjmat[i][k] + adjmat[k][j]){
					cout << -1;
					return 0;
				}
			}
			if(magic) ans+=adjmat[i][j];
		}
	}
	cout << ans;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.12lf\n", sqrt(d));
}

Measured memory_bytes: 128
N = int(input())

# 現時点でのパラメータ
pt = 0
px = 0
py = 0

for i in range(N):
    t, x, y = map(int, input().split())

    time = abs(t - pt)
    # いわゆるマンハッタン距離
    dist = abs(x - px) + abs(y - py)

    if dist > time:
        print("No")
        exit()

    # x+yの偶奇は毎秒変わる
    # timeとdistの偶奇は一致する
    if time % 2 != dist % 2:
        print("No")
        exit()

    pt, px, py = t, x, y

print("Yes")


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mod 1000000007


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int> arr(n);
    for(auto &x:arr)
        cin>>x;
    sort(arr.begin(), arr.end());
    int ans=0;
    for(int i=arr[0]; i<=arr[n-1]; i++)
    {
        int x=i;
        auto it=lower_bound(arr.begin(), arr.end(), x);
        if(arr.end()-it==it-arr.begin())
            ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
from collections import deque

h,w = map(int,input().split())
s = [None]*h

for i in range(h):
    s[i] = input()

d = [[10000000 for i in range(w)] for j in range(h)]
sharp = 0

sx,sy = 0,0
gx,gy = w-1 , h-1
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sharp += 1

def bfs():
    d[sy][sx] = 0
    que = deque([[sy,sx]])
    
    while que:
        y,x = que.popleft()
        
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            
            if 0<=nx and nx<w and 0<=ny and ny<h and s[y][x] != '#':
                if d[ny][nx] > d[y][x]+1:
                    d[ny][nx]=d[y][x]+1
                    que.append([ny,nx])
                    
    if d[gy][gx] == 10000000:
        print("-1")
    else:
        print(w*h - sharp - (d[gy][gx]+1))
        
bfs()

Measured memory_bytes: 3316
PROGRAM ATCODER

implicit none
character(len=10**5) :: s
integer :: count=0,i

read(*,*) s

do i = 1, len_trim(s)-1
  if(s(i:i) /= s(i+1:i+1))then
    count = count + 1
  end if
end do

write(*,'(i0)') count

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER

Measured memory_bytes: 700
n = input()
a = list(map(int, input().split()))
count = 0
while True:
  f = 0
  for i in range(len(a)):
    if a[i]%2 == 0:
      a[i] = a[i]/ 2
    else:
      f =1
      break
  if f == 1:
    break 
  else:
    count +=1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MaxN = 102;
const int MaxVal = 1e5+2;
const int INF = 1e9+7;
int profit[MaxN], weight[MaxN];
int dp[MaxN][MaxVal];
int N,W;

int rec(int pos, int rem){

    if(rem==0) return 0;
    if(rem<=0 || pos>=N) return INF;
    auto &ret = dp[pos][rem];
    if(ret!=-1) return ret;
    return ret = min( rec(pos+1,rem-profit[pos]) + weight[pos] ,rec(pos+1,rem) );


}

void read(){

    cin>>N>>W;
    memset(dp,-1,sizeof dp);
    for(int i=0; i<N; i++)
        cin>>weight[i]>>profit[i];
}


void solve(){

    read();
    int res = 0;
    for(int i=0; i<MaxVal; i++){
        int ret = rec(0,i);
        if(ret<=W) res = i;
    }

    cout<< res <<"\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

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

int main(){
 int ans = 0;
 string s;
 cin >> s;
  
 if(s[0] == '1'){
  ans++;
 }
 
 if(s[1] == '1'){
  ans++;
 }
 
 if(s[2] == '1'){
  ans++;
 }
  
 cout << ans << endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

bool isPalindrome(string s) {
    string rs(s.rbegin(), s.rend());
    return s == rs;
    
}

void func(std::string S){
    int n = S.size();
    bool isStrongParindrome = isPalindrome(S) && isPalindrome(S.substr(0, (n-1)/2)) && isPalindrome(S.substr((n+1)/2));
    cout << (isStrongParindrome? YES : NO) << endl;
}


int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 256
n,d = map(int,input().split())
x=[[0]*d]*n
p = 0
for i in range(n):
  x[i] = list(map(int,input().split()))
for i in range(n-1):
  for j in range(i+1,n):
    s = 0
    for k in range(d):
      s = s + (x[i][k]-x[j][k])**2
    s = s**(0.5)
    if s == int(s):
      p = p + 1
print(p)

Measured memory_bytes: 38384
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500 * i + 100 * j + 50 * k == x:
        cnt += 1
        
print(cnt)

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int D,ans;
string s,a;

signed main() {
    cin >> s;
    rep(i,s.size()-1) {
        if (s[i] == 'B' && s[i+1] == 'C') a.pb('D'),i++;
        else a.pb(s[i]);
    }
    if (s[s.size()-2] != 'B' || s[s.size()-1] != 'C') a.pb(s[s.size()-1]);
    for(int i=a.size()-1;i>=0;i--) {
        if (a[i] == 'D') D++;
        else if (a[i] == 'A' && D) ans+=D;
        else D=0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
vector<int> G[300100];
int dist[300100];
int main()
{
	int N,M;
	cin>>N>>M;
	for(int i=0;i<N*3;i++)
		dist[i]=-1;
	while(M--)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		for(int i=0;i<3;i++)
			G[x*3+i].push_back(y*3+(i+1)%3);
	}
	int S,T;
	cin>>S>>T;
	S--;
	T--;
	queue<int> q;
	S*=3;
	T*=3;
	q.push(S);
	dist[S]=0;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0;i<G[x].size();i++)
			if(dist[G[x][i]]==-1)
			{
				dist[G[x][i]]=dist[x]+1;
				q.push(G[x][i]);
			}
	}
	if(dist[T]==-1)
		puts("-1");
	else	cout<<dist[T]/3<<endl;
	return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 3e3;
int n;
double a[maxn];
double dp[maxn][maxn];
//a(i): heads, tails = 1-a(i);

int main(){
	scanf("%d", &n);
	for(int i = 1; i<=n; i++) scanf("%lf", &a[i]);
	dp[1][0] = 1.00-a[1], dp[1][1] = a[1];
	for(int i = 2; i<=n; i++){
		for(int c = 0; c<=i; c++){
			dp[i][c] = dp[i-1][c] * (1.00-a[i]);
			if (c>0) dp[i][c] += dp[i-1][c-1] * a[i];
		}
	}
	double ans = 0.00;
	for(int i = (n+1)/2; i<=n; i++) ans+= dp[n][i];
	printf("%.10lf\n", ans);
	return 0;
}


Measured memory_bytes: 68864
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  string S;
  cin >> S;
  
  string abc = "abcdefghijklmnopqrstuvwxyz";
  int ans = 1000;
  
  for( int i = 0; i < abc.size(); i++ ){
    int tochu = 0;
    int cnt = 0;
    for( int j = 0; j < S.size(); j++ ){
      if( S.at(j) == abc.at(i) ){
        tochu = max( tochu, cnt );
        cnt = 0;
      }else{
        cnt++;
      }
    }
    tochu = max( tochu, cnt );
    ans = min( tochu, ans );
  }
  cout << ans << endl;
    
}

Measured memory_bytes: 256
M = 10**9+7

def factorial(n):
    f = 1
    for i in range(1,n+1):
        f = f*i%M
    return f

def comb(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    return perm(n,k)*inverse(factorial(k))%M

def mcomb(n,k):
    return comb(n+k-1,k)

def perm(n,k):
    if n==0 or k == 0:
        return 1
    if n<k:
        return 0

    p = 1
    for i in range(n-k+1,n+1):
        p = p*i%M

    return p

def inverse(a):
    return pow(a,M-2,M)

def main():
    n = int(input())
    
    if n==1:
        print(0)
    else:
        ans = pow(10,n,M)-2*pow(9,n,M)+pow(8,n,M)
        ans %= M
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9228
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair((a),(b))
#define list3(a,b,c) mp((a),mp((b),(c)))
#define list4(a,b,c,d) mp((a),list3((b),(c),(d)))
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};


bool vis[40][40][40][40];
PI memo[40][40][40][40];
int sum[40][40];
int in[40][40];
int h,w,s;

int su(int x1,int y1,int x2,int y2){
  return
    sum[x2][y2]-sum[x1][y2]-sum[x2][y1]+sum[x1][y1];
}

PI rec(int x1,int y1,int x2,int y2){
  if(vis[x1][y1][x2][y2])
    return memo[x1][y1][x2][y2];
  vis[x1][y1][x2][y2]=true;
  int all=su(0,0,h,w);  
  PI &ret=memo[x1][y1][x2][y2]=mp(1,s-(all-su(x1,y1,x2,y2)));

  for(int x=x1+1;x<x2;++x){
    if(all-su(x1,y1,x,y2)>s) continue;
    if(all-su(x,y1,x2,y2)>s) continue;
    PI a(rec(x1,y1,x,y2));
    PI b(rec(x,y1,x2,y2));
    ret=max(ret,mp(a.F+b.F,min(a.S,b.S)));
  }

  for(int y=y1+1;y<y2;++y){
    if(all-su(x1,y1,x2,y)>s) continue;
    if(all-su(x1,y,x2,y2)>s) continue;    
    PI a(rec(x1,y1,x2,y));
    PI b(rec(x1,y,x2,y2));
    ret=max(ret,mp(a.F+b.F,min(a.S,b.S)));    
  }
  //cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << ret.F << ' ' << ret.S << endl;
  return ret;
}

void solve(){
  rep(i,h)rep(j,w) cin >> in[i][j];
  rep(i,h)rep(j,w)
    sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+in[i][j];
  CLR(vis);
  PI ans(rec(0,0,h,w));
  cout << ans.F <<  ' ' << ans.S << endl;
}

int main(){
  while(cin >> h >> w >> s && h) solve();
}

Measured memory_bytes: 23692
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

const int N = 1e5 + 10;
int a[N], pref[N], suf[N], sum[N];  

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = pref[i - 1];
    if (a[i] > 0) {
      pref[i] += a[i];
    }
    sum[i] = sum[i - 1] + a[i];
  }  
  for (int i = n; i >= 1; i--) {
    suf[i] = suf[i + 1];
    if (a[i] > 0) {
      suf[i] += a[i];
    }
  }
  int ans = 0;
  for (int lst = 1; lst + k - 1 <= n; lst++) {
    ans = max(ans, pref[lst - 1] + suf[lst + k] + max(0ll, sum[lst + k - 1] - sum[lst - 1]));
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3328
from collections import Counter
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
c = c.most_common()
c.sort()
if n % 2 == 1:
    if c[0] != (0, 1):
        print(0)
        exit()
        
    num = 2
    for i, v in c[1:]:
        if (i, v) != (num, 2):
            print(0)
            exit()
        num += 2
else:
    num = 1
    for i, v in c:
        if (i, v) != (num, 2):
            print(0)
            exit()
        num += 2
print(2 ** (n//2) % mod)

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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long x,i,ans;
  cin>>x;
  for(i=x; i<1000000; i++){
    ans=i;
    for(int j=2; j*j<x; j++){
      if(i%j==0){
        ans=0;
        break;
      }
    }
    if(ans!=0){
      cout<<ans;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    int N;
    cin >> N;
    float T;
    float A;
    cin >> T >> A;
    float H[1100];
    REP(i, N) cin >> H[i];
    int ans = 1;
    float mindif = 100000;
    REP(i, N){
        float temp =  T - H[i]*0.006;
        float dif = fabs(A - temp);
        if (mindif > dif){
            mindif = dif;
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

ll N, A, B, C;

/* 
  選択肢が1つだけの場合は簡単
  隅に移動しなければ大丈夫
    A+B+C>=3 の場合はおそらく大丈夫
  ややこしいのは (A,B,C) = (1,1,0) で ABの場合
    どちらも隅に移動することになる
    この場合は次の入力を見て詰まない方を選ぶ
*/

char step( ll &a, ll &b, ll c, char aa, char bb, bool next_is_bc ){
	if ( a == 0 && b == 0 ){
		return 'Z';
	}
	
	if ( a == 1 && b == 1 && c == 0 ){
		if ( next_is_bc ){
			// 次はBCなので、Bを増やす
			a--;
			b++;
			return bb;
		}
		else {
			a++;
			b--;
			return aa;
		}
	}
	else {
		if ( a < b ){
			a++;
			b--;
			return aa;
		}
		else {
			a--;
			b++;
			return bb;
		}
	}
}

int main(){
	cin >> N >> A >> B >> C;
	
	
	/*
	  input
	    0: A以外を増減
	    1: B以外を増減
	    2: C以外を増減
	*/
	vector<int> input(N+1);
	vector<char> output(N);
	
	for ( int i = 0; i < N; i++ ){
		string s;
		cin >> s;
		if ( s == "BC" ) input[i] = 0;
		if ( s == "AC" ) input[i] = 1;
		if ( s == "AB" ) input[i] = 2;
	}
	input[N] = -1;
	
	ll sum = A+B+C;
	
	for ( int i = 0; i < N; i++ ){
		//cout << A << " " << B << " " << C << "  input=" << input[i] << endl;
		
		char d;
		switch ( input[i] ){
		case 0: d = step( B, C, A, 'B', 'C', input[i+1] == 1 ); break;
		case 1: d = step( C, A, B, 'C', 'A', input[i+1] == 2 ); break;
		case 2: d = step( A, B, C, 'A', 'B', input[i+1] == 0 ); break;
		}
		if ( d == 'Z' ){
			cout << "No" << endl;
			return 0;
		}
		output[i] = d;
		//cout << "  output=" << d << endl;
	}
	
	cout << "Yes" << endl;
	for ( auto it : output )
		cout << it << endl;
	
	
	return 0;
}



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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long n, MAX = -10000000, S = 0, x;
	cin >> n;
	while (n--){
		cin >> x;
		S+=x;
		MAX=max(MAX,x);
	}
	cout << S - MAX + MAX/2;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long MOD = 1000000007;
const long long INF = (1LL << 60);
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int n,w,weight[110],value[110];
int dp[110][100100] = { 0 };
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> w;
	rep(i, n)cin >> weight[i] >> value[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			if (j - weight[i] >= 0) {
				chmax(dp[i + 1][j], dp[i][j - weight[i]]+value[i]);
			}
			chmax(dp[i + 1][j], dp[i][j]);
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}

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

int main() {
  int N, count=0;
  string A, B, C;
  cin >> N >> A >> B >> C;
  for (int i=0; i<N; i++){
    if (A.at(i)!=B.at(i) && C.at(i)!=B.at(i) && A.at(i)!=C.at(i)) {
      count+=2;
    }
    else if(A.at(i)==B.at(i) && C.at(i)==B.at(i) && A.at(i)==C.at(i)) {
      count+=0;
    }
    else {
      count +=1;
    }
  }
  cout << count << endl;
      
}

Measured memory_bytes: 256
#from functools import reduce
from math import log
A,B = map(int, input().split())

def f(x):
    if x <= 0:
        return []
    n = int(log(x,2))
    r = [0 for i in range(n+1)]
    while x > 0:
        n = int(log(x,2))
        for i in range(n):
            r[i] += pow(2,n-1)
        x -= pow(2,n)
        r[n] += x+1
    return r

a = f(A-1)
b = f(B)
for i,v in enumerate(a):
    b[i] -= v

ans = 0
for i,v in enumerate(b):
    if v % 2 == 1:
        ans += pow(2,i)
print(ans)

#print(reduce(lambda x,y:x^y, range(A,B+1)))


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

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

int main(int argc, char** argv) {
  int N;
  std::cin >> N;
  std::cout << ((N/2+((N%2)?1:0))) << '\n';
}


Measured memory_bytes: 888
N = int(input())
count = 0
for i in range(N):
    xu = list(input().split())
    u = xu[1]
    if u == 'JPY':
        x = int(xu[0])
        count += x
    else:
        x = float(xu[0])
        count += x*380000.0
print(count)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

#define P (1'000'000'007)

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;}

inline int fast_pow(int x, int n, int mod) {
    long long signed res = 1;
    long long accumulation = x;
    for (int i = 0; n >> i > 0; ++ i) {
        if ((n >> i) % 2) {
            res *= accumulation;
            res %= mod;
        }
        accumulation *= accumulation;
        accumulation %= mod;
    }

    return res;
}

template<int MOD=P>
struct Mod {
public:
    long long signed value;

    Mod(long long signed val): value(val % MOD) {
        if (value < 0) value += MOD;
    }

    constexpr Mod& operator+=(const Mod& other) noexcept { 
        value += other.value;
        value %= MOD;
        return *this;
    }
    constexpr Mod& operator-=(const Mod& other) noexcept {
        value -= other.value;
        if (value < 0) value += MOD;
        return *this;
    }
    constexpr Mod& operator*=(const Mod& other) noexcept {
        value *= other.value;
        value %= MOD;
        return *this;
    }

    constexpr Mod operator-() noexcept {
         return value == 0 ? 0 : MOD - value;
    }

    constexpr Mod operator+(const Mod& other) const noexcept { return Mod(*this) += other; }
    constexpr Mod operator-(const Mod& other) const noexcept { return Mod(*this) -= other; }
    constexpr Mod operator*(const Mod& other) const noexcept { return Mod(*this) *= other; }
    constexpr bool operator==(const Mod& other) const noexcept { return this->value == other.value; }
    constexpr bool operator!=(const Mod& other) const noexcept { return this->value != other.value; }
};

signed main() {
    int n, k;
    cin >> n >> k;

    Mod ans(0);

    int vc[100001] = {0};

    rep(i, k) {
        int x = k - i;
        int p = fast_pow(k / x, n, P);
        for (int i = x * 2; i <= k; i += x) {
            p -= vc[i];
        }
        vc[x] = p;
        ans += x * p;
    }

    cout << ans.value;

    return 0;
}


Measured memory_bytes: 3944
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let _n = {
        let i = read::<isize>();
        i[0]
    };

    let a = read::<isize>();

    let mut max = a[0];
    let mut min = a[0];
    for an in a {
        if an > max {
            max = an;
        }
        if an < min {
            min = an;
        }
    }

    let ans = max - min;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,from,to,p,d,n,prime[2000000],x;

int main(){
	for(i=2;i<=1000000;i++)prime[i]=1;
	for(i=2,n=0;i<=1000000;i++){
		if(prime[i]==1){
			n++;
			if(i<=1000)for(j=i*i;j<=1000000;j+=i)prime[j]=0;
		}
		prime[i]=n;
	}
	while(scanf("%d",&n)*n){
		x=0;
		for(;n>0;n--){
			scanf("%d %d",&p,&d);
			from=(p-d-1>0?p-d-1:0);
			to=(p+d<1000000?p+d:1000000);
			x+=prime[to]-prime[from]-1;
		}
		printf("%d\n",x);
	}
	return 0;
}

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

const int INF = 100100100;

int c[10][1005];

int main(){
	int h, w, k;
  	cin >> h >> w >> k;
  	vector<string> s(h);
  	rep(i, h) cin >> s[i];
  	
  	int ans = INF;
  	rep(div, 1<<(h-1)){
    	int g = 0;
      	vector<int> id(h);
      	rep(i, h){
        	id[i] = g;
          	if(div>>i&1) g++;
        }
      	g++;
      
      	rep(i, g)rep(j, w) c[i][j] = 0;
      	rep(i, h)rep(j, w) c[id[i]][j] += (s[i][j]-'0');
      
      	int num = g - 1;
      	vector<int> now(g);
      	
      	auto add = [&](int j){
            rep(i, g) now[i] += c[i][j];
        	rep(i, g) if(now[i] > k) return false;
			return true;
        };
      
      	rep(j, w){
			if(!add(j)){
            	num++;
              	now = vector<int>(g);
              	
              	if(!add(j)){
                	num = INF;
                  	break;
                }
            }
        }
      
      	ans = min(ans, num);
    }
  
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        s: chars,
    }
    let c = s[0];
    let s: Vec<char> = "abcdefghijklmnopqrstuvwxyz".chars().collect();
    let ans = s.iter().position(|x| *x == c).unwrap();
    println!("{}", s[ans + 1]);
}

fn main() {
    run();
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";

ll mod = 1000000007;

using namespace std;

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

	int n;
	cin>>n;
	map<string,int> mp;
	string str;
	cin>>str;
	char last = str[str.size()-1];
	mp[str]++;
	for (int i = 0; i < n-1; ++i)
	{
		cin>>str;
		mp[str]++; 
		if(mp[str] > 1)
		{
			cout<<"No\n";
			return 0;
		}
		if(last != str[0])
		{
			cout<<"No\n";
			return 0;
		}

		last = str[str.size()-1];
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [input() for _ in range(H)]
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == 'S':
        A[i] = A[i][:j] + '.' + A[i][j + 1:]
        break
visited = [[False] * W for _ in range(H)]
ans = float('inf')
Q = collections.deque([[i, j, K]])
while Q:
    h, w, res = Q.popleft()
    if A[h][w] == '.' and not visited[h][w]:
        visited[h][w] = True
        ans = min([ans, h, H - 1 - h, w, W - 1 - w])
        if res:
            res -= 1
            if h:
                Q += [[h - 1, w, res]]
            if h < H - 1:
                Q += [[h + 1, w, res]]
            if w:
                Q += [[h, w - 1, res]]
            if w < W - 1:
                Q += [[h, w + 1, res]]
print(1 + math.ceil(ans / K))


Measured memory_bytes: 100056
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << "ABC" + s << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

typedef vector< vector< ll > > mat;
typedef vector< ll > vec;
mat mtmul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
       rep(i, (int)A.size()) {
               rep(k, (int)B.size()) {
                       rep(j, (int)B[0].size()) {
                           C[i][j] = (C[i][j] + (A[i][k] * B[k][j])%mod )%mod ;
                       }
               }
       }
       return C;
}
mat mtpow(mat A, ll n) {
       mat B(A.size(), vec(A.size()));
       rep(i, (int)A.size()) {
               B[i][i] = 1;
       }
       while (n > 0) {
               if (n&(ll)1)B = mtmul(B, A);
               A = mtmul(A, A);
               n >>= 1;
       }
       return B;
}

int n;
ll k;
mat A;


void solve(){
    cin >> n >> k;
    A.resize(n,{});
    rep(i,n){
        A[i].resize(n,0);
    }
    rep(i,n){
        rep(j,n){
            cin >> A[i][j];
        }
    }
    mat B=mtpow(A,k);
    // rep(i,n){
    //     rep(j,n){
    //         cout << A[i][j] << " ";
    //     }
    //     cout << "" << endl;
    // }
    // rep(i,n){
    //     rep(j,n){
    //         cout << B[i][j] << " ";
    //     }
    //     cout << "" << endl;
    // }
    mat a;
    vec t(n,1);
    a.push_back(t);
    a=mtmul(a,B);
    ll ans=0;
    rep(i,n){
        ans+=a[0][i];
        //cout << a[0][i] << endl;
        ans%=mod;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 512
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

c = 0
for _ in range(N):
  A = list(map(int, input().split()))
  sum = 0
  for a, b in zip(A, B):
    sum += a*b
  if sum + C > 0:
    c+=1
print(c)

Measured memory_bytes: 3060
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main()
{
    int a, b,c=0,d,e,y;
    double x;
    cin >> a >> b;
    d = b;
    while (d > 0) {
        d /= 10;
        c++;
    }
    e = a * pow(10, c) + b;
    x = sqrt(e);
    y = int(x);
    if (x == y)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

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


signed main(void) {
    int a,b;
    cin >> a >> b;
    if(abs(a-b)%2){
        cout << "IMPOSSIBLE" << endl;
    }else{
        int t = abs(a-b)/2;
        cout << min(a,b)+t << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lvector L(100,0); L[0]=2; L[1]=1;
  for(ll i=2;i<100;++i) L[i]=L[i-1]+L[i-2];
  ll n;cin>>n;
  print(L[n]);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  for(int i = 0; i < 3; ++i){
    if(a[i] != b[2-i]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()

ans = []
tmp = [T[0]]
now = 1
for i in range(1, N):
    if now == C or T[i] - tmp[0] > K:
        ans.append(tmp)
        tmp = [T[i]]
        now = 1
    else:
        tmp.append(T[i])
        now += 1
ans.append(tmp)

print(len(ans))


Measured memory_bytes: 17120
#include <bits/stdc++.h>
using namespace std;
const int n = 1000000;
int main(){
    int x; cin >> x;
    vector<int> a(n, 1);
    a[0] = 0; a[1] = 0;
    for(int i=0; i<n; ++i){
        if(a[i]!=1){continue;}
        for(int j=2*i; j<n; j+=i){
            a[j] = 0;
        }
    }
    for(int i=x; i<n; ++i){
        if(a[i]==1){cout << i << endl; return 0;}
    }
    return 0;
}

Measured memory_bytes: 7212
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{␣"; for(auto nth : list){ cout << nth << "␣"; } cout << "}" << endl;

using namespace std;

string converter = "bcdefghijklmnopqrstuvwxyza";

int main() {
    string S;
    int K;
    cin >> S >> K;

    for (int nth = 0; nth < S.size() - 1; ++nth) {
        int ascii = S[nth] - 97; 
        if (S[nth] != 'a' && K >= (26 - ascii)) { // aまで変換できるなら
            K -= (26 - ascii);
            S[nth] = 'a';
        }
    }

    if (K > 26) {
        K = K % 26;
    }

    for (int i = 0; i < K; ++i) {
        int ascii = S[S.size() - 1] - 97; 
        S[S.size() - 1] = converter[ascii];
    }

    cout << S << endl;
    return 0;
}


Measured memory_bytes: 640
import itertools
from collections import Counter


n = int(input())
s = input()

numbers = set()
# init
for i in range(1, n - 1):
    if i == 1:
        c = s[i]
        head = dict(Counter(s[i - 1]))
        tail = dict(Counter(s[i + 1:]))

        for h, p in itertools.product(head.keys(), tail.keys()):
            numbers.add((h, c, p))
        if c in head:
            head[c] += 1
        else:
            head[c] = 1
        tail[s[i + 1]] -= 1
        if tail[s[i + 1]] == 0:
            tail.pop(s[i + 1])

    else:
        c = s[i]
        for h, p in itertools.product(head.keys(), tail.keys()):
            numbers.add((h, c, p))

        if i == n - 1:
            break

        if c in head:
            head[c] += 1
        else:
            head[c] = 1
        tail[s[i + 1]] -= 1
        if tail[s[i + 1]] == 0:
            tail.pop(s[i + 1])

print(len(numbers))


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

int main(){
	LL h, w;
	cin >> h >> w;
	map<char, int> r;
	for(int i = 0; i < h; i++){
		string f;
		cin >> f;
		for(int j = 0; j < w; j++){
			r[f[j]]++;
		}
	}
	LL n4 = 0;
	LL n2 = 0;
	LL n1 = 0;
	LL ok = 1;
	LL a = h/2;
	LL b = w/2;
	LL a2 = h - 2*a;
	LL b2 = w - 2*b;
	n4 = a*b;
	n2 = a*b2+b*a2;
	for(int i = 0; i < n4; i++){
		int done = 0;
		for(char c = 'a'; c <= 'z'; c++){
			if(r[c] >= 4){
				r[c] -= 4;
				done = 1;
				break;
			}
		}
		if(!done){
			ok = 0;
			break;
		}
	}
	for(int i = 0; i < n2; i++){
		int done = 0;
		for(char c = 'a'; c <= 'z'; c++){
			if(r[c] >= 2){
				r[c] -= 2;
				done = 1;
				break;
			}
		}
		if(!done){
			ok = 0;
			break;
		}
	}
	if(!ok){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 256