akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
#include <set>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> w(n+1,0), b(n+1,0);
    for(int i = 1; i <= n; i++)
    {
        if (s[i-1] == '.') {
            w[i] = w[i-1] + 1;
            b[i] = b[i-1];
        }
        else
        {
            w[i] = w[i-1];
            b[i] = b[i-1] + 1;
        }
    }
    int ans = 1000000;
    for(int i = 1; i <= n; i++)
    {
        if (s[i-1] == '.') {
            ans = min(ans, w[n]-w[i]+b[i]);
        }
        else
        {
            ans  = min(ans, w[n]-w[i]+b[i]-1);
        }
    }
    OUT(ans);
}

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

using namespace std;

typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=2e3+5,LG=19,SM=600,inf=1e9+1;
ll mod=1e9+7;

ll n,k;
vll g[M];

ll qt,qh;
ll qu[M];
ll dis[M];

ll check()
{
    fill(dis,dis+n,inf);
    For(i,0,qt)
        dis[qu[i]]=0;
    qh=0;
    ll cnt=0;
    while (qt!=qh)
    {
        ll u=qu[qh++];
        for (ll v:g[u])
        {
            if (dis[v]>dis[u]+1)
            {
                dis[v]=dis[u]+1;
                if (dis[v]>k/2)
                    cnt++;
                qu[qt++]=v;
            }   
        }
    }
    return cnt;
}

ll yu[M],yv[M];

int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> k;
    For(i,1,n)
    {
        cin >> yu[i] >> yv[i];
        yu[i]--;yv[i]--;
        g[yu[i]].PB(yv[i]);
        g[yv[i]].PB(yu[i]);
    }
    ll res=n-k;
    if (k%2)
    {
        For(i,1,n)
        {
            qu[0]=yu[i];
            qu[1]=yv[i];
            qt=2;
            smin(res,check());
        }
    }    
    else
    {
        For(i,0,n)
        {
            qu[0]=i;
            qt=1;
            smin(res,check());
        }
    }           
    cout << res;      
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
    int m,f,r,i;
    
    for(i=1; i>0;i++){
        scanf("%d %d %d",&m,&f,&r);
        if(m == -1 && f == -1 && r == -1)
        {
            i = i*-1;
        }else{
            if(m == -1||f == -1)
            {
                printf("F\n");
            }else{
                if(m + f >= 80){
                    printf("A\n");
                }
                if(m + f >= 65 && m + f < 80){
                    printf("B\n");
                }
                if(m + f >= 50 && m + f < 65){
                    printf("C\n");
                }
                if(m + f >= 30 && m + f < 50){
                    if(r >= 50){
                        printf("C\n");
                    }else{
                        printf("D\n");
                    }
                }
                if(m+f < 30)
                {
                    printf("F\n");
                }
            }
        }
    }  
    return 0;
}

Measured memory_bytes: 584
import bisect
N, M = list(map(int,input().split()))
data = list(map(int,input().split()))
data.sort()
def cost(x):
    re = 0
    for i in range(N):
        idx = bisect.bisect_left(data,x - data[i])
        re += N - idx
    return re
#binery_search
lb = 0
ub = 2*max(data) + 1
while ub - lb > 1:
    mid = (ub+lb)//2
    if cost(mid) >= M:
        lb = mid
    else:
        ub = mid
ans = 0 - (cost(lb) - M)* lb
cum_data = [0]*(N+1)
for i in range(1,N+1):
    cum_data[i] = cum_data[i -1] + data[i-1]
data_idx = [0]*N
for i in range(N):
    idx = bisect.bisect_left(data,lb - data[i])
    data_idx[i] = idx
for i in range(N):
    ans += (N - data_idx[i]) * data[i]
    ans += cum_data[N] - cum_data[data_idx[i]]
print(ans)

Measured memory_bytes: 15952
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

int gcd(int a, int b)
{
    if (a < b)
        return gcd(b, a);

    int r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int gcd(int a, int b, int c)
{
    return gcd(gcd(a, b), c);
}

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

    i64 sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd(a, b, c);
            }
        }
    }
    cout << sum << endl;
}


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

int main() {
  int N,M,i,j,k,l,x,y;
  int ans=0;
  cin >> N >> M;
  int a[M];
  int c[M];
  for(i=0;i<M;i++) cin >> a[i] >> c[i];
  bool b[N+1][N+1];
  for(i=0;i<=N;i++) {
    for(j=0;j<=N;j++) {
	b[i][j]=false;
    }
  }
  for(i=0;i<M;i++) {
	b[a[i]][c[i]] = true;
	b[c[i]][a[i]] = true;
  }

  for(i=0;i<M;i++) {
	bool d[N+1][N+1];
	for(x=0;x<=N;x++) {
		for(y=0;y<=N;y++) {
			d[x][y]=b[x][y];
		}
	}
	d[a[i]][c[i]]=false;
	d[c[i]][a[i]]=false;
	for(j=1;j<=N;j++) {
		for(k=1;k<=N;k++)  {
			for(l=1;l<=N;l++) {
			  d[k][l] = (d[k][l]||(d[k][j]&&d[j][l]));
			  d[l][k] = d[k][l];
			 }
		}
	}
	if(d[a[i]][c[i]]==false) ans += 1;
	
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
#include "atcoder/segtree"

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;
using namespace atcoder;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;
ll op(ll a, ll b) {
    return max(a, b);
}
ll e() {
    return -1;
}

int v;
bool f(ll x){
    return v > x;
}

int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    segtree<ll, op, e> seg(a);
    while(q--){
        int t; cin >> t;
        if(t==1)
        {
            int X,V; cin >> X >> V;
            X--;
            seg.set(X,V);
        }
        else if(t == 2)
        {
            int l, r; cin >> l >> r;
            l--;
            cout << seg.prod(l,r) << endl;
        }
        else
        {
            ll X; cin >> X >> v;
            X--;
            cout << seg.max_right<f>(X) + 1<< endl;
        }
    }

}

Measured memory_bytes: 8976
import numpy as np
N, M, X, Y = map(int, input().split())
x_n = np.array([input().split()], dtype=int)
y_n = np.array([input().split()], dtype=int)
count=0
for Z in range(X+1, Y+1):
    if np.all(x_n<Z) & np.all(y_n>=Z):
        count+=1
if count>0:
    print('No War')
else:
    print('War')

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

int main(void){
  int n,c;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  rep(i,n)if(a[i]<0){a[i]*=-1;++c;}
  sort(a.begin(),a.end());
  if(c%2==1)a[0]*=-1;
  ll sum=0;
  rep(i,n)sum+=a[i];
  cout<<sum;
}

Measured memory_bytes: 640
abcdef = [int(input()) for i in range(6)]
abcd = abcdef[0:4]
ef = abcdef[4:6]

#print(abcd)
#print(ef)

def quicksort(list):
    if len(list) < 2:
        return list
    else:
        pivot = list[0]
        #pivotよりも小さい要素を全て含んだ部分配列
        less = [i for i in list[1:] if i <= pivot]
        #pivotよりも大きい要素を含んだ部分配列
        greater = [i for i in list[1:] if i > pivot]
        return quicksort(greater) + [pivot] + quicksort(less)

s_abcd = quicksort(abcd)
s_ef = quicksort(ef)

#print(s_abcd)
#print(s_ef)

sum = 0
for i in s_abcd[0:3]:
    sum = sum + i

best = sum + s_ef[0]
print(best)


Measured memory_bytes: 5600
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		int c = a + b;
		
		if (c >= 10) {
			System.out.println("error");
		} else {
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

int main() {
	int n;
	int jpy = 0;
	double btc = 0;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		double x;
		string u;
		cin >> x;
		cin >> u;
		
		if(u == "JPY") {
			jpy += x;
		} else {
			btc += x;
		}
	}
	printf("%.12f\n", jpy + btc * 380000);
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.append(0)
total=0
for i in range(N+1):
    total+=abs(A[i]-A[i+1])

for i in range(1,N+1):
    print(total-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))

Measured memory_bytes: 13920
#include <stdio.h>
#include <stdbool.h>
   
int lpyrJudge(int x, int y);
   
int main(void)
{
    int sta, fin;
    int judgecount = 0;
    while (true) {
        scanf("%d %d", &sta, &fin);
        if (sta == 0 && fin == 0) {
            break;
        } else {
            if (judgecount != 0) {
                printf("\n");
            }
            lpyrJudge(sta, fin);
        }
        judgecount++;
    }
    return 0;
}
   
int lpyrJudge(int x, int y)
{
    int minmod4x;   //x??\?????????????°????4???????????°
    if (x % 4 == 0){
        minmod4x = x;
    } else {
        minmod4x = x - x % 4 + 4;
    }
    if (y - minmod4x < 0) {
        printf("NA\n");
    } else {
        for (int i = minmod4x; i <= y; i = i + 4) {
            if (i % 100 == 0) {
                if(i % 400 == 0) {
                    printf("%d\n", i);
                } else {    //??????????????????????????????
                }
            } else {
                printf("%d\n", i);
            }
        }
    }
    return 0;
} 

Measured memory_bytes: 1044
def dv(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
A = list(map(int,input().split()))
l=[]
cnt = 0
for i in set(dv(A[0])+dv(A[1])):
    cnt = 0
    for j in range(len(A)):
        if A[j]%i == 0:
            cnt += 1
    if cnt >= N-1:
        l.append(i)
print(max(l))

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);

int main() {
  cout << fixed << setprecision(20);
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  double RA = ((double) (H * 60 + M) / 2);
  double TA = RA * (M_PI / 180);
  double AX = A * sin(TA);
  double AY = A * cos(TA);
  double RB = M * 6;
  double TB = RB * (M_PI / 180); 
  double BX = B * sin(TB);
  double BY = B * cos(TB);
  cout << sqrt((AX-BX) * (AX-BX) + (AY-BY) * (AY-BY)) << endl;
}


Measured memory_bytes: 4100
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N; cin >> N;
  vector<int> P(N), Q(N), ids(N); cin >> P >> Q;
  for (int i = 1; i <= N; ++i) ids[i-1] = i;

  int a = -1, b = -1, i = 0;
  do {
    ++i;
    if (ids == P) a = i;
    if (ids == Q) b = i;
  } while (next_permutation(ids.begin(), ids.end()));
  cout << abs(a-b) << endl;
}


Measured memory_bytes: 256
n, we = map(int, input().split())

cf=[(0, 0)]*n

cf = sorted(tuple( int(x) for x in input().split()) for _ in range(n))

dp=[0]*(we+1)

best=0
cnt=1
lim=0

for w,c in cf:
    cnt=cnt+w
    lim=min(cnt, we-w)
    for j in range(lim, -1, -1):
        if dp[j+w]<(dp[j] + c) : dp[j+w]=dp[j] + c

print(max(dp))

Measured memory_bytes: 9784
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000




int main(){
	int N,M;
	cin>>N>>M;
	
	int safe_A = 0;
	int safe_B = 0;
	
	set<int> A,B;
	
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.insert(a);
	}
	
	for(int i=0;i<M;i++){
		int b;
		cin>>b;
		B.insert(b);
	}
	
	int ans = 1;
	
	for(int i=N*M;i>=1;i--){
		bool fa=A.count(i),fb=B.count(i);
		int ind = N*M-i;
		if(fa&&fb){
			safe_A++;
			safe_B++;
		}
		else if(fa){
			safe_A++;
			ans = mod(ans*safe_B);
		}
		else if(fb){
			safe_B ++;
			ans = mod(ans * safe_A);
		}
		else{
			ans = mod(ans * mod(safe_A*safe_B-ind));
		}
		
	}
	
	cout<<ans<<endl;
			
		
	
	return 0;
}


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

int main(){
    int a,b;
    cin>>a>>b;

    int digit=0;
    int num = b;
    while(num!=0){
        num /= 10;
        digit++;
    }

    // digit = to_string(num).length();

    int n=0;
    rep(i,digit){
        a *= 10;
    }
    n = a+b;

    // cout<<n<<endl;
    // cout<<sqrt(n)<<endl;

    if(floor(sqrt(n))==(sqrt(n))) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}


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

using namespace std;

typedef long long ll;
const int N = 1e3 + 5;
const ll oo = 1e18;
int n, f[N][N], p[N][N];

int bit(int x, int i) {
    return (x >> i) & 1;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; i++) 
        for(int j = 0; j < 10; j++) cin >> f[i][j];
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= 10; j++) cin >> p[i][j];

    ll res = -oo;
    for(int i = 1; i < (1 << 10); i++) {
        ll s = 0;
        for(int j = 1; j <= n; j++) {
            int cnt = 0;
            for(int k = 0; k < 10; k++) cnt += f[j][k] && bit(i, k);
            s += p[j][cnt];
        } 
        res = max(res, s);
    }

    cout << res;
}


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

int main(){
    string N;
    cin >> N;
    int si = N.size()-1;
    if(N[si]=='2'||N[si]=='4'||N[si]=='5'||N[si]=='7'||N[si]=='9') cout << "hon" << endl;
    else if(N[si]=='0'||N[si]=='1'||N[si]=='6'||N[si]=='8') cout << "pon" << endl;
    else cout << "bon" << endl;
    return 0;
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] NMX = Console.ReadLine().Split(' ');
            int N = int.Parse(NMX[0]);
            int M = int.Parse(NMX[1]);
            int X = int.Parse(NMX[2]);
            
            int[] Cs = new int[N];
            int[,] As = new int[N, M];

            for(int i = 0; i < N; i++) {
                String[] CandAs = Console.ReadLine().Split(' ');
                Cs[i] = int.Parse(CandAs[0]);
                for(int j = 0; j < M; j++) As[i, j] = int.Parse(CandAs[j + 1]);

            }
            
            var nums = Enumerable.Range(0, N).ToArray();
            int answer = -1;
            for(int k = 1; k <= N; k++){
                int[][] Is = Combination.Enumerate(nums, k, withRepetition:false).ToArray();
                foreach(int[] I in Is){
                    int tmpAnswer = -1;
                    int[] Ms = Enumerable.Repeat(0, M).ToArray();
                    for(int i = 0; i < I.Length; i++){
                        for(int j = 0; j < M; j++){
                            Ms[j] += As[I[i], j];
                        }
                    }
                    if(Ms.All(n => n >= X)){
                        tmpAnswer = 0;
                        for(int i = 0; i < I.Length; i++) tmpAnswer += Cs[I[i]];
                    }
                    if(tmpAnswer != -1) {
                        if(answer == -1) answer = tmpAnswer;
                        else if(answer != -1) answer = Math.Min(answer, tmpAnswer);
                    }
                }
            }

            Console.WriteLine(answer);
        }

        public static class Combination {
            public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) {
                if (k == 1) {
                    foreach (var item in items)
                        yield return new T[] { item };
                    yield break;
                }
                foreach (var item in items) {
                    var leftside = new T[] { item };

                    // item よりも前のものを除く （順列と組み合わせの違い)
                    // 重複を許さないので、unusedから item そのものも取り除く
                    var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

                    foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
                        yield return leftside.Concat(rightside).ToArray();
                    }
                }
            }
        }
    }
}


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

int N;

long long solve() {
  long long r = 0, a;
  cin >> a; if(a != 0) return -1;
  int prev = 0;
  for(int i = 1; i < N; ++i) {
    cin >> a;
    if(prev + 1 < a) return -1;
    if(prev + 1 > a) r += prev;
    prev = a;
  }
  r += prev;
  return r;
}

int main() {
  cin >> N;
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ull unsigned long long 
#define int long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define MAX 1e18
#define PI 3.14159265
const int mod = 1e9 + 7;
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
 
 
 
int power(int x, int y) 
{ 
   int res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  
 
        y = y>>1; 
 
        if (x<=100000000)
        x = (long long)(x*x);
 
        //cout<<x<<'\n'; 
    } 
    return res; 
} 
 
int gcd (int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

int ceiling(int a,int b){
  if(a%b!=0){
    return (a/b)+1;

  }
  else
    return (a/b);
}
 

 void solve()
 {
  int n;
  cin>>n;
  map<string,int>m;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    m[s]++;
  }

  
    cout<<"AC"<<" "<<"x"<<" "<<m["AC"]<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<m["WA"]<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<m["TLE"]<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<m["RE"]<<endl;
  

  return;
 }


 int32_t main()
 {
  int t;
  t=1;
  while(t--){
    solve();
  }
  return 0;
 }


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

int main() {
  int N = 0, K = 0, sum = 1;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    if((sum + K) < (sum * 2)){
      sum += K;
    }else{
      sum *= 2;
    }
  }
  
  cout << sum << endl;
  
   
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main(){

	int a, b ,c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
		
	return 0;
}

Measured memory_bytes: 256
$%=<>;$_=[glob]for@D=<>;for(2..2*(@s=(_,0,(-1e15)x$%))){$s[$$_[1]]+=$-=$s[$$_[0]]+$$_[2]-$s[$$_[1]]for@D;$_-$%or$s=$s[-2]}print$s<$s[-2]?inf:$s

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    for(int i=0;i<n;i++)
     {
           int t; cin >>t;
            if(t%2==0)cnt++;
      }
     int ans = pow(3,n) - pow(2,cnt);
 cout<<ans; return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int *A = new int[N];
  for (int i = 0; i < N; i++)
    cin >> A[i];

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

    int v = A[i];
    int j = i - 1;
    while ((j >= 0) && (A[j] > v)){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
  }
  for (int k = 0; k < N; k++){
    if (k) cout << " ";
    cout << A[k];
  }
  cout << endl;

  delete[] A;

  return 0;
}



Measured memory_bytes: 3120
#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 tlll=tuple<ll,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(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll 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 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;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S,class T>ostream&operator<<(ostream&os,map<S,T>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;};
template<class S>ostream&operator<<(ostream&os,set<S>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;};
template<class S>auto&operator<<(ostream&os,vector<S>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,r;
    cin>>n>>r;
    if(n>=10)puta(r);
    else puta(r+100*(10-n));
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    char card_taro[101], card_hanako[101];
    int score_taro, score_hanako;
    int i;
    int r;
    
    scanf("%d", &n);

    score_taro = score_hanako = 0;
    for (i = 0; i < n; i++){
        scanf("%s%s", card_taro, card_hanako);
        r = strcmp(card_taro, card_hanako);
        if (r > 0){
            score_taro += 3;
        }
        else if (r < 0){
            score_hanako += 3;
        }
        else {
            score_taro++;
            score_hanako++;
        }
    }
    printf("%d %d\n", score_taro, score_hanako);

    return (0);
}



Measured memory_bytes: 2036
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    while(true) {
        int N = readln.chomp.to!int;
        if (N == 0) break;

        int[][] ans = [[-1, -1]];
        readln.split.to!(int[]).each!((a) {
            if (a == ans.back.back+1) {
                ans.back.back++;
            } else {
                ans ~= [a, a];
            }
        });
        ans[1..$].map!(a => a.front==a.back ? a.front.to!string : a.front.to!string~"-"~a.back.to!string).reduce!((a, b) => a~" "~b).writeln;
    }
}

Measured memory_bytes: 2600
#include<iostream>
using namespace std;
main()
{
	long a,b,c,x,y;cin>>a>>b>>c>>x>>y;
	long ans=0;c*=2;
	ans=(x<y?x:y)*(a+b<c?a+b:c);
	x<y?(y-=x,x=0):(x-=y,y=0);
	ans+=x*(a<c?a:c);
	ans+=y*(b<c?b:c);
	cout<<ans<<endl;
}


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

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

int main() {
    int n, k; cin >> n >> k;
    int r,s,p; cin >> r >> s >> p;
    string t; cin >> t;

    string ans = "";
    rep(i, n) {
        if(i >= k) {
            char tmp;
            if(t[i] == 'r') tmp = 'p';
            else if(t[i] == 's') tmp = 'r';
            else tmp = 's';

            if(ans[i-k] == tmp) {
                ans += '_';
            } else {
                ans += tmp;
            }
        } else {
            if(t[i] == 'r') ans += 'p';
            else if(t[i] == 's') ans += 'r';
            else ans += 's';
        }
    }

    int count = 0;

    rep(i, n) {
        if(ans[i] == 'r') count += r;
        else if(ans[i] == 's') count += s;
        else if(ans[i] == 'p')  count += p;
    }

    cout << count << endl;


    return 0;
}



Measured memory_bytes: 640
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(n,r))

# r=input1()
# print(2*math.pi*r)

# n,m=input2()
# A=input_array()

# if n<sum(A):
# 	print(-1)
# else:
# 	print(n-sum(A))

n=input1()
A=input_array()
people={i:0 for i in range(1,n+1)}

for i in range(1,n):
	people[A[i-1]]+=1

for v in people.values():
	print(v)















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

int toInt(const string &s){
  stringstream ss;
  ss<<s;
  int a;
  ss>>a;
  return a;
}

int c(const string& s){
  vector<int> a;
  //cerr<<s<<endl;
  if(s[0]!='[')return toInt(s)/2+1;
  for(int i=0,b=0,begin=0;i<s.size();++i){
    if(s[i]=='['){
      if(b==0) begin=i;
      ++b;
    }else if(s[i]==']'){
      --b;
      if(b==0){
          int t=c(s.substr(begin+1, i-begin-1));
          a.push_back(t);
      }
    }
  }
  sort(a.begin(),a.end());
  int t=0;
  for(int i=0;i<a.size()/2+1;++i){
    t+=a[i];
  }
  return t;
}

int main(void){
  int n;cin>>n;
  while(n--){
    string s;cin>>s;
    cout<<c(s)<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int l[2005];
  for( int i = 0; i < n; ++i ) {
    cin >> l[i];
    
  }
  sort( l, l + n );
  
  int res = 0;
  for( int i = 0; i < n - 1; ++i ) {
    for( int j = i + 1; j < n; ++j ) {
      int tmp = l[i] + l[j];
      int *pos = lower_bound( l, l + n, tmp );
      res += max( 0, (int)(pos - (l + j) - 1) );
      
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
W = list(map(int, input().split()))

A = sum(W)
ans = [A]
for i in range(len(W)):
  ans.append(ans[i]- 2*W[i])
  if ans[i+1] <= 0:
    print(min(abs(ans[-1]),abs(ans[-2])))
    exit()

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    map<int,int> b;//mapはサイズを初期化しなくても代入後自動的に決まる説
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    for(int i=0;i<N;i++){
        b[A.at(i)]++;
    }
    //cout<<b.size()<<endl;
    vector<int> c(b.size());
    int j=0;
    for(auto itr=b.begin();itr!=b.end();itr++){
        c.at(j)=itr->second;
        j++;
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    int a=0;
    int l=c.size();
    while(l>K){
        a+=c.at(l-1);
        l--;
    }
    cout<<a<<endl;
    return 0;
} 
    
    /*set<int> st;
    for(int i=0;i<N;i++){
        st.insert(A.at(i));
    }
    for(auto itr=st.begin();itr!=st.end();itr++){
        cout<< *itr <<endl;
    }
    int c=0;
    while(K!=st.size()){
    st.erase(A.at(A.size()-1));
    c++;
    }
    cout << c <<endl;
}*/



Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<vector<int>> wsum(4 * k + 1, vector<int>(4 * k + 1)), bsum(4 * k + 1, vector<int>(4 * k + 1));
	int wcnt = 0, bcnt = 0;
	for(int i = 0; i < n; ++ i){
		int x, y;
		char c;
		cin >> x >> y >> c;
		if(c == 'W'){
			++ wsum[x % (2 * k) + 1][y % (2 * k) + 1];
			++ wsum[x % (2 * k) + 1][y % (2 * k) + 2 * k + 1];
			++ wsum[x % (2 * k) + 2 * k + 1][y % (2 * k) + 1];
			++ wsum[x % (2 * k) + 2 * k + 1][y % (2 * k) + 2 * k + 1];
			++ wcnt;
		}
		else{
			++ bsum[x % (2 * k) + 1][y % (2 * k) + 1];
			++ bsum[x % (2 * k) + 1][y % (2 * k) + 2 * k + 1];
			++ bsum[x % (2 * k) + 2 * k + 1][y % (2 * k) + 1];
			++ bsum[x % (2 * k) + 2 * k + 1][y % (2 * k) + 2 * k + 1];
			++ bcnt;
		}
	}
	for(int i = 1; i <= 4 * k; ++ i){
		for(int j = 1; j <= 4 * k; ++ j){
			wsum[i][j] += wsum[i - 1][j] + wsum[i][j - 1] - wsum[i - 1][j - 1];
			bsum[i][j] += bsum[i - 1][j] + bsum[i][j - 1] - bsum[i - 1][j - 1];
		}
	}
	auto cnt = [&](const vector<vector<int>> &sum, int x, int y, int xx, int yy){
		return sum[xx][yy] - sum[x][yy] - sum[xx][y] + sum[x][y];
	};
	int res = 0;
	for(int i = 0; i < 2 * k; ++ i){
		for(int j = 0; j < 2 * k; ++ j){
			ctmax(res, cnt(wsum, i, j, i + k, j + k) + cnt(wsum, i + k, j + k, i + 2 * k, j + 2 * k) + bcnt - cnt(bsum, i, j, i + k, j + k) - cnt(bsum, i + k, j + k, i + 2 * k, j + 2 * k));
		}
	}
	cout << res;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 125568
from itertools import accumulate

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 累積和
a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

ans = 0
j = M
for i in range(N + 1):
    # Aで既にKを超えていたらBから取れない
    if a[i] > K:
        break
    # 選択可能な最大のjを探す
    # 最大のjは前回のj以下
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 50744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   int n;
   cin>>n;
   ll a,b,x[n];
   cin>>a>>b;
   rep(i,n)cin>>x[i];
   ll ans=0;
   rep(i,n-1)ans+=min(b,a*(x[i+1]-x[i]));
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	In(char,x, y);
	puts(x == y ? "=" : x < y ? "<" : ">");
}

Measured memory_bytes: 256
program many_medians
  implicit none
  integer :: n, a(200000,2), i, h(2)
  real(8) :: m
  a = 0
  read(*,*) n
  read(*,*) a(1:n,1)
  do i = 1, n
    a(i,2) = i
  end do
  call merge_sort(n,a(1:n,1:2),1)
  h(1) = a(n/2,1)
  h(2) = a(n/2+1,1)
  m = 0.5d0*real(h(1)+h(2),8)
  call merge_sort(n,a(1:n,1:2),2)
  do i = 1, n
    if (real(a(i,1),8).lt.m) then
      write(*,'(i0)') h(2)
    else
      write(*,'(i0)') h(1)
    end if
  end do
  stop
contains
  subroutine merge_sort(n,c,idx)
    implicit none
    integer, intent(in)    :: n, idx
    integer, intent(inout) :: c(n,2)
    integer                :: number, length, i, ubnd
    number = n
    length = 1
    do while (number.gt.1)
      do i = 1, number/2
        ubnd = min(2*i*length,n)
        call merge(c(2*(i-1)*length+1:(2*i-1)*length,:),c((2*i-1)*length+1:ubnd,:),idx)
      end do
      length = 2*length
      number = (number+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merge(c1,c2,idx)
    implicit none
    integer, intent(inout) :: c1(:,:), c2(:,:)
    integer, intent(in)    :: idx
    integer                :: c(size(c1(:,1))+size(c2(:,1)),size(c1(1,:)))
    integer                :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(c1(:,1))
    n2 = size(c2(:,1))
    do while ((i1.le.n1).and.(i2.le.n2))
      if (c1(i1,idx).le.c2(i2,idx)) then
        c(i1+i2-1,:) = c1(i1,:)
        i1 = i1+1
      else
        c(i1+i2-1,:) = c2(i2,:)
        i2 = i2+1
      end if
    end do
    if (i1.le.n1) then
      c(i1+i2-1:n1+n2,:) = c1(i1:n1,:)
    else if (i2 .le. n2) then
      c(i1+i2-1:n1+n2,:) = c2(i2:n2,:)
    end if
    c1 = c(1:n1,:)
    c2 = c(n1+1:n1+n2,:)
    return
  end subroutine merge
end program many_medians

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int k, x;
	cin >> k >> x;
	for(int i=x-k+1; i<=x+k-1; i++) cout << i << " ";
	cout << endl;
	return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i=0; i<n; ++i) {
		int l;
		cin >> l;
		v.push_back(l);
	}
	sort(v.begin(), v.end(), greater<int>());
	cout << accumulate(v.begin(), v.begin()+k, 0) << endl;;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if(a<b){
      System.out.println("a < b");
    } else if(a>b) {
      System.out.println("a > b");
    } else {
      System.out.println("a == b");
    }

  }
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  string S;
  cin >> N >> S;

  vector<int> r, g, b;
  REP(i, N) {
    if (S.at(i) == 'R') {
      r.push_back(i);
    } else if (S.at(i) == 'G') {
      g.push_back(i);
    } else {
      b.push_back(i);
    }
  }

  ll ans = r.size() * g.size() * b.size();

  REP(i, N) {
    REPI(j, i + 1, N) {
      int k = j + (j - i);
      if (k >= N)
        break;

      if (S.at(i) != S.at(j) && S.at(i) != S.at(k) && S.at(j) != S.at(k)) {
        --ans;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3676
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string s;
  cin >> s;
  set<char> characters;
  for (char ch : s) {
    characters.insert(ch);
  }
  if (characters.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  int64_t result = INT64_MAX;
  for (const char target : characters) {
    string temp = s;
    int64_t count = 0;
    while (true) {
      bool dirty = false;
      ++count;
      string current;
      swap(current, temp);
      const int64_t L = static_cast<int64_t>(current.length());
      for (int64_t i = 0; i <= L - 2; ++i) {
        if (current[i] == target || current[i + 1] == target) {
          temp.push_back(target);
        } else {
          temp.push_back(current[i]);
          dirty = true;
        }
      }
      if (!dirty) {
        break;
      }
    }
    result = min(result, count);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;


ll N;

vector <ll> A;
vector <ll> ans;

bool F[1000001] = { false };

void output(vector<ll> L) {
	for (ll i : L) {
		cout << i << " ";

	}
	cout << endl;
}


int main() {
	cin >> N;

	A.reserve(N);

	for (ll i = 0; i < N; i++) {
		ll a;
		cin >> a;
		A.emplace_back(a);
		F[a] = true;
	}

	sort(A.begin(), A.end());


	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}

	if (A[0] == 1) {
		if (A[1] > 1)
			cout << 1 << endl;
		else
			cout << 0 << endl;
		return 0;
	}

	ll m = 0;
	while (m < N) {

		if (F[A[m]] == false){
			m++;
			continue;
		}	

		ll x = A[m];

		if (m < N-1) {
			if (A[m + 1] != x) {
				ans.push_back(x);
			}
			else {
				F[A[m]] = false;
			}
		}
		else {
			if (m == N - 1) {
				ans.push_back(x);
				m++;
				continue;
			}
		}

		for (ll i = A[m]*2; i <= A[N-1]; i+=x) {
			F[i] = false;
		}
		m++;
	}

	//output(ans);

	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 6604
S = input()
i = 0
C = 1000
F = 0
for s in S:
    if s == 'C':
        C = min(C, i)
    elif s == 'F':
        F = max(F, i)
    i += 1
if C < F:
    print('Yes')
else:
    print('No')


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

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; }
constexpr int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &a) { return (os << a.x); }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (auto &e : a) cin >> e;
  sort(all(a), greater<int>());
  float acc = accumulate(all(a), 0);

  if (static_cast<float>(a[m - 1]) >= acc / (4.0 * m))
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                int N = scan.nextInt();
                int K = scan.nextInt();
                int[] costs = new int[N];
                int[] cache = new int[N];
                for(int i = 0 ; i < N ; i++) {
                        costs[i] = scan.nextInt();
                        cache[i] = 2147483647;
                }
                cache[0] = 0;
                cache[1] = Math.abs(costs[1]-costs[0]);
                System.out.println(jump(costs, K, cache));
                return;
        }

        private static int jump(int[] costs, int k, int[] cache) {
                for(int i = 2 ; i < costs.length ; i++) {
                    for(int j = k ; j > 0 ; j--){
                        if(i-j >=0) {
                            cache[i] = Math.min(cache[i], cache[i-j]+(Math.abs(costs[i] - costs[i-j])));
                        }
                    }
                    //cache[i] = Math.min(cache[i-1]+Math.abs(costs[i-1]-costs[i]), cache[i-2]+Math.abs(costs[i-2]-costs[i]));
                }
                return cache[costs.length-1];
        }
}

Measured memory_bytes: 58156
import copy
import collections
import sys


def input():
    return sys.stdin.readline()[:-1]


def bfs(sx, sy):
    # sx,sy := スタートの座標
    # gx,gy := ゴールの座標
    que = collections.deque()
    que.append([sx, sy])
    d = [[inf]*W for _ in range(H)]
    d[sx][sy] = 0
    s = copy.copy(field)
    while (len(que) > 0):
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0 <= nx and nx < H and 0 <= ny and ny < W and s[nx][ny] != "#" and d[nx][ny] == inf):
                que.append([nx, ny])
                d[nx][ny] = d[p[0]][p[1]] + 1
    return d  # d[gx][gy]


inf = -1
H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]
d = [[inf]*W for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

cand = []
memo = []

for h1 in range(H):
    for w1 in range(W):
        if field[h1][w1] == '#':
            continue
        cand.append([h1, w1])
for c in cand:
    res = bfs(*c)
    memo.append(max(sum(res, [])))
print(max(memo))


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

int main() {
  int N, M;
  int p[16];
  int temp;
  
  std::vector<int> v;
  std::cin >> N >> M;
  for(int i = 0; i < N; ++i) {
    std::cin >> temp;
    if( temp == 1 ) {
      v.push_back(i);
    }
  }
  for(int i = 0; i < M; ++i) {
    std::cin >> p[i];
  }

  std::vector<int> tv;
  std::vector<int> f[2];
  for(int k = 0; k < 2; ++k) {
    std::vector<int> tv;
    for(int i = 0; i < M; ++i) {
      for(int j = 0; j < p[i]; ++j) {
        tv.push_back((i + k) % 2);
      }
    }
    for(int i = 0; i < N; ++i) {
      if( tv[i] == 1 ) {
        f[k].push_back(i);
      }
    }
  }
  
  int res = 1000000;
  for(int k = 0; k < 2; ++k) {
    if( f[k].size() == v.size() ) {
      int tres = 0;
      for(int i = 0; i < (int)f[k].size(); ++i) {
        tres += abs(f[k][i] - v[i]);
      }
      res = std::min(res, tres);
    }
  }

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

  

Measured memory_bytes: 1212
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    ll ret=1;
    vector<ll> A;
    REP(i,0,N){
        ll a=ii();
        if(a==0){
            oie(0);
            return 0;
        }
        A.push_back(a);
    }
    for(ll a:A){
        if(ret<=1000000000000000000/a){
            ret*=a;
        }else{
            oie(-1);
            return 0;
        }
    }
    oie(ret);
    return 0;
}

Measured memory_bytes: 4316