akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline long long read () {
	long long num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
namespace graph {
	const int maxn = 100020;
	struct node {
		int y, next;
	} a[maxn << 1];
	int head[maxn], top = 0;
	void insert (int x, int y) {
		a[top].y = y;
		a[top].next = head[x];
		head[x] = top ++;
	}
} using namespace graph;

namespace INIT {
	map <long long, int> m;
	int n; long long d[maxn];
	void init () {
		n = read ();
		for (int i = 1;i <= n;i ++) {
			d[i] = read ();
			m[d[i]] = i;
		}
		sort (d + 1,d + 1 + n);
	}
} using namespace INIT;

namespace WORK {
	int size[maxn];
	void work () {
		memset (head, -1, sizeof head);
		for (int i = 1;i <= n;i ++)
			size[i] = 1;
		for (int i = n;i > 1;i --) {
			int x = m[d[i]];
			long long t = n - 2 * size[x];
			/*if (t < 0) {
				printf ("-1\n");
				exit (0);
			}*/
			t = d[i] - t;
			if (m.count(t) == 0) {
				printf ("-1\n");
				exit (0);
			}
			int y = m[t];
			insert (y, x);
			insert (x, y);
			size[y] += size[x];
		}
	}
} using namespace WORK;

namespace CHECK {
	int dis[maxn];
	void dfs (int x, int fa) {
		for (int i = head[x];i + 1;i = a[i].next) {
			int y = a[i].y;
			if (y == fa) continue;
			dis[y] = dis[x] + 1;
			dfs (y, x);
		}
	}
	void check () {
		dfs (m[d[1]], -1);
		long long s = 0;
		for (int i = 1;i <= n;i ++)
			s += dis[i];
		if (s != d[1]) printf ("-1\n");
		else for (int i = 0;i < top;i += 2) 
				printf ("%d %d\n",a[i].y, a[i ^ 1].y);
	}
} using namespace CHECK;
int main () {
	init ();
	work ();
	check ();
	return 0;
}

Measured memory_bytes: 13440
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;
 
int main() {
    
    int N;
    cin >> N;
    vector<int> h(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    h[0] = h[1];
    vector<int> dp(N + 1, 0);
    dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N]<<endl;
    return 0;
    
    
}

// dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    while(S != "#"){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;d--;
        vector<string> G(15);
        int now = 0;
        for(int i=0; i<S.size(); i++){
            if(S[i] == '/'){
                now++;
            }else{
                if(S[i] == 'b'){
                    G[now].push_back('b');
                }else{
                    int cnt = S[i]-'0';
                    while(cnt){
                        G[now].push_back('.');
                        cnt--;
                    }
                }
            }
        }
        now++;
        swap(G[a][b],G[c][d]);
        string ans = "";
        for(int i=0; i<now; i++){
            int cnt = 0;
            for(int j=0; j<G[i].size(); j++){
                if(G[i][j] == '.'){
                    cnt++;
                }else{
                    if(cnt){
                        ans.push_back(cnt+'0');
                    }
                    cnt = 0;
                    ans.push_back('b');
                }
            }
            if(cnt){
                ans.push_back(cnt+'0');
                cnt = 0;
            }
            if(i != now-1){
                ans.push_back('/');
            }
        }
        cout << ans << "\n";
        cin >> S;
    }
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d)printf("Yes");
  else printf("No");
}

Measured memory_bytes: 256
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(read())
str_n = str(N)
for c in list(str_n):
    if c == '7':
        print('Yes')
        sys.exit()

print("No")


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

int main() {
	int a,b,c,d;
  	cin>>a>>b>>c>>d;
  if (a+b>c+d){
    cout<<"Left"<<endl;}
  else if(a+b==c+d){
    cout<<"Balanced"<<endl;}
  else {
    cout<<"Right"<<endl;}
}

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

int main(){
  int N;
  int flag = 0;
  cin >> N;
  while(N){
    int m = N % 10;
    N = N / 10;
    if( m == 7 ){
      flag = 1;
      break;}
    }
  if(flag)
     cout << "Yes" <<endl;
  else
     cout <<"No"<< endl;
  return 0;
}

Measured memory_bytes: 3632
#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();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#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;

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

    int r=0,l=0;
    REP(i,n){
        if(s[i]=='('){
            l++;
        } else if(s[i]==')'){
            if(l != 0){
                l--;
            }
            else r++;
        }
    }

    s = string(r,'(') + s + string(l,')');
    cout << s << endl;
    
    return 0;
}



Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


n,q = inpl()
s = input()
qq = []
cnt = [0] * n
for i in range(q):
    a,b = inpl()
    qq.append([a,b])
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]
for i in qq:
    l = i[0]
    r = i[1]
    print(cnt[r-1] - cnt[l-1])
 

Measured memory_bytes: 87128
#include <stdio.h>
#include <string.h>

int main(void) {
	int n, taro_p=0, hanako_p=0;
	scanf("%d", &n);
	int i;
	for (i=1; i<=n; i++)
	{
		char taro[101]={}, hanako[101]={};
		scanf("%s%s", taro, hanako);
		if (strcmp(taro, hanako)==0)
		{
			taro_p++;
			hanako_p++;
		} else if (strcmp(taro, hanako)>0)
		{
			taro_p+=3;
		} else if (strcmp(taro, hanako)<0)
		{
			hanako_p+=3;
		}
	}
	printf("%d %d\n", taro_p, hanako_p);
	return 0;
}

Measured memory_bytes: 604
#include<cstdio> //不懂  照题解敲的 期望之间的关系与状态转移 
#include<cstring>

const int maxn=300+5;

double dp[maxn][maxn][maxn];

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

		int sum[4]={0};

	for(int i=0;i<n;i++){
	
		int cur; scanf("%d",&cur);

		sum[cur]++;
	}

	int total=sum[1]+sum[2]+sum[3];

	memset(dp,0,sizeof(dp)); // 递推顺序有错 理解不清

	for(int k=0;k<=total;k++){

		for(int j=0;j+k<=total;j++){
	
			for(int i=0;i+j+k<=total;i++){
		
				if((!i && !j && !k) || i+j+k>total) continue;	

				double wait=1.0*n/(i+j+k);

				double pi=1.0*i/(i+j+k); // 只用从选了有的里面考虑 选了空的已经在wait中计算了

				double pj=1.0*j/(i+j+k);

				double pk=1.0*k/(i+j+k);

				if(i) dp[i][j][k]+=pi*dp[i-1][j][k]; 

				if(j) dp[i][j][k]+=pj*dp[i+1][j-1][k]; 

				if(k) dp[i][j][k]+=pk*dp[i][j+1][k-1]; 
		
				dp[i][j][k]+=wait;
			}
		}
	}

	printf("%.10lf\n",dp[sum[1]][sum[2]][sum[3]]);

	return 0;
}

Measured memory_bytes: 221824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a < b) {
            System.out.println("a < b");
        } else if (a == b) {
            System.out.println("a == b");
        } else if (a > b) {
            System.out.println("a > b");
        }
        sc.close();
    }

}


Measured memory_bytes: 26236
// Try KEYENCE Programming Contest 2019
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut xs = vec![];
    for _ in 0..4 {
    	xs.push(get!());
    }
    xs.sort();
    if xs == [1, 4, 7, 9] {
    	println!("YES");
    } else {
    	println!("NO");
    }
    
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= (j);i--)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

int main()
{
    int A,B;
    cin >> A >> B;
    if(A <= 5) cout << 0 << endl;
    else if(A <= 12) cout << B/2<<endl;
    else cout << B << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{/*
ll t;
cin>>t;
while(t--)
{*/
 ll x;
cin>>x;
ll i;
ll f=100;
ll ans=0;
for(i=0;i<100000000;i++)
{
f+=f/100;
ans++;
if(f>=x)
break;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3676
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    // #pragma GCC optimize("Ofast")
    using namespace std;
    //library
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define F first
    #define S second
    #define pb push_back
    #define mkp make_pair
    #define int long long
    #define ld long double
    //scankar
    #define sz(x) (int)(x).size()
    #define all(x) x.begin(),x.end() 
    #define rall(x) x.rbegin(),x.rend()
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    typedef map<int,int> mii;
    typedef map<int,bool> mib;
    typedef map<char,int> mci;
    typedef map<string,int> msi;
    
    const int INF = 1e18L + 5;
    const int MAX = 2e6 + 7;
    const int MOD =  1000000007;
    const long double PI  =3.141592653589793238463;
    //direction
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ D $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;
    //debugger

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int x,y,cnt,flag;
    void solve()
    {
        cin>>n;
        fo(i,0,n)
        {
            cin>>x>>y;
            if(x==y)
            {
                if(cnt)cnt++;
                else cnt=1;
                if(cnt>=3)flag=1;
            }
            else cnt=0;
        }
        if(flag)cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          THE GAME STARTS HERE                             //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        
        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 3648
from collections import Counter
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
minus = Counter([i-a[i] for i in range(n)])
plus = Counter([i+a[i] for i in range(n)])

cnt = 0
for i in minus:
    if i in plus:
        cnt += minus[i] * plus[i]
print(cnt)


Measured memory_bytes: 61584
#include<iostream>

using namespace std;

int main() {
    int w, h , x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (x < r || x > (w - r) || y < r || y > (h - r)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  int N;
  cin >> N;
  vi F(N, 0);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 10; j++){
      int f;
      cin >> f;
      if(f==1) F.at(i) |= (1<<j);
    }
  }
  vvll P(N, vll(11));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 11; j++){
      cin >> P.at(i).at(j);
    }
  }

  ll result = -1 * INF;
  for(int tmp = 1; tmp < (1<<10); tmp++){
    ll sum = 0;
    for(int i = 0; i < N; i++){
      int bit = tmp & F.at(i);
      int num = __builtin_popcount(bit);
      sum += P.at(i).at(num);
    }
    chmax(result, sum);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int n,i,max,min,temp;
	int s[100][5];

	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d %d %d %d %d",&s[i][0],&s[i][1],&s[i][2],&s[i][3],&s[i][4]);
		}
		max=min=s[0][0]+s[0][1]+s[0][2]+s[0][3]+s[0][4];
		for(i=0;i<n;i++){
			temp=s[i][0]+s[i][1]+s[i][2]+s[i][3]+s[i][4];
			if(temp>max){
				max=temp;
			}
			if(temp<min){
				min=temp;
			}
		}
		printf("%d %d\n",max,min);
	}

	return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    ll ans = 0;
    REP(i,n) {
        ans += a[i]-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<ll,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
ll sum[maxn];
map<ll,int> id;
vi G[maxn];
int sz[maxn];
ll rs=0;
bool ok=1;
void dfs(int u,int d=0)
{
    rs+=d;
    for(auto v:G[u])
    {
        dfs(v,d+1);
    }
}
int main()
{
    int n;
    cin>>n;
    priority_queue<pi> q;
    for(int i=1;i<=n;i++) 
    {
        cin>>sum[i];
        id[sum[i]]=i;
        q.push(make_pair(sum[i],i));
        sz[i]=1;
    }
    vc<pi> ans;
    while(!q.empty())
    {
        auto u=q.top();q.pop();
        if(q.empty())
        {
            dfs(u.second);
            if(rs!=sum[u.second]) ok=0;
            break;
        }
        ll fad=u.first-(n-2*sz[u.second]);
        if(!id.count(fad)||fad>=u.first)
        {
            ok=0;
            break;
        }
        sz[id[fad]]+=sz[u.second];
        ans.emplace_back(u.second,id[fad]);
        G[id[fad]].push_back(u.second);
    }
    if(!ok) print(-1);
    else{
        for(auto u:ans) cout<<u.first<<" "<<u.second<<'\n';
    }
}

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

int main() {
	string S1, S2, S3;
	cin >> S1 >> S2 >> S3;
	
	string result = S1.substr(0,1)+S2.substr(1,1)+S3.substr(2,1);
	
	cout << result;
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
// Author: πα

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

int main()
{
    int n, i;
    cin >> n;
    vector<int> v(n);
    for(i = 0; i < n; ++i)
        cin >> v[i];
    int idx = max_element(v.begin(), v.end()) - v.begin();
    int p = v[idx];
    v[idx] = 0;
    int q = *max_element(v.begin(), v.end());
    for(i = 0; i < n; ++i)
        cout << (i == idx ? q : p) << '\n';
    return 0;
}


Measured memory_bytes: 2432
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=0x3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=2e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
//const ll MOD=1e9+7;
const int MOD=1e9+7;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("in2.txt","r",stdin);
    freopen("out2.txt","w",stdout);
}
const int maxn=1e3+5;
vector<int> G[maxn];//存原图 初始化仅需初始此
int n,m;
int a[MAX],b[MAX];
int da[1005][1005],xiao[1005][1005];
//bool vi[1005];
void dfs(int now,int id,int st,int x[1005][1005] )
{
//    printf("now=%d id=%d st=%d\n",now,id,st);
//    vi[now]=true;
    x[st][now]=id;
    for(int u:G[now])
        if(x[st][u]==-1&&u!=st)dfs(u,id,st,x);
}
void solve(int st)
{
    for(int i=0;i<G[st].size();i++)
    {
        int to=G[st][i];
//        memset(vi,false,sizeof(vi));
//        vi[st]=1;
        if(xiao[st][to]==-1)
            dfs(to,i,st,xiao);
    }
//    memset(vi,false,sizeof(vi));
    for(int i=G[st].size()-1;i>=0;i--)
    {
        int to=G[st][i];
//        memset(vi,false,sizeof(vi));
//        vi[st]=1;
        if(da[st][to]==-1)
            dfs(to,i,st,da);
    }
}
int main()
{
    read(n);read(m);
    memset(da,-1,sizeof(da));
    memset(xiao,-1,sizeof(xiao));
    for(int i=1;i<=m;i++){read(a[i]);read(b[i]);G[a[i]].pb(b[i]);}
//    find_scc(n);
    for(int i=1;i<=n;i++)
        solve(i);
    for(int i=1;i<=m;i++)
    {
//        printf("%d %d %d\n",da[a[i]][b[i]],xiao[a[i]][b[i]],da[b[i]][a[i]]);
        if((da[a[i]][b[i]]!=xiao[a[i]][b[i]])==(da[b[i]][a[i]]!=-1))printf("same\n");
        else printf("diff\n");
    }

}
/*
4
1 2 3 2
*/



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

typedef pair<int,int> pii;

/*
no reason to use a set when a simple greedy works...
avoid overkill, after getting an answer look back for another path
*/

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m;	
	string s;
	cin >> n >> m >> s;
	int ans = -1;
	vector<int> nxt(n+1, -1);
	int ind = n - 1;
	int bestr = n;
	int bestnxt = -1;
	nxt[n] = n;
	while(ind >= 0){
		if(ind + m < bestr){
			if(bestnxt == -1)break;
			else if(ind + m < bestnxt)break; // nxt might not be in range
			else bestr = bestnxt;
		}
		if(s[ind] == '0'){
			nxt[ind] = bestr;
			bestnxt = ind; 
		}
		--ind;
	}
	if(nxt[ind] != -1){
		vector<int> res;	
		int ind = 0;
		while(ind != n){
			res.push_back(nxt[ind] - ind);
			ind = nxt[ind];
		}
		for(int a:res){
			cout << a << ' ';
		}
		cout << '\n';
	}
	else{
		cout << -1 << '\n';
	}
}


Measured memory_bytes: 1480
#include <stdio.h>

int main(void)
{
    int n, i;
    int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    char s[4];

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%s", &s);
        if (s[0] == 'A') c1++;
        else if(s[0] == 'W') c2++;
        else if(s[0] == 'T') c3++;
        else c4++;
    }

    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", c1, c2, c3, c4);
    
    return 0;
}


Measured memory_bytes: 1700
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int actime[60][20];
int nwrong[60][20];

int T, P, R;

bool accepted(int t, int p){
  return actime[t][p] > 0;
}

int acproblems(int t){
  int count = 0;
  for(int i = 0; i < 20; i++){
    if(actime[t][i] > 0) count++;
  }
  return count;
}
int totaltime(int t){
  int total = 0;
  for(int i = 0; i < 20; i++){
    if(actime[t][i] > 0){
      total += actime[t][i];
      total += nwrong[t][i] * 1200;
    }
  }
  return total;
}

int main(){
  int tID, pID, timei;

  string message;
  
  while(cin >> T >> P >> R && (T + P + R) > 0){
    memset(actime, 0, sizeof(actime));
    memset(nwrong, 0, sizeof(nwrong));

    while(R--){
      cin >> tID >> pID >> timei >> message;
      
      if(accepted(tID, pID)) continue;
      if(message == "CORRECT"){
        actime[tID][pID] = timei;
      }else{
        nwrong[tID][pID]++;
      }
    }
    
    vector<int> vi(T);
    
    REP(i, T) vi[i] = i + 1;
    for(int i = 0; i < T; i++){
      for(int j = 0; j < T - 1; j++){
        if(acproblems(vi[j]) < acproblems(vi[j+1]) ||
           (acproblems(vi[j]) ==acproblems(vi[j+1]) &&
            totaltime(vi[j]) > totaltime(vi[j+1])))
          swap(vi[j], vi[j+1]);
      }
    }
    
    for(int i = 0; i < T; i++){
      cout << vi[i] << " " << acproblems(vi[i]) << " " << totaltime(vi[i]) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1224
N, C = map(int, input().split())

r = [[0 for i in range(C)] for j in range(100000)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        r[i][c - 1] = 1

ans = 0
for i in range(100000):
    val = sum(r[i])
    if val > ans:
        ans = val

print(ans)


Measured memory_bytes: 40308
n = int(input())
b = list(map(int,input().split()))
a = [0 for i in range(n)]

a[0],a[1] = b[0],b[0]

for i in range(n-2):
    a[i+2] = b[i+1]
    
    if a[i+1] > b[i+1]:
        a[i+1] = b[i+1]

print(sum(a))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll s;
    cin>>s;
    ll ans,c;
    ll d=100,b=1;
    for(int i=0;i<10;i++){
        d*=10;
        if(i==0){
            c=s%d;
            //cout<<c<<endl;
            ans=abs(753-c);
        }
        else{
            b*=10;
            c=s%d;
            c/=b;
            //cout<<c<<endl;
            ans=min(ans,abs(753-c));
        }
        if(c<100) break;
    }
    cout<<ans<<endl;
    
    return 0;
}



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

long long d[40][40];
int grid[505][505];

long long colors[3][40];

int main() {
	int n, c;
	cin >> n >> c;
	for (int i = 1; i <= c; i++ ) {
		for (int j = 1; j <= c; j++) {
			cin >> d[i][j];
		}
	}
	for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= c; j++) {
			colors[i][j] = 0;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			long long g;
			cin >> g;
			colors[(i + j) % 3][g]++;
		}
	}
	
	long long ans = 500 * 500 * 1000 + 100;
	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++) {
			for (int k = 1; k <= c; k++) {
				if (i == j || j == k || k == i) {
					continue;
				}
				long long cnt = 0;
				for (int p = 0; p <= c; p++) {
					cnt += colors[0][p] * d[p][i];
				}
				for (int p = 0; p <= c; p++) {
					cnt += colors[1][p] * d[p][j];
				}
				for (int p = 0; p <= c; p++) {
					cnt += colors[2][p] * d[p][k];
				}
				ans = min(ans, cnt);

			}
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;

ll A, B, C, D, E;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll solve(ll x) { return x - x / C - x / D + x / E; }
int main() {
  cin >> A >> B >> C >> D;
  E = C * D / gcd(C, D);
  cout << solve(B) - solve(A - 1) << endl;
  return 0;
}


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

int main(){

  int N=0;

  cin>>N;
  
  double X[N];
  vector<double> v;
  
  rep(i,N){
  
    cin>>X[i];
    v.push_back(X[i]);
  }
  double ave=accumulate(v.begin(),v.end(),0.0)/N;
  int mean = round(ave);
	//  cout<<mean;

  int sum=0;
  rep(i,N){sum+=(X[i]-mean)*(X[i]-mean);}
    
  cout<<sum<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, h := nextInt(), nextInt(), nextInt()
	fmt.Println((a + b) * h / 2)
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)) {
			String data = scanner.nextLine();

			int n = Integer.parseInt(data);

			int ans = (10000 - n) % 1000;

			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 35808
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[4]={0};
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s[0]=='A')a[0]++;
		if(s[0]=='W')a[1]++;
		if(s[0]=='T')a[2]++;
		if(s[0]=='R')a[3]++;
	}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl;
return 0;
}


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

const double PI=3.141592653589793;
const ll MX = 1e18;


int main()
{
  string S;
  int N;
  cin >> N >> S;
  int ds = 0;
  rep(i, S.size() - 1)
  {
    if(S[i]==S[i+1]){
      ds++;
    }
  }

  cout << S.size() - ds << endl;

  return 0;
}


Measured memory_bytes: 3720
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let x = ref 0
let y = for i = 0 to n - 2 do for j = i + 1 to n - 1 do if a_s.(i) > a_s.(j) then incr x done done;
  Array.fold_left (fun c a0 -> Array.fold_left (fun c a -> if a0 > a then c + 1 else c) c a_s) 0 a_s
let c = k * (k - 1) / 2 mod 1000000007
let f g a b = g a b mod 1000000007
let ( * ) = f ( * )
let (+) = f (+)
let _ = !x * k + c * y |> Printf.printf "%d\n"

Measured memory_bytes: 3072
#include<iostream>
#include<string>

int main(){
    std::string s;
    std::string str = "Yes";

    std::cin >> s;

    for(int a = 0; a < s.size(); a++){
        if(a % 2 == 0){
            //奇数番目
            if(s[a] == 'L'){
                str = "No";
                break;
            }
        }else{
            //偶数番目
            if(s[a] == 'R'){
                str = "No";
                break;
            }
        }
    }

    std::cout << str << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll MOD = 1e9 + 7;

// g = eGCD(a, b, s, t)  --->  sa + tb = g
constexpr ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u = 0;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}


struct Fp {
  ll val;

  Fp(ll t = 0) :
    val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {}

  Fp& operator +=(const Fp& t) {
    val += t.val;
    if (val > MOD) val -= MOD;
    return *this;
  }

  Fp& operator -=(const Fp& t) {
    val -= t.val;
    if (val < 0) val += MOD;
    return *this;
  }

  Fp& operator *=(const Fp& t) {
    val = (val * t.val) % MOD;
    return *this;
  }

  Fp inv() const {
    if (val == 0) {
      cerr << "inv() is called for zero." << endl;
      exit(1);
    }
    ll u = 0;
    ll v = 0;
    eGCD(val, MOD, u, v);
    return Fp(u);
  }

  Fp& operator /=(const Fp& t) {
    return (*this) *= t.inv();
  }

  Fp operator +(const Fp& t) const { return Fp(val) += t; }
  Fp operator -(const Fp& t) const { return Fp(val) -= t; }
  Fp operator *(const Fp& t) const { return Fp(val) *= t; }
  Fp operator /(const Fp& t) const { return Fp(val) /= t; }
  Fp operator -() const { return Fp(-val); }

  bool operator ==(const Fp& t) const { return val == t.val; }
  bool operator !=(const Fp& t) const { return val != t.val; }
  
  operator ll() const { return val; }

};

constexpr ll MaxN = 1e5;
ll N, M;
vector<ll> a(MaxN + 1);

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N >> M;
  for (int i = 0; i < M; i++)  {
    ll x;
    cin >> x;
    a.at(x) = 1;
  }
  Fp prev = 0;
  Fp cur = 1;
  for (int i = 1; i <= N; i++) {
    if (a.at(i) == 0) {
      Fp ncur = cur + prev;
      prev = cur;
      cur = ncur;
    }else {
      prev = cur;
      cur = 0;
    }
  }
  cout << (ll)cur << endl;

  return 0;
}



Measured memory_bytes: 1152
N = int(input())
p = list(map(int, input().split()))

max0, max1, count = p[0], 0, 0
for i in p:
    max0 = min(max0, i)
    max1 = i
    if max1 == 1:
        count += 1
        break
    elif max0 >= max1:
        count += 1
print(count)


Measured memory_bytes: 24744
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
ll n;
vector<P> vec;
ll dp[1005][1005]={0},dp2[1005]={0};
bool sec_ok[1005][1005]={0};
const ll inf=174417441744;
ll sec_dp(ll l,ll r){
	if(l==r){
		sec_ok[l][r]=true;
		return dp[l][r]=vec[l].second;
	}
	if(dp[l][r]!=inf) return dp[l][r];
	ll ldp=sec_dp(l+1,r);
	ll rdp=sec_dp(l,r-1);
	ll lk=0,rk=0;
	bool f=false;
	if(ldp-vec[l].first<=0&&sec_ok[l+1][r]){
		f=true;
		lk=ldp+vec[l].second;
	}
	if(rdp-vec[r].first<=0&&sec_ok[l][r-1]){
		f=true;
		rk=rdp+vec[r].second;
	}
	if(!f){
		//if(l==0&&r==1) cout<<"12FALSE"<<endl;
		sec_ok[l][r]=false;
		return dp[l][r]=0;
	}
	sec_ok[l][r]=true;
	//if(l==0&&r==1) cout<<ldp-vec[l].first<<"   12inayo   "<<rdp-vec[r].first<<endl;
	return dp[l][r]=max(lk,rk);
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		ll c,w;
		cin>>c>>w;
		vec.push_back(P(c,w));
	}
	for(int i=0;i<1005;i++){
		for(int j=0;j<1005;j++){
			 dp[i][j]=inf;
			 sec_ok[i][j]=true;
		 }
		 dp2[i]=inf;
	}
	sec_dp(0,n-1);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
	//		cout<<(sec_ok[i][j]?"O":"X")<<" ";
		}
//		cout<<endl;
	}
	//cout<<endl;

	dp2[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(sec_ok[i][j]) dp2[j+1]=min(dp2[j+1],(ll)(dp2[i]+1));
		}
	}
//	for(int i=0;i<=n;i++) cout<<dp2[i]<<" ";
//	cout<<endl;
	cout<<dp2[n]<<endl;
}



Measured memory_bytes: 12080
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int A,B,X;
    cin >> A >> B >> X;
    if(X >= A && X-A <= B) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
char s[101];
char t[101];
char sortedS[101];
char sortedT[101];
int SA[26];
int TA[26];

int sort(bool asc) {
	if (asc) {
		int p = 0;
		for (int i = 0; i < 26; i++) {
			for (int j = SA[i]; j > 0; j--) {
				sortedS[p++] = (char)(i + 'a');
			}
		}
		sortedS[p++] = '\0';
	}
	else {
		int p = 0;
		for (int i = 25; i >= 0; i--) {
			for (int j = TA[i]; j > 0; j--) {
				sortedT[p++] = (char)(i + 'a');
			}
		}
		sortedT[p++] = '\0';
	}
}

bool compare() {
	int i = 0;

	rep(i, 0, 101)
	{
		if (sortedS[i] == '\0' && sortedT[i] != '\0') return true;
		if (sortedT[i] == '\0') return false;

		if (sortedS[i] == sortedT[i]) {
			continue;
		}

		return (sortedS[i] < sortedT[i]);
	}
}

int main() {
	cin >> s >> t;

	rep(i, 0, 26) {
		SA[i] = 0;
		TA[i] = 0;
	}

	for (int i = 0; s[i] != '\0'; i++) {
		SA[s[i] - 'a']++;
	}
	for (int i = 0; t[i] != '\0'; i++) {
		TA[t[i] - 'a']++;
	}
	sort(true);
	sort(false);
	cout << (compare() ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>B[2];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++){
		scanf("%d",&x);
		B[i%2].push_back(x);
	}
	if(n%2){
		for(int i=B[1].size()-1;i>=0;i--)printf("%d ",B[1][i]);
		for(int i=0;i<B[0].size();i++)printf("%d ",B[0][i]);
	}else{ 
		for(int i=B[0].size()-1;i>=0;i--)printf("%d ",B[0][i]);
		for(int i=0;i<B[1].size();i++)printf("%d ",B[1][i]);
	}return 0;
}

Measured memory_bytes: 3316
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int p[] = new int[n];
    int q[] = new int[n];
    int count = 0;
    for(int i=0 ; i<n ; i++){
      p[i] = sc.nextInt();
    }
    for(int i=0 ; i<n ; i++){
      q[i] = p[i];
    }
    Arrays.sort(q);
    // for(int i=0 ; i<n ; i++){
    //   System.out.print(q[i]);;
    // }
    for(int i=0 ; i<n ; i++){
      if(p[i]!=q[i]){
        count++;
      }
    }
    if(count<=2){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 23124
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string L;
	cin >> L;

	Int len = L.size();
	vector<vector<mint>> dp(len+1, vector<mint>(2));//dp[i][smaller]:Lを上からi桁目まで決めた時の総数
	//最上位桁は必ず1
	dp[1][0] = 2;
	dp[1][1] = 1;

	for (Int i = 1; i < len; i++) {
		if (L[i]=='1') {//上からi+1桁目が1の場合（1-indexed)
			dp[i + 1][1] = dp[i][1] * 3 + dp[i][0];
			dp[i + 1][0] = dp[i][0] * 2;
		}
		else {
			dp[i + 1][1] = dp[i][1] * 3;
			dp[i + 1][0] = dp[i][0];
		}
	}

	cout << dp[len][0]+dp[len][1] << "\n";
}


Measured memory_bytes: 5840
a , b, k = map(int,input().split())

if (b-a) > k:
    small_list = [i for i in range(a,a+k)]

    big_list = [j for j in range(b-k+1,b+1)]

    for number in small_list:
        if number in big_list:
            small_list.remove(number)

    list_number = small_list + big_list

else:
    list_number = range(a,b+1)

for i in list_number:
    print(i)


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

int main() {
  string n;
  cin >> n;
  for (int i = 0; i < 3; i++) {
    if (n.at(i) == '1')
      n.at(i) = '9';
    else if (n.at(i) == '9')
      n.at(i) = '1';
  }
  cout << n << endl;
  return 0;
}



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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<bool> flags(N, false);
	int mizuyari = 0;
	for (int i = 0; i < N; ++i)
	{
		int h;
		cin >> h;
		for (int j = 0; j < 100; ++j)
		{
			if (h >= j + 1)
			{
				if (!flags[j])
				{
					++mizuyari;
					flags[j] = true;
				}
			}
			else
			{
				flags[j] = false;
			}
		}
	}

	cout << mizuyari;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int a = s.size();
  int b= t.size();
  int c, d;
  d = 0;
  for (int i = 0; i < a - b + 1; i++) {
    c = 0;
    for (int j = 0; j < b; j++) {
      if (t.at(j) == s.at(i + j) ) {
        c++;
      }
    }
    if (d < c) {
      d = c;
    }
  }
  cout << b -d << endl;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 998244353, INF = 1e16;

lint N;
lint A[50], B[50];
int main() {
	cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N) {
		cin >> B[i];
	}

	vector<lint> vec;
	REP(i, 50) {
		vec.push_back(i + 1);
	}

	lint _dp[51][51];
	REP(i, 51) {
		REP(j, 51) {
			_dp[i][j] = INF;
		}
	}
	REP(i, SZ(vec)) {
		REP(j, 51) {
			_dp[j][j % vec[i]] = 1;
		}
	}

	REP(k, 51) {
		REP(i, 51) {
			REP(j, 51) {
				chmin(_dp[i][j], _dp[i][k] + _dp[k][j]);
			}
		}
	}
	REP(i, N) {
		if (_dp[A[i]][B[i]] == INF) {
			cout << -1 << endl;
			return 0;
		}
	}

	set<lint> must;
	REP(_, 50) {
		lint tmp = vec[SZ(vec) - 1];
		vec.pop_back();
		lint dp[51][51];

		REP(i, 51) {
			REP(j, 51) {
				dp[i][j] = INF;
				if (i == j) dp[i][j] = 1;
			}
		}
		REP(i, SZ(vec)) {
			REP(j, 51) {
				dp[j][j % vec[i]] = 1;
			}
		}
		for(auto itr : must) {
			REP(j, 51) {
				dp[j][j % itr] = 1;
			}
		}
		REP(k, 51) {
			REP(i, 51) {
				REP(j, 51) {
					chmin(dp[i][j], dp[i][k] + dp[k][j]);
				}
			}
		}
		bool flag = true;
		REP(i, N) {
			if (dp[A[i]][B[i]] == INF) flag = false;
		}
		if (!flag) {
			must.insert(tmp);
		}
	}
	lint ans = 0;
	for (auto itr : must) {
		ans += pow(2, itr);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4108
N = int(input())
dp = [[0 for _ in range(4**4)] for _ in range(N-3)]
cau = [6, 9, 24, 25, 26, 27, 33, 36, 37, 38, 39, 41, 45, 57, 70, 73, 97, 132, 133, 134, 135, 137, 161, 198, 201, 225]
if N==3:
    print(61)
    exit()

for i in range(4**4):
    dp[0][i] = 1 - cau.count(i)
for i in range(N-4):
    for j in range(4**4):
        if j in cau:
            dp[i+1][j] = 0
            continue
        tgt = 4*(j%(4**3))
        tgt_list = [tgt+i for i in range(4) if tgt+i not in cau]
        for elem in tgt_list:
            dp[i+1][j] += dp[i][elem]
        dp[i+1][j] = dp[i+1][j]%(10**9+7)
print(sum(dp[N-4])%(10**9+7))
"""
# calc cau
res = [[] for _ in range(8)]
for j in range(4**4):
    j1 = j//(4**3)
    j2 = j%(4**3)//(4**2)
    j3 = j%(4**2)//4
    j4 = j%4
    #res = 0
    if j2==0 and j3==2 and j4==1:
        res[0].append(j)
    if j1==0 and j3==2 and j4==1:
        res[1].append(j)
    if j1==0 and j2==2 and j4==1:
        res[2].append(j)
    if j2==2 and j3==0 and j4==1:
        res[3].append(j)
    if j2==0 and j3==1 and j4==2:
        res[4].append(j)
    if j1==0 and j2==2 and j3==1:
        res[5].append(j)
    if j1==2 and j2==0 and j3==1:
        res[6].append(j)
    if j1==0 and j2==1 and j3==2:
        res[7].append(j)
print(res)
"""


Measured memory_bytes: 42460