akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    int a,b,i;
    scanf("%d", &a);
    scanf("%d", &b);
    if(a <= b){
        for(i = 0;i < b;i ++){
            printf("%d", a);
        }
    }
    else{
        for(i = 0;i < a;i ++){
            printf("%d", b);
        }
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long n = sc.nextLong();
			int k = sc.nextInt();
			long r = sc.nextLong();
			long s = sc.nextLong();
			long p = sc.nextLong();
			// 文字列の入力
			String t = sc.next();
			List<Integer> hands = new ArrayList<Integer>();
			long score = 0;
			for (int i = 1; i <= n; i++) {
				char t1 = t.charAt(i - 1);
				if (t1 == 'r') {
					if (i <= k || hands.get(i - k - 1) != 2) {
						score = score + p;
						hands.add(2);
					} else {
						hands.add(3);
					}
				} else if (t1 == 's') {
					if (i <= k || hands.get(i - k - 1) != 0) {
						score = score + r;
						hands.add(0);
					} else {
						hands.add(3);
					}
				} else if (t1 == 'p') {
					if (i <= k || hands.get(i - k - 1) != 1) {
						score = score + s;
						hands.add(1);
					} else {
						hands.add(3);
					}
				}
			}
			System.out.println(score);
		}
	}
}

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

int main(void){
    int n ;
    vector<double> v ;
    cin >> n ;
    for (int i=0; i<n; i++){
        double x ;
        cin >> x ;
        v.push_back(x) ;
    }
    sort (v.begin(),v.end()) ;
    double ans=(v[0]+v[1])/2 ;
    for (int i=2; i<n; i++){
        ans=(ans+v[i])/2 ;
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
#a = [int(i) for i in input().split()]

ans = 0
for i in range(1, n + 1):
    if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
        ans += i
print(ans)


Measured memory_bytes: 9160
#include <stdio.h>

int main(void)
{
    char n[200001];
    long res=0;
    scanf("%s",&n);
    for (int i=0; n[i]!='\0'; i++){
        res=res+(int)n[i]-48;
    }
    if (res%9==0)    {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}   

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

int main(){
    double l;
    cin>>l;
    long double ans=1.0000000,a=0.00000000;
    a=l/3;
    ans=a*a*a;
    cout<<setprecision(16)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int rank[2][4] = {0};
	float temp[2];
	
	while (scanf("%f%f",&temp[0],&temp[1]) != EOF){
		
		for (i = 0;i < 2; i++){
			if (temp[i] >= 1.1){
				rank[i][0]++;
			}
			else if (temp[i] >= 0.6){
				rank[i][1]++;
			}
			else if (temp[i] >= 0.2){
				rank[i][2]++;
			}
			else {
				rank[i][3]++;
			}
		}
	}
	
	for (i = 0; i < 4; i++){
		printf("%d %d\n", rank[0][i], rank[1][i]);
	}
	
	return (0);
}

Measured memory_bytes: 0
R, C, K = map(int, input().split())

grid = [[0 for c in range(C)] for r in range(R)]

for k in range(K):
    r, c, v = map(int, input().split())
    grid[r-1][c-1] = v

dp = [[[-1000 for c in range(C)] for r in range(R)] for k in range(4)]

if grid[0][0] > 0:
    dp[1][0][0] = grid[0][0]
dp[0][0][0] = 0

for r in range(R):
    for c in range(C):
        if c >= 1:
            dp[0][r][c] = max(dp[0][r][c], dp[0][r][c-1])
            dp[1][r][c] = max(dp[1][r][c], dp[1][r][c-1])
            dp[2][r][c] = max(dp[2][r][c], dp[2][r][c-1])
            dp[3][r][c] = max(dp[3][r][c], dp[3][r][c-1])
        if r >= 1:
            dp[0][r][c] = max(dp[0][r][c], dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
        v = grid[r][c]
        if v > 0:
            if c >= 1:
                dp[1][r][c] = max(dp[1][r][c], dp[0][r][c-1] + v)
                dp[2][r][c] = max(dp[2][r][c], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c], dp[2][r][c-1] + v)
            if r >= 1:
                dp[1][r][c] = max(dp[1][r][c], dp[0][r-1][c]+v, dp[1][r-1][c]+v, dp[2][r-1][c]+v, dp[3][r-1][c]+v)

print(max(dp[0][R-1][C-1], dp[1][R-1][C-1], dp[2][R-1][C-1], dp[3][R-1][C-1]))


Measured memory_bytes: 471320
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int k, s;
    cin >> k >> s;
    int sum = 0;
    for (int x = 0; x < k + 1; x++) {
        for (int y = 0; y < k + 1; y++) {
            if (s - y - x >= 0 && s - y - x <= k) sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()

result = True
for i in range(0, len(s), 2):
  if s[i] == 'L':
    result = False
    break
    
if result:
  for i in range(1, len(s), 2):
    if s[i] == 'R':
      result = False
      break

print('Yes' if result else 'No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n; cin >> n;
    V<int> P(n);
    loop (n, i) cin >> P[i];

    int ans = 0;
    loop (n - 2, i) {
        if (min(P[i], P[i + 2]) < P[i + 1] && max(P[i], P[i + 2]) > P[i + 1]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
S = input()

A = [-1, ] * (len(S) + 1)
cnt = 0
for i in range(0, len(S)):
    if S[i] == '<':
        A[i] = cnt
        cnt += 1
        A[i + 1] = cnt
    else:
        cnt = 0

cnt = 0
for i in range(len(S) - 1, -1, -1):
    if S[i] == '>':
        A[i + 1] = cnt
        cnt += 1
        A[i] = max(cnt, A[i])
    else:
        cnt = 0

print(sum(A))


Measured memory_bytes: 46536
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll infl = 1ll<<60;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    vector<int> p(4);
    cin>>n>>k;
    cin>>p[1]>>p[2]>>p[3];
    string t;
    cin>>t;
    
    vector<int> v(n+1);
    ll sum = 0ll;
    for(int i=0;i<k;++i){
        int pre = 0;
        int cur = 0;
        for(int j=i;j<n;j+=k){ 
            switch(t[j]){
                case 'r':
                    cur = 3;break;
                case 's':
                    cur = 1;break;
                case 'p':
                    cur = 2;break;
            }
            if(pre != cur)sum += p[cur],pre = cur;
            else pre = 0;
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
  double min = 999999999999999.0;
  vector<long long> answers;
  for (long long i = 1000000000000LL; i > 0; i /= 10) {
    for (int j = 1000; j > 100; j--) {
      long long n = i * j - 1;
      long long x = n;
      int s = 0;
      while (x > 0) {
        s += x % 10;
        x /= 10;
      }
      double v = (double) n / s;
      if (v <= min) {
        min = v;
        answers.push_back(n);
      }
    }
  }
  for (long long i = 100; i > 0; i--) {
    long long x = i;
    int s = 0;
    while (x > 0) {
      s += x % 10;
      x /= 10;
    }
    double v = (double) i / s;
    if (v <= min) {
      min = v;
      answers.push_back(i);
    }
  }
  reverse(answers.begin(), answers.end());
  int k;
  cin >> k;
  for (int ki = 0; ki < k; ki++) {
    cout << answers[ki] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

LL t[100005];

int main(){
	LL n,m;
	LL i,j,k;
	LL a,b,c,d;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
	}
	sort(t,t+n);
	b=0,c=0;
	for(i=0;i<2;i++){
		swap(b,c),a=0,d=1e9;
		for(j=0;j<n;j++){
			if((i+j)%2==0)k=j/2;
			else k=n-j/2-1;
			if(a!=0){
				b+=abs(a-t[k]);
				d=min(d,abs(a-t[k]));
			}
			a=t[k];
		}
		if(i==0)b+=abs(t[0]-t[k]);
		else b+=abs(t[n-1]-t[k]);
		b-=d;
	}
	cout<<max(b,c)<<endl;
}

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



int main(){
	int n;
	cin>>n;
	int h[n];
	rep(i,n)cin>>h[i];
	int k[n],cnt=0,l=101,r=0,tmp;


	for(int i=0;i<n;i++){
		while(h[i]>0){
			int r;
			for(r=i+1;r<n;r++){
				if(h[r]==0)break;
			}
			for(int j=i;j<r;j++){
				h[j]--;
			}
		cnt++;
		}
	}

	cout<<cnt<<endl;

	//rep(i,n)//cout<<h[i]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define incant() cin.tie(0), ios::sync_with_stdio(false)
#define int long long
#define uint unsigned long long
#define double long double
using str = string;
template <class T> using vec = vector<T>;
template <class T> using vvec = vec<vec<T>>;
template <class T> using que = queue<T>;
template <class T> using pque = priority_queue<T>;
template <class... T> using tup = tuple<T...>;
using vint = vec<int>;
using vvint = vvec<int>;
using vstr = vec<str>;
using pint = pair<int, int>;
using vp = vec<pint>;
using tll = tup<int, int, int>;
using vt = vec<tll>;
using mint = map<int, int>;
using dict = map<str, int>;
using qint = que<int>;
using qp = que<pint>;
using pqint = pque<int>;
using pqp = pque<pint>;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define ms(v, x) memset(v, x, sizeof(v))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) out(x), indent()
#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'
#define YN(x) print((x) ? "YES" : "NO")
#define Yn(x) print((x) ? "Yes" : "No")
#define yn(x) print((x) ? "yes" : "no")
#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")
#define Pos(x) print((x) ? "Possible" : "Impossible")
#define pos(x) print((x) ? "possible" : "impossible")
const int INF = LLONG_MAX - INT_MAX, MOD = 1e9 + 7, LIMIT = 100001;
const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const double EPS = 1e-9;
int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int factorial(int a){return a < 2 ? 1 : factorial(a - 1) * a;}
int summation(int a){return a < 1 ? 0 : (a * a + a) / 2;}
int combination(int n, int r){int res = 1; rep(i, 1, r + 1) res *= n--, res /= i; return res;}
const str alphabet = "abcdefghijklmnopqrstuvwxyz";
int a, b, c, k, n, m, x, y, z, w, h, res = 0, cnt = 0, sum = 0, mx = -INF, mn = INF;
str s, t;
bool flag = true;

signed main(){
    incant();
    cin >> n >> k;
    int v[n];
    each(i, v){
        cin >> i;
    }
    rev(i, 41){
        cnt = 0;
        each(j, v){
            cnt += j >> i & 1;
        }
        if(2*cnt < n && (res | (1LL << i)) <= k){
            res |= 1LL << i;
        }
    }
    each(i, v){
        sum += i ^ res;
    }
    print(sum);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
//invの要素にはiの逆元が格納されている
//前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;//i!(mod MOD)を計算
        inv[i] = MOD - inv[MOD%i]* (MOD / i) % MOD;//i!の逆元を計算
        finv[i] = finv[i - 1] * inv[i] % MOD;//i!(mod MOD)の逆元を計算
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;//nCk = n!/(k!*(n-k)!)を計算
}

long long nPm(int n, int m){
    if(n < m) return 0;
    if(n < 0 || m < 0) return 0;
    return fac[n] * finv[n - m] % MOD;
}


int main(){
    COMinit();
    long long N, M;
    cin >> N >> M;
    long long ans = nPm(M, N) * nPm(M, N) % MOD;
    for(int i = 1; i <= N; i++){
        if(i % 2 == 1) {
            ans -= COM(N, i) * nPm(M, i) % MOD * nPm(M - i, N - i) % MOD * nPm(M - i, N - i) % MOD;
            ans = (ans + MOD) % MOD;
        }
        else{
            ans += COM(N, i) * nPm(M, i) % MOD * nPm(M - i, N - i) % MOD * nPm(M - i, N - i) % MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 15560
/**
 * A - Sheep and Wolves
 * https://atcoder.jp/contests/abc164/tasks/abc164_a
 */
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    // 羊が S 匹、狼が W匹います。
    // 狼の数が羊の数以上のとき、羊は狼に襲われてしまいます
    int S, W;
    cin >> S >> W;
    // 羊が狼に襲われるなら unsafe、襲われないなら safe を出力してください。
    cout << (W >= S ? "unsafe" : "safe") << endl;
}
 

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    string s, t;
    cin >> s >> t;

    if (s == t.substr(0, s.size()))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,m,f[1<<12];
int dp[1<<12];
void solve(){
    memset(f,1,sizeof f);
    cin>>n>>m;
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        int cur=0;
        rep(j,0,b){
            int x;
            cin>>x;
            cur|=(1<<(x-1));
        }
        f[cur]=min(f[cur],a);
    }
    memset(dp,1,sizeof dp);
    dp[0]=0;
    rep(i,0,1<<n){
        rep(j,0,1<<n){
            dp[i]=min(dp[i],dp[i^(i&j)]+f[j]);
        }
    }
    if(dp[(1<<n)-1]<hell) cout<<dp[(1<<n)-1]<<endl;
    else cout<<-1<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <regex>

using namespace std;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(_debuged) cerr << #_debuged << ":" << _debuged << endl;

struct L
{
	int t;
	int x;
	int y;
};

vector<int> loadn(int n)
{
	vector<int> v(n);
	REP(i, n)
		cin >> v[i];
	return v;
}

uint64_t modpower(const unsigned int N, const unsigned int K, const unsigned int MOD)
{
	uint64_t ret = 1;
	uint64_t k2 = N;
	REP(i, 31)
	{
		if ((K >> i) & 0x1)
		{
			ret *= k2;
			ret = ret % MOD;
		}
		k2 = (k2 * k2) % MOD;
	}
	return ret;
}

class ModCombinationMemo
{
public:
	const unsigned int N;
	const unsigned int MOD;
	vector<uint64_t> memo = { 1 };

	ModCombinationMemo(uint32_t N, uint32_t MOD)
		: N(N), MOD(MOD)
	{
	}

	uint64_t c(uint64_t k)
	{
		if (memo.size() > k)
		{
			return memo[k];
		}

		FOR(i, memo.size(), k + 1)
		{
			const auto number = (memo[i - 1] * (N - i + 1)) % MOD;
			const auto reverceDeon = modpower(i, MOD - 2, MOD);
			memo.push_back(number * reverceDeon % MOD);
		}

		return memo[k];
	}
};

uint64_t c(const unsigned int N, const unsigned int K, const unsigned int MOD)
{
	if (K == 0)
	{
		return 1;
	}

	uint64_t n = 1, k = 1;

	REP(i, K)
	{
		n *= N - i;
		k *= i + 1;

		n = n % MOD;
		k = k % MOD;
	}

	uint64_t powerk = modpower(k, MOD - 2, MOD);

	return (n * powerk) % MOD;
}

unsigned trailing_zeros(unsigned n)
{
	if (!n)
		return -1;
	unsigned int c = 32; // c will be the number of zero bits on the right
	n &= -(signed)n;
	if (n)
		c--;
	if (n & 0x0000FFFF)
		c -= 16;
	if (n & 0x00FF00FF)
		c -= 8;
	if (n & 0x0F0F0F0F)
		c -= 4;
	if (n & 0x33333333)
		c -= 2;
	if (n & 0x55555555)
		c -= 1;
	return c;
}

unsigned int digitssum(uint64_t source) {
	int result = 0;

	while (source > 0) {
		result += source % 10;
		source /= 10;
	}

	return source;
}

struct oishisa
{
	int64_t x;
	int64_t y;
	int64_t z;
};

int64_t cint()
{
	int64_t i;
	cin >> i;
	return i;
}

int main(int argc, char *argv[], char *envp[])
{
	int i = 0;
	REP(n, 4) {
		char sign;
		cin >> sign;
		i += (sign == '+' ? +1 : -1);
	}
	cout << i;
}
/*
int main(int argc, char *argv[], char *envp[])
{
	const int K(cint());

	
	int result = 0;
	
	for (uint64_t target = 1; result < K; target++) {
		FOR(s, 1, 127) {
			int minimum = target + 1;
			while(digitssum(minimum) != s) {
				minimum += 
			}

			if (target * digitssum(minimum) > minimum * digitssum(target)) {
				goto b;
			}
		}

		cout << target << endl;
		result++;

	b:;
		
	}

	return 0;
}
*/

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

void split(string s, string &s1, string &s2){
  for(int i=0;i<s.size();i++){
    if (s[i] == '-') {
      s1 = s.substr(0, i);
      s2 = s.substr(i+1, s.size() - (i + 1));
      return;
    }
  }

  return;
}

int dist[SIZE][SIZE];
bool exist[SIZE][SIZE] = {};

bool solve(){
  int n;
  map<string, int> dict;
  int ids = 0;
  int p[SIZE][2];
  string s;

  cin >> n;

  if(n == 0) return false;

  for(int i=0;i<200;i++){
    for(int j=0;j<200;j++){
      dist[i][j] = INF;
      exist[i][j] = false;
    }
    dist[i][i] = 0;
  }
  
  for(int i=0;i<n;i++){
    string s1, s2;
    cin >> s;
    split(s, s1, s2);

    if(dict.find(s1) == dict.end()) dict[s1] =  ids++;
    if(dict.find(s2) == dict.end()) dict[s2] =  ids++;

    p[i][0] = dict[s1];
    p[i][1] = dict[s2];

    dist[p[i][0]][p[i][1]] = 1;
    exist[p[i][0]][p[i][1]] = true;
  }

  for(int i=0;i<ids;i++){
    for(int j=0;j<ids;j++){
      bool f = false;

      for(int k=0;k<ids;k++){
        f |= (exist[i][k] || exist[k][i]) && (exist[j][k] || exist[k][j]);
      }

      for(int k=0;k<ids;k++){
        f &= !(exist[i][k] && exist[k][j]);
        f &= !(exist[k][i] && exist[j][k]);
      }

      if(f) dist[i][j] = dist[j][i] = 2;
    }
  }

  for(int k=0;k<ids;k++){
    for(int i=0;i<ids;i++){
      for(int j=0;j<ids;j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int q;

  scanf("%d", &q);

  printf("%d\n", ids);
  
  for(int i=0;i<q;i++){
    string s1, s2;
    cin >> s;
    split(s, s1, s2);

    if (dict.find(s1) == dict.end() || dict.find(s2) == dict.end()){
      puts("NO");
      continue;
    }
    
    int res = dist[dict[s1]][dict[s2]];

    //debug(dict[s1]); debug(dict[s2]);
    //debug(res);
    
    if(res != INF && res%2){
      puts("YES");
    }else{
      puts("NO");
    }
  }

  return true;
}

int main(){
  while(solve());
  
  return 0;
}



Measured memory_bytes: 4232
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
using namespace std;

int main(){
	 string s; cin >>s;
	 for(int i=0;i<s.size()-1;i++){
	 	if(s[i]=='A'&&s[i+1]=='C'){
	 		cout << "Yes" << endl;
	 		return 0;
	 	}
	 }
	 cout << "No" << endl;
	 return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
struct ban
{
    long long x;
    ban()
    {
        x = 0;
    }
    ban(long long x)
    {
        this->x = (x % M);
    }
};
ban operator+(const ban& a, const ban& b)
{
    return ban(a.x + b.x);
}
ban operator-(const ban& a, const ban& b)
{
    return ban(a.x - b.x + M);
}
ban operator*(const ban& a, const ban& b)
{
    return ban(a.x * b.x);
}
ban ast(ban x, int n)
{
    if (n == 0)
        return ban(1);
    if (n % 2 == 0)
    {
        ban y = ast(x, n / 2);
        return y * y;
    }
    else
    {
        ban y = ast(x, n - 1);
        return x * y;
    }
}
ban operator/(const ban& a, const ban& b)
{
    return a * ast(b, M - 2);
}
ban gum(int x)
{
    return ban((x + 1) * 1LL * x / 2);
}

int n, m, k;

int main()
{
    cin >> n >> m >> k;

    ban z(1);
    for (int i = n * m - 2, j = k - 2; j > 0; --i, --j)
        z = z * ban(i);
    for (int i = 1; i <= k - 2; ++i)
        z = z / ban(i);

    ban ans;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            ban x = gum(i - 1) + gum(n - i);
            ban y = gum(j - 1) + gum(m - j);
            ans = ans + x * ban(m) + y * ban(n);
        }
    }
    ans = ans / ban(2);
    ans = ans * z;
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

ll pow(ll x, ll n) {
    if (n == 0) {
        return 1;
    }
    ll res = pow(x * x, n / 2);
    if (n & 1) {
        res = res * x;
    }
    return res;
}

// dfs(0, ttop, chars, pretotal);
void dfs(ll keta, ll top, ll &total, vector<char> &chars, ll K) {
    if (total > K) {
        return;
    }

    if (keta == -1) {
        total++;
        if (total == K) {
            for (ll s = chars.size() - 1; s >= 0; s--) {
                print0(chars[s]);
            }
            print();
        }
        return;
    }
    if (top > 0) {
        chars[keta] = (char)top + '0' - 1;
        dfs(keta - 1, top - 1, total, chars, K);
    }
    chars[keta] = (char)top + '0';
    dfs(keta - 1, top, total, chars, K);
    if (top < 9) {
        chars[keta] = (char)top + '0' + 1;
        dfs(keta - 1, top + 1, total, chars, K);
    }
}
int main() {
    ll K;
    cin >> K;
    vector<vector<ll>> rr(100000, vector<ll>(10, 0));
    ll total = 0;
    for (ll top = 1; top <= 9; top++) {
        rr[1][top] = 1;
        total += 1;
    }
    if (K <= 9) {
        print(K);
        return 0;
    }
    ll tketa = -1;
    ll ttop = -1;
    ll pretotal = 9;

    rr[1][0] = 1;
    for (ll keta = 2; true; keta++) {
        for (ll top = 1; top <= 9; top++) {
            if (top == 1) {
                rr[keta][top] = rr[keta - 1][top] + rr[keta - 1][top + 1] + rr[keta - 1][0];
                total += rr[keta][top];
            } else if (top == 9) {
                rr[keta][top] = rr[keta - 1][top - 1] + rr[keta - 1][top];
                total += rr[keta][top];
            } else {
                rr[keta][top] = rr[keta - 1][top - 1] + rr[keta - 1][top] + rr[keta - 1][top + 1];
                total += rr[keta][top];
            }
            if (total >= K) {
                tketa = keta;
                ttop = top;
                break;
            }
            pretotal = total;
        }
        rr[keta][0] = rr[keta - 1][0] + rr[keta - 1][1];
        if (tketa >= 0) {
            break;
        }
    }
    vector<char> chars(tketa);
    //    dfs(0, ttop, chars, pretotal);

    chars[tketa - 1] = ttop + '0';
    dfs(tketa - 2, ttop, pretotal, chars, K);
}


Measured memory_bytes: 14872
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=300010;

ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=res*x%mod;
        b/=2;
        x=x*x%mod;
    }
    return res;
}

signed main(){
    ll n,c;cin>>n>>c;
    vector<ll>a(n);
    vector<ll>b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    vector<vector<ll> >k(n,vector<ll>(c+1));
    rep(i,n){
        rep(j,c+1){
            ll cnt=0;
            REP(l,a[i],b[i]+1){
                cnt=(cnt+rui(l,j))%mod;
            }
            k[i][j]=cnt;
        }
    }
    vector<vector<ll> >dp(n+1,vector<ll>(c+1));
    dp[0][0]=1;
    rep(i,n){
        rep(j,c+1){
            REP(l,j,c+1){
                dp[i+1][l]=(dp[i+1][l]+dp[i][j]*k[i][l-j]%mod)%mod;
            }
        }
    }
    ll ans=dp[n][c];
    cout<<ans<<endl;
}

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

int main() {
   int n, m, i, count=0;
   float sum=0.0;
   cin >> n >> m;
   int A[n];

   for(i=0; i<n; i++){
       cin >> A[i];
       sum += A[i];
   }

   for(i=0; i<n; i++){
       if(A[i] >= sum / (4 * m)){
           count++;
       }
   }
   if(count >= m){
       cout << "Yes";
   }else{
       cout << "No";
   }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

using ld=long double;
int main() {	
	int N;
	ld t;cin>>N>>t;
	ld ans=0;
	for (int i = 0; i < N; ++i) {
		ld x,h;cin>>x>>h;
		ans=max(ans,h/x*t);
	}
	cout<<setprecision(10)<<fixed<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
    int Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    
    ll add_1 = (ll)min({S, 2 * H, H + 2 * Q, 4 * Q});
    ll add_2 = min(2 * add_1, (ll)D);
    
    if(N == 1){
        cout << add_1 << endl;
        return 0;
    }
    if(N == 2){
        cout << add_2 << endl;
        return 0;
    }
    
    ll temp1 = add_1;
    ll temp2 = add_2;
    
    for(int i = 3; i <= N; i++){
        ll temp = temp2;
        temp2 = min(temp1 + add_2, temp2 + add_1);
        temp1 = temp;
    }
    
    cout << temp2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool f(int a,int b)
{
	if(a==b)
	{
		return true;
	}
	return false;
}
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int count=0;
	if(f(a,b))
	{
		count++;
	}
	if(f(a,c))
	{
		count++;
	}
	if(f(b,c))
	{
		count++;
	}
	if(count==3)
	cout<<1;
	if(count==1)
	cout<<2;
	if(count==0)
	cout<<3;

	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<double> denominator(n);
    for(int i = 0;i < n;i++){
        denominator[i] = n;
        if(i + 1 < k){
            int res = i + 1;
            while(res < k){
                res *= 2;
                denominator[i] *= 2;
            }
        }
    }
    double max_denominator = *max_element(begin(denominator), end(denominator));
    double numerator = 0;
    for(auto& e : denominator){
        numerator += (max_denominator / e);
    }
    cout << fixed << setprecision(10) << numerator / max_denominator << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<string,string> P;
const int DRAW = 0;
const int WIN = 1;
const int LOSE = 2;
string s[15] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"};
map<string,int> m;
int h[15][15] = {0};

int main(){
	for(int i=0 ; i < 15 ; i++ ){
		m[s[i]] = i;
		for(int j=i+1 ; j <= i+7 ; j++ ){
			h[i][j%15] = WIN;
			h[j%15][i] = LOSE;
		}
	}
	
	int n;
	while( cin >> n, n ){
		vector<string> hand(n);
		string ans;
		
		for(int i=0 ; i < n ; i++ ){
			cin >> hand[i];
		}
		for(int i=0 ; i < n ; i++ ){
			int win=0, lose=0, draw=0;
			
			for(int j=0 ; j < n ; j++ ){
				int res = h[m[hand[i]]][m[hand[j]]];
				if( res == LOSE ){
					lose++;
					break;
				}
				if( res == WIN ) win++;
				if( res == DRAW ) draw++;
			}
			if( lose == 0 && win > 0 ) ans = hand[i];
		}
		if( ans.empty() ){
			cout << "Draw" << endl;
		}else{
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1272
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int x;
int c[15], ch[15];
int lev[15];
int a[15][15];
int ans = 0x7f7f7f7f;
void dfs(int cur) {
	if (cur > n) {
		int now = 0;
		for (int j = 1; j <= m; j++) lev[j] = 0;
		for (int i = 1; i <= n; i++) {
			if (ch[i] == 1) {
				now += c[i];
				for (int j = 1; j <= m; j++) {
					lev[j] += a[i][j];
				}
			}
		}
		bool flag = 1;
		for (int i = 1; i <= m; i++) {
			if (lev[i] < x) {
				flag = 0;
				break;
			}
		}
		if (flag) {
			ans = min(ans, now);
		}
		return;
	}
	ch[cur] = 1;
	dfs(cur + 1);
	ch[cur] = 0;
	dfs(cur + 1);
}
int main() {
	scanf("%d%d", &n, &m);
	scanf("%d", &x);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &c[i]);
		for (int j = 1; j <= m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	dfs(1);
	if (ans < 0x7f7f7f7f) {
		cout << ans;
	} else {
		cout << -1;
	}
	return 0;
}

Measured memory_bytes: 3764
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		TreeMap<String,ArrayList<Integer>> tm=new TreeMap<String,ArrayList<Integer>>(); 
		ArrayList<String> AL=new ArrayList<String>();

		while(in.hasNext())
		{
			String st=in.next();
			int n=in.nextInt();
			if(tm.containsKey(st))
			{
				tm.get(st).add(n);
				Collections.sort(tm.get(st));
			}
			else
			{
				AL.add(st);
				ArrayList<Integer>al=new ArrayList<Integer>();
				al.add(n);
				tm.put(st, al);
				Collections.sort(tm.get(st));
			}
		}
		Collections.sort(AL);
		for(int i=0;i<AL.size();i++)
		{
			System.out.println(AL.get(i));
			ArrayList AL2=tm.get(AL.get(i));
			for(int j=0;j<AL2.size()-1;j++)
				System.out.print(AL2.get(j)+" ");
			System.out.println(AL2.get(AL2.size()-1));
		}
	}
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 20296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a,b;
  int count = 0;
  for (int A =0; A<=100; A++){
    for (int B = 0; B<=100; B++){
      int X = 4*A + 7*B;
      if (X == N){count++;}
    }
  }
 if(count == 0){cout << "No" << endl;}
  else{cout << "Yes" << endl;}
}


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

using namespace std;
#define nn 12

int n,m;char buf[nn][nn];
int vis[nn][nn];
#define err {puts("Impossible");exit(0);}
int main()
{
	int x=0,y=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%s",buf[i]);
	
	while(x!=n-1 or y!=m-1)
	{
		if(buf[x][y]!='#') err;
		vis[x][y]=1;
		if(buf[x+1][y]=='#') x++;
		else if(buf[x][y+1]=='#') y++;
		else err;
	}
	vis[x][y]=1;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) 
		if(!vis[i][j] and buf[i][j]=='#') err;
	puts("Possible");
}

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

int main(){
  int n;
  cin >> n;
  int ans=0;
  if(n!=1){
  for(int i=2;i<=sqrt(n);i++){
    int a=1;
    while(pow(i,a)<=n){
      a++;
    }
    a=pow(i,a-1);
    ans=max(ans,a);
  }
  cout << ans << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 4108
import math
def factrial(n):
    factor = set()
    for i in range(1, int(math.sqrt(n)+1)):
        if n % i == 0:
            factor.add(i)
            factor.add(n//i)
    return factor

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n%m)

a, b = map(int, input().split())

fact_a = factrial(a)
fact_b = factrial(b)
fact_int = sorted(list(fact_a & fact_b))

choice = []
for i in fact_int:
    prime = True
    for j in choice:
        if gcd(i, j) != 1:
            prime = False
            break
    if prime:
        choice.append(i)

print(len(choice))

Measured memory_bytes: 5136
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
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;
}
const double pi = 3.14159265358979323846;

int main() {
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double time = 60.0 * H + M;
    long double t1 = pi * 2 * time / (60.0 * 12.0);
    long double t2 = pi * 2 * time / 60.0;
    long double xx = (sin(t1) * A - sin(t2) * B) * (sin(t1) * A - sin(t2) * B);
    long double yy = (cos(t1) * A - cos(t2) * B) * (cos(t1) * A - cos(t2) * B);
    long double res = sqrt(xx + yy);
    cout << setprecision(15)<<res << endl;
}


Measured memory_bytes: 4172
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s: Vec<char> = s.trim().chars().collect();
    let ans = if s[2] == s[3] && s[4] == s[5] {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4476
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
#include <functional>
 
using namespace std;
typedef long long ll;
const ll INF = 1e18;

# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()
# define pb push_back
 
ll N, M;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    double l;
    cin >> l;
    double ans = pow(l/3,3);
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

int main()
{
	int X,Y,Z;
    cin >> X >> Y >> Z;
	int k;
	k=X;
	X=Y;
	Y=k;
	k=X;
	X=Z;
	Z=k;
	
	cout << X << " " << Y << " " << Z <<endl;
	return 0;
}

Measured memory_bytes: 256
def number_of_digits(a,b):
    num_of_digits_a=1
    num_of_digits_b=1
    while a//10 !=0:
        a=a//10
        num_of_digits_a +=1
    while b//10 !=0:
        b=b//10
        num_of_digits_b +=1
    if num_of_digits_a >= num_of_digits_b:
        return(num_of_digits_a)
    else:
        return(num_of_digits_b)

N=int(input())
ans=0
for i in range(1,10**5+1):
    if N%i ==0:
        tmp = number_of_digits(i,N//i)
        if i==1:
            ans=tmp
        else:
            if ans>tmp:
                ans=tmp
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;

lint dp[2123][2123];

template<class T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
    lint n;
    cin >> n;

    vector<P> a(n);
    for(lint i=0; i<n; i++) {
        lint x;
        cin >> x;
        a.emplace_back(x, i);
    }
    sort(a.rbegin(), a.rend());

    fill(&dp[0][0], &dp[2123][0], -1e18);
    dp[0][0] = 0;
    for(lint all=0; all<n; all++) {
        auto [x, i] = a[all];
        for(lint mn=0; mn<=all; mn++) {
            chmax(dp[all+1][mn], dp[all][mn] + x * abs(n-1-all+mn-i));
            chmax(dp[all+1][mn+1], dp[all][mn] + x * abs(mn-i));
        }
    }

    cout << *max_element(begin(dp[n]), end(dp[n])) << endl;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s;cin>>s;
  int n=s.size()-1;
  if(s[n]=='3')cout<<"bon"<<endl;
  else if(s[n]=='0'||s[n]=='1'||s[n]=='6'||s[n]=='8')
  {
    cout<<"pon"<<endl;
  }
  else cout<<"hon"<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main() {
    int N{};
    cin >> N;
    if (N / 1000 > 0) {
        int remain = N % 1000;
        if (remain == 0)
            cout << remain;
        else
            cout << 1000 - remain;
    } else {
        cout << 1000 - N << endl;
    }
    return 0;
}


Measured memory_bytes: 3168
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt();
		boolean[][] s = new boolean[h][w];
		int[][] d = new int[h][w];
		int countInitialBlack = 0;
		for (int i = 0; i < h; i++) {
			String str = sc.next();
			for (int j = 0; j < w; j++) {
				s[i][j] = str.charAt(j) == '.';
				d[i][j] = -1;
				if(!s[i][j]) {
					countInitialBlack++;
				}
			}
		}
		
		Queue<Point> queue = new LinkedList<>();
		Point start = new Point(0, 0);
		Point goal = new Point(h-1, w-1);
		int tmpX, tmpY;
		
		queue.offer(start);
		d[start.y][start.x] = 0;
		int[] dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
		
		while(queue.size() > 0) {
			Point p = queue.poll();
			if(p.y == goal.y && p.x == goal.x) {
				break;
			}
			for(int i = 0; i < 4; i++) {
				tmpY = p.y + dy[i];
				tmpX = p.x + dx[i];
				
				if(0 <= tmpY && tmpY < h && 0 <= tmpX && tmpX < w 
						&& s[tmpY][tmpX] && d[tmpY][tmpX] == -1) {
					queue.offer(new Point(tmpY, tmpX));
					d[tmpY][tmpX] = d[p.y][p.x] + 1;
				}
					
			}
		}
		
		int minWhiteCell = d[h-1][w-1] + 1;
		if(d[h-1][w-1] != -1) {
			System.out.println(h * w - countInitialBlack - minWhiteCell);
		}else {
			System.out.println(-1);
		}
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

class Point {
	int x;
	int y;
	public Point(int y, int x) {
		this.y = y;
		this.x = x;
	}
	
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){   
   int n,m;
   cin>>n>>m;
   vector<int>a(m);

   rep(i,m){
      a[i]=0;
   }
   int b;
   rep(i,n){
      int k;
      cin>>k;
      rep(i,k){
         cin>>b;
         a[b-1]++;
      }
   }
   int count=0;
   rep(i,m){
      if(a[i]==n){
         count++;
      }
   }
   cout<<count;

  
   

return 0;
}

Measured memory_bytes: 256
//////////////////////////////////////////
/* ************************************ */
/*    @@@@@      X     X       @@@@@    */
/*   @     @      X   X       @     @   */
/*  @  @@@@ @      X X       @  @@@@ @  */
/* @  @   @  @      X       @  @   @  @ */
/*  @  @@@ @@      X X       @  @@@ @@  */
/*   @            X   X       @         */
/*    @@@@@      X     X       @@@@@    */
/* ************************************ */
//////////////////////////////////////////

//Tayyorgarchilik
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define AXA true
#define ishkal_tugadi 0
#define ishkal_boshlandi main
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))
#define pii pair<int,int>
#define ft first
#define sd second
#define vi vector <int>
#define si set <int>
#define db(x) cerr<<#x<<" = "<<x<<endl;
#define R(i,a,n) for(ll i=a; i<=n; i++)
#define RALL(i,a) for(auto i:a)
#define L(i,n,a) for (ll i=n; i>=a; i--)
#define standart 1
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
    return a*(b/gcd(a,b));
}
string sum(string a, string b){
    string ans="";
    R(i,0,max(SZ(a),SZ(b)))ans+='0';
    reverse(ALL(a));
    reverse(ALL(b));
    while (SZ(a)>SZ(b))b+='0';
    while (SZ(a)<SZ(b))a+='0';
    R(i,0,SZ(a)-1){
        int temp=int(ans[i]-'0');
        temp+=(a[i]-'0');
        temp+=(b[i]-'0');
        int j=0;
        while (temp>0){
            ans[i+j]=char((temp%10)+'0');
            temp/=10;
            j++;
        }
    }
    reverse (ALL(ans));
    while (ans[0]=='0' && SZ(ans)>1)ans.erase(0,1);
    return ans;
}
bool prime(ll x){
    if (x==0)return 1;
    if (x==1) return 0;
    R(i,2,sqrt(x)){
        if (x%i==0)return 0;
    }
    return 1;
}
bool palindrom(string s){
    string ss=s;
    reverse(ALL(ss));
    return ss==s;
}











int ishkal_boshlandi(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (!standart){
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }



    int n,a,b;
    cin>>n>>a>>b;
    if (abs(a-b)%2==0)cout<<"Alice";
    else cout<<"Borys";


    return ishkal_tugadi;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define FOR(var,start,end) for(int var=start; var<end; var++)
#define REP(var,cnt) FOR(var,0,cnt)

int main(void) {
	int A, B;
	cin >> A>> B;
	
	double test = (double)A + (double)B;
	int X = ceil(test/2);
	cout << X << endl;
}


Measured memory_bytes: 256
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 + 7 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	ll a = read(),b =  read();
	ll d = min(a*100/8,b*10);
	ll ans = 1;
	for(int i = d;i <= d + 10000;++i){
		if(i*8/100==a&&i/10==b) return cout << i,0;
	}
	puts("-1");
}


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

void solve() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  s1[0] = toupper(s1[0]);
  s2[0] = toupper(s2[0]);
  s3[0] = toupper(s3[0]);
  cout << s1[0] << s2[0] << s3[0];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>

#define rep(i, n) for (int i = 0; i < n; i++) 
#define rrep(i, n) for(int i = n-1; i>=0; i--)
#define range(i, n, m) for (int i = n; i < m; i++) 
#define rrange(i, n, m) for (int i = n - 1; i => m; i--) 
#define MOD 1000000007;

typedef long long int ll;
typedef unsigned long long int ull;


using namespace std;

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

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

	string S;
	ll N, Q;

	cin >> N >> Q;
	cin >> S;

	vector<ll> l(Q), r(Q);
	vector<ll> A(N);

	rep(i, Q) {
		cin >> l[i] >> r[i];
	}

	A[0] = 0;
	range(i, 1, N) {
		A[i] = A[i - 1];

		if (S[i - 1] == 'A' && S[i] == 'C') {
			A[i]++;
		}
	}



	rep(i, Q) {
		cout << dec << (A[r[i] - 1] - A[l[i] - 1]) << endl;
	}

	






	return 0;
}


Measured memory_bytes: 3408
#include <iostream>
using namespace std;
int main(void){
    int n,a,b;
    cin>>n>>a>>b;
    long long int ans=0;
    for(int i=1;i<=n;i++){
        int q=i;
        int sum=0;
        while(q!=0){
            sum+=q%10;
            q/=10;
        }
        if(a<=sum&&sum<=b)ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

using Int = int64_t;
using Uint = uint64_t;

int main() {
  Uint X;
  cin >> X;

  if (X == 2) {
    cout << 2 << endl;
    return 0;
  }

  for(Uint i=3;i<=1000000;i+=2) {
    Uint k=0;
    for(Uint j=3;j<=sqrt(i);j+=2) {
      if(i%j==0) {
        k=1;
        break;
      }
    }

    if(k==0 && i >= X)  {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


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

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

void solve(vector<vector<long long>> A, long long N, vector<long long> b){
    vector<vector<int>> check(3, vector<int>(3));
    for (long long bb : b) {
        for(int i = 0 ; i < 3 ; i++){
            for(int j = 0 ; j < 3 ; j++){
                if (A[i][j] == bb) {
                    check[i][j] = 1;
                }
            }
        }
    }

    for(int i = 0 ; i < 3 ; i++){
        // 横
        if (accumulate(check[i].begin(), check[i].end(), 0) == 3) {
            cout << YES << endl;
            return;
        }
    }
    for (int j = 0; j < 3; j++) {
        // 縦
        if (check[0][j] + check[1][j] + check[2][j] == 3) {
            cout << YES << endl;
            return;
        }
    }
    if (check[0][0] + check[1][1] + check[2][2] == 3) {
        cout << YES << endl;
        return;
    }
    if (check[0][2] + check[1][1] + check[2][0] == 3) {
        cout << YES << endl;
        return;
    }
    cout << NO << endl;
    return;
}

int main(){
    vector<vector<long long>> A(3, vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long N;
    scanf("%lld",&N);
    vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(move(A), N, move(b));
    return 0;
}


Measured memory_bytes: 256