akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const int N=2e5+20;
int n,a[N];
int main()
{
	while(cin>>n)
	{
		int s=0;
		for(int i=1;i<=n;i++)
			cin>>a[i],s+=a[i];
		if(s%10)
			cout<<s<<endl;
		else
		{
			bool flag=false;
			sort(a+1,a+1+n);
			for(int i=1;i<=n;i++)
			{
				if(a[i]%10)
				{
					s-=a[i];
					flag=true;
					break;
				}
			}	
			if(flag)
				cout<<s<<endl;
			else
				puts("0");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const int SIZE=1e6+10;
const double PI=acos(-1);

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	long long sum=0;
	map<int,int> mp;
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		mp[x]++;
		sum+=x;
	}
	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		int b,c;
		cin >> b >> c;
		if(b==c){
			cout << sum << endl;
			continue;
		}else{
			long long sum_temp=sum+mp[b]*(c-b);
			mp[c]+=mp[b];
			mp[b]=0;
			cout << sum_temp << endl;
			sum=sum_temp;
		}
	}
	return 0;
}


Measured memory_bytes: 8032
#include <cstdio>
#include <cctype>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar()) init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 100005, INF = 1e9;

/*******************************************************************************
 *
 * AtC: abc132_e
 * 每个点作为同一种余数的情况之用算一次
 *
 ******************************************************************************/

int n, m;

struct EDGE {
	int to, nex;
} edge[N];
int head[N], cntedge;
void Addedge(int u, int v) {
	edge[++cntedge] = (EDGE) { v, head[u] };
	head[u] = cntedge;
}

int mark[N][3];
struct NODE {
	int id, d, r;
} ;
int Bfs(int s, int t) {
	queue < NODE > Q;
	Q.push((NODE) { s, 0, 0 });
	mark[s][0] = true;
	while (!Q.empty()) {
		int u = Q.front().id, dis = Q.front().d, r = Q.front().r;
		if (r == 0 && u == t) return dis;
		Q.pop();
		if ((++r) % 3 == 0) ++dis, r = 0;
		for (int i = head[u], v; i; i = edge[i].nex) {
			v = edge[i].to;
			if (!mark[v][r]) {
				Q.push((NODE) { v, dis, r });
				mark[v][r] = true;
			}
		}
	}
	return -1;
}

int main() {
	n = read<int>(), m = read<int>();
	rep (i, 1, m) {
		int x = read<int>(), y = read<int>();
		Addedge(x, y);
	}
	int s = read<int>(), t = read<int>();
	cout << Bfs(s, t) << endl;
	return 0;
}



Measured memory_bytes: 2560
n=int(input())
a=[int(i) for i in input().split()]
dp=[0 for i in range(n)]
dp[0]=sum(a)-2*sum(a[1::2])
for i in range(1,n):
    dp[i]=2*a[i-1]-dp[i-1]
print(' '.join(map(str,dp)))

Measured memory_bytes: 19096
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=505;
int s[N],t[N];
bool visr[N],visc[N];
ull a[N][N],u[N],v[N],b[N],c[N];
int n;
int main()
{
    ull one=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    for(int i=1;i<=n;i++) scanf("%d",&t[i]);
    for(int i=1;i<=n;i++) scanf("%llu",&u[i]);
    for(int i=1;i<=n;i++) scanf("%llu",&v[i]);
    for(ull k=0;k<64;k++)
    {
        memset(visr,false,sizeof(visr));
        memset(visc,false,sizeof(visc));
        vector<int>r,c;
        for(int i=1;i<=n;i++)
        {
            if(s[i]==0) r.push_back(i);
            if(t[i]==0) c.push_back(i);
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
        {
            if(s[i]==0&&(u[i]>>k&1)||t[j]==0&&(v[j]>>k&1)||s[i]==1&&(u[i]>>k&1)&&t[j]==1&&(v[j]>>k&1)&&!(visr[i]&&visc[j]))
                a[i][j]|=one<<k,visr[i]=visc[j]=true;
        }
        bool f1=false,f2=false;
        int p1=0,p2=0;
        for(int i=1;i<=n;i++)
            if((u[i]>>k&1)&&s[i]==1&&!visr[i])
        {
            f1=true;
            a[i][c[p2]]|=one<<k;
            p2++;if(p2==c.size()) p2=0;
        }
        for(int i=1;i<=n;i++)
            if((v[i]>>k&1)&&t[i]==1&&!visc[i])
        {
            f2=true;
            a[r[p1]][i]|=one<<k;
            p1++;if(p1==r.size()) p1=0;
        }
        assert(!(f1&&f2));
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        if(s[i]) b[i]|=a[i][j];
        else b[i]&=a[i][j];
        if(t[j]) c[j]|=a[i][j];
        else c[j]&=a[i][j];
        if(j==1) b[i]=a[i][j];
        if(i==1) c[j]=a[i][j];
    }
    for(int i=1;i<=n;i++)
        if(u[i]!=b[i]||v[i]!=c[i])
    {
        printf("-1\n");return 0;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        printf(j==n?"%llu\n":"%llu ",a[i][j]);
}


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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;
    int64_t K;
    cin >> K;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') {
            if (K == i + 1) {
                cout << '1' << endl;
                break;
            }
        } else {
            cout << s[i] << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
"""AtCoder"""

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

for i in range(M):
  ans = 0
  for j in range(N):
    if P[i][0] - 1 == j:
      ans += P[i][1]
    else:
      ans += T[j]
  print(ans)


Measured memory_bytes: 3060
N=int(input())
A=[]
X=list()
for i in range(N):
   X.append([])

Y=list()
for i in range(N):
   Y.append([])

for i in range(N):
   A_i=int(input())
   A.append(A_i)

   for j in range(A_i):
      x,y=list(map(int,input().split()))
      X[i].append(x)
      Y[i].append(y)

max_nin=0
#bit全探索
for i in range(1<<N):
   honest_kamo=[]
   for j in range(N):
      if(i>>j)&1:
         honest_kamo.append(j)

   liar_kamo=[c for c in range(N)]
   liar_kamo=list(set(liar_kamo)-set(honest_kamo))
   #print("honest_kamo:",honest_kamo)
   #print("liar_kamo:",liar_kamo)

   flag=True
   for i in honest_kamo:
      for j in range(A[i]):
         if Y[i][j]==1:
            if X[i][j]-1 in liar_kamo:
               flag=False
         elif Y[i][j]==0:
            if X[i][j]-1 in honest_kamo:
               flag=False
   
   #print(flag)
   if flag:
      max_nin=max(max_nin,len(honest_kamo))

print(max_nin)

Measured memory_bytes: 45404
#include <iostream>
#define MAX_LENGTH 105
using namespace std;

char str[MAX_LENGTH] = {0};
int main(int argc, char const *argv[])
{
	int length;
	cin >> length;
	cin >> str;
	if (length & 1)
	{
		cout << "No";
		return 0;
	}
	int res = 1;
	for (int i = 0; i < (length >> 1); ++i)
	{
		if (str[i] != str[(length >> 1) + i])
			res = 0;
	}
	if (res) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    float A,B;
    cin >> A >> B;
    float a_price,b_price,a_up,b_up;
    a_price = A / 0.08;
    b_price = B / 0.1;
    a_up = (A+1) / 0.08;
    b_up = (B+1) / 0.1;

    int a = ceil(a_price);
    int b = ceil(b_price);
    int au = ceil(a_up);
    int bu = ceil(b_up);

    if(a >= b && a<b_up){
        cout << a << endl;
    }else if(b >= a && b<a_up){
        cout << b << endl;
    }else{
        cout << -1 << endl;
    }

}

Measured memory_bytes: 256
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{
    int n ;
    cin >> n ; 
    int y = n/100;
    int m = n%100;
    if(y < 13 and y > 0 and m < 13 and m > 0){
        cout << "AMBIGUOUS" << endl ;
    }
    else if(y < 13 and y > 0){
        cout << "MMYY" << endl ;
    }
    else if(m < 13 and m > 0){
        cout << "YYMM" << endl ;
    }
    else{
        cout << "NA" << endl ;
    }
    return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<climits>
#include<map>
#include<queue>
#include<iomanip>

using namespace std;

int main(){

	int A,B;

	cin >> A >> B;

	cout << max(max(A+B,A-B),A*B) << endl;

	return 0;


}


Measured memory_bytes: 764
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      double lng = 0;
      double[] a = new double[n];
      for(int i=0;i<n;i++){
        a[i] = Double.parseDouble(sc.next());
        lng += a[i];
      }

      double hidari = 0.0;
      double center = lng/2;
      double migi = 0.0;

      double ch = a[0];
      if(ch>=center){
        hidari = 0.0;
        migi = ch;
      }
      else{
        for(int i=1;i<n;i++){
          ch += a[i];
          if(ch>=center){
            hidari = ch -a[i];
            migi = ch;
            break;
          }
        }
      }
      //System.out.println(hidari+" "+center+" "+migi);

      int ans = 0;

      if(hidari==center || center==migi){
        System.out.println("0");
      }
      else{
////////////////////////////////////////////////////////////
double min = Math.min((center-hidari),(migi-center));

min = min*2;
System.out.println((int)min);
////////////////////////////////////////////////////////////
      }




    }
}


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

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

    int size = (int)S.size();
    vector<int> flags(size, 0);

    int pre_val = S[0] - '0';
    int pre_index = 0;
    int i=1;
    while(i < size){
        int val = S[i] - '0';
        if(val == pre_val){
            pre_val = val;
            pre_index = i;
            i++;
        }else{
            flags[pre_index] = 1;
            flags[i] = 1;
            pre_val = -1;
            for(int j=0; j<size; j++){
                if(flags[j]==0){
                    pre_val = S[j] - '0'; 
                    pre_index = j;
                    break;
                }
            }
            if(pre_val==-1){break;}
            i++;
        }
    }

    int num=0;
    for(int i=0; i<size; i++){
        num += flags[i];
    }

    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    rep(ki,k){
        vector<int> b(n+1);
        rep(i,n){
            int l=max(0,i-a[i]);
            int r=min(i+a[i]+1,n);
            b[l]++,b[r]--;
        }
        rep(i,n) b[i+1]+=b[i];
        b.pop_back();
        if(a==b) break;
        a=b;
    }

    rep(i,n) cout<<a[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 4816
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    String[] line = br.readLine().split(" ");
    Infant[] infants = new Infant[n];
    long dp[][] = new long[n + 1][n + 1];
    for (int i = 0; i < n; i++) {
      infants[i] = new Infant(i, Long.parseLong(line[i]));
    }
    Arrays.sort(infants, (o1, o2) -> Long.compare(o2.hp, o1.hp));
    for (int i = 0; i < n; i++) {
      Infant infant = infants[i];
      for (int j = 0; j <= i; j++) {
        //left
        long left = Math.abs( i - j - infant.order) * infant.hp;
        dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + left);
        long right = Math.abs(n - 1 - j - infant.order) * infant.hp;
        dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + right);
      }
    }
    long answer = 0;
    for(int i = 0; i <= n; i++){
      answer = Math.max(answer, dp[n][i]);
    }
    System.out.println(answer);
  }

  static class Infant {

    public Infant(int order, long hp) {
      this.order = order;
      this.hp = hp;
    }

    int order;
    long hp;
  }
}

Measured memory_bytes: 84252
def p(x):
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
def f():
 n,c=map(int,input().split())
 s='9'*n
 if c<0:return(11,s+s)[n>1]
 for h in'9731':
  if n-1:
   for m in range(int(10**~-n),0,-1):
    t=h+str(m-1).zfill(n-1)
    a=int(t+str(c)+t[::-1])
    if p(a):return a
  else:
   a=int(h+str(c)+h)
   if p(a):return a
 return s+str(c)+s
print(f())


Measured memory_bytes: 5636
#n = int(input())
n,k = map(int,input().split())
#a_L = list(map(int,input().split()))

dic = {}
for i in range(1,n+1):
    dic[i] = 0

for i in range(k):
    d = int(input())
    a_L = list(map(int,input().split()))
    
    for j in a_L:
        dic[j] = 1

#print(dic)
ans = 0
for k,v in dic.items():
    if v == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9200
#include<stdio.h>
int main()
{
    int i,x;
    scanf("%d",&x);
    for(i=1;i<=x;i++)
    {
        if(i%3==0)
        {
            printf(" %d",i);
        }
        else if(i%10==3)
        {
            printf(" %d",i);
        }
        else if(i/10==3)
        {
            printf(" %d",i);
        }
        else if(i/10%10==3)
        {
            printf(" %d",i);
        }
        else if(i/100==3)
        {
            printf(" %d",i);
        }
        else if(i/100%10==3)
        {
            printf(" %d",i);
        }
        else if(i/1000==3)
        {
            printf(" %d",i);
        }

    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main()
{
	int a,b,c,i,sum=0,A,B;
	scanf("%d%d",&a,&b);
	for(i=0;i<a;i++)
	{
		scanf("%d",&c);
		A=c;B=b-c;
		if(A>B)sum=sum+B*2;
		else sum=sum+A*2;
	}
	printf("%d",sum);
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int S; cin >> S;
    int dp[S + 1] = {};
    dp[0] = 1;

    REP(i, 3, S + 1) {
        REP(j, 0, i - 3 + 1) {
            dp[i] += dp[j];
            dp[i] %= MOD;
        }
    }
    cout << dp[S] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;
    int mod = 1000000007;
    int ans = fastpow(10, N, mod);

    mat dp(N + 1, vec(1 << (X + Y + Z - 1), 0));
    dp[0][0] = 1;
    //00000 0000000 11111
    int mask1 = (1 << X) - 1;
    //00000 1111111 10000
    int mask2 = (1 << (X + Y)) - (1 << (X - 1));
    //11111 1000000 00000
    int mask3 = (1 << (X + Y + Z)) - (1 << (X + Y - 1));

    mat nextb(1 << (X + Y + Z - 1), vec(8));
    REP(b, 1 << (X + Y + Z - 1)){
        FOR(n, 1, 8){
            int b2 = ((b << n) | (1 << (n - 1))) & mask1;
            b2 |= ((b & mask2) << n) & mask2;
            b2 |= ((b & mask3) << n) & mask3;
            nextb[b][n] = b2;
        }
    }


    REP(i, N){
        REP(b, 1 << (X + Y + Z - 1)){
            FOR(n, 1, 8){
                int b2 = nextb[b][n];
                if(b2 < (1 << (X + Y + Z - 1))){
                    dp[i + 1][b2] += dp[i][b];
                    dp[i + 1][b2] %= mod;
                }
            }
            //8,9,10
            dp[i + 1][0] += 3 * dp[i][b];
            dp[i + 1][0] %= mod;
        }
    }

    REP(b, 1 << (X + Y + Z - 1)){
        ans += mod - dp[N][b];
        ans %= mod;
    }
    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 28028
n = int(raw_input())
N = 8
data = [['.' for i in range(N)] for j in range(N)]
row = [0 for i in range(N)]
col = [0 for i in range(N)]
dpos = [0 for i in range(2*N-1)]
dneg = [0 for i in range(2*N-1)]
for i in range(n):
    tmp = map(int, raw_input().split())
    data[tmp[0]][tmp[1]] = 'Q'
    row[tmp[0]] = 1; col[tmp[1]] = 1
    dpos[tmp[0]+tmp[1]] = 1
    dneg[tmp[0]-tmp[1]+N-1] = 1
    
def printBoard(dt):
    for i in range(N):
        print ''.join(map(str, dt[i]))
        
def recursive(i, r, l, pos, neg, dt):
    if i == N:
        printBoard(dt)
        return
    if r[i] == 1:
        recursive(i+1, r, l, pos, neg, dt)
        return
    for j in range(N):
        if l[j] == 1 or pos[i+j] == 1 or neg[i-j+N-1] == 1:
            continue
        r[i] = 1; l[j] = 1
        pos[i+j] = 1; neg[i-j+N-1] = 1; dt[i][j] = 'Q'
        recursive(i+1, r, l, pos, neg, dt)
        r[i] = 0;l[j] = 0
        pos[i+j] = 0; neg[i-j+N-1] = 0; dt[i][j] = '.'
recursive(0, row, col, dpos, dneg, data)

Measured memory_bytes: 6492
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
using namespace std;
typedef long long ll;
ll f[500];
ll n, d, ans;
ll s[15][15];
int main()
{
    for (int i = 0; i < 450; i++)
    {
    	f[i] = i * i;
	}
	scanf("%lld%lld", &n, &d);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++)
		{
			scanf("%lld", &s[i][j]);
		}
		for (int j = 0; j < i; j++)
		{
			ll sum = 0;
			for (int k = 0; k < d; k++)
			{
				sum += (s[i][k] - s[j][k]) * (s[i][k] - s[j][k]);
			}
			ll x = lower_bound(f, f + 450, sum) - f;
			if (f[x] == sum)	ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
/*  -*- coding: utf-8 -*-
 *
 * 2967.cc: AIGo
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

char s[MAX_N + 4], t[MAX_N];
int ls[MAX_N];

/* subroutines */

bool placeable(int i, int m) {
  if (ls[i] > 1) return true;

  if (((i > 0 && t[i - 1] == 'B') ||
       (i > 1 && t[i - 1] == 'W' && t[i - 2] == 'B')) &&
      ((i + 1 < m && t[i + 1] == 'B') ||
       (i + 2 < m && t[i + 1] == 'W' && t[i + 2] == 'B')))
    return false;
  return true;
}

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d%s", &n, s);

  int m = 0;
  for (int i = 0; i < n;) {
    int j = i + 1;
    while (j < n && s[i] == s[j]) j++;
    t[m] = s[i];
    ls[m] = j - i;
    m++;
    i = j;
  }
  //printf("m=%d\n", m);
  //for (int i = 0; i < m; i++) printf("%c(%d) ", t[i], ls[i]); putchar('\n');

  int maxl = 0;
  for (int i = 0; i < m; i++)
    if (t[i] == '.' && placeable(i, m)) {
      if (i > 1 && t[i - 1] == 'B' && t[i - 2] == 'W')
	setmax(maxl, ls[i - 1]);
      if (i + 2 < m && t[i + 1] == 'B' && t[i + 2] == 'W')
	setmax(maxl, ls[i + 1]);
    }

  printf("%d\n", maxl);
  return 0;
}



Measured memory_bytes: 3232
#include <stdio.h>

int main(void) {
  int a,b,c,d,i;
  char f[20],g[2000],h[2000];
  scanf("%s",g);
  scanf("%d",&a);
  for(b=0;b<a;b++){
    scanf("%s",f);
    scanf("%d%d",&c,&d);
   if(f[2]=='i'){
    for(i=0;i<=d-c;i++)
    h[i]=g[c+i];
    h[i]='\0';
    printf("%s\n",h);}
   else if(f[2]=='p'){
     scanf("%s",h);
     for(i=0;i<=d-c;i++)
     g[c+i]=h[i];}
   else {
     for(i=0;i<=d-c;i++)
      h[i]=g[d-i];
     for(i=0;i<=d-c;i++)
     g[c+i]=h[i];
   }
  }
  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

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

    vint bossNum(N, 0);
    rep(i, N-1) {
        int boss;
        cin >> boss;
        bossNum[boss - 1]++;
    }

    rep(i, N) {
        cout << bossNum[i] << endl;
    }
}

Measured memory_bytes: 3948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<pair<int,int>,string> item;
main(){
	int n,i,w,s,S;
	string f;
	for(;cin>>n,n;){
		vector<item> items,result;
		for(i=0;i<n;i++)cin>>f>>w>>s,items.push_back(make_pair(make_pair(w,s),f));
		sort(items.begin(),items.end());
		S=999999999;
		do{
			for(s=w=i=0;i<n;i++){ //from upper
				if(items[i].first.second<w)break;
				w+=items[i].first.first;
				s+=(n-i)*items[i].first.first;
			}
			if(i==n&&s<S)S=s,result=items;
		}while(next_permutation(items.begin(),items.end()));
		reverse(result.begin(),result.end());
		for(i=0;i<n;i++)cout<<result[i].second<<endl;
	}
}

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

const int mod = 2;

char s[1000010];

int lucas(int a, int b) {
	if (a < 2 && b < 2) {
		if (a == 0 && b == 1) return 0;
		return 1;
	}
	return lucas(a >> 1, b >> 1) * lucas(a & 1, b & 1);
}

int main () {
	int n; scanf("%d", &n);
	scanf("%s", s);
	int pd = 0;
	for (int i = 0; i < n; i++) {
		s[i]--;
		if (s[i] == '1') pd = 1;
	}
	if (pd) {
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '1') {
				ans ^= lucas(n - 1, i);
			}
		}
		printf("%d\n", ans ? 1 : 0);
	} else {
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '2') {
				ans ^= lucas(n - 1, i);
			}
		}
		printf("%d\n", ans ? 2 : 0);
	}
	return 0;
}


Measured memory_bytes: 1280
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0
for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            continue
        else:
            dist=[[inf for _ in range(w)] for _ in range(h)]
            dist[i][j]=0
            que=deque([(i,j)])
            while que:
                si,sj=que.popleft()
                for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                    if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                        if dist[ni][nj]>dist[si][sj]+1:
                            dist[ni][nj]=dist[si][sj]+1
                            ans=max(ans,dist[si][sj]+1)
                            que.append((ni,nj))
print(ans)

Measured memory_bytes: 48348
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
		int [] v = new int [n];
        int [] c = new int [n];
        for(int i=0;i<n;i++){v[i] = sc.nextInt();
                            }
        for(int i=0;i<n;i++){c[i] = sc.nextInt();
                            }
        int ans = 0;
        for(int i=0;i<n;i++){ans+=Math.max(0,v[i]-c[i]);
                            }
        System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int euq(int a, int b) {
    return b ? euq(b, a%b) : a;
}

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

    vi a(n);
    rep(i, n) {
        cin >> a[i];
        a[i] /= 2;
    }

    int num = 0;
    rep(i, n) {
        int t = a[i], cnt = 0;
        while(t%2==0) {
            t /= 2;
            cnt++;
        }
        if(i>0 && num!=cnt) {
            cout << 0 << endl;
            return 0;
        }
        num = cnt;
    }

    int lc = a[0];
    FOR(i, 1, n) {
        int g = euq(lc, a[i]);
        lc = (lc*a[i])/g;
    }

    int res = (m/lc+1)/2;

    cout << res << endl;

    
    return 0;
}

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

int main() {
  int N, Ave=0, Sum=0, Sum2=0, Sum3=0;
  cin >> N;
  vector<int> A(N);
  rep(i, N){
    cin >> A.at(i);
    Sum=Sum+A.at(i);
  }
  Ave=Sum/N;
  rep(i, N) Sum2=Sum2+(A.at(i)-Ave)*(A.at(i)-Ave);
  rep(i, N) Sum3=Sum3+(A.at(i)-Ave-1)*(A.at(i)-Ave-1);
  cout << min(Sum2, Sum3) << endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n+2);
  a[0] = 0;
  a[n+1] = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += abs(a[i] - a[i-1]);
  }
  sum += abs(a[n+1] - a[n]);
  for (int i = 1; i <= n; i++) {
    int diff = abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]) - abs(a[i+1] - a[i-1]);
    cout << sum - diff << endl;
  }
  return 0;
}

Measured memory_bytes: 3788
N = int(input())
S = list(map(int, input().split()))
dif = 100000
for i in range (N):
    if abs(sum(S[i+1:]) - sum(S[:i+1])) < dif:
        dif = abs(sum(S[i+1:]) - sum(S[:i+1]))
print(dif)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)
 
 
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
   
}
    
ll maxl(ll a,ll b){
    if(a>b)return a;
    return b;
}
 
ll minl(ll a,ll b){
    if(a>b)return b;
    return a;
}
 
ll mod = 998244353;
 
ll mulmod(ll a, ll b,ll c){ 
    ll res = 0; 
    a = a % c; 
    while (b > 0){ 
        if (b % 2 == 1){ 
            res = (res + a) % c;
        }
        a = (a * 2) % c; 
        b /= 2; 
    } 
    return res % c; 
}
 
int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
        if (arr[mid] == x) 
            return mid; 
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    } 
    return -1; 
} 
 
int a[100005];
int tree[200005];
 
void build(int st,int low,int high){
    if(low==high){
        tree[st] = a[high]%2;
        return;
    }
    int mid = low+(high-low)/2;
    build(2*st,low,mid);
    build(2*st+1,mid+1,high);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
void update(int st,int start,int end,int ind,int val){
    if(start==end){
        tree[st] = val%2;
        return;
    }
    int mid = start+(end-start)/2;
    if(ind<=mid){
        update(2*st,start,mid,ind,val);
    }
    else update(2*st+1,mid+1,end,ind,val);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
int query(int st,int start,int end,int low,int high){
    if(start>high || end<low)return 0;
    int mid = start + (end-start)/2;
    if(start==low && end==high){
        return tree[st];
    }
    if(low>mid)return query(2*st+1,mid+1,end,low,high);
    if(high<=mid)return query(2*st,start,mid,low,high);
    return query(2*st,start,mid,low,mid)+query(2*st+1,mid+1,end,mid+1,high);
}


int main(){
	ios_base::sync_with_stdio(false);
	cout << setprecision(12);
	int n;
    cin >> n;
    int v[n];
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    double ans = 0;
    for(int i=0;i<n;i++){
        ans+= 1.0/v[i];
    }
    cout << 1.0/ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

vector<int> find_all(const std::string str, const std::string subStr) {
	std::vector<int> result;

	int pos = str.find(subStr);

	while (pos != std::string::npos) {
		result.push_back(pos);
		pos = str.find(subStr, pos + 1);
	}

	return result;
}

int main() {

	string s;
	scans(s);
	vector<int> findJOI = find_all(s, "2");
	printf("%d\n", findJOI.size());

	Please AC;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    let A: i64 = iter.next().unwrap().parse().unwrap();
    let B: i64 = iter.next().unwrap().parse().unwrap();
    
    if (A + B) % 2 == 0 {
        println!("{}", (A + B) / 2);
    } else {
        println!("IMPOSSIBLE");
    }
    
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;

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

    ll h,w,d;cin>>h>>w>>d;
    vector<ll> x(h*w+1),y(h*w+1);
    vector<ll> cost(h*w+1,0);
    for(int i=0;i < h;i++)
    {
        for(int j=0;j < w;j++)
        {
            ll a;cin>>a;
            x[a]=j+1;y[a]=i+1;
        }
    }
    x[0]=x[d];y[0]=y[d];

    for(int j=1+d;j < h*w+1;j++)
    {
        cost.at(j) = abs(x.at(j)-x.at(j-d))+abs(y.at(j)-y.at(j-d)) +cost.at(j-d);
        //cout<<i<<" "<<j<<"cost"<<cost[i][j]<<endl;
    }

    ll q;cin>>q;
    for(int i=0;i < q;i++)
    {
        ll l,r;cin>>l>>r;
        cout<<cost.at(r)-cost.at(l)<<endl;
    }
   
}

Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{


    private static final BufferedReader scan= new BufferedReader(new InputStreamReader(System.in));
    static char [][] arr;
    static StringBuilder sb;
    static long[][] dp;

    public static void main(String [] args) throws IOException {
        String [] nm= scan.readLine().split(" ");

        int n= Integer.parseInt(nm[0]);
        int m= Integer.parseInt(nm[1]);

        arr= new char[n][m];

        for(int i= 0; i< n; i++){
            String  rItem= scan.readLine();
            for(int j= 0; j< m; j++){
                arr[i][j]= rItem.charAt(j);
            }
        }

        dp= new long[n][m];
        for(long[] longs: dp) Arrays.fill(longs, -1);
        System.out.println(countPath(0, 0));
    }

    private static long countPath(int rIdx, int cIdx) {
        if(rIdx == arr.length || cIdx == arr[0].length || arr[rIdx][cIdx] == '#')
            return 0;

        if(rIdx == arr.length - 1 && cIdx == arr[0].length - 1)
            return 1;

        if(dp[rIdx][cIdx] != -1)
            return dp[rIdx][cIdx];

        long right= countPath(rIdx, cIdx + 1);
        long down= countPath(rIdx + 1, cIdx);

        return dp[rIdx][cIdx]= (right + down) % (long)(Math.pow(10, 9) + 7) ;
    }
}


Measured memory_bytes: 47484
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+500;
int c[N]={0};
 struct point{
    int num;
    long long year;
    int t;
    int st;
}b[N];
bool cmp1(struct point s1,struct point s2){
    if(s1.num == s2.num){
        return s1.year<s2.year;
    }
	else{
        return s1.num<s2.num;
    }
}
bool cmp2(struct point s1,struct point s2){
    return s1.t<s2.t;
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
    	scanf("%d %d",&b[i].num,&b[i].year);
        b[i].t = i;
    }
    sort(b+1,b+m+1,cmp1);
    for(int i = 1;i<=m;i++){
        b[i].st = c[b[i].num];
        c[b[i].num]++;
    }
    sort(b+1,b+m+1,cmp2);
    for(int i =1;i<=m;i++){
        printf("%06d%06d\n",b[i].num,b[i].st+1);
    }
    return 0;
}


Measured memory_bytes: 4224
#include<cstdio>
using namespace std;
int main()
{
	long long x;
	scanf("%lld",&x);
	for(long long i=-1000;i<=1000;i++)
	{
		for(long long j=-1000;j<=1000;j++)
		{
			if(i*i*i*i*i-j*j*j*j*j==x)
			{
				printf("%lld %lld\n",i,j);
				return 0;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 1732
#include <stdio.h>
int  linearsearch(long int *s,long int key,int n){
  int i=0;
  s[n]=key;
  while(s[i]!=key) i++;
  if(i==n)return 0;
  return 1;
    
}
int main(){
  int i,j;
  int n,q;
  int count=0;
  long int s[10001];
  long int t[500];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&t[i]);
  for(i=0;i<q;i++) count=count+linearsearch(s,t[i],n);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 680
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 n,t;
    int64 ans = 0;
    cin >> n >> t;

    int pre = 0;
    for (int i=0; i<n; i++) {
        int64 ti;
        cin >> ti;

        if (pre + t <= ti) ans += t;
        else ans += ti - pre;

        pre = ti;
    }

    cout << ans + t << endl;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,D;
inline void solve(){
  IN4(A,B,C,D);
  OUT(A*B>C*D?A*B:C*D);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import collections

local = False
if local:
    file = open("A.txt", "r")

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

S = inp()

if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")

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

int main() {
	int count_5 = 0;
	int count_7 = 0;

	int input;

	for (int i = 0; i < 3; i++) {
		cin >> input;
		if (input == 5) {
			count_5++;
		}
		else if (input == 7) {
			count_7++;
		}
		else {
			continue;
		}
	}

	if ((count_5 == 2) && (count_7 == 1)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>

int main()
{
    int N;
    int v[100000];
    int ans;

    // 整数の入力
    scanf("%d", &N);

    // get data
    for(int i=0; i<N; i++){
        std::cin >> v[i];
    }

    int counter_odd[100000];
    int counter_even[100000];

    // init
    for(int i=0; i<100000; i++){
        counter_odd[i] = 0;
        counter_even[i] = 0;
    }

    // count
    for(int i=0; i<N; i+=2){
        counter_odd[v[i]] += 1;        
        counter_even[v[i+1]] += 1;
    }

    // best, second_best and its count
    int num_best[2], num_s_best[2], count_best[2] = {0, 0}, count_s_best[2] = {0, 0};
    for(int i=0; i<100000; i++){
            if(counter_odd[i] > count_best[0]){
                int temp = count_best[0];
                count_best[0] = counter_odd[i];
                count_s_best[0] = temp;
                temp = num_best[0];
                num_best[0] = i;
                num_s_best[0] = temp;
            }
            else if(counter_odd[i] > count_s_best[0]){
                count_s_best[0] = counter_odd[i];
                num_s_best[0] = i;
            }
            if(counter_even[i] > count_best[1]){
                int temp = count_best[1];
                count_best[1] = counter_even[i];
                count_s_best[1] = temp;
                temp = num_best[1];
                num_best[1] = i;
                num_s_best[1] = temp;
            }
            else if(counter_even[i] > count_s_best[1]){
                count_s_best[1] = counter_even[i];
                num_s_best[1] = i;
            }
    }

    if(num_best[0] != num_best[1]){
        ans = N - count_best[0] - count_best[1];
    }
    else if(count_best[0] > count_best[1]){
        ans = N - count_best[0] - count_s_best[1];
    }
    else if(count_best[0] < count_best[1]){
        ans = N - count_s_best[0] - count_best[1];
    }
    else if(count_s_best[0] > count_s_best[1]){
        ans = N - count_s_best[0] - count_best[1];
    }
    else{
        ans = N - count_best[0] - count_s_best[1];
    }

    // 出力
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static void D_Cake123();

int main()
{
	D_Cake123();

	fflush(stdout);
	return 0;
}

void GetUlls(std::vector<unsigned long long>& vUll, unsigned int cnt, FILE* strm = stdin)
{
	unsigned long long ull = 0;

	for (unsigned int i = 0; i < cnt; i++) {
		fscanf(strm, " %llu", &ull);
		vUll.push_back(ull);
	}
}

void GetInts(std::vector<int>& vInt, unsigned int cnt, FILE* strm = stdin)
{
	int num = 0;

	for (unsigned int i = 0; i < cnt; i++) {
		fscanf(strm, " %d", &num);
		vInt.push_back(num);
	}
}


static void D_Cake123()
{
	int X, Y, Z, K;

	scanf(" %d %d %d %d", &X, &Y, &Z, &K);

	std::vector<unsigned long long> vAx, vBy, vCz, vAxBy, vAxByCz;

	GetUlls(vAx, X);
	GetUlls(vBy, Y);
	GetUlls(vCz, Z);

	for (int x = 0; x < X; x++) {
		for (int y = 0; y < Y; y++) {
			vAxBy.push_back(vAx[x] + vBy[y]);
		}
	}

	std::sort(vAxBy.begin(), vAxBy.end(), std::greater<unsigned long long>());

	int abCnt = vAxBy.size();
	if (abCnt > K) abCnt = K;

	for (int ab = 0; ab < abCnt; ab++) {
		for (int z = 0; z < Z; z++) {
			vAxByCz.push_back(vAxBy[ab] + vCz[z]);
		}
	}

	std::sort(vAxByCz.begin(), vAxByCz.end(), std::greater<unsigned long long>());

	for (int k = 0; k < K; k++) {
		printf("%llu\n", vAxByCz[k]);
	}
}


Measured memory_bytes: 43272
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t; cin>>s>>t;
  vector<char>S(s.size());
  vector<char>T(t.size());
  for(int i=0;i<s.size();i++)S[i]=s.at(i);
  for(int i=0;i<t.size();i++)T[i]=t.at(i);
  sort(S.begin(),S.end());
  sort(T.begin(),T.end());
  reverse(T.begin(),T.end());
  for(int i=s.size()-1;i>=0;i--)s.at(i)=S[i];
  for(int i=0;i<t.size();i--)t.at(i)=T[i];
  cout<<(s<t? "Yes":"No")<<endl;
}

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

using namespace std;

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

    int n; cin >> n;
    vector<int> a(n), b(n), c(n);

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

    vector<vector<int>> dp(n, vector<int>(3, 0));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int main(){
	int n;
	int a[3];
	cin >> n;
	while(n){
		string s;
		for(int i = 0; i < 3; i++){
			cin >> a[i];
		}
		sort(a, a+ 3);
		if(a[2] * a[2] == a[1] * a[1] + a[0] * a[0]) s = "YES\n";
		else s = "NO\n";
		cout << s;
		n--;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;
class v {
public:
	int x;
	int y;
	int tag;

	v(int x, int y, int tag) {
		this->x = x;
		this->y = y;
		this->tag = tag;
	}

	int d(v obj) {
		return abs(obj.x - this->x) + abs(obj.y - this->y);
	}

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

	vector<v> a;
	for (int i = 0; i < n; i++) {
		int ta, tb;
		cin >> ta >> tb;
		a.push_back(v(ta, tb, i+1));
	}
	vector<v> c;
	for (int i = 0; i < m; i++) {
		int tc, td;
		cin >> tc >> td;
		c.push_back(v(tc, td, i+1));
	}

	for (auto e : a) {
		int min = 2000000000;
		int mintag = 55;
		for (auto f : c) {
			if (min > e.d(f)) {
				min = e.d(f);
				mintag = f.tag;
			}
		}
		cout << mintag << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nm = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var l = 1;
            var r = nm[0];
            for (var i = 0; i < nm[1]; i++)
            {
                var lr = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                l = Math.Max(lr[0], l);
                r = Math.Min(lr[1], r);
            }
            Console.WriteLine(Math.Max(r - l + 1, 0));
        }
    }
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> G;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        G.push_back(make_pair(a, b));
    }

    sort(G.begin(), G.end(), [](const auto &a, const auto &b) {return a.second < b.second;});

    int cnt = 0;
    int tmp = -1;
    rep(i, M) {
        if (G[i].first >= tmp) {
            cnt++;
            tmp = G[i].second;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4308
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, num; bool A[500010], B[500000], C[500000]; bool dp[100200];
str S; bool check = false;	vector<ll> v;







int main() {
	//Code Line


	cin >> n >> S;

	for (auto ch : S) {
		v.emplace_back(ch - '0');
	}

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

		if (A[v[i]])continue;
		A[v[i]] = true;

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

			if (C[v[i] * 10 + v[j]])continue;
			C[v[i] * 10 + v[j]] = true;

			for (int k = j + 1; k < n; k++) {

				if (B[v[i] * 100 + v[j] * 10 + v[k]])continue;
				else { a++; B[v[i] * 100 + v[j] * 10 + v[k]] = true; }
				
			}

		}

	}

	cout << a;

	return 0;
}


Measured memory_bytes: 656