akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

	string str;

	cin >> str;

	LL maxmin = str.size();

	for(LL i = 0; i < str.size()-1; i++){
		if(str[i] != str[i+1]){
			maxmin = min(maxmin,max((LL)str.size()-i-1,i+1));
		}
	}

	cout << maxmin << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
    while( true ){
        int n;
        cin >> n;

        if (n == 0) break;

        int a[n];

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

        sort(a,a+n);

        for(int i=2;i<n-1;i++){
            a[1]+=a[i];
        }

        cout<<a[1]/(n-2)<<endl;

    }   
    return 0; 
}

Measured memory_bytes: 1176
#include<iostream>
using namespace std;
#define df 0
#define MAX 10000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)



int main(){
  int n; cin >>n;
  string s; cin >>s;
  char c=s[0];
  int ans=1;
  repa(i,1,s.size()){
    if(c!=s[i]){
      ans++;
      c=s[i];
    }
  }
  printf("%d",ans);
}

/// confirm df==0 ///


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#define SIZE 50

using namespace std;
typedef long long int ll;
typedef pair <string,string> P;

char str[SIZE];
map <P,int> mp;

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",&str);
	for(int S=0;S<1<<n;S++)
	{
		string A="",B="";
		for(int i=0;i<n;i++)
		{
			if(S>>i&1)
			{
				A+=str[i];
			}
		}
		for(int i=n-1;i>=0;i--)
		{
			if(!(S>>i&1))
			{
				B+=str[i];
			}
		}
		mp[P(A,B)]++;
	}
	ll ret=0;
	for(int S=0;S<1<<n;S++)
	{
		string A="",B="";
		for(int i=0;i<n;i++)
		{
			if(S>>i&1)
			{
				A+=str[n+i];
			}
		}
		for(int i=n-1;i>=0;i--)
		{
			if(!(S>>i&1))
			{
				B+=str[n+i];
			}
		}
		ret+=mp[P(B,A)];
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 91904
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

//unionfind tree
struct UnionFind {
  vector<int> par;
  vector<int> rnk;
  int n;
  UnionFind(int n):n(n){
    par.resize(n);rnk.resize(n);
    for(int i=0; i<n; i++){par[i] = i;rnk[i] = 0;}
  }
  int find(int x){
      if(par[x] == x) return x;
      else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
      x = find(x);y = find(y);
      if(x == y) return;
      if(rnk[x] < rnk[y])par[x] = y;
      else {
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
      }
      return;
  }
  bool isSame(int x, int y){return find(x) == find(y);}
};

// クラスカル法(最小全域木求めるやつ)
struct edge{ll u, v ; ll cost; };

bool comp(edge& e1, edge& e2){
  return e1.cost < e2.cost;
}

int main(){
    int V,E;
    cin>>V>>E;
    vector<edge> es(E);
    FOR(i,0,E){
        cin>>es[i].u>>es[i].v>>es[i].cost;
    }
    sort(es.begin(), es.end(), comp);
    UnionFind U(V);
    ll res = 0;
    FOR(i,0,E){
        edge e = es[i];
        if(!U.isSame(e.u, e.v)){
            U.unite(e.u, e.v);
            res += e.cost;
        }
    }
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 5212
package main

import (
    "fmt"
)

func main() {
    var n int
    var s string
    result := map[string]int{"AC":0, "WA":0, "TLE":0, "RE":0}
    fmt.Scan(&n)
    for i:=0; i<n; i++ {
        fmt.Scan(&s)
        result[s] += 1
    }
    fmt.Printf("AC x %d\n", result["AC"])
    fmt.Printf("WA x %d\n", result["WA"])
    fmt.Printf("TLE x %d\n", result["TLE"])
    fmt.Printf("RE x %d\n", result["RE"])
}


Measured memory_bytes: 6328
#include <iostream>
#include <algorithm>
#include<functional>
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#include<vector>
#include<cmath>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if ((a * b) % 2 == 0) {
		cout << "Even";
	}
	else {
		cout << "Odd";
	}
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
S=s2(n)

d={"M":0,"A":0,"R":0,"C":0,"H":0}
for s in S:
    if s[0] in "MARCH":
        d[s[0]]+=1

l=list(d.values())

ans=0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans+=l[i]*l[j]*l[k]
print(ans)

Measured memory_bytes: 9752
N, M = map(int, input().split(' '))
AC_dir = {}
WA_dir = {}
for i in range(M):
    p, S = input().split(' ')
    if S == 'AC' and p not in AC_dir:
        AC_dir[p] = 1
    elif S == 'WA' and p not in WA_dir and p not in AC_dir:
        WA_dir[p] = 1
    elif S == 'WA' and p in WA_dir and p not in AC_dir:
        WA_dir[p] += 1
print(sum(AC_dir.values()), sum([k for j, k in WA_dir.items() if j in AC_dir]), sep=' ')


Measured memory_bytes: 17116
#include <stdio.h>

int gcd(int a,int b);

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",gcd(a,b));
}

int gcd(int a,int b){
    int m,M;
    if(a<=b){
        m=a;
        M=b;
    }
    else{
        m=b;
        M=a;
    }
    if(m==0){
        return M;
    }
    else{
        return gcd(m,M%m);
    }
}



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

const int maxn = 4e5 + 10;

int s[maxn], t[maxn];
int a[maxn], b[maxn];
int fail[maxn];

int n, m;
void getfail()
{
    memset(fail, 0, sizeof(fail));
    int len = n;
    int j = 0, k = fail[0] = -1;
    while (j < len)
    {
        while (k != -1 && t[j] != t[k])
            k = fail[k];
        fail[++j] = ++k;
    }
}

int kmp()
{
    int i = 0, j = 0;
    int ret = 0;
    while (i < n * 2)
    {
        while (j != -1 && s[i] != t[j])
            j = fail[j];
        i++, j++;
        if (j == m)
        {
            //printf("debug: i: %d j: %d\n", i, j);
            if (i < 2 * n)
                printf("%d %d\n", i - j, a[(i - j)] ^ b[0]);
            ret++, j = fail[j];
        }
    }
    return ret;
}

int main()
{
    scanf("%d", &n);
    m = n;
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for (int i = 0; i < n; i++)
        scanf("%d", &b[i]);

    for (int i = 0; i < n; i++)
        s[i] = a[i] ^ a[(i + 1) % n], t[i] = b[i] ^ b[(i + 1) % n];
    for (int i = n; i < 2 * n; i++)
        s[i] = s[i - n];
    /*     for (int i = 0; i < 2 * n; i++)
        cout << s[i] << " ";
    cout << endl;
    for (int i = 0; i < n; i++)
        cout << t[i] << " ";
    cout << endl; */
    getfail();
    kmp();
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <queue>
using namespace std;

int dp[500];
int dp1[11111500];
int dp2[11111100];
int main(){
    dp[1]=1;
    for(int i=2;i<210;i++){
        dp[i]=dp[i-1]+i;
    }
    for(int i=2;i<210;i++){
        dp[i]=dp[i-1]+dp[i];
    }
   // fill(dp,dp+400,0);
    fill(dp1,dp1+1111100,99999999);
    fill(dp2,dp2+1111100,99999999);
    dp1[0]=0;dp2[0]=0;
    for(int i=1;i<210;i++){
        int now=dp[i];
        for(int k=now;k<1100000;k++){
            if(dp1[k]>dp1[k-now]+1){
                dp1[k]=dp1[k-now]+1;
            }
        }
    }
    for(int i=1;i<300;i++){
        int now=dp[i];
        if(now%2==0)
            continue;
        for(int k=now;k<1100000;k++){
            if(dp2[k]>dp2[k-now]+1)
                dp2[k]=dp2[k-now]+1;
        }
    }
    int n;
    while(1){
        cin>>n;
        if(n==0)break;
        cout<<dp1[n]<<" "<<dp2[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 13444
#include<stdio.h>
#define N 100
void show(int,int *);
int main(){
  int i,j,n,key,num[N];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&num[i]);
    }
    show(n,num);
    for(i=1;i<n;i++){
      key=num[i];
      for(j=i-1;j>=0;j--){
	if(key>num[j])
	  break;
	num[j+1]=num[j];
      }
      num[j+1]=key;
      show(n,num);
    }
    return 0;
}
void show(int n,int num[]){
  int i;
  for(i=0;i<n;i++){
    if(i!=0)
      printf(" ");
    printf("%d",num[i]);
  }
  printf("\n");
}


Measured memory_bytes: 2144
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int n, i;
	cin >> n;
      
      int res = 0;
      for(i=1; i<n+1; i++){
          int tmp = (int)to_string(i).length();
          if(tmp%2==1){res++;}
      }
      cout << res;
	return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n, ans = 0;
    cin >> n;
    ans = (1000 - (n % 1000)) % 1000;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
int digits(int arg)
{
	int result = 0;
	while (arg != 0)
	{
		arg /= 10;
		result++;
	}
	return result;
}
signed main()
{
	int n = in();
	vector<int>nums(n); REP(i, n)cin >> nums[i];
	int mines[3] = { 1000010001,1000010001,1000010001 };
	REP(i, n)
	{
		REP(j, n)
		{
			if (i == j)continue;
			int temp_i = nums[i];
			REP(i, digits(nums[j]))temp_i *= 10;
			int result = temp_i + nums[j];
			if (result < mines[0])
			{
				mines[2] = mines[1];
				mines[1] = mines[0];
				mines[0] = result;
			}
			else if (result < mines[1])
			{
				mines[2] = mines[1];
				mines[1] = result;
			}
			else if (result < mines[2])
			{
				mines[2] = result;
			}
		}
	}
	cout << mines[2] << endl;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll INF = 1e6;

void solve()
{
    ll n, ans=0;
    cin>>n;
    ans+=1000*(n/500);
    n-=(n/500)*500;
    ans+=5*(n/5);
    cout<<ans;
}
 
int main()
{
    SPEED;
    ll t = 1;
    //cin>>t;
    while(t--) solve();
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s.EndsWith("A"))
                Console.WriteLine("T");
            if (s.EndsWith("T"))
                Console.WriteLine("A");
            if (s.EndsWith("G"))
                Console.WriteLine("C");
            if (s.EndsWith("C"))
                Console.WriteLine("G");
        }
    }
}


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

int main(){
int n,m,x;
cin >> n >> m >> x;

int a[15],cost,p[15];
int inf = 1100000000;
int ans = inf;

int v[15][15];

rep(i,n){
  cin >> p[i];
  rep(j,m) cin >> v[i][j];
}


rep(bit,1<<n){
  int cost =0;
  vector<int> d(m);
  rep(i,n){
    if(bit&1<<i){
      cost +=p[i];
      rep(j,m) d[j]+=v[i][j];
    }
  }
  bool ok = true;
  rep(i,m){
    if(d[i]<x) ok = false;
  }
  if(ok) ans = min(cost,ans);
  
}

if(ans == inf) cout << -1 <<endl;
else cout << ans << endl;
return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll ans=0;
ll x=5;
unsigned long long doublefactorial(long long a) {

	while(x>=a){
		ans++;
		x*=x;
	}


    if (a==0 || a==1) 
      return 1; 
    return a*doublefactorial(a-2); 
} 

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


	ll x=5;
	ll sum=0;
	ll sum2=0;
	if(n%2==0){
		while(x<=n/2){
			sum+=n/2/x;
			x*=5;
		}
		cout<<sum<<endl;
		return 0;
	}else{
		cout<<0<<endl;
		return 0;
	}

	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
vector<data_type> prime;
bitset<1000009>mark;
inline void sieve( data_type n)
{
    mark[0]=mark[1]=1;
    data_type i,j,limit=sqrt(n*1.0)+2;
    prime.emplace_back(2);
    for(i=4; i<=n; i+=2)
        mark[i]=1;
    for(i=3; i<=n; i+=2)
        {
            if(!mark[i])
                {
                    prime.emplace_back(i);
                    if(i<=limit)
                        {
                            for(j=i*i; j<=n; j+=i*2)
                                mark[j]=1;
                        }
                }
        }
}
int main()
{

    sieve(1000007);
    data_type n,a,sum=0,i,j;
    vector<data_type>dcount(1000007),vc;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a,vc.push_back(a),dcount[a]++;
    for(int i=0; prime[i]<=1000000; i++)
        {
            sum=0;
            for(int j=prime[i]; j<=1000000; j+=prime[i])
                sum+=dcount[j];
            if(sum>1)
                break;
        }

    if(sum<=1)
        return cout<<"pairwise coprime"<<endl,0;
    data_type g=vc[0];
    for(int i=1; i<n; i++)
        g=__gcd(g,vc[i]);
    if(g==1)
        return cout<<"setwise coprime"<<endl,0;
    cout<<"not coprime"<<endl;

    return 0;

}



Measured memory_bytes: 20200
#include <iostream>
#define white 0
#define black 1

using namespace std;

int main(void)
{
    int W, H, N, x[101], y[101], a[101], i, j, k, color[101][101], ans=0;

    cin >> W >> H >> N;

    for(i=1; i<=N; i++){
        cin >> x[i] >> y[i] >> a[i];
    }

    for(i=0; i<=W-1; i++){
        for(j=0; j<=H-1; j++){
            color[i][j] = white;
        }
    }

    for(i=1; i<=N; i++){
        if(a[i] == 1){
            for(j=0; j+1<=x[i]; j++){
                for(k=0; k<=H-1; k++){
                    color[j][k] = black;
                }
            }
        }
        else if(a[i] == 2){
            for(j=W-1; j+1>x[i]; j--){
                for(k=0; k<=H-1; k++){
                    color[j][k] = black;
                }
            }
        }
        else if(a[i] == 3){
            for(j=0; j<=W-1; j++){
                for(k=0; k+1<=y[i]; k++){
                    color[j][k] = black;
                }
            }
        }
        else{
            for(j=0; j<=W-1; j++){
                for(k=H-1; k+1>y[i]; k--){
                    color[j][k] = black;
                }
            }
        }
    }

    for(i=0; i<=W-1; i++){
        for(j=0; j<=H-1; j++){
            if(color[i][j] == white){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main () {
  int A, B;
  cin >> A >> B;
  
  int number_of_tap = 1;
  int ans = 0;
  
  while (number_of_tap < B) {
    number_of_tap = number_of_tap + A - 1;
    ans++;
  }
  
  cout << ans << endl;
}

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

int main(void){
	char s[100001], c;
	s[0]=0;
	int p=0;
	while((c=getchar())!=10) s[++p]=c;
	while(p>0){
		if(s[p]=='m'){
			if(s[--p]=='a' && s[--p]=='e' && s[--p]=='r' && s[--p]=='d'){
				p--;
			}else break;
		}else if(s[p]=='e'){
			if(s[--p]=='s' && s[--p]=='a' && s[--p]=='r' && s[--p]=='e'){
				p--;
			}else break;
		}else if(s[p]=='r'){
			if(s[--p]=='e'){
				p--;
				if(s[p]=='m'){
					if(s[--p]=='a' && s[--p]=='e' && s[--p]=='r' && s[--p]=='d'){
						p--;
					}else break;
				}else if(s[p]=='s'){
					if(s[--p]=='a' && s[--p]=='r' && s[--p]=='e'){
						p--;
					}else break;
				}else break;
			}else break;
		}else break;
	}
	puts(p==0?"YES":"NO");
}


Measured memory_bytes: 256
if __name__== "__main__":
    n,m = map(int,input().split(" "))
    x = list(map(int,input().split(" ")))
    x_mod = list(map(lambda x: x%m, x))
    s = [set() for _ in range(m)]
    num = [0 for _ in range(m)]
    pair = [0 for _ in range(m)]
    dic = [0 for _ in range(100001)]
    sum = 0
    sum_h = 0
    for i in range(n):
        s[x_mod[i]].add(x[i])
        num[x_mod[i]] += 1
        dic[x[i]] += 1
        if x_mod[i]==0:
            sum += 0.5
        if m%2==0 and x_mod[i] == m/2:
            sum_h += 0.5
    for i in range(1,m):
        if i == m/2:
            continue
        p = list(s[i])
        for j in range(len(s[i])):
            pair[i] += int(dic[p[j]]/2)
    
    sum = int(sum)
    sum_h = int(sum_h)
    sum += sum_h
    for i in range(1,int((m+1)/2)):
        i_1 = i
        i_2 = m-i
        if num[i]>num[m-i]:
            i_1 = m-i
            i_2 = i
        sum += num[i_1]
        sum += min(int((num[i_2]-num[i_1])/2), pair[i_2])
    print(int(sum))




Measured memory_bytes: 33788
N = int(input())
D = [[] for _ in range(N)]
for i in range(N):
    D[i] = list(map(int, input().split()))

cnt = 0
for i in range(N):
    if D[i][0] == D[i][1]:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 62388
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){

	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[]){
	char ch;
	while((ch = getchar()) != EOF){
		if(ch == '9'){
			puts("Yes");
			return 0;
		}
	}
	printf("No\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

unsigned long long a[3];
unsigned long long ans[3];
bool oushu = false;
int main()
{
    for(int i = 0 ; i < 3 ; i++)
    {
        cin>>a[i];
        if((a[i] % 2) == 0) oushu = true;    
    }
    if(oushu)
    {
        cout<<0<<"\n";
        return 0 ;
    }
    ans[0] = a[0] * a[1];
    ans[1] = a[1] * a[2];
    ans[2] = a[0] * a[2];
    sort(ans,ans+3);
    cout<<ans[0]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;

bool debug = false;
const int NIL = -1;
const ll INF = 400000000000;
const int NUM = 10010;
clock_t START, END;

queue<int> Q;
list<int> out;
vector<int> G[NUM];
int indeg[NUM], cor[NUM];
int V;

void bfs(int s)
{
	int u;
	Q.push(s);
	cor[s] = 1;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		out.push_back(u);
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if (indeg[v] == 0 && cor[v] == 0) {
				cor[v] = 1;
				Q.push(v);
			}
		}
	}
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in44.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
	int E, s, t;
	bool negative = false;
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		indeg[t]++;
	}
	for (int i = 0; i < V; i++) {
		if (indeg[i] == 0 && cor[i] == 0)
			bfs(i);
	}
	for (list<int>::iterator it = out.begin(); it != out.end(); it++)
		cout << *it << endl;
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


Measured memory_bytes: 4076
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long

int main(){
  ll int x,p=0,pt=0;
  scanf("%lld",&x);
  if(x>=500){
    p = x/500;
    x = x%500;
  }
    if(x>=5){
      pt = x/5;
    }

  printf("%lld",p*1000 + pt*5);
  return 0;
}

Measured memory_bytes: 128
#include <string>
#include <iostream>
#include <set>

using namespace std;

int main()
{
	string S;
	cin >> S;
	set <char> Myset;
	for(int i = 0; i < S.size(); i++) {
		Myset.insert(S[i]);
	
	}
	if (Myset.count('N')==Myset.count('S') && Myset.count('E')==Myset.count('W')) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = 0
for i in range(1, N+1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)


Measured memory_bytes: 9268
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);

		int setnum, btncnt;
		String[] btn = {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
		String numString, tmpstring/*, message*/;

		setnum = scanner.nextInt();

		for(int i = 0; i < setnum; i++){
			/*message = "";*/
			tmpstring = "";
			numString = scanner.next();
			for(int j = 0;j < numString.length() ;j++){
				if((Integer.parseInt(numString.charAt(j) + "")) == 0){
					System.out.print(tmpstring);
					tmpstring = "";
				}else if(Integer.parseInt(numString.charAt(j) + "") > 0){
					btncnt = 0;
					int hoge = Integer.parseInt(numString.charAt(j) + "");
					while(hoge == Integer.parseInt(numString.charAt(j)+ "")){
						j++;
						btncnt++;
					}
					System.out.print(btn[hoge].charAt((btncnt - 1) % btn[hoge].length()));
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define ll long long
#define ull unsigned long long
#define MAXM 100010
#define MAXN 110
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
#define mii map<int, int>
#define umii unordered_map<int, int>
#define allof(x) x.begin(), x.end()
#define DEBUG 1
// #define NOT_DMOJ 0
#ifdef DEBUG
	#define D(x...) printf(x)
#else
	#define D(x...)
#endif
using namespace std;

inline int GCD (int a, int b) { return b == 0 ? a : GCD(b, a % b); }
inline int LCM (int a, int b) { return a * b / GCD(a, b); }
inline ll PowMod (ll a, ll b, ll mod) { ll val = 1; while (b) { if (b & 1) val = (val * a) % mod; a = (a * a) % mod; b >>= 1; } return val; }

ll N, W, ans;
ll w[MAXN], v[MAXN];
ll DP[MAXN][MAXM];

int main (int argc, char const *argv[]) {
	#ifdef NOT_DMOJ
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif // NOT_DMOJ
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> W;
	for (int i=1; i<=N; i++) {
		cin >> w[i] >> v[i];
	}
	memset(DP, INF, sizeof(DP));
	DP[0][0] = 0LL;
	for (int i=1; i<=N; i++) {
		for (int j=0; j<=100000; j++) {
			if (j >= v[i]) {
				DP[i][j] = min(DP[i - 1][j], DP[i - 1][j - v[i]] + w[i]);
			}
			else DP[i][j] = DP[i - 1][j];
		}
	}
	for (int i=0; i<=100000; i++) {
		if (DP[N][i] <= W) ans = i;
	}
	cout << ans << "\n";
	return 0;
}

/* 
 * Look for:
 * the exact constraints (multiple sets are too slow for n=10^6 :( ) 
 * special cases (n=1?)
 * overflow (ll vs int?)
 * array bounds
 */

Measured memory_bytes: 86272
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int, int>pii;
vector<int>pat[2][55];
bool flag[55];
set<pii>se[2];
vector<int>zp[55];
int cnt;
void dfs(int node, int t, bool f)
{
	flag[node] = true;
	for (int i = 0; i < pat[t][node].size(); i++)
	{
		int v = pat[t][node][i];
		if (!flag[v])
		{
			if (f&&se[1 - t].find(make_pair(node, v)) != se[1 - t].end())dfs(v, t, true);
			else
			{
				dfs(v, t, false);
				if (t == 0)cnt++;
				if (!f)
				{
					if (t == 0)zp[v].push_back(node);
					else zp[node].push_back(v);
				}
			}
		}
	}
}
int fin[55];
int pt;
void dfs2(int node)
{
	if (flag[node])return;
	flag[node] = true;
	for (int i = 0; i < zp[node].size(); i++)dfs2(zp[node][i]);
	fin[node] = pt++;
}
int get(int num, vector<pii>ea, vector<pii>eb, int r)
{
	for (int i = 0; i < num; i++)pat[0][i].clear(), pat[1][i].clear(), zp[i].clear();
	se[0].clear(), se[1].clear();
	for (int i = 0; i < ea.size(); i++)pat[0][ea[i].first].push_back(ea[i].second), pat[0][ea[i].second].push_back(ea[i].first);
	for (int i = 0; i < eb.size(); i++)pat[1][eb[i].first].push_back(eb[i].second), pat[1][eb[i].second].push_back(eb[i].first);
	for (int i = 0; i < ea.size(); i++)se[0].insert(ea[i]), se[0].insert(make_pair(ea[i].second, ea[i].first));
	for (int i = 0; i < eb.size(); i++)se[1].insert(eb[i]), se[1].insert(make_pair(eb[i].second, eb[i].first));
	cnt = 0;
	fill(flag, flag + num, false);
	dfs(r, 0, true);
	fill(flag, flag + num, false);
	dfs(r, 1, true);
	pt = 0;
	fill(flag, flag + num, false);
	for (int i = 0; i < num; i++)dfs2(i);
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < zp[i].size(); j++)
		{
			if (fin[i] < fin[zp[i][j]])return 1000000000;
		}
	}
	return cnt;
}
int deg[55];
int main()
{
	int data;
	scanf("%d", &data);
	for (int p = 0; p < data; p++)
	{
		int num;
		scanf("%d", &num);
		fill(deg, deg + num, 0);
		vector<pii>v1, v2;
		for (int i = 0; i < num - 1; i++)
		{
			int za, zb;
			scanf("%d%d", &za, &zb);
			za--, zb--;
			v1.push_back(make_pair(za, zb));
		}
		for (int i = 0; i < num - 1; i++)
		{
			int za, zb;
			scanf("%d%d", &za, &zb);
			za--, zb--;
			v2.push_back(make_pair(za, zb));
			deg[za]++, deg[zb]++;
		}
		int mini = 1000000000;
		for (int i = 0; i < num; i++)
		{
			int z = get(num, v1, v2, i);
			mini = min(mini, z);
			//printf("   %d %d\n", i + 1, z);
		}
		for (int i = 0; i < num; i++)
		{
			if (deg[i] != 1)continue;
			for (int j = 0; j < num; j++)
			{
				if (i == j)continue;
				vector<pii>zv;
				for (int k = 0; k < v2.size(); k++)
				{
					if (v2[k].first != i&&v2[k].second != i)zv.push_back(v2[k]);
					else zv.push_back(make_pair(i, j));
				}
				int z = get(num, v1, zv, i);
				mini = min(mini, z + 1);
				//printf("   %d %d %d\n", i + 1, j + 1, z);
			}
		}
		if (mini == 1000000000)printf("-1\n");
		else printf("%d\n", mini);
	}
}

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

int main(){
  string str;
  vector<int> v(26);
  while(getline(cin, str)){
    for(int i=0;i<str.size();i++){
      if(str[i] >= 'a' && str[i] <= 'z'){
        v[str[i]-'a']++;
      } else if(str[i] >= 'A' && str[i] <= 'Z'){
        v[str[i]-'A']++;
      }
    }
  }

  for(int i=0;i<26;i++){
    cout << (char)('a' + i) << " : " << v[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
persons = []
chechpoints = []
for i in range(N):
    a = list(map(int,input().split()))
    persons.append(a)
for j in range(M):
    a = list(map(int,input().split()))
    chechpoints.append(a)

for i in range(N):
    x = persons[i][0]
    y = persons[i][1]
    distance = []
    for j in range(M):
        distance_j = abs(x-chechpoints[j][0])+abs(y-chechpoints[j][1])
        distance.append(distance_j)
    print(distance.index(min(distance))+1)



Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc149/tasks/abc149_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K, a, b, c;
    cin >> N >> K >> a >> b >> c;
    string s;
    cin >> s;
    int ans = 0;

    REP(i, N) {
        if (i >= K && s[i] == s[i - K]) {
            // 得点を加算せず、現時点＋Kでは必ず得点を加算
            s[i] = '-';
        } else if (s[i] == 's') {
            ans += a;
        } else if (s[i] == 'p') {
            ans += b;
        } else if (s[i] == 'r') {
            ans += c;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<set>
 
int main()
{
	std::set<int> s;
	int x, n;
	size_t ans;
	scanf("%d", &n);
	while(n--&&scanf("%d", &x)!=EOF) s.insert(x);
	ans=s.size();
	printf("%lu", ans);
  	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul  unsigned long long int
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod
//ll divide(ll a, ll b)  //euler's theorem(a/b)%mod
//{
//   return a*power(b,mod-2)%mod;  //only when mod is prime
//}

ll power(ll x, ll y)
{
    ll res = 1;
   while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
int main()
{
    speed;
    int n;
    cin>>n;
    vector<int>v(n);
	vector<pair<int,int>> point(n+1);
    for(int i=1;i<=n;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	point[i]={x,y};
    	v[i-1]=i;
    }
	long double sum=0;
		for(int i=0;i<n-1;i++)
		{
			long double x1=point[v[i]].first,y1=point[v[i]].second,x2=point[v[i+1]].first,y2=point[v[i+1]].second;
			x1=x1-x2;
			y1=y1-y2;
			sum+=sqrt(x1*x1+y1*y1);

		}
	while(next_permutation(v.begin(), v.end()))
	{
		for(int i=0;i<n-1;i++)
		{
			long double x1=point[v[i]].first,y1=point[v[i]].second,x2=point[v[i+1]].first,y2=point[v[i+1]].second;
//			cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<'\n';
//            cout<<v[i]<<" "<<v[i+1]<<' ';
			long double t1=x1-x2 , t2=y1-y2;
//			cout<<sqrt(t1*t1+t2*t2)<<"sff "<<'\n';
			sum+=sqrt(t1*t1+t2*t2);
		}
	}
	int t=1;
	for(int i=1;i<=n;i++)
	t=t*i;
	
	cout<<setprecision(11)<<sum/t<<'\n';


	return 0;
}


Measured memory_bytes: 3768
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	a := getStdinInt()
	fmt.Printf("%d\n", a+a*a+a*a*a)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

using namespace std;

#define ll long long
#define pb push_back
#define sz size()
#define S second
#define F first
#define all(x) x.begin(), x.end()

typedef vector < int >  vi;
typedef vector < vector < int > >  vvi;

void solve(){
    int n;
    cin >> n;
    string s;
    int ac = 0, tle = 0, re = 0, wa = 0;
    for(int i = 1; i <= n; i++){
        cin >> s;
        if(s == "AC"){
            ac++;
        }
        if(s == "TLE") tle++;
        if(s == "RE") re++;
        if(s == "WA") wa++;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
}

signed main() {
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
        cout << "\n";
    }
}




Measured memory_bytes: 3628
object Main {
  def main(args: Array[String]): Unit = {
    var button_size = io.StdIn.readLine().split(" ").map{_.toInt}
    var total_coin  = 0

    (0 until 2).foreach { i =>
      if(button_size(0) > button_size(1)) {
        total_coin += button_size(0)
        button_size(0) -= 1
      }
      else {
        total_coin += button_size(1)
        button_size(1) -= 1
      }
    }
    println(total_coin)
  }
}

Measured memory_bytes: 27204
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;

#define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; i++)
#define all(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())

int main(void)
{
  // code begin

  int n, d, x;
  vector<vi> xs;
  cin >> n >> d;
  rep(i, n){
    xs.push_back(vi{});
      rep(j, d){
        cin >> x;
        xs[i].push_back(x);
    }
  }

  float innerR = 0;
  float root = 0;
  int ans = 0;
  rep(i, n){
    rep(j, i){
      rep(k, d){
        innerR += pow((xs[i][k] - xs[j][k]), 2);
      }
      root = sqrt(innerR);
      if(ceil(root) == floor(root) && root != 0)
        ans++;
      innerR = 0;
    }
  }

  cout << ans << endl;
  // code end
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Ints(a)
	fmt.Println(a[len(a)-1] - a[0])
}


Measured memory_bytes: 640
n=int(input())
d12=[map(int, input().split()) for _ in range(n)]
d1,d2= [list(i) for i in zip(*d12)]

count=0
for i in range(n):
    if d1[i]==d2[i]:
        count+=1
    else:
        count=0

    if count==3:
        print('Yes')
        break

else:
    print('No')

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

bool isInclude3(int x){
    if(x%10==3){
        return true;
    }else{
        if(x/10){
            return isInclude3(x/10);
        }else{
            return false;
        }
    }
}

int main(){
    int n;
    cin >> n;
    
    for(int i=1; i<=n; i++){
        if(i%3 ==0 || isInclude3(i)){
            cout << " " <<i;
        }
    }
    cout << endl;
    
    return 0;
}




Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define dracarys ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
 
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define dbg(x) cout << " Here => " << x 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool ptime;
void inline fileIO(){ 
    ptime=false;
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        ptime=true;
    #endif
        srand((unsigned)time(0));
}

void inline solve(int tc){
    int n,x,t;
    cin >> n >> x >> t;
    cout << ((n/x+(n%x!=0))*t) << "\n";
}

int main(){
    fileIO();

    dracarys

    int tt=0,t=1;
    //cin >> t;

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

    if (ptime)
        cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s    ";


    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#define LEN 100005
using namespace std;

int search(int A[],int n,int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key)i++;
    return i != n;
}
int main(){
    int n,A[10000+1],q,key,sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++)cin >> A[i];
    
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> key;
        if(search(A,n,key))sum++;
    }
    cout << sum << endl;
    return 0;
}




Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define vll vector<ll>
#define G vector<vll >
#define gg vector<int>
#define F first
#define S second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
#define clr(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define rll read_ll();
#define gc getchar
#define pc putchar
typedef long long ll;

template<class T> inline T lcm(T a,T b){
        return a/gcd(a,b)*b;
}
template<typename T>
void debug(T first) {
    cout << first << "\n";
}
template<typename T, typename... Args>
void debug(T first, Args... args) {
    cout << first << " ";
    debug(args...);
}



int main()
{
    ll n; cin>>n;
    vector<ll>a(n);
    vector<pll>cnto, cnte;
    map<ll,ll>h;
    FOR(i,1,n) {
        cin>>a[i];
        if(i&1)
        h[a[i]]+=1;
    }
    map<ll,ll>h2;
    FOR(i,1,n) {
        if(i%2 == 0) 
            h2[a[i]] += 1;
    }
    for(auto v : h) cnto.pb({v.S,v.F});
    for(auto v : h2) cnte.pb({v.S,v.F});
    ll ans = n;
    sort(all(cnto),greater<pll>()); sort(all(cnte),greater<pll>());

    if(cnto.size() == cnte.size() && cnto.size() == 1 && cnto[0].S != cnte[0].S) {
        ans = 0;
    } else {
        ans = min(n-cnto[0].F,n-cnte[0].F);
        ll siz = cnto.size();
        for(int i = 0; i < min(siz,2LL); i++) {
            ll t;
            if(cnto[i].S == cnte[0].S) t = n;
            else t = n-cnto[i].F-cnte[0].F;
            // debug(cnto[i].S,cnte[0].S,t);
            ans = min(ans,t);
        }
        siz = cnte.size();
        for(int i = 0; i < min(siz,2LL); i++) {
            ll t;
            if(cnte[i].S == cnto[0].S) t = n;
            else t = n-cnte[i].F-cnto[0].F;
            // debug(i,":",cnte[i].S,cnto[0].S,t);
            ans = min(ans,t);
        }
    }
    
    // for(auto v : cnte) debug(v.F,v.S);
    debug(ans);
    return 0;
}






Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	string t = "keyence";
	cin >> s;
	int i = 0;
	if(s[i]=='k'){
		while(s[i]==t[i]&&i<t.size()){
			i++;
		}
	}
	if(i==t.size()){
		cout <<"YES"<<endl;
		return 0;
	}else {
		for(int j=i;j<s.size();j++){
			int p = i;
			int k = j;
			if(s[j]==t[p]){
				while(s[k]==t[p]&&k<s.size()&&p<t.size()){
					k++;
					p++;
				}
			}
			if(p==t.size()&&k==s.size()){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(int a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(int a){
	write(a); puts("");
}
inline int read()//不管是正负数，都可以 
{
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
const int N=100005;
struct point{
	int x,y,num;
}a[N],e[N<<1];
inline bool cmp1(point a,point b){
	return a.x<b.x;
}
inline bool cmp2(point a,point b){
	return a.y<b.y;
}
inline bool cmp3(point a,point b){
	return a.num<b.num;
}
long long ans;
int n,have,m,father[N];
inline int getfather(int x){
	return x==father[x]?x:father[x]=getfather(father[x]);
}
int main(){
	n=read(); 
	for(int i=1;i<=n;i++){a[i].x=read(); a[i].y=read(); father[i]=a[i].num=i;}
	sort(&a[1],&a[n+1],cmp1); 
	for(int i=1;i<n;i++){
		e[++m].x=a[i].num; e[m].y=a[i+1].num; e[m].num=a[i+1].x-a[i].x;
	}
	sort(&a[1],&a[n+1],cmp2);
	for(int i=1;i<n;i++){
		e[++m].x=a[i].num; e[m].y=a[i+1].num; e[m].num=a[i+1].y-a[i].y;
	}
	sort(&e[1],&e[m+1],cmp3);
	for(int i=1;have<n-1;i++){
		int t1=getfather(e[i].x),t2=getfather(e[i].y);
		if(t1!=t2){
			father[t1]=t2;
			have++; ans+=e[i].num;
		}
	}
	writeln(ans);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (a <= x && x <= a + b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N, cake = 4, donut = 7;
    bool ans = false;

    cin >> N;

    for (int i = 0; i <= N / cake; i++) {
        if ((N-cake*i) % donut == 0) {
            ans = true;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ull nax=1e9;
ll n,m;
ll valid(ll i,ll j)
{
 if(i>=0 && i<n && j>=0 && j<m)
 return true;
 return false;
 //return 0;
}
int main()
{ 
    ll a,b,v,w,t;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    a=abs(a-b);
    if(v<w)
     cout<<"NO";
     else
     {
         v=abs(v-w);
         if(v*t>=a)
         cout<<"YES";
         else
         cout<<"NO";
     }

    return 0;
}


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

#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    REP(i, H) cin >> s[i];

    const int INF = H + W;

    vector<vector<int>> dp(H, vector<int>(W, INF));

    dp[0][0] = 0;

    REP(i, H) REP(j, W) {
        if (i + 1 < H) {
            amin(dp[i + 1][j], dp[i][j] + (s[i][j] != s[i + 1][j]));
        }
        if (j + 1 < W) {
            amin(dp[i][j + 1], dp[i][j] + (s[i][j] != s[i][j + 1]));
        }
    }

    int result = dp[H - 1][W - 1] / 2 + (s[0][0] == '#' || s[H - 1][W - 1] == '#');

    cout << result << endl;

    return 0;
}


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

typedef long long ll;

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

    int a, b;
    cin >> a >> b;

    cout << ((a + b) & 1 ? "IMPOSSIBLE" : to_string((a + b) / 2)) << endl;
}

/**
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
  int ac,wa,tle,re,n;
  ac = 0;
  wa = 0;
  tle = 0;
  re = 0;
  cin >> n;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    if(s=="AC") {
      ac++;
    }
    else if(s=="WA"){
      wa++;
    }
    else if(s=="TLE"){
      tle++;
    }
    else{
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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

using namespace std;

int
main(void){
	int x, n; cin >>  n;
	vector<int> vec(n);
	for(int i = 0; i < n; i++) cin >>vec[i];
	vector<int> mp(1e6 + 1, 0);
	vector<int> done(1e6 + 1, 0);
	vector<int> ans(n, true);
	for(int i = 0; i < n; i++){
		if(mp[vec[i]] == 1) ans[i] = false;
		if(done[vec[i]] == 0){
			done[vec[i]] = 1;
			for(int j = vec[i]; j <= 1e6; j += vec[i]){
				mp[j] = 1;
			}
		}
	}
	for(int i = 0; i < 1e6 + 1; i++){
		mp[i] = done[i] = 0;
	}
	for(int i = n - 1; i >= 0; i--){
		if(mp[vec[i]] == 1) ans[i] = false;
		if(done[vec[i]] == 0){
			done[vec[i]] = 1;
			for(int j = vec[i]; j <= 1e6; j += vec[i]){
				mp[j] = 1;
			}
		}
	}
	int num = 0;
	for(int i = 0; i < n; i++){
		if(ans[i]) num++;
	}
	cout << num;
}

Measured memory_bytes: 12768
fun ac098(args: Array<String>) {
    val charList = args[1].toCharArray()
    val left = Array(charList.size) { 0 }
    val right = Array(charList.size) { 0 }
    (1 until charList.size).forEach {
        if (charList[it - 1] == 'W') {
            left[it] = left[it - 1] + 1
        } else {
            left[it] = left[it - 1]
        }
        if (charList[charList.size - it] == 'E') {
            right[charList.size - 1 - it] = right[charList.size - it] + 1
        } else {
            right[charList.size - 1 - it] = right[charList.size - it]
        }
    }
    val ans = (0 until charList.size).map{left[it] + right[it]}.min()
    println(ans)
}
fun main(args: Array<String>) {
    ac098(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


Measured memory_bytes: 52284