akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (a, b, c) = [int(e) for e in lines[0].split(" ")]

    return (a, b, c)


def solve(a, b, c):



    result = 'No'
    d = c - a - b
    if d > 0:
        if 4 * a * b < d * d:
            result = 'Yes'

    return  result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

int main()
{
    long long A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    A *= 100;
    B *= 100;

    // ありえる水の量を列挙
    set<int> w;
    for (int i = 0; i <= F / A; i++)
        for (int j = 0; j <= F / B; j++)
            if (i * A + j * B <= F && i * A + j * B != 0)
                w.insert(i * A + j * B);

    double m = 0, ms = 0, mw = A;
    for (auto x : w)
    {
        for (int i = 0; i <= min((x / 100 * E) / C, (F - x) / C); i++)
        {
            int sugar = i * C + min((x / 100 * E - i * C) / D * D, (F - x - i * C) / D * D);
            double noudo = (double)sugar / (x + sugar);
            if (noudo > m)
            {
                m = noudo;
                ms = sugar;
                mw = x;
            }
        }
    }

    cout << ms + mw << ' ' << ms << endl;
}

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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;

void solve() {
	int n;
	cin >> n;
	int ans = 3 * n * n;
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

vector<int> tonari[200005];

int main() {
    string s,t;
    cin>>s>>t;
    vector<ll> apps[26];
    for (int i = 0; i < s.length(); ++i) {
        apps[s[i]-'a'].push_back(i+1);
    }
    if(apps[t[0]-'a'].empty()){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=apps[t[0]-'a'][0];
    ll last=ans;

    for (int i = 1; i < t.length(); ++i) {
        int c=t[i]-'a';
        if(apps[c].empty()){
            cout<<-1<<endl;
            return 0;
        }
        auto tsugi=lower_bound(apps[c].begin(),apps[c].end(),last+1);
        if(tsugi-apps[c].begin()==apps[c].size()){
            ans+=apps[c][0]+s.length()-last;
            last=apps[c][0];
        }else{
            ans+=(ll)*tsugi-last;
            last=*tsugi;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6460
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef unsigned long long ll;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
 
int main(){
    //int n, m;
 
    string s;
 
    //cin >> n >> m;
    cin >> s;
    int size = s.size();
    int res = 1;
    if(size%2==1) res = 0;
    rep(i, size){
    if(i%2 == 0){
        if(s[i] == 'h') continue;
        else {
            res = 0;
            break;
        }
    } 
    if(i%2 == 1){
        if(s[i] == 'i')continue;
        else {
            res = 0;
            break;
        }
    }
    }
     
 
    if(res) cout << "Yes";
    else cout << "No";
 
 
    return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;



int main(void) {
	ll n;
	cin >> n;
	vl a(n);
	rep(i, n) cin >> a[i];
	vl ans(n);
	ll bit = 1;
	rep(i, 30) {
		ll zero = 0;
		ll one = 0;
		rep(j, n) {
			if (a[j] & bit) one++;
			else zero++;
		}
		if (one % 2 == 0) {
			rep(j, n) {
				if (a[j] & bit) {
					ans[j] += bit;
				}
			}
		}
		else {
			rep(j, n) {
				if (!(a[j] & bit)) {
					ans[j] += bit;
				}
			}
		}
		bit <<= 1;
	}
	rep(i, n) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 6316
D(S,d,s,n){if(d==0)return S==s;int r=0;for(;n<10;n++)r+=D(S,d-1,s+n,n+1);return r;}
main(n,s){for(;scanf("%d%d",&n,&s),n|s;)printf("%d\n",D(s,n,0,0));exit(0);}

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

int main() {
  int n;
  cin >> n;
  deque<int> dq;
  for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      if (i % 2 == 0) {
          dq.push_front(a);
      } else {
          dq.push_back(a);
      }
  }
  if (n % 2) {
      for (int i = 0; i < n; i++) {
          cout << dq[i] << " \n"[i == n - 1];
      }
  }else{
      for (int i = n - 1; i >= 0; i--) {
          cout << dq[i] << " \n"[i == 0];
      }
  }
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}
 
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a,b);
  auto f = factorize(g);
  int ans = f.size() + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

void solve(int n, int m, int x, vector<int> &a){
    vector<int> sum(n+1, 0);
    vector<int> isGate(n, 0);
    REP(i, m){
        isGate[a[i]] = 1;
    }
    REP(i, n){
        sum[i+1] = sum[i] + isGate[i];
    }
    cout << min(sum[x] - sum[0], sum[n] - sum[x]) << endl;
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    REP(i, m){
        cin >> a[i];
    }
    solve(n, m, x, a);
    return 0;
}

Measured memory_bytes: 256
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates

int main()
{
    ll x, n;
    cin >> x >> n;
    set<ll> p;
    rep(i, n) {
        ll pp;
        cin >> pp;
        p.insert(pp);
    }
    rrepp(i, 0, 101) {
        if (p.find(x - i) == p.end()) {
            cout << x - i << endl;
            return 0;
        }
        if (p.find(x + i) == p.end()) {
            cout << x + i << endl;
            return 0;
        }
    }
    return 0;
}


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

int main(void){
    int n, cnt=0;
    cin >> n;
    if(n < 357){
        cout << "0\n";
        return 0;
    }
    int start = 357;
    if(n>500000000){
        start = 499999999;
        cnt += 14384;
    }
    for(int i=start;i<=n;i=i+2){
        int j=i, flg=1, c3=0, c5=0, c7=0;
        while(j>0){
            int k = j%10;
            if(k!=3 && k!=5 && k!=7){
                flg = 0;
                break;
            }
            if(k==3) ++c3;
            if(k==5) ++c5;
            if(k==7) ++c7;
            j /= 10;
            if(j > 0 && j%2==0){
                flg = 0;
                break;
            }
        }
        if(flg){
            if(c3>0 && c5>0 && c7>0) ++cnt;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int q; cin>>q;
    while(q--){
        long long a,b; cin>>a>>b;
        if(a>b) swap(a,b);
        long long ans;
        if(b-a<=1) ans=2*(a-1);
        else{
            long long ok=a,ng=b;
            while(abs(ok-ng)>1){
                long long mid=(ok+ng)/2;
                if(mid*mid<a*b){
                    ok=mid;
                }else{
                    ng=mid;
                }
            }
            long long c=ok;
            if(c*(c+1)>=a*b) ans=2*(c-1);
            else ans=2*c-1;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vd = vector<double>;
using vi = vector<int>;
int main(){
    int N;
    cin >> N;
    queue<int> A;
    int a;
    for(int i = 0; i < N; i++){
        cin >> a;
        A.push(a);
    }
    int b = 1;
    for(int i = 0; i < N; i++){
        if(A.front() == b){
            b++;
            A.pop();
        }
        else{
            A.pop();
        }
    }
    if(b == 1){
        cout << -1 << endl;
    }
    else{
        cout << N - (b - 1) << endl;
    }
    return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

ll f(ll b, ll n){
  if(n<b) return n;
  else return f(b, floor(n/b)) + ( n%b );
}

int main(){
  long long k,tmp;
  std::cin >> k;
  int n=50;
  std::cout << n << std::endl;
  tmp=k/n;
  std::vector<long long> a(n,n-1+tmp);
  tmp=k%n;
  if(tmp>0)rep(i,n){
    if(i<tmp){
      a[i]+= n;
      a[i]-= tmp-1;
    }
    else a[i]-=tmp;
  }
  rep(i,n) {
    std::cout << a[i];
    if(i!=n-1) std::cout << " " ;
  }
  std::cout << std::endl;
}


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

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string T;
  cin >> T;
  rep(i, T.size()){
    if (T[i] == '?')
    {
      T[i] = 'D';
    }
  }

  cout << T << "\n";
    return 0;
}




Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=302;
int n,A,B,C;
double dp[M][M][M];

double Rec(int i,int j,int k){
	if(dp[i][j][k]>-eps) return dp[i][j][k];
	if(i+j+k==0) return dp[i][j][k]=0;
	double t=1;
	if(i) t+=Rec(i-1,j,k)*i/n;
	if(i<M-1&&j) t+=Rec(i+1,j-1,k)*j/n;
	if(j<M-1&&k) t+=Rec(i,j+1,k-1)*k/n;
	return dp[i][j][k]=t*n/(i+j+k);
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x==1) A++;
		if(x==2) B++;
		if(x==3) C++;
	}
	for(int i=0;i<M;i++) for(int j=0;j<M;j++) fill(dp[i][j],dp[i][j]+M,-1);
	cout<<syosu(11)<<Rec(A,B,C)<<endl;
}

Measured memory_bytes: 215424
n = int(input())
l = list(map(int,input().split()))

count = 0
for i in range(n-2):

    if(l[i] < l[i+1] and l[i+1] < l[i+2]):
        count += 1
        continue
    if(l[i+2] < l[i+1] and l[i+1] < l[i]):
        count += 1
        continue

print(count)

Measured memory_bytes: 3060
/*
  AOJ 1109
  Title:Fermat's Last Theorem
  @kankichi573
*/
#include <stdio.h>

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

int cube[1112];
cube_root(int x)
{
  int i;

  for(i=0;i<=1111;i++)
    if(cube[i+1]>x && cube[i]<=x)
      return(i);
  return(0);
}


init()
{
  int i;

  for(i=0;i<=1111;i++)
    cube[i]=i*i*i;
}

main()
{
  int i,max_,sum,x,y,z;

  init();


  while(scanf("%d",&z) && z)
    {
      //printf("cu=%d cur=%d\n",cube[z],cube_root(cube[z]/2));
      max_=0;
      for(x=1;x<=cube_root(cube[z]/2);x++)
	{
	  y = cube_root(cube[z]-cube[x]);
	  //printf("xy=%d %d\n",x,y);
	  sum = cube[x]+cube[y];
	  //printf("xy=%d %d %d\n",x,y,sum);
	  max_=max(max_,sum);
	}
      printf("%d\n",cube[z]-max_);
    }

  return(0);

}

Measured memory_bytes: 604
N = int(input())
d = list(map(int,input().split()))
#N = 14
#d = [99592,10342,29105,78532,83018,11639,92015,77204,30914,21912,34519,80835,100000,1]
d.sort()
m = d[N//2-1]
M = d[N//2]
ans = 0
if m == M:
    ans = 0
else:
    ans = M - m
print(ans)

Measured memory_bytes: 14428
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

typedef long long ll;

int main(void)
{
    int n;
    cin >> n;
    int x[n];
    int y[n];
    int array[n];

    REP(i, n)
    {
        cin >> x[i] >> y[i];
        array[i] = i;
    }
    double ans = 0;
    ll count = 0;
    do
    {
        double dist = 0;
        count++;
        rep(i, 1, n)
        {
            double dx, dy;
            dx = x[array[i]] - x[array[i - 1]];
            dy = y[array[i]] - y[array[i - 1]];
            dist += sqrt(pow(dx, 2) + pow(dy, 2));
        }
        ans += dist;
    } while (next_permutation(array, array + n));
    //cout << (double)ans / count << endl;
    printf("%.16f\n", (double)ans / count);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  stringstream ss;
  cin >> n;
  cout << "Christmas";
  for(int i=n;i<25;i++) cout << " Eve";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  static int N,K,A[100010];
  cin>>N>>K;
  for(int t=0;t<N;t++)cin>>A[t];

  int ans=1;
  ans+=floor((N-K)/(K-1));
  if((N-K)%(K-1)!=0)ans++;

  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 1024
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	map<string,int> mp;
	rep(i,n){
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"]<<"\n";
	
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
using namespace std;
int f(int p) {
	int a[10];
	a[0] = (p - p % 1000) / 1000;
	p -= a[0] * 1000;
	a[1] = (p - p % 100) / 100;
	p -= a[1] * 100;
	a[2] = (p - p % 10) / 10;
	p -= a[2] * 10;
	a[3] = p;
	sort(a, a + 4);
	return a[3] * 1000 + a[2] * 100 + a[1] * 10 + a[0] - a[0] * 1000 - a[1] * 100 - a[2] * 10 - a[3];
}
int main() {
	int n; while (cin >> n) {
		if (n == 0)return 0;
		else if (n % 1111 == 0) { cout << "NA\n"; continue; }
		else {
			for (int i = 0; i <= 6174; i++) {
				if (n == 6174) {
					cout << i << endl;
					i = 10000;
				}
				else n = f(n);
			}
		}
	}

}

Measured memory_bytes: 3124
import java.io.*;
import java.util.*;

public class Main {
    class Frac {
        public int a, b;

        public Frac(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int gcd(int a, int b) {
            if (b == 0) return a;
            return gcd(b, a % b);
        }

        public void fix() {
            int gcd_ = gcd(a, b);
            a /= gcd_;
            b /= gcd_;
        }

        public void add(Frac frac) {
            int base = this.b / gcd(this.b, frac.b) * frac.b;
            int child = this.a * (base / this.b) + frac.a * (base / frac.b);
            this.b = base;
            this.a = child;
            fix();
        }

        public void sub(Frac frac) {
            add(new Frac(-frac.a, frac.b));
        }


    }

    void run() {
        while (true) {
            String s = read();
            if (s.equals("#")) {
                break;
            }
            String t = s;
            ArrayList<Integer> dir = new ArrayList<Integer>();
            while (true) {
                if (t.startsWith("north")) {
                    dir.add(0);
                    t = t.substring(5);
                }
                if (t.startsWith("west")) {
                    dir.add(1);
                    t = t.substring(4);
                }
                if (t.isEmpty()) break;
            }
            Collections.reverse(dir);
//            sysout.println(Arrays.toString(dir.toArray()));
            Frac frac = null;
            if (dir.get(0) == 0) frac = new Frac(0, 1);
            if (dir.get(0) == 1) frac = new Frac(90, 1);
            for (int i = 1; i < dir.size(); i++) {
                if (dir.get(i) == 0) {
                    frac.sub(new Frac(90, (int) Math.pow(2, i)));
                }
                if (dir.get(i) == 1) {
                    frac.add(new Frac(90, (int) Math.pow(2, i)));
                }
            }
            if (frac.b == 1) sysout.println(frac.a);
            else sysout.println(frac.a + "/" + frac.b);
        }
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = new StringTokenizer("");

    String read() {
        if (!buffer.hasMoreTokens()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }

    String readLine() {
        buffer = new StringTokenizer("");
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Measured memory_bytes: 16948
#include <iostream>
#include <bitset>
#include <cmath>
using namespace std;

const int C=20;
typedef long long ll;
int main() { 
    string S; cin >> S;
    ll N = S.size();
    // ll n = 0;


    ll ct1=0;
    ll ct2=0;
    for (int i=0; i<N; i++) {
        // ll pw = pow(2, N-1-i); 
        // if (S[i] == '1') n+= pw;
        bool cl = (S[i] == '1');
        if (i%2==0) {
            if (!cl) ct1++;
            if (cl) ct2++;
        } else {
            if (cl) ct1++;
            if (!cl) ct2++;
        }
    }
    cout << min(ct1, ct2) << endl;

    // cout << n << endl;

    // cout << "cand1" << endl;
    // // cout << bitset<C>(n) << endl;
    // // cout << bitset<C>(cand1) << endl;
    // cout << bitset<C>(n^cand1) << endl;
    // ll xor1 = n^cand1;

    // // cout << "cand2" << endl;
    // // cout << bitset<C>(cand2) << endl;
    // cout << bitset<C>(n^cand2) << endl;
    // ll xor2 = n^cand2;

    // int ct1 = 0;
    // for (int i=0; i<N; i++) {
    //     if (xor1 & (1<<i)) ct1++;
    // }    
    // int ct2 = 0;
    // for (int i=0; i<N; i++) {
    //     if (xor2 & (1<<i)) ct2++;
    // }    

    // cout << min(ct1, ct2) << endl;


    
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N;
    string S;
    cin >> N;
    vector<ll> A(N);
    REP(i, N)
        cin >> A.at(i);

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    vec_p pairs(N);
    ll count = 1;
    ll j = 0;
    REP(i, N - 1)
    {
        if (A.at(i) == A.at(i + 1))
        {
            count++;
        }
        else{
            pairs.at(j) = make_pair(A.at(i), count);
            j++;
            count = 1;
        }
    }
    pairs.at(j) = make_pair(A.at(N-1), count);

    bool flag_1 = false;
    bool flag_2 = false;
    ll tmp;

    REP(i,pairs.size()){
        if(pairs.at(i).second>=4&&flag_1==false){
            cout << pairs.at(i).first * pairs.at(i).first << endl;
            flag_2 = true;
            break;
        }
        else if(pairs.at(i).second>=2){
            if(flag_1==false){
                tmp = pairs.at(i).first;
                flag_1 = true;
            }
            else{
                cout << tmp * pairs.at(i).first << endl;
                flag_2 = true;
                break;
            }
        }
    }
    if(flag_2==false){
        cout << 0 << endl;
    }
}


Measured memory_bytes: 2560
import java.util.*;
public class Main{
  	public static void main (String [] args){
      	Scanner scanner = new Scanner (System.in);
      	int N = scanner.nextInt();
      	int [] arr = new int [N];
      	for (int i = 0; i < N; i++){
          	arr[i] = scanner.nextInt();
        }
      	Arrays.sort(arr);
      	int half = (arr[N-1])/2;
      	int sum = 0;
      	for (int i = 0; i < N-1; i++){
          	sum += arr[i];
        }
      	sum += half;
      	System.out.println(sum);
    }
}

Measured memory_bytes: 35644
#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 FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(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; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, A, B;
  cin >> n >> A >> B;
  string s;
  cin >> s;
  vector <bool> T(n, false);
  int pp = 0, abrord = 1;

  REP(i,n) {
    if(s.at(i) == 'a' && pp < A+B) {
      T.at(i) = true;
      ++pp;
    }
    if(s.at(i) == 'b' && pp < A+B && abrord <= B) {
      T.at(i) = true;
      ++pp;
      ++abrord;
    }
  }
  REP(i,n) {
    YesorNo(T.at(i));
  }
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
using namespace std;


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  
  int N,x[8],y[8],nkai=1;
  double len= 0;
  cin >> N;
  rep(i,N){
    cin >> x[i] >> y[i];
  }
  rep(i,N){
    nkai *= i+1;
  }
  rep(i,N-1){
    
    for(int l = i+1;l<N;l++){
 		len += pow((pow((x[i]-x[l]),2)+pow((y[i]-y[l]),2)),0.5)*2/N*nkai;
    }
  }
  len = len/nkai;
  cout << std::setprecision(15)<<len << endl;
}






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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  auto solve = [&](int init) {
    int cur = init, ans = 1, prev_len = init;
    while (cur < s.size()) {
      if (prev_len == 1) {
        if (s[cur] == s[cur - 1]) {
          if (cur != s.size() - 1) {
            cur += 2;
            ans++;
            prev_len = 2;
          } else {
            cur++;
          }
        } else {
          cur++;
          ans++;
          prev_len = 1;
        }
      } else {
        cur++;
        ans++;
        prev_len = 1;
      }
    }

    return ans;
  };

  cout << max(solve(1), solve(2)) << '\n';
  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> avec(N);
  for (auto &a : avec)
    cin >> a;
  sort(avec.begin(), avec.end());
  cout << avec[N - 1] - avec[0] << endl;
}


Measured memory_bytes: 256
num = int(input())
official_house = [[[0 for _idx3_ in range(10)] for _idx2_ in range(3)] for _idx1_ in range(4)]

for _ in range(num):
    building,floor,room,count = map(int, input().split())
    official_house[building-1][floor-1][room-1] += count

for building in range(4):
    for floor in range(3):
        for room in range(10):
            print(f" {official_house[building][floor][room]}", end="")
        print("")
    if building < 3:
        print("####################")


Measured memory_bytes: 5636
// finish date: 2018/03/04

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    map<char, int> mp;
    string s;
    rep(i, N) {
        cin >> s;
        mp[s[0]]++;
    }
    vc vChar={'M','A','R','C','H'};
    ll ans = 0;
    rep(i,5){
        FOR(j,i+1,5){
            FOR(k,j+1,5){
                ans+=(ll)mp[vChar[i]]*(ll)mp[vChar[j]]*(ll)mp[vChar[k]];
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<set>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int maxn=500010;
char s[maxn];
int n;
set<int> F,G; 
set<int>::iterator it;
void Add() {
	if(s[n]!=9) {
		if(s[n]==s[n-1]-1) F.erase(n);
		if(s[n]==s[n-1]) G.insert(n);
	}
	s[n]++;int x=n;
	if(s[n]==10) {
		G.erase(x);
		while(s[x]==10) {
			s[x]=0,s[--x]++;
		}
		F.insert(x+1),G.erase(x+1);
		if(x>1&&s[x]==s[x-1]) F.erase(x);
		if(x>1&&s[x]>s[x-1]) G.insert(x);
	}
}
int main() {
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n) s[i]-='0';
	dwn(i,n,2) {
		if(s[i]<s[i-1]) F.insert(i);
		if(s[i]>s[i-1]) G.insert(i);
	}
	int ans=0;
//	for(it=F.begin();it!=F.end();it++) printf("%d ",(*it));puts("");
//	for(it=G.begin();it!=G.end();it++) printf("%d ",(*it));puts("");
	rep(i,1,n) {
		int p=n;ans++;
		int k;it=F.lower_bound(i+1);
		if(it==F.end()) break;
		k=(*it);it=G.upper_bound(k-1); 
		if(it==G.begin()) p=i;
		else it--,p=max(i,(*it));
		Add();i=p;
	/*	rep(j,p+1,n) printf("%d",s[j]);puts("");
		for(it=F.begin();it!=F.end();it++) printf("%d ",(*it));puts("");
		for(it=G.begin();it!=G.end();it++) printf("%d ",(*it));puts("");*/
	}
	printf("%d\n",ans);
	return 0;
}
/*
98990009978996999999
*/

Measured memory_bytes: 21888
#include <bits/stdc++.h>
using namespace std;
 
ifstream in ("test.in" );
ofstream out("test.out");
 
const int DIM = 1e2 + 5;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
 
bool oki[DIM][DIM]; int mat[DIM][DIM];
pair<int, int> lst[DIM * DIM];
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int h, w, n;
    cin >> h >> w >> n;
    
    for (int i = 0; i <= h + 1; ++i)
        oki[i][0] = oki[i][w + 1] = 1;
    for (int j = 0; j <= w + 1; ++j)
        oki[0][j] = oki[h + 1][j] = 1;
    
    oki[1][1] = 1; lst[1] = make_pair(1, 1);
    for (int i = 1, j = 1, p = 2, d = 0; p <= h * w; ++p) {
        while (oki[i + dx[d]][j + dy[d]])
            d = (d + 1) & 3;
        
        i += dx[d]; j += dy[d];
        oki[i][j] = 1; lst[p] = make_pair(i, j);
    }
    
    for (int i = 1, j = 1; i <= n; ++i) {
        int x;
        cin >> x;
        
        for (; x != 0; --x, ++j)
            mat[lst[j].first][lst[j].second] = i;
    }
    
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j)
            cout << mat[i][j] << " ";
        cout << "\n";
    }
 
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int a[maxn];
int main(){
	int ans=1e9;
	int n=read(),m=read();
	REP(i,1,n) a[i]=read();
	int u=upper_bound(a+1,a+n+1,0)-a-1;
	REP(i,0,m){
		if(u-i<0) continue;
		if(u+m-i>n) continue;
		int x=-a[u-i+1],y=a[u+m-i];
		if(m-i==0) y=0;
		if(i==0) x=0;
		chkmin(ans,min(x+2*y,y+2*x));
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
	char c;
	cin >> c;
	vector <char> vowel(5);
	vowel = { 'a', 'i', 'u', 'e', 'o' };
	
	int check = 0;
	for (int i = 0; i < vowel.size(); i++) {
		if(vowel[i] == c) { check = 1; }
	}
	if(check) {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 256
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 20 * 1000 + 47;
const int MAGIC = 1000 * 100 / 3;

int P[MAX];

int main()
{
    
   // freopen("in.txt", "r", stdin);
    //ios::sync_with_stdio(false); cin.tie(0);
    
    int n;
    scanf("%d", &n);
    FOR(i, 1, n+1)
    {
        int x;
        scanf("%d", &x);
        P[x] = i;
    }
    FOR(i, 1, n + 1)
        printf("%d ", MAGIC * i + P[i]);
    printf("\n");
    FOR(i, 1, n+1)
        printf("%d ", MAGIC * (MAX - i));
}





Measured memory_bytes: 768
def c_mod(n, r, mod=10 ** 9 + 7):
	n1, r = n + 1, min(r, n - r)
	numer = denom = 1
	for i in range(1, r + 1):
		numer = numer * (n1 - i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod - 2, mod) % mod

x,y=map(int,input().split())
if (2*x-y)%3==0 and (2*y-x)%3==0 and (2*x-y)>=0 and (2*y-x)>=0 :
  l=int((2*x-y)/3)
  k=int((2*y-x)/3)
  ans=c_mod(l+k,k)

else:
  ans=0
print(ans)


Measured memory_bytes: 38512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[100100][2];

int main(){
  string s; cin >> s;
  int n=s.size();
  dp[0][0]=1;
  rep(i,n){
    if(s[i]=='1'){
      dp[i+1][0]=dp[i][0]*2%mod;
      dp[i+1][1]=(dp[i][1]*3+dp[i][0])%mod;
    }
    else{
      dp[i+1][0]=dp[i][0];
      dp[i+1][1]=dp[i][1]*3%mod;
    }
  }
  cout << (dp[n][0]+dp[n][1])%mod << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

class BipartiteMatching{
    private:
        int n; // 頂点数
        vector<vector<int>> graph;
        vector<int> match;
        vector<int> used;
        bool Dfs(int v);
    public:
        BipartiteMatching(int n);
        void AddEdge(int u, int v);
        int Run();
        int Match(int u);
};

BipartiteMatching::BipartiteMatching(int n): 
    n(n),
    graph(n),
    match(n),
    used(n)
    {}

void BipartiteMatching::AddEdge(int u, int v){
    graph[u].push_back(v);
    graph[v].push_back(u);
}

bool BipartiteMatching::Dfs(int v){
    used[v] = true;
    for(int u : graph[v]){
        int w = match[u];
        if(w == -1 || (!used[w] && Dfs(w))){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int BipartiteMatching::Run(){
    int res = 0;
    fill(begin(match), end(match), -1);
    for(int v = 0; v < n; ++v){
        if(match[v] == -1){
            fill(begin(used), end(used), false);
            if(Dfs(v)) res++;
        }
    }
    return res;
}
/*************** using variables ***************/

/**********************************************/

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

    int n;
    vector<P> blue, red;
 
    cin >> n;
    REP(i, n){
        int a, b;
        cin >> a >> b;
        red.pb(P(a, b));
    }
    REP(i, n){
        int c, d;
        cin >> c >> d;
        blue.pb(P(c, d));
    }
 
    BipartiteMatching bm(n*2);
    REP(i, n){
        REP(j, n){
            if(red[i].first < blue[j].first && red[i].second < blue[j].second){
                bm.AddEdge(i, j+n);
            }
        }
    }
 
    cout << bm.Run() << endl;
}


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

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

    int odd=0, four=0;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        if(a%4 == 0)four++;
        else if(a%2 == 1)odd++;
    }
    if(abs(four-odd) <= 1){
        if(four >= odd) cout << "Yes" << endl;
        else if(four + odd == n) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(four > odd)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
a[101],b[101];j;k;y;z;main(x){for(;~scanf("%d%d",a+k++,b+k););for(;j++-*a;printf("%d ",z))for(k=0;k++-*b;k==1|x<y?y=x,z=k:0)x=abs(a[j]-a[*a+k])+abs(b[j]-b[*a+k]);}


Measured memory_bytes: 128
from itertools import product

N,M=map(int,input().split())
k=[0]*M
s=[[0] for _ in range(M)]
for i in range(M):
  k[i],*s[i]= map(int,input().split())
p= list(map(int,input().split()))
a=list(product([0,1],repeat=N))

ans=0
for c in a:  #スイッチ状態
  cnt=0
  for i in range(M):  #電球はM個ある
    tmp=0
    for t in s[i]:
      tmp += c[t-1]
    if tmp%2==p[i]:
      cnt +=1
  if cnt==M:
    ans += 1
print(ans)

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

const int MAX_L = 2 * 1e+5 + 2;
const ll INF = 1 << 30;

ll A[MAX_L], dp[MAX_L][5];

int main() {
    int L;
    cin >> L;
    for (int i = 1; i <= L; i++) {
        cin >> A[i];
    }
    for (int i = 0; i <= L; i++) {
        for (int j = 0; j < 5; j++) dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= L; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k <= j; k++) {
                if (j == 0 || j == 4) dp[i][j] = min(dp[i][j], dp[i - 1][k] + A[i]);
                else if (j == 1 || j == 3) {
                    if (A[i] == 0) dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
                    else dp[i][j] = min(dp[i][j], dp[i - 1][k] + A[i] % 2);
                }
                else {
                    dp[i][j] = min(dp[i][j], dp[i - 1][k] + (A[i] % 2 == 1 ? 0 : 1));
                }
            }
        }
    }
    ll ans = INF;
    for (int i = 0; i < 5; i++) {
        ans = min(ans, dp[L][i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define BUG(x) (cerr << #x << " = " << x << "\n")
#define ARRAY(f) {cerr << #f << " = "; FOR(i, f) cout << i << ' '; cout << "\n";}
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define bit(x, i) ((x >> (i)) & 1LL)
#define onbit(x, i) (x | (1LL << (i)))
#define offbit(x, i) (x & ~(1 << (i)))

const int N = 1 << 18;

int n, a[N];
int f[N];
II g[N];

void update(int i, int j) {
    if (j == -1) return;
    if (j == g[i].fi) return;
    if (a[j] >= a[g[i].fi]) {
        g[i].se = g[i].fi;
        g[i].fi = j;
    } else if (a[j] > a[g[i].se]) {
        g[i].se = j;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    srand(time(NULL));
    #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        //freopen("","w",stdout);
    #endif
    cin >> n;
    REP(i, two(n)) cin >> a[i];
    f[0] = 0;
    g[0] = II(0, -1);
    For(tt, 1, two(n)-1) {
        f[tt] = f[tt-1];
        g[tt] = II(tt, 0);
        if (a[tt] < a[0]) g[tt] = II(0, tt);
        REP(i, n) if (bit(tt, i)) {
            int tt2 = offbit(tt, i);
            update(tt, g[tt2].first);
            update(tt, g[tt2].second);
        }
        f[tt] = max(f[tt], a[g[tt].fi] + a[g[tt].se]);
    }
    For(i, 1, two(n)-1) cout << f[i] << "\n";
}




Measured memory_bytes: 7168