akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/math/common_factor.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

ll mymod(ll dividend, ll divisor) {
    return dividend >= 0 ? dividend % divisor : dividend % divisor + abs(divisor);
};

ll mydiv(ll dividend, ll divisor) {
    ll modulo = dividend >= 0 ? dividend % divisor : dividend % divisor + abs(divisor);
    return (dividend - modulo) / divisor;
};


pair<ll, ll> divmod(ll dividend, ll divisor){
    ll modulo = dividend >= 0 ? dividend % divisor : dividend % divisor + abs(divisor);
    return make_pair((dividend - modulo) / divisor, modulo);
};

bool sub(ll a, ll b, ll c, ll d){
    if (a < b || b > d)return false;
    else {
        ll m = boost::math::gcd<ll>(b, d);
        ll r = mymod(a, m);
//        在庫はmの倍数+r個にしかならない
//        逆に，mの倍数+r個は全部移動してしまう
//        ギリギリ補充されない状況は夜にc+1に一番近いmの倍数+r個の状態
//        この状態でb個以上あれば生き残れる
//        z = (c+1に一番近い，[mの倍数+r]個)
//        ところで，(double)型の(c+1-r)/mを考えると，
//        (c+1-r)/m * m + r == c+1となる
//        llについて/を切り捨て演算と考えると，
        ll z = mydiv(c+1-r, m) * m + r + ((c + 1 - r) % m == 0 ? 0 : m);
        if (z >= b) {
            return true;
        } else {
            return false;
        }
    }
}


int main() {
    ll T;
    cin >> T;
    for (auto && i: irange(0LL, T)){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if (sub(a, b, c, d)){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(b%a == 0){
        cout << a+b;
    }
    else{
        cout << b-a;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll d=n/(a+b);
  ll ans=d*a;
  n%=a+b;
  pr(ans+min(n,a));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 764
import heapq

N, K = map(int, input().split())
V = [int(s) for s in input().split()]

ans = 0
for i in range(N+1):
    for j in range(N+1):
        if i + j > min(K, N):
            continue
        que = []
        for k in range(i):
            heapq.heappush(que, V[k])
        for k in range(j):
            heapq.heappush(que, V[-k-1])

        for l in range(K-i-j):
            if len(que) == 0 or que[0] > 0:
                break
            heapq.heappop(que)

        #print(i, j, K-i-j, que)

        ans = max(ans, sum(que))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


const int INF = 1<<29;        // 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int k;
queue<vector<int>> que;
vector<vector<int>> v;

// bool check(int x, int y) {
//     if(x < 0 || x >= r || y < 0 || y >= c || maze[x][y] == '#') {
//         return false;
//     }
//     if(reached[x][y]) {
//         return false;
//     }
    
//     reached[x][y] = true;
 
//     return true;
// }
 
 ll printnum(vector<int> n) {
    ll sum = 0;
    REP(i, n.size()) {
        cout << n[i];
    }
    cout << endl;;
    return sum;
}
int main() {

    cin >> k;

    REP(i, 9) {
        vector<int> n(1);
        n[0] = i+1;
        que.push(n);
    }
    int cnt = 0;
    while(!que.empty()) {
        vector<int> n = que.front();
        que.pop();
        // printnum(n);
        cnt++;
        if(cnt == k) {
            printnum(n);
            return 0;
        }

        int suf = n[n.size()-1];
        if(suf == 0) {
            vector<int> n2(n.size());
            copy(n.begin(), n.end(), n2.begin());
            n2.push_back(0);
            que.push(n2);
            

            vector<int> n3(n.size());
            copy(n.begin(), n.end(), n3.begin());
            n3.push_back(1);
            que.push(n3);
            // printnum(n3);

        } else if(suf >= 1 && suf <= 8) {
            vector<int> n2(n.size());
            copy(n.begin(), n.end(), n2.begin());
            n2.push_back(suf-1);
            que.push(n2);
            // printnum(n2);
            
            vector<int> n3(n.size());
            copy(n.begin(), n.end(), n3.begin());
            n3.push_back(suf);
            que.push(n3);
            // printnum(n3);

            vector<int> n4(n.size());
            copy(n.begin(), n.end(), n4.begin());
            n4.push_back(suf+1);
            que.push(n4);
            // printnum(n4);

        } else if(suf == 9) {
            vector<int> n2(n.size());
            copy(n.begin(), n.end(), n2.begin());
            n2.push_back(suf-1);
            que.push(n2);
            
            vector<int> n3(n.size());
            copy(n.begin(), n.end(), n3.begin());
            n3.push_back(suf);
            que.push(n3);
            // printnum(n3);
        } 
    }
 
}
 
 

Measured memory_bytes: 15360
N=int(input())
H=list(map(int,input().split()))

A=[0 for _ in range(N)]

number=0

for i in range(N-1):
    if H[i]<H[i+1]:
        A[i]=number
        number=0
    else:
        number+=1
        if i==N-2:
            A[i+1]=number

print(max(A))





Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();

		if(S.charAt(S.length() - 1) == 's'){
			System.out.println(S + "es");
		}
		else{
			System.out.println(S + "s");
		}
		stdIn.close();
	}
}

Measured memory_bytes: 38400
#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include<iomanip>



#define ll long long
using namespace std;


ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;

    return n * factorial(n - 1);
}


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

    ll n;
    cin >> n;
    ll arr[n][3];
    ll dp[n + 1][3];
    for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) cin >> arr[i][j];

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    ll ans = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            dp[i][j] = 0;
            for (int z = 0; z < 3 ; z++)
            {
                if (j == z) continue;
                dp[i][j] = max(dp[i - 1][z] + arr[i - 1][j], dp[i][j]);
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        long n,k; cin>>n>>k;
        cout<<min({n%k,k-n%k,n})<<endl;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int na, nb, m;
  cin >> na >> nb >> m;
  vi a(na), b(nb);
  rep(i, na) cin >> a[i];
  rep(i, nb) cin >> b[i];
  int ans = 0;
  int mina = INF;
  int minb = INF;
  rep(i, na) mins(mina, a[i]);
  rep(i, nb) mins(minb, b[i]);
  ans = mina + minb;
  rep(i, m) {
    int x, y, c;
    cin >> x >> y >> c;
    int sum = a[x - 1] + b[y - 1] - c;
    mins(ans, sum);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

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

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

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int K, X;
    cin >> K >> X;
    YESNO(K * 500 >= X, "Yes", "No");
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

class TaskD {
 public:
  void solve(std::istream &in, std::ostream &out) {
    int N, Z, W;
    in >> N >> Z >> W;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
      in >> A[i];
    }

    int diff = abs(A[N - 1] - W);
    if (N > 1) {
      diff = max(diff, abs(A[N - 2] - A[N - 1]));
    }
    out << diff;
  }
};


int main() {
  TaskD solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}
 
int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}



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

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

    int n;cin>>n;
    vector<int> v(n),p(n),q(n);
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++)cin>>q[i];
    for(int i=0;i<n;i++)v[i]=i+1;

    int a=0,b=0;

    int pos=1;
    while(a==0||b==0)
    {
        if(a==0)
        {   
            int i=0;
            for(;i<n;i++)if(v[i]!=p[i])break;
            if(i==n)a=pos;
        }
        if(b==0)
        {   
            int i=0;
            for(;i<n;i++)if(v[i]!=q[i])break;
            if(i==n)b=pos;
        }

        pos++;
        next_permutation(v.begin(),v.end());
    }

    cout<<abs(a-b)<<"\n";

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<string>
using namespace std;
 
int main() {
    string moji;
    int a,b,i;
    for(i=0;i<9;i++){
        cin>>moji;
        cin>>a>>b;
        cout<<moji<<" "<<a+b<<" "<<a*200+b*300<<endl;
    }
    return 0;
}

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

using namespace std;

int main(){
    const int64_t INF = 1e18;
    const int INF_INT = 1e9;
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int64_t>> D(n + 1, vector<int64_t>(n + 1, INF));
    for (int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        D[a][b] = c;
        D[b][a] = c;
    }

    for (int i = 0; i <= n; i++)
        D[i][i] = 0;

    for (int k = 0; k <= n; k++){
        for (int i = 0; i <= n; i++){
            for (int j = 0; j <= n; j++){
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
            }
        }
    }
    vector<vector<int>> DP(n + 1, vector<int>(n + 1, INF_INT));
    for (int i = 0; i <= n; i++){
        DP[i][i] = 0;
        for (int j = 0; j <= n; j++){
            if (D[i][j] <= l)
                DP[i][j] = 0;
        }    
    }

    for (int k = 0; k <= n; k++){
        for (int i = 0; i <= n; i++){
            for (int j = 0; j <= n; j++){
                DP[i][j] = min(DP[i][j], DP[i][k] + DP[k][j] + 1);
            }
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++){
        int s, t;
        cin >> s >> t;
        cout << (DP[s][t] == INF_INT ? -1 : DP[s][t]) << endl;
    }
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector <vector<int>>;
using vvl = vector <vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> d(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    cin >> d[i];
  }
  bool ok = false;
  for (int i = 2; i < n; i++)
    if (d[i * 2 - 4] == d[i * 2 - 3] && d[i * 2 - 2] == d[i * 2 - 1] && d[i * 2] == d[i * 2 + 1])ok = true;
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int l,r;
  int ans=0;
  for(int i=0;i<n;i++){
    cin >> l >> r;
    r-=l;
    ++r;
    ans+=r;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, Q int
	fmt.Scan(&N)
	S := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&S[i])
	}
	fmt.Scan(&Q)
	T := make([]int, Q)
	for i := 0; i < Q; i++ {
		fmt.Scan(&T[i])
	}
	var count int
	for _, t := range T {
		for _, s := range S {
			if t == s {
				count++
				break
			}
		}
	}
	fmt.Println(count)
}



Measured memory_bytes: 1688
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c) {
    if (a % 2 == 0) cout << -1 << endl;
    if (a % 2 == 1) cout << 0  << endl;
    return 0;
  }

  int idx = 0;
  while (true) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
      cout << idx << endl;
      return 0;
    }
    idx++;
    int A = (b+c)/2;
    int B = (c+a)/2;
    int C = (a+b)/2;

    a = A; b = B; c = C;
  }
  return 0;
}

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

int main() {
  
  string a, b, c;
  cin >> a >> b >> c;
 
  cout << 'A' << b[0] << 'C' << endl;

}

Measured memory_bytes: 256
//om namah shivaaay//
#include <bits/stdc++.h>
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
 #define ll long long
 using namespace std;
 int main()
 {
    Om_namah_Shivaay;
     float r;
      double f =3.14159;
  
    cin>>r;
    cout<<setprecision(25)<<r*f*2;
}


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

#define mod 1000000007

int totalPaths(int grid[1005][1005], int h, int w) {

	int dp[1005][1005] = {0};
	dp[h - 1][w - 1] = 0;
	dp[h - 1][w - 2] = 1;
	dp[h - 2][w - 1] = 1;
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (grid[i][j] == 0) {
				if (i + 1 <= h - 1) {
					dp[i][j] += dp[i + 1][j];
				}
				if (j + 1 <= w - 1) {
					dp[i][j] = ((dp[i][j] % mod) + (dp[i][j + 1] % mod)) % mod;
				}
			} else {
				dp[i][j] = 0;
			}
		}
	}

	return  dp[0][0];
}


int main() {
	int h, w;
	cin >> h >> w;
	int grid[1005][1005];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char x;
			cin >> x;
			x == '.' ? grid[i][j] = 0 : grid[i][j] = 1;
		}
	}
	cout << totalPaths(grid, h, w) << endl;
}

Measured memory_bytes: 10972
count= -1
flag = 1

num_list = [0]*int(input())
num_list = [int(x) for x in input().split()]

while 1:
    i=0
    for x in num_list:
        if x%2==1:
            flag = 0
            break
        else:
            num_list[i]=num_list[i]/2
        i=i+1
    count = count + 1
    if flag==0:
        break


print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>

using namespace std;

int main(){
    int n;
    int a[22];
    while(cin>>n,n){
        for(int i=0;i<n;i++)
            cin>>a[i];
        unsigned long long l=0;
        int mi=INT_MAX;
        while(l<(1<<n)){
            int p=0,q=0;
            for(int i=0;i<n;i++){
                if((l>>i)&1)
                    p+=a[i];
                else
                    q+=a[i];
            }
            mi=min(abs(q-p),mi);
            l++;
        }
        cout<<mi<<endl;
    }
    
}

Measured memory_bytes: 1160
import sys
N, A, B = map(int, input().split())
if A > B:
    print(0)
    sys.exit()
if N == 1:
    if A != B:
        print(0)
        sys.exit()
    else:
        print(1)
        sys.exit()
else:
    mn = A*(N-1) + B
    mx = A + B*(N-1)
    ans =mx -mn + 1
    print(ans)


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

int main()
{
	int N, Y;
	cin >> N >> Y;
	for(int i=0; i<=N && 1000*i<=Y; ++i){
		int price = 10000*i;
		for(int j=0; j<=N && price<=Y; ++j){
			if(i+j == N && price == Y){
				cout << i << " " << j << " " << 0 << endl;
				return 0;
			}
			if( (N-i-j)*1000 == (Y-price) ){
				cout << i << " " << j << " " << (N-i-j) << endl;
				return 0;
			}
			price += 5000;
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

	for (int i = 0;i < k;i++) {
		cout << "ACL";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=1e9+7;
const int N=1e6+5;
ll add(ll a, ll b){a+=b; if(a>=MOD)a-=MOD; return a;}
ll sub(ll a, ll b){a-=b; if(a<0)a+=MOD; return a;}
ll mult(ll a, ll b){return (a*b)%MOD;}
ll h,w,n,dp[N];

ll fact[N],rf[N];
pair<ll,ll> A[N];
ll be(ll b, ll e){
	ll r=1;
	while(e)if(e&1)r=mult(r,b),e^=1;else b=mult(b,b),e>>=1;
	return r;
}
ll cmb(ll n, ll k){
	return mult(fact[n],mult(rf[k],rf[n-k]));
}

int main(){FIN;
	cin >> h >> w >> n;
	fact[0]=rf[0]=1;
	fore(x,1,N)fact[x]=mult(fact[x-1],x),rf[x]=be(fact[x],MOD-2);
	A[0]={1,1};
	vector<pair<ll,int> > B = {{2,0}};
	fore(x,1,n+1)cin>>A[x].fst>>A[x].snd,B.pb({A[x].fst+A[x].snd,x});
	n++;
	A[n]={h,w};B.pb({h+w,n});
	sort(ALL(B));
	dp[0]=1;
	fore(i,1,n+1){
		int x=B[i].snd;
		dp[x] = cmb(A[x].fst+A[x].snd-2,A[x].fst-1);
		fore(j,1,i){
			int y=B[j].snd;
			if(A[y].fst<=A[x].fst&&A[y].snd<=A[x].snd){
				ll dx = A[x].fst - A[y].fst;
				ll dy = A[x].snd - A[y].snd;
				dp[x] = sub(dp[x],mult(dp[y],cmb(dx+dy,dy)));
			}
		}
	}
	cout<<dp[n]<<"\n";
}

Measured memory_bytes: 18816
#include<stdio.h>

int main(){

	int N;
	int c=0; 
	double ans;
	
	scanf("%d", &N);

	for( int i=1; i<=N; i++ ){
		int num = i%2;
		if( num == 1 ){
			c++;
		}
	}

	double c2 = c;
	double N2 = N;

	ans = c2/N2;
	printf("%f\n", ans);

	return 0;
}

Measured memory_bytes: 128
a = list(input())
b = list(input())
c = list(input())

s = a.pop(0)

while True:
    if s == 'a':
        if a == []:
            print('A')
            break
        s = a.pop(0)
    elif s == 'b':
        if b == []:
            print('B')
            break
        s = b.pop(0)
    else:
        if c == []:
            print('C')
            break
        s = c.pop(0)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
    int a,b;

    cin >> a >> b;

    if(a == 1)a = 14;
    if(b == 1)b = 14;

    if(a > b)cout << "Alice"<<endl;
    else if(a < b)cout << "Bob"<<endl;
    else cout << "Draw" <<endl;
    
    return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  int x = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I'){
      x++;
    }else{
      x--;
    }
    ans = max(ans,x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b;
	cin >> a;
	cin >> b;
	int cnt=0;
	for(int i=0; i<=2; i++){
		if(a[i]==b[i]){
			cnt++;
		}
	}
	cout << cnt << endl;
}

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

string s;
int i;

int char2num(){
    int n = 0;
    for (; '0' <= s[i] && s[i] <= '9' && i < s.size(); i++){
	n *= 10;
	n += s[i] - '0';
    }
    return n;
}

int main(){

    int n = 0;
    while (cin >> s){
	for (i = 0; i < s.size(); i++)
	    if ('0' <= s[i] && s[i] <= '9') n += char2num();
    }
    cout << n << endl;
}

Measured memory_bytes: 0
n, k = map(int, input().split())
N = 10 ** 9 + 7

def kai(a):
    res = 1
    for i in range(1, a+1):
        res = res * i
    return res

def cmb(n, r):
    return kai(n) // kai(r) // kai(n-r)
#
# for i in range(1, k + 1):
#     nao = cmb(k - 1, i - 1)
#     nak = cmb(n - k + 1,  i)
#     print(nao * nak % N)

ans = 0
for i in range(1, k+1):
    if i == 1:
        ans = cmb(k - 1, i - 1) * cmb(n - k + 1,  i)
    print(ans  % N)
    ans = ans * (k - i) // i * (n - k - i + 1) // (i + 1)


Measured memory_bytes: 3316
N, Y = map(int, input().split())

for y10k in range(N + 1):
	for y5k in range(0, N - y10k + 1):
		y1k = max(0, N - y10k - y5k)
		if Y == y10k * 10000 + y5k * 5000 + y1k * 1000:
			print(y10k, y5k, y1k)
			exit()
else:
	print(-1, -1, -1)


Measured memory_bytes: 41564
#include <bits/stdc++.h>
#define maxn 209
using namespace std;
int n,m;
int a[maxn][maxn];
long long dp[maxn][maxn][maxn];
int dx[]={1,0};
int dy[]={0,1};
const long long INF=1e18;
bool in(int x,int y){
    return 1<=x&&x<=n&&1<=y&&y<=m;
}
long long dfs(int x,int y,int z){
    if(!in(x,y)||!in(z,x+y-z))
        return -INF;
    if(x==n&&y==m&&z==n)
        return a[x][y];
    long long &ans=dp[x][y][z];
    if(ans!=-1) return ans;
    int add;
    if(x==z)
        add=a[x][y];
    else
        add=a[x][y]+a[z][x+y-z];
    ans=0;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            ans=max(ans,dfs(x+dx[i],y+dy[i],z+dx[j]));
        }
    }
    ans+=add;
    return ans;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    memset(dp,-1,sizeof(dp));
    cout<<dfs(1,1,1)<<endl;
    return 0;
}


Measured memory_bytes: 71808
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N, 0);
    // flag=1なら単調増加,flag=0なら単調減少
    ll ans = 1, flag = -1;
    rep(0, i, N)
    {
        cin >> A.at(i);
        if (i == 0)
        {
            continue;
        }
        if (flag == -1)
        {
            if (A.at(i) - A.at(i - 1) < 0)
            {
                flag = 0;
            }
            if (A.at(i) - A.at(i - 1) > 0)
            {
                flag = 1;
            }
            continue;
        }
        // 単調増加だったのに単調減少に切り替わった
        if ((A.at(i) - A.at(i - 1) < 0) && flag == 1)
        {
            ans++;
            flag = -1;
        }
        // 単調減少だったのに単調増加になった
        if ((A.at(i) - A.at(i - 1) > 0) && flag == 0)
        {
            ans++;
            flag = -1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,count = 0;
    cin >> n;

    vector<int>v(n);
    vector<int>check(3);

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

    for(int i = 0;i < n-2;i++){
        for(int j = i;j < i+3;j++){
            check[j-i] = v[j];
        }
        sort(check.begin(),check.end());
        if(v[i+1] == check[1])count++;
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static class UnionFind {
		int[] param;
		int[] rank;
		int N;
		int xlen;
		
		public UnionFind(int n) {
			N=n;
			param = new int[N];
			rank = new int[N];
			for(int i=0; i<N; i++)
				param[i] = i;
		}
		
		public void init() {
			for(int i=0; i<N; i++)
				param[i] = i;
			Arrays.fill(rank, 0);
		}
		
		public UnionFind(int x, int y) {
			this(x*y);
			xlen=y;
		}
		
		public boolean same(int a, int b) {
			return getRoot(a)==getRoot(b);
		}
		
		public boolean same(int x1, int y1, int x2, int y2) {
			return same(x1*xlen+y1, x2*xlen+y2);
		}
		
		public int getRoot(int a) {
			if(param[a]==a) return a;
			else return (param[a] = getRoot(param[a]));
		}
		
		public void unite(int a, int b) {
			a = getRoot(a);
			b = getRoot(b);
			if(a==b)
				return;
			
			if(rank[a] < rank[b]) {
				param[a] = b;
			} else {
				param[b] = a;
				if(rank[a]==rank[b])
					rank[a]++;
			}
		}
		
		public void unite(int x1, int y1, int x2, int y2) {
			unite(x1*xlen+y1, x2*xlen+y2);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		UnionFind uf = new UnionFind(N*2);
		boolean[] Connected = new boolean[N];
		for(int i=0; i<M; i++) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			uf.unite(u, N+v);
			uf.unite(N+u, v);
			Connected[u] = Connected[v] = true;
		}
		
		HashSet<Integer> roots = new HashSet<>();
		long oddRoopCluster = 0;
		long solo = 0;
		for(int i=0; i<N; i++) {
			if(Connected[i]) {
				int r = uf.getRoot(i);
				if(!roots.contains(r)) {
					roots.add(r);
					if(r == uf.getRoot(N+i)) {
						oddRoopCluster++;
					}
				}
			} else {
				solo++;
			}
		}
		long cluster = (roots.size()+oddRoopCluster)/2;
		
		long ans = (cluster * cluster) + (cluster-oddRoopCluster)*(cluster-oddRoopCluster) + ((long)N*N-(N-solo)*(N-solo));
		System.out.println(ans);
		sc.close();
	}
}


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

using namespace std;
typedef long long ll;
#define pi M_PI
#define gcd(a,b) __gcd(a,b)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fr first
#define sc second
#define pb push_back
#define in insert
#define mp make_pair
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define inmas(i,a,b,c)cin>>b;forr(i,a,b)cin>>c[i]
#define mod 1000000007
ll n,m,ans=0,k,s=0;
int main()
{
cin>>n;
if(n%111!=0)ans=1;
k=n/111;
forr(i,0,3)
cout<<k+ans;





return 0;
}


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

int main() {
    int n,k;
    cin >> n >> k;
    
    vector<int> a_cnt(n+1,0);
    int ai;
    int k0=0;
    for (int i = 0; i < n; i++){
        cin >> ai;;
        if(a_cnt[ai]==0){
            k0++;
        }
        a_cnt[ai]++;
    }
    
    sort(a_cnt.begin(),a_cnt.end());
    ai=1;
    while(a_cnt[ai]==0){
        ai++;
    }
    
    int ans=0;
    for (int i = ai; i < ai+max(0,k0-k) ; i++){
        ans=ans+a_cnt[i];
    }

    cout << ans << endl;

}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	long long N, K;
	cin>>N>>K; N%=K;
	cout<<min(N,K-N)<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  string s;
  char me;
  cin >> s;
  if(s == "AAA" || s == "BBB"){
  cout << "No\n";	
  }
  else {
    cout << "Yes\n";
  }
  
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int32 N, C;
vector<vector<int64>> D;
vector<vector<int64>> c;
vector<int64> num[3], cost[3];

int main(void){
	cin >> N >> C;
	D = vector<vector<int64>>(C, vector<int64>(C));
	c = vector<vector<int64>>(N, vector<int64>(N));
	REP(i, 3) cost[i] = vector<int64>(C, 0);

	REP(i, C) REP(j, C) cin >> D[i][j];
	REP(i, N) REP(j, N) cin >> c[i][j];

	REP(i, N){
		REP(j, N){
			REP(k, C){
				cost[(i+j)%3][k] += D[c[i][j]-1][k];
			}
		}
	}
	int64 res = INF_LL;
	REP(i, C){
		REP(j, C){
			REP(k, C){
				if(i == j || j == k || i == k) continue;
				res = min(res, cost[0][i]+cost[1][j]+cost[2][k]);
			}
		}
	}
	cout << res << endl;

}


Measured memory_bytes: 2816
#include <iostream>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    ll h, w;
    cin >> h >> w;
    ll d = 10000000000;
    for (int i = 0; i <= h; i++) {
        ll h2 = h - i;
        ll s1 = i * w;
        ll s2 = h2 * (w / 2);
        ll s3 = h2 * (w - (w / 2));
        ll smax = max(s1, max(s2, s3));
        ll smin = min(s1, min(s2, s3));
        d = min(d, smax - smin);
        s2 = w * (h2 / 2);
        s3 = w * (h2 - (h2 / 2));
        smax = max(s1, max(s2, s3));
        smin = min(s1, min(s2, s3));
        d = min(d, smax - smin);
    }
    swap(h,w);
    for (int i = 0; i <= h; i++) {
        ll h2 = h - i;
        ll s1 = i * w;
        ll s2 = h2 * (w / 2);
        ll s3 = h2 * (w - (w / 2));
        ll smax = max(s1, max(s2, s3));
        ll smin = min(s1, min(s2, s3));
        d = min(d, smax - smin);
        s2 = w * (h2 / 2);
        s3 = w * (h2 - (h2 / 2));
        smax = max(s1, max(s2, s3));
        smin = min(s1, min(s2, s3));
        d = min(d, smax - smin);
    }
    cout << d << endl;
}

Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = input()
    ld = defaultdict(int)
    rd = defaultdict(int)

    for i in range(2**n):
        r = ""
        b = ""
        for j,sj in enumerate(s[:n:]):
            if (i>>j)&1:
                r += sj
            else:
                b += sj
        ld[(r,b)] += 1

    for i in range(2**n):
        r = ""
        b = ""
        for j,sj in enumerate(s[2*n-1:n-1:-1]):
            if (i>>j)&1:
                r += sj
            else:
                b += sj
        rd[(r,b)] += 1

    ans = 0
    for lk,lv in ld.items():
        ans += lv*rd[lk]
    print(ans)
    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 265780
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int x;
  cin>>x;
  cout<<(x>=30?"Yes":"No")<<newl;
  return 0;
}


Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program{
	static void Main(){
		List<int> abcde = new List<int>();
		for (int i = 0;i < 5;i++)
			abcde.Add(int.Parse(Console.ReadLine()));
		int ans = 0;
		foreach (var i in abcde) ans += Ten(i);
		List<int> dis = new List<int>();
		foreach (var i in abcde) dis.Add((10 - i % 10) % 10);
		ans -= dis.Max();
		Console.WriteLine(ans);
	}

	static int Ten(int k){
		if (k % 10 == 0) return k;
		return k + 10 - k % 10;
	}
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

bool can_reach_from_A[200000];
bool can_reach_from_B[200000];
bool can_reach_from_C[200000];
bool can_reach_from_D[200000];

int main(){
    int N;
    int A;
    int B;
    int C;
    int D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    can_reach_from_A[A - 1] = true;
    for(int i = A; i < N; i++){
        if(i > 1){
            can_reach_from_A[i] = (can_reach_from_A[i - 1] || can_reach_from_A[i - 2]) && (S[i] != '#');
        } else {
            can_reach_from_A[i] = can_reach_from_A[i - 1] && (S[i] != '#');
        }
    }
    can_reach_from_B[B - 1] = true;
    for(int i = B; i < N; i++){
        if(i > 1){
            can_reach_from_B[i] = (can_reach_from_B[i - 1] || can_reach_from_B[i - 2]) && (S[i] != '#');
        } else {
            can_reach_from_B[i] = can_reach_from_B[i - 1] && (S[i] != '#');
        }
    }

    can_reach_from_C[C - 1] = true;
    for(int i = C - 2; i >= 0; i--){
        if(i < N - 2){
            can_reach_from_C[i] = (can_reach_from_C[i + 1] || can_reach_from_C[i + 2]) && (S[i] != '#');
        } else {
            can_reach_from_C[i] = can_reach_from_C[i + 1] && (S[i] != '#');
        }
    }

    can_reach_from_D[D - 1] = true;
    for(int i = D - 2; i >= 0; i--){
        if(i < N - 2){
            can_reach_from_D[i] = (can_reach_from_D[i + 1] || can_reach_from_D[i + 2]) && (S[i] != '#');
        } else {
            can_reach_from_D[i] = can_reach_from_D[i + 1] && (S[i] != '#');
        }
    }

    if(C < D){
        if(can_reach_from_A[C - 1] && can_reach_from_B[D - 1]){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if(can_reach_from_A[C - 1] && can_reach_from_B[D - 1]){
            for(int i = B - 1; i <= D - 1; i++){
                if(i > 0 && can_reach_from_A[i - 1] && can_reach_from_B[i] && can_reach_from_D[i] && can_reach_from_C[i + 1]){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
            cout << "No" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    /*
    for(int i = 0; i < N; i++){
        cout << can_reach_from_A[i] << " ";
    }
    cout << endl;
     for(int i = 0; i < N; i++){
        cout << can_reach_from_B[i] << " ";
    }
    cout << endl;
     for(int i = 0; i < N; i++){
        cout << can_reach_from_C[i] << " ";
    }
    cout << endl;
     for(int i = 0; i < N; i++){
        cout << can_reach_from_D[i] << " ";
    }
    cout << endl;
    */
    return 0;
}


Measured memory_bytes: 1284
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var S = ReadLine();

        var ans = Range(1, N - 1).Select(i => (X: S[..i], Y: S[i..])).Select(t => t.X.Intersect(t.Y).Count()).Max();

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28420
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string.h>
#include<algorithm>
#include<functional>
using namespace std;

int main(void){

	int n;
	int L[200];

	for (int i = 0; i < 200; i++)L[i] = 0;

	cin >> n;
	int l = n * 2;
	for (int i = 0; i < l; i++)cin >> L[i];
	sort(L, L + l);

	int sum = 0;
	
	for (int i = 0; i < l;i+=2){
		sum += L[i];
	}

	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int  

using namespace std;

void solve(){

	ll a,b,c;
	cin>>a>>b>>c;

	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;

}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF=(1LL<<60);
const int mod=1000000007;

int main(void){
    int a,b,c; cin >> a >> b >> c;
    if(c<=a+b+1) cout << b+c << endl;
    else cout << a+b+b+1 << endl;
}

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

int main(){
	int n;
	cin>>n;
	long long t, tt, a, aa, k;
	cin>>t>>a;

	for(int i=1;i<n;i++){
		tt=t;
		aa=a;
		cin>>t>>a;
		if((tt/t)>(aa/a)){
			k=tt/t;
			if(tt%t==0) { t*=k; a*=k; }
			else { t*=(k+1); a*=(k+1); }
		}
		else { 
			k=aa/a;
			if(aa%a==0) { t*=k; a*=k; }
			else { t*=(k+1); a*=(k+1); }
		}	
	}
	printf("%lld\n",t+a);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
ll N,M;


int main(){
  ll k,a,b,d=1;

  cin >> k >> a >> b;
  if(b-a < 2) cout << k+1 << endl;
  else{
    ll r = min(k,a-1);
    d+=r;
    k-=r;
    d+=(k/2) * (b-a);
    d+=(k%2);
    cout << d << endl;
  } 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int a[432];
Int sum[432];
Int dp[432][432];
Int n;
int main(){
  cin >> n;
  for(int i = 0;i < 432;i++)
    for(int j = 0;j < 432;j++)
      dp[i][j] = INF;
  for(int i = 1;i <= n;i++)cin >> a[i], sum[i] = sum[i-1] + a[i];
  for(int dif = 1;dif <= n;dif++){
    for(int i = 1;i+dif <= n+1;i++){
      int j = i + dif;
      if(dif == 1){
	dp[i][j] = 0;
      }
      else{
	for(int k = i+1;k < j;k++){
	  dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + sum[j-1] - sum[i-1]);
	}
      }
      //      cout << i << " " << j << " " << dp[i][j] << endl;
    }
  }
  cout << dp[1][n+1] << endl;
  return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
static const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  cin>>s; list<int>seq(ALL(s));
  int ans=0;
  while(!seq.empty()){
    cf=seq.front(),cb=seq.back();
    if(cf!=cb){
      if(cf!='x'&&cb!='x'){pri1(-1); return 0;}
      else if(cf=='x'){seq.pop_front(); ans++;}
      else{seq.pop_back(); ans++;}
    }else{seq.pop_front(); if(!seq.empty())seq.pop_back();}
  }
  END
}

Measured memory_bytes: 3536
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int INF = 1 << 28;
		int n = sc.nextInt();
		int[][] root = new int[n + 1][n + 1];
		for (int i = 0; i <= n; i++) {
			Arrays.fill(root[i], INF);
			root[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			int r = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				root[r][sc.nextInt()] = 1;
			}
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					root[i][j] = Math.min(root[i][j], root[i][k] + root[k][j]);
				}
			}
		}
		int p = sc.nextInt();
		for (int i = 0; i < p; i++) {
			int s = sc.nextInt();
			int d = sc.nextInt();
			int v = sc.nextInt();
			int dis = root[s][d];
			if (dis == INF) {
				System.out.println("NA");
			} else if (dis < v) {
				System.out.println(dis + 1);
			} else {
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 26368
#include <iostream>
#include <string>
int main() {
    std::string s;
    int i, flag_1 = -1, flag_2 = -1;
    std::cin >> s;
    i = 0;
    for(i ; i < s.size() ; i++)
    {
        if (s[i] == 'A' && flag_1 == -1)
        {
            flag_1 = i;
        }
        else if (s[i] == 'Z')
        {
            flag_2 = i;
        }
    }
    std::cout << flag_2 - flag_1 + 1 << std::endl;
    return 0;
}

Measured memory_bytes: 640