akhauriyash/Code-Regression huggingface dataset:
h, w, k = map(int, input().split())
c = []
for _ in range(h):
  c.append(list(input()))

#数えておいただけ。これは落書き
all = 0
for i in c:
  all += i.count("#")

ans = 0
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for hh in range(2 ** h):
  for ww in range(2 ** w):
    #ここで全盤面を再現するわよ
    cnt = 0
    #座標C(h,w)をひとつずつ判定して、countしていくわ
    for i in range(h):
      for j in range(w):
        #bit全探索結果の、1を赤白、0 を黒とするわね
        if (hh >> i) & 1 == 0 and (ww >> j) & 1 == 0:
          if c[i][j] == "#":
            cnt += 1
    if cnt == k:
      ans += 1
print(ans)

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

// {u}{int,long,llong}_{max,min}
#define inf         int_max/3
#define llinf       llong_max/3
#define mod         (1000000007ll)
#define moda(a, b)  a=((a)+(b))%mod
#define modp(a, b)  a=((a)*(b))%mod
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using ll  = long long;
using g   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string a, b;cin >> a >> b;
    string s = a+b;
    int n = stoi(s);
    string ans = "No";
    for(int i=1;i*i<=n;i++){
        if(i*i == n) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

int main(void) {
    int r;
    cin >> r;

    float pi = 3.14159265;

    float ans = 2 * (float) r * pi;
    // cout << 2 * r * pi << endl;
    printf("%f\n", ans);
    return 0;
}


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

int main(){
  int cnt;
  string N;
  cin >> N;
  for(int i; i<3; i++) {
    if (N.at(i) == '7') {}
      else{
      cnt++;
      }
  }
  if (cnt != 3) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	vector<int>v(n);
	REP(i,n){
		cin>>v[i];
	}
	LL res=0;
  	int h=0;
  	REP(i,n){
  		if(v[i]>=h){
  			res++;
  			h=v[i];
  		}
  	}
  	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
    string S, T;
    cin >> S;
    cin >> T;

    vector<vector<int>> s_idx(26);
    vector<vector<int>> t_idx(26);

    vector<int> s_p(26, -1);
    vector<int> t_p(26, -1);

    int i = 0;
    /*while(S[i] != '\0'){
        s_idx[S[i] - 'a'].push_back(i);
        t_idx[T[i] - 'a'].push_back(i);
        for(int j = 0; j < s_idx[S[i] - 'a'].size(); j++){
            if(s_idx[S[i] - 'a'][j] != t_idx[T[i] - 'a'][j]){
                cout << "No";
                return 0;
            }
        }
        i++;
    }*/

    while(S[i] != '\0'){
        if(s_p[S[i] - 'a'] >= 0){
            if(s_p[S[i] - 'a'] != T[i]){
                cout << "No";
                return 0;
            }           
        }
        if(t_p[T[i] - 'a'] >= 0){
            if(t_p[T[i] - 'a'] != S[i]){
                cout << "No";
                return 0;
            }
        }
        s_p[S[i] - 'a'] = T[i];
        t_p[T[i] - 'a'] = S[i]; 
        i++;
    }
    cout << "Yes";

}

Measured memory_bytes: 776
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
    unsigned int N;
    unsigned int A[200000];
    unsigned int i, counter = 0;

    scanf("%d", &N);
    for (i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
        counter++;
    }
    qsort(A, counter, sizeof(int), compare_int);
    for (i = 0; i < N; i++)
    {
        if (A[i + 1] != '\0' && A[i] == A[i + 1])
        {
            printf("NO");
            return (0);
        }
    }
    printf("YES");
    return (0);
}

Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys
import math
input = sys.stdin.readline
MOD = 10**9 + 7

ab = []
n, t = [int(item) for item in input().split()]
for i in range(n):
    a, b = [int(item) for item in input().split()]
    ab.append((a, b))
ab.sort()

dp = [[-1] * (t+1) for _ in range(n+1)]
dp[0][0] = 0
ans = 0
for i, (a, b) in enumerate(ab):
    for j in range(t-1, -1, -1):
        if dp[i][j] == -1:
            continue
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if a + j >= t:
            ans = max(ans, dp[i][j] + b)
            continue
        dp[i+1][j + a] = max(dp[i][j + a], dp[i][j] + b)
        ans = max(ans, dp[i+1][j + a])

print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N, 0);
  for (int i = 0; i < N; i++)
  {
      cin >> d[i];
  }
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
      ans++;
      while ((i + 1 < N) && (d[i] == d[i + 1]))
      {
          i++;
      }
      
  }

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


Measured memory_bytes: 256
def Bubble(A, N):
    f = 1
    c = 0
    while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
    return A, c

N = int(input())
A = list(map(int, input().split(' ')))
A, c = Bubble(A, N)
ans = ' '.join(map(str, A)) + '\n' + str(c)
print(ans)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll n;
ll ch[100010];
vector<vector<pair<ll,ll>>>a(100010);
void dep(ll now,ll p,ll c){
	for(ll i=0;i<a[now].size();i++){
		ll nex=a[now][i].first;
		if(ch[nex]!=-1){
			continue;
		}
		ll nexc=c;
		ll nexw=a[now][i].second;
		if(nexw%2){
			nexc=abs(c-1);
		}
		ch[nex]=nexc;
		dep(nex,now,nexc);
	}
}

int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n-1;i++){
		ll x,y,w;
		cin>>x>>y>>w;
		x--;y--;
		a[x].push_back(make_pair(y,w));
		a[y].push_back(make_pair(x,w));
	}
	for(ll i=0;i<n;i++){
		ch[i]=-1;
	}
	dep(0,-1,0);
	for(ll i=0;i<n;i++){
		cout << ch[i]<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 11008
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif

typedef std::pair<int, int> IntPair;


//static void ABC120D_DecayedBridges();
static void ABC116B_CollatzProblem();


#if 1
int main()
{
	//ABC120D_DecayedBridges();
	ABC116B_CollatzProblem();

	fflush(stdout);
	return 0;
}
#endif

static int ABC116B_fn(int n)
{
	if ((n % 2) == 0) {
		return (n / 2);
	}
	else {
		return ((3 * n) + 1);
	}
}
static void ABC116B_CollatzProblem()
{
	int a1, a2 = 0;
	scanf(" %d", &a1);

	std::set<int> answers;

	answers.insert(a1);
	int n = 1;
	while (1) {
		n++;
		a2 = ABC116B_fn(a1);
		if (answers.find(a2) != answers.end()) {
			break;
		}

		answers.insert(a2);
		a1 = a2;
	}
	printf("%d\n", n);
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int i = 1;
		while(true) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			}
			else {
				while(true) {
					if(x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
					if(x == 0) {
						break;
					}
				}
			}
			
			if(++i <= n) {
				continue;
			}
			else {
				break;
			}
		}
		System.out.println();
		
		
		
	}

}



Measured memory_bytes: 28768
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

class TREE{
public:
  int count;
  vector<int> next;
  TREE(){
    count=0;
  }
};

vector<TREE> t;

void addCount(int current, int before){
  for(int i=0;i<t[current].next.size();i++){
    if(t[current].next[i]==before)
      continue;
    else{
      t[t[current].next[i]].count+=t[current].count;
    }
    addCount(t[current].next[i],current);
  }
}

void countCheck(){
  cout<<t[0].count;
  for(int i=1;i<t.size();i++){
    cout<<" "<<t[i].count;
  }
  cout<<"\n";
}

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

  int N, Q, tmpi, tmpj, tmpp, tmpx;
  
  cin>>N>>Q;
  for(int i=0;i<N;i++){
    t.push_back(TREE());
  }
  for(int i=0;i<N-1;i++){
    cin>>tmpi>>tmpj;
    t[tmpi-1].next.push_back(tmpj-1);
    t[tmpj-1].next.push_back(tmpi-1);
  }

  for(int i=0;i<Q;i++){
    cin>>tmpp>>tmpx;
    t[tmpp-1].count+=tmpx;
  }
  
  addCount(0,-1);
  
  countCheck();
  
  return 0;
}

Measured memory_bytes: 25320
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
int main() {
	map<string, long long> k;

	int n, c = 0;
	long long ans = 0;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	for (int i = 0; i < n; i++){

		k[s[i]]++;
	

	}
	for (auto hoge = k.begin(); hoge != k.end(); hoge++){
		ans += (hoge->second*(hoge->second-1))/2;

	}
	
	cout << ans << endl;
	/*int a[2];
	map<string, int> mp;
	mp["abc"]++;
	mp["ab"] = 5;
	mp["abc"]++;
	cout << mp["abc"] << endl;
	cout << mp["ab"] << endl;
	for (auto it = mp.begin(); it != mp.end();++it){
		cout << it->second << endl;
	}*/
	return 0;
}



Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define MAX_V 10000
#define INF 1e9
using namespace std;

struct edge{int to, cap,cost,rev;};
int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return res;

    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int main(){
  int n,A[1001],B[1001];
  cin>>n;
  set<int> S;
  for(int i=0;i<n;i++){
    cin>>A[i]>>B[i];
    S.insert(A[i]),S.insert(B[i]);
  }
  vector<int> num;
  for(set<int>::iterator it=S.begin();it!=S.end();it++) num.push_back(*it);
  
  int s=3*n+num.size(),t=s+1;
  for(int i=0;i<n;i++){
    int a=lower_bound(num.begin(),num.end(),A[i])-num.begin();
    int b=lower_bound(num.begin(),num.end(),B[i])-num.begin();
    add_edge(s,i,1,0);
    add_edge(i,n+i*2,1,0);
    add_edge(i,n+i*2+1,1,0);
    add_edge(n+i*2,3*n+a,1,-B[i]);
    add_edge(n+i*2+1,3*n+b,1,-A[i]);
  }
  for(int i=0;i<num.size();i++)add_edge(3*n+i,t,1,0);



  V = 3*n+num.size()+2;
  int r,ans=0;
  while((r=min_cost_flow(s,t,1))<0)ans+=r;
  cout<<-ans<<endl;

  return 0;
}

Measured memory_bytes: 3904
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
  double w,h,x,y;
  cin>>w>>h>>x>>y;


  cout<<w*h/2<<" ";

  if(w/2==x&&h/2==y){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph= vector<vector<int>>;
const int Ndig= 10;

void solve(const Graph &weights, int g, vector<int> *dists){
  using path= pair<int, int>;

  Graph dp= weights;
  for(int k=0; k<Ndig; k++){
    for(int from=0; from<Ndig; from++){
      for(int to=0; to<Ndig; to++){
        dp.at(from).at(to)= min(dp.at(from).at(to), dp.at(from).at(k)+ dp.at(k).at(to));
      }
    }
  }

  for(int from=0; from<Ndig; from++){
    dists->at(from)= dp.at(from).at(g);
  }
}

int main(){
  int H,W,buf;
  cin >> H >> W;

  Graph weights(Ndig, vector<int>(Ndig));
  vector<int> freq(Ndig);
  for(int i=0; i<Ndig; i++){
    for(int j=0; j<Ndig; j++){
      cin >> weights.at(i).at(j);
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> buf;

      if(buf != -1){ freq.at(buf)++; }
    }
  }

  vector<int> dists(Ndig, INT_MAX);
  solve(weights, 1, &dists);

  int ans= 0;
  for(int i=0; i<Ndig; i++){
    ans+= freq.at(i)* dists.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

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

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


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

    vector<int> array(N);
    vector<int> A;

    rep(i,N-1)
    {
        int t;
        cin >> t;
        A.push_back(t);
    }

    for(auto i:A)
    {
        array[i-1]++;
    }

    for(auto i:array)
    {
        cout << i << endl;
    }


    return 0;
}


Measured memory_bytes: 5036
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define INF 1e9
using namespace std;

double d;
int n,b;
double p[11],h[11];

double C(int bt){
	double ang=0.0;
	bt++;
	double bx=(double)d/bt;
	for(int i=0;i<n;i++){
		double lx=fmod(p[i],(double)d/bt);
		double vx=sqrt((1.0/(2.0*h[i]))*(-lx*lx+lx*bx));
		double vy=bx/(2.0*vx);
		ang=max(ang,atan2(vy,vx));
	}
	ang=max(M_PI/4,ang);
	double v=sqrt(d/(2.0*sin(ang)*cos(ang)*bt));
	return v;
}

int main(void){
	scanf("%lf %d %d",&d,&n,&b);
	for(int i=0;i<n;i++){
		scanf("%lf %lf",&p[i],&h[i]);
	}
	double res=INF;
	for(int i=0;i<=b;i++){
		res=min(res,C(i));
	}
	printf("%.10f\n",res);
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<int> v(n);

    rep(i, n) cin >> v[i];

    vector<int> v2(n);
    rep(i, n) {
        v2[v[v[i]-1]-1] = v[i];
    }

    rep(i, n-1) {
        cout << v2[i] << " ";
    }
    cout << v2[n-1];

    return 0;
}


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

int main() {
  int N;
  char c;
  string temp_ans = "Three";
  
  
  cin >> N;
  
  for( int i =0; i< N; i++){
    cin >> c;
    if (c == 'Y'){
      temp_ans = "Four";
      break;
    }
  }
  
  cout << temp_ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::cout << 1000 * tools::ceil<i64>(N, 1000) - N << std::endl;
  return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int d= sc.nextInt();
		System.out.println(n%(2*d+1)==0?(n/(2*d+1)):(n/(2*d+1)+1));
	}
}


Measured memory_bytes: 23764
n = int(input())
s = input()
t = input()

M = [[0] * n for i in range(n)]

for i in range(n):
    M[i][0] = int(s[i] == t[0])

for i in range(1, n):
    for j in range(0, i+1):
        if s[i] == t[j]:
            M[i][j] = M[i-1][j-1] + 1
# print(M)
print(n*2 - max(M[-1]))

Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int mx = 0;
	int num = 1;
	for (int i = 1; i <= n; ++i) {
		int tmp = 0;
		int now = i;
		while (now % 2 == 0) now /= 2, tmp++;
		if (mx < tmp) {
			mx = tmp;
			num = i;
		}
	}
	printf("%d", num);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll t[100000];
int main() {
	int n; ll c, k;
	cin >> n >> c >> k;
	rep(i, n) {
		cin >> t[i];
	}
	sort(t, t + n);
	ll now = -1;
	int out = 0; int cnt = 1;
	rep(i, n) {
		if (cnt==c||now < t[i]) {
			out++; cnt = 1;
			now = t[i] + k;
		}
		else {
			cnt++;
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    h = list(map(int, input().split()))[::-1]
    ans = [0 for _ in range(n)]

    for i in range(1, n):
        if h[i] >= h[i - 1]:
            ans[i] += ans[i - 1] + 1

    print(max(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y;
int main(){
    scanf("%d",&n);
    for (int i=0;i<n;i++){
        scanf("%d%d%d",&t,&x,&y);
        if (x+y>t){
            printf ("No\n");
            return 0;
        }
        if ((x+y)%2==0&&t%2){
            printf("No\n");
            return 0;
        }
        if((x+y)%2&&t%2==0){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
using namespace std;


typedef long long       ll;
struct edge { ll to; ll cost; };
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

// マクロ
#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX 9223372036854775807
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}

// ***<ここから>****************************************************************

int main(void) {

	int H, W;
	cin >> H >> W;
	vvc s(H, vc(W));

	rep(i, H) {
		rep(j, W) {
			cin >> s[i][j];
		}
	}

	rep(i, H) {
		rep(j, W) {
			if (s[i][j] == '#') {
				bool ok = false;
				rep(k, 4) {
					if (j + dx[k] < 0 || j + dx[k] >= W || i + dy[k] < 0 || i + dy[k] >= H) continue;
					if (s[i + dy[k]][j + dx[k]] == '#') ok = true;
				}
				if (!ok) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//atcoder ABC 082 D
using namespace std; 
int dp[4001][16002];
int ax[8001];
int ay[8001];
int tx,ty;
void dfsx(int t,int n)
{
	if(dp[t][n+8000])return ;
	if(t<tx)
	{
		dfsx(t+1,n+ax[t]);
		dfsx(t+1,n-ax[t]);
	}
	dp[t][n+8000]=1;
}
void dfsy(int t,int n)
{
	if(dp[t][n+8000])return ;
	if(t<ty)
	{
		dfsy(t+1,n+ay[t]);
		dfsy(t+1,n-ay[t]);
	}
	dp[t][n+8000]=1;
}
int main()
{
	string s;
	int x,y;
	cin>>s>>x>>y;
	int q=1;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='F')
		{
			if(q) ax[tx]++;
			else ay[ty]++;
		}
		else
		{
			if(q) q=0,tx++;
			else q=1,ty++;
		}
	}
	if(s[s.length()-1]=='F')
	{
		if(q) tx++;
		else ty++;
	}
	dfsx(1,ax[0]);
	int x1=dp[tx][x+8000];
	memset(dp,0,sizeof(dp));
	dfsy(0,0);
	int y1=dp[ty][y+8000];
	if(x1&&y1)cout<<"Yes";
	else	cout<<"No";
	return 0;
}

Measured memory_bytes: 250496
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (n == k) {
            System.out.println(1);
        } else if (k == 2) {
            System.out.println(n - 1);
        } else {
            int a = n - k;
            int ans = (int) Math.ceil(a * 1.0 / (k - 1));
            System.out.println(ans + 1);
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  string S;
  cin >> S;
  char before = S[0];
  int ans = 0;
  for (int i = 1; i < S.length();)
  {
    if (before == S[i])
    {
      before = S[i] == '0' ? '1' : '0';
      ans++;
      i++;
    }
    else
    {
      before = S[i];
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
S=input()
S+="1"
A=[]
count1=0
count2=0
total=0
for i in range(600000):
    total+=i
    A.append(total)

total=0
for i in range(len(S)):
    if S[i]=="<":
        count1+=1
    if S[i]==">":
        count2+=1
    if S[i]==">" and S[i+1]=="<":
        total+=A[max(count1,count2)]
        if min(count1, count2) != 0:
            total+=A[min(count1,count2)-1]
        #print(count1, count2,total)
        count1=0
        count2=0

total+=A[max(count1,count2)]
if min(count1,count2)!=0:
    total+=A[min(count1,count2)-1]
#print(A)
#print(count1,count2)


print(total)


Measured memory_bytes: 67364
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    int x,y;cin>>x>>y;
    bool ans=0;
    rep(i,x+1){
        if(4*x-2*i==y){
ans=1;
        }
    }


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

Measured memory_bytes: 3632
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))

if k == 0:
	print(max(a))
	exit()

suki = 1000000000
kirai = 0
while suki-kirai>1:
	targ = (suki+kirai)//2
	cnt = 0
	mode = 1
	for i in range(n):
		cnt += -(-a[i]//targ)-1
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))

Measured memory_bytes: 93680
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cctype>
#include<iomanip>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define true false
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define pq priority_queue
#define rep(i,n) for (int i=0;i<n;++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 1e9+222
#define init(x) memset(x,0,sizeof(x))
ll n,a[200005],s[200005],ans=0;
set<ll> st;
int main()
{
	ios::sync_with_stdio(true);
    cin>>n;
	for (int i=1;i<=n;++i) cin>>a[i];
	for (int i=1;i<=n;++i) s[i]=s[i-1]+a[i];
	sort(s,s+n+1);
	ll cnt=1;
	for (int i=1;i<=n;++i){
		if (s[i]==s[i-1]) ++cnt;
		else{
			ans+=cnt*(cnt-1)/2;
			cnt=1;
		}
	}
	ans+=cnt*(cnt-1)/2;
	cout<<ans;
	return 0;
}

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

int main() {
    int n,m;cin>>n>>m;
    string a[n],b[m];
    for (int i=0;i<n;i++)
        cin>>a[i];
    for (int i=0;i<m;i++)
        cin>>b[i];
    for (int i=0;i<=n-m;i++)
        for (int j=0;j<=n-m;j++) {
            for (int k=0;k<m;k++)
                for (int l=0;l<m;l++)
                    if (a[i+k][j+l]!=b[k][l])
                        goto aaa;
            puts("Yes");
            return 0;
            aaa:;
        }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll n,c;cin>>n>>c;
  vll x(n),v(n),y1(n+1,0),y2(n+1,0),z1(n+1,0),z2(n+1,0),sum1(n+1,0),sum2(n+1,0);
  rep(i,0,n){
    cin>>x[i]>>v[i];
  }
  rep(i,0,n){
    sum1[i+1]=sum1[i]+v[i];
    y1[i+1]=max(y1[i],sum1[i+1]-x[i]);
    z1[i+1]=max(z1[i],sum1[i+1]-2*x[i]);
  }
  drep(i,n-1,0){
    sum2[i]=sum2[i+1]+v[i];
    y2[i]=max(y2[i+1],sum2[i]-(c-x[i]));
    z2[i]=max(z2[i+1],sum2[i]-2*(c-x[i]));
  }
  ll ans=0;
  //片方固定
  rep(i,0,n+1){
    ans=max(ans,max(y1[i]+z2[i],y2[i]+z1[i]));
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 6528
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var X = input[0].map(e => parseInt(e, 10))[0];
	var N = input[0].map(e => parseInt(e, 10))[1];
	var ans = 0;
  	if (N == 0){
      	ans = X;
    } else {
    	var vec_p = input[1].map(e => parseInt(e, 10));
	    var tmpDiff = X;
    	for (var i = 1; i <= 101; i++){
    		if (vec_p.indexOf(i) == -1){
    			if (Math.abs(i - X) < tmpDiff){
	              tmpDiff = Math.abs(i - X);
    				ans = i;
    			}
    		}
    	}
    }
    console.log(ans);
}   

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

struct Problem {
public:

	void Solve() {
		UL A, B; cin >> A >> B;
		cout << A * B << endl;
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
     int a;
      cin>>a;
      int b;
        b=a%10;
      if(b==2|| b==4|| b==5|| b==7|| b==9){
      cout<<"hon"<<endl;
      }
      else if(b==0|| b==1|| b==6|| b==8){
      cout<<"pon"<<endl;
      }
      else{
      cout<<"bon"<<endl;}
      return (0);
      
    }

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int a;
    while(scanf("%d",&n)!=EOF)
    {
        int sum1=0,sum2=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a);
            if(a%4==0)
            {
                sum1++;
            }
            else if(a%2==0)
            {
                sum2++;
            }
        }
        if(sum2)
        {
            n-=sum2-1;
        }
        if(sum1>=n/2)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

// ダブリング解法

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];
// to[i][j] = jから2^i乗個先

void	solve()
{
	int n; ll k;
	cin >> n >> k;

	vector<int> a(n);
	rep(i, n) {
		cin >> to[0][i];
		to[0][i]--;
	}
	rep(i, D - 1){
		rep(j, n) {
			to[i + 1][j] = to[i][to[i][j]];
		}
	}
	int v = 0;
	for (int i = D - 1; i >= 0; --i) {
		ll l = 1ll << i;
		if (l <= k) {
			v = to[i][v];
			k -= l;
		}
	}
	cout << v + 1 << endl;
}

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

	solve();
}


Measured memory_bytes: 50984
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		System.out.println("A"+s.charAt(8)+"C");
	}
}

Measured memory_bytes: 38540
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    string S;
    cin>>S;
    bool ans = true;
    for(int i=0;i<S.size();++i){
        if(i%2==0){
            if(S[i]=='L') ans = false;
        }
        else{
            if(S[i]=='R') ans = false;
        }
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
# x, y, z = list(map(int, input().split()))
lis = []
sum_ = 0
for i in range(1, N+1):
    if (i % 3 != 0) and (i % 5 != 0):
        sum_ += i
print(sum_)


Measured memory_bytes: 27116
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  cout<<n<<":";
  
  int a=n;
  for(int i=2;i*i<=a;i++){
    while(n%i==0){
      cout<<" "<<i;
      n/=i;
    }
  }
  if(n>1) cout<<" "<<n;
  cout<<endl;

  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
using namespace std; 
int main()
{
double a,b,c,d,e,f;
while(cin>>a>>b>>c>>d>>e>>f)
{
printf("%.3f %.3f\n", (b*f - c*e)/(b*d - a*e)+0.0001, (a*f - c*d)/(a*e - b*d)+0.0001);
}
return 0;
}

Measured memory_bytes: 1240
def main(input_alphabet):
    al_list = [chr(ord('a') + i ) for i in range(26)]
    for j,alphabet in enumerate(al_list):
        if alphabet == input_alphabet:
            return al_list[j+1]
    
if __name__ == "__main__":
    input_alphabet = input()
    print(main(input_alphabet))

Measured memory_bytes: 2940
N = int(input())
a = []
for i in range(N):
        x = int(input())
        a.append(x)
m = max(a)
n = a.index(max(a))
for i in range(N):
        if i == n:
                b = a[:n] + a[n+1:]
                print(max(b))
        else:
                print(m)

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


using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
bool isPrime[MAXN];
void sevie() {
    memset(isPrime, 1, sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for (ll i = 2; i * i <= MAXN; i++) {
        if (isPrime[i]) {
            for (ll j = i * 2; j <= MAXN; j += i) {
                isPrime[j] = 0;

            }
        }
    }
}
ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}
//__builtin_popcount ();
bool isPrim(int n) {
    if (n == 1 || n == 0)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}




int main() {
    FAST
string h;
    cin>>h;
    if(h[2]==h[3] && h[4]==h[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
int main()
{
  int N;
   cin >> N;
   vector<int>A(N,0);
   rep(i,N)cin >> A[i];
   int m=INF;
   int M=0;
   rep(i,N){
       m=min(A[i],m);
       M=max(A[i],M);
   }
   cout << M-m << endl;
}


Measured memory_bytes: 256
S=input()

T=S.replace("x","")
if T!=T[::-1]:
    print(-1)
    exit()

S="*"+S+"*"
U=S[::-1]

a,b=0,0
K=0
for _ in range(len(T)+2):
    old_a,old_b=a,b
    while S[a]=="x":
        a+=1

    while U[b]=="x":
        b+=1

    delta_a=a-old_a
    delta_b=b-old_b

    K+=max(delta_a,delta_b)-min(delta_a,delta_b)

    a+=1
    b+=1
    assert 1

print(K//2)

Measured memory_bytes: 73496
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        long int n;
        cin >> n;
        long int min=n*2-2;
        for(int i=1;i<=sqrt(n);++i){
            if(n%i==0 && min>i+n/i-2){
                min = i+n/i-2;
            }
        }
        cout << min << endl;
        return 0;
    }

Measured memory_bytes: 256
// Last Change: 04/08/2019 23:44:30.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

const ll INF = 1e5;

class Info {
public:
  ll num = 0;
  ll val = 0;

  bool operator<(const Info &another) const {
    return val < another.val;
  }

  bool operator>(const Info &another) const {
    return val > another.val;
  }
};

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; ++i) {
    cin >> v[i];
  }

  //奇数番目
  vector<Info> cnt1(INF + 5);
  for (ll i = 0; i < INF + 5; ++i) {
    cnt1[i].num = i;
  }
  for (ll i = 0; i < n; i += 2) {
    ++cnt1[v[i]].val;
  }
  sort(cnt1.begin(), cnt1.end(), greater<Info>());

  //偶数番目
  vector<Info> cnt2(INF + 5);
  for (ll i = 0; i < INF + 5; ++i) {
    cnt2[i].num = i;
  }
  for (ll i = 1; i < n; i += 2) {
    ++cnt2[v[i]].val;
  }
  sort(cnt2.begin(), cnt2.end(), greater<Info>());

  ll pos1, pos2, ans;
  pos1 = pos2 = 0;
  if (cnt1[0].num == cnt2[0].num) {
    ans = min(n - cnt1[0].val - cnt2[1].val, n - cnt1[1].val - cnt2[0].val);
  } else {
    ans = n - cnt1[0].val - cnt2[0].val;
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 4224
"use strict"

const main = arg => {
  arg = arg.trim().split("\n");
  const H = parseInt(arg[0].split(" ")[0]);
  const W = parseInt(arg[0].split(" ")[1]);
  
  const tiles = arg.slice(1, H + 1).map(n=>n.split(""));
  
  const dx = [1, 0, -1, 0];
  const dy = [0, 1, 0, -1];
  
  for(let i in tiles) {
      for(let j in tiles[i]) {
          let cnt = 0;
          
          for(let k=0; k<4; k++) {
              let nx = dx[k] + parseInt(j);
              let ny = dy[k] + parseInt(i);
              
              if(ny < 0 || ny > H - 1) continue;
              if(nx < 0 || nx > W - 1) continue;
             
              if(tiles[ny][nx] === ".") {
                  cnt++;
              }
          }
          
          if(tiles[i][j] === "#" && cnt === 4) {
              console.log("No");
              return;
          }
      }
   }
   
   console.log("Yes");
}

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


Measured memory_bytes: 9536
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
	int x, y;
	cin >> x >> y;
	for (int i = 0; i <= x; i++) {
		if (2 * i + 4 * (x - i) == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

ll binom[2005][2005];
const ll MOD = 1e9 + 7;

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

    for(int i = 0; i < 2005; i++)
        binom[i][0] = binom[i][i] = 1;
    for(int i = 1; i < 2005; i++)
        for(int j = 1; j < 2005; j++)
            binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1])%MOD;

    ll n, k;
    cin >> n >> k;
    for(ll i = 1; i <= k; i++) {
        cout << (binom[k - 1][i - 1] * binom[n - k + 1][i]) % MOD << '\n';
    }
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    string s1, s2, s3, s4;
    cin >> s1 >> s2;

    // 処理
    // 出力
    if (s1[1] != s2[1] || s1[0] != s2[2] || s1[2] != s2[0]) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
s=int(input())

counts = 0
ans = 1

for i in range(s + 1):
  k = i
  count = 0
  while(True):
    if i % 2 == 1 or i == 0:
      break

    i = i / 2
    count += 1
  
  if counts < count:
    counts = count
    ans = k

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 100005

using namespace std;

int main()
{
    char str[sz];
    string ss;

    scanf("%s",str);

    ll len=strlen(str);

    for(ll i=0;i<len;i++)
    {
        if(i%2==0)
            ss+=str[i];
    }

    cout<<ss<<endl;

    return (0);
}


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

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> mass(H,vector<char>(W,'.'));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c;
            cin >> c;
            if(mass.at(i).at(j) != c){
                mass.at(i).at(j) = c;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(mass.at(i).at(j) == '#'){
                break;
            }
            if(j==W-1){
                for(int k=0;k<W;k++){
                    mass.at(i).at(k) = '@';
                }
            }
        }
    }
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
            if(mass.at(i).at(j) == '#'){
                break;
            }
            if(i==H-1){
                for(int k=0;k<H;k++){
                    mass.at(k).at(j) = '@';
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        int count=0;
        for(int j=0;j<W;j++){
            if(mass.at(i).at(j) != '@'){
                cout << mass.at(i).at(j);
                count++;
            }
        }
        if(count){
            cout << endl;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main()
{
	int n;
	scanf("%d",&n);
	vector<vector<int>> can(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			scanf("%d",&can[i][j]);
		}
	}
	int mx=(1<<n);
	int dp[mx]={};
	dp[0]=1;
	for(int mask=0;mask<mx-1;mask++)
	{
		int a=__builtin_popcount(mask);
		for(int b=0;b<n;b++)
		{
			if(can[a][b] && !(mask & 1<<b))
			{
				int m2=mask^(1<<b);
				dp[m2]=(dp[m2]+dp[mask])%mod;
			}
		}
	}
	cout<<dp[mx-1];
}

Measured memory_bytes: 8448
n,k = map(int, input().split())
p = list(map(lambda z:int(z)-1, input().split()))
c = list(map(int, input().split()))

data = [[0 for i in range(n+1)] for j in range(n)]
loop = [10**10 for i in range(n)]
for i in range(n):
    j = i
    for t in range(1,n+1):
        j = p[j]
        data[i][t] += data[i][t-1] + c[j]
        if j == i:
            loop[i] = min(loop[i],t)

ans = -10**10
#print(data)
#print([data[i][loop[i]] for i in range(n)])

for i in range(n):
    for j in range(1,min(n,k)+1):
        if j > loop[i]:break
        if data[i][loop[i]] <= 0:
            ans = max(ans,data[i][j])
        else:
            ans = max(ans,data[i][loop[i]]*((k-j)//loop[i])+data[i][j])

print(ans)


Measured memory_bytes: 280612
#!/usr/bin/env python3
import collections

n = int(input())

# dp == [[0]*n for _ in range(75]


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


count = 0
div = {}
for i in range(2, n+1):
    c = collections.Counter(prime_factorize(i))
    for key, value in c.items():
        if key in div:
            div[key] += value
        else:
            div[key] = 1
# print(div)


def num(m):
    return len(list(filter(lambda x: x+1 >= m, div.values())))


# print(num(75))
print(num(75) + num(25)*(num(3)-1) + num(15) *
      (num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)//2)


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

int main () {
  long long a=100;
  double r=1.01;
  long long X;
  cin >> X;
  int n=0;
  while (a < X) {
    a = a * r;

    n++;
  }
  cout << n;
  return 0;
}


Measured memory_bytes: 3596
#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    A = N[0:9]
    N_number = N[9]
    b = N[10:]

    Ab_comm = set(A) & set(b)
    A_rep = [0 if i in Ab_comm else i for i in A]

    Ax=[]
    Ay=[]
    for i in range(0,3):
        Ax.append(A_rep[3*i] + A_rep[3*i + 1] + A_rep[3*i + 2])
        Ay.append(A_rep[i] + A_rep[i + 3] + A_rep[i + 6])
    An=[]
    An.append(A_rep[0] + A_rep[4] + A_rep[8])
    An.append(A_rep[2] + A_rep[4] + A_rep[6])
    if min(Ax + Ay + An) == 0:
        print("Yes")
    else:
        print("No")
        

main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,s,d;
    cin >>a>>s>>d;
    if((a<=d)&&(d<=s)){
        cout << "Yes" <<endl;
    }
    else if((s<=d)&&(d<=a)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }

    return 0;
}


Measured memory_bytes: 256