akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define W 0
#define B 1
#define inf 2000000
#define NIL -1
#define N 101

int main()
{
  int n,i,j,mincost,u,v,a=0;
  int g[N][N];
  int d[N], p[N],c[N];
 
scanf("%d",&n);
for(i=1;i<=n;i++)
  {
    for(j=1;j<=n;j++)
      {
    scanf("%d",&g[i][j]);
      }
  }
 
for(u=1;u<=n;u++)
  {
    d[u] = inf;
    p[u] = NIL;
    c[u] = W;
  }
 d[1] = 0;
 
 while(1)
   {
     mincost =inf;
     for(i=1;i<=n;i++)
       {
     if(c[i]!=B && d[i]<mincost)
       {
         mincost = d[i];
         u=i;
       }
       }
     if(mincost ==inf)break;
 
     c[u]=B;
 
 
         for(v=1;v<=n;v++)
           {
         if(g[u][v] == -1) continue;
        else if(c[v]!=B && g[u][v]<d[v])
           {
             p[v] =u;
             d[v] = g[u][v];
           }
           }
       }
        
 
 for(i=1;i<=n;i++)
   a+=d[i];
 printf("%d\n",a);
 return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> ans(n+1);
  rep(i,n) {
    int a; cin >> a;
    ans.at(a) = i+1;
  }
  rep(i,n) {
    cout << ans.at(i+1) << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int n,k,s;
int main()
{
	cin>>n>>k>>s;
	for(int i=1;i<=k;i++)
		cout<<s<<" ";
	for(int i=k+1;i<=n;i++)
	{
		if(s!=1e9)
			cout<<s+1<<" ";
		else
			cout<<1<<" ";
	}
	return 0;
}


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

int main(int argc, char *argv[])
{
	char x, y;
	cin >> x >> y;

	if (x > y)
		cout << ">\n";
	else if (y > x)
		cout << "<\n";
	else
		cout << "=\n";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
    char name;
    scanf("%c", &name);

    for(int i = 0; name != '\0'; i++){
        if(name >= 'a' && name <= 'z'){
        puts("a");
        break;
        }
        else if(name >= 'A' && name <='Z'){
        puts("A");
        break;
        }
    }
    return 0;
}

Measured memory_bytes: 1600
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int A[] = new int[1000001];
    for(int i=1; ; i++){
      if(A[s] != 0){
        System.out.println(i);
        return;
      }
      A[s] = i;
      if(s%2==0) s/=2;
      else s=s*3+1;
    }
  }
}

Measured memory_bytes: 25940
while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break

    data = [list(map(int, input().split())) for i in range(m)]

    data.sort()
    infect = [False for i in range(n + 1)]
    infect[1] = True
    for t, s, d in data:
        if infect[s]:
            infect[d] = True

    print(infect.count(True))


Measured memory_bytes: 14416
N = int(input())
a = list(map(int,input().split()))
#a = [100]*N
A = dict(zip(list(range(len(a))),a))
ans = 0
suma = 0
suma = sum(a)

for i in range(len(a)-1):
  suma -= A[i]
  ans = (ans + A[i]*suma)%1000000007
  
print(ans)

Measured memory_bytes: 42624
#!/usr/bin/env python3
def main():
    import numpy as np

    N = int(input())
    happiness = [list(map(int, input().split())) for _ in range(N)]

    dp = np.zeros((N, 3), dtype=np.int64)
    dp[0] = happiness[0]
    for i in range(1, N):
        for a, yesterday in enumerate(dp[i - 1]):
            for b, today in enumerate(happiness[i]):
                if a == b:
                    continue
                dp[i][b] = max(dp[i][b], yesterday + today)
    print(max(dp[-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 50312
#include <stdio.h>

int main(void){
    int len,score=0,i,j,k,buf=0;
    scanf("%d", &len);
    int ary[len];
    for(i=0;i<len;i++) scanf("%d", &ary[i]);
    for(j=len-1;j>=0;j--){
        for(k=0;k<j;k++){
            if (ary[k] > ary[k+1]){
                buf=ary[k], ary[k]=ary[k+1], ary[k+1]=buf;
                score++;
            }
        }
    }
    for(i=0;i<len;i++){(i<len-1)? printf("%d ",ary[i]) : printf("%d", ary[i]);}
    printf("\n%d\n", score);
    return 0;
}


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

int main() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if(0<=x-r && 0<=y-r && x+r<=W && y+r<=H){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  
  return 0;
}

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

int main() {
  int X, N;
  cin >> X;
  cin >> N;
  vector<int> p(N);
  unordered_set<int> exist;

  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    exist.insert(p[i]);
  }

  int mindiff = 1000;
  int minnum = 1000;
  sort(p.begin(), p.end());
  int j;
  for (j = -1; j <= max(p[p.size() - 1] + 1, X + 1); j++) {
    if (exist.count(j) == 0 and abs(X - j) < mindiff) {
      mindiff = abs(X - j);
      minnum = j;
    }
  }
  cout << minnum << endl;
}


Measured memory_bytes: 3640
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=2e5+10;
const int inf=1e9;
int n;
int main(){
    //ios::sync_with_stdio(false);
    //freopen("in","r",stdin);
    scanf("%d",&n);
    int mn=inf,ans=0;
    rep(i,1,n){
        int x;
        scanf("%d",&x);
        mn=min(mn,x);
        if(mn==x) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3784
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 200010;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1];
	constexpr unko() : fac(), ifac() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
	}
} f;

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


	int N, M, K;
	scanf("%d %d %d", &N, &M, &K);

	if (M == 1) {
		if (K == N - 1) printf("1");
		else printf("0");

		return 0;
	}
	if (N == 1) {
		printf("%d", M);
		return 0;
	}

	ll kotae = 0;
	ll tmp = ll(M) * f.fac[N - 1] % mod * modpow(M - 1, N - K - 1) % mod;
	for (int k = K; k >= 0; k--) {
		kotae += tmp * f.ifac[k] % mod * f.ifac[N - 1 - k] % mod;
		tmp = tmp * (M - 1) % mod;
	}

	printf("%lld", kotae % mod);



	Would you please return 0;
}

Measured memory_bytes: 2620
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {
	
	const ll MOD = 1e9 + 7;

	ll N;
	cin >> N;
	vector<ll> vec(N);
	rep(i, N) cin >> vec[i];

	vector<ll> clr(3,-1);

	ll ans = 1;

	rep(i, N) {

		int choice = 0;
		rep(j, 3) {
			if (clr[j] == vec[i] - 1) choice++;
		}
		ans = (ans * choice)%MOD;

		if (clr[0] == vec[i] - 1) clr[0]++;
		else if (clr[1] == vec[i] - 1) clr[1]++;
		else if (clr[2] == vec[i] - 1) clr[2]++;

	}
	//ll clrNum = 0;
	//rep(i, 3) if (clr[i] != -1) clrNum++;

	//if (clrNum == 1) ans = (ans * 3) % MOD;
	//else ans = (ans * 6) % MOD;

	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = int.Parse(Console.ReadLine());
            var h = (S / 3600);
            var M = (S / 60);
            var m = (M % 60);
            var s = (S % 60);
            Console.WriteLine("{0}:{1}:{2}", h, m, s);
        }
    }
}

Measured memory_bytes: 9072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nkq = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var n = nkq[0];
            var k = nkq[1];
            var q = nkq[2];

            var ans = new int[n];
            for (var i = 0; i < q; i++)
            {
                ans[int.Parse(Console.ReadLine()) - 1]++;
            }

            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(k - q + ans[i] > 0 ? "Yes" : "No");
            }
        }
    }
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();
            var digitCount = vals[0];
            var condCount = vals[1];

            var digits = new int?[digitCount];
            for (int i = 0; i < condCount; i++)
            {
                vals = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();
                var idx = vals[0] - 1;
                var num = vals[1];

                if (idx == 0 && num == 0 && digitCount >= 2)
                {
                    Console.WriteLine(-1);
                    return;
                }

                if (digits[idx] != null && digits[idx] != num)
                {
                    Console.WriteLine(-1);
                    return;
                }
                digits[idx] = num;
            }

            //1桁のとき
            if (digitCount == 1)
            {
                if (digits[0] == null)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Console.WriteLine(digits[0]);
                }
                return;
            }
            //2桁以上
            if (digits[0] == null)
            {
                digits[0] = 1;
            }
            for (int i = 1; i < digitCount; i++)
            {
                if (digits[i] == null)
                {
                    digits[i] = 0;
                }
            }
            foreach (var n in digits)
            {
                Console.Write(n);
            }
            Console.WriteLine();
        }
    }
}


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

public class Program
{
    public static void Main()
    {
        //int[] num = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        //string s = Console.ReadLine();
        //int num = int.Parse(Console.ReadLine());
        ulong u = ulong.Parse(Console.ReadLine());
        ulong ans = 1;
        for (ulong i = 1; i <= u; i++) {
            ans = (ans * i)% 1000000007;
        }
        Console.WriteLine(ans);
    }

}

Measured memory_bytes: 11220
#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 << "Balanced" << endl;
  }else if (a + b < c + d) {
    cout << "Right" << endl;
  }else if (a + b > c + d) {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
//B - Digital Gifts
int main(void){
    int n;
    std::cin >> n;
    double x;
    string u;
    double sum=0;
    for(int i=0;i<n;i++){
        std::cin >> x >> u;
        if(u=="JPY"){
            sum+=x;
        }else{
            sum+=x*380000;
        }
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include <atcoder/dsu>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, Q;
  cin >> N >> Q;
  dsu d(N);
  REP(q, Q) {
    int t, u, v;
    cin >> t >> u >> v;
    if(t == 0) d.merge(u, v);
    else {
      if(d.same(u, v)) cout << 1 << "\n";
      else cout << 0 << "\n";
    }
  }
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  bool ans = true;
  for(ll i=b+1;i<=d;i++){
    if(s[i]=='#' && s[i-1]=='#'){
      ans = false;
      break;
    }
  }
  if(d<c){
    ll stay = -1;
    for(ll i=b;i<=d;i++){
      if(i==0) continue;
      if(s[i-1]=='.' && s[i]=='.' &&s[i+1]=='.'){
        stay = i;
        break;
      }
    }
    if(stay<0){
      cout << "No" << endl;
      return 0;
    }
    s[stay] = '#';
  }
  for(ll i=a+1;i<=c;i++){
    if(s[i]=='#' && s[i-1]=='#'){
      ans = false;
      break;
    }
  }
  if(!ans){
    cout << "No" << endl;
    return 0;
  } else {
    cout << "Yes" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 640
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a == 12 && c == 1 && d == 1) {
        cout << 1 << endl;
        return 0;
    }
    if((c-a)*d == 1) cout << 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,q,in,ans=0;
	cin>>n>>q;
	int ev = (n%2==0?1:0);
	vl a(n),sum(n+1);
	rep(i,n)cin>>a[i];
	if(ev==1){
		n--;
		a.erase(a.begin());
	}
	rrep(i,n) sum[i]=sum[i+1]+a[i];
	vl line,lsum(1);
	for(int i=0;i<n-2;i+=2){
		line.push_back((a[i]+a[i+(n-i-1)/2])/2+1);
		lsum.push_back(lsum.back()+a[i]);
	}
	line.push_back(LINF);

	//scout<<line<<endl;
	//cout<<lsum<<endl;

	rep(i,q){
		cin>>in;
		int e=upper_bound(all(line),in)-line.begin();
		cout<<lsum[e]+sum[n/2+e] <<"\n";
		//cout<<e<<"  "<<lsum[e]<<"   "<<sum[n/2+e] <<"\n";
	}
}

 

Measured memory_bytes: 4340
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Mod 1000000007
char a[110],b[110];
int main()
{
    int n,i,j,k,flag;
    long long s;
    scanf("%d",&n);
    scanf("%s%s",a,b);
    if(n==1)
    {
        printf("3\n");
        return 0;
    }
    if(n==2)
    {
        printf("6\n");
        return 0;
    }
    if(a[0]==b[0])
    {
        s=3;
        flag=2;
        for(i=1;i<n;i++)
        {
            if(a[i]==b[i])
            {
                if(flag==2)
                    s=s*2%Mod;
                flag=2;
            }
            else
            {
                if(flag==1)
                s=s*3%Mod;
                else
                s=s*2%Mod;
                flag=1;
                i++;
            }
        }
    }
    else
    {
        s=6;
        flag=1;
        for(i=2;i<n;i++)
        {
            if(a[i]==b[i])
            {
                if(flag==2)
                    s=s*2%Mod;
                flag=2;
            }
            else
            {
                if(flag==1)
                    s=s*3%Mod;
                else
                s=s*2%Mod;
                flag=1;
                i++;
            }
        }
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N, K, Q; cin >> N >> K >> Q;
    vector<ll> A(Q);
    rep(i, Q) cin >> A[i];
    map<ll, ll> ma;
    rep(i, Q) ++ma[A[i]-1];
    ll jj = 0;
    rep(i, N) {
        if (Q - ma[i] < K) { cout << "Yes" << endl; }
        else { cout << "No" << endl; }
    }
}

Measured memory_bytes: 7680
using System;
using System.Collections.Generic;
class Program
    {
        class Node<T>
        {
            private int m_height;
            private Node<T> m_parent;
            public T Item { get; private set; }
            private int m_size;
            public Node(T item)
            {
                m_height = 0;
                m_parent = this;
                Item = item;
                m_size = 1;
            }
            public int Size()
            {
                return Find().m_size;
            }
            public Node<T> Find()
            {
                if (m_parent == this) { return this; }
        
                Node<T> parent = m_parent.Find();
                m_parent = parent;
                return parent;
            }
            public static void Unite(Node<T> a, Node<T> b)
            {
                Node<T> p = a.Find();
                Node<T> q = b.Find();
                if (p == q) return;
                if (p.m_height < q.m_height)
                {
                    p.m_parent = q;
                    q.m_height = Math.Max(p.m_height + 1, q.m_height);
                    q.m_size = p.m_size + q.m_size;
                }
                else
                {
                    q.m_parent = p;
                    p.m_height = Math.Max(q.m_height + 1, p.m_height);
                    p.m_size = p.m_size + q.m_size;
                }
            }
        }
        static long comb2(int num)
        {
            return (long) num * (num - 1) / 2;
        }
    	static void Main(string[] args)
    	{
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]), m = int.Parse(input[1]);
            Node<int>[] nodes = new Node<int>[n];
            for (int i=0; i<n; i++) nodes[i] = new Node<int>(i);
            int[,] decayList = new int[m, 2];
            for (int i=0; i<m; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                decayList[i, 0] = int.Parse(s[0]) - 1;
                decayList[i, 1] = int.Parse(s[1]) - 1;
            }
            long[] ans = new long[m + 1];
            ans[m] = comb2(n);
            for (int i=m-1; i>=0; i--)
            {
                Node<int> n1 = nodes[decayList[i, 0]], n2 = nodes[decayList[i, 1]];
                int a = n1.Size(), b = n2.Size();
                Node<int>.Unite(n1, n2);
                int c = n1.Size();
                //Console.Error.WriteLine("c: " + c);
                if (c > a) ans[i] = ans[i + 1] - comb2(c) + comb2(a) + comb2(b);
                else ans[i] = ans[i + 1];
            }
            for (int i=1; i<=m; i++) Console.WriteLine(ans[i]);
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 24588
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007

using namespace std;

int main(){

  int a,n,m;
  long long ans=0;
  priority_queue<int> q;

  //入力を受け取る
  cin >> n >> m;
  
  rep(i,0,n-1){
    cin >> a;
    q.push(a);
  }

  //チケットを一枚ずつ使う
  rep(i,0, m-1){
    //qから最大値を取り出し、値を半分にしてqに戻す
    a = q.top();
    q.pop();
    q.push(a/2);
  }

  //チケットを使い終わった後、qに残っている金額を合計する
  rep(i,0,n-1){
    a = q.top();
    q.pop();
    ans += a;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 892
/*input
1729
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 2005;

ll dp[MX];

ll solve(ll s) {
	if(s == 0) {
		return 1;
	}
	if(dp[s] != -1) {
		return dp[s];
	}
	ll ans = 0;
	for(ll i = 3; i <= s; i++) {
		ans = (ans + solve(s - i)) % MOD;
	}
	return dp[s] = ans;
}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll s; cin >> s;
	memset(dp, -1, sizeof(dp));
	cout << solve(s) << endl;
	return 0;
}




















Measured memory_bytes: 3672
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;


public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().exec();
	}
	
	public void exec() throws IOException {
		InputUtil in = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int X = in.nextInt();
		int t = in.nextInt();
		int ans = (X>t)?(X-t):0;
		out.println(ans);
		out.flush();
	}
	
}

class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 10000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 19668
using System;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var A = int.Parse(input.Split(' ')[0]);
            var B = int.Parse(input.Split(' ')[1]);
			if(A >9 || B >9)
            {
              Console.WriteLine("-1");
            }
          else
          {
            Console.WriteLine(A*B);
          }
            
        }
    }
}


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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;


int main() {
    string s; cin >> s;
    replace(s.begin(),s.end(),',',' ');
    cout << s << endl;

    return 0;

}


Measured memory_bytes: 256
N,M,C=gets.split.map(&:to_i)
BS=gets.split.map(&:to_i)
AS=N.times.map { gets.split.map(&:to_i) }

cnt = 0
N.times do |i|
  sum=0
  AS[i].zip(BS).each do |a, b|
      sum+=a*b
  end
  cnt+=1 if sum+C>0
end

p cnt


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main(void){
  int n,m;
  int a,b,s;
  int z=0;
  bool f=false;
  cin>>n>>m;
  z=s=m;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    s+=a;
    s-=b;
    z=max(z,s);
    if(s<0){
      f=true;
    }
  }
  if(f)cout<<"0"<<endl;
  else cout<<z<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	cin >> n;
	vector<int> ans(7,0);
	if(n == 0) break;
	REP(i,n){
	    int temp;
	    cin >> temp;
	    ans[min(temp/10,6)]++;
	}
	REP(i,7){
	    cout << ans[i] << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  double l;
  cin >> l;
  cout << fixed << setprecision(10);
  cout << l*l*l/27 << endl;
}


Measured memory_bytes: 256
// D - Semi Common Multiple
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int solve(int N, int M, vi &A){
	int T, x = A[0]/2; for(T=0; !(x&1); T++) x>>=1;
	M >>= T;
	ll L = 1;
	for(int a:A){
		int b = a/2;
		int t; for(t=0; !(b&1); t++) b>>=1;
		if(t != T) return 0;
		if((L=lcm(L, b)) > M) return 0;
	}
	return (M/L+2-1)/2;//round up
}

int main(){
	int N,M; cin>>N>>M;
	vi A(N); rp(i, 0, N) cin>>A[i];
	cout<< solve(N,M,A) <<endl;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000009;





int main() {

	int a, b, t;
	cin >> a >> b >> t;
	cout << (t / a)*b << endl;


	return 0;
}





Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        HashMap<Integer, List<Task>> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int A = scan.nextInt();
            long B = scan.nextLong();
            Task t = new Task();
            t.DEAD = M - A;
            t.A = A;
            t.B = B;
            if (!map.containsKey(t.DEAD)) {
                map.put(t.DEAD, new ArrayList<>());
            }
            map.get(t.DEAD).add(t);
        }
        long answer = 0;
        PriorityQueue<Task> queue = new PriorityQueue<>(new TaskComparator());
        for (int i = M - 1; 0 <= i; i--) {
            if (map.containsKey(i)) {
                List<Task> list = map.get(i);
                for (Task t : list) {
                    queue.add(t);
                }
            }
            if (queue.isEmpty()) {
                continue;
            }
            Task t = queue.poll();
            answer += t.B;
        }
        System.out.println(answer);
    }
    class Task {
        int DEAD;
        int A;
        long B;
    }
    class TaskComparator implements Comparator<Task> {
        @Override
        public int compare(Task o1, Task o2) {
            if (o1.B == o2.B) {
                return -Integer.compare(o1.DEAD, o2.DEAD);
            }
            return -Long.compare(o1.B, o2.B);
        }
    }
}


Measured memory_bytes: 103872
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, A, B, C, D = map(int, rl().split())
    S = input()
    
    if C < D:
        if S[A - 1:D].find('##') == -1:
            print('Yes')
        else:
            print('No')
    else:
        if S[B - 2:D + 1].find('...') == -1:
            print('No')
        else:
            print('Yes')


if __name__ == '__main__':
    solve()


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

ll max1(ll a,ll b)
{
	return((a>b)?a:b);
}

int main()
{
	int n,i;
	cin>>n;
	int a[n+1],b[n+1],c[n+1];
	for(i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	ll h[n+1][4],mx;
	h[1][1]=a[1];h[1][2]=b[1];h[1][3]=c[1];
	for(i=2;i<=n;i++)
	{
		h[i][1]=max1(h[i-1][2],h[i-1][3])+a[i];
		h[i][2]=max1(h[i-1][1],h[i-1][3])+b[i];
		h[i][3]=max1(h[i-1][1],h[i-1][2])+c[i];
	}
	mx=max1(h[n][1],h[n][2]);
	mx=max1(mx,h[n][3]);
	cout<<mx<<endl;
}

Measured memory_bytes: 4480
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <vector>

int main()
{
    int n, l, r;
    long long ans = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++)
    {
        std::cin >> l >> r;
        ans += r - l + 1;
    }

    std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll L, R, d;
    cin >> L >> R >> d;

    cout << R/d - (L-1)/d << endl;
}


Measured memory_bytes: 3656
Module Module1

    Sub Main()
        Dim N As Integer = Val(Console.ReadLine())
        Dim t As String() = Split(Console.ReadLine(), " ")
        Dim a(N - 1) As Integer
        For i As Integer = 0 To N - 1
            a(i) = Val(t(i)) - 1
        Next
        Dim count As Integer = 0
        For i As Integer = 0 To N - 1
            If a(a(i)) = i Then count += 1
        Next
        Console.WriteLine(count / 2)
        Stop
    End Sub

End Module


Measured memory_bytes: 16056
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;
	int x[n];
	for(int i=0;i<n;i++)	cin >> x[i];
	sort(x,x+n);
	int add=0;
	for(int i=n-1;i>n-k-1;i--)
	{
		add+=x[i];
	}
	cout << add;
	return 0;
}

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


int main(int argc,char** argv)
{

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

	long long cnt[a];
	long long tmp[b];
	long long oki,tisa;
	long long ans,lustans=4000000000;

	for(int i = 0; i < a-b+1; i++){
		tisa = c[i];
		oki = c[i+b-1];

		if(tisa < 0 && 0 < oki){
			ans = min(abs(tisa),abs(oki))*2 + max(abs(tisa),abs(oki));
		}
		else{
			ans = max(abs(tisa),abs(oki));
		}

		lustans = min(lustans,ans);

	}
	cout << lustans <<endl;

	return 0;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;

    input!{
        n: i32,
        k: i32,
    }
    let mut ans = 1;
    for _i in 0..n {
        ans = min(ans*2, ans+k);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=200005;
struct node{
	int p[N];ll c[N];
}b[65];
int a[N],las[N],fir[N],vis[N],stk[N],top,n,x;
ll K,now;

node mul(node a,node b){
	node res;
	rep(i,1,n){
		res.p[i]=b.p[a.p[i]];
		res.c[i]=b.c[a.p[i]]+a.c[i];
	}
	return res;
}

void doit(int L){
	rep(i,L,n)
		if(vis[a[i]]){
			while(stk[top]!=a[i])
				vis[stk[top--]]=0;
			vis[stk[top--]]=0;
		}
		else stk[++top]=a[i],vis[a[i]]=1;
	rep(i,1,top)printf("%d ",stk[i]);
}

int main(){
	scanf("%d%lld",&n,&K);
	rep(i,1,n){
		scanf("%d",&a[i]);
		if(!fir[a[i]])fir[a[i]]=i;
	}
	per(i,n,1){
		if(!las[a[i]]){
			b[0].p[i]=fir[a[i]]+1;
			b[0].c[i]=1;
		}
		else b[0].p[i]=las[a[i]]+1;
		if(b[0].p[i]==n+1){
			b[0].p[i]-=n;
			b[0].c[i]++;
		}
		las[a[i]]=i;
	}
	rep(i,1,60)b[i]=mul(b[i-1],b[i-1]);
	x=1,now=1;
	per(i,60,0)
		if(now+b[i].c[x]<=K){
			now+=b[i].c[x];
			x=b[i].p[x];
		}
	doit(x);
	return 0;
}

Measured memory_bytes: 156032
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,P0=0,ANS;
	vector<ll>V;
	cin>>N;
	rep(i,N){
		ll t;
		cin>>t;
		if(t%2==0)P0++;
	}
	N=int(pow(3,double(N)));
	ANS=N-int(pow(2,double(P0)));
	cout<<ANS<<endl;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
VL a;
VL now(13);

signed main() {
    cin >> N;
    REP(i, N) { now[IN() / 400]++; }
    ll ans = 0, rem = 0;
    REP(i, 8) if(now[i]) ans++;
    FOR(i, 8, 13) rem += now[i];
    cout << max(ans, 1LL) << " " << ans + rem << "\n";
}

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

int main() {
  vector<int> vec(3);
  rep(i,3)cin>>vec[i];
  sort(all(vec));
  int ans=vec[2]-vec[1];
  if((vec[1]-vec[0])%2==0)ans+=(vec[1]-vec[0])/2;
  else ans+=(vec[1]-vec[0]+1)/2+1;
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
from collections import deque
K = int(input())
A = deque([str(i) for i in range(1,10)])
cnt = 0
while cnt<K:
    a = A.popleft()
    cnt += 1
    if a[-1]=="0":
        a0 = a+"0"
        a1 = a+"1"
        A.append(a0)
        A.append(a1)
    elif a[-1]=="9":
        a0 = a+"8"
        a1 = a+"9"
        A.append(a0)
        A.append(a1)
    else:
        b = a[-1]
        a0 = a+str(int(b)-1)
        a1 = a+b
        a2 = a+str(int(b)+1)
        A.append(a0)
        A.append(a1)
        A.append(a2)
print(a)

Measured memory_bytes: 88684
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	xs <- sort <$> readInts
	print $ minimum $ do
		i <- [ 0 .. 100 ]
		return $ sum $ map ( ( ^ 2 ) . subtract i ) xs

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256