akhauriyash/Code-Regression huggingface dataset:
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for i in range(N)]
area = [[0 for i in range(H)] for j in range(W)]
for i in range(N):
    if zahyo[i][2] == 1:
        for j in range(zahyo[i][0]):
            for k in range(H):
                area[j][k] = 1
                
    elif zahyo[i][2] == 2:
        for j in range(zahyo[i][0], W):
            for k in range(H):
                area[j][k] = 1
                
    elif zahyo[i][2] == 3:
        for j in range(W):
            for k in range(zahyo[i][1]):
                area[j][k] = 1
                
    elif zahyo[i][2] == 4:
        for j in range(W):
            for k in range(zahyo[i][1], H):
                area[j][k] = 1

cnt = 0
for l in area:
    for m in range(H):
        if l[m] == 0:
            cnt += 1
print(cnt)

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

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    set<int> st;

    for (int i = 0; i < K; i++)
        if (A + i <= B)
            st.insert(A + i);

    for (int i = K - 1; i >= 0; i--)
        if (B - i >= A)
            st.insert(B - i);

    for (int x : st)
        cout << x << endl;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    int cnt = 0;

    rep(i, 1, s.size())
    {
        if (s[i] != s[i - 1])
            ++cnt;
    }

    cout << cnt << '\n';
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;

int main()
{
    ll n, d;
    cin >> n >> d;
    int count = 0;
    d = d * d;

    REP(i, n)
    {
        ll x, y;
        cin >> x >> y;
        ll dis = x * x + y * y;
        if (dis <= d)
            count++;
    }

    cout << count << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, n, m;
    cin >> a >> n >> m;
    int ans = 0;
    for (int i = 1; i * i <= m; ++i) {
        long long y_a = i + a;
        int time = n;
        while (--time) {
            y_a *= (i + a);
        }
        if (y_a > m) break;
        int sum = 0;
        int alt = y_a;
        while (alt > 0) {
            sum += alt % 10;
            alt /= 10;
        }
        if (sum == i) ++ans;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<ll,ll> P;
//#include <boost/multiprecision/cpp_int.hpp>
//using bint = boost::multiprecision::cpp_int;


int main(){
    string s;
    cin >> s;
    if (s.size()%2 == 1){
        cout << "No"; rn 0;
    }
    for(int i = 0; i< s.size()/2;i++){
        if (s[2*i] != 'h' || s[2*i+1] !='i'){
            cout << "No"; rn 0;
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int ans = -1;
		int[] A = new int[5];
		for(int i=0; i<5; i++) {
			A[i] = sc.nextInt();
			if(A[i] == 0) {
				ans = i+1;
			}
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 35792
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC {
    class Program {
        static void Main (string[] args) {
            var S = Read ();
            var holi = new Dictionary<string, int> () { { "SUN", 7 }, { "MON", 6 }, { "TUE", 5 }, { "WED", 4 }, { "THU", 3 }, { "FRI", 2 }, { "SAT", 1 } };

            Console.WriteLine (holi[S]);
        }

        static string Read () { return Console.ReadLine (); }
        static int ReadInt () { return int.Parse (Read ()); }
        static long ReadLong () { return long.Parse (Read ()); }
        static int[] ReadArrayInt () { return Read ().Split (' ').Select (s => int.Parse (s)).ToArray (); }
        static long[] ReadArrayLong () { return Read ().Split (' ').Select (s => long.Parse (s)).ToArray (); }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

const int N=3e6+100;
vector <int> g[N];
vector <int> in[N];
ll ind[N];

ll dis[N];

ll dp(ll v){
    ll ma=0;
    for (int i=0;i<in[v].size();i++){
        ll u=in[v][i];
        if (dis[u]>1e9){
            dp(u);
        }
        ma=max(ma,dis[u]+1);
    }
    dis[v]=ma;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        ll x;
        cin >> x;
        ll z=i;
        if (x<i){
            swap(x,z);
        }
        ll cnt=z*1000+x;
        for (int j=0;j<n-2;j++){
            ll x;
            cin >> x;
            ll z=i;
            if (x<i)
                swap(x,z);
            g[cnt].pb(z*1000+x);
            in[z*1000+x].pb(cnt);
            ind[z*1000+x]++;
            cnt=z*1000+x;
        }
    }
    memset(dis,69,sizeof dis);
    queue <int> q;
    for (int i=1;i<N;i++){
        if (ind[i]==0){
            q.push(i);
            dis[i]=0;
        }
    }
    while(q.size()){
        ll v=q.front();
        q.pop();
        for (int i=0;i<g[v].size();i++){
            ll u=g[v][i];
            ind[u]--;
            if (ind[u]==0){
                dis[u]=0;
                q.push(u);
            }
        }
    }
    ll ma=0;
    for (int i=1;i<N;i++){
        ma=max(ma,dis[i]);
    }
    if (ma>1e9){
        cout << -1 << endl;
        return 0;
    }
    memset(dis,69,sizeof dis);
    ma=0;

    for (int i=1;i<N;i++){
        if (dis[i]>1e9){
            dp(i);
            ma=max(ma,dis[i]);
        }
    }
    cout << ma+1;

}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>

class UnionFind {
public:
	UnionFind(int n) : parent_(n), size_(n, 1) {
		for (int i = 0; i < n; i++) {
			parent_[i] = i;
		}
	}

	bool isSame(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) {
			return;
		}

		if (size_[x] < size_[y]) {
			parent_[x] = y;
			size_[y] += size_[x];
		}
		else {
			parent_[y] = x;
			size_[x] += size_[y];
		}
	}

	int size(int x) {
		return size_[root(x)];
	}

private:
	int root(int x) {
		if (parent_[x] == x) {
			return x;
		}
		return parent_[x] = root(parent_[x]);
	}

	std::vector<int> parent_;
	std::vector<int> size_;
};

int main() {
	long long n, m;
	std::cin >> n >> m;

	std::vector<long long> a(m), b(m);
	for (int i = 0; i < m; i++) {
		std::cin >> a[i] >> b[i];
	}

	UnionFind uf(n);
	long long c = n * (n - 1) / 2;
	std::vector<long long> ans;

	for (int i = m - 1; i >= 0; i--) {
		ans.push_back(c);
		int ia = a[i] - 1;
		int ib = b[i] - 1;
		if (uf.isSame(ia, ib)) {
			continue;
		}
		c -= uf.size(ia) * uf.size(ib);
		uf.unite(ia, ib);
	}
	reverse(ans.begin(), ans.end());

	for (long long d : ans) {
		std::cout << d << std::endl;
	}

	return 0;

}

Measured memory_bytes: 4596
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
 
using namespace std;
typedef long long ll;

int main()
{
	ll a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	
	if(a+b > c){
		printf("No\n");
	}else{
		if(4 * a * b < (c-a-b) * (c-a-b)){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
n = int(input())
s = []
h = []
c = []
d = []

for i in range(n):
    st,nu = input().split()
    if st == 'S':
        s.append(int(nu))
    elif st == 'H':
        h.append(int(nu))
    elif st == 'C':
        c.append(int(nu))
    else:
        d.append(int(nu))

for i in range(1,14):
    if i not in s:
        print('S',i)
for i in range(1,14):
    if i not in h:
        print('H',i)
for i in range(1,14):
    if i not in c:
        print('C',i)
for i in range(1,14):
    if i not in d:
        print('D',i)





Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
ll a[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n < s.size()){
        for(int i = 0;i < n;i++) cout << s[i];
        cout << "..." << endl;
    }
    else cout << s << endl;
    return 0;
}


Measured memory_bytes: 3640
import math
k = int(input())
s = 0
i = 0
d = [0]*k*k
for a in range(1,k+1):
    for b in range(1,k+1):
        d[i] = math.gcd(a,b)
        i+=1
for c in range(1,k+1):
        s += sum(map(lambda x: math.gcd(x,c),d))
print(s)

Measured memory_bytes: 9256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
 
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
const int INF = 100000000;
const double EPS = 0.0000001;
typedef pair<int,int> P;

int a,d,n;
bool isPrime[1000003];

void init() {
	rep(i,1000003) isPrime[i]=true;
	isPrime[0]=isPrime[1]=false;

	for(int i=2;i<1000003;i++) {
		if(isPrime[i]) {
			for(int j=i+i;j<1000003;j+=i) isPrime[j]=false;
		}
	}


}
void solve() {
	int cnt=0;
	while (true)
	{
		if(isPrime[a]) cnt++;
		if(cnt==n) break;
		a+=d;
	}
	
	cout<<a<<endl;
}

int main() {
	init();
	while (cin>>a>>d>>n)
	{
		if(a+d+n==0) return 0;
		solve();
	}
	return 0;
}

Measured memory_bytes: 2136
/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
#define MOD1 1e18
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
typedef long double ld;
const ll inf=(1LL<<60)-1;
const ll mxn=1e5;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
long long ans,a[100005];
ll mod(ll x)
{
    ll res=x%MOD;
    while(res<0)
        res+=MOD;
    return res;
}
ll bigmod(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)
            res=(res*x)%MOD;
        x=(x*x)%MOD;
        n>>=1;
    }
    return res;
}
/*
sort(v.begin(),v.end(),[&](const pair<ll,ll>&a,const pair<ll,ll>&b)
   {
       if(a.first==b.first)
           return a.second<b.second;
       else
           return a.first>b.first;
   });
   */
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll n,k,nd=-MOD1,pos=0,c=0;
    cin>>n>>k;
    vector<string> S(n);
    for(int i=0; i<n; i++)
    {
        cin>>S.at(i);

    }
    sort(S.begin(), S.end());

    for(auto i:S)
    {
        cout <<i;
    }

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


Measured memory_bytes: 3628
#include<stdio.h>
typedef long long LL;
LL IN(void)
{
  LL x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  LL N=IN();static int i=0,str[11]={},sz=0;
  while(N){N--;str[sz++]=97+N%26;N/=26;}
  while(i<sz){printf("%c",str[sz-i++-1]);}
}

Measured memory_bytes: 1472
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	cat L;
	int N;
	cin >> L >> N;
	vector<cat> A(N+1, 0);
	for(int i = 0; i < N; i++) cin >> A[i+1];
	cat ans = 0;
	for(int k = 0; k < 2; k++) {
		for(int i = 1; i <= N; i++) A[i] = (L-A[i]) % L;
		reverse(begin(A)+1, end(A));
		vector<cat> sum_back(N+1, 0);
		sum_back[1] = L-A[N];
		for(int i = 2; i <= N; i++)
			sum_back[i] = sum_back[i-2] + 2 * (L - A[N+1-i/2]) + (i&1) * (A[N-i/2+1] - A[N-i/2]);
		vector<cat> pref_sum(N+2, 0);
		for(int i = 0; i <= N; i++) pref_sum[i+1] = pref_sum[i] + A[i];
		vector<cat> sum_front(N+1, 0);
		for(int i = 1; i <= N; i++) if(2*i >= 1+N)
			sum_front[1+2*N-2*i] = A[i] + 2 * (pref_sum[i] - pref_sum[2*i-N]);
		for(int i = 1; i <= N; i++) if(2*i >= N)
			sum_front[2*N-2*i] = 2 * (pref_sum[i+1] - pref_sum[2*i-N+1]);
		for(int i = 1; i <= N; i++) ans = max(ans, sum_front[i] + sum_back[i-1]);
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 6572
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N=200005;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<ll>v(n+1,0);
    vector<ll>pref(n+1,0);
    vector<ll>F(n+1,0);
    for(int i=0;i<n;i++){
        cin>>v[i+1];
    }
    for(int i=1;i<=n;i++){
        pref[i]=pref[i-1]+v[i];
        F[i]=(pref[i]-i)%k;
    }
    map<ll,ll>m;
    ll res=0;
    for(int i=0;i<=n;i++){
        if(i>=k){
            m[F[i-k]]--;
        }
        if(m[F[i]]>=1){
            res+=m[F[i]];m[F[i]]++;
        }
        else{
            m[F[i]]=1;
        }
    }
    cout<<res<<endl;
    return 0;
    }


Measured memory_bytes: 17408
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {

    input! {
        n: usize, k: usize,
    }
    let mut sunukes = vec![false; n];

    for i in 0..k {
        input! {
            d: usize,
            a: [Usize1; d],
        }
        for sunuke in a {
            sunukes[sunuke] = true;
        }
    }

    let ans = sunukes.into_iter().filter(|&sunuke| !sunuke).count();
    println!("{}", ans);

}


Measured memory_bytes: 2192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    sort(a.begin(), a.end());
    ll INF = 1001001001;
    ll l = -INF * INF;
    ll r = INF * INF;
    while(l + 1 < r){
        ll x = (l + r) / 2;
        ll cnt = 0;
        rep(i, n){
            if(a[i] < 0){
                int nl = -1;
                int nr = i;
                while(nl + 1 < nr){
                    int nx = (nl + nr) / 2;
                    if(a[i] * a[nx] > x)nl = nx;
                    else nr = nx;
                }
                cnt += i - nr;
            }else{
                int nl = -1;
                int nr = i;
                while(nl + 1 < nr){
                    int nx = (nl + nr) / 2;
                    if(a[i] * a[nx] > x)nr = nx;
                    else nl = nx;
                }
                cnt += nl + 1;
            }
        }
        if(cnt < k)l = x;
        else r = x;
    }
    cout << r << endl;
}

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

int main() {
	
	int h, w;
	cin >> h >> w;
	for (int i=0; i<h; i++) {
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
	
	
	
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
	class Program
	{
		public class Bot : IComparable
		{
			public long pos = 0;
			public long min = 0;
			public long max = 0;
			public Bot(long x, long l)
			{
				pos = x;
				min = x - l;
				max = x + l;
			}

			public int CompareTo(object obj)
			{
				if (obj == null)
				{
					return 1;
				}
				var o = obj as Bot;
				if (o == null)
				{
					return 1;
				}
				return (int)(pos - o.pos);
			}
		}

		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var bots = new List<Bot>(n);

			for (int i = 0; i < n; i++)
			{
				var xl = Console.ReadLine().Split();
				bots.Add(new Bot(long.Parse(xl[0]), long.Parse(xl[1])));
			}

			// 座標の小さい順に並べる (a, b, ...)
			// b.min < a.max なら取り除く必要がある
			// その場合、b.max と a.max を比較して大きい方を取り除く
			bots.Sort();

			int num = n;
			long tmpMax = bots[0].max;
			for (int i = 1; i < n; i++)
			{
				if (bots[i].min < tmpMax)
				{
					tmpMax = Math.Min(tmpMax, bots[i].max);
					num--;
				}
				else
				{
					tmpMax = bots[i].max;
				}
			}
			Console.WriteLine(num);
		}
	}

}


Measured memory_bytes: 19780
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int a;
string s;
int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> a >> s;
	if (a < 3200) cout << "red\n";
	else cout << s << endl;

	return 0;
}


Measured memory_bytes: 384
A = []
for _ in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
B = [int(input()) for _ in range(N)]
bingo = [[False for _ in range(3)] for _ in range(3)]
for b in B:
    for h in range(3):
        for w in range(3):
            if A[h][w] == b:
                bingo[h][w] = True

for w in range(3):
    flag = True
    for h in range(3):
        if not bingo[h][w]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

for h in range(3):
    flag = True
    for w in range(3):
        if not bingo[h][w]:
            flag = False
            break
    if flag:
        print("Yes")
        exit()

flag = True
for i in range(3):
    if not bingo[i][i]:
        flag = False
        break

if flag:
    print("Yes")
    exit()

flag = True
for i in range(3):
    if not bingo[i][2-i]:
        flag = False
        break
if flag:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
A, B = list(map(int, input().split()))

import math
def prime(x):
  p = {}
  cnt = 2
  Flag = True
  L = []
  while Flag:
    last = math.ceil(x ** 0.5) 
    if cnt > last:
      break
    for i in range(cnt, last + 1):
      if x % i == 0:
        x //= i
        p[i] = 1
        cnt = i + 2
        L.append(i)
        while x % i == 0:
          x //= i
          p[i] += 1
        cnt = i + 1
        break
      if i == last:
        Flag = False
  if x != 1:
    p[x] = 1
    L.append(x)
  return L


a = prime(A)
b = prime(B)

ans = 1

for i in a:
  if i in b:
    ans += 1

print(ans)

Measured memory_bytes: 40172
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    map<int,int>mp1;
    rep(i,n) {
        if(i==0) {
            string s;
            cin >> s;
            rep(j,s.size()) {
                mp1[s[j]-'0']++;
            }
            continue;
        }
        string s;
        cin >> s;
        map<int,int>mp2;
        rep(j,s.size()) {
            mp2[s[j]-'0']++;
        }
        for(int j = 49;j<=74;j++) {
            if(mp1[j]>0) {
                if(mp1[j]>=mp2[j]) {
                    mp1[j] = mp2[j];
                }
            }
        }
    }
    vector<int>use;
    for(int i = 49;i<=74;i++) {
        int num = mp1[i];
        rep(j,num) use.push_back(i);
    }
    sort(use.begin(),use.end());
    string ans = "";
    rep(i,use.size()) {
        ans += use[i]+'0';
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
N = int(input())
para = [int(i) for i in input().split()]
odd = 0
even = 0
for i in range(N):
    if para[i] % 2 == 0 :
        even += 1
    else : odd += 1

even += (odd//2)
odd = (odd % 2)
while even > 1:
    p = (even//2)
    q = (even % 2)
    even = (p + q)

if (odd + even) == 1 :
    print("YES")
else :
    print("NO")

Measured memory_bytes: 14108
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日  1/14 22:02:31 2018
 * Ended  Time*  : 四  1/18 13:11:34 2018
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
#include <bitset>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

const int MaxN = 2000;
int n;

int main()
{
	while(~scanf("%d", &n)){
		bitset<MaxN * MaxN> dp;
		dp[0] = 1;
		int sum = 0;
		for(int i = 1; i <= n; i++){
			int x;
			scanf("%d", &x);
			sum += x;
			dp |= dp << x;
		}
		for(int i = (sum+1)/2; ; i++){
			if(dp[i]) { printf("%d\n", i); break;}
		}
	}
    return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N, i, j, k;
    vector<vector<int> > A(3, vector<int>(3));
    vector<vector<int> > ans(3, vector<int>(3, 0));

    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            cin >> A[i][j];
        }
    }

    cin >> N;

    vector<int> b(N);

    for(i=0; i<N; i++) {
        cin >> b[i];
        for(k=0; k<3; k++) {
            for(j=0; j<3; j++) {
                if(A[k][j] == b[i]) {
                    ans[k][j]++;
                }
            }
        }
    }

    if(ans[0][0]>0&&ans[0][1]>0&&ans[0][2]>0 || ans[1][0]>0&&ans[1][1]>0&&ans[1][2]>0 || ans[2][0]>0&&ans[2][1]>0&&ans[2][2]>0 || ans[0][0]>0&&ans[1][0]>0&&ans[2][0]>0 || ans[0][1]>0&&ans[1][1]>0&&ans[2][1]>0 || ans[0][2]>0&&ans[1][2]>0&&ans[2][2]>0 || ans[0][0]>0&&ans[1][1]>0&&ans[2][2]>0 || ans[0][2]>0&&ans[1][1]>0&&ans[2][0]>0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let dd = (0..n).map(|_| read::<usize>()).collect::<Vec<_>>();
    let mut ans = 0;
    for i in 0..n {
        for j in i + 1..n {
            ans += dd[i] * dd[j]
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int m = sc.nextInt();
        int d = sc.nextInt();
        if(m <= d){
        	System.out.println(m);
        }else{
        	System.out.println(m - 1);
        }
    }
}

Measured memory_bytes: 35676
//package C;

import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	Scanner sc;

	Main() {
		sc = new Scanner(System.in);
	}

	class si implements Comparable<si> {
		String data;
		int time;

		si(String d, int t) {
			data = d;
			time = t;
		}

		public int compareTo(si tar) {
			return this.time - tar.time;
		}
	}

	public void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			String a = sc.next();
			String b = sc.next();

			TreeSet<Long> used = new TreeSet<Long>();

			PriorityQueue<si> q = new PriorityQueue<si>();

			q.add(new si(a, 0));

			char goal[] = b.toCharArray();

			for (;;) {
				if (q.isEmpty()) {
//					System.err.println("err");			
				}

				si s = q.poll();
				String st = s.data;
				if (used.contains(Long.valueOf(st))) {
					continue;
				}
//				System.out.println(st + " " + s.time);
				used.add(Long.valueOf(st));

				if (st.equals(b)) {
					System.out.println(s.time);
					break;
				}
				int pt = s.time;

				/* +++ */
				int from = 0;
				char temp[] = st.toCharArray();
				while (temp[from] == goal[from]) {
					from++;
				}
				/* +++ */
				/*
				 * for (int from = ind; from < n; from++) { char temp[] =
				 * st.toCharArray();
				 */if (temp[from] == goal[from]) {
					continue;
				}
				int diff = goal[from] - temp[from];
				temp[from] += diff;
				if (temp[from] < '0') {
					temp[from] += 10;
				}
				if (temp[from] > '9') {
					temp[from] -= 10;
				}
				if (!used.contains(Long.valueOf(String.valueOf(temp))))
					q.add(new si(String.valueOf(temp), pt + 1));
				for (int to = from + 1; to < n; to++) {
					temp[to] += diff;
					if (temp[to] < '0') {
						temp[to] += 10;
					}
					if (temp[to] > '9') {
						temp[to] -= 10;
					}
					if (!used.contains(Long.valueOf(String.valueOf(temp))))
						q.add(new si(String.valueOf(temp), pt + 1));
					/* } */
				}
				/*
				 * for (int from = 0; from < n; from++) { char temp[] =
				 * st.toCharArray(); if (temp[from] == goal[from]) { continue; }
				 * int diff = goal[from] - temp[from]; temp[from] += diff; if
				 * (temp[from] < '0') { temp[from] += 10; } if (temp[from] >
				 * '9') { temp[from] -= 10; } if
				 * (!used.contains(Long.valueOf(String.valueOf(temp))))
				 * q.add(new si(String.valueOf(temp), pt + 1)); for (int to =
				 * from - 1; to >= 0; to--) { temp[to] += diff; if (temp[to] <
				 * '0') { temp[to] += 10; } if (temp[to] > '9') { temp[to] -=
				 * 10; } if (!used.contains(Long.valueOf(String.valueOf(temp))))
				 * q.add(new si(String.valueOf(temp), pt + 1)); } }
				 */
			}

		}
	}

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

}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = 200200;
ll f[N], rf[N];
ll pA[N], pB[N];
int n;
ll A, B, C;

ll getC(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	scanf("%d%lld%lld%lld", &n, &A, &B, &C);
	pA[0] = pB[0] = 1;
	pA[1] = mult(A, rev(A + B));
	pB[1] = mult(B, rev(A + B));
	for (int i = 2; i < N; i++) {
		pA[i] = mult(pA[i - 1], pA[1]);
		pB[i] = mult(pB[i - 1], pB[1]);
	}
	ll ans = 0;
	for (int k = 0; k < n; k++) {
		ll cur = getC(n - 1 + k, k);
		ans = add(ans, mult(mult(cur, n + k), add(mult(pA[n], pB[k]), mult(pB[n], pA[k]))));
	}
	ans = mult(ans, mult(100, rev(A + B)));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 6528
#include <iostream>

int encode(char c, int n){
    switch(c){
        case 'S':
            return 0 + n;
        case 'H':
            return 13 + n;
        case 'C':
            return 26 + n;
        case 'D':
            return 39 + n;
    }
}

void decode(int num){
    if (num <= 13){
        std::cout << "S "<< num  << '\n';
    } else if (num <= 26){
        std::cout << "H "<< num -13 << '\n';
    } else if (num <= 39){
        std::cout << "C "<< num -26 << '\n';
    } else if (num <= 52){
        std::cout << "D "<< num -39 << '\n';
    } else {
        return ;
    }
}

int main(){
    int n;
    std::cin >> n;
    int cards[54];
    for (int i = 0; i < 54; i++){
        cards[i] = 0;
    }
    for (int i = 0; i < n; i++){
        char c; int num;
        std::cin >> c >> num;
        cards[encode(c, num)] = 1;
    }
    for (int i = 1; i < 54; i++){
        if(cards[i] != 1){
            decode(i);
        }
    }

    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	bool flag = true;
	int count = 0;
	for(int j = 0; flag; ++j){
		flag = 0;
		for (int i = N - 1; i > j; --i) {
			if (A[i] < A[i - 1]) {
				swap(A[i], A[i - 1]);
				++count;
				flag = 1;
			}
		}
	}

	for (int i = 0; i < N - 1; ++i) {
		cout << A[i] << " ";
	}
	cout << A[N - 1] << endl;
	cout << count << endl;
	return 0;
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    
    static void solve(InputReader in, PrintWriter out){
        char[]  s = in.ns().toCharArray();
        int min = inf;
        for (int i = 0; i < 26; i++) {
            int max = 0, cur = 0;
            for (int j = 0; j < s.length; j++) {
                if(s[j]!='a'+i) cur++;
                else{
                    max = Math.max(max, cur);
                    cur = 0;
                }
            }
            max = Math.max(max, cur);
            min = Math.min(min, max);
        }
        out.println(min);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define INF 1e9+123
#define VEC(type,A,N) vector<type> A(N+10)
#define VEC2(type,A,N,M) vector<vector<type>> A(N+10,vector<type>(M+10))
#define ALL(v) v.begin()+1, v.end()-9

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> su(N+10,0);
    REP(i,K){
        int d;
        cin>>d;
        REP(j,d){
            int A;
            cin>>A;
            su[A]++;
        }
    }
    int cnt=0;
    REP(i,N){
        if(su[i]==0)cnt++;
    }
    cout<<cnt;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    return 0;
}


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

using ll = long long;

const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B;
    cin >> A >> B;
    cout << 6 - A - B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
            using namespace std;
             
         int main() {
              int N, A ;
              cin >> N >> A; 
           int B; 
           B= N % 500; 
           if ( B > A ){ cout << "No" << endl; } 
           else{ cout << "Yes" << endl; } 
         }

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

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

    vector<pair<int, int>> D(N);
    for(int i = 0; i < N; i++) cin >> D.at(i).first >> D.at(i).second;

    bool check = false;
    for(int i = 0; i <= N-3; i++){
        if(D.at(i).first == D.at(i).second && D.at(i+1).first == D.at(i+1).second && D.at(i+2).first == D.at(i+2).second)
        check = true;
    }

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


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 500005
using namespace std;
inline int read()
{
	char x = getchar();
	int lin = 0, f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
    while(x >= '0' && x <= '9')
	{
		lin = lin * 10 + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
int a[maxn],n,m,id,b[maxn];
int main(){
	n = read(); m = read();
	for(int i = 1; i <= m; i++)
	{
		a[i] = read();
		if(a[i] & 1) ++id;
	}
	if(m == 1)
	{
		printf("%d\n",a[1]);
		if(a[1] == 1) printf("1\n1");
		else printf("2 \n%d %d",a[1] - 1,1);
		return 0;
	}
	if(id > 2)
	{
		printf("Impossible");
		return 0;
	}
	for(int i = 1; i <= m; i++)
		if(a[i] & 1)
		{
			swap(a[i],a[1]);
			break;
		}
	for(int i = m; i > 1; i--)
		if(a[i] & 1)
		{
			swap(a[i],a[m]);
			break;
		}
	for(int i = 1; i <= m; i++)
		printf("%d ",a[i]);
	puts("");
	for(int i = 1; i <= m; i++)
		b[i] = a[i];
	++b[1],--b[m];
	if(!b[m]) --m;
	printf("%d\n",m);
	for(int i = 1; i <= m; i++)
		printf("%d ",b[i]);
}

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

int main() {
    string s;
    cin >> s;
    bool a = 0;
   
    int n = s.size();
    int u = n/2;
    rep(i, (n - 1) / 2) {
        if(s[i] != s[n - 1 - i]) {
            goto OUT;
        }
    }

    
    rep(j, u) {
        if(s[j] != s[u-j-1] || s[j + (n + 1) / 2] != s[u-1 -j+ (n + 1) / 2]) {
            goto OB;
        }
    }
    a = 1;

OUT: 
OB:
    if(a) cout<< "Yes"<< endl;
    else cout << "No" << endl;
    
}



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

string S="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  char a;
  cin>>a;
  rep(i,26){
    if(a==S[i]){
      cout<<"A"<<endl;
      return 0;
    }
  }
  cout<<"a"<<endl;
}

Measured memory_bytes: 3616
n = int(input())
a = list(map(int, input().split()))

if(max(a) - min(a) > 1):
    print('No')
    exit()
elif(max(a) - min(a) == 0):
    var = max(a)
    if((var==n-1)|(var <= n//2)):
        print('Yes')
    else:
        print('No')
    exit()

max_n = a.count(max(a))
min_n = a.count(min(a))

max_var = min_n + max_n//2
min_var = min_n + 1

if((min(a) >= min_var - 1) & (max(a) <= max_var)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 52676
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
private:
	int num[6];

	void roll(FACE a, FACE b, FACE c, FACE d) {
		swap(num[a], num[b]);
		swap(num[b], num[c]);
		swap(num[c], num[d]);
	}

public:
	dice() {
		num[TOP] = 1;
		num[BOTTOM] = 6;
		num[FRONT] = 2;
		num[BACK] = 5;
		num[RIGHT] = 3;
		num[LEFT] = 4;
	}

	void set(int top, int front) {
        if(num[RIGHT] == top || num[LEFT] == top) west();
        while(num[TOP] != top) north();
        while(num[FRONT] != front) ccw();
	}

	const int &operator[](FACE f) const { return num[f]; }

	void north() { roll(TOP, BACK, BOTTOM, FRONT); }
	void east()  { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void west()  { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void south() { roll(TOP, FRONT, BOTTOM, BACK); }
	void ccw()   { roll(BACK, RIGHT, FRONT, LEFT); }
	void cw()    { roll(BACK, LEFT, FRONT, RIGHT); }
};


int right_face[7][7];
void init() {
	dice d;
	for(int t = 1; t <= 6; ++t) {
		for(int f = 1; f <= 6; ++f) {
			if(t == f || t + f == 7) continue;
			d.set(t, f);
			right_face[t][f] = d[RIGHT];
		}
	}
}

int top[3][3][3];
int front[3][3][3];

vector<int> ans;

void dfs(int x, int y, int z) {
	if(z == 3) {
		int sum = 0;
		for(int z = 0; z < 3; ++z) {
			for(int y = 0; y < 3; ++y) {
				sum += right_face[top[z][y][2]][front[z][y][2]];
			}
		}
		ans.emplace_back(sum);
	}
	else if(y == 3) {
		dfs(0, 0, z + 1);
	}
	else if(x == 3) {
		dfs(0, y + 1, z);
	}
	else {
		const int p_top = top[z][y][x];
		const int p_front = front[z][y][x];
		for(int t = 1; t <= 6; ++t) {
			if(top[z][y][x] && top[z][y][x] != t) continue;
			if(z && top[z - 1][y][x] != t) continue;

			for(int f = 1; f <= 6; ++f) {
				if(t == f || t + f == 7) continue;
				if(front[z][y][x] && front[z][y][x] != f) continue;
				if(y && front[z][y - 1][x] != f) continue;
				if(x && right_face[top[z][y][x - 1]][front[z][y][x - 1]] != right_face[t][f]) continue;

				top[z][y][x] = t;
				front[z][y][x] = f;
				dfs(x + 1, y, z);
				top[z][y][x] = p_top;
				front[z][y][x] = p_front;
			}
		}
	}
}

void solve() {
	ans.clear();
	memset(top, 0, sizeof(top));
	memset(front, 0, sizeof(front));

	for(int y = 2; y >= 0; --y) {
		for(int x = 0; x < 3; ++x) {
			cin >> top[0][y][x];
		}
	}

	for(int z = 0; z < 3; ++z) {
		for(int x = 0; x < 3; ++x) {
			cin >> front[z][0][x];
		}
	}

	dfs(0, 0, 0);
	if(ans.size()) {
		sort(ans.begin(), ans.end());
		ans.erase(unique(ans.begin(), ans.end()), ans.end());
		for(unsigned i = 0; i < ans.size(); ++i) {
			cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
		}
	}
	else {
		cout << "0\n";
	}
}

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

	init();

	int n;
	cin >> n;

	while(n--) solve();

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(std::string S){
  int N = S.size();
  string rSubS = S.substr((N + 1) / 2, N / 2);
  reverse(rSubS.begin(), rSubS.end());

  int ans = 0;
  REP(x, N / 2) {
    if (S.at(x) != rSubS.at(x)) ++ans;
  }
  cout << ans << endl;
}

signed main(){
  std::string S;
  std::cin >> S;
  solve(S);
}


Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*; 
import java.lang.*; 
import java.io.*;
import java.math.BigInteger; 
import java.math.*;

 public class Main {
     
	public static void main(String[] args) {
		
		InputStream inputStream = System.in;

		InputReader sc = new InputReader(inputStream);

				
		// int t=sc.nextInt();
		 long c=1000000007;
	
	    int n=sc.nextInt();
	    int a[] = new int[n];
	    for(int i=0;i<n;i++){
	      a[i]=sc.nextInt();
	    }
	    int dp[]= new int[n];
	    dp[0]=0;
	     dp[1]=Math.abs(a[1]-a[0]);
	    for(int i=2;i<n;i++){
	      dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
	    }
	    System.out.println(dp[n-1]);
	}
	

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
				    tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
				    throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public float nextFloat() {
			return Float.parseFloat(next());
		}
		
		
	}
}

Measured memory_bytes: 32112