akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1e10

ll dp[3111][3111];

int main(){
	string s, t;
	cin >> s >> t;
	int x = s.size(), y = t.size();
	for(int i = 0; i < y; i++){
		if(s[0]==t[i])dp[0][i]=1;
		if(i>0)dp[0][i]=max(dp[0][i],dp[0][i-1]);
	}
	for(int i = 1; i < x; i++){
		for(int j = 0; j < y; j++){
			dp[i][j]=dp[i-1][j];
			if(j>0)dp[i][j]=max(dp[i][j],dp[i][j-1]);
			if(s[i]==t[j]){
				if(j==0) dp[i][j]=1;
				else dp[i][j]=max(dp[i][j],1+dp[i-1][j-1]);
			}
		}
	}
	x--;y--;
	string ans="";
	int cur=dp[x][y];
	while(x>-1 && y>-1){
		//cout << x << " " << y << endl;
		if(s[x]==t[y]){
			if((x*y==0)||dp[x-1][y-1]==cur-1){
				ans+=s[x];
				cur--;
				x--;
				y--;
			}
			else{
				if(x!=0 && dp[x-1][y]==cur){
					x--;
				}
				else{
					y--;
				}
			}
		}
		else{
			if(x!=0 && dp[x-1][y]==cur){
				x--;
			}
			else{
				y--;
			}
		}
		//cout << ans << endl;
	}
	for(int i = ans.size()-1; i >= 0; i--){
		cout << ans[i];
	}
	cout<<'\n';
}


Measured memory_bytes: 74112
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  int n;cin>>n;
  int h[n];
  fol(i,n)cin>>h[i];
  bool flg = true;
  bool f = false;
  int c = h[0];
  fol(i,n){
    if(c - h[i] > 1){
      flg = false;
      break;
    }else if(c-h[i]==1){
      if(f){
        flg = false;
        break;
      }else{
        f = true;
      }
    }else if(c-h[i]==0){
    }else f = false;
    c = h[i];
  }
  cout << (flg?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 640
//毒瘤!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define maxn 1005
#define maxm 200005
using namespace std;
inline int qread(){
	int x=0,sign=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') sign=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*sign;
}
int n,m; 
int s[maxm],e[maxm];
vector<int>E[maxn];
void add_edge(int u,int v){
	E[u].push_back(v);
}
int used[maxn];
int route[maxn][maxn];
void dfs(int s,int x){
	int y;
	used[x]=1;
	route[s][x]++;
	int cnt=E[x].size();
	for(int i=0;i<cnt;i++){
		y=E[x][i];
		if(y==s) continue;
		if(!used[y]&&route[s][y]<2){
			dfs(s,y);
		}
	}
}

int judge(int u,int v){//1为diff,0为same 
	if(route[v][u]>0){//在一个SCC中 
		if(route[u][v]>=2) return 0;
		else return 1; 
	}else{//不在一个SCC中 
		if(route[u][v]>=2) return 1;
		else return 0;
	}
}

char a[]="same",b[]="diff";
void qprint(char *s,int len){
	for(int i=0;i<len;i++){
		putchar(s[i]);
	}
	putchar('\n');
}
int main(){
//	scanf("%d %d",&n,&m);
	n=qread();
	m=qread(); 
	int u,v;
	for(int i=1;i<=m;i++){
//		scanf("%d %d",&u,&v);
		s[i]=qread();
		e[i]=qread();
		add_edge(s[i],e[i]);
	}
	int y;
	for(int i=1;i<=n;i++){
		int cnt=E[i].size();
		for(int j=0;j<cnt;j++){
			y=E[i][j];
			if(route[i][y]<2){
				memset(used,0,sizeof(used));
				dfs(i,y);
			}
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++){
//			printf("%d ",route[i][j]);
//		}
//		printf("\n");
//	}
	for(int i=1;i<=m;i++){
		if(judge(s[i],e[i]) )qprint(b,4);
		else qprint(a,4);
	}
}

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

using namespace std;

string seg[10] = {
"0111111",
"0000110",
"1011011",
"1001111",
"1100110",
"1101101",
"1111101",
"0100111",
"1111111",
"1101111"
};

int in,now;

string ans;

void solve(){
	ans.clear();
	for(int i=0; i<7; i++){
		if(seg[now][i] != seg[in][i])
			ans += '1';
		else
			ans += '0';
	}
	now = in;
}

int main(){
	int n;
	while(true){
		cin >> n;
		if(n == -1)
			return 0;
		for(int i=0; i<n; i++){
			cin >> in;
			if(i==0){
				now = in;
				cout << seg[now] << endl;
				continue;
			}
			solve();
			cout << ans << endl;
		}
	}
}

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

int main()
{
    int n ;
	int ball[11] , b[11] , c[11];
	cin >> n ;
	for(int j=0 ; j<n ; j++){
		int flag=0, cntb=1 , cntc=1;
		for(int i=1 ; i<=10 ;i++){
			cin >> ball[i] ;
		}

		b[0]=0;
		c[0]=0;

		for(int i=1 ; i<=10 ; i++){
			if(b[cntb-1] < ball[i]){
				b[cntb]=ball[i];
				cntb++;
			}else if(c[cntc-1] < ball[i]){
				c[cntc]=ball[i];
				cntc++;
			}else{
				flag++;
				break;
			}
		}
		if(flag==0){
			cout <<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF ((int)1e9)
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define N 100005
vvi g(N);
int n, a, b, ans; int par[N], sub[N], depth[N];
int dfs(int u, int p) {
    sub[u] = 1;
    par[u] = p;
    depth[u] = depth[p] + 1;
    for(int v : g[u]) {
        if(p == v) continue;
        dfs(v,u);
        sub[u] += sub[v];
    }
}
int main() {
    SYNC
    cin >> n;
    FOR0(i, n-1) {
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    depth[0] = 0;
    dfs(1, 0);
    int u = n;
    while(u != 1) {
        if(depth[u] == (depth[n]+1)/2 + 1) ans = sub[u] >= n-sub[u];
        u = par[u];
    }
    cout << (ans ? "Snuke": "Fennec");
}

Measured memory_bytes: 13184
s = input()
n = len(s)
up = []
down = []
for i in range(1,n):
  if s[i] != s[i-1]:
    if s[i] == 'L':
      down.append(i)
    else:
      up.append(i)
ans = [0 for _ in range(n)]
try:
  top = up[0]
except IndexError:
  top = 2 * n
bottom = down[0]
count = 0
for i in range(n):
  diff = i - bottom
  if diff % 2 == 0:
    ans[bottom] += 1
  else:
    ans[bottom-1] += 1
  #print(ans)
  if i+1 == top:
    count += 1
    try:
      top = up[count]
    except IndexError:
      pass
    bottom = down[count]
print(' '.join(map(str,ans)))

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

int main() {
    int n; cin >> n;
    vector<int> t(n);
    for (auto& e : t) cin >> e;
    int m; cin >> m;
    
    int sum = accumulate(t.begin(), t.end(), 0);
    
    int p, x;
    for (int i = 0; i < m; i++) {
        cin >> p >> x;
        cout << sum-t[p-1]+x << endl;
    }
}


Measured memory_bytes: 256
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
ls = [l for l in ls if l.count('.') < w]


def transpose(ls):
    res = []
    h = len(ls)
    w = len(ls[0])
    for j in range(w):
        l = ''
        for i in range(h):
            l += ls[i][j]
        res.append(l)
    return res


h = len(ls)
ls = transpose([l for l in transpose(ls) if l.count('.') < h])

print(*ls, sep='\n')

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define REG register
#define LLI long long
#define DBL double
#define CHR char
#define BOL bool
const int MXN = 200010;

int n, a[MXN];

CHR s[MXN];
int main() {
	//freopen("template.in", "r", stdin);
	//freopen("template.out", "w", stdout);
	REG int i, j; REG LLI cnt=0, ans=0;
	
	scanf("%s", s+1);
	n = strlen(s+1);
	for(i = 1; i <= n; i++)
		if(s[i] == 'B')
			cnt++;
		else
			ans += cnt;
	printf("%lld\n", ans);

	return 0;
}



Measured memory_bytes: 384
(let* ((n (read))
       (x (make-array `(,n)))
       (y (make-array `(,n)))
       (acc 0))
  (loop :for i :from 0 :to (1- n)
        :do (setf (aref x i) (read))
        :do (setf (aref y i) (read)))
  (loop :for i :from 0 :to (- n 2)
        :do (loop :for j :from (1+ i) :to (1- n)
                  :do (incf acc (sqrt (+ (expt (- (aref x i) (aref x j)) 2d0)
                                         (expt (- (aref y i) (aref y j)) 2d0))))))
  (format t "~F~%" (/ (* acc 2) n)))


Measured memory_bytes: 23972
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] token = line.split(" ");
        int a = Integer.parseInt(token[0]);
        int b = Integer.parseInt(token[1]);

        int sum = a + b;
        int diff = a - b;
        int mul = a * b;

        int max = Math.max(sum, Math.max(diff, mul));

        System.out.println(max);
    }

}

Measured memory_bytes: 23636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n, q;
vector<llong> G[200005];
llong x[200005];
bool visit[200005];

void dfs(llong pos) {
    visit[pos] = 1;
    for (int i = 0; i < G[pos].size(); i++) {
        if (!visit[G[pos][i]]) {
            visit[G[pos][i]] = 1;
            x[G[pos][i]] += x[pos];
            dfs(G[pos][i]);
        }
    }
    return;
}

int main() {
    cin >> n >> q;
    for (int i = 0; i < n - 1; i++) {
        llong a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < q; i++) {
        llong a, b;
        cin >> a >> b;
        x[a] += b;
    }

    dfs(1);

    for (int i = 1; i <= n; i++) {
        if (i > 1) cout << ' ';
        cout << x[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 24448
MOD = 10**9+7
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

if len(set(a)) < n or len(set(b)) < m:
    print(0)
    exit()
if max(a) != n*m or max(b) != n*m:
    print(0)
    exit()

a = sorted(a, reverse = True)
b = sorted(b, reverse = True)
i, j = 0, 0
ans = 1
for num in range(n*m, 0, -1):
    while i < n-1 and a[i+1] >= num:
        i += 1
    while j < m-1 and b[j+1] >= num:
        j += 1
        
    if a[i] == num and b[j] == num:
        pass
    elif a[i] == num:
        ans = (ans*(j+1))%MOD
    elif b[j] == num:
        ans = (ans*(i+1))%MOD
    else:
        cand = max((i+1)*(j+1) - (n*m - num), 0)
        ans = (ans*cand)%MOD
print(ans)

Measured memory_bytes: 3316
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
s = ns()

lr = 0
rl = 0
same = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        same += 1
    elif s[i] == "L":
        lr += 1
    else:
        rl += 1
dv = min(lr, rl, k)
ans = 0
ans += 2*dv
k -= dv
if s[0] == "L" and lr-dv > 0 and k > 0:
    ans += 1
    k -= 1
    lr -= 1
if s[0] == "R" and rl-dv > 0 and k > 0:
    ans += 1
    k -= 1
    rl -= 1
if s[-1] == "L" and rl-dv > 0 and k > 0:
    ans += 1
    k -= 1
    rl -= 1
if s[-1] == "R" and lr-dv > 0 and k > 0:
    ans += 1
    k -= 1
    lr -= 1

print(same + ans)

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

int main() {
	int64_t n, h;
	cin >> n >> h;
	vector<double_t> a(n);
	vector<double_t> b(n);
	for (size_t i = 0; i < n; i++)cin >> a.at(i) >> b.at(i);
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	int64_t ans = 0;
	for (size_t i = 0; i < n; i++) {
		if (b.at(i) > a.at(0)) {
			h -= b.at(i);
			ans++;
		}
		if (h <= 0) {
			cout << ans << endl;
			return 0;
		}
	}
	ans += ceil(h / a.at(0));
	cout << ans << endl;
}

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

using namespace std;

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int ans=0;
    for(int i=1;i<=2;i++){
        if(a>=b){
            ans+=a;
            a--;
        }
        else {
            ans+=b;
            b--;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).OrderBy(p => p).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			int c = vs[2];
			int ans = c * 10 + b + a;
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int n,m;
	cin>>n>>m;
	cout<<(n*(n-1))/2+ (m*(m-1))/2;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)
#define MOD (1000000007)

/////////////////////////////////////////////////////////

void chmin(ll &a, ll b) {if(a > b) a = b; return;}

void Main(){
  ll H, W; cin >> H >> W;
  ll res = INF;

  if(H % 3 == 0) chmin(res, 0);
  else chmin(res, W);
  
  if(W % 3 == 0) chmin(res, 0);
  else chmin(res, H);

  rep(h, 1, H){
    ll ma, mi;
    if(W & 1){
      ma = max(h * W, (H - h) * (W + 1) / 2);
      mi = min(h * W, (H - h) * (W - 1) / 2);
    }else{
      ma = max(h * W, (H - h) * W / 2);
      mi = min(h * W, (H - h) * W / 2);
    }
    chmin(res, ma - mi);
  }

  rep(w, 1, W){
    ll ma, mi;
    if(H & 1){
      ma = max(w * H, (W - w) * (H + 1) / 2);
      mi = min(w * H, (W - w) * (H - 1) / 2);
    }else{
      ma = max(w * H, (W - w) * H / 2);
      mi = min(w * H, (W - w) * H / 2);
    }
    chmin(res, ma - mi);
  }

  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

int main() { _
  string s; cin >> s;
  string a = s.substr(0, (s.size()-1)/2);
  string b = s.substr((s.size()+3)/2 - 1, (s.size()-1)/2);
  string ar = a;
  reverse(ar.begin(), ar.end());
  if (ar == b && ar == a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define MAX_N 100000
#define MAX_M 100

using namespace std;

int N, M;
int A[MAX_N];

vector<int> solve()
{
    vector<int> B;
    switch ( M )
    {
    case 1:
        B.push_back( 1 );
        break;
    case 2:
        B.push_back( A[1] + 1 );
        break;
    default:
        vector<int> idx_odds;
        for ( int i = 0; i < M; i++ )
            if ( A[i] % 2 ) idx_odds.push_back( i );

        switch ( idx_odds.size() )
        {
        case 2:
            swap( A[idx_odds[1]], A[M - 1] );
        case 1:
            swap( A[idx_odds[0]], A[0] );
            break;
        case 0:
            break;
        default:
            return B;
        }

        for ( int i = 1; i < M - 1; i++ ) B.push_back( A[i] );
        B.push_back( A[M - 1] + 1 );
    }

    if ( A[0] > 1 ) B.insert( B.begin(), A[0] - 1 );

    return B;
}

int main( int argc, char **argv )
{
    cin >> N >> M;

    for ( int i = 0; i < M; i++ ) cin >> A[i];

    auto ans = solve();

    if ( ans.size() == 0 )
        cout << "Impossible" << endl;
    else
    {
        for ( int i = 0; i < M - 1; i++ ) cout << A[i] << " ";
        cout << A[M - 1] << endl;

        cout << ans.size() << endl;

        for ( int i = 0; i < ans.size() - 1; i++ ) cout << ans[i] << " ";
        cout << ans[ans.size() - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a[5];
    int k;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
    }
    cin >> k;
    if(a[4]-a[0] > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int z[n];
    for(int i=0;i<n;i++){
        scanf("%d",&z[i]);
    }
    
    
    int a[n];
    
    for(int i=0;i<n;i++)
    {
        a[i]=0;
        if(z[i]!=2&&z[i]%2!=0)
        {
        for(int j=1;(2*j+1)*(2*j+1)<=z[i]&&a[i]==0;j++)
                {
                if(z[i]%(2*j+1)==0)a[i]++;
                else;
                }
        }
        else if(z[i]==2);
        else a[i]++;
    }
    
    int x=0;
    for(int i=0;i<n;i++){
        if(a[i]==0) x++;
        else;
    }
    
    printf("%d\n",x);
    
    return 0;
    
}



Measured memory_bytes: 2096
n = gets.to_s.to_i
s = gets.to_s.chomp.split('')

cnt = 0
n.times do |i|
  j = i + 1
  k = i + 2
  while k < n
    cnt += 1 if s[i] != s[j] && s[j] != s[k] && s[i] != s[k]
    j += 1
    k += 2
  end
end

ans = s.count('R') * s.count('G') * s.count('B') - cnt

puts ans

Measured memory_bytes: 14272
n = int(input())
a = input()
b = input()
c = input()

cnt = 0
for i in range(0, n):
    if (a[i] != b[i]) and (b[i] != c[i]) and (a[i] != c[i]):
        cnt = cnt + 2
    elif (a[i] == b[i]) and (b[i] == c[i]) and (a[i] == c[i]):
        pass
    elif (a[i] == b[i]) or (b[i] == c[i]) or (a[i] == c[i]):
        cnt = cnt + 1

print(cnt)


Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i,n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }

const int mod = 1000000007;
const int INF = 1001001001;

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    int st = -1;
    reverse(t.begin(), t.end());
    reverse(s.begin(), s.end());
    for(int i = 0; i < s.size() - t.size() + 1; i++) {
        bool flag = true;
        for(int j = 0; j < t.size(); j++) {
           if (s[i+j] != '?' && s[i+j] != t[j]) {
               flag = false;
               break;
           }
        }

        if(flag) {
            st = i;
            break;
        }
    }

    string ans = "";
    if(st == -1) cout << "UNRESTORABLE" << endl;
    else {
        for (int i = 0; i < s.size(); i++) {
            if (i == st) {
                rep(j, t.size()) ans += t[j];
                i += t.size() - 1;
            } else {
                if (s[i] == '?') ans += 'a';
                else ans += s[i];
            }
        }

        reverse(ans.begin(), ans.end());

        cout << ans << endl;
    }
}

Measured memory_bytes: 256
//素数判定
#include <iostream>
using namespace std;

int main() {
    int n, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        long long a;
        int b = 1;
        cin >> a;
        //ここを無傷で抜けられたら素数
        for (long long j = 2; j * j <= a; j++) {
            if (a % j == 0) {
                b = 0;
                break;
            }
        }
        cnt += b;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, ll> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll sum = 0;
    for (auto e : mp) {
        ll m = e.second;
        sum += m * (m - 1) / 2;
    }
    for (int i = 0; i < n; i++) {
        ll m = mp[a[i]];
        ll sub = m * (m - 1) / 2 - (m - 1) * (m - 2) / 2;
        cout << sum - sub << endl;
    }
    return 0;
}


Measured memory_bytes: 10240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	char  a;
	char  b;
	int ia,ib;

//入力
    scanf("%c %c",&a,&b);
    ia=(int)a-(int)'0';
    ib=(int)b-(int)'0';

    char  dat[10];

    if(a>b) {memset(dat,b,ia);dat[ia]=0x00;}
    else    {memset(dat,a,ib);dat[ib]=0x00;}

    printf("%s \n",dat);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;

uint64_t A[300001];

ll modexp(int i, ll p){
	if(p == 0) return 1;
	ll ans = modexp(i,p/2);
	ans = (ans*ans)%MOD;
	if(p%2) ans =  (i*ans)%MOD;
	return ans;
}

void solve(){
	int n; cin>>n;
	for(int i=0; i<n; i++){
		cin>>A[i];
	}
	ll ans=0;
	for(int bit=0; bit<60; bit++){
		ll x=0;
		for(int i=0; i<n; i++){
			if((A[i] & (1ULL <<bit))){
				x++;
			}
		}
		//cout<<bit<<" : "<<x<<" sex\n";
		x = (x*(n-x))%MOD;
		ans += (modexp(2,bit)*x)%MOD;
		ans = ans%MOD;
	}
	cout<<ans;

}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;cin >> n;
  int d[n];
  for(int i = 0; i < n; i++)cin >> d[i];
  sort(d, d+n);
  cout << d[n/2]-d[n/2-1] << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int i,a,A[100000],z,jsta=0,jend=0,B[100000],j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<a;i++){
    if(A[i]<=A[a-1]){
      z=A[jsta];
      A[jsta]=A[i];
      A[i]=z;
      jsta++;
      jend++;
    }
    else jend++;
  
  }

   for(i=0;i<a;i++){
     if(i==jsta-1)printf("[%d] ",A[i]);
     else if(i!=a-1)printf("%d ",A[i]);
     else printf("%d",A[i]);
  }
   printf("\n");
}



Measured memory_bytes: 3012
def nsin(X,n):
    if(int(X/n)):
        return nsin(int(X/n),n)+str(X%n)
    return str(X)

N = int(input())
score = N
for i in range(N+1):
    score = min(score,sum(map(int,nsin(i,6)+nsin(N-i,9))))
print(score)

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

int main() {
  int N;
  int a[100000] = {};

  cin >> N;
  for(int i = 1; i <= N; i++){
    cin >> a[i];
  }

  int s = 0;
  for(int i = 0; i <= N; i++){
    s += abs(a[i] - a[i+1]);
  }

  int ans = 0;
  for(int i = 1;i <=N; i++){
    ans = s - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]);
    cout << ans << endl;
  }

}

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

int main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c), s;
    for(int i = 0; i < a; i++) cin >> p[i];
    for(int i = 0; i < b; i++) cin >> q[i];
    for(int i = 0; i < c; i++) cin >> r[i];
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());

    for(int i = 0; i < x; i++) s.push_back(p[i]);
    for(int i = 0; i < y; i++) s.push_back(q[i]);
    for(int i = 0; i < c; i++) s.push_back(r[i]);

    sort(s.begin(), s.end(), greater<int>());
    
    long long ans = 0;
    for(int i = 0; i < x + y; i++) ans += s[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class47
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (I[0] == I[1])
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	ll X, Y;
	scanf("%lld %lld", &X, &Y);

	int ans = 0;
	while (X <= Y) {
		ans++;
		X *= 2;
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int i;
  int j;
 

  for(i=1;i<=9;i++){
    for (j=1;j<=9;j++){
      // k = i * j;
      printf("%dx%d=%d\n",i,j,i*j);
}
}

  return 0;
}

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

int main() {
  string s;cin>>s;
  int n=s.size();
  vector<int> c(n);
  int k;cin>>k;
  rep(i,n) {
    c[i] = static_cast<int>(s[i]-'a');
  }
  rep(i,n) {
    if(i==n-1) {
      c[i] = (c[i]+k)%26;
      break;
    }
    if(c[i]==0) continue;
    if(k+c[i]>=26) {
      k-=26-c[i];
      c[i]=0;
    }
  }
  stringstream ss;
  rep(i,n) {
    ss<<static_cast<char>('a'+c[i]);
  }
  cout << ss.str() << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  vector<int> ans(n);

  int cnt = 0;
  rep(i, n)
  {
    if (s[i] == 'R')
      cnt++;
    else
    {
      ans[i] += cnt / 2;
      ans[i - 1] += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  for (int i = n - 1; 0 <= i; i--)
  {
    if (s[i] == 'L')
      cnt++;
    else
    {
      ans[i] += cnt / 2;
      ans[i + 1] += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  rep(i, n)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1088
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> A >> B;
  ll max_ab = max(A+B, A-B);
  cout << max(max_ab, A*B) << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[100];

    scanf("%s",s);

    if(s[0] == 'S'){
        printf("Cloudy\n");
    } else if(s[0] == 'C'){
        printf("Rainy\n");
    } else {
        printf("Sunny\n");
    }

    return 0;
}

Measured memory_bytes: 128
using System;
	
class Test
{
  static int Main(string[] args){
    
	var code = "";
	code = Console.ReadLine();
    for(int i = 0 ; i < 3 ; i++)
    {
		if(code[i] == code[i+1])
        {
          Console.WriteLine("Bad");
          return 0;
        }
	}
    	Console.WriteLine("Good");
    	return 0;
  }
}

Measured memory_bytes: 13140
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

counter = Counter(read().rstrip()).values()

counter

N = sum(counter)
x = N * (N - 1) // 2 + 1
x -= sum(x * (x - 1) // 2 for x in counter)
print(x)

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

yes = False
for i in range(N + 1):
    for j in range(N + 1):
        if Y == i * 1000 + j * 5000 + 10000 * (N - i - j) and i + j <= N:
            yes = True
            break
    if yes:
        break
        
if yes:
    print(N - i - j, j, i)
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		if((b-a)%2 == 0) {
			System.out.println((b-a)/2);
		}else {
			long answer = 0;
			if((a-1) > (n-b)) {
				answer = (n-b) + ((n-a) -(n-b) +1)/2;
			}else {
				answer = (a-1) + (b-(a-1) +1)/2;
			}
			System.out.println(answer);
		}
	}

}

Measured memory_bytes: 23892
#include <iostream>
#include<string>
using namespace std;
int main()
{
	string S[7] = { "SUN","MON","TUE","WED","THU", "FRI","SAT" };
	string b;
	while (cin >> b)
	{
		if (b == S[0])
		{
			cout << 7 << endl;
		}
		else if (b == S[1])
		{
			cout << 6 << endl;
		}
		else if (b == S[2])
		{
			cout << 5 << endl;
		}
		else if (b == S[3])
		{
			cout << 4 << endl;
		}
		else if (b == S[4])
		{
			cout << 3 << endl;
		}
		else if (b == S[5])
		{
			cout << 2 << endl;
		}
		else 
		{
			cout << 1 << endl;
		}
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    vector <int> a;
    int n,x;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    while(a.size()>1){
        x=a.back();
        a.pop_back();
        if (x==a.back()){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
 }


Measured memory_bytes: 1400
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int mod = 998244353;

inline int add(int a, int b) {
  return a+b >= mod ? a+b-mod : a+b;
}

inline int sub(int a, int b) {
  return a >= b ? a-b : a-b+mod;
}

inline int mul(int a, int b) {
  return llint(a)*b % mod;
}

int powmod(int a, int b) {
  if (b == 0) return 1;
  if (b&1) return mul(a, powmod(a, b-1));
  return powmod(mul(a, a), b/2);
}

namespace NTT {
  int g = 0; // !

  void findPrimitiveRoot() {
    if (g) return;

    vector<int> d;
    for (int i = 2; i*i <= mod-1; ++i)
      if ((mod-1) % i == 0) d.push_back(i), d.push_back((mod-1)/i);
    for (g = 2; ; g++) {
      bool ok = true;
      for (int x: d) ok &= powmod(g, x) != 1;
      if (ok) break;
    }
  }
  
  void transform(int* a, int* z, int* omega, int m, int N) {
    if (m == 1) {
      z[0] = a[0];
    } else {
      int s = N/m;
      m /= 2;
 
      transform(a, z, omega, m, N);
      transform(a+s, z+m, omega, m, N);
 
      REP(i, m) {
        int c = mul(omega[s*i], z[m+i]);
        z[m+i] = sub(z[i], c);
        z[i] = add(z[i], c);
      }
    }
  }

  vector<int> fft(vector<int>& a) {
    findPrimitiveRoot();

    int N = a.size();
    int w = powmod(g, (mod-1) / N);
    vector<int> omega(N);
    omega[0] = 1;
    FOR(i, 1, N) omega[i] = mul(omega[i-1], w);

    vector<int> z(N);
    transform(a.data(), z.data(), omega.data(), N, N);
    return z;
  }
  
  vector<int> ifft(vector<int>& a) {
    findPrimitiveRoot();

    int N = a.size();
    int wi = powmod(powmod(g, (mod-1)/N), mod-2);
    vector<int> omega(N);
    omega[0] = 1;
    FOR(i, 1, N) omega[i] = mul(omega[i-1], wi);

    vector<int> z(N);
    transform(a.data(), z.data(), omega.data(), N, N);
    
    int invN = powmod(N, mod - 2);
    REP(i, N) z[i] = mul(z[i], invN);
    return z;
  }
  
  vector<int> mult(vector<int> a, vector<int> b) {
    int N = a.size() + b.size();
    while (N & (N-1)) ++N;

    a.resize(N, 0);
    b.resize(N, 0);

    vector<int> ta = fft(a);
    vector<int> tb = fft(b);
    REP(i, N) ta[i] = mul(ta[i], tb[i]);
    return ifft(ta);
  }
};

const int MAX = 10010;

int f[MAX], invf[MAX];

int main(void) {
  NTT::findPrimitiveRoot();
  
  f[0] = 1;
  FOR(i, 1, MAX) f[i] = mul(f[i-1], i);
  REP(i, MAX) invf[i] = powmod(f[i], mod-2);
  
  static char a[MAX], b[MAX];
  scanf("%s", a);
  scanf("%s", b);

  int n = strlen(a);
  int x = 0, y = 0;
  REP(i, n) {
    if (a[i] == '1') {
      if (b[i] == '0') x++;
      else y++;
    }
  }

  vector<int> r(y + 1, 1);
  vector<int> v(y + 1);
  for (int i = 0; i <= y; ++i) {
    v[i] = invf[i + 1];
  }

  
  int e = x;
  while (e > 0) {
    if (e % 2) {
      r = NTT::mult(v, r);
      r.resize(y + 1);
    }
    v = NTT::mult(v, v);
    v.resize(y + 1);
    e /= 2;
  }

  int ret = r[y];
  ret = mul(ret, f[x + y]);
  ret = mul(ret, f[y]);
  ret = mul(ret, f[x]);
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 1588
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

ll mod_pow(ll a,ll x){
    ll ret=1;
    while(x>0){
        if(x&1){(ret*=a)%=MOD;}
        x>>=1;
        (a*=a)%=MOD;
    }
    return ret;
}

int main(){
    string L;
    cin>>L;
    ll ans=0,cnt=0;
    for(ll i=0;i<L.size();i++){
        if(L[i]=='1'){
            ans+=mod_pow(3,L.size()-i-1)*mod_pow(2,cnt)%MOD;
            cnt++;
        }
    }
    ans+=mod_pow(2,cnt);
    ans%=MOD;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {
		int n=sc.nextInt();
		String[] keys=new String[n];
		for(int i=0;i<n;i++){
			keys[i]=sc.next();
		}
		Arrays.sort(keys);

		int m=sc.nextInt();
		boolean locked=true;
		for(int i=0;i<m;i++){
			String key=sc.next();
			int j=Arrays.binarySearch(keys,key);
			if(j>=0){
				ln((locked?"Opened":"Closed")+" by "+key);
				locked=!locked;
			}else{
				ln("Unknown "+key);
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 20428
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int ans;
	if (s == "SUN")
		ans = 7;
	else if (s == "MON")
		ans = 6;
	else if (s == "TUE")
		ans = 5;
	else if (s == "WED")
		ans = 4;
	else if (s == "THU")
		ans = 3;
	else if (s == "FRI")
		ans = 2;
	else
		ans = 1;
	cout << ans;
	return 0;
}

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

long long gcd(long long x, long long y){
  long long a = max(x, y), b = min(x, y);
  if(b == 0){
    return a;
  }
  return gcd(b, a % b);
}

int main(){
  int N, M;
  cin >> N >> M;

  vector<int> a(N);
  for(auto& x: a){
    cin >> x;
  }

  // X = a_k * (p + 0.5)
  // X = (a_k / 2) * (2p + 1)

  for_each(a.begin(), a.end(), [](auto& x){x /= 2;});

  vector<int> two_factor_cnt(N);
  for(int i = 0; i < N; i++){
    int a_copy = a[i];
    while(a_copy % 2 == 0){
      a_copy /= 2;
      two_factor_cnt[i]++;
    }
  }

  bool inequal_evenness = false;
  for(int i = 0; i + 1 < N; i++){
    if(two_factor_cnt[i] != two_factor_cnt[i + 1]){
      inequal_evenness = true;
    }
  }
  if(inequal_evenness){
    cout << 0 << endl;
    return 0;
  }

  long long lcm = a[0];
  for(int i = 1; i < N; i++){
    if(lcm > M){
      cout << 0 << endl;
      return 0;
    }
    long long gcd_tmp = gcd(lcm, a[i]);
    lcm = lcm * a[i] / gcd_tmp;
  }

  //cout << lcm << endl;
  cout << (M / lcm + 1) / 2 << endl;

}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=998244353 ;


ll dp[333][333][333], dp2[333][333][333], used[666][666];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.size();
    string t(s.rbegin(),s.rend());
    dp[0][0][0]=1;
    rep(i,n+1)rep(j,301)rep(k,301){
        if(i==0&&j==0&&k==0)continue;
        if(i==0){
            if(j>0)dp[i][j][k]+=dp[i][j-1][k];
            if(k>0)dp[i][j][k]+=dp[i][j][k-1];
        }
        if(i>0 && t[i-1]=='0'){
            dp[i][j][k]+=dp[i-1][j][k];
            if(k>0)dp[i][j][k]+=dp[i][j][k-1];
        }
        if(i>0 && t[i-1]=='1'){
            dp[i][j][k]+=dp[i-1][j][k];
            if(j>0)dp[i][j][k]+=dp[i][j-1][k];
        }
        dp[i][j][k]%=mod;
    }
    dp2[0][0][0]=1;
    rep(i,n+1)for(int j=300;j>=0;--j)for(int k=300;k>=0;--k){
        if(j>=2)dp2[i][j-2][k]|=dp2[i][j][k];
        if(k>=2)dp2[i][j][k-2]|=dp2[i][j][k];
        if(j>=1 && k>=1)dp2[i][j-1][k-1]|=dp2[i][j][k];
        if(i<n && s[i]=='0'){
            if(j>0||k>0)dp2[i+1][j][k]|=dp2[i][j][k];
            if(k>0)dp2[i+1][j+1][k-1]|=dp2[i][j][k];
        }
        if(i<n && s[i]=='1'){
            if(j>0)dp2[i+1][j-1][k+1]|=dp2[i][j][k];
            if(j>0||k>0)dp2[i+1][j][k]|=dp2[i][j][k];
        }
        if(i+1<n){
            if(s[i]=='0'||s[i+1]=='0')dp2[i+2][j+1][k]|=dp2[i][j][k];
            if(s[i]=='1'||s[i+1]=='1')dp2[i+2][j][k+1]|=dp2[i][j][k];
        }
    }
    ll ans=0;
    int z=0, o=0;
    used[0][0]=1;
    rep(i,n+1){
        if(i!=0){
            if(s[n-i]=='0')z++;
            else o++;
        }
        rep(j,n+1)rep(k,n+1){
            if(dp2[n-i][j][k] && !used[z+j][o+k]){
                ans+=dp[i][j][k];
                used[z+j][o+k]=1;
            }
        }
    }
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 478836
#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

int __gcd(int x, int y) { if(!y) return x; return __gcd(y, x % y); }

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define sag (k + k + 1)
#define sol (k + k)

#define type(x) __typeof(x.begin())

#define orta ((bas + son) >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair


#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
int mod = (int) 1e9;
const int logN = 18;
const int inf = 1e9 + 9;

const int N = 1e5 + 5;

int n, t, x, y;

int main(){
	int xx = 0, yy = 0, tt = 0, f = 1;
	scanf("%d", &n);
	FOR(i, 1, n) {
		scanf("%d %d %d", &t, &x, &y);
		int d = abs(x - xx) + abs(y - yy);
		if(t - tt < d || (t-tt-d) % 2 != 0) f = 0;
		tt = t; xx = x; yy = y;
	}
	if(f) cout << "Yes\n" << endl;
	else cout << "No\n" << endl;
	return 0;
}

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

int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a == 0) cout << 1 << endl;
  if(b == 0) cout << 2 << endl;
  if(c == 0) cout << 3 << endl;
  if(d == 0) cout << 4 << endl;
  if(e == 0) cout << 5 << endl;
}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int a, b, c;
int main() {
		cin >> a >> b >> c;
		if (a == b) {
			if (a != c)
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		}
		else if (a == c || b == c)
			cout << "Yes" << endl;
		else cout << "No" << endl;
}

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

using namespace std;

int main(){
	map<char, bool> mp;
	map<char, bool> apa_s, apa_t;
	string s, t;
	cin >> s >> t;
	int len_s = s.length();
	int len_t = t.length();
	int pakai = min(len_s, len_t);
	bool haha = 0; char ss = s[0], tt = t[0];
	int awal = 0, jum_s = 0, jum_t = 0;
	while(!haha){
		if(awal >= pakai) break;
		for(int i = 0; i < len_s; i++) {
			if(apa_s[s[i]] == 0) { //cout << "CIKKK" << endl;
				apa_s[s[i]] = 1; jum_s++;
			}
			if(mp[s[i]] != 1) ss = min(ss, s[i]);
		}
		for(int i = 0; i < len_t; i++) {
			if(apa_t[t[i]] == 0) { //cout << "YES" << endl;
				apa_t[t[i]] = 1; jum_t++;
			}
			if(mp[t[i]] != 1) tt = max(tt, t[i]);
		}
		mp[ss] = 1; mp[tt] = 1;
		//cout << ss << ' ' << tt << endl;
		if(ss != tt) haha = 1;
		awal++;
	} //cout << jum_s << ' ' << jum_t << endl;
	if(jum_s == 1 && jum_t == 1 && len_s < len_t){
		printf("Yes\n");
		return 0;
	}
	if(ss < tt) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256