akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; ll k;
    cin>>n>>k;
    int x[200020];
    for(int i=0; i<n; i++){
        cin>>x[i];
    }
    int nx[20][200020], nxr[20][200020];
    ll sl[20][200020], sr[20][200020];
    nx[0][n]=n;
    nxr[0][0]=0;
    for(int i=0; i<n; i++){
        nx[0][i]=lower_bound(x, x+n, x[i]+k)-x;
        sl[0][i]=nx[0][i];
        nxr[0][i+1]=upper_bound(x, x+n, x[i]-k)-x;
        sr[0][i+1]=nxr[0][i+1];
    }
    for(int i=1; i<20; i++){
        for(int j=0; j<=n; j++){
            nx[i][j]=nx[i-1][nx[i-1][j]];
            sl[i][j]=sl[i-1][j]+sl[i-1][nx[i-1][j]];
            nxr[i][j]=nxr[i-1][nxr[i-1][j]];
            sr[i][j]=sr[i-1][j]+sr[i-1][nxr[i-1][j]];
        }
    }
    int q; cin>>q;
    while(q--){
        int l, r; cin>>l>>r;
        l--; r--;
        if(l==r){
            cout<<1<<endl;
            continue;
        }
        ll suml=0, sumr=0;
        int c=0;
        int l1=l;
        for(int i=19; i>=0; i--){
            if(nx[i][l1]<=r){
                c+=(1<<i);
                suml+=sl[i][l1];
                l1=nx[i][l1];
            }
        }
        int r1=r+1;
        for(int i=19; i>=0; i--){
            if(nxr[i][r1]>=l+1){
                sumr+=sr[i][r1];
                r1=nxr[i][r1];
            }
        }
        cout<<sumr-suml+r+1-l<<endl;
    }
    return 0;
}



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

int main(int argc, char const* argv[])
{
	int a, b;
	cin >> a >> b;
	int max = -2001;
	if(b > 0)max = a + b;
	else max = a -b;
	if(max < a * b)max = a * b;
	cout << max << endl;
	return 0;
}


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

using namespace std;

int main(){
    int n;
    string s;
    char a[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    cin >> n;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        s[i] += n; 
        cout << a[(s[i] - 65) % 26];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long a[1001];
int main()
{
	int n, k;
	long long mx = 0;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%lld", &a[i]);
		a[i] += a[i - 1];
	}
	vector<long long> b(0);
	for(int i = 0; i <= n; ++i)
	{
		for(int j = i + 1; j <= n; ++j)
		{
			b.push_back(a[j] - a[i]);
		}
	}
	for(int i = 40, count = 0; i >= 0; --i, count = 0)
	{ 
		long long l = mx + (1ll << i);
		for(long long j : b)
		{
			if((j & l) == l)
			{
				++count;
			}
		}
		if(count >= k)
		{
			mx = l;
		}
	}
	printf("%lld\n", mx);
}


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

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

int main() {
    int64 mod = 1000000007;
    int64 n;
    cin >> n;
    
    vector dp(n+1, vector(4, 0LL));
    dp[0][0] = 1;

    for (int i=1; i<=n; i++) {
        dp[i][0] = (dp[i-1][0] * 8) % mod;
        dp[i][1] = (dp[i-1][0] + dp[i-1][1]*9) % mod;
        dp[i][2] = (dp[i-1][0] + dp[i-1][2]*9) % mod;
        dp[i][3] = (dp[i-1][1] + dp[i-1][2] + dp[i-1][3]*10) % mod;
    }

    cout << dp[n][3] << endl;
}


Measured memory_bytes: 73068
#include<stdio.h>



int main()
{
  int n,r[101],c[101],m[101][101],i,j,k,l,q;

  scanf("%d",&n);
  
  for(i = 1;i <= n;i++)
    scanf("%d%d",&r[i],&c[i]);
  
  for(i = 1;i <= n;i++) m[i][i] = 0;

  
  for(l = 2;l <= n;l++) {
    for(i = 1;i <= n - l + 1;i++) {
      j = i + l - 1;
      m[i][j] = 100000000;
      for(k = i;k <= j - 1;k++){
	q = m[i][k] +m[k + 1][j] + r[i] * c[k] * c[j];
	if(m[i][j] > q) m[i][j] = q;


      }
    }
  }
  
  printf("%d\n",m[1][n]);

  return 0;
}



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

int main(){
  string N;
  cin>>N;
  bool ans=true;
  for(int i=0;i<3;i++){
    if(N.at(i)=='7'){
      cout<<"Yes"<<endl;
      ans=false;
      break;
    }
  }
  if(ans){
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3580
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,
        k:usize,
        a:[i32;n],
    }
    let mut ans = vec![];
    for i in k..n {
        if a[i - k] < a[i] {
            ans.push(true);
        } else {
            ans.push(false);
        }
    }
    for &x in ans.iter() {
        print!("{} ", if x { "Yes" } else { "No" });
    }
}


Measured memory_bytes: 5152
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    n,k=map(int,input().split())
    s=input()
    G=groupby(s)
    A=[]
    cnt=0
    if(s[0]=='0'): A.append(0)
    for key,iter in G:
        cnt+=key=='0'
        A.append(len(list(iter)))
    if(s[-1]=='0'): A.append(0)
    if(cnt<=k):
        print(n)
        return

    n=len(A)
    now=sum(A[:2*k+1])
    score=now
    for i in range(2*k+2,n,2):
        now+=A[i]+A[i-1]-A[i-2*k-2]-A[i-2*k-1]
        score=max(score,now)
    print(score)
resolve()

Measured memory_bytes: 45168
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll d;
    cin>>d;
    if(d==22){
        cout<<"Christmas Eve Eve Eve"<<endl;
    }else if(d==23){
        cout<<"Christmas Eve Eve"<<endl;
    }else if(d==24){
        cout<<"Christmas Eve"<<endl;
    }else if(d==25){
        cout<<"Christmas"<<endl;
    }
}

Measured memory_bytes: 256
//***********************
//Author:kibi11
//Quarantine Days
//***********************

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define N 2e6+1
#define MOD 1000000007
#define dd double
#define fr(i, n) for(int i = 0; i < n; i++)
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,k) for(int i=a;i>=k;i--)
#define same int t;cin>>t;while(t--)
#define check(x) cout << (#x) << " is " << (x) << endl;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
#define pi = 3.14159265358979323846

//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
 
ll powermod(ll base, ll exp, ll mod) {
	ll result = 1;
	while (exp != 0) {
		if ((exp % 2) == 1) {
			result = (result * base) % mod;
		}
		base = (base * base) % mod;
		exp /= 2;
	}
	return result;
}

///////////////////////////////////////////////////////////////////////////
//Fuctions if any:
std::vector<ll> v(N);
int n;
bool see(ll mid,ll k)
{
	ll count=0;
	fr(i,n)
	{
		count+=(v[i]-1)/mid;
	}
	// cout<<count<<endl;
	return count<=k;
}





///////////////////////////////////////////////////////////////////////////
int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
//ios_base& scientific (ios_base& str);

ll k;
cin>>n>>k;
// vector<int> v(n);
fr(i,n) cin>>v[i];
ll min=1;
ll max=*max_element(v.begin(), v.end());
ll mid;
while(min!=max)
{
	
	mid=(min+max)/2;
	// debug(min,max,mid);
	if(see(mid,k))
	{
		max=mid;
	}
	else
	{
		min=mid+1;
	}
	// debug(min,max,mid);

}
cout<<max<<endl;
cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}

Measured memory_bytes: 18636
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = Mint(2).pow(n);
  Mint pow(long long n) const {
    if (n==0) return Mint(1);
    Mint y = pow(n>>1); // pow(n/2)を計算する
    y *= y;
    if (n%2==1) y *= *this;
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return a.pow(mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    Mint one = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= (i + one);
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

long long dp[200004][3];
int main() {
  int N;
  std::cin >> N;
  std::vector<long long > A(N);
  for (int i=0; i<N; i++) {
    std::cin >> A[i];
  }
  for (int i=0; i<200004; i++) {
    dp[i][0] = -1e18;
    dp[i][1] = -1e18;
    dp[i][2] = -1e18;
  }
  dp[0][0] = A[0];
  dp[1][1] = A[1];
  dp[2][2] = A[2];
  for (int i=2; i<N; i++) {
    dp[i][0] = std::max(dp[i][0], dp[i-2][0] + A[i]);
    dp[i][1] = std::max(dp[i][1], dp[i-2][1] + A[i]);
    dp[i][2] = std::max(dp[i][2], dp[i-2][2] + A[i]);
    if (i>=3) {
      dp[i][1] = std::max(dp[i][1], dp[i-3][0]+A[i]);
      dp[i][2] = std::max(dp[i][2], dp[i-3][1]+A[i]);
    }
    if (i>=4) {
      dp[i][2] = std::max(dp[i][2], dp[i-4][0]+A[i]);
    }
  }
  long long ans = -1e18;
  /*for (int i=0; i<N; i++) {
    printf("dp[%d][0]=%lld\n", i, dp[i][0]);
    printf("dp[%d][1]=%lld\n", i, dp[i][1]);
    printf("dp[%d][2]=%lld\n", i, dp[i][2]);
  }*/
  if (N%2==0) {
    ans = std::max(ans, dp[N-2][0]);
    ans = std::max(ans, dp[N-1][1]);
  } else {
    ans = std::max(ans, dp[N-1][2]);
    ans = std::max(ans, dp[N-2][1]);
    ans = std::max(ans, dp[N-3][0]);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int main()
{
  fast();
  int n=D();
  int x=n/15;
  ll sum1=(800*n)-(x*200);
  cout<<sum1<<endl;

}



Measured memory_bytes: 256
s=input()
if s==s[-1::-1] and s[:(len(s)-1)//2]==s[(len(s)-1)//2-1::-1] and s[(len(s)+3)//2-1:]==s[-1:-(len(s)-1)//2-1:-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int a,s,d,i;
	scanf("%d",&a);
	while(a!=0){
	d=0;
	for(i=1;i<=9;i++){
		scanf("%d",&s);
		d=s+d;
	}
	printf("%d\n",a-d);
	scanf("%d",&a);
	}
	return 0;
}

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

const int MAX_N	= 100000;
bool bC[ 31 ][ MAX_N + 5 ];

int main()
{
int i;
int j;
int N;
int C;
int s;
int t;
int c;
int iMax;
int iCnt;

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

	cin >> N;
	cin >> C;

	for( i = 1; i <= N; i++ )
	{
		cin >> s;
		cin >> t;
		cin >> c;

		for( j = s - 1; j < t; j++ )
			bC[ c ][ j ] = true;
	}

	iMax = 0;
	for( j = 1; j <= MAX_N; j++ )
	{
		iCnt = 0;
		for( i = 1; i <= C; i++ )
		{
			if( bC[ i ][ j ] ) iCnt++;
		}

		if( iMax < iCnt ) iMax = iCnt;
	}

	cout << iMax << endl;

	return 0;
}




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

int main()
{
        int a,b,f=0,j,k,sum,ans,n,odd,even,c=0;
    
        cin>>a>>b;
        for(int i=0;i<a;i++)
        {
            cin>>k;
            if(k>=b)
                c++;
        }
        cout<<c<<"\n";
        return 0;
    }


Measured memory_bytes: 256
n , k = map(int ,input().split())
n_all_list = []
cnt = 1
n_cnt = 0
while cnt <= k :
    d_x = int(input())
    n_list = map(int,input().split())
    n_all_list.extend(n_list)
    cnt += 1

set(n_all_list)
n_all_dict = {}
for i in range(1,n + 1):
    n_all_dict[i] = ""

for x in n_all_list :
    n_all_dict[x] = "exsit"

for i in n_all_dict.values():
    if i == "":
        n_cnt += 1

print(n_cnt)

Measured memory_bytes: 9084
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 2e6;
int a, b, c;
int cnt;
int main(){
	while(~scanf("%d %d %d", &a, &b, &c)){
		bool flag = false;
		while(true){
			if((a & 1) || (b & 1) || (c & 1)){
				flag = true;
				break;
			}
			cnt++;
			int ta, tb, tc;
			ta = a, tb = b, tc = c;
			a = (tb + tc) / 2;
			b = (ta + tc) / 2;
			c = (ta + tb) / 2;
			if(cnt > MaxN) break;
		}
		if(flag) printf("%d\n", cnt);
		else printf("-1\n");
	}
	return 0;
}
			


Measured memory_bytes: 128
// ABC087

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  const A = parseInt(input[0],10);
  const B = parseInt(input[1],10);
  const C = parseInt(input[2],10);
  const X = parseInt(input[3],10);
  var count = 0;

  for(var a=0;a<=A;a++) {
    for(var b=0;b<=B;b++) {
      for(var c=0;c<=C;c++) {
        var sum = (a*500) + (b*100) + (c*50);
        if(sum == X)count++;
      }
    }
  }
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define range(i, a, b) for(long long i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int n, m;
vector <long long> x, y, z;

long long exe(bool negx, bool negy, bool negz) {
    long long sum = 0;
    vector <long long> va;
    rep (i, n) {
        long long xx = x[i], yy = y[i], zz = z[i];
        if (negx) xx *= -1;
        if (negy) yy *= -1;
        if (negz) zz *= -1;
        va.push_back(xx + yy + zz);
    }
    sort(va.rbegin(), va.rend());
    rep (i, m) sum += va[i];
    return sum;
}

int main() {
    cin >> n >> m;
    x = y = z = vector <long long> (n);
    rep (i, n) cin >> x[i] >> y[i] >> z[i];

    long long ans = 0;
    rep (i, 2) rep (j, 2) rep (k, 2) ans = max(ans, exe(i, j, k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def answer():
    S = input()
    K = int(input())

    previous = S[0]
    i = 0
    continue_dict = {
        0: 0
    }
    for s in S:
        if s == previous:
            continue_dict[i] += 1
        else:
            i += 1
            continue_dict[i] = 1
        previous = s

    if len(continue_dict) == 1:
        ans = continue_dict[0] * K // 2
    else:
        # head + tail
        count_ht = 0
        for l in continue_dict.values():
            count_ht += l // 2

        if K > 1:
            # between
            if S[0] == S[-1]:
                continue_dict[0] += continue_dict[i]
                continue_dict.pop(i)

            count_btw = 0
            for l in continue_dict.values():
                count_btw += l // 2

            ans = count_ht + count_btw * (K-1)
        else:
            ans = count_ht

    print(ans)


if __name__ == '__main__':
    answer()



Measured memory_bytes: 3064
numList = map(int, raw_input().split())
k = int(raw_input())
maxN = max(numList)
maxIndex = numList.index(maxN)
ans = 0
for i in range(len(numList)):
    if i == maxIndex:
        tmp = maxN
        for j in range(k):
            tmp *= 2
        ans += tmp
    else:
        ans += numList[i]
print ans


Measured memory_bytes: 2568
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

A=0
B=0
C=0
z=[]
for i in range(n):
    A+=abs(x[i]-y[i])
    B+=(x[i]-y[i])*(x[i]-y[i])
    C+=(abs(x[i]-y[i]))**3
    z.append(abs(x[i]-y[i]))
D=max(z)

    
B=B**(1/2)
C=C**(1/3)

print(A)
print(B)
print(C)
print(D)



Measured memory_bytes: 5640
#include<iostream>
#include<vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(void){
    int N,D;
    cin>>N>>D;
    int coun=0;
    int avi=0;
    avi=2*D*(coun)+coun;
    do{
         coun++;
        avi=2*D*(coun)+coun;
    }while(avi<N);

    cout<<coun<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>

#include <sstream>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    auto data = vector<int>(n + 1, 0);
    for (int i = 1; i <= n; i++) scanf("%d", &data[i]);
    auto balls = vector<int>(n + 1, 0);
    vector<int>ans;
    for (int i = n; i >= 1; i--) {
        int s = 0;
        for (int j = i + i; j <= n; j += i) {
            s ^= balls[j];
        }

        if (s != data[i]) {
            balls[i] = 1;
            ans.push_back(i);
        }
    }

    // printf("%d\n", ans.size());
    if (ans.size() == 0) {
        cout << 0 << endl;
    } else {
        cout << ans.size() << endl;
        auto it = ans.crbegin();
        cout << *it++;
        for (auto end = ans.crend(); it != end; ++it) {
          cout << " " << *it;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3064
s = input()
s_l = [0] * (len(s) + 1)
s_r = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        s_l[i + 1] = s_l[i] + 1
for i in range(len(s)):
    if s[- i - 1] == '>':
        s_r[- i - 2] = s_r[- i - 1] + 1
        
ans = 0
for i, j in zip(s_l, s_r):
    ans += max(i, j)
print(ans)

Measured memory_bytes: 32996
N, W = map(int, input().split())
t = [[int(i) for i in input().split()] for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)]

for n in range(1, N+1):
    for w in range(1, W+1):
        if w - t[n-1][0] >= 0:
            dp[n][w] = max(dp[n-1][w-t[n-1][0]]+t[n-1][1], dp[n-1][w])
        else:
            dp[n][w] = dp[n-1][w]

print(dp[N][W])


Measured memory_bytes: 120172
/*input
abracadabra
avadakedavra

*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    

 

int32_t main() {
    IOS;
	string s,t;cin>>s>>t;
	int n = s.size(),m = t.size();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++)dp[i][0] = 0;
	for(int i=0;i<=m;i++)dp[0][i] = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1])
				dp[i][j] = dp[i-1][j-1]+1;
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	int i = n,j = m;
	string ans;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			ans.push_back(s[i-1]);
			i--;
			j--;
		}
		else{
			if(dp[i][j]==dp[i][j-1]){
				j--;
			}
			else{
				i--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}






Measured memory_bytes: 70656
#include <stdio.h>

int main(void)
{
	int num;
	double kg, m, b;
	
	while (scanf("%d,%lf,%lf", &num, &kg, &m) != EOF){
		b = kg /(m * m);
		if (25.0 <= b){
			printf("%d\n", num);
		}
	}
	
	return 0;
}

Measured memory_bytes: 628
import java.io.*;
import java.util.*;
public class Main {
static long[][] memo;
static int I,J;
static String h,s;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
	   h=sc.nextLine();
	   s=sc.nextLine();
	   I=h.length();
	   J=s.length();
	   memo=new long[I][J];
	   for(long []a:memo)
		   Arrays.fill(a,-1);
	   dp(0,0);
	   long max=0; int im=0; int jm=0;
	   for(int i=0;i<I;i++) {
		   for(int j=0;j<J;j++)
			   if(memo[i][j]>=max) {
				   max=memo[i][j];
				   im=i;
				   jm=j;
			   }
	   }
	   if(max==0) {
		   System.out.println(" ");
		   return;
	   }
	   trace(0,0);
	}
	static void trace(int i,int j) {
		if(i==I || j==J)
			return;
		if(i==I-1 && j==J-1) {
			if(s.charAt(j)==h.charAt(i))
				System.out.print(s.charAt(j));
			return;
		}
		if(i==I-1) {
			if(s.charAt(j)==h.charAt(i)) {
				System.out.print(s.charAt(j));
			return ;}
			trace(i,j+1); return;
		}
		if(j==J-1) {
			if(s.charAt(j)==h.charAt(i)) {
				System.out.print(s.charAt(j));
			return ;}
			trace(i+1,j); return;
		}
		if(h.charAt(i)==s.charAt(j)) {
			System.out.print(s.charAt(j));
			trace(i+1,j+1);
			return;
		}
		if(dp(i+1,j)>dp(i,j+1))
			trace(i+1,j);
		else
			trace(i,j+1);
	}
	static long dp(int i,int j) {
		if(i==I || j==J)
			return 0;
		if(memo[i][j]!=-1)
			return memo[i][j];
		long v=0;
		if(h.charAt(i)==s.charAt(j))
		v=1+dp(i+1,j+1);
		return memo[i][j]=Math.max(v, Math.max(dp(i,j+1),dp(i+1,j)));
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 130076
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int to[5000][1001];

int a, b;
int ca[5000];
int cb[5000];

int main(){
    scanf("%d%d", &a, &b);
    for(int i = 0; i < a; i++){
        fill(to[i], to[i] + 1001, INF);
        scanf("%d", ca + i);
    }
    for(int i = 0; i < b; i++){ scanf("%d", cb + i); }
    for(int i = 0; i < a; i++){
        for(int j = i+1; j < a; j++){
            to[i][ca[j]] = min(to[i][ca[j]], j);
        }
    }
    int ans = 0;
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++){
            if(ca[i] != cb[j]) continue;
            int depth = 1, inda = i, indb = j + 1;
            while(inda < a && indb < b){
                inda = to[inda][cb[indb]];
                if(inda == INF) break;
                ++depth; ++indb;
            }
            ans = max(ans, depth);
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;


class node {
  public:
    long long int value;
    node *prev;
    node *next;
    node(long long int _value, node* _prev, node* _next) {
      value = _value;
      prev = _prev;
      next = _next;
    };
};

node *nil;

void init() {
  nil = new node(-1, NULL, NULL);
  nil->prev = nil;
  nil->next = nil;
}

int main() {
  init();  

  int n;
  string command;
  long long int key;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command;

    if (command == "insert") {
      cin >> key;
      node* x = new node(key, nil, nil);

      nil->next->prev = x;
      x->next = nil->next;

      x->prev = nil; 
      nil->next = x;
    } else if (command == "delete") {
      cin >> key;
      node* x = nil->next;

      while(x != nil) {
        if (x->value == key){
          x->next->prev = x->prev;
          x->prev->next = x->next;
          break;
        }
        x = x->next;
      }
    } else if (command == "deleteFirst") {
      if(nil != nil->next) {
        nil->next = nil->next->next;
        nil->next->prev = nil;
      }
    } else if (command == "deleteLast") {
      if(nil != nil->prev) {
        nil->prev = nil->prev->prev;
        nil->prev->next = nil;
      }
    }
  }

  node* ni = nil->next;
  while(ni != nil) {
    if(ni->prev != nil) cout << " ";
    cout << ni->value;

    ni = ni->next;
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 37440
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (a < b)
                out.println("a < b");
            else if (a > b)
                out.println("a > b");
            else
                out.println("a == b");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}




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

int main(){
  int X, N; cin >> X >> N;
  map<int, int> mp;
  rep(i, N) {
    int p; cin >> p;
    mp[p]++;
  }
  int ans, score = 1000;
  rep(i, 102) {
    if (mp[i] > 0) continue;
    if (abs(X - i) < score) {
      score = abs(X - i);
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
N=int(input())

for h in range(1,3500+1):
    for n in range(1,3500+1):
        try:
            if (N*h*n)%(4*h*n-N*(h+n))==0 and (4*h*n-N*(h+n))>0:
                A,B,C=h,n,(N*h*n)//(4*h*n-N*(h+n))
        except:
            pass
print(A,B,C)

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>p(n);
  rep(i,0,n)cin>>p[i];
  ll mi=INF;
  rep(i,0,n){
    if(mi>=p[i])res++;
    chmin(mi,p[i]);
  }
  cout<<res<<endl;
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;

  string board[h];
  for (int i = 0; i < h; i++) { cin >> board[i]; }

  // counter clockwise
  const int dx[8] = {1, 1, 0, -1, -1, -1,  0,  1};
  const int dy[8] = {0, 1, 1,  1,  0, -1, -1, -1};

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#') { continue; }

      int num = 0;
      for (int d = 0; d < 8; d++) {
        // vertical
        const int ni = i + dy[d];
        // horizontal
        const int nj = j + dx[d];
        if (ni < 0 || ni >= h) { continue; }
        if (nj < 0 || nj >= w) { continue; }
        if (board[ni][nj] == '#') { num++; }
      }

      board[i][j] = '0' + num;
    }
  }

  for (int i = 0; i < h; i++) { cout << board[i] << endl; }
  return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>
#define N 100


int main()
{
  int i,j,a[N],n,v,c = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
	v = a[j];
	a[j] = a[j-1];
	a[j-1] = v;
	c++;
      }/* 隣あう値が後ろ側に小さい値がある場合交換する */
    }/* n個目から交換の終っているi番目迄実行する */
  }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long qp(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
struct Matrix {
	long long mat[2][2];
	Matrix(long long x = 0) {
		memset(mat, 0, sizeof(mat));
		mat[0][0] = mat[1][1] = x;
	}
	Matrix operator * (const Matrix &oth) const {
		Matrix res;
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++)
				for (int k = 0; k < 2; k++)
					res.mat[i][j] = (res.mat[i][j] + mat[i][k] * oth.mat[k][j] % mod) % mod;
		return res;
	}
};
Matrix mp(Matrix a, long long b) {
	Matrix res(1);
	while (b) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
int n, m, c_lr, c_ud, c_b, c_n_lr, c_n_ud, c_n;
char s[1005][1005];
long long K;
int main() {
	scanf("%d%d%lld", &n, &m, &K);
	if (!K) {puts("1"); return 0;}
	for (int i = 1; i <= n; i++) {
		scanf(" %s", s[i] + 1);
		for (int j = 1; j <= m; j++)
			if (s[i][j] == '#')
				c_b++;
	}
	for (int i = 1; i <= n; i++) {
		if (s[i][1] == '#' && s[i][m] == '#') c_lr++;
		for (int j = 1; j < m; j++)
			if (s[i][j] == '#' && s[i][j + 1] == '#') c_n_lr++;
	}
	for (int j = 1; j <= m; j++) {
		if (s[1][j] == '#' && s[n][j] == '#') c_ud++;
		for (int i = 1; i < n; i++)
			if (s[i][j] == '#' && s[i + 1][j] == '#') c_n_ud++;
	}
	if (c_lr && c_ud) {puts("1"); return 0;}
	if (!c_lr && !c_ud) {printf("%lld\n", qp(c_b, K - 1)); return 0;}
	if (c_ud) {c_lr = c_ud; c_n = c_n_ud;}
	else {c_n = c_n_lr;}
	Matrix matrix;
	matrix.mat[0][0] = c_lr; matrix.mat[0][1] = c_n;
	matrix.mat[1][0] = 0; matrix.mat[1][1] = c_b;
	matrix = mp(matrix, K - 1);
	printf("%lld\n", (matrix.mat[1][1] - matrix.mat[0][1] + mod) % mod);
	return 0;
}

Measured memory_bytes: 1280
def selectionSort(a, n):
    cnt = 0
    for i in range(n-1):
        minj = i
        for j in range(i, n):
            if a[j] < a[minj]:
                minj = j
        a[i], a[minj] = a[minj], a[i]
        if i != minj:
            cnt += 1

    print(' '.join(map(str, a)))
    print(cnt)

n = int(input())
a = list(map(int, input().split()))

selectionSort(a, n)


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(2*M);
  for (int i = 0; i < 2*M; i++)
    cin >> vec.at(i);

  for (int i = 1;i <= N; i++) {
    int C = 0;
    for (int k = 0;k < 2*M; k++) {
      if (vec.at(k) == i) 
        C++;
    }
    cout << C << endl;
  }
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    stack<string> st;
    int depth = 0;

    REP(i, n) {
      string s; cin >> s;
      int cnt = 0;
      string num = "";
      REP(j, SZ(s)) {
        if(s[j] == '.') {
          cnt++;
        } else {
          num = s[j];
        }
      }

      if(depth < cnt) {
        st.push(num);
        depth++;
      } else if(depth == cnt) {
        st.push(num);
      } else {
        while(depth > cnt) {
          vector<string> tmp;
          string op = "";
          while(!st.empty()) {
            string now = st.top(); st.pop();
            if(now == "+" || now == "*") {
              op = now;
              break;
            } else {
              tmp.pb(now);
            }
          }
          int ans = stoi(tmp[0]);
          FOR(k, 1, SZ(tmp)) {
            if(op == "+") {
              ans += stoi(tmp[k]);
            } else if("*") {
              ans *= stoi(tmp[k]);
            } else {
              break;
            }
          }
          st.push(to_string(ans));
          depth--;
        }
        st.push(num);
      }
    }
    string op = "";
    vector<string> tmp;
    string ans = "";
    while(!st.empty()) {
      string now = st.top(); st.pop();
      // cout << now << endl;
      if(now == "+" || now == "*") {
        op = now;
        int ans = stoi(tmp[0]);
        FOR(k, 1, SZ(tmp)) {
          if(op == "+") {
            ans += stoi(tmp[k]);
          } else if("*") {
            ans *= stoi(tmp[k]);
          } else {
            break;
          }
        }
        // cout << "push " << ans << endl;
        st.push(to_string(ans));
        tmp.clear();
      } else {
        if(st.empty()) {
          ans = now;
          break;
        }
        tmp.pb(now);
      }
    }



    cout << ans << endl;
  }
}



Measured memory_bytes: 3244
fun main(args: Array<String>) {
    val mod = 1000000007L
    val l = readLine()!!.toCharArray()
    val dp = Array(l.size) { LongArray(2) { 0L } }
    dp[0][0] = 1L
    dp[0][1] = 2L

    for (i in 1 until l.size) {
        dp[i][0] = (dp[i - 1][0] * 3) % mod
        if (l[i] == '1') {
            dp[i][0] = (dp[i][0] + dp[i - 1][1]) % mod
            dp[i][1] = (dp[i - 1][1] * 2) % mod
        } else {
            dp[i][1] = (dp[i - 1][1]) % mod
        }
    }
    println((dp[l.size-1][0]+dp[l.size-1][1])%mod)
}

Measured memory_bytes: 43376
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

int q,a,b,c,d,n;

void solve()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);n=a+b;
	int ans=(max(a,b)+min(a,b))/(min(a,b)+1),nl;
	
	int l=0,r=a+1,mid;
	while(l<r-1)
	{
		mid=(l+r)>>1;
		int nb=max(0,(mid-1)/ans);
		if(b-nb<=(LL)(a-mid+1)*ans)l=mid;
		else r=mid;
	}
	nl=l+max(0,(l-1)/ans);
	
	for(int i=c;i<=d;i++)
	{
		if(i<=nl)
		{
			if(i%(ans+1)==0)putchar('B');
			else putchar('A');
		}
		else
		{
			if((n-i+1)%(ans+1)==0)putchar('A');
			else putchar('B');
		}
	}
	puts("");
}

int main()
{
	scanf("%d",&q);
	while(q--)solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    ll N;
    cin>>N;
    ll h, n, w;
    rep1(i,3501)rep1(j,3501){
        h = ll(i);
        n = ll(j);
        ll ue = 4*h*n-N*n-h*N;
        ll shita = N*h*n;
        if(ue<=0)continue;
        //cerr<<ue<<"/"<<shita<<endl;
        //cerr<<shita%ue<<endl;
        if(shita%ue == 0){
            w =  shita/ue;
            cout<<h<<" "<<n<<" "<<w<<endl;
            return 0;
        }
    }
}

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

using namespace std;

int main()
{
   string s,t;
   cin>>s>>t;
   string x;
   for(int i=0;i<t.length()-1;i++)
    x+=t[i];
   if(s==x) cout<<"Yes";
   else cout<<"No";
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define pi 3.141592653589793238

ll find(vector<ll> &v, ll a, ll b, ll c){
    if(b < a+c) return 1;
    else return 0;
}

void solve(){
    ll n; cin >> n;
    ll m[n+1] = {0};
    for(ll i = 1;i < n;i++){
        ll x; cin >> x;
        m[x]++;
    }
    for(ll i = 1;i <= n;i++) cout << m[i] << endl;
}


int main() {
    //int t; cin >> t; while(t--)
    solve();
    
	return 0;
}


Measured memory_bytes: 5152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		char c[][]= new char[H][W];
		for (int i=0;i<H;i++) {
			String s= sc.next();
			for (int j=0;j<W;j++) {
				c[i][j] = s.charAt(j);
			}
		}
		int h[] = new int[H];
		int w[] = new int[W];
		int sum =0;
		for (int i=0;i<H;i++) {
			int count =0;
			for (int j=0;j<W;j++) {
				if (c[i][j]=='#') {
					count ++;
				}
			}
			h[i]=count;
			sum +=h[i];
		}
		for (int i=0;i<W;i++) {
			int count =0;
			for (int j=0;j<H;j++) {
				if (c[j][i]=='#') {
					count ++;
				}
			}
			w[i]=count;
		}
		int result =0;
		for (int i=0;i<Math.pow(2, H);i++) {
			for (int j=0;j<Math.pow(2, W);j++) {
				int count = Main.count(h, i)+Main.count(w, j);
				count -=Main.c(c, i, j);
				if (sum-count ==K) {
					result++;
				}
			}
		}
		System.out.println(result);
	}

	public static int c(char H[][],int h,int w) {
		int count =0;
		int i=0;
		int j=0;
		while (h>0) {
			int temp =w;
			if (h%2==1) {
				j=0;
				while (temp>0) {
					if (temp%2==1&&H[i][j]=='#') {
						count++;
					}
					j++;
					temp/=2;
				}
			}
			h/=2;
			i++;
		}
		return count;
	}
	public static int count(int h[],int c) {
		int result =0;
		int i=0;
		while (c>0) {
			if (c%2==1) {
				result+=h[i];
			}
			c/=2;
			i++;
		}
		return result;
	}
}

Measured memory_bytes: 35780
#include<stdio.h>

int main(void){

  int length = 0;

  int height = 0;

  int area = 0;

  int cir = 0;

  scanf("%d %d",&length,&height);

  area = length * height;

  cir = length*2 + height*2;

  printf("%d %d\n",area,cir);

  return 0;

}
 

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

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

    string s; cin>>s;

    vector<int> ans(q,0);

    vector<int> moji(n+1,0);

    for(int i=0; i<n-1; i++ ){
        
        if(s[i] == 'A' && s[i+1] == 'C' ) moji[i+1] = moji[i] + 1;

        else moji[i+1] = moji[i];
     }

    for(int i=0; i<q; i++){
        
        int l,r; cin>>l>>r;

        ans[i] = (moji[r-1] - moji[l-1]);
    } 

    for(int i=0; i<q; i++) cout<<ans[i]<<endl;
    
    return 0;

}

Measured memory_bytes: 1792
#include <stdio.h>
#define W 0
#define G 1
#define B 2
#define inf 1000000000

int prim();
int n, M[100][100];

int main(){
  int e;
  int i, j;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d",&e);
      M[i][j] = (e == -1) ? inf : e;
    }
  }
  printf("%d\n",prim());
  return 0;
}

int prim(){
  int u, minv, sum;
  int d[100], p[100], c[100];
  int i, v;

  for(i=0; i<n; i++){
    d[i] = inf;
    p[i] = -1;
    c[i] = W;
  }
  d[0] = 0;

  while(1){
    minv = inf;
    u = -1;
    for(i=0; i<n; i++){
      if(d[i] < minv && c[i] != B){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1)break;
    c[u] = B;
    for(v=0; v<n; v++){
      if(c[v] != B && M[u][v] != inf){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  c[v] = G;
	}
      }
    }
  }
  sum = 0;
  for(i=0; i<n; i++){
    if(p[i] != -1)sum += M[i][p[i]];
  }
  return sum;
}




Measured memory_bytes: 2104
S=chomp(readline())
T=chomp(readline())
R=zeros(Int,26)
RR=zeros(Int,26)
for i=1:length(S)
	s=Int(S[i])-96
	t=Int(T[i])-96
	if R[s]==0
		R[s]=t
	else
		if R[s]!=t
			println("No")
			exit()
		end
	end
	if RR[t]==0
		RR[t]=s
	else
		if RR[t]!=s
			println("No")
			exit()
		end
	end
end
println("Yes")


Measured memory_bytes: 121352
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

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

	string s;
	cin >> s;
	bool N = false, W = false, S = false, E = false;
	for(char c : s) {
		if(c == 'N') N = true;
		if(c == 'W') W = true;
		if(c == 'S') S = true;
		if(c == 'E') E = true;
	}
	if((E ^ W) || (S ^ N)) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

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

int main(){
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  int ans = 0;
  int differ = 0;
  for(int i = 1; i < N; i++){
    if(S[i] == S[i-1]){
      ans++;
    }else{
      differ++;
    }
  }
  if(K*2 > differ){
    cout << ans+differ << endl;
  }else{
    cout << ans+K*2 << endl;
  }
}


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

int main() {
  int A = 0, B = 0, C = 0, D = 0;

  cin >> A >> B >> C >> D;
  
  int left = A + B;
  int right = C + D;
  
  if( left > right )
	cout << "Left" << endl;
  else if ( left < right )
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N;

	cin>>N;
	vector<long long> A(N,0);
	long long num=0;
	long long P;
	long long minP=1;
	int i;
	for (i=0;i<N;i++){
		cin>>A[i];
	}
	for (i=0;i<N;i++){
		if (i==0){
			num = A[i] -1;
			minP = 2;
		}else{
			if (A[i]<=minP){
				if (A[i]==minP){
					minP++;
				}
				continue;
			}
			P = minP;
			long long x=A[i]/P;
			long long y=A[i]%P;
			if (x==0){
				minP=A[i]+1;
			}else{
				num += x;
				if (y==0){
					 num--;
				}
			}

		}
	}
	cout<<num<<endl;
	return 0;
}


Measured memory_bytes: 1024