Problem:
往復すごろく
JOI 高校の葵は新しいすごろくを購入した．このすごろくは
N+2
個のマスが横一列に並んだ形をしている．これらのマスには，左端のマスから右端のマスへと順に，
0
から
N+1
までの番号がついている．初め，マス
0
とマス
N+1
には
X
が，マス
i
(
1 ≦ i ≦ N
) には
S
i
が書かれている．ただし，
S
i
は文字
.
または
#
である．
葵はこのすごろくと
1
つの駒を使って遊んでいる．初め，駒はマス
A
(
1 ≦ A ≦ N
) に右を向いた状態で置かれている．ただし，
S
A
は文字
.
である．葵は
1
秒経つごとに，駒を向いている方向へ
1
マス移動させる．
このすごろくには次のような
ルール
が設定されている．
X
が書かれたマスに駒が乗ると，駒の向きは反転する．
.
が書かれたマスに駒が乗ったとしても，何も起こらない．
#
が書かれたマスに駒が乗ると，駒の向きは反転する．このとき，このマスに書かれた文字を
.
に変更する．したがって，その後はこのマスに駒が乗ったとしても向きは反転しない．
なお，駒の反転や文字の変更にかかる時間は無視できる．
すごろくと駒の初めの状態が与えられたとき，
#
が書かれたマスがすべてなくなるまでに要する時間を求めるプログラムを作成せよ．
制約
2 ≦ N ≦ 200000
．
1 ≦ A ≦ N
．
S
i
は文字
.
または
#
である (
1 ≦ i ≦ N
)．
S
A
は文字
.
である．
S
i
が文字
#
であるような
i
(
1 ≦ i ≦ N
) が少なくとも
1
つ存在する．
入力
入力は以下の形式で標準入力から与えられる．
N
A
S
ただし，
S
は長さ
N
の文字列で，その
i
文字目 (
1 ≦ i ≦ N
) は
S
i
である．
出力
標準出力に，
#
が書かれたマスがすべてなくなるまでに何秒かかるかを
1
行で出力せよ．
入出力例
入力例 1
7 3
.#.#..#
出力例 1
8
時間が経過するにつれてすごろくの状態は次のように変化する．ただし，右向きの駒が置かれたマスを
>
，左向きの駒が置かれたマスを
<
で表す．
X.#>#..#X
X.#.<..#X
X.#<...#X
X.>....#X
X..>...#X
X...>..#X
X....>.#X
X.....>#X
X......<X
したがって，
8
秒で
#
が書かれたマスがすべてなくなるので，
8
を出力する．
入力例 2
4 1
.#.#
出力例 2
7
時間が経過するにつれてすごろくの状態は次のように変化する．
X>#.#X
X.<.#X
X<..#X
>...#X
X>..#X
X.>.#X
X..>#X
X...<X
したがって，
7
秒で
#
が書かれたマスがすべてなくなるので，
7
を出力する．
入力例 3
6 6
#####.
出力例 3
35
情報オリンピック日本委員会
作 『第 20 回日本情報オリンピック JOI 2020/2021 二次予選競技課題』

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
using namespace std;
int main(void){
    vector<int> v;
    bool t={true};
    int n,a,c=0,i,j=0,k,vp,vc=0;
    string s;
    cin >> n >> a >> s;
    a-=1;
    n-=1;
    for(i=0;i<s.size();i++){
        if(s[i]=='#')v.push_back(i);
    }
    for(i=0;i<s.size();i++){
        if(s[i]=='#'){
            vc++;
        }
        if(s[i]=='#' and a<i){
            vp=vc-1;
            break;
        }
        vp=vc;
    }
    while(v.size()!=0){
  //     cout << a << ' ' << s[a] << endl;
        if(t==true){
            if(v.size()<=vp){
                c+=s.size()-a+1;
                t=false;
                vp=v.size()-1;
                a=s.size()-1;
            }
            else{
                c+=v[vp]-a;
                a=v[vp];
                t=false;
                v.erase(v.begin()+vp);
                vp--;
            }
        }
        else {
            if(vp==-1){
                c+=a+2;
                t=true;
                vp=0;
                a=0;
            }
            else{
                c+=a-v[vp];
                a=v[vp];
                t=true;
                v.erase(v.begin()+vp);
            }
        }
    }
    cout << c << endl;
}
accuracy: 0.6041666666666666
time_ms: 470
memory_kb: 3584
final_rank: 13

code_snippet: #include <iostream>
#include <set>
#include <functional>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	unsigned int N, A, i;
	unsigned long long time = 0;
	char S[200001];
	bool right = true;
	cin >> N >> A >> S;

	set<unsigned int> sharp_l;
	set<unsigned int, greater<unsigned int>> sharp_g;
	for (i = 0; i != N; ++i)
		if (S[i] == '#')
			sharp_l.insert(i + 1), sharp_g.insert(i + 1);

	for (; !sharp_l.empty(); right ^= true)
	{
		if (right)
		{
			auto itr = sharp_l.lower_bound(A);
			if (itr == sharp_l.end()) time += (N + 1) - A, A = N + 1;
			else time += *itr - A, A = *itr, sharp_g.erase(sharp_g.find(*itr)), sharp_l.erase(itr);
		}
		else
		{
			auto itr = sharp_g.lower_bound(A);
			if (itr == sharp_g.end()) time += A, A = 0;
			else time += A - *itr, A = *itr, sharp_l.erase(sharp_l.find(*itr)), sharp_g.erase(itr);
		}
	}

	cout << time << '\n';
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 22304
final_rank: 10

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

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

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, A;
  string S;
  cin >> N >> A >> S;
  ll dir = 1;
  set<ll> h;
  S = "X" + S + "X";
  rep(i, len(S)) {
    if (S[i] != '.') h.insert(i);
  }
  ll rem = len(h) - 2;
  ll ans = 0;
  while (rem > 0) {
    if (dir == 1) {
      auto lb = h.lower_bound(A+1);
      ans += *lb - A;
      A = *lb;
      if (*lb <= N) {
        h.erase(lb);
        rem--;
      }
    } else {
      auto lb = h.lower_bound(A);
      lb--;
      ans += A - *lb;
      A = *lb;
      if (lb != h.begin()) {
        h.erase(lb);
        rem--;
      }
    }
    dir = -dir;
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 12840
final_rank: 4

code_snippet: #line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 3 "/home/kuhaku/home/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/home/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/home/github/algo/lib/template/atcoder.hpp"
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 3 "a.cpp"

int main(void) {
    int n, m;
    cin >> n >> m;
    --m;
    string s;
    cin >> s;

    set<int> st;
    st.emplace(-1);
    st.emplace(n);
    rep (i, n) {
        if (s[i] == '#')
            st.emplace(i);
    }

    bool f = true;
    ll ans = 0;
    while (st.size() > 2) {
        if (f) {
            int x = *st.upper_bound(m);
            ans += x - m;
            if (x != n) {
                st.erase(x);
            }
            m = x;
        } else {
            int x = *prev(st.lower_bound(m));
            ans += m - x;
            if (x != -1) {
                st.erase(x);
            }
            m = x;
        }
        f = !f;
    }
    co(ans);

    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 12760
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n, now;
    cin >> n >> now;
    string str;
    cin >> str;
    set<int> s;
    for (int i = 0; i < n; i++) {
        if (str[i] == '#') s.insert(i + 1);
    }
    s.insert(0);
    s.insert(n + 1);
    bool is_right = true;
    long long ans = 0;
    while (s.size() > 2) {
        if (is_right) {
            auto it = s.upper_bound(now);
            ans += *it - now;
            now = *it;
        } else {
            auto it = prev(s.lower_bound(now));
            ans += now - *it;
            now = *it;
        }
        if (now != 0 && now != n + 1) {
            s.erase(now);
        }
        is_right ^= true;
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 60
memory_kb: 12820
final_rank: 8

code_snippet: #include <iostream>
#include<set>
#include <cmath>
using namespace std;
set<int> ss;
string str;
int main() {
	int n,p,r;
	long long int ans;
	cin>>n>>p;
	cin>>str;
	r=1;
	for(int i=0;i<n;i++){
		if(str[i]=='#'){
			ss.insert(i+1);
		}
	}
	ss.insert(0);
	ss.insert(n+1);
	ans=0;
	while(ss.size()>2){
		int p2;
		if(r==1){
			p2=(*(ss.upper_bound(p)));
		}else{
			set<int>::iterator it=ss.lower_bound(p);
			it--;
			p2=(*it);
		}
		ans+=abs(p2-p);
		if(p2!=0 && p2!=n+1){
			ss.erase(p2);
		}
		p=p2;
		r*=-1;
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 12568
final_rank: 7

code_snippet: #include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
//wordol

int main()
{
    long n,a,ans=0,k,way;
    cin>>n>>a;
    string s;
    cin>>s;
    vector <int>left,right;
    for (int i=0;i<n;i++){
        if (s[i]=='#'){
            if (a>i+1) left.push_back(i+1);
            else right.push_back(i+1);
        }
    }
    
    //for(int i=0;i<left.size();i++)cout<<left[i]<<" ";
    //cout<<endl;
    //for(int i=0;i<right.size();i++)cout<<right[i]<<" ";
    
    //cout<<endl<<endl;
    way=min(left.size(),right.size());
    if(left.size()==right.size()) ans-=abs(a-left[0]);
    //cout<<"w"<<way<<endl;
    for(int i=0;i<way;i++){
        
        k=left.size();
        ans+=abs(right[0]-a)*2+abs(left[k-1]-a)*2;
        //cout<<ans<<"-";
        right.erase(right.begin()+0);
        left.erase(left.begin()+k-1);
        
    }
    
    if(left.size()==right.size()) {
    cout<<ans<<endl; 
    return 0;
    }
    
    if(right.size()==1) {
    cout<<ans+(right[0]-a)<<endl; 
    return 0;
    }
    
    if(right.size()>1){
        for (int i=0;i<right.size()-1;i++) ans+=a*2+abs(right[i]-a)*2;
        ans+=right[right.size()-1]-a;
    }
    
     if(left.size()>0){
        for (int i=left.size()-1;i>0;i--) ans+=(n-a+1)*2+abs(left[i]-a)*2;
        ans+=a-left[0]+(n-a+1)*2;
    }
    
    cout<<ans<<endl;
    
}
accuracy: 1
time_ms: 580
memory_kb: 4020
final_rank: 9

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	vector<int> left, right;
	int n, a,k,to=1,ans=0,now;
	cin >> n >> a;
	string s;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == '#') {
			if (i+1 < a) left.push_back(i+1);
			if (i+1 > a) right.push_back(i+1);
		}
	}

	


	now = a;
	//to=1で右 -1で左
	while (left.size()>0 || right.size()>0) {

		/*
		cout << "now:" << now << "ans:" << ans << endl;
		
		cout << "left:";
		k = (int)left.size();
		for (int i = 0; i < k; i++) {
			cout << left[i] << " ";
		}

		cout << "\nright:";
		k = (int)right.size();
		for (int i = 0; i < k; i++) {
			cout << right[i] << " ";
		}
		
		cout << "\n";
		*/

		if (to == 1) {
			if (right.size()>0) {
				ans += abs(now - right[0]);
				now = right[0];
				to = -1;
				right.erase(right.begin() + 0);
			}
			else {
				to = -1;
				ans += (n - now + 1) * 2;
			}
		}
		else {
			if (left.size()>0) {
				//cout << "a";
				k = (int)left.size();
				ans += abs(now - left[k-1]);
				now = left[k-1];
				to = 1;
				left.erase(left.begin() + k-1);
			}
			else {
				to = 1;
				ans += now* 2;
			}
		}

	}
	
	cout << ans << endl;
}
accuracy: 0.6041666666666666
time_ms: 300
memory_kb: 3884
final_rank: 12

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0691.cc: 往復すごろく
 */

#include<cstdio>
#include<set>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;
typedef set<int> si;

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  int n, a;
  scanf("%d%d%s", &n, &a, s);

  si rs;
  for (int i = 0; i < n; i++)
    if (s[i] == '#') rs.insert(i + 1);
  rs.insert(0), rs.insert(n + 1);

  ll t = 0;
  int di = 1;
  while (rs.size() > 2) {
    //printf("%d -> ", a);
    si::iterator sit = rs.lower_bound(a);
    if (di > 0) {
      if (*sit == a) sit++;
      t += *sit - a;
      a = *sit;
      if (*sit <= n) rs.erase(sit);
    }
    else {
      sit--;
      t += a - *sit;
      a = *sit;
      if (*sit > 0) rs.erase(sit);
    }
    di *= -1;
    //printf("%d\n", a);
  }

  printf("%lld\n", t);

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 12572
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N, A;
    string S;
    cin >> N >> A >> S;
    set<ll> P;
    P.insert(0);
    P.insert(N + 1);
    rep(i, N)if (S[i] == '#')P.insert(i + 1);
    ll an = 0;
    bool D = 1;
    while (P.size() > 2) {
        if (D == 1) {
            auto p = P.upper_bound(A);
            an += *p - A;
            A = *p;
            if (*p != N + 1)P.erase(*p);
        }
        else {
            auto p = P.lower_bound(A);
            p--;
            an += A - *p;
            A = *p;
            if (*p != 0)P.erase(*p);
        }
        D =!D;
    }
    cout << an << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 12820
final_rank: 6

code_snippet: #include <iostream>
#include <string>
#include <set>

using namespace std;

int main()
{
	int N, A; cin >> N >> A;
	string S; cin >> S;
	set<int> SS;
	for (int i = 0; i < N; ++i) if (S[i] == '#') SS.insert(i + 1);
	int_fast64_t t = 0;
	for (auto p = SS.upper_bound(A);;) {
		if (p != SS.end()) {
			t += *p - A;
			A = *p;
			p = SS.erase(p);
			if (SS.empty()) break;
		} else {
			t += N + 1 - A;
			A = N + 1;
		}
		if (p != SS.begin()) {
			--p;
			t += A - *p;
			A = *p;
			p = SS.erase(p);
			if (SS.empty()) break;
		} else {
			t += A;
			A = 0;
		}
	}
	cout << t << endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 12820
final_rank: 3

code_snippet: #include <iostream>
#include <string>
#include <set>

using namespace std;

int main()
{
	int N, A; cin >> N >> A;
	string S; cin >> S;
	set<int> SS;
	for (int i = 0; i < N; ++i) if (S[i] == '#') SS.insert(i + 1);
	int t = 0;
	for (auto p = SS.upper_bound(A);;) {
		if (p != SS.end()) {
			t += *p - A;
			A = *p;
			p = SS.erase(p);
			if (SS.empty()) break;
		} else {
			t += N + 1 - A;
			A = N + 1;
		}
		if (p != SS.begin()) {
			--p;
			t += A - *p;
			A = *p;
			p = SS.erase(p);
			if (SS.empty()) break;
		} else {
			t += A;
			A = 0;
		}
	}
	cout << t << endl;
	return 0;
}
accuracy: 0.6041666666666666
time_ms: 10
memory_kb: 8040
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e18;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
int main() {
    ll N, A; cin >> N >> A;
    string S; cin >> S;
    priority_queue<ll>left;
    priority_queue<ll, vector<ll>, greater<ll>>right;
    for (ll i = 1; i <= N; i++) {
        if (S[i - 1] == '#') {
            if (i < A) left.push(i);
            else right.push(i);
        }
    }
    left.push(0LL); right.push(N + 1);
    ll ans = 0;
    bool check = true;
    while (left.size() != 1 || right.size() != 1) {
        if (check) {
            ans += abs(A - right.top());
            A = right.top();
            if (right.top() != N + 1) right.pop();
        }
        else {
            ans += abs(A - left.top());
            A = left.top();
            if (left.top() != 0) left.pop();
        }
        check = !check;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5636
final_rank: 1