akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
  string S;
  cin >> S;
  
  int len = S.length();
  string SS, SS1, SS2;
  int ans;
  for (int i = len-2; i >= 2; i-=2){
    SS = S.substr(0, i);
    SS1 = SS.substr(0, i/2);
    SS2 = SS.substr(i/2, i/2);
    if(SS1 == SS2){
      ans = i;
      break;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, n) for (size_t i = 0; i < (n); i++)
#define REP(n) FOR(i, n)
#define cinv(v, n) REP(n) {cin>>(v)[i];}
#define nvec(T, v, n) vector<T> v(n); cinv(v, n)
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
 
#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))
 
#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )
 
#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}
 
#define acm accumulate
#define pub push_back
#define pof pop_front
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
 
#define GCD(v) gcd(ALL(v), 0l)
 
template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}
 
 
 
int main(){
  int n; string s;
  cin>>n>>s;
  int r=0,g=0,b=0;
  long long count = 0;
  for (size_t in = 0; in < n; in++) {
 
    if(s[in]=='R'){
      r++;
      count+=g*b;
      for (int i = in-2; i >= 0; i-=2) {
        if(i<0)break;
        if((s[i]=='G'&&s[(i+in)/2]=='B') || (s[i]=='B'&&s[(i+in)/2]=='G')){
          count--;
        }
      }
    }
 
    if(s[in]=='G'){
      g++;
      count+=r*b;
      for (int i = in-2; i >= 0; i-=2) {
        if(i<0)break;
        if((s[i]=='R'&&s[(i+in)/2]=='B') || (s[i]=='B'&&s[(i+in)/2]=='R')){
          count--;
        }
      }
    }
 
    if(s[in]=='B'){
      b++;
      count+=g*r;
      for (int i = in-2; i >= 0; i-=2) {
        if(i<0)break;
        if((s[i]=='G'&&s[(i+in)/2]=='R') || (s[i]=='R'&&s[(i+in)/2]=='G')){
          count--;
        }
      }
    }
 
    
  }
  cout<<count;
}
 
 
 
 
 
 
/* きょむ〜 */

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  bool b = false;
  for(int i=0; n-4*i>=0; i++) {
    if((n-4*i)%7 == 0) {
      b = true;
    }
  }
  yorn(b);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>

template <class T>
T sq(T x) { return x * x; }

using ldouble = long double;

struct Point {
    ldouble x, y;
    Point(ldouble x, ldouble y) : x(x), y(y) {}

    Point operator+(const Point& p) const {
        return Point(x + p.x, y + p.y);
    }
};

struct Circle {
    Point p;
    ldouble r;
    Circle(ldouble x, ldouble y, ldouble r)
        : p(x, y), r(r) {}
};

constexpr ldouble EPS = 1e-10;

int compare(ldouble lhs, ldouble rhs) {
    if (std::abs(lhs - rhs) < EPS) {
        return 0;
    } else {
        return lhs < rhs ? -1 : 1;
    }
}

ldouble dist(const Point& a, const Point& b) {
    return std::hypot(a.x - b.x, a.y - b.y);
}

std::vector<Point> crosspoint(
    const Circle& a, const Circle& b) {
    std::vector<Point> ret;

    ldouble d = dist(a.p, b.p);
    if (compare(d, a.r + b.r) > 0 ||
        compare(d, std::abs(a.r - b.r)) < 0) return ret;

    ldouble theta = std::acos((sq(d) + sq(a.r) - sq(b.r)) / (a.r * d * 2));
    ldouble phi = std::atan2(b.p.y - a.p.y, b.p.x - a.p.x);

    ret.emplace_back(a.p.x + a.r * std::cos(phi + theta),
                     a.p.y + a.r * std::sin(phi + theta));
    ret.emplace_back(a.p.x + a.r * std::cos(phi - theta),
                     a.p.y + a.r * std::sin(phi - theta));
    return ret;
}

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<Circle> ps;
    std::vector<ldouble> cs;
    for (int i = 0; i < n; ++i) {
        ldouble x, y, c;
        std::cin >> x >> y >> c;
        ps.emplace_back(x, y, 0);
        cs.push_back(c);
    }

    ldouble ok = 1e9, ng = 0;
    for (int q = 0; q < 100; ++q) {
        ldouble t = (ok + ng) / 2;

        std::vector<Point> qs;
        for (int i = 0; i < n; ++i) {
            ps[i].r = t / cs[i];
            qs.push_back(ps[i].p);
        }

        for (int j = 0; j < n; ++j) {
            for (int i = 0; i < j; ++i) {
                for (auto p : crosspoint(ps[i], ps[j])) {
                    qs.push_back(p);
                }
            }
        }

        bool judge = false;
        for (auto p : qs) {
            int cnt = 0;
            for (auto c : ps) {
                auto d = dist(p, c.p);
                if (compare(d, c.r) <= 0) ++cnt;
            }
            if (cnt >= k) judge = true;
        }

        if (judge) {
            ok = t;
        } else {
            ng = t;
        }
    }

    std::cout << std::fixed << std::setprecision(10)
              << ok << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<complex>
#include<fstream>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

//
int main()
{
	int n;
	cin >> n;
	int left=100, right=0;
	vector<int>a(n);
	rep(i, 0, n) {
		cin >> a[i];
		left = min(left, a[i]);
		right = max(right, a[i]);
	}

	long long int m=INF;
	rep(i, left, right+1) {
		long long int total = 0;
		rep(j, 0, n) {
			total += (a[j] - i) * (a[j] - i);
		}
		m = min(m, total);
	}
	cout << m << endl;
}

Measured memory_bytes: 3596
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  val buff = ListBuffer.empty[Int]
  (1 to n).foreach { i =>
    var x = i
    if(x % 3 == 0) {
      buff += x
    } else {
      var continue = true
      do {
        if(x % 10 == 3) {
          buff += i
          continue = false
        } else {
          x = x / 10
        }
      } while(x != 0 && continue)
    } 
  }
  println(" " + buff.mkString(" "))
}


Measured memory_bytes: 47536
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main() {
  int X;
  cin >> X;
  int ans = 1;
  
  for(int i=2; i*i<=X; i++) {
    int num = 1;
    int cnt = 0;
    while(num*i <= X) {
      num*=i;
      cnt++;
    }
    int tmp = pow(i,cnt);
    // cout << num << ":" << cnt << ":" << tmp << endl;
    ans = max(tmp,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 1e6 + 10, N2 = 2e5, delta = 10067, mod = 1234, oo = 1e9, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli a[LOG][LOG], dp[N];
vector <lli> v[N];

int32_t main() {
	fast;
	lli n;
	cin >> n;
	for (lli i = 0; i < n; i++)
		for (lli j = 0; j < n; j++)
			cin >> a[i][j];
	for (lli mask = 0; mask < (1 << n); mask++)
		for (lli i = 0; i < n; i++)
			if (mask & (1 << i))
				v[mask].pb(i);
	for (lli mask = 0; mask < (1 << n); mask++) {
		for (lli i: v[mask])
			for (lli j: v[mask])
				dp[mask] += a[i][j];
		dp[mask] /= 2;
	}
	for (lli mask = 0; mask < (1ll << n); mask++)
		for (lli sub = mask; sub; sub = (sub - 1) & mask)
			dp[mask] = max (dp[mask], dp[sub] + dp[mask ^ sub]);
	cout << dp[(1 << n) - 1] << '\n';
	return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define each(i, c) for (auto& (i) : (c))

using namespace std;
typedef long long int lli;
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }

int main() {
    string a, b;
    cin >> a >> b;
    if (a == "H" && b == "H" || a == "D" && b == "D") cout << "H" << endl;
    else cout << "D" << endl;
    return 0;
}

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

int main()
{
    int s;
    string temp;
    getline(cin,temp);
    std::string::iterator it;
    s=0;
    for (it=temp.begin(); it!=temp.end(); it++)
    {
        s=s+(*it - '0');
    }
    if(s%9==0)
    {
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 3844
#include <cstdio>
#include <algorithm>

int main()
{
  int n;
  int l[2000];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", l + i);
  }
  std::sort(l, l + n);
  int sum[1000 * 2001];
  int *p = sum;
  for (int i = 0; i < n - 1; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      *p++ = l[i] + l[j];
    }
  }
  std::sort(sum, p);
  long long ans = 0;
  for (int i = 0; i < n; ++i)
  {
    long long lc = n - 1 - i;
    ans += (p - std::upper_bound(sum, p, l[i])) - (n - 1) - lc * (lc - 1) / 2 - lc * (n - lc - 1);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 7936
<?php
fscanf(STDIN, "%d %d", $total_dis, $dim_count);

$arr = [];
for ($i = 0; $i < $total_dis; ++$i) {
    $arr[] = array_map("intval", explode(" ", trim(fgets(STDIN))));
}

$count = 0;
for ($i = 0; $i < $total_dis-1; ++$i) {
    for ($j = $i; $j < $total_dis; ++$j) {
        if ($i == $j) {
            continue;
        }
        $count += distance($arr[$i], $arr[$j]);
    }
}


echo $count, "\n";

function distance($a, $b) {
    global $dim_count;
    $total = 0;
    
    for ($i = 0; $i < $dim_count; ++$i) {
        $total += pow(abs($a[$i]-$b[$i]), 2);
    }
    
    if (sqrt($total) == floor(sqrt($total))) {
        return 1;
    }
    return 0;
}

Measured memory_bytes: 3828
#include<iostream>
using namespace std;
int main()
{
    int h,w,n,ans;
    cin >> h;
	cin >> w;
  	cin >> n;
  
    if(h > w) {
        ans = (n + h - 1) / h;
    } else {
      	ans = (n + w - 1) / w;
    }

    cout << ans  << endl;
}

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

#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define debug(x) cerr << #x << " = " << x << endl;
#define SET(c, v) memset(c, v, sizeof c)
#define pi 3.14159265358979323846264338
#define all(S) (S).begin(), (S).end()
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pf push_front
#define pb push_back
#define mk make_pair
#define MAX 3010
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<ll, ll> ii;
typedef pair<int, ii> pii;
typedef unsigned long long int ull;
int pd[MAX][MAX];
string a, b, c;

void solve(int t1, int t2)  {
	REP(i, 0, t1)
		REP(j, 0, t2) {
			if(!i || !j) pd[i][j] = 0;
			else if(a[i-1] == b[j-1]) pd[i][j] = pd[i-1][j-1] + 1;
			else pd[i][j] = max(pd[i-1][j], pd[i][j-1]);
		} 
	int i = t1, j = t2;
	while (i > 0 && j > 0) {
		if(a[i-1] == b[j-1]) { c.pb(a[i-1]); i--; j--; }
		else if (pd[i-1][j] > pd[i][j-1]) i--;
		else j--; 
	}
	reverse(all(c));
}

int main(int argc, char** argv) {
	cin >> a >> b;
	memset(pd, -1, sizeof pd);
	solve(a.size(), b.size());
	cout << c << endl;
	return 0;
}



Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll inf = 1e9+7;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vector<vector<int>> cnt(n, vector<int>(30, 0));
  rep(i, n){
    for(const auto& x : s[i]) ++cnt[i][x-'a'];
  }
  vector<int> mincnt(30, 60);
  rep(i, 27) rep(j, n) mincnt[i] = min(mincnt[i], cnt[j][i]);
  for(char i = 'a'; i <= 'z'; ++i){rep(j, mincnt[i-'a']) cout << i;}
  return 0;
}   

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

using namespace std;

int n, a[22], c;

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", a + i);
    for(int i = 1; i < n - 1; i++){
        if(a[i] > a[i - 1])
            c += a[i] < a[i + 1];
        else
            c += a[i] > a[i + 1];
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pp=pair<ll,pair<int,int>>;
using Graph=vector<vector<int>>;

int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  ll sum=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    sum+=A.at(i);
  }

  if(sum%(N*(N+1)/2)!=0){
    cout<<"NO"<<endl;
  }else{
    ll count=sum/(N*(N+1)/2);
    ll a=0;
    bool flag=true;
    for(int i=0;i<N;i++){
      if(A.at(i)-count<0){
        flag=false;
      }
    }
    for(int i=0;i<N-1;i++){
      if((count-A.at(i+1)+A.at(i))%N!=0){
        flag=false;
      }else{
        a+=(count-A.at(i+1)+A.at(i))/N;
        if(A.at(i)-(count-A.at(i+1)+A.at(i))/N*(N-1)-count<0){
          flag=false;
        }
      }
    }
    if((count-A.at(0)+A.at(N-1))%N!=0){
      flag=false;
    }else{
      a+=(count-A.at(0)+A.at(N-1))/N;
      if(A.at(N-1)-(count-A.at(0)+A.at(N-1))/N*(N-1)-count<0){
        flag=false;
      }
    }
    if(a!=count){
      flag=false;
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif


void Main() {
    string s; cin >> s;
    vector<string> x{"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    ll ans = distance(x.begin(), find(x.begin(), x.end(), s)) + 1;
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    let N: usize = read();
    let K: usize = read();
    let mut v = vec![false; N];
    for i in 0..K {
        let d: usize = read();
        for j in 0..d {
            let mut a: usize = read();
            a -= 1;
            v[a] = true;
        }
    }
    let mut ans = 0;
    for i in 0..N {
        if v[i] {
            continue;
        }
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(){
    int a;
    cin>>a;
    string b;
    cin>>b;
    int d=1;
    for(int i=0;i<a-1;i++){
        if(b.at(i)!=b.at(i+1)){
            d++;
    }
 }
   cout<<d<<endl;
}

Measured memory_bytes: 512
n,a,b,c,d = map(int,input().split())
s = input()
a,b,c,d = a-1,b-1,c-1,d-1

def move(a,s):
    ar = a
    while(ar<n-2):
        if(s[ar+2]=='.'):
            ar += 2
        elif(s[ar+1]=='.'):
            ar +=1
        else:
            break
    if(ar!=n-1):
        ar+=(s[ar+1]=='.')
    return ar

def pr_end(x):
    if(x):
        print('Yes')
    else:
        print('No')
    exit()

ar = move(a,s)
br = move(b,s)

if(c<d):
    if(c<=ar)&(d<=br):
        pr_end(1)
    else:
        pr_end(0)

for i in range(b-1,d):
    if(s[i:i+3] =='...'):
        if(c<=ar)&(d<=br):
            pr_end(1)
        else:
            pr_end(0)

pr_end(0)

Measured memory_bytes: 40048
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;

// ---
int N;
string S;

int Ans() {
  unordered_map<char, int> h;
  REP(i, N) { h[S[i]] += 1; }

  int ans = 1;
  for (auto it = h.begin(); it != h.end(); ++it) {
    ans = ans * (it->second + 1) % (POW_10_9 + 7);
  }
  return ans - 1;
}

signed main() {
  cin >> N;
  cin >> S;

  auto ans = Ans();

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


Measured memory_bytes: 512
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (ch == '\n' ) break;
    if (isalpha(ch)) {
      if (isupper(ch)) ch = tolower(ch);
      else if (islower(ch)) ch = toupper(ch);
    }

    printf("%c", ch);
  }

  printf("\n");
return 0;
}

Measured memory_bytes: 2612
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;

ll func(vector<ll> arr){
    int n = arr.size();
    for(int i = 1; i < n; i++)  arr[i] += arr[i-1];
    ll tot = arr[n-1], ans = INF;
    for(int i = 0; i < n; i++){
        ans = min(ans, abs(tot - arr[i] - arr[i]));
    }
    return ans;
}

main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin >> n;
    vector<ll> arr(n);
    for(int i = 0; i < n; i++)  cin >> arr[i];
    ll ans = func(arr);
    cout << ans;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
long long ans;
long long m,a,r,c,h;
long long max(long long x,long long y,long long z){
//	return ((x>y?x:y)>z?(x>y?x:y):z);
	return x*y*z;
}
int main(){
	int n;
	cin>>n;
	string s[n+5];
	for(int i=0;i<n;i++){
		cin>>s[i];
		if(s[i][0]=='M') m++;
		if(s[i][0]=='A') a++;
		if(s[i][0]=='R') r++;
		if(s[i][0]=='C') c++;
		if(s[i][0]=='H') h++;
	}
	if(m&&a&&r)	ans+=max(m,a,r);
	if(m&&a&&c) ans+=max(m,a,c);
	if(m&&a&&h) ans+=max(m,a,h);
	if(m&&r&&c) ans+=max(m,r,c);
	if(m&&r&&h) ans+=max(m,r,h);
	if(m&&c&&h) ans+=max(m,c,h);
	if(a&&r&&c) ans+=max(a,r,c);
	if(a&&r&&h) ans+=max(a,r,h);
	if(a&&c&&h) ans+=max(a,c,h);
	if(r&&c&&h) ans+=max(r,c,h);
	cout<<ans<<endl;	
	return 0;
}

Measured memory_bytes: 6144
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

ll n, m, t, a[MXN], b[MXN], c[MXN], d[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main() {
  fast();
  cin >> n >> m;
  FOR(i, 0, n) { cin >> a[i] >> b[i]; }
  FOR(i, 0, m) { cin >> c[i] >> d[i]; }
  FOR(i, 0, n) {
    ll mn = abs(a[i] - c[0]) + abs(b[i] - d[0]), idx = 1;
    FOR(j, 1, m) {
      ll dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dis < mn) {
        mn = dis, idx = j + 1;
      }
    }
    cout << idx << "\n";
  }

  return 0;
}



Measured memory_bytes: 3624
import java.io.*;
import java.util.StringTokenizer;
import java.util.Stack;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				Stack<Double> stack = new Stack<Double>();
				StringTokenizer st = new StringTokenizer(buf);
				while (st.hasMoreTokens()) {
					String s = st.nextToken();
					if (s.equals("+")) {
						double b = stack.pop();
						double a = stack.pop();
						stack.push(a+b);
					} else if (s.equals("-")) {
						double b = stack.pop();
						double a = stack.pop();
						stack.push(a-b);
					} else if (s.equals("*")) {
						double b = stack.pop();
						double a = stack.pop();
						stack.push(a*b);
					} else if (s.equals("/")) {
						double b = stack.pop();
						double a = stack.pop();
						stack.push(a/b);
					} else {
						stack.push(Double.parseDouble(s));
					}
				}
				System.out.println(stack.pop());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16928
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double M = sc.nextInt();
		double[] A = new double[N];
		double sum = 0;
		int count = 0;
		for(int i=0; i<N; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}

		//System.out.println(1/(4*M) +","+ A[0]/sum);

		for(int i=0; i<N; i++) {
			if( 1/(4*M) <= A[i]/sum ) {
				count++;
			}
		}

		/*if(count >= M) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}*/
		System.out.println(count >= M?"Yes":"No");



		sc.close();



	}

}


Measured memory_bytes: 35748
n=int(input())
h=list(map(int,input().split()))

dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(1,n-1):
    dp[i+1]=min(dp[i]+abs(h[i+1]-h[i]), dp[i-1]+abs(h[i+1]-h[i-1]))

print(dp[n-1])

Measured memory_bytes: 20340
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#include<assert.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int n,a[3001];
ll ans;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
		cin>>a[i],ans+=a[i]-1;
	cout<<ans;
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }

ll dp[101][101][301] = {};
int main(){
    ll n,W;
    cin >> n >> W;
    ll w[n],v[n];
    
    ll wmemo = 0;
    rep(i,0,n){
        cin >> w[i] >> v[i];
        if(i == 0) wmemo = w[i];
        w[i] -= wmemo;
    }

    rep(i,1,n+1){
        rep(j,1,n+1){
            rep(k,0,301){
                dp[i][j][k] = max(dp[i-1][j][k], dp[i][j-1][k]);
                if(k-w[i-1] >= 0) dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-w[i-1]]+v[i-1]);
            }
        }
    }

    ll ans = 0;
    rep(j,1,n+1){
        rep(k,0,301){
            if(j*wmemo+k <= W) ans = max(ans,dp[n][j][k]);
        }
    }
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 27352
n=int(input())

a="abcdefghijklmnopqrstuvwxyz"
aa=list(a)

stra=""
kk=n
for i in range(15):
    ki=(kk-1)%26+1
    if ki!=0:
        stra=aa[ki-1]+stra    
    else:
        stra=aa[25]+stra    
    kk=(kk-ki)//26
#    print(kk,ki,stra)
    if kk==0:
        break
    
print(stra)

Measured memory_bytes: 9188
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n,d,x,cnt=0;
    scanf("%d%d%d",&n,&d,&x);
    for(int i = 0; i < n; i++)
    {
        int temp;
        scanf("%d",&temp);
        int ti = 1;
        while(ti <= d)
        {
            cnt++;
            ti += temp;
        }
    }
    printf("%d\n",cnt+x);
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()



int main()
{
	ll N, A, B;
	cin >> N >> A >> B;

	ll s = A + B;

	ll c = N / s;
	ll d = N % s;

	cout << c * A + min(d, A) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll a, b;
  cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
/*
* @Author: kabbo
* @Date:   2020-05-10 18:03:01
* @Last Modified by:   kabbo
* @Last Modified time: 2020-05-10 18:04:45
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
void solve() {
	string s, t;
	cin >> s >> t;
	t.pop_back();
	s == t ? cout << "Yes\n" : cout << "No" << endl;
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	/*int t;
	cin >> t;
	for (int i(1); i <= t; ++i) {
		printf("Case %d: ", i);*/
	solve();
	//}
#ifndef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	string s, a, b;
	cin >> s;
	s.pop_back();
	for (int i = s.size(); i >= 0; i--) {
		a = s.substr(0, i);
		b = s.substr(0, i / 2);
		b += b;
		if (a == b) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int f(int x, int y) {
  if (x>y) return x-y;
  else return y-x;
}
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (f(a,c)<=d) cout << "Yes" << endl;
  else if (f(a,b)<=d && f(b,c)<=d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W; cin >> H >> W;
    VVI A(H,VI(W)), B(H,VI(W));
    REP(i,H)REP(j,W) cin >> A[i][j];
    REP(i,H)REP(j,W) cin >> B[i][j];
    int c = 160*160;
    bitset<2*160*160+1> b[H][W];
    b[0][0][A[0][0]-B[0][0]+c] = 1; b[0][0][B[0][0]-A[0][0]+c] = 1;
    REP(i,H)REP(j,W){
        if(i){
            b[i][j] |= (b[i-1][j]>>(abs(A[i][j]-B[i][j])));
            b[i][j] |= (b[i-1][j]<<(abs(B[i][j]-A[i][j])));
        }
        if(j){
            b[i][j] |= (b[i][j-1]>>(abs(A[i][j]-B[i][j])));
            b[i][j] |= (b[i][j-1]<<(abs(B[i][j]-A[i][j])));
        }
    }

    int ans = INT_INF;
    REP(i,2*c+1) if(b[H-1][W-1][i]) chmin(ans, abs(i-c));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 40320
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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 int inf = 1001001001;
const ll linf = 1001001001001001001;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(i,h) rep(j,w) {
        if(s[i][j] == '.') continue;
        bool ok = false;
        rep(k,4) {
            int ni = i+dx[k];
            int nj = j+dy[k];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(s[ni][nj] == '#') ok = true;
        }
        if(!ok) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
// AOJ 0146: Lupin The 4th
// 2017.9.28 bal4u@uu
// 2017.11.21

#include <stdio.h>
#include <string.h>

#define INF 1e10
#define ABS(a) ((a)>=0?(a):-(a))
#define MAX 32768

int s[17], d[17], v[17];	// ????????±?????????????????¢???????????±?????°
double dp[16][MAX];			// DP????????¨?????????
int w[16][MAX];				// ????????±????????°
int prev[16][MAX][2];		// ???????????????????????????
int ord[16];				// ???????????????????????????????????????????????´???

int main()
{
	int n, i, j, k, ii, lim;
	double x;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d%d%d", s+i, d+i, v+i);

	memset(prev, -1, sizeof(prev));
	for (ii = 1, i = 0; i < n; i++, ii <<= 1) {
		w[i][ii] = v[i];
//		prev[i][ii][0] = prev[i][ii][1] = -1;
	}

	lim = 1 << n;
	for (k = 0; k < lim; k++) {
		for (ii = 1, i = 0; i < n; i++, ii <<= 1) {		// ??´????????????
			if (k & ii) continue;
			for (j = 0; j < n; j++) {	// ??´?????????
				if (i == j || w[j][k] == 0) continue;
				int t = k | ii;
				x = dp[j][k] + (ABS(d[i] - d[j])*(7+2*w[j][k]))/200.0;
				if (dp[i][t] == 0 || x < dp[i][t]) {
					dp[i][t] = x, w[i][t] = w[j][k] + v[i];
					prev[i][t][0] = j;
					prev[i][t][1] = k;
				}
			}
		}
	}

	// ???????§???????????????????
	for (x = INF, ii = 0, i = 0; i < n; i++) {
		if (dp[i][lim-1] == 0) continue;
		if (dp[i][lim-1] < x) x = dp[i][lim-1], ii = i;
	}

	// ?????£???????????????
	for (ord[0] = ii, i = ii, j = lim-1, k = 1; k < n; k++) {
		ord[k] = prev[i][j][0];
		     j = prev[i][j][1];
		     i = ord[k];
	}

	// ??????
	printf("%d", s[ord[n-1]]);
	for (i = 1; i < n; i++) printf(" %d", s[ord[n-i-1]]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 10840
class Array
  def lower_bound(x)
    bsearch_index { |v| v >= x }
  end
end

N = gets.to_i
A = gets.split.map(&:to_i).sort

c = A.pop
m = c / 2.0

i = A.lower_bound(m) || A.size - 1

if i > 0 && (m - A[i]).abs > (m - A[i - 1]).abs
  i -= 1
end

puts [c, A[i]].join(' ')



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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 ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
	st l;
	cin >> l;
	ll n = l.size();
	vll dp1(n + 1, 0), dp2(n + 1, 0);
	dp1.at(0) = 0, dp2.at(0) = 1;
	rep(i, 0, n){
		dp1.at(i + 1) = (dp1.at(i) * 3 + (l.at(i) == '1' ? dp2.at(i) : 0)) % mod;
		dp2.at(i + 1) = (l.at(i) == '1' ? 2 : 1) * dp2.at(i) % mod;
		if(i == n - 1){
			dp1.at(i + 1) = (dp1.at(i + 1) + dp2.at(i + 1)) % mod;
		}
	}
	cout << dp1.at(n) << endl;	
}

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

constexpr int mod = 1e9+7;

vector<int> g[200005];
map<int, int> match;
int pw2[200005];

struct dat {
  long long z,o,t;
};

deque<dat> foo(int c) {
  deque<dat> ret;
  if(g[c].empty()) {
    ret.push_back({1,1,0});
    return ret;
  }


  vector<deque<dat>> dl;
  for(int i : g[c])
    dl.push_back(foo(i));
  int mi = 0;
  for(int i=1;i<dl.size();i++) {
    if(dl[i].size() > dl[mi].size()) mi = i;
  }
  dl.back().swap(dl[mi]);
  ret = move(dl.back());
  dl.pop_back();
  int m = 0;
  for(auto & l : dl) {
    m = max(m, (int)l.size());
    for(int i=0;i<l.size();i++) {
      long long tot = (ret[i].z + ret[i].o + ret[i].t) % mod;
      tot = tot * (l[i].z + l[i].o + l[i].t) % mod;
      long long tz = ret[i].z * l[i].z % mod;
      long long to = (ret[i].z * l[i].o + ret[i].o * l[i].z) % mod;
      long long tt = (tot - tz - to + mod*2) % mod;
      ret[i] = {tz, to, tt};
    }
  }
  for(int i=0;i<m;i++) {
    ret[i] = {ret[i].z+ret[i].t, ret[i].o, 0};
  }
  ret.push_front({1,1,0});
  return ret;
}

int main() {
  int n;
  scanf("%d",&n);
  pw2[0] = 1;
  for(int i=1;i<=n+1;i++)
    pw2[i] = pw2[i-1]*2%mod;
  for(int i=0;i<=n+1;i++)
    match[pw2[i]] = pw2[n+1-i];
  for(int i=1;i<=n;i++) {
    int x;
    scanf("%d",&x);
    g[x].push_back(i);
  }
  deque<dat> ret = foo(0);
  int ans = 0;
  for(auto p : ret) {
    int tot = (p.z + p.o) % mod;
    int tmp = p.o * match[tot] % mod;
    ans = (ans + tmp) % mod;
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 190080
#include<bits/stdc++.h>
using namespace std;
int m,n,a[105][105];
char s;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	    for(int j=1;j<=m;j++)
	    {
	    	cin>>s;
	    	if(s=='#') a[i][j]=1;
	    	else a[i][j]=0;
		}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]==1) putchar('#');
			else cout<<a[i-1][j]+a[i-1][j+1]+a[i][j+1]+a[i+1][j+1]+a[i+1][j]+a[i+1][j-1]+a[i][j-1]+a[i-1][j-1];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void main (void) {
    long long int n;
    float m;
    long long int r = 0;
    long long int s = 0;
    scanf("%lld %f", &n, &m);

    int vetor[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &vetor[i]);
        //vetor[i] = 1;
    }

    for (int i = 0; i < n; i++) {
        s = s + vetor[i];
    }

    for (int i = 0; i < n; i++) {
        if (vetor[i] >= s/(4*m)) {
            r++;
        }
        //printf("%d", vetor[i]);
    }
    /*
    printf("\n\n\n");
    printf("%lld\n", r);
    printf("%lld\n", s);
    */
    if (r >= m) {
        printf("Yes");
    } else {
        printf("No");
    }
}

Measured memory_bytes: 128
import collections
n = int(input())
s = input()
dic = dict(collections.Counter(s))
#W,Eどちらかしか無い場合
if len(dic)==1:
  print(0)
  exit()
left_w = 0
right_e = dic["E"]
cnt = [[] for _ in range(n)]
#(左にあるWの数+右にあるEの数)の最小値が答え


ans = n
for i in range(n):
  if s[i] == "W":
    cnt[i] = [left_w,right_e]
    ans = min(ans,left_w+right_e)
    left_w += 1
  elif s[i] == "E":
    cnt[i] = [left_w,right_e]
    ans = min(ans,left_w+right_e)
    right_e -= 1

#(右にあるWの数+左にあるEの数)の最小値が答えの場合もあるか
left_e = 0
right_w = dic["W"]

for i in range(n-1,-1,-1):
  if s[i] == "E":
    ans = min(ans,left_e+right_w)
    left_e += 1
  elif s[i] == "W":
    ans = min(ans,left_e + right_w)
    right_w -= 1

print(ans)



Measured memory_bytes: 43852
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
#define per(i, a, b) for (int i = a; i >= b; -- i)
const int mo = 1000000007, N = 5005;
using namespace std;
int n, m, he[N], ta[N], opt[210][N];
ll v[N], a[N][210], f[N];
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 2, n) scanf("%lld", &v[i]), v[i] += v[i - 1];
	rep(i, 1, n) rep(j, 1, m) scanf("%lld", &a[i][j]);
	rep(i, 1, m) he[i] = 1, ta[i] = 0; ll ans = 0;
	per(i, n, 1) {
		rep(j, 1, m) {
			int st = opt[j][ta[j]];
			for ( ; he[j] <= ta[j] && a[opt[j][ta[j]]][j] <= a[i][j]; -- ta[j]) {
				int u = opt[j][ta[j]];
				if (u == st) continue ;
				f[u] -= a[u][j] - a[opt[j][ta[j] + 1]][j];
			}
			if (he[j] <= ta[j]) {
				int u = opt[j][ta[j]];
				if (u != st) f[u] -= a[u][j] - a[opt[j][ta[j] + 1]][j];
				f[u] += a[u][j] - a[i][j];
			}
			opt[j][++ ta[j]] = i;
		}
		ll ret = 0;
		rep(j, 1, m) ret += a[i][j];
		ans = max(ans, ret);
		rep(j, i + 1, n) ret += f[j],
			ans = max(ans, ret - v[j] + v[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f q.front()
#define SIZE (ll)(1e3)
#define mod (ll)(1e9+7)
using namespace std;
typedef long long int ll;

int main(){
string s,c;cin>>s>>c;
int k=s.length();
int m=c.length();
int dp[k+1][m+1];
for(int i=0;i<=k;i++){
	for(int j=0;j<=m;j++){
         if(i==0||j==0)
         	dp[i][j]=0;
         else if(s[i-1]==c[j-1])
         	dp[i][j]=1+dp[i-1][j-1];
         else 
         	dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
}
int kanafusi=dp[k][m];
char subh[kanafusi+1];
subh[kanafusi]='\0';
int i=k;int j=m;
while(i>0&&j>0){
	if(s[i-1]==c[j-1])
		{subh[kanafusi-1]=s[i-1];
			i--;j--;kanafusi--;}
	else if(dp[i-1][j]>dp[i][j-1])
		i--;
	else
		j--;
}
cout<<subh;
return 0;}

Measured memory_bytes: 35456
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
a = reads()
freq = defaultdict(lambda: 0)
for x in a:
  freq[x] += 1
ans = sum(v - k if v >= k else v for k, v in freq.items())
print(ans)


Measured memory_bytes: 18664
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	vi dp(n+1);
	dp[0]=0;
	dp[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++) {
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
		//cerr<<dp[i]<<" ";
	}
	cout<<dp[n-1];
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3964
import sys 
sys.setrecursionlimit(2147483647)

INF = float("inf")

memo = [float("inf")]*100005

def rec(n):
    if n==0:
        return 0
    if memo[n]!=float("inf"):
        return memo[n]
    res = float("inf")
    val = 1
    while val<=n:
        res = min(res,rec(n-val)+1)
        val*=6
    
    val = 1
    while val<=n:
        res = min(res,rec(n-val)+1)
        val*=9
    memo[n]=res
    return memo[n]

dp = [INF]*100005

def morau_dp():
    #min(dp[n-x]+1....)
    N = int(input())
    dp[0]=0
    for i in range(1,N+1):
        val = 1
        while val<=N:
            dp[i]=min(dp[i],dp[i-val]+1)
            val*=6
        
        val = 1
        while val<=N:
            dp[i] = min(dp[i],dp[i-val]+1)
            val*=9

    print(dp[N])


if __name__ == "__main__":
    # N = int(input())
    # print(rec(N))
    morau_dp()

Measured memory_bytes: 10584
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int mod = 1e9+7;
long long int f[100050];
int main(){
	int n,m;
	long long int sum = 0;
	scanf("%d %d",&n,&m);
	f[1] = 1;
	int M = max(n,m);
	for(int i = 2;i <= M;i++){
		f[i] = i * f[i-1];
		f[i] %= mod;
	}
	if(m-n==0){
		sum = 2*f[n]*f[n];
		printf("%lld\n",sum%mod);
	}
	else if(abs(m-n)==1){
		sum = f[n] * f[m];
		printf("%lld\n",sum%mod);
	}
	else if(abs(m-n)>1){
		printf("0\n");
	}
	//printf("%lld",sum%mod);
}

Measured memory_bytes: 896
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    X=int(input())
    # map(int, input().split())

    m=100
    y=0
    while True:
        y+=1
        m+=int(m*0.01)
        if m>=X:
            print(y)
            break

if __name__ == '__main__':
    main()


Measured memory_bytes: 9176