akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace V1141{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            while(true){
                var a = sr.Next<int>();
                var d = sr.Next<int>();
                var n = sr.Next<int>();
                if(a + d + n == 0) break;

                var x = a;
                var cnt = 0;
                while(true){
                    if(Prime.Is(x)) cnt++;
                    if(cnt == n) break;
                    x += d;
                }

                Console.WriteLine(x);
            }
            //---------------------------------
        }
    }

    public class Prime{
        public static bool Is(int n){
            for(var i = 2; i * i <= n; i++) if(n % i == 0) return false;
            return n > 1;
        }

        public static IEnumerable<int> Sieve(int n){
            var sieve = new bool[n + 1];
            for(var i = 2; i <= n; i++){
                if(!sieve[i]){
                    yield return i;
                    for(var j = i << 1; j <= n; j += i) sieve[j] = true;
                }
            }
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 9772
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;

int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48,ch=getchar();}
	return x*f;
}
const int maxn = 101000;
char s[maxn];
int a[maxn];
int main()
{
	scanf("%s",s);
	int n=strlen(s),ans=0;
	for(int i=0;i<n;i++) a[i]=(int)s[i]-'0';
	for(int i=1;i<n;i++)
		if(a[i]==a[i-1]) a[i]=!a[i],ans++;
	int ans2 = 1;
	for(int i=0;i<n;i++) a[i]=(int)s[i]-'0';
	a[0]=!a[0];
	for(int i=1;i<n;i++)
		if(a[i]==a[i-1]) a[i]=!a[i],ans2++;
	printf("%d\n",min(ans,ans2));
	return 0;
}

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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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


int main(){
  string s; cin >> s;
  int pres = 1;
  char pre = s[0];
  int size = s.size();
  int cnt = 1;

  for(int i = 1; i < size; ++i){
    if(pres == 1){
      if(pre == s[i]){
	i++;
	if(i >= size) break;
	pres = 2;
      }
      pre = s[i];
    } else {
      pres = 1;
      pre = s[i];
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main() {
  int a;
  int b;
  char op;

  int calc;
  while(1) {
    std::cin >> a >> op >> b;
    if(op == '?') break;
    switch(op) {
      case '+':
        calc = a + b;
        break;
      case '-':
        calc = a - b;
        break;
      case '*':
        calc = a * b;
        break;
      case '/':
        calc = a / b;
        break;
    }
    std::cout << calc << std::endl;
  }

  return 0;
}

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

int main(){
  long long h,w;
  cin >>h>>w;
  if(h==1||w==1){
    cout << 1 << endl;
  }
  else{
  if(h%2==0){
    cout << h*w/2 << endl;
  }
  else{
    if(w%2==0){
      cout << h*w/2 << endl;
    }
    else{
      cout << (h*w+1)/2 << endl;
    }
  }
  }
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
	a, b = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)

ans = []
l, r = 0, g[0][0]
ans.append(l)
ans.append(r)
used = [l == i or r == i for i in range(n)]
end_l, end_r = False, False

while True:
	if not end_l:
		nxt = -1
		for i in g[l]:
			if used[i]: continue
			used[i] = True
			nxt = i
			ans.insert(0, nxt)
			l = nxt
			break
		if nxt == -1: end_l = True
	if not end_r:
		nxt = -1
		for i in g[r]:
			if used[i]: continue
			used[i] = True
			nxt = i
			ans.append(nxt)
			r = nxt
			break
		if nxt == -1: end_r = True
	if end_l and end_r: break
print(len(ans))
for i in ans:
	print(i + 1, end=' ')
print()


Measured memory_bytes: 23568
from collections import deque
s = deque(x for x in input())
s.append('END')
k = 0
l = [s.popleft()]
while True:
  if s[0] == 'END':
    break
  elif l[k] == s[0]:
    if s[1] == 'END':
      break
    else:
      l.append(s.popleft()+s.popleft())
  else:
    l.append(s.popleft())
  k += 1
print(len(l))

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

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy";
  if (s == "Rainy")
    	cout << "Sunny";
     if (s == "Cloudy")
       		cout << "Rainy";
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
#define umap unordered_map
#define all(x) x.begin(), x.end()
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M ;
    }
    return res%M;
}
lli solve(){
    lli n;
    cin>>n;
    vector<vll> S(n+1, vll(3, 0));
    loop(i, 1, n+1)
        cin>>S[i][0]>>S[i][1]>>S[i][2];
    vector<vll> dp(n+1, vll(3, 0));
    loop(i, 1, n+1){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + S[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + S[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + S[i][2];
    }
    cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
	// cin>>t;
    t = 1;
    while(t>0){ 
        t--;
        solve();
    }
}

Measured memory_bytes: 14268
#include<stdio.h>
int main()
{
    int a,b,cp,d,m,mn;
    int c[5];
    scanf("%d%d%d",&m,&cp,&d);
    c[1]=0;
    c[2]=0;
    c[3]=0;
    for(a=0;a<m;a++)
    {
        scanf("%d",&b);
        if(b<=cp)
            c[1]=c[1]+1;
        else if(b>d)
            c[2]=c[2]+1;
        else
            c[3]=c[3]+1;
    }
    mn=999;
    for(a=1;a<4;a++)
    {
        if(mn>c[a])
            mn=c[a];
    }
    printf("%d\n",mn);
  
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
#define ll long long
using namespace std;
struct Info{int nu,ne;}a[10010];
int n,x,y,num,b[5010],si[5010];
ll g[5010],dp[5010][5010][2],ansn,p[5010][2];
void jb(int x,int y){a[++num].nu=y;a[num].ne=b[x];b[x]=num;}
void dfs(int x,int fa){
	si[x]=1;dp[x][1][0]=1;
	for (int y=b[x];y;y=a[y].ne){
		if (a[y].nu!=fa){
			dfs(a[y].nu,x);
			for (int i=1;i<=si[x];i++){
				for (int j=1;j<=si[a[y].nu];j++){
					p[i+j][0]=(p[i+j][0]+dp[x][i][1]*dp[a[y].nu][j][1]+dp[x][i][0]*dp[a[y].nu][j][0])%mo;
					p[i+j][1]=(p[i+j][1]+dp[x][i][1]*dp[a[y].nu][j][0]+dp[x][i][0]*dp[a[y].nu][j][1])%mo;
					p[i][0]=(p[i][0]+g[j]*((dp[a[y].nu][j][1]*dp[x][i][0]+dp[a[y].nu][j][0]*dp[x][i][1])%mo))%mo;
					p[i][1]=(p[i][1]+g[j]*((dp[a[y].nu][j][0]*dp[x][i][0]+dp[a[y].nu][j][1]*dp[x][i][1])%mo))%mo;
				}
			}
			si[x]+=si[a[y].nu];
			for (int i=1;i<=si[x];i++){dp[x][i][0]=p[i][0];p[i][0]=0;dp[x][i][1]=p[i][1];p[i][1]=0;}
		}
	}
}
int main(){
	cin>>n;
	g[0]=1;
	for (int i=1;i<=n;i++)if(i%2==1)g[i]=0;else g[i]=g[i-2]*(i-1)%mo;
	for (int i=1;i<n;i++){cin>>x>>y;jb(x,y);jb(y,x);}
	dfs(1,0);
	for (int i=1;i<=n;i++) ansn=(ansn+g[i]*(dp[1][i][0]-dp[1][i][1]))%mo;
	ansn=(ansn+mo)%mo;
	cout<<ansn<<endl;
	return 0;
}

Measured memory_bytes: 391168
/*input
3 3
1 7
3 2
1 7
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m; cin >> n >> m;
    vector<pii> sc(m);
    for(int i = 0; i < m; i++) cin >> sc[i].first >> sc[i].second;
    if(n == 1)
    {
    	bool flag = 1;
    	for(int i = 0; i < m; i++) if(sc[i].second != 0)
    	{
    		flag = 0;
    		break;
    	}
    	if(flag)
    	{
    		cout << 0;
    		return 0;
    	}
    }
    for(int i = pow(10, n - 1); i < pow(10, n); i++)
    {
    	int ii = i;
    	vector<int> d(n);
    	for(int j = n - 1; j > -1; j--)
    	{
    		d[j] = ii % 10;
    		ii /= 10;
    	}
    	bool ok = 1;
    	for(int j = 0; j < m; j++) if(d[sc[j].first - 1] != sc[j].second)
    	{
    		ok = 0;
    		break;
    	}
    	if(ok)
    	{
    		cout << i;
    		return 0;
    	}
    }
    cout << -1;

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
typedef long double ldouble;
// 小大
int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}
typedef struct{
    llint aa;
    llint bb;
}frequent;
// 小大
int cmp( const void *p, const void *q ) {
    return ((frequent*)p)->bb - ((frequent*)q)->bb;
}
/*2つのうち小さい数を返す*/
llint min2(llint a,llint b){return a>=b?b:a;}

int main(void){
    llint n,i,ans=0,most;
    scanf("%lld",&n);
    llint p[n];
    for(i=0;i<n;i++){
        scanf("%lld",&p[i]);
        if(i==0){
            most=p[0];
            ans++;
            continue;
        }
        most=min2(most,p[i]);
        if(most==p[i]) ans++;
    }



    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

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

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    cin >> p >> q >> r;

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());

    vector<ll> pq(x + y);
    rep(i, x) pq[i] = p[i];
    rep(i, y) pq[x + i] = q[i];

    sort(pq.rbegin(), pq.rend());
    sort(r.rbegin(), r.rend());

    vector<ll> sum_pq(x + y + 1), sum_r(c + 1);
    rep(i, x + y) sum_pq[i + 1] = sum_pq[i] + pq[i];
    rep(i, c) sum_r[i + 1] = sum_r[i] + r[i];

    ll ans = 0;
    rep(cnt_r, min(c, x + y) + 1) {
        if (x + y < x + y - cnt_r) continue;
        chmax(ans, sum_r[cnt_r] + sum_pq[x + y - cnt_r]);
            //cout << sum_r[cnt_r] << " " << sum_pq[x + y - cnt_r] << endl;

    }
    cout << ans << endl;
}

Measured memory_bytes: 6144
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
	int n;
	int buy;
	int ice[10];

	while (scanf("%d", &n), n != 0){
		for (int i = 0; i < 10; i++){
			ice[i] = 0;
		}
		for (int i = 0; i < n; i++){
			scanf("%d", &buy);
			ice[buy]++;
		}

		for (int i = 0; i < 10; i++){
			for (int j = 0; j < ice[i]; j++){
				if (ice[i] == 0){
					cout << "-" << endl;
					break;
				}
				else {
					cout << "*";
				}
			}
			cout << endl;
		}
	}

	return (0);
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e9;



signed main(){
	int N;
	cin >> N;
	set<string>st;
	REP(i,N){
		string s;
		cin >> s;
		st.insert(s);
	}
	out(st.size());
}

Measured memory_bytes: 19224
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    while (true){
        cin >> H >> W;
        if (H == 0 && W == 0){
            break;
        }
        for(int i = 0; i < H; i++){
            for(int j =0; j < W; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}



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

int main(){
  int N,K,Q;
  cin >>N>>K>>Q;
 vector<int> data(N);
  for(int i=0;i<N;i++){data.at(i)=0;}
  int q;
for(int i=0;i<Q;i++){
  cin >>q;
  data.at(q-1)=data.at(q-1)+1;
}
for(int i=0;i<N;i++){
  if(K-(Q-data.at(i))>0){cout <<"Yes"<<endl;}
  else{cout <<"No"<<endl;}
}
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    string s;
    string t;

    cin>>s>>t;
    ll cnt=0;

    forn(i,sz(s)){
        if(s[i]!=t[i])cnt++;
    }

    cout<<cnt<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(N);
    ll ans = 0;
    REP(i,N) {
        cin >> A[i]; A[i]--;
    }
    REP(i,N-1) {
        if(A[i+1]>A[i])ans += (ll)A[i+1] - A[i];
        else ans += (ll)A[i+1]- A[i] + M;
    }
    vector<ll> v(2*M+1);
    REP(i,N-1) {
        if(A[i+1]>A[i]){
            v[A[i]+2]++;
            v[A[i+1]+1]--;
        }
        else {
            v[A[i]+2]++;
            v[A[i+1]+M+1]--;
        }
    }
    REP(i,2*M) v[i+1] += v[i];
    // REP(i,2*M+1) cout << v[i] << " "; cout << endl;
    REP(i,N-1) {
        if(A[i+1]>A[i]) v[A[i+1]+1] -= A[i+1] - A[i] - 1;
        else v[A[i+1]+1+M] -= A[i+1] + M - A[i] - 1;
    }
    REP(i,2*M) v[i+1] += v[i];
    // REP(i,2*M+1) cout << v[i] << " "; cout << endl;
    ll ma = 0;
	REP(i,M) ma = max(ma, v[i] + v[i+M]);
    ans -= ma;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
	string s,t;
	getline(cin,s);
	getline(cin,t);
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	bool ans=false;
	if(s.length()>=t.length()){
		for(int i=0; i<t.length(); i++){
			if(s[i]>t[i])break;
			else if(s[i]<t[i]){
				ans=true;
				break;
			}
		}
	}else{
		ans = true;
		for(int i=0; i<t.length(); i++){
			if(s[i]>t[i]){
				ans=false;
				break;
			}else if(s[i]<t[i]){
				break;
			}
		}
	}
	if(ans)cout<<"Yes\n";
	else cout<<"No\n";
      return 0;
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int r ;
	cin >> r ;
    cout << 3*r*r << endl;
}

Measured memory_bytes: 256
n,ais = int(raw_input()), map(int, raw_input().split())
import collections
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q = collections.deque()
while(n):
	if len(q) == 0:
		for u in range(3)[::-1]:
			if cc[u] > 0:
				q.append(u)
				cc[u]-=1
				n -=1
				break
		if len(q) == 0: break
	else:
		if q[-1] == 0:
			if cc[2]:
				q.append(2)
				cc[2]-=1
				n-=1
			elif cc[1]:
				q.append(1)
				cc[1]-=1
				n-=1
			elif cc[0]:
				q.append(0)
				cc[0]-=1
				n-=1
			else:
				break
		elif q[-1] == 2:
			if cc[0] == 0:
				break
			else:
				q.append(0)
				cc[0]-=1
				n-=1
		elif q[-1] == 1:
			if cc[1] > 0:
				q.append(1)
				cc[1]-=1
				n-=1
			else:
				break

print 'Yes' if n == 0 else 'No'

Measured memory_bytes: 89424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  string s,t,u;
  cin >> s >> t >> u;
  cout << 'A' << t[0] << 'C' << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		solve100();
	}

	public static void solve100(){
		Scanner sc = new Scanner(System.in);
		while(true) {
			int m = sc.nextInt();
			int nmin = sc.nextInt();
			int nmax = sc.nextInt();
			if(m==0&nmin==0&nmax==0) {
				break;
			}
			int sa =0 ;
			int kazu=0;
			int[] P = new int[m];
			for(int i=0;i<m;i++) {
				P[i] = sc.nextInt();
			}
			for(int i=nmin-1;i<nmax;i++) {
				if(sa <= (P[i]-P[i+1])) {
					sa = P[i]-P[i+1];
					kazu=i+1;
				}
			}
			System.out.println(kazu);
		}
	}

}


Measured memory_bytes: 55736
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#define MAX_SIZE 51
#define INF 10000
typedef long long int ll;
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b < 24){
        cout << a + b << endl;
    }
    else
    {
        cout << a + b - 24 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let mut b = (0..n).map(|_| it.next().unwrap().parse::<usize>().unwrap()).collect::<Vec<_>>();
    let mut res = Vec::new();
    for _ in 0..n {
        let mut idx = !0;
        for j in 0..b.len() {
            if b[j] == j+1 { idx = j }
        }
        if idx == !0 { break }
        res.push(idx+1);
        b.remove(idx);
    }
    if b.is_empty() {
        res.reverse();
        for &r in &res {
            println!("{}", r);
        }
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter < vec.end(); iter++)


int gcd(int x, int y)
{
    if (y > x)
        std::swap(x, y);
    while (y > 0)
    {
        int t = x % y;
        x = y;
        y = t;
    }
    return x;
}


int main()
{
    int x;
    cin >> x;
    int g = gcd(x, 360);
    int all = x * 360 / g;
    cout << all / x << endl;

    return 0;
}


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

int main(void){
  int S, W;
  bool ans = true;
  cin >> S >> W;
  if(W >= S)
    ans = false;
  if(ans) cout << "safe" << "\n";
  else cout << "unsafe" << "\n";
  return 0;
}

Measured memory_bytes: 3592
n=parse(Int,readline())
a=map(x->parse(Int,x),split(readline()))
m=0
for i=1:n
	if m<a[i]
		m=a[i]
	end
end
d=-1
for i=1:n
	if m!=a[i]&&abs(m-2*d)>abs(m-2*a[i])
		d=a[i]
	end
end
print(m,' ',d)

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

int main() {
	// your code goes here
	int n,m;cin>>n>>m;
	double sum=0;
	double a[n+1];for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
	sum=sum/(4*m);
	sort(a,a+n,greater<int>());
	for(int i=0;i<m;i++)
	{
	    if(a[i]<sum)
	    {
	        cout<<"No";
	        return 0;
	    }
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);

	        int N = sc.nextInt();
	        int K = sc.nextInt();
	        int[][] m = new int[1005][N+5];
	        for (int i=0 ; i<N; i++) {
	        	int tmp= Integer.parseInt(sc.next());
	            m[0][Math.max(0,i)]+=tmp;
	            m[0][Math.min(N,i+1)]-=tmp;
	        }
	        
    		int tmp=0;
	        for(int i=1;i<=Math.min(K, 100);i++) {
	        	for(int j=0;j<N;j++) {
	        		if(j==0) {
	        			tmp=m[i-1][0];
	        		} else {
	        			tmp=tmp+m[i-1][j];
	        		}
		        	m[i][Math.max(0,j-tmp)]++;	        		
		        	m[i][Math.min(N,j+tmp)+1]--;	        		
	        	}
	        }
	        int[] ans = new int[N];
	        ans[0]=m[Math.min(K, 100)][0];
	        System.out.print(ans[0]);
	        if(N!=1)System.out.print(" ");
	        for(int i=1;i<N;i++) {
	        	ans[i]=ans[i-1]+m[Math.min(K, 100)][i];
	        	System.out.print(ans[i]);
	        	if(i==N-1) {
	        		System.out.println();
	        	} else {
	        		System.out.print(" ");
	        	}
	        }
	        
	       
	    }
	}

Measured memory_bytes: 965124
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int MOD = 1e9 + 7;

int add(int x, int y) {
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

int sub(int x, int y) {
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

int mul(int x, int y) {
    return (1LL * x * y) % MOD;
}

int bin_pow(int a, int p) {
    if (!p)
        return 1;
    if (p % 2)
        return (1LL * bin_pow(a, p - 1) * a) % MOD;
    int t = bin_pow(a, p / 2);
    return (1LL * t * t) % MOD;
}

int inv(int x) {
    return bin_pow(x, MOD - 2);
}

vector <int> f;

int c(int n, int k) {
    return mul(f[n], inv(mul(f[k], f[n - k])));
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    f.resize(5000);
    f[0] = 1;
    forn (i, 1, sz(f))
        f[i] = mul(f[i - 1], i);
    int s;
    cin >> s;
    int ans = 0;
    forn (i, 1, s + 1) {
        int x = s - i * 3;
        if (x < 0)
            break;
        ans = add(ans, c(x + i - 1, i - 1));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;

class Myon
{
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        //Console.SetOut(new Printer(Console.OpenStandardOutput()));
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }


    public void calc()
    {
        int a = cin.nextInt(), b = cin.nextInt(), c = cin.nextInt();
        //Console.WriteLine($"{a} {b} {c}");
        if (a <= c && c <= b) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    
}

class Printer : StreamWriter
{
    public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
    public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio> 
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>

#define MAXN 0x7fffffff

using namespace std;

int m,n,i,j,k,p,q,l,flag=0;

int main(){
	scanf("%d",&n);
	m=sqrt(n);
	i=pow(m,2);
	printf("%d",i);
}

Measured memory_bytes: 256
/*
 © 2020-07-11 06:54:04 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const int N = 2e5 + 5;
lli m[2][N];
lli f(lli x){
  lli res = 1;
  while(x > 0){
    x %= __builtin_popcountll(x);
    res++;
  }
  return res;
}
int main(){ _
  lli n; string x; cin >> n >> x;
  lli cnt = 0;
  fore(i, 0, n){
    cnt += x[i] == '1';
  }
  lli cur = 1;
  if(cnt > 1){
    fore(i, 0, n){
      cur %= (cnt - 1ll);
      m[0][n - i - 1] = cur;
      cur <<= 1ll;
    }
  }
  cur = 1;
  fore(i, 0, n){
    cur %= (cnt + 1ll);
    m[1][n - i - 1] = cur;
    cur <<= 1ll;
  }
  lli acu0 = 0, acu1 = 0;
  fore(i, 0, n) if(x[i] == '1') acu0 += m[0][i];
  fore(i, 0, n) if(x[i] == '1') acu1 += m[1][i];
  // fore(i, 0, n) cout << m[0][i] << ' '; cout << ENDL;
  // fore(i, 0, n) cout << m[1][i] << ' ' ; cout << ENDL;
  // cout << acu0 << ' ' << acu1 << ENDL;
  fore(i, 0, n){
    if(x[i] == '1'){
      if(cnt == 1) cout << 0 << ENDL;
      else if(cnt == 2) cout << 1 << ENDL;
      else cout << f((acu0 - m[0][i]) % (cnt - 1ll)) << ENDL;
    }else{
      if(cnt == 0) cout << 1 << ENDL;
      else cout << f((acu1 + m[1][i]) % (cnt + 1ll)) << ENDL;
    }
  }
  return 0;
}


Measured memory_bytes: 6832
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

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

  vector<int> a(n);
  r(i,n)cin>>a.at(i);
  int cnt=0;

  r(i,n){
    while(a.at(i)!=0){
      if(a.at(i)%2==0)a.at(i)/=2,cnt++;
      else break;
    }
  }

  cout<<cnt<<endl;

  return 0;
}


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

int main(){
    ll N,A;
    cin >> N >> A;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<vector<ll> > dp(51,vector<ll> (2501));
    rep(i,51){
        rep(j,2501){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    rep(i,N){
        for (ll j = 49; j >= 0; j--){
            for (ll k = 2450; k >= 0; k--){
                dp[j + 1][k + vec[i]] += dp[j][k];
            }
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= 50; i++){
        ans += dp[i][i * A];
    }
    cout << ans << endl;
}



Measured memory_bytes: 1280
fun main(args: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(' ').map { it.toDouble() }
    val s = T1A.Segment(T1A.Point(x1, y1), T1A.Point(x2, y2))
    val q = readLine()!!.toInt()
    repeat(q) {
        val (x, y) = readLine()!!.split(' ').map { it.toDouble() }
        val p = T1A.Point(x, y)
        println(p.project(s))
    }
}

private class T1A {

    data class Point(val x: Double, val y: Double) {

        fun dot(p: Point): Double {
            return x * p.x + y * p.y
        }

        fun norm(): Double {
            return x * x + y * y
        }

        fun project(s: Segment): Point {
            val base = s.p2 - s.p1
            val r = (this - s.p1).dot(base) / base.norm()
            return s.p1 + base * r
        }

        operator fun plus(p: Point): Point {
            return Point(x + p.x, y + p.y)
        }

        operator fun minus(p: Point): Point {
            return Point(x - p.x, y - p.y)
        }

        operator fun times(r: Double): Point {
            return Point(x * r, y * r)
        }

        override fun toString(): String {
            return "$x $y"
        }

    }

    data class Segment(val p1: Point, val p2: Point)

}



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

#define int long long int
#define main signed main()
#define bye return 0

#define rep(i, n) for (int i = 0; i < (n); i++)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define sum(v) accumulate(all(v), 0)
#define cinv(v, n) rep(i, n) cin >> v[i]
#define prec(n) fixed << setprecision(n)
#define stlice(s, l) substr(s, s + l + 1)
#define odd(n) ((n) % 2)
#define even(n) (!((n) % 2))

#define INF 1e9
#define MOD (1e9 + 7)

#define pb push_back
#define mt make_tuple
#define fi first
#define se second
#define str string
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<str>

using namespace std;

main {
  int h, w;
  cin >> h >> w;
  int c = 0;
  rep(i, h) {
    str a;
    cin >> a;
    rep(j, a.size()) c += a[j] == '#';
  }
  cout << (h + w - 1 == c ? "Possible" : "Impossible") << endl;
  bye;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int n,q;
	while(1){
		cin>>n>>q;
		if(n==0)break;
	//	vector<vector<int> > date(n,vector<int>);
		vector<int> time(101,0);
		bool flag=true;
		int m;
		int ans=0;
		for(int i=0;i<n;i++){
			cin>>m;
			int a;
			for(int j=0;j<m;j++){
				cin>>a;
				time[a]++;
			//	if(time[a]==q&&flag){
				//	ans=min(a,ans);
			//		ans=a;
				//	flag=false;
			//	}
			}
		}
		int ma=0;
		for(int i=0;i<101;i++){
			if(time[i]>=q&&time[i]>ma){
				ma=time[i];
				ans=i;
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 3092
/*
  AtCoder Beginner Contest 081
  C - Not so Diverse

  方針
    数の少ない数字が書かれたボールを最も数の多い数字に書き換えるのが効率が良い。
    数字の種類は関係なく、各数字が書かれている数のみが必要である。
  
  実装
    1. unordered_mapに各数字がいくつ書かれているかを格納する。
    2. 各数字の数に関して、降順にソートする。
    3. 数字の種類数がK個になるように、数の総和を取る。
*/

#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;

int N, K, A;
unordered_map<int, int> A_map;
vector<int> A_cnt;

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A);
    auto itr = A_map.find(A);
    if (itr != A_map.end()) itr->second += 1;
    else A_map[A] = 1;
  }

  for (auto& itr : A_map) A_cnt.push_back(itr.second);
  sort(A_cnt.begin(), A_cnt.end());

  int cnt = 0;
  if ((int)A_cnt.size() - K > 0) {
    for (int i = 0; i < A_cnt.size() - K; ++i) cnt += A_cnt[i];
  }

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 10312
import sys
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

H,W = map(int,input().split(' '))
MAP = [None]*H
for i in range(H):
    MAP[i] = list(input())

ANS = 0

dxy = [(0,1),(1,0),(0,-1),(-1,0)]

import queue
q = queue.Queue()

for i in range(H):
    for j in range(W):
        st = MAP[i][j]
        if st=='#': continue
        dist = [[0]*W for i in range(H)]
        visited = [[0]*W for i in range(H)]
        visited[i][j] = 1
        q.put([i,j])
        while not q.empty():
            y,x = q.get()
            for dy,dx in dxy:
                ny,nx = y+dy,x+dx
                if not (0<=nx<W): continue
                if not (0<=ny<H): continue
                if visited[ny][nx]: continue
                if MAP[ny][nx] == '#': continue
                visited[ny][nx] = 1
                dist[ny][nx] = dist[y][x] + 1
                q.put([ny,nx])
        ANS = max(ANS, max(max(row) for row in dist))
print(ANS)

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);
    
    set<string> x;
    for(string i: s) {
        x.insert(i);
    }
    cout << x.size() << endl;
}

Measured memory_bytes: 25064
#include <cstdio>
#include <algorithm>
#include <queue>

#define EiP 40320
#define MAX 100000
using namespace std;

int ans,dis[EiP];
int vx[] = {0,0,1,-1},vy[] = {1,-1,0,0};
int a[8]={0,1,2,3,4,5,6,7};


void IntToMat(int n,int* a){
	int rank= EiP;
	bool b[8];
	for(int i=0;i<8;i++) b[i] = true;
	
	for(int i=0;i<8;i++){
		rank = rank/(8-i);
		int j,sum=0;
		for(j=0;j<8;j++){
			if(b[j]) sum++;
			if(sum == n/rank+1) break;
		}
		b[j] = false;
		a[i] = j;
		n = n%rank;
	}
}

void MatToInt(int a[8], int* n){
	int l=7; *n = 0;
	bool b[8];
	for(int i=0;i<8;i++) b[i] = true;
	for(int i=0;i<7;i++){
		int sum=0;
		b[a[i]] = false;
		for(int j=0;j<a[i];j++)
			if(b[j]) sum++;
		*n = (7-i)*(*n+sum);
	}
}

void set(){
	queue<int> que;
	MatToInt(a,&ans);
	dis[ans] = 0;
	que.push(ans);
	
	int c[8];
	while(!que.empty()){
		int v=que.front(); que.pop();
		IntToMat(v,c);
		int z;
		for(int i=0;i<8;i++)
			if(c[i] == 0) z = i;
		for(int i=0;i<4;i++){
			int px,py;
			px = z/4 + vx[i];
			py = z%4 + vy[i];
			if(-1<px&&px<2&&-1<py&&py<4){
				int id,pz,l;
				pz = 4*px+py;
				l = c[z]; c[z] = c[pz]; c[pz] = l;
				MatToInt(c,&id);
				if(dis[v]+1<dis[id]){
					que.push(id);
					dis[id] = dis[v]+1;
				}
				l = c[z]; c[z] = c[pz]; c[pz] = l;
			}
		}
	}
}

void solve(){
	MatToInt(a,&ans);
	printf("%d\n",dis[ans]);
}

int main(){
	for(int i=0;i<EiP;i++) dis[i] = MAX;
	set();
	for(int p=0;p<1000;p++){
		for(int i=0;i<8;i++){
			if(EOF == scanf(" %d",&a[i])){
				return 0;
			}
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[100010],b[100010],c[100010],dp[100010][3],ans=0;
inline int read(){
     int x=0,f=1;char ch=getchar();
     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
     while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
     return x*f;
 }
int main ( )
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),c[i]=read();
	dp[1][0]=a[1];dp[1][1]=b[1];dp[1][2]=c[1];
	for(int i=2;i<=n;i++)
	{
		dp[i][0]=std::max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=std::max(dp[i-1][2]+b[i],dp[i-1][0]+b[i]);
		dp[i][2]=std::max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
	}
	for(int i=0;i<3;i++) ans=std::max(ans,dp[n][i]);
	cout<<ans;
	return 0;
}

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

int main() {
    int N;
    std::cin >> N;
 
    const int num = 3 * N;
    std::vector<int> a(num);
    for (int i = 0; i < num; ++i) {
        std::cin >> a[i];
    }
    
    std::sort(a.begin(), a.end(), std::greater<int>());
 
    long long ret = 0;
    for (int i = 0; i < N; ++i) {
        ret += a[2 * i + 1];
        // cout << "the process of ans is " << ret << endl;
    }
 
    std::cout << ret << std::endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
typedef long double ld;
int main(){
  ll n;  cin >> n;
  ll cnt = 0;
  ll ans[10][10]={0};
  rep(i,1,n+1){
    string s = to_string(i);
    int f = s[0] - '0';
    int b = s[s.size()-1] - '0';
    if(!f || !b) continue;
    ans[f][b]++;
  }
  rep(i,1,10)rep(j,1,10){
    cnt += ans[i][j] * ans[j][i];
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
#define SZ 233333
const int MOD=1e9+7; //or any prime
ll qp(ll a,ll b)
{
	ll x=1; a%=MOD;
	while(b)
	{
		if(b&1) x=x*a%MOD;
		a=a*a%MOD; b>>=1;
	}
	return x;
}
namespace linear_seq {
inline vector<int> BM(vector<int> x)
{
	//ls: (shortest) relation sequence (after filling zeroes) so far
	//cur: current relation sequence
	vector<int> ls,cur;
	//lf: the position of ls (t')
	//ld: delta of ls (v')
	int lf,ld;
	for(int i=0;i<int(x.size());++i)
	{
		ll t=0;
		//evaluate at position i
		for(int j=0;j<int(cur.size());++j)
			t=(t+x[i-j-1]*(ll)cur[j])%MOD;
		if((t-x[i])%MOD==0) continue; //good so far
		//first non-zero position
		if(!cur.size())
		{
			cur.resize(i+1);
			lf=i; ld=(t-x[i])%MOD;
			continue;
		}
		//cur=cur-c/ld*(x[i]-t)
		ll k=-(x[i]-t)*qp(ld,MOD-2)%MOD/*1/ld*/;
		vector<int> c(i-lf-1); //add zeroes in front
		c.pb(k);
		for(int j=0;j<int(ls.size());++j)
			c.pb(-ls[j]*k%MOD);
		if(c.size()<cur.size()) c.resize(cur.size());
		for(int j=0;j<int(cur.size());++j)
			c[j]=(c[j]+cur[j])%MOD;
		//if cur is better than ls, change ls to cur
		if(i-lf+(int)ls.size()>=(int)cur.size())
			ls=cur,lf=i,ld=(t-x[i])%MOD;
		cur=c;
	}
	for(int i=0;i<int(cur.size());++i)
		cur[i]=(cur[i]%MOD+MOD)%MOD;
	return cur;
}
int m; //length of recurrence
//a: first terms
//h: relation
ll a[SZ],h[SZ],t_[SZ],s[SZ],t[SZ];
//calculate p*q mod f
inline void mull(ll*p,ll*q)
{
	for(int i=0;i<m+m;++i) t_[i]=0;
	for(int i=0;i<m;++i) if(p[i])
		for(int j=0;j<m;++j)
			t_[i+j]=(t_[i+j]+p[i]*q[j])%MOD;
	for(int i=m+m-1;i>=m;--i) if(t_[i])
		//miuns t_[i]x^{i-m}(x^m-\sum_{j=0}^{m-1} x^{m-j-1}h_j)
		for(int j=m-1;~j;--j)
			t_[i-j-1]=(t_[i-j-1]+t_[i]*h[j])%MOD;
	for(int i=0;i<m;++i) p[i]=t_[i];
}
inline ll calc(ll K)
{
	for(int i=m;~i;--i)
		s[i]=t[i]=0;
	//init
	s[0]=1; if(m!=1) t[1]=1; else t[0]=h[0];
	//binary-exponentiation
	while(K)
	{
		if(K&1) mull(s,t);
		mull(t,t); K>>=1;
	}
	ll su=0;
	for(int i=0;i<m;++i) su=(su+s[i]*a[i])%MOD;
	return (su%MOD+MOD)%MOD;
}
inline int work(vector<int> x,ll n)
{
	if(n<int(x.size())) return x[n];
	vector<int> v=BM(x); m=v.size(); if(!m) return 0;
	for(int i=0;i<m;++i) h[i]=v[i],a[i]=x[i];
	return calc(n);
}
}
using linear_seq::work;
int main()
{
	int t; cin>>t;
	for (int i=0; i<t; i++) {
		int n; cin>>n;
		cout<<work({0, 0, 0, 0, 0, 1, 11, 71, 341, 1346, 4598, 14038, 39138, 101193, 245443, 563447, 1232837, 2585672, 5222552, 10198232, 19316488, 35588718, 63933498, 112225058, 192839398, 324900532, 537499132, 874246012, 399637805, 207858088, 434820093, 274485959, 780358, 996765147, 793168065, 118878018, 966647141, 677996797, 52230779, 485540255, 147468710, 203524158, 94513877, 885277100, 697944950, 247718575, 502478077, 491383141, 292066399, 231133366, 338549256, 103211098, 584671766, 944719442, 472440689, 187649773},n)<<endl;
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        int n;
        cin >> n;
        int mod = 1e9 + 7;
        if (n == 1)
        {
            cout << 0 << endl;
            return (0);
        }
        if (n == 2)
        {
            cout << 2 << endl;
            return (0);
        }
        int ans = 1;
        rep(i,0,n)
        {
            ans = ((ans % mod) * 10) % mod;
        }
        int del = 1;
        rep(i,0,n)
        {
            del = ((del % mod) * 9) % mod;
        }
        int add = 1;
        rep(i, 0, n)
        {
            add = ((add % mod) * 8) % mod;
        }
        del = (((2*del)%mod - add%mod)%mod+mod)%mod;
        cout << ((ans%mod-del%mod)%mod+mod)%mod << endl;
    }
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false


int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    SORT(a);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256