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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string S;
  cin >> S;
  bool ok = true;
  for(int i = 0; i < S.length(); i = i + 2){
    if(S[i] == 'L'){
      ok = false;
    }
  }

  for(int i = 1; i < S.length(); i = i + 2){
    if(S[i] == 'R'){
      ok = false;
    }
  }

  if(ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int C[3][3];
signed main() {
    rep(i,0,3) rep(j,0,3) cin >> C[i][j];
    repq(a1,0,100) repq(b1,0,100) {
        if(a1 + b1 != C[0][0]) continue;
        vector<int> A(3, a1), B(3, b1);
        for(int i=1; i<3; i++) {
            A[i] = C[i][0] - b1;
            B[i] = C[0][i] - a1;
        }

        bool ok = true;
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if(C[i][j] != A[i] + B[j]) ok = false;
            }
        }
        if(ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll n, a, b;
	cin >> n >> a >> b;
	
	if( a > b || (a != b && n == 1) ) {
		cout << 0 << endl;
	} else {
		cout << (b - a) * (n - 2LL) + 1LL << endl;
	}
	
	return 0;
}


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

using namespace std;

int main()
{
	string s;
	long long k;
	cin >> s >> k;
	for (int i = 0; i < k; i++)
		if (s[i] != '1')
		{
			cout << s[i] << endl;
			return 0;
		}
	cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 5000000;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
 */
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k;
ll ans;
ll x[500005], y[500005], z[500005];
bool dp[3][20][20][20];
char s[400004];

int main(){
    cin >> n;
    cin >> s;
    dp[1][10][10][10] = true;
    for(int i=0;i<n;i++){
        ll num = s[i] - '0';
        for(int s1=0;s1<=10;s1++){
            for(int s2=0;s2<=10;s2++){
                for(int s3=0;s3<=10;s3++){
                    dp[i%2][s1][s2][s3] |= dp[(i+1)%2][s1][s2][s3];
                }
            }
        }
        for(int s1=0;s1<=10;s1++){
            for(int s2=0;s2<=10;s2++){
                for(int s3=0;s3<=10;s3++){
                    dp[i%2][s2][s3][num] |= dp[(i+1)%2][s1][s2][s3];
                }
            }
        }
    }
    for(int s1=0;s1<10;s1++){
        for(int s2=0;s2<10;s2++){
            for(int s3=0;s3<10;s3++){
                if(dp[(n+1)%2][s1][s2][s3]){
                    ans++;
                    //pe(s1);pe(s2);p(s3);
                }
            }
        }
    }
    p(ans);
    return 0;
    
}


















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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;

    vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1, 0)), trace(s.length() + 1, vector<int>(t.length() + 1, 0));
    for (int i = 1; i <= s.length(); i++){
        for (int j = 1; j <= t.length(); j++){
            if (s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
                trace[i][j] = 1;
            }
            else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                if (dp[i - 1][j] > dp[i][j - 1])
                    trace[i][j] = -1;
                else
                    trace[i][j] = -2;
            }
        }
    }
    
    int i = s.length(), j = t.length();
    string ans;
    while (1){
        if (i == 0 || j == 0)
            break;

        if (trace[i][j] == 1){
            ans += s[i - 1];
            i -= 1;
            j -= 1;
        }
        else if (trace[i][j] == -1)
            i -= 1;
        else
            j -= 1;
    }
    
    reverse(ans.begin(), ans.end());

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 73608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long lint;
const int N=1e5+5;
int n,m,q;
lint seq[N],ans[N],buk[N];

template <class T> inline T nxi(){
	T x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

int main(){
	n=nxi<int>(),q=nxi<int>();
	seq[++m]=n;
	for(int i=1; i<=q; ++i){
		lint x=nxi<lint>();
		while(m&&seq[m]>x) --m;
		seq[++m]=x;
	}
	buk[m]=1;
	for(int i=m; i; --i){
		if(!buk[i]) continue;
		lint tmp=seq[i];
		for(int j=i; tmp>seq[1]; ){
			j=std::lower_bound(seq+1,seq+j,tmp)-seq-1;
			lint f=tmp/seq[j];
			tmp-=f*seq[j];
			buk[j]+=buk[i]*f;
		}
		ans[tmp]+=buk[i];
	}
	for(int i=seq[1]; i; --i){
		ans[i-1]+=ans[i];
	}
	for(int i=1; i<=n; ++i){
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main() {
    size_t n, m;
    cin >> n >> m;
    priority_queue<size_t> a;
    for (size_t i = 0; i < n; ++i) {
        size_t x;
        cin >> x;
        a.push(x);
    }
    for (size_t i = 0; i < m; ++i) {
        auto x = a.top();
        x /= 2;
        a.pop();
        a.push(x);
    }
    size_t c = 0;
    while (!a.empty()) {
        c += a.top();
        a.pop();
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(container) container.begin(), container.end()
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;

int main() {
  int n, count;
  string a, b, c;
  cin >> n >> a >> b >> c;

  count = 0;
  rep(i, 0, n) {
    if ((a[i] == b[i] && b[i] != c[i]) || (b[i] == c[i] && c[i] != a[i]) || (c[i] == a[i] && a[i] != b[i])) {
      count++;
    } else if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
      count += 2;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n;
    double m, a2;
    while ((n = sc.nextInt()) != 0) {
      m = 0;
      a2 = 0;
      int s[] = new int[n];
      for (int i = 0; i < n; i++) {
        s[i] = sc.nextInt();
        m += s[i];
      }
      m /= n;
      for (int i = 0; i < n; i++) {
        a2 += (s[i] - m) * (s[i] - m);
      }
      a2 /= n;
      System.out.printf("%f\n", Math.sqrt(a2));
    }
  }
}



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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

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


int main(){
    string s;
    cin >> s;
    ll n = s.size();

    ll dp[n+1][4] = {};
    rep(i,0,n+1) rep(j,0,4) dp[i][j] = -LINF;
    dp[0][0] = 0;

    rep(i,1,s.size()+1){
        rep(j,1,4){
            rep(k,0,4){
                if(i - j < 0) continue;
                if(dp[i-j][k] < 0) continue;
                if(s.substr(i-j-k,k) != s.substr(i-j,j)){
                    dp[i][j] = max(dp[i][j],dp[i-j][k]+1);
                }
            }
        }
    }
    ll ans = 0;
    rep(i,0,4){
        ans = max(ans,dp[n][i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10012
memo = [[0] * 60 for i in range(60)]

def comb(n,k):
    if memo[n][k] > 0:
        return memo[n][k]
    elif k == 0 or k == n:
        memo[n][k] = 1
        return memo[n][k]
    else:
        memo[n][k] = comb(n-1,k) + comb(n-1,k-1)
        return memo[n][k]

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

v.sort()
v.reverse()
if len(set(v[:a])) == 1:
    print(v[0])
    cnt = 0
    for i in range(n):
        if v[i] == v[0]:
            cnt += 1
    ans = 0
    for i in range(a,min(b,cnt)+1):
        ans += comb(cnt,i) 
    print(ans)
else:
    total = 0
    for i in range(a):
        total += v[i]
    print("%.10f" % (total/a))
    if a < n and v[a] == v[a-1]:
        l = r = 0
        for i in range(n):
            if v[i] == v[a]:
                if i < a:
                    l += 1
                else:
                    r += 1
        print(comb(l+r,l))
    else:
        print(1)

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

int main()
{
    string a;
    cin>>a;
    if(a[0]==a[1] && a[1]!=a[2] && a[2]==a[3])
    {
        cout<<"Yes\n";
    }
    else if(a[0]==a[2] && a[2]!=a[1] && a[1]==a[3])
    {
        cout<<"Yes\n";
    }
    else if(a[0]==a[3] && a[3]!=a[1] && a[1]==a[2])
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_5.cpp

const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = (b[i][0]*c[0][j] + b[i][1]*c[1][j] + b[i][2]*c[2][j]) % MOD;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	static LL t[60][3][3];
	static bool flag = true;
	
	if(flag) { // いいかげんな高速化
		inc(i, 3) {
		inc(j, 3) {
			t[0][i][j] = b[i][j];
		}
		}
		inc(i, 60 - 1) {
			mat_prod(t[i + 1], t[i], t[i]);
		}
		flag = false;
	}
	
	LL cc = c, d = 0;
	while(cc) { cc >>= 1; d++; }
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, d) {
		if((c >> i) & 1) {
			mat_prod(a, a, t[i]);
		}
	}
}

LL n, m, x[100002];

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod(c, b, c); }
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


Measured memory_bytes: 1024
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function upper_bound(d,a,b,e){for(var c;1<b-a;)d[c=0|(a+b)/2]<=e?a=c:b=c;return d[a]<=e?b:a};

console.log(main());
function main(){
  var s= o.a(1);
  var a = ["A","T","G","C"];
  var ans = 0, t = 0;
  for(var i = 0; i < s.length; i++){
    var f = 0;
    for(var j = 0; j < 4; j++){
      if(s[i] === a[j])f = 1;
    }
    if(f)t++;
    else{
      if(ans < t)ans = t;
      t = 0;
    }
  }
  return Math.max(ans,t);
}

Measured memory_bytes: 21064
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int a,b;
    cin>>a>>b;
    a=(a+11)%13;
    b=(b+11)%13;
    if(a<b) cout<<"Bob\n";
    if(a==b)cout<<"Draw\n";
    if(a>b) cout<<"Alice\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
#define RI register int
int read(){
    int q=0;char ch=' ';
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
    return q;
}
typedef long long LL;
const int N=200005,inf=0x3f3f3f3f;
int h[N],ne[N<<1],to[N<<1],mx[N],se[N],d[N],sz[N];
int n,tot;
LL ans;
char S[N];
inline void add(int x,int y){to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
inline void dfs1(int x,int las){
    if(S[x]=='1')d[x]=0,sz[x]=1;
    else d[x]=inf;
    for(RI i=h[x];i;i=ne[i]){
        if(to[i]==las)continue;
        int y=to[i];dfs1(y,x),sz[x]+=sz[y];
        if(mx[y]+1>mx[x])se[x]=mx[x],mx[x]=mx[y]+1;
        else if(mx[y]+1>se[x])se[x]=mx[y]+1;
        if(sz[y])d[x]=min(d[x],mx[y]+1);
    }
}
inline void dfs2(int x,int las){
    int R=min(se[x]+1,mx[x]-1);
    if(d[x]<=R)ans+=(LL)(R-d[x]+1);
    for(RI i=h[x];i;i=ne[i]){
        if(to[i]==las)continue;
        int y=to[i],kl=(mx[y]+1==mx[x]?se[x]+1:mx[x]+1);
        if(kl>mx[y])se[y]=mx[y],mx[y]=kl;
        else if(kl>se[y])se[y]=kl;
        if(sz[1]-sz[y])d[y]=min(d[y],kl);
        dfs2(y,x);
    }
}
int main(){
    int x,y;
    n=read();
    rep(i,2,n)x=read(),y=read(),add(x,y),add(y,x);
    scanf("%s",S+1);
    dfs1(1,0),dfs2(1,0);
    printf("%lld\n",ans+1);
    return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

string s, t;
map<char, int> mp, mp2;

signed main()
{
    cin >> s >> t;
    int n = s.size();
    for(int i = 0; i < n; i++){
        if(mp[t[i]] == 0){
            mp[t[i]] = i + 1;
        }
        else if(mp[t[i]] > 0){
            if(s[i] != s[mp[t[i]] - 1]){
                printf("No\n");
                return 0;
            }
        }
        if(mp2[s[i]] == 0){
            mp2[s[i]] = i + 1;
        }
        else if(mp2[s[i]] > 0){
            if(t[i] != t[mp2[s[i]] - 1]){
                printf("No\n");
                return 0;
            }
        }

    }
    printf("Yes\n");



    return 0;
}
/*


*/


Measured memory_bytes: 776
import math
def main():
  n=int(input())
  w = list(map(int,input().split()))
  ans=abs(sum(w[:1])-sum(w[1:]))
  for t in range(2,n+1):
    if ans>abs(sum(w[:t])-sum(w[t:])):
      ans=abs(sum(w[:t])-sum(w[t:]))
  print(ans)

main()

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

int n,m; 
char a[520][520];
char b[520][520];
char c[520][520];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(j==1) b[i][j]='.';
			else if(j==m) b[i][j]='#';
			else if(j!=m&&j!=1&&i%2==1) b[i][j]='.';
			else b[i][j]='#';
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(b[i][j]=='.') c[i][j]='#';
			else c[i][j]='.';
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=m;j++)
//		{
//			cout<<b[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='#'){
				b[i][j]='#';
				c[i][j]='#';
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<b[i][j];
		}
		cout<<endl;
	}
	cout<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<c[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int R0, W0, C, R;
  while(cin >> R0 >> W0 >> C >> R, R0) {
    cout << max(0, (C*W0-R0 + R-1)/R) << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
import collections
n = int(input())
a = list(map(int, input().split()))
b = collections.Counter(a)
c = [ 0 for _ in range(n)]
i = 0
for l, cnt in b.items():
    if 1 < cnt < 4:
        c[i] = l
        i += 1
    elif 3 < cnt:
        c[i] = l
        c[i + 1] = l
        i += 2
c.sort(reverse=True)
print(c[0] * c[1])


Measured memory_bytes: 18600
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

bool isPrime[1299709+1];

int main(){

	memset(isPrime,-1,sizeof(isPrime));
	isPrime[0] = false;
	isPrime[1] = false;

	vector<int> prime;
	for(int i=2;i<=1299709;i++){
		if(isPrime[i]){
			prime.push_back(i);
			for(int j=i+i;j<=1299709;j+=i){
				isPrime[j] = false;
			}
		}
	}
	int n;

	while(~scanf("%d",&n)){
		if(n==0) break;
		if(isPrime[n]){
			printf("%d\n",0);
		}

		else{
			vector<int>::iterator it = lower_bound(prime.begin(),prime.end(),n);
			printf("%d\n",*it - *(it-1));
		}
	}
}

Measured memory_bytes: 2856
#include <iostream>
#include <vector>
#include <unordered_map>
#include <set>
#include <queue>
//#include "../cxx-prettyprint/prettyprint.hpp"


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

    std::unordered_map<int, std::vector<int>> Adj(n);

    for (int i = 0; i < n; i ++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> V(k);
        for (int& v : V) {
            std::cin >> v;
        }
        Adj[u] = V;
    }

    std::set<int> nodes_unvisited;
    std::unordered_map<int, int> distances;
    for (int i = 1; i <= n; i ++) {
        nodes_unvisited.insert(i);
        distances[i] = -1;
    }

    nodes_unvisited.erase(1);
    distances[1] = 0;
    std::queue<int> queue;
    queue.push(1);

    while (!queue.empty()) {
        int u = queue.front();
        queue.pop();
        for (int v : Adj[u]) {
            if (nodes_unvisited.find(v) != nodes_unvisited.end()) {
                nodes_unvisited.erase(v);
                distances[v] = distances[u] + 1;
                queue.push(v);
            }
        }
    }

    for (int i = 1; i <= n; i ++) {
        std::cout << i << " " << distances[i] << std::endl;
    }
}



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

int  A[100001];

//親の節点番号を求める
int parent( int i ) {
  return i/2;
}

//左の子の節点番号を求める
int left ( int i ) {
  return 2 * i;
}

//右の子の節点番号を求める
int right ( int i ) {
  return 2 * i + 1;
}

int main() {
  //入力
  int H; cin >> H;
  for ( int i = 1; i <= H; i++ ) cin >> A[i];
  
  //出力
  for ( int i = 1; i <= H; i++ ) {
    
    cout << "node " << i << ": key = " << A[i] << ", ";

    //節点番号が1以上か確認
    if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    
    //節点番号がH以下か確認
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    
    //節点番号がH以下か確認
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000
typedef long long i64;

int n;
char s[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	scanf("%s", s);
	return 1;
}

void init() {
}

int solve() {
	if (n%2) return 0;
	for (int i=0; i<n/2; i++)
		if (s[i] != s[i+n/2]) return 0;
	return 1;
}

void output(int ans) {
	printf("%s\n", ans? "Yes":"No");
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int counter = 0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if((500*i+100*j+50*k)==x){
                    counter++;
                }
            }
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)

    g = [["."] * N for _ in range(N)]

    d = dict()

    d[(3, 1)] = (".zz", "z..", "z..")
    d[(3, 2)] = ("aab", "b.b", "baa")
    d[(4, 3)] = ("aaba", "ccba", "abcc", "abaa")
    d[(5, 3)] = ("aabbc", "bc..c", "bc..b", "a.ccb", "abbaa")

    def fill(si, sj, b):
        nb = len(b)
        for i in range(nb):
            for j in range(nb):
                g[si + i][sj + j] = b[i][j]

    if N <= 2:
        print(-1)
        return
    elif N == 3:
        fill(0, 0, d[(3, 1)])
    elif N & 1 == 0:
        # N >= 4 and N even.
        # N = 2*(3*m + 2*n)
        n, m = 0, 0
        while 6 * m <= N:
            if (N - 6 * m) % 4 == 0:
                n = (N - 6 * m) // 4
                break
            m += 1
        for k in range(m):
            fill(6 * k, 6 * k, d[(3, 1)])
            fill(6 * k + 3, 6 * k + 3, d[(3, 1)])
            fill(6 * k, 6 * k + 3, d[(3, 2)])
            fill(6 * k + 3, 6 * k, d[(3, 2)])
        for k in range(n):
            fill(6 * m + 4 * k, 6 * m + 4 * k, d[(4, 3)])

    elif N == 7:
        _s = "aabbcc."
        for i in range(N):
            g[i][6] = _s[i]
            g[6][i] = _s[i]
        for k in range(2):
            for l in range(2):
                fill(3 * k, 3 * l, d[(3, 1)])

    elif N == 11:
        fill(0, 0, d[(3, 1)])
        fill(3, 3, d[(3, 1)])
        fill(3, 0, d[(3, 2)])
        fill(0, 3, d[(3, 2)])

        fill(6, 6, d[(5, 3)])

    else:
        # N != 7, 11 and even
        # N = 5*m + 4*n
        n, m = 0, 0
        while 5 * m <= N:
            if (N - 5 * m) % 4 == 0:
                n = (N - 5 * m) // 4
                break
            m += 1

        for k in range(m):
            fill(5 * k, 5 * k, d[(5, 3)])
        for k in range(n):
            fill(5 * m + 4 * k, 5 * m + 4 * k, d[(4, 3)])

    print(*["".join(g[i]) for i in range(N)], sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 52720
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
     }else{
    cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


def main():
    S = input()[:-1]
    N = len(S)

    A = [1] * N
    R = [0, 0]
    for i in range(N-1):
        if S[i] == "R" and S[i+1] == "R":
            R[i%2] += 1
            A[i] = 0
        elif S[i] == "R" and S[i+1] == "L":
            A[i] += R[i%2]
            A[i+1] += R[(i+1)%2]
            R = [0, 0]
    L = [0, 0]
    for i in reversed(range(N-1)):
        if S[i] == "L" and S[i+1] == "L":
            L[i%2] += 1
            A[i+1] = 0
        elif S[i] == "R" and S[i+1] == "L":
            A[i] += L[(i+1)%2]
            A[i+1] += L[i%2]
            L = [0, 0]
    
    print(" ".join(map(str, A)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 12736
use std::io::*;
const MOD: u64 = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut dp: Vec<u64> = vec![0; k + 1];
    dp[0] = 1;
    for i in 0..n {
        let mut next = vec![0; k + 1];
        for j in 1..k + 1 {
            dp[j] += dp[j - 1];
        }
        for j in 0..k + 1 {
            if j > a[i] as usize {
                next[j] += dp[j] - dp[j - a[i] as usize - 1];
            } else {
                next[j] += dp[j];
            }
            next[j] %= MOD;
        }
        dp = next;
    }
    println!("{}", dp[k]);
}


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

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vvint(v, w, n) vector<int> v(n); vector<int> w(n); REP(i,n) cin >> v[i] >> w[i];
#define vlint(v, n) vector<ll int> v(n); REP(i,n) cin >> v[i];
#define vdouble(v, n) vector<double> v(n); REP(i,n) cin >> v[i];
#define vvdoube(v, n1, n2) vector<vector<double> > v(n1, vector<double>(n2, 0)); REP(i,n1) REP(j,n1) cin >> v[i][j];
#define string(x) string x; cin >> x;
#define vstring(v, n) vector<string> v(n); REP(i,n){string a; std::cin >> a; v.push_back(a); }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()
#define len(v) (v).length()
#define FIND(s, n) (s.find(n) != s.end())
#define SORT(a) sort(all(a))

static const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long int MOD = 1000000007;
static const double PI=3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[]={0, 0, 1, -1};
static const int dx4[]={1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};


int Knapsack_01(int N,int W,vector<int> v,vector<int> w) {

  int dp[N+1][W+1];
//std::vector<std::vector<int> > dp(N + 1, std::vector<int>(W + 1, 0));
  for (int i = 0; i <= N; i++) dp[i][0] = 0;
  for (int j = 0; j <= W; j++) dp[0][j] = 0;

  REP(i, N) REPS(j, 1, W+1){
      if (j < w[i]) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j], dp[i+1][j - w[i]] + v[i]);
  }
  return dp[N][W];
}

int Knapsack_eco(int N,int W, vector<int> v,vector<int> w) {

    vector<int> dp(W+1, 0);

    REP(i, N) REPS(j, w[i], W+1) dp[j] = max(dp[j], dp[j-w[i]]+v[i]);

    return dp[W];
}

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

  int N, W;
  cin >> N >> W;

  vvint(v, w, N);

  cout << Knapsack_01(N, W, v, w) << endl;

}

Measured memory_bytes: 7100
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  char c;
  cin>>c;
  cout<<char(c+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,T; cin >> n >> T;
    vector<ll> t(n);
    rep(i,n) cin >> t[i];
    ll ans = 0;
    ll st = t[0];
    rep(i,n){
        if(t[i] - st > T){
            ans += T;
            st = t[i];
        }
        else{
            ans += t[i] - st;
            st = t[i];
        }
    }
    ans += T;
    cout << ans << endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x, a, b;
	cin >> x >> a >> b;
	
	int A = abs(a - x);
	int B = abs(b - x);
	
	if (A < B) {
		cout << "A" << endl;
	} else {
		cout << "B" << endl;
	}
}

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

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

int main() {

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

	Int a, b;
	cin >> a >> b;

	cout << (b % a ? b - a : a + b) << "\n";


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main() {
    int n;
    cin>>n;
    n=log2(n);
    n=pow(2,n);
    cout<<n;
}



Measured memory_bytes: 4052
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=307;
const ll mod=998244353;

int n, k;

char wcz[nax];

int m;
int tab[nax];

int dp[nax][nax][2*nax];

inline void dod(int &a, int b)
{
	if ((a+=b)>=mod)
		a-=mod;
}

void sdod(ll &a, ll b)
{
	a=(a+b)%mod;
}

int main()
{
	scanf("%s", wcz+1);
	scanf("%d", &k);
	n=strlen(wcz+1);
	wcz[n+1]='0';
	n++;
	int x=0;
	for (int i=1; i<=n; i++)
	{
		if (wcz[i]=='1')
		{
			x++;
		}
		else
		{
			m++;
			tab[m]=x;
			x=0;
		}
	}
	//~ debug() << range(tab+1, tab+1+m);
	dp[0][0][0]=1;
	int s=0;
	int cs=0;
	for (int i=1; i<=m; i++)
		cs+=tab[i];
	for (int i=1; i<=m; i++)
	{
		s+=tab[i];
		for (int j=s; j<=cs; j++)
		{
			for (int l=0; l<=cs; l++)
			{
				for (int p=0; p<=j; p++)
				{
					if (!dp[i-1][j-p][l])
						continue;
					dod(dp[i][j][l+max(0, tab[i]-p)], dp[i-1][j-p][l]);
				}
			}
		}
	}
	int wyn=0;
	for (int i=0; i<2*nax; i++)
		if (i<=k)
			dod(wyn, dp[m][s][i]);
	printf("%d\n", wyn);
	return 0;
}


Measured memory_bytes: 57212
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) {
  x += v;
  if (x >= MOD) x -= MOD;
}

int N;
string S[2];
int dp[53][3][3];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> S[0] >> S[1];
  if (S[0][0] == S[1][0]) rep(k, 3) dp[1][k][k] = 1;
  else rep(k1, 3) rep(k2, 3) if (k1 != k2) dp[1][k1][k2] = 1;

  for (int i=1; i<N; i++) {
    rep(k1, 3) {
      rep(k2, 3) {
        if (dp[i][k1][k2] == 0) continue;
        int nn1 = -1, nn2 = -1;
        if (S[0][i] == S[0][i-1]) nn1 = k1;
        if (S[1][i] == S[1][i-1]) nn2 = k2;
        rep(n1, 3) {
          rep(n2, 3) {
            if (nn1 != -1 && n1 != nn1) continue;
            if (nn2 != -1 && n2 != nn2) continue;
            if (S[0][i] == S[1][i]) {
              if (n1 != n2) continue;
              if (n1 == k1 || n1 == k2) continue;
            }
            else {
              if (n1 == n2) continue;
              if (nn1 == -1 && n1 == k1) continue;
              if (nn2 == -1 && n2 == k2) continue;
            }
            add(dp[i+1][n1][n2], dp[i][k1][k2]);
          }
        }
      }
    }
  }
  int s = 0;
  rep(a, 3) rep(b, 3) add(s, dp[N][a][b]);
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<s.length(); i++) {
            if (i % n == 0) {
                sb.append(s.charAt(i));
            }
        }
        System.out.println(sb.toString());
    }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(string, s);
  vector<int> ans(s.size());
  int re = 0;
  int ro = 0;
  rep(i, s.size() - 1) {
    if (s[i] == 'R') {
      swap(re, ro);
      ++re;
    }
    if (s[i + 1] == 'L') {
      ans[i] += re;
      ans[i + 1] += ro;
      re = ro = 0;
    }
  }
  int le = 0;
  int lo = 0;
  for (int i = s.size() - 1; i >= 1; --i) {
    if (s[i] == 'L') {
      swap(le, lo);
      ++le;
    }
    if (s[i - 1] == 'R') {
      ans[i] += le;
      ans[i - 1] += lo;
      le = lo = 0;
    }
  }
  rep(i, s.size()) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 3840
toll_list = [[0, 300, 500, 600, 700, 1350, 1650],
             [300, 0, 350, 450, 600, 1150, 1500],
             [500, 350, 0, 250, 400, 1000, 1350],
             [600, 450, 250, 0, 250, 850, 1300],
             [700, 600, 400, 250, 0, 600, 1150],
             [1350, 1150, 1000, 850, 600, 0, 500],
             [1650, 1500, 1350, 1300, 1150, 500, 0]]

over_forty_list = [[1,6], [1,7], [2,7], [3,7], [6,1], [7,1], [7,2], [7,3]]

while dpt = gets.to_i
  break if dpt.zero?

  dh, dm = gets.split.map(&:to_i)
  arv = gets.to_i
  ah, am = gets.split.map(&:to_i)
  toll = toll_list[dpt-1][arv-1]

  dpt_total = 60*dh + dm
  arv_total = 60*ah + am
  limit = (17*60+30..19*60+30)

  toll /= 2 if (limit.include?(dpt_total) || limit.include?(arv_total)) && !over_forty_list.include?([dpt, arv])

  if (toll%50).nonzero?
    surplus = toll % 100
    toll = (toll/100)*100 + (surplus < 50 ? 50 : 100)
  end
  
  puts toll
end

Measured memory_bytes: 6112
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
char a[110];
int main()
{     long long n,i,j,k,sum=1;
      cin>>n;
      for(i=1;i<=n;i++)
         cin>>a[i];
      for(i=1;i<=n;i++)
         cin>>a[i+n];
      for(i=1;i<=n;i++){
      	if(i==1&&a[i]==a[i+n])sum*=3;
      	  else if(i==1&&a[i]==a[i+1])sum*=6,i+=1;
      	  else if(a[i]==a[i+1]&&a[i-1]==a[i-1+n])sum*=2,i+=1;
      	  else if(a[i]==a[i+1])sum*=3,i+=1;
      	  else if(a[i]==a[i+n]&&a[i-1]==a[i-1+n])sum*=2;
      	sum%=1000000007;
      }
      cout<<sum%1000000007<<endl;
	  return 0;
}


Measured memory_bytes: 256
def Find(x, par):
  if par[x] < 0:
    return x
  else:
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)
  
  if x != y:
    if rank[x] < rank[y]:
      par[x] = y
    else:
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1
    
def Same(x, y, par):
  return Find(x, par) == Find(y, par)
 
n, k, l = map(int, input().split())
rpar = [-1]*n
tpar = [-1]*n
rrank = [0]*n
trank = [0]*n
 
for i in range(k):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, rpar, rrank) 

for i_ in range(l):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, tpar, trank)

d = {}
IDs = [0]*n
for j in range(n):
  ID = Find(j, rpar)+(Find(j, tpar)+1)*10**8
  IDs[j] = ID
  if ID in d:
    d[ID] += 1
  else:
    d[ID] = 1

ans = []
for j in range(n):
    ans.append(d[IDs[j]])
print(*ans)

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

int main() {
  int N;
  string S;
  cin>>N>>S;
  int A=0;
  int B=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='E') A++;
    else B++;
  }
  int D=10000000;
  int LE=0;
  int LW=0;
  int RE=A;
  int RW=B;
  if(S.at(0)=='E'){
    RE--;
    D=RE;
  }
  else{
    RW--;
    D=RE;
  }
  for(int i=1;i<N;i++){
    if(S.at(i-1)=='E') LE++;
    else LW++;
    if(S.at(i)=='E'){
      RE--;
      D=min(D,LW+RE);
    }
    else{
      RW--;
      D=min(D,LW+RE);
    }
  }
  cout<<D<<endl;
}

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 1; i <= n; ++i)

int h, w, k;
std::vector<std::vector<int>> s;

int getS(int x, int y, int j)
{
    int res = 0;
    for (int i = x + 1; i <= y; ++i)
        res += s[i][j];
    return res;
}

int getL(int x, int y, int l)
{

    int lb = l, ub = w + 1;

    while (ub - lb > 1)
    {
        int mid = (lb + ub) / 2;

        if (getS(x, y, mid) - getS(x, y, l) <= k)
            lb = mid;
        else
        {
            ub = mid;
        }
    }
    return lb;
}

int main()
{

    std::cin >> h >> w >> k;
    s.resize(h + 1, std::vector<int>(w + 1));
    //std::cerr << "dd" << std::endl;

    rep(i, h)
    {
        rep(j, w)
        {
            char ch;
            std::cin >> ch;
            s[i][j] = (ch == '0') ? 0 : 1;
            s[i][j] += s[i][j - 1];
        }
    }

    //std::cerr << "dd" << std::endl;

    int aa = w - 1 + h - 1;
    for (int i = 0; i < (1 << (h - 1)); ++i)
    {
        //std::cerr << "dd" << std::endl;
        std::vector<int> indexes;
        indexes.push_back(0);
        for (int j = 0; j < h - 1; ++j)
        {
            if (i & (1 << j))
                indexes.push_back(j + 1);
        }
        indexes.push_back(h);

        /*std::cerr << "DEBUG" << std::endl;
        for (int x : indexes)
            std::cerr << x << ' ';
        std::cerr << std::endl;*/

        int l = 0;
        int ans = -1;
        while (l < w)
        {
            ++ans;
            int nl = w;
            for (int j = 1; j < indexes.size(); ++j)
            {
                nl = std::min(nl, getL(indexes[j - 1], indexes[j], l));
            }
            if (nl == l)
            {
                goto xx;
            }
            l = nl;
            //std::cerr << l << std::endl;
        }
        aa = std::min(aa, ans + (int)indexes.size() - 2);
    xx:;
    }

    std::cout << aa << std::endl;

    return 0;
}

Measured memory_bytes: 3696