akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int hwmax = 10001;
int h,w;
vvint fi(hwmax,vint(hwmax,0));
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    queue<pair<int,int> > q1,q2;
    int cnt = 0;
    REP(i,h){
        string s;
        cin >> s;
        REP(j,w){
            if(s[j]=='#'){
                fi[i][j]=1;
                q1.push(make_pair(i,j));
                cnt++;
            }else{
                fi[i][j]=0;
            }
        }
    }
    int ans = 0;
    while(cnt<h*w){
        ans++;
        while(!q1.empty()){
            pair<int,int> p = q1.front();
            q1.pop();
            int i = p.fi;
            int j = p.se;
            if(j+1<w&&fi[i][j+1]==0){
                cnt++;
                fi[i][j+1]=1;
                q2.push(make_pair(i,j+1));
            }
            if(j-1>=0&&fi[i][j-1]==0){
                cnt++;
                fi[i][j-1]=1;
                q2.push(make_pair(i,j-1));
            }
            if(i+1<h&&fi[i+1][j]==0){
                cnt++;
                fi[i+1][j]=1;
                q2.push(make_pair(i+1,j));
            }
            if(i-1>=0&&fi[i-1][j]==0){
                cnt++;
                fi[i-1][j]=1;
                q2.push(make_pair(i-1,j));
            }
        }
        while(!q2.empty()){
            auto p = q2.front();
            q2.pop();
            q1.push(p);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 399504
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,M,sum=0;
    cin>>N>>M;
    ll A[M];
    for(ll i=0;i<M;i++){
        cin>>A[i];
        sum+=A[i];
    }
    if(N-sum>=0) cout<<N-sum<<endl;
    else cout<<"-1"<<endl;
}

Measured memory_bytes: 3672
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int can1 = 0;
        int can2 = 0;
        int can3 = 0;
        for (int i = 0; i < n; i++) {
            int val = sc.nextInt();
            if (val <= a) {
                can1++;
            } else if (val <= b) {
                can2++;
            } else {
                can3++;
            }
        }

        int min = Math.min(can1,Math.min(can2, can3));
        System.out.println(min);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#define N_MAX 100
using namespace std;

void insertionSort(int a[] , int n) {
    for (int i = 0; i < n; ++i) {
        int tmp = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > tmp ){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = tmp;

        for (int k = 0; k < n; ++k){
            if(k > 0) cout << " ";
            cout << a[k];
        }
        cout << endl;

    }
}

int main(){
    int n;
    cin >> n;
    int a[N_MAX];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    insertionSort(a, n);

    return 0;
}

Measured memory_bytes: 3040
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100005;
int n,q,i,cnt;
ll a[N],w,c[N],s[N];
void work(ll x)
{
	if(x<=a[1])
	{
		s[x]+=c[i];
		return;
	}
	int j=upper_bound(a+1,a+i,x)-a-1;
	c[j]+=x/a[j]*c[i];
	work(x%a[j]);
}
int main()
{
	scanf("%d%d",&n,&q);
	a[cnt=1]=n;
	for(i=1;i<=q;++i)
	{
		scanf("%lld",&w);
		while(cnt>=1&&a[cnt]>=w)
			--cnt;
		a[++cnt]=w;
	}
	c[cnt]=1;
	for(i=cnt;i>=1;--i)
		work(a[i]);
	for(i=n;i>=1;--i)
		s[i]+=s[i+1];
	for(i=1;i<=n;++i)
		printf("%lld\n",s[i]);
	return 0;
}


Measured memory_bytes: 3968
#include<stdio.h>

typedef long long ll;

int main(void){
    ll X=0;

    scanf("%lld", &X);

    ll happy=0;

    happy += (X/500)*1000;
    X = X%500;
    happy += (X/5)*5;

    printf("%lld", happy);
    
    return 0;
}

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

const int limit = 100100;
using edge = struct {
    int to;
    ll cost;
};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
    depth[v] = d;
    for (auto &e : tree[v]) {
        if (e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

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

    for (int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int q, k;
    cin >> q >> k;
    k--;

    dfs(k, -1, 0);
    while (q--) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << depth[x] + depth[y] << endl;
    }
}

Measured memory_bytes: 14336
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    V = list(map(int, readline().split()))
    max_value = 0
    for L in range(N+1):
        for R in range(N+1):
            if L+R>K:
                break
            if L+R>N:
                break
            get = V[:L]
            if R>0:
                get += V[-R:]
            get.sort()
            rest = K - (L+R)
            minus = sum((1 if x<0 else 0 for x in get))
            if minus>rest:
                value = sum(get[rest:])
            else:
                value = sum((x for x in get if x>0))
            if value>max_value:
                max_value=value
    print(max_value)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <cstring>

using namespace std;
typedef long long ll;


double dp[310][310][310];

double dfs(int i, int j, int k, int n)
{
  if( dp[i][j][k] >= 0 )
    return dp[i][j][k];

  double e = 0.;

  if( i>0 )
    e += i*dfs(i-1, j, k, n);
  if( j>0 )
    e += j*dfs(i+1, j-1, k, n);
  if( k>0 )
    e += k*dfs(i, j+1, k-1, n);
  
  e += n;
  e /= i+j+k;
  //  cout << i << " " << j << " " << k << " " << e << endl;
  dp[i][j][k] = e;
  return e;
}

int main()
{
  cout << setprecision(16);
  int N;
  cin >> N;
  vector<int> a(3);

  for( int i=0;i<N;i++ )
    {
      int n = 0;
      cin >> n;
      a[n-1]++;
    }

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

  cout << dfs(a[0], a[1], a[2], N) << endl;
}


Measured memory_bytes: 233088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll ans=0;
  map<pair<string,string>,ll> mp;
  for(int i=0;i<(1<<n);i++){
    int tmp=i,count=n;
    string v,w;
    while(count<2*n){
      if(tmp%2) v=v+s[count];
      else w=s[count]+w;
      count++;
      tmp/=2;
    }

    mp[make_pair(v,w)]++;
  }

  for(int i=0;i<(1<<n);i++){
    int tmp=i,count=0;
    string v,w;
    while(count<n){
      if(tmp%2) v=v+s[count];
      else w=s[count]+w;
      count++;
      tmp/=2;
    }

    ans+=mp[make_pair(w,v)];
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 84992
#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() {
  string s; cin>>s;
  map<char,int> m;
  string ans = "Yes";
  rep(i,s.size()) m[s[i]]++;
  if (m.count('E') == true && m.count('W') == false ||
       m.count('E') == false && m.count('W') == true) ans = "No";
  
  if (m.count('N') == true && m.count('S') == false ||
       m.count('N') == false && m.count('S') == true) ans = "No";
  cout << ans << endl;
  
  return 0;
}
 

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0)
		cout<<"Possible";
	else
		cout<<"Impossible";
	return 0;
}

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

int main(){
    int w,h,x,y,r;
    
    cin >> w >> h >> x >> y >> r;
    
    if(x >= r && y >= r && w - x >= r && h - y >= r){
        cout << "Yes" << endl;
        
    }
    else{
        cout << "No" <<endl;
        
    }
}


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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,e,0)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

typedef struct edge_def {
  int from;
  int to;
  int cost;

  edge_def(int _from, int _to, int _cost) {
    from = _from;
    to   = _to;
    cost = _cost;
  };
} edge;

const int INF = 1e9;
const int V = 1000;   //??????????????§??°
const int E = 100;  //???????????§??°
int nv, ne;        //?????????????????°
int usd[V];        //?¢??????????????????§????????¨
vector<edge> es[V];  //dijkstra??¨(es[i].from == i)

int dfs(int k) {
  int res = 1;
  usd[k] = 1;
  REP(i,(int)es[k].size()) {
    int nxt = es[k][i].to;
    if (!usd[nxt]) res += dfs(nxt);
  }
  return res;
}

int main() {
  scanf("%d%d ", &nv, &ne);
  REP(i,nv) es[i].clear();
  REP(i,ne) {
    int a, b;
    scanf("%d%d ", &a, &b);
    a--; b--;
    es[a].psb(edge(a,b,1));
    es[b].psb(edge(b,a,1));
  }

  memset(usd, 0, sizeof(usd));
  int prf=0, vlg=0;
  REP(i,nv) {
    if (!usd[i]) {
      if (dfs(i)>1)
        vlg++;
      else
        prf++;
    }
  }

  printf("%d\n", abs(prf-vlg));

  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////


int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    int n,d,x;cin>>n>>d>>x;
    int p[d][n];
    rep(i,0,d-1)rep(j,0,n-1)cin>>p[i][j];
    int del[d-1][n];
    rep(i,0,d-2)rep(j,0,n-1)del[i][j]=p[i+1][j]-p[i][j];
    
    int dp[d][100005][n];memset(dp,0,sizeof(dp));
    rep(k,0,d-2){
        rep(i,0,x){
            rep(j,0,n-1){
                if(j>=1)dp[k][i][j]=dp[k][i][j-1];
                if(i-p[k][j]>=0)dp[k][i][j]=max(dp[k][i][j],dp[k][i-p[k][j]][j]+del[k][j]);
            }
        }
        int maxpro=dp[k][0][n-1];
        rep(i,1,x)maxpro=max(maxpro,dp[k][i][n-1]);
        x+=maxpro;
    }
    cout<<x<<endl;
    
    return 0;
}


Measured memory_bytes: 42268
N = int(input())
B = list(map(int,input().split()))
TF = [False]*N
L = []
s = 0
lenstr = N-1
for i in range(N):
  cnt = 0
  tr = 0
  for j in range(N-1,-1,-1):
    if TF[j] == False:
      if lenstr-cnt-tr+i <= N-1:
        if B[lenstr-cnt-tr+i] == lenstr-cnt+1:
          TF[lenstr-cnt-tr+i] = True
          L.append(lenstr-cnt+1)
          lenstr -= 1
          break
        else:
          cnt += 1
      else:
          print(-1)
          exit()
    else:
      tr += 1
if len(L) == N:
  for i in range(N):
    print(L[N-i-1])
else:
  print(-1)

Measured memory_bytes: 3064
n, m, x = map(int, input().split())
# 長さNの配列を作成し、すべての要素に対して初期値を0に設定する。
tollList = [0] * (n + 1)
a = list(map(int, input().split()))
# 料金所がある場所の要素を0→1に変更
for num in a:
    tollList[num] = 1
ans = min(sum(tollList[0:x+1]), sum(tollList[x:]))
# この指定方法でもいける。
# ans = min(sum(tollList[0:x + 1]), sum(tollList[-1:x - 1:-1]))
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <cstdio>
using namespace std;
int main(){
	int a,b,c,tyou=0,hisi=0;
	while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
		if(a*a+b*b==c*c && a!=b) tyou++;
		else if(a==b) hisi++;
	}
	cout<<tyou<<endl<<hisi<<endl;
	return 0;
}

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

int K, A, B;
bool valid;

int main () {
    cin >> K;
    cin >> A >> B;
    for(int i=A; i<=B; i++) {
        if (i%K == 0)
            valid = true;
    }
    if (valid) cout << "OK" << endl;
    else cout << "NG" << endl;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		
		if(A+B==0) {
			System.out.println(0);
		} else {
			long it = N/(A+B);
			System.out.println(it*A+Math.min(A, N%(A+B)));
		}

		sc.close();
	}
}


Measured memory_bytes: 24788
#include <stdio.h>
#include <string.h>
 
char lowerCaseChar(char ch)
{
    char ret;
    if (ch >= 0x41 && ch <= 0x5a) {
        ret = ch + 0x20;
    }
    else {
        ret = ch;
    }
    return ret;
}
 
void lowerCase(char *str)
{
    int i;
    for (i = 0; str[i] != '\0'; i++) {
        str[i] = lowerCaseChar(str[i]);
    }
}
 
int main(int argc, char *argv[])
{
    char word[1001], search_word[11];
    int i, cnt = 0;
 
    memset(word, '\0', sizeof(word));
    memset(search_word, '\0', sizeof(search_word));
 
    scanf("%s", search_word);
 
    lowerCase(search_word);
 
    while (scanf("%s", word) != EOF) {
        if (strcmp(word, "END_OF_TEXT") == 0) {
            break;
        }
 
        lowerCase(word);
 
        if (strcmp(word, search_word) == 0) {
            cnt++;
        }
    }
 
    printf("%d\n", cnt);
 
 
    return 0;
}

Measured memory_bytes: 548
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2730
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n;
	string s;
	vector<pair<int,int>> line;
	int a1, b1, a2, b2, ans = 0;
	cin>>n>>s;
	
	a1 = n, b1 = n, a2 = -1, b2 = -1;
	
	line.push_back(make_pair(0,0));
	
	for(int i = 0, a = 0, b = 0, c = 0; i < n; i++){
		if(s[i] == '>' && a1 == n) a1 = i;
		if(s[i] == '<' && b1 == n) b1 = i;
		if(s[i] == '>') a2 = i;
		if(s[i] == '<') b2 = i;
	}
	
	ans = max(max(a2 - a1 + 1, b2 - b1 + 1), max(1ll, b2 - a1 + 1));
	
	cout<<ans<<endl;
	
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a;
    ll sum = 0;
    rep(i,n) {
        int x;
        cin >> x;
        sum += x;
        a.push_back(sum);
    }
    ll ans = 0;
    map<ll,ll> mp;
    rep(i,a.size()){
        mp[a[i]]++;
    }
    for(auto x : mp){
        if(x.first==0) {
            ans += x.second;
        }
            ans += (x.second*(x.second-1)/2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17056
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define rep(i,x) for(int i=0;i<x;i++)
int NN,k;
int ran[600005];
int tmp[600005];
int sa[600005];
bool compare_sa(int i,int j)
{
	if(ran[i] != ran[j]) return ran[i] < ran[j];
	else
	{
		int ri = i+k<=NN ? ran[i+k]: -1;
		int rj = j+k<=NN ? ran[j+k]: -1;
		
		return ri < rj;
	}
}

void construct_sa(string S)
{
	NN = S.size();
	for(int i=0;i<=NN;i++)
	{
		sa[i] = i;
		ran[i] = i<NN?S[i]:-1;
	}
	
	for(k=1;k<=NN;k*=2)
	{
		sort(sa,sa+NN+1,compare_sa);
		
		tmp[sa[0]] = 0;
		for(int i=1;i<=NN;i++)
		{
			tmp[sa[i]] = tmp[sa[i-1]] + compare_sa(sa[i-1],sa[i]);
		}
		for(int i=0;i<=NN;i++)
		{
			ran[i] = tmp[i];
		}
	}
}
int lcp[600005];
void construct_lcp(string S)
{
	int n = S.size();
	for(int i=0;i<=n;i++) ran[sa[i]] = i;
	
	int h = 0;
	lcp[0] = 0;
	
	for(int i=0;i<n;i++)
	{
		int j = sa[ran[i]-1];
		
		if(h) h--;
		for(;j+h<n && i+h<n;h++)
		{
			if(S[j+h] != S[i+h]) break;
		}
		lcp[ran[i]-1] = h;
	}
}

int seg[(1<<21)+5];
void update(int k,int a){
	k+=(1<<20)-1; seg[k] = a;
	while(k>0){
		k=(k-1)/2;
		seg[k]=min(seg[k*2+1],seg[k*2+2]);
	}
}
int query(int a,int b,int k,int l,int r){
	if(r<a || b<l) return INF;
	if(a<=l && r<=b) return seg[k];
	else{
		int vl=query(a,b,k*2+1,l,(l+r)/2);
		int vr=query(a,b,k*2+2,(l+r)/2+1,r);
		return min(vl,vr);
	}
}

string s,t;
int n,b;
int main(){
	cin >> s >> t;
	n = s.size(); b = s.size()+1;
	s += "$"; s += t;
	construct_sa(s);
	construct_lcp(s);
	for(int i=0;i<s.size();i++){
		update(i,lcp[i]);
	}
	int ret = 0;
	for(int i=0;i<n;i++){
		if(i+t.size() > n) break;
		int P = ran[i], Q = ran[b];
		int L = query(min(P,Q),max(P,Q)-1,0,0,(1<<20)-1);
		if(L == t.size()){
			continue;
		}
		if(L == t.size()-1){
			ret++; continue;
		}
		P = ran[i+L+1],Q = ran[b+L+1];
		int L2 = query(min(P,Q),max(P,Q)-1,0,0,(1<<20)-1);
		ret += (L+L2 == t.size()-1);
	}
	cout << ret << endl;
}

Measured memory_bytes: 14880
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    string s;
    int n;
    int count=0;
    cin>>n;
    cin>>s;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='A')
        {
            if(i<=s.size()-3)
            {
                if(s[i+1]=='B' && s[i+2]=='C')
                {
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(){
  int num;
  std::cin >> num;
  std::vector<int> a;
  for(int i=0;i<num;++i){
    int n;
    std::cin >> n;
    a.push_back(n);
  }
  int count = 0;
  while(1){
  for(auto& c : a){
    if(c % 2){
     std::cout << count << std::endl;
     return 0;
    }
    c /= 2;
  }
    count++;
  }
}

Measured memory_bytes: 256
import Data.List(sort, (\\))
import Data.Functor((<$>))
import Control.Applicative((<*>))

data Mark = S | H | C | D deriving (Show, Eq, Ord, Enum)
type Card = (Mark, Int)

main = do
    getLine
    cs <- getContents
    let inputs = sort $ map (convCard . words) (lines cs)
    let allpair = sort $ makeCard <$> "SHCD" <*> [1..13]
    mapM_ putStrLn $ map (\(x,y) -> show x ++ " " ++ show y) (allpair \\ inputs)

convCard :: [String] -> Card
convCard (x:y:_) = makeCard (head x) (read y)

makeCard :: Char -> Int -> Card
makeCard m i
    | m == 'S' = (S, i)
    | m == 'H' = (H, i)
    | m == 'C' = (C, i)
    | m == 'D' = (D, i)


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> S;
  S+='0';T="";
  rep(i,1,N+1)if(S[i-1]!=S[i])T+=S[i-1];
  Out(T.size());
}

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


template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int q;
  cin>>q;

  auto f=[&](int a,int b){return a|b;};
  SegmentTree<int> seg(f,0);
  seg.build(vector<int>(n,0));
  for(int i=0;i<n;i++)
    seg.set_val(i,1<<(s[i]-'a'));

  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1){
      int p;
      char c;
      cin>>p>>c;
      p--;
      seg.set_val(p,1<<(c-'a'));
    }
    if(t==2){
      int l,r;
      cin>>l>>r;
      l--;
      cout<<__builtin_popcount(seg.query(l,r))<<"\n";
    }
  }
  cout<<flush;
  return 0;
}


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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int r = 0; r*R <= N; r++) {
    for (int g = 0; g*G <= N - r*R; g++) {
      int x = N - r*R - g*G;
      if (x%B == 0) {
        int b = x/B;
        if (r*R + g*G + b*B == N) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int M,N; cin >> N >> M;
    vector<vector<char>> A(N),B(M);
    rep(i,N){
        rep(j,N){
            char x; cin >> x;
            A[i].push_back(x);
        }
    }
    rep(i,M){
        rep(j,M){
           char x; cin>>x;
           B[i].push_back(x);
        }
    }

    bool ans=false;
    for(int i=0; i<=N-M; i++){
        for(int j=0; j<=N-M; j++){
            bool flg=true;
            // 一致チェックループ
            for(int k=0; k<M; k++){
                for(int l=0; l<M; l++){
                    if(A[i+k][j+l] != B[k][l]){
                        flg = false;
                    }

                }
            }
            if(flg) ans=true;
        }
    }

    // rep(i,N){
    //     rep(j,N){
    //         cerr << A[i][j];
    //     }
    //     cerr << endl;
    // }
    // cerr << "-------------" << endl;
    // rep(i,M){
    //     rep(j,M){
    //        cerr << B[i][j];
    //     }
    //     cerr << endl;
    // }


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


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

int main() {
	string s,t ;
	cin >> s >> t;
	int n = sz(s), m = sz(t);
	vector<vector<int>> is(26);
	rep(i,n) is[s[i] - 'a'].push_back(i);
	rep(i,n) is[s[i] - 'a'].push_back(i+n);
	ll ans = 0;
	int p = 0;
	rep(i,m) {
		int c = t[i]-'a';
		if (sz(is[c]) == 0) {
			puts("-1");
			return 0;
		}
		p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
		if (p >= n) {
			p -= n;
			ans += n;
		}
	}
	ans += p;
	cout << ans << endl;
	return 0;

	/*
	string s, t;
	cin >> s;
	cin >> t;
	ll len_s = s.length(), len_t = t.length();
	ll ans = 0, idx = 0;
	
	while(1) {
		ll idx_plus = 0;
		rep(i,len_s) {
			ans++;
			if(t[idx] == s[i]) {
				idx++;
				idx_plus++;
				if (idx == len_t) {
					cout << ans << endl;
					return 0;
				}
			}
		}
		if (idx_plus == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
	*/
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, p[N], pos[N];
class SegTree {
private:
	int t[N << 2][2];
	void build(int l, int r, int x) {
		if (l == r) {
			t[x][0] = inf, t[x][1] = inf;
			t[x][l & 1] = p[l];
			return;
		}
		int m = (l + r) >> 1;
		build(l, m, x << 1), build(m + 1, r, x << 1 | 1);
		t[x][0] = min(t[x << 1][0], t[x << 1 | 1][0]);
		t[x][1] = min(t[x << 1][1], t[x << 1 | 1][1]);
	}
	int getMin(int l, int r, int s, int e, int x, int parity) {
		if (l > r || l > e || r < s) return inf;
		if (s <= l && r <= e) return t[x][parity];
		int m = (l + r) >> 1;
		return min(getMin(l, m, s, e, x << 1, parity), getMin(m + 1, r, s, e, x << 1 | 1, parity));
	}
public:
	int n;
	void init(int _n) { n = _n; build(0, n - 1, 1); }
	int getMin(int l, int r, int parity) { return getMin(0, n - 1, l, r, 1, parity); }
} st;
struct Segment {
	int l, r, mnValue;
	Segment(int l = -1, int r = -1, int mnValue = -1): l(l), r(r), mnValue(mnValue) {};
	bool operator<(const Segment &rhs) const { return mnValue < rhs.mnValue; }
};
set<Segment> s;
vector<int> ans;
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) {
		cin >> p[i];
		pos[p[i]] = i;
	}
	st.init(n);
	s.insert(Segment(0, n - 1, st.getMin(0, n - 2, 0)));
	while (!s.empty()) {
		Segment tmp = *s.begin(); s.erase(s.begin());
		int mnValue, mnPos;
//		cout << "tmp.l = " << tmp.l << " tmp.r = " << tmp.r << " mnValue = " << tmp.mnValue << "\n";
		mnValue = tmp.mnValue, mnPos = pos[mnValue];
		int nxtMn = st.getMin(mnPos + 1, tmp.r, tmp.r & 1), nxtMnPos = pos[nxtMn];
//		cout << "mnPos = " << mnPos << " nxtMnPos = " << nxtMnPos << "\n";
		ans.pb(mnValue), ans.pb(nxtMn);
		if (tmp.l < mnPos) s.insert(Segment(tmp.l, mnPos - 1, st.getMin(tmp.l, mnPos - 2, tmp.l & 1)));
		if (mnPos + 1 <= nxtMnPos - 1) 
			s.insert(Segment(mnPos + 1, nxtMnPos - 1, st.getMin(mnPos + 1, nxtMnPos - 2, (mnPos + 1) & 1)));
		if (nxtMnPos + 1 <= tmp.r) 
			s.insert(Segment(nxtMnPos + 1, tmp.r, st.getMin(nxtMnPos + 1, tmp.r - 1, (nxtMnPos + 1) & 1)));
	}
	fa (i, ans) cout << i << " ";
	return 0;
}

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

bool kansu( pair< string, long long int > p, pair< string, long long int > q ) {

  if ( p.first[1] < q.first[1] ) return true;

  return false;

}

void print( long long int n, vector< pair< string, long long int > > v ) {

  bool f = true;

  for ( long long int i = 0; i < n; i++ ) {

    if ( i != 0 ) {
      cout << " ";
      if ( v[i-1].first[1] == v[i].first[1] && v[i-1].second > v[i].second ) f = false;
    }
    cout << v[i].first;

  }

  cout << endl;

  if ( f == true ) {
    cout << "Stable" << endl;
  }else {
    cout << "Not stable" << endl;
  }

  return;

}

void BubbleSort( long long int n, vector< pair< string, long long int > > v ) {

  for ( long long int i = 0; i < n; i++ ) {

    for ( long long int j = n - 1; j > i; j-- ) {

      if ( kansu( v[j], v[j-1] ) == true ) swap( v[j], v[j-1] );

    }

  }

  print( n, v );

  return;

}

void SelectionSort( long long int n, vector< pair< string, long long int > > v ) {

  for ( long long int i = 0; i < n; i++ ) {

    long long int minj = i;

    for ( long long int j = i; j < n; j++ ) {

      if ( kansu( v[j], v[minj] ) == true ) minj = j;

    }

    swap( v[i], v[minj] );

  }

  print( n, v );

  return;

}

int main() {

  long long int n;
  cin >> n;

  vector< pair< string, long long int > > v;

  for ( long long int i = 0; i < n; i++ ) {

    string in;
    cin >> in;

    v.push_back( make_pair( in, i ) );

  }

  BubbleSort( n, v );
  SelectionSort( n, v );

  return 0;

}

Measured memory_bytes: 1216
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double ans = 0.0;
    if((2*x)/(a*a*b)>=1){
        double up = 2*(a*a*b -x);
        ans = atan(up/(a*a*a));
    }else{
        ans = atan((a*b*b)/(2*x));
    }
    ans *= 180;
    ans /= M_PI;
    cout << fixed << setprecision(8)<< ans << endl;
}

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

int main() {
  int n=0, a=0, b=0;
  cin >> n >> a;
  b = (n/1000)*1000;
  n = n-b;
  if (n <= a) {
    cout << "Yes" << endl;
  } else {
    if (n >= 500 && (n-500) <= a) {
      cout <<  "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n; cin >> n;
    vector<pair<pair<string, int>, int>> sp(n);
    rep(i, n) {
        cin >> sp[i].first.first >> sp[i].first.second;
        sp[i].first.second *= -1;
        sp[i].second = i+1;
    }
    sort(all(sp));
    rep(i, n) cout << sp[i].second << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int max = 0;
    @SuppressWarnings("resource")
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static int m = sc.nextInt();
    static int q = sc.nextInt();
    static int[] a = new int[q];
    static int[] b = new int[q];
    static int[] c = new int[q];
    static int[] d = new int[q];

    public static void main(String[] args) {
        for (int i = 0; i < q; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        List<Integer> list = new ArrayList<Integer>();
        dfs(list);
        System.out.println(max);
    }

    static void dfs(List<Integer> list) {
        if (list.size() == n) {
            int sum = 0;
            for (int i = 0; i < q; i++) {
                if (list.get(b[i]) - list.get(a[i]) == c[i]) {
                    sum += d[i];
                }
            }
            max = Math.max(max, sum);
            return;
        }
        for (int i = 0; i < 10; i++) {
            if ((list.size() == 0 || i >= list.get(list.size() - 1)) && i <= m - 1) {
                list.add(i);
                dfs(list);
                list.remove(list.size() - 1);
            }
        }
    }

}

Measured memory_bytes: 38772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &x : A) cin >> x;
    reverse(A.begin(), A.end());

    vector<int> LIS(N, INT_MAX);
    for (auto &x : A) {
        *upper_bound(LIS.begin(), LIS.end(), x) = x;
    }

    cout << lower_bound(LIS.begin(), LIS.end(), INT_MAX) - LIS.begin() << endl;

    return 0;
}

Measured memory_bytes: 1024
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for n in range(N):
    s = input()
    if s == 'AC':
        AC += 1
    if s == 'WA':
        WA += 1
    if s == 'TLE':
        TLE += 1
    if s == 'RE':
        RE += 1
print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))

Measured memory_bytes: 9212
package main

import (
	"fmt"
	"sort"
)

func main() {
	var q, h, s, d, n int
	fmt.Scan(&q, &h, &s, &d, &n)

	doublePrices := []int{8 * q, 4 * h, 2 * s, d}
	sort.Ints(doublePrices)

	var ans int
	if doublePrices[0] == d && n%2 == 1 {
		if n == 1 {
			ans = doublePrices[1] / 2
		} else {
			ans = (n-1)*d/2 + doublePrices[1]/2
		}
	} else {
		ans = n * doublePrices[0] / 2
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
#define fi first
#define se second
#define fo(name,start,end) for(int (name)=(start);(name)<(end);(name)++)
#define mkpr(fir,sec) make_pair((fir),(sec))
#define lo long
#define sz(a) int((a).size())
#define pb push_back
#define all(cont) (cont).begin(),(cont).end()
#define foit(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define mspre(cont,name) ((cont).find(name) != (cont).end())
#define cpre(cont,name) (find(all(cont),name) != (cont).end())
#define ist istringstream
#define ost ostringstream
#define vi  vector<int>
#define pii pair<int,int>
#define ret return
using namespace std;
lo lo int x,y;
main()
{
    ios::sync_with_stdio(0);
    cin >> x >> y;
    if(x==y || y==1 || x%y==0)
    {
        cout << -1;
        ret 0;
    }
    for(lo lo int i =2 ; x*i < 1e18+1 ; i++)
    {
        if((x*i)%y)
        {
            cout  << x*i;
            ret 0;
        }
    }
    cout << -1;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Array
main = do
  [n,m] <- map read . words <$> getLine
  a <- listArray ((1,1),(n,n)) . concat <$> replicateM n getLine
  b <- listArray ((1,1),(m,m)) . concat <$> replicateM m getLine
  putStrLn $ if or [
      and [b!(p,q) == a!(i+p-1,j+q-1) |
        p <- [1..m],
        q <- [1..m]] |
      i <- [1..1`max`(n-m)], 
      j <- [1..1`max`(n-m)]]
    then "Yes" 
    else "No"

Measured memory_bytes: 1020
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N;
    cin >> N;
    int V[N];
    int C[N];
    int X[N];
    for(int i=0;i<N;++i){
        cin >> V[i];
        X[i]=V[i];
    }
    
    for(int i=0;i<N;++i){
        cin >> C[i];
        X[i]-=C[i];
    }
    int num=0;
    
    for(int i=0;i<N;++i){
        if(X[i]>=0){
            num+=X[i];
        }
    }
    cout << num;
    }

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {

	long N; cin >> N;

	long dp[4][4][4][200] = {};//ACGT -> 0123 最後の三文字

	if (N == 1) cout << 1 << endl;
	if (N == 2) cout << 16 << endl;
	if (N == 3) cout << 61 << endl;
	if (N <= 3) return 0;

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 4; k++) {
				dp[i][j][k][3] = 1;
			}
		}
	}

	dp[0][1][2][3]--;
	dp[0][2][1][3]--;
	dp[2][0][1][3]--;

	for (int t = 4; t <= N; t++) {
		
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 4; k++) {
					for (int l = 0; l < 4; l++) {
						if (j == 0 && k == 1 && l == 2) continue;
						if (j == 0 && k == 2 && l == 1) continue;
						if (j == 2 && k == 0 && l == 1) continue;
						if (i == 0 && k == 2 && l == 1) continue;
						if (i == 0 && j == 2 && l == 1) continue;

						dp[j][k][l][t] += dp[i][j][k][t - 1];
						dp[j][k][l][t] %= mod;
				   }
				}
			}
		}
	}

	long res = 0;

	for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) for (int k = 0; k < 4; k++) { res += dp[i][j][k][N]; res %= mod; }

	cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
 	
  	int n;
  	string s;
  	cin >> n >> s;
  	int x = 0;
	rep(i,n) {if(s[i]=='A'){
      		if(s[i+1]=='B'){
            if(s[i+2]=='C'){x++;}
            }
    		}
            }
  cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

int main() {
    using namespace std;
    long n,a=0,b=0,c=0,d=0;
    char s[5],sa[]="AC",sb[]="WA",sc[]="TLE",sd[]="RE";
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>s;
        if (strcmp(s,sa)==0)
            a++;
        if (strcmp(s,sb)==0)
            b++;
        if (strcmp(s,sc)==0)
            c++;
        if (strcmp(s,sd)==0)
            d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
    return 0;
    }

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int n,k; cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(), h.end());
    vector<int> sa;
    rep(i,n-k+1) sa.push_back(h[i+k-1]-h[i]);
    sort(sa.begin(), sa.end());
    cout << sa[0] << endl;
    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define dbg cout<<"wtf"<<endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000007
#define MOD 1000000007 
//3
typedef long long ll;
typedef pair<int,int> pii;
priority_queue< int > pq;
priority_queue< int , vector<int> , greater<int> > rpq;
set<int>s;
set <int > :: iterator itr; 
vector<int> vec;
int n,m,inp,tc;
int dp[3007][3007];


string solve(string str1,string str2){
	int i = n;
	int j = m;
	string res;
	while(i>0 && j>0){
		if(str1[i-1] == str2[j-1]) {
			i--;
			j--;
			if(i>=0)
			res+=str1[i];
		}
		else {
			(dp[i-1][j] > dp[i][j-1]) ? i-- : j--;
		}
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
//	dbg;
	string str1;
	string str2;
//	dbg;
	cin>>str1;
	cin>>str2;
	n=str1.length();
	m=str2.length();
	for(int i=0 ;i<= n; i++){
		for(int j=0; j<=  m ; j++){
			if(i==0 || j==0) dp[i][j]=0;
			else{
				int val = max(dp[i-1][j], dp[i][j-1]);
				dp[i][j] = (str1[i-1] == str2[j-1]) ? max(dp[i-1][j-1]+1,val) : val;
			}
		}
	}
	cout<<solve(str1,str2)<<endl;
	
//	for(int i=0 ;i<= n; i++){
//		for(int j=0; j<=  m ; j++){
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
//	cout<<dp[n][m]<<endl;
	return 0 ;
}


Measured memory_bytes: 35584
A = input()
A = int(A)
B = input()
B = int(B)
C = input()
C = int(C)
D = input()
D = int(D)
if A <= B:
    if C <= D:
        print(A + C)
    else:
        print(A + D)
else:
    if C <= D:
        print(B + C)
    else:
        print(B + D)

Measured memory_bytes: 3060
#!/usr/bin/python3
# -*- coding: utf-8 -*-



H,W = map(int, input().split())
builds = []
for h in range(H):
  l = str(input())
  for w in range(W):
    if l[w] == "B":
      builds.append([h,w])

ans = 0
for i,hw1 in enumerate(builds):
  for hw2 in builds[i+1:]:
    ans = max(ans,abs(hw1[0]-hw2[0])+abs(hw1[1]-hw2[1]))
print(ans)


Measured memory_bytes: 5612
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");
    const [N, K] = input[0].split(" ").map(BigInt)
    const as = input[1].split(" ").map(n => Number(n));

    let loop = [0]
    let current = 0
    let loopStart = 0
    let visited = {}
    for (let i = 0; i < K; i++) {
        current = as[current] - 1
        if (visited[current]) {
            loopStart = loop.indexOf(current)
            loop = loop.slice(loopStart)
            break
        }
        visited[current] = true
        loop.push(current)
    }
    console.log(loop[(K - BigInt(loopStart)) % BigInt(loop.length)] + 1)

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  


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

int main() {
    int x, y;

    while (true) {
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        } else {
            if (x < y) {
                cout << x << " " << y << endl;
            } else {
                cout << y << " " << x << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include <cstdio>
#include<cctype>
#include <cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int M=300005,mod=1000000007;
int mp[8][2]={3,1,5,2,2,2,4,7,3,3,6,1,5,5,3,1},f[M][8],len;
char s[M];
void AC()
{
	int i,j;
	len=strlen(s);
	f[len][1]=f[len][2]=1;
	for(i=len-1;i>=0;i--)
		for(j=0;j<8;++j)
    	{
        	if(s[i]!='0')f[i][j]+=f[i+1][mp[j][1]];
        	if(s[i]!='1')f[i][j]+=f[i+1][mp[j][0]];
        	f[i][j]%=mod;
    	}
    printf("%d",f[0][0]);
}
int main()
{
	scanf("%s",s);
	AC();
	return 0;
} 


Measured memory_bytes: 13492
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections #-}
{-# OPTIONS_GHC -O2 #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import Data.Bits
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Complex
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Maybe
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- r'
    print $ solve 0 0 as

solve :: Int -> Int -> [Int] -> Int
solve h ac [] = ac
solve h ac (a:as)
    | a > h = solve a ac as
    | otherwise = solve h (ac + (h-a)) as




Measured memory_bytes: 10184
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

ll f(ll n)
{
    ll ret = 0;
    ll x = (n + 1) / 2;
    if (x & 1) ret = 1;
    if ((n & 1) == 0)
    {
        ret = ret ^ n;
    }
    return ret;
}

int main()
{
    ll A, B;
    cin >> A >> B;
    ll ans = A != B ? f(A - 1) ^ f(B) : A;
    cout << ans;
    return 0;
}



Measured memory_bytes: 256