akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,tmp,num,m_num=0,abs_min=10000000000,abs_sum=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> tmp;
    num = abs(tmp);
    abs_sum+=num;
    if(tmp<0){
      m_num++;
    }
    if(num<abs_min){
      abs_min=num;
    }
  }
  if(m_num%2==0){
    cout << abs_sum<<endl;
  }else{
    cout << abs_sum-2*abs_min<<endl;
  }
    
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
    int i=0;
    int[] answer = new int[26];
    
    Scanner scan = new Scanner(System.in);
    while(scan.hasNext()){
    try{
      String line = scan.nextLine();
      for(i = 0;i < 1200;i++){
        int n = line.charAt(i);
        if(n >= 97 && n <= 122){
          char c= (char) (n - 32);
          System.out.print(c);
        }else if (n >= 65 && n <= 90){
          char c= (char) (n + 32);
          System.out.print(c);
        }else{
          System.out.print(line.charAt(i));
        }
      }
      
		}catch(Exception e){
      break;
    }
  }
  System.out.print("\n");
  

  }
}


Measured memory_bytes: 26904
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n);
    rep(i,n) cin>>A[i],A[i]%=4;
    int A2=0,A4=0;
    rep(i,n){
        if(A[i]==2) A2++;
        if(A[i]==0) A4++;
    }
    if(n-A2-A4<=A4||(A2==0&&n-A4==A4+1)) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3980
class Solution:
    def solve(self, N: int, A, B, C) -> int:

        answer = 0
        previous = -2

        for a in A:
            answer += B[a-1]

            if previous + 1 == a and a > 1:
                answer += C[a-2]

            previous = a

        return answer


if __name__ == '__main__':

    # standard input
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    # solve
    solution = Solution()
    print(solution.solve(N, A, B, C))


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
const int maxn = 55;
char s[maxn][maxn];
int n,m,ans;
int xx[]={1,-1,0,0},yy[]={0,0,1,-1};
bool check(int x,int y)
{
    _for(i,0,3)
    {
        int nowx = x+xx[i];
        int nowy = y+yy[i];
        if(nowx>n||nowx<1||nowy>m||nowy<1)continue;
        if(s[nowx][nowy]=='#')return false;
    }
    return true;
}
int main(int argc, char const *argv[])
{
    cin>>n>>m;
    _for(i,1,n)
    {
        _for(j,1,m)cin>>s[i][j];
    }
    _for(i,1,n)
    {
        _for(j,1,m)if(s[i][j]=='#')if(check(i,j))ans = 1;
    }
    if(ans)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

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

def iter_A(N,M_,M):
    if N==1:
        yield from ([a] for a in range(M_,M+1))
    else:
        for a in range(M_,M+1):
            yield from ([a] + b for b in iter_A(N-1,a,M))

def solve():
    N, M, Q = map(int, input().split())
    E = {}
    X = []
    for q in range(Q):
        a,b,c,d = map(int, input().split())
        X.append((a-1,b-1,c,d))

    
    return str(max(sum(d for a,b,c,d in X if A[b]-A[a]==c) for A in iter_A(N,1,M)))


if __name__ == '__main__':
    print(solve())



Measured memory_bytes: 9212
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main(){
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
 
    return 0;
}
 

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

using namespace std;

int main(){
	int n, m;
	int k[1000];
	vector<int> card;
	cin >> n >> m;
	for(int i = 0; i < n*2; i++){
		card.push_back(i+1);
	}
	for(int i = 0; i < m; i++){
		cin >> k[i];
	}

	for(int i = 0; i < m; i++){
		vector<int> a, b, c;
		if(k[i] == 0){
			for(int j = 0; j < card.size(); j++) a.push_back(card[j]);
			for(int j = n; j < card.size(); j++) b.push_back(card[j]);
			for(int j = 0; j < n; j++){
				c.push_back(a[j]), c.push_back(b[j]);
			}
			card = c;
		}else{
			for(int j = k[i]; j < card.size(); j++) c.push_back(card[j]);
			for(int j = 0; j < k[i]; j++) c.push_back(card[j]);
			card = c;
		}
	}

	for(int i = 0; i < card.size(); i++) cout << card[i] << endl;

	return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int calc(VI x){
	int n = x.size();
	if (n <= 1) return 0;

	// for (int p : x) cout << p << " ";
	// cout << endl;

	VVI dp(n, VI(5));
	dp[0][1] = x[0];
	dp[0][2] = x[1] - 1;
	dp[0][3] = x[1];
	REP(i,n-2){
		if (x[i+1] > 1){
			dp[i+1][0] = max({dp[i][0], dp[i][1], dp[i][2], dp[i][3]});
			dp[i+1][1] = max({dp[i][0] + x[i+1], dp[i][1] + x[i+1] - 1});
			dp[i+1][2] = max({dp[i][0], dp[i][1], dp[i][2]}) + x[i+2] - 1;
			dp[i+1][3] = max({dp[i][0], dp[i][1], dp[i][2]}) + x[i+2];
		}else{
			dp[i+1][0] = max({dp[i][0], dp[i][1], dp[i][2], dp[i][3]});
			dp[i+1][1] = max({dp[i][0] + x[i+1]});
			dp[i+1][2] = max({dp[i][0]}) + x[i+2] - 1;
			dp[i+1][3] = max({dp[i][0]}) + x[i+2];
		}
	}
	int ret = *max_element(ALL(dp[n-2]));
	// cout << ret << endl;
	return ret;
}

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

	int ans = 0;
	VI one;
	int x = 0;
	REP(i,n){
		int p = s[i] - '0';
		if (p == 1){
			x++;
		}else{
			if (x){
				one.push_back(x);
				x = 0;
			}else{
				ans += calc(one);
				one.clear();
			}
		}
	}

	if (x) one.push_back(x);
	ans += calc(one);

	cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;

vector<vector<pair<int, int>>> g;
vector<int> c;

void dfs(int v, long long weight)
{
    if (c[v] > -1)
    {
        return;
    }
    c[v] = weight % 2;
    for (int i = 0; i < g[v].size(); ++i)
    {
        int nextv = g[v][i].first;
        long long nextw = weight + (long long)g[v][i].second;
        dfs(nextv, nextw);
    }
    return;
}


int main() {
    

    
    int n;
    cin >> n;
    
    g = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>());
    c = vector<int>(n, -1);
    
    for (int i = 0; i < n - 1; ++i)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }
    
    dfs(0, 0);
    
    for (int i = 0; i < n; ++i)
    {
        cout << c[i] << endl;
    }
    
    return 0;
}


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)

signed main () {
  int r;
  cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}


Measured memory_bytes: 256
n=int(input())
s=input()
t=input()
cnt=0
for i in range(min(len(s),len(t))+1):
    #print(s[len(s)-i:],t[:i])
    if s[len(s)-i:]==t[:i]:
        cnt=i
    

print(len(s)+len(t)-cnt)

Measured memory_bytes: 3060
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(min(x//500,a)+1):
  for j in range(min((x-500*i)//100,b)+1):
    if (x - 500*i-100*j) % 50 ==0  and (x - 500*i-100*j) / 50  <= c:
      count += 1
      continue
print(count)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int V = scanner.nextInt();
        int E = scanner.nextInt();
        scanner.nextLine();

        WarshallFroyd warshallFroyd = new WarshallFroyd(V);
        for (int i = 0; i < E; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            warshallFroyd.addEdge(e[0], e[1], e[2]);
        }
        warshallFroyd.run();
        for (int i = 0; i < V; i++) {
            if (warshallFroyd.dist[i][i] < 0) {
                System.out.println("NEGATIVE CYCLE");
                return;
            }
        }
        for (int i = 0; i < V; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < V; j++) {
                if (warshallFroyd.dist[i][j] == Long.MAX_VALUE / 2)
                    sb.append("INF");
                else
                    sb.append(warshallFroyd.dist[i][j]);
                sb.append(' ');
            }
            System.out.println(sb.toString().trim());
            sb = new StringBuilder();
        }
    }


}

class WarshallFroyd {

    private int size;
    public long[][] dist;
    public long[][] from;

    public WarshallFroyd(int size) {
        this.size = size;
        dist = new long[size][size];
        for (int i = 0; i < size; i++) {
            Arrays.fill(dist[i], Long.MAX_VALUE / 2);
            dist[i][i] = 0;
        }
        from = new long[size][size];
        for (long[] arr : from) {
            Arrays.fill(arr, -1);
        }
    }

    public void addEdge(int from, int to, int cost) {
        dist[from][to] = cost;
    }

    public void run() {
        for (int via = 0; via < size; via++) {
            for (int fr = 0; fr < size; fr++) {
                for (int to = 0; to < size; to++) {
                    if (dist[fr][via] != Long.MAX_VALUE / 2
                            && dist[via][to] != Long.MAX_VALUE / 2
                            && dist[fr][to] > dist[fr][via] + dist[via][to]) {
                        dist[fr][to] = dist[fr][via] + dist[via][to];
                        from[fr][to] = via;
                    }
                }
            }
        }
    }
}


class Edge {
    public final int from;
    public final int to;
    public final int cost;

    public Edge(int from, int to, int cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return from == edge.from &&
                to == edge.to &&
                cost == edge.cost;
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to, cost);
    }
}



Measured memory_bytes: 67312
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
#define pff(a,b) printf("%d  %d\n",a,b);
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int a[5];
	rep(i, 5) cin >> a[i];

	int b[5] = { 0 };
	int maxi = 0;
	int mx = 0;
	rep(i, 5) {
		if (a[i] % 10 == 0) continue;
		b[i] = 10 - (a[i] % 10);
		if (mx <= b[i]) {
			maxi = i;
		}
		mx = max(mx, b[i]);
	}
	int time = 0;
	rep(i, 5) {
		if (i == maxi) continue;
		time += a[i];
		if (time % 10 == 0) continue;
		time += 10 - (a[i] % 10);
	}
	time += a[maxi];
	pf(time);

	return 0;
}

Measured memory_bytes: 3764
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (#x) << " is " << (x) << endl;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n) { for (int i = 0 ; i < n ; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n) {for (int i = 0; i < n; i++)cin >> a[i];}
//continue break deque stack queue sort reverse accumulate  count lower_bound upper_bound
// next_permutation copy_n __builtin_popcount

signed  main() {
  SPD_emergency

   // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  //int t; cin >> t; int tt = 1; while (t--)
  {
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while( 1){
    c = c-b;
    if(c<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    a = a-d;
    if(a<=0){
      cout<<"No"<<endl;
      return 0;
    }
  }
   

  
  return 0;
   }
}

Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int N = 100;


int main() {
    int A[N][N] = {{0}};

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            A[u-1][x-1] = 1;
        }
    }

    vector<int> d(n, -1);
    using int_pair = pair<int, int>;
    queue<int_pair> Q;
    Q.push(int_pair(0, 0));
    while (!Q.empty()) {
        auto p = Q.front();
        Q.pop();

        int k = p.first;
        int t = p.second;
        if (d[k] == -1) {
            d[k] = t;
        } else if (d[k] < t) {
            continue;
        } else {
            d[k] = t;
        }
        for (int i = 0; i < n; ++i) {
            if (A[k][i] != 0) {
                Q.push(int_pair(i, t + 1));
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " " << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4168
import numpy as np

k,x = np.array(list(map(int,input().split())))
initial = int(x)

for index in range(k-1):
  x = np.append(x,initial+index+1)
  x = np.insert(x,0,initial-index-1)

if x.size > 1:
  print(" ".join(list(map(str,x))))
else:
  print(x)

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

int main(){
  int w,h,tmp;
  string s;
  cin >> w >> h;
  for(int i=0; i<w*h; i++){
    cin >> s;
    if(s=="snuke"){ 
      tmp = i;
      break;
    }
  }
  char x;
  x = 65+tmp%h;
  cout << x << 1+(tmp/h) << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
cnt = 0

for x in range(10):
	for y in range(10):
		for z in range(10):
			i = s.find(str(x))
			if i != -1:
				i = s.find(str(y), i+1)
				if i != -1:
					i = s.find(str(z), i+1)
					if i != -1:
						cnt += 1
				
print(cnt)

Measured memory_bytes: 3060
import heapq

def main():

    INF = 1000000009
    n = int(input())
    e = [[] for _ in range(n)]
    for i in range(n):
        inf = list(map(int,input().split()))
        for j in range((inf[1])):
            e[inf[0]].append([inf[2+j*2],inf[2+j*2+1]])
    
    dp = [INF]*n
    dp[0] = 0
    pq = [[0,0]]
    heapq.heapify(pq)
    while pq:
        cost,v = heapq.heappop(pq)
        if dp[v]<cost:continue

        for i in range(len(e[v])):
            u = e[v][i][0]
            ncost = cost+e[v][i][1]
            if ncost < dp[u]:
                dp[u] = ncost
                heapq.heappush(pq,[ncost,u])
    for i in range(n):
        print(i,dp[i])


if __name__ == '__main__':
    main()




Measured memory_bytes: 6168
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define N 1000010
#define LL long long
using namespace std;
int n;
int a[210];

int main(){
	int i;
	scanf("%d", &n);
	n *= 2;
	for (i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	sort(a + 1, a + 1 + n);
	LL ans = 0;
	for (i = 1; i <= n; i += 2) ans += 1LL * a[i];
	printf("%I64d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
using namespace std;
typedef unsigned long long ll;

ll N,P;
int main(){
	cin >> N >> P;
	map<ll,ll> m;
	ll p = P;
	for(ll i=2;i*i<=P;i++){
		while(p%i==0){
			m[i]++; p /= i;
		}
	}
	if(p!=1) m[p]++;
	ll ans = 1;
	for(auto x:m){
		ll s = x.second/N;
		for(ll i=0;i<s;i++) ans *= x.first;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

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


int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }

    vector<ll> nab(n, 0);
    ll na = 0, nb = 0, bothab = 0;
    for (int i = 0; i < n; i++){
        for (int k = 0; k < s[i].size() - 1; k++){
            if (s[i].substr(k, 2) == "AB"){
                nab[i]++;
            }
        }
        if (s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') bothab++;
        if (s[i][0] == 'B' && s[i][s[i].size()-1] != 'A') nb++;
        if (s[i][0] != 'B' && s[i][s[i].size()-1] == 'A') na++;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++){
        ans += nab[i];
    }

    if (bothab > 0){
        ans += bothab - 1;
        if (na > 0){
            ans++;
            na--;
        }
        if (nb > 0){
            ans++;
            nb--;
        }
        ans += min(na, nb);
    }else{
        ans += min(na, nb);
    }

    cout << ans << endl;

    return 0;
}










Measured memory_bytes: 896
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
    int A,B,N,k=0,newN,po=1;
    int temp=0,asum=0,sum=0;
    cin >> N>>A >>B;

    for(int i=0;i<=N;i++){
        newN = i;
        while(k++<=3){
          po *= 10;
        }
        k=0;
      for(int j=4;j>=0;j--){


          // printf("\npo    %d \n",po);
        temp = newN/po;
//  printf("\na    %d %d  %d  %d\n",j,newN,temp,asum );
        asum +=temp;

        temp *= po;

        newN -= temp;

    //  printf("\nb   %d %d  %d  %d\n",j,newN,temp,asum );

        // if(newN==0){
        //   newN = i;
        // }
po/=10;
      //  printf("%d  %d\n",temp,asum );
      }
      if((asum<=B)&&(asum>=A)){
        sum+=i;
      }
      po = 1;
      asum=0;
      temp=0;
    }
   cout << sum << "\n";

    return 0;
}


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

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

int a[ 110 ];

int main()
{
int i;
int N;
int iA;
int iB;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	rep( i, N ) cin >> a[ i ];

	sort( a, a + N, greater<int>() );

	iA = 0;
	iB = 0;
	rep( i, N )
	{
		if( i % 2 == 0 )
			iA += a[ i ];
		else
			iB += a[ i ];
	}

	cout << iA - iB << endl;

	return 0;
}

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

string jisho1(string &a){
  char moji1, moji2;
  for(int i;i<a.size()-1;i++){
    moji1=a.at(i);
    moji2=a.at(i+1);
    if(moji1 <= moji2){
      continue;
    }
    else{
      a.at(i)=moji2;
      a.at(i+1)=moji1;
      a=jisho1(a);
    }
  }
  return a;
}
string jisho2(string &a){
  char moji1, moji2;
  for(int i;i<a.size()-1;i++){
    moji1=a.at(i);
    moji2=a.at(i+1);
    if(moji1 >= moji2){
      continue;
    }
    else{
      a.at(i)=moji2;
      a.at(i+1)=moji1;
      a=jisho2(a);
    }
  }
  return a;
}
int main(){
  string b,c;
  cin>>b>>c;
  b=jisho1(b);
  c=jisho2(c);
  if(b>=c){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

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

int main()
{		

		string number;

	int askii[1000]={};

		while (cin >> number)
		{	
				for (int j = 0; j < number.size(); j++)
				{
					char a=number[j];
					
					if('A'<=a&&a <='Z')
					{
						a+=32;
					}
					askii[a]++;
				}

		}
	
	for(char a='a';a<='z';a++)
	{
		
		cout << a << " : " << askii[a] << endl;
	
	}
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int ans=1;
  for(int i=1; i<N; ++i){
    if(S.at(i-1)!=S.at(i)){
      ans++;
    }
  }    
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
for i in range(3000):
  h,w=(int(a) for a in input().split())
  if w==0 and h==0:
    break
  for j in range(h):
    for k in range(w):
      if (j+k)%2==0:
        print("#",sep="",end="")
      else:
         print(".",sep="",end="")
    print("")
  print("")


Measured memory_bytes: 7016
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int sum;
	int s[100];
	
}p[100500];
void judge(int x)
{
		int i=0;
		int y=p[x-1].s[0];
		if(p[x-1].sum==1)
		{
			if(y+1<10)
			{
				p[x].s[0]=y+1;
				p[x].sum=1;
			}
			else
			{
				p[x].s[0]=0;
				p[x].s[1]=1;
				p[x].sum=2;
			}
		}
		else
		{
			if(y+1<10&&fabs(y+1-p[x-1].s[i+1])<=1)
			{
				memcpy(p[x].s,p[x-1].s,sizeof(p[x-1].s));
				p[x].s[0]++;
				p[x].sum=p[x-1].sum;
			}
			else
			{
				for(int j=1;j<p[x-1].sum;j++)
				{
					if(j==p[x-1].sum-1)
					{
						if(p[x-1].s[j]==9)
						{
							p[x].s[j+1]=1;
							for(int h=0;h<=j;h++)
							{
								p[x].s[h]=0;
							}
							p[x].sum=p[x-1].sum+1;
							break;
						}
						else
						{
							memcpy(p[x].s,p[x-1].s,sizeof(p[x-1].s));
							p[x].s[j]++;
							for(int h=j-1;h>=0;h--)
							{
								if(p[x].s[h+1]-1>=0)
								{
									p[x].s[h]=p[x].s[h+1]-1;
								}
								else
								{
									p[x].s[h]=0;
								}
							}
							p[x].sum=p[x-1].sum;
							break;
						}
					}
					else if(p[x-1].s[j]+1<10&&abs(p[x-1].s[j]+1-p[x-1].s[j+1])<=1)
					{
						
						memcpy(p[x].s,p[x-1].s,sizeof(p[x-1].s));
						p[x].s[j]++;
						for(int h=j-1;h>=0;h--)
						{
							if(p[x].s[h+1]-1>=0)
							{
								p[x].s[h]=p[x].s[h+1]-1;
							}
							else
							{
								p[x].s[h]=0;
							}
						}
						p[x].sum=p[x-1].sum;
						break;	
					}
				}	
			}
		}
}
int main()
{	
	int k;
	cin>>k;
	p[1].s[0]=1;
	p[1].sum=1;
	for(int i=2;i<=k;i++)
	{
		judge(i);
//		for(int j=p[i].sum-1;j>=0;j--)
//		{
//			cout<<p[i].s[j];
//		}
//		cout<<endl;
	}
	for(int i=p[k].sum-1;i>=0;i--)
	{
		cout<<p[k].s[i];
	}
	cout<<endl;
    return 0;
}



Measured memory_bytes: 39680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  long long mod=1e9+7;
  long long arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  long long suffix[n];
  suffix[n-1]=arr[n-1]%mod;
  for(int i=n-2;i>0;i--)
    suffix[i]=(suffix[i+1]+arr[i])%mod;
  long long ans=0;
  for(int i=0;i<n-1;i++)
    ans=(ans+(arr[i]*suffix[i+1])%mod)%mod;
  cout<<ans<<endl;
  return 0;
}

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

#define DEBUG(X) if(X)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int main()
{
  FASTIO;
  string str;
  int a, b;
  cin >> a >> b;
  int ans = a / 0.08;
  int ans2 = b / 0.1;
  if(ans < ans2)
    swap(ans, ans2);
  bool got = false;
  while(ans2 <= ans + 1)
  {
    int x = ans2 * 0.08, y = ans2 * 0.1;
    if(x == a && y == b)
    {
      cout << ans2 << endl;
      got = true;
      break;
    }
    else
      ans2++;
  }
  if(!got)
    cout << -1 << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second

const int maxn = 112345;

ll x[maxn], has[maxn], need[maxn];
int p[maxn], cnt[maxn], ans, n, m;
vector<pair<ll, pii>> e;

int Find(int x) {
    return p[x] == x ? x : p[x] = Find(p[x]);
}

void Union(int u, int v, ll to) {
    int fu = Find(u), fv = Find(v);
    if (fu == fv) {
        cnt[fu]++;
        need[fu] = to;
        return;
    }
    p[fu] = fv;
    cnt[fv] += cnt[fu] + 1;
    has[fv] += has[fu];
    need[fv] = to;
}

int main() {
    scanf("%d%d", &n, &m);
    FOR(i, 1, n) scanf("%lld", x + i);
    FOR(i, 1, n) {
        p[i] = i;
        has[i] = x[i];
    }
    FOR(i, 1, m) {
        ll y;
        int u, v;
        scanf("%d%d%lld", &u, &v, &y);
        e.eb(y, mp(u, v));
    }
    sort(all(e));
    for (const auto &cur : e) {
        ll now = cur._1;
        int u = cur._2._1, v = cur._2._2;
        Union(u, v, now);
        int r = Find(u);
        if (has[r] >= need[r]) {
            ans += cnt[r];
            cnt[r] = 0;
        }
    }
    printf("%d", m - ans);
}

Measured memory_bytes: 5104
def levenshtein(a,b):
    """
    :param a: string or list
    :param b:  string or list
    :return:  Levenstein distance
    """
    la = len(a)
    lb = len(b)
    dp = [[la+lb]*(lb+1) for i in range(la+1)]
    dp[0][0] = 0
    for i in range(1,la):
        dp[i][0] = i
    for j in range(1,lb):
        dp[0][j] = j
    for i in range(la):
        for j in range(lb):
            dp[i+1][j+1] = min(dp[i][j+1]+1,
                               dp[i+1][j]+1,
                               dp[i][j]+(a[i]!=b[j]))
    l_dist = dp[-1][-1]
    return l_dist

a = input()
b = input()

l_dist = levenshtein(a,b)
print(l_dist)


Measured memory_bytes: 43076
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int n,a[3],b[3],dp1[4][5010],dp2[4][25000010];
signed main(){
	cin>>n;
	f(i,3)cin>>a[i];
	f(i,3)cin>>b[i];
	f(i,3){
		f(j,n+1){
			if(j<a[i])dp1[i+1][j]=dp1[i][j];
			else dp1[i+1][j]=max(dp1[i][j],dp1[i+1][j-a[i]]+b[i]-a[i]);
		}
	}
	n+=dp1[3][n];
	f(i,3){
		f(j,n+1){
			if(j<b[i])dp2[i+1][j]=dp2[i][j];
			else dp2[i+1][j]=max(dp2[i][j],dp2[i+1][j-b[i]]+a[i]-b[i]);
		}
	}
	cout<<n+dp2[3][n]<<endl;
}


Measured memory_bytes: 587008
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <string>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <cmath>

typedef unsigned long long int ulli;
typedef   signed long long int slli;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MOD = 1e9 + 7;

#ifdef __USE_REAL__
typedef long double real;
const real MATH_PI =  3.141592653589793238462643383279502884197169399375105820974944;
const real MATH_E  =  2.718281828459045235360287471352662497757247093699959574966967;
const real eps = 1e-14;
#endif /* __USE_REAL__ */

#ifdef __DEBUG__
template<typename T, typename U=T>
std::string to_string(
	const std::list<T>& l, 
	std::function<U(T)> conv = [](const T& v){ return v; },
	const std::string delim = ","
)
{
	std::stringstream ss;
	auto itr = l.begin();
	while(itr != l.end())
	{
		ss << conv(*itr);
		++itr;
		if(itr != l.end()) ss << delim;
	}
	return ss.str();
}

template<typename T, typename U=T>
std::string to_string(
	const std::vector<T>& v, 
	std::function<U(T)> conv = [](const T& v){ return v; },
	const std::string delim = ","
)
{
	std::stringstream ss;
	for(ulli i=0; i<v.size(); ++i)
	{
		ss << conv(v[i]);
		if((i + 1) < v.size()) ss << delim;
	}
	return ss.str();
}
#endif

template<typename T, class InputIterator>
inline bool have(
	InputIterator first, 
	InputIterator last, 
	const T &val
)
{
	return std::find(first, last, val) != last;
}

template<class InputIterator, class UnaryPred>
inline bool have_if(
	InputIterator first, 
	InputIterator last, 
	UnaryPred pred
)
{
	return std::find_if(first, last, pred) != last;
}

int main()
{
	unsigned N, L;
	std::cin >> N >> L;
	
	std::vector<std::string> S(N);
	for(unsigned n=0; n<N; ++n)
	{
		std::cin >> S[n];
	}
	
	std::sort(S.begin(), S.end());
	
	for(unsigned n=0; n<N; ++n)
	{
		std::cout << S[n];
	}
	std::cout << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b,c[300],d[300],i,j,k=0,l;

	while(1){
		scanf("%d %d",&a,&b);
		if(a==0 && b==0)
			break;
		c[k]=a;
		d[k]=b;
		k++;
	}
	for(l=0;l<k;l++){
		for(i=0;i<c[l];i++){
			for(j=0;j<d[l];j++){
				if(i%2==0){
					if(j%2==0)
						printf("#");
					else
						printf(".");
				}
				else{
					if(j%2==0)
						printf(".");
					else
						printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<stdio.h>

int main(){
	int n;
	scanf("%d",&n);
	int p[n];
	for(int i=0; i<n; i++){
		scanf("%d",&p[i]);
	}
	int missmatch = 0;
	for(int i=0; i<n; i++){
		if(p[i] != i+1) missmatch++;
	}
	if((missmatch == 2) || (missmatch == 0)) printf("YES");
	else printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  vector<int> cards = { 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
  int a, b; cin >> a >> b; --a; --b;
  if (cards[a] > cards[b]) cout << "Alice" << endl;
  else if (cards[a] < cards[b]) cout << "Bob" << endl;
  else cout << "Draw" << endl;
  return 0;
}


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

using namespace std;

#define pause

#ifdef _DEBUG
#define pause system("pause");
#endif

int main() {
	int n, m;
	cin >> n;
	vector<int> v(n);
	vector<char> bv(n);
	cin >> v[0];
	v[0]--;
	bv[0] = v[0] == 0;
	int ans = bv[0];
	for (int i = 1; i < n; ++i) {
		cin >> v[i];
		v[i]--;
		bv[i] = !bv[i - 1] && v[i] == i;
		ans += bv[i];
	}
	cout << ans << endl;
	pause return 0;
}
/*
7
3 1 4 1 5 9 2
*/

Measured memory_bytes: 768
n = int(input())
a = list(map(int, input().split()))

if n % 2 == 0:
    b = []
    for i in reversed(range(n // 2)):
        b.append(a[2 * i + 1])
    for i in range(n // 2):
        b.append(a[2 * i])
    print(' '.join([str(_b) for _b in b]))
else:
    b = []
    for i in reversed(range(n // 2 + 1)):
        b.append(a[2 * i])
    for i in range(n // 2):
        b.append(a[2 * i + 1])
    print(' '.join([str(_b) for _b in b]))


Measured memory_bytes: 29764
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
int main() {
  long long n, k;
  cin >> n >> k;
  bitset<40> bitK(k);
  vector<bitset<40>> bitA(n);
  for(int i=0;i<n;i++) {
    long long a;
    cin >> a;
    bitset<40> ba(a);
    bitA[i] = ba;
  }
  vector<long long> setted(40);
  for(int i=0;i<n;i++) {
    for(int j=0;j<40;j++) {
      if(bitA[i].test(j)) setted[j]++;
    }
  }
  long long ans = 0;
  // x == 0
  for(int i=0;i<40;i++) {
    ans += (long long)pow(2, i) * setted[i];
  }
  // x == k
  long long alt = 0;
  for(int i=0;i<40;i++) {
    if(bitK.test(i)) alt += (long long)pow(2, i) * (n - setted[i]);
    else alt += (long long)pow(2, i) * setted[i];
  }
  chmax(ans, alt);
  for(int i=0;i<40;i++) {
    long long tmp = 0;
    if(!bitK.test(i)) continue;
    bitset<40> x;
    for(int j=0;j<i;j++) {
      tmp += (long long)pow(2, j) * max(n - setted[j], setted[j]);
    }
    tmp += pow(2, i) * setted[i];
    for(int j=i+1;j<40;j++) {
      if(bitK.test(j)) {
        tmp += (long long)pow(2, j) * (n - setted[j]);
      }
      else {
        tmp += (long long)pow(2, j) * setted[j];
      }
    }
    chmax(ans, tmp);
  }
  cout << ans << endl;
}


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

int main(){
    bool isEqual;
    string s1, t;
    cin >> s1 >> t;

    vector<char> s;
    for (int i = 0; i < s1.size(); ++i) {
        s.push_back(s1[i]);
    }
    reverse(t.begin(), t.end());
    reverse(s.begin(), s.end());

    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < s.size(); ++j) {
            isEqual = true;
            if(s[j] != t[j]){
                isEqual = false;
                char buf = s[s.size()-1];
                s.pop_back();
                s.insert(s.begin(), buf);
                break;
            }
        }
        if(isEqual){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define P           pair<int, int>
#define dint        long double

const int mod = 998244353;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

int modpow(int a, int b) {
    if(a == 0 || a == 1 || b == 1) return a;
    int ans = 1;
    while(b) {
        if(b%2) ans = mul(ans, a);    
        b /= 2; a = mul(a, a);
    }   return ans;
}

void solve() {
    dint pi = 3.141592653589;
    int n; cin >> n;
    dint ans = 2*pi*n;
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;

}



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



int main(){

int n;
cin >> n;

vector<ll>a(n+1);
vector<ll>b(n);
rep(i,n+1) cin >> a[i];
rep(i,n) cin >> b[i];


ll ans = 0;

rep(i,n){
//勇者iが倒せる数が残っていないときは次の勇者へ
    if(b[i]==0) continue;

    //勇者iが倒せる数が残っているモンスターの数より少ないときは倒せるだけ倒す
    //都市iのモンスターを倒しきれないとき
   if(b[i]<= a[i]){
       ans += b[i];
       continue;
   }

    //勇者iが倒せる数が残っているモンスターの数より少ないときは倒せるだけ倒す
    //都市iのモンスターは倒せるが都市i+1のモンスターは倒しきれないとき
    if(b[i] <= a[i] + a[i+1]){
        ans += b[i];
        b[i] -= a[i];
        a[i+1] -= b[i];
        continue;
    }

    //勇者iが都市i, i+1のモンスターをすべて倒しきれるときはすべて倒す
        ans += a[i] + a[i+1];
        a[i+1] = 0;
   
    //a[i]も0にすべきだが、この変数はこの後使わないので省略

}
cout << ans << endl;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,m; cin >> n >> m;
  static int s[20][20];
  for(int i = 0; i < m; i++){
    int k; cin >> k;
    for(int j = 0; j < k; j++){
      int idx; cin >> idx;
      s[i][idx-1] = 1;
    }
  }
  static int p[20];
  for(int i = 0; i < m; i++){
    cin >> p[i];
  }

  int ans = 0;
  for(int i = 0; i < (1 << n); i++){
    vector<int> v(m,0);
    for(int j = 0; j < n; j++){
      if((i >> j) & 1){
        for(int k = 0; k < m; k++){
          v[k] += s[k][j] == 1;
        }
      }
    }
    //cout << i << " " << v << endl;
    bool judge = true;
    for(int j = 0; j < m; j++){
      if(v[j]%2 != p[j]) judge = false;
    }
    if(judge) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

#define int ll
int go[10][10] = {};
void solve() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		string s = to_string(i);
		go[s[0] - '0'][s.back() - '0']++;
	}
	for (int i = 1; i <= n; ++i) {
		string s = to_string(i);
		ans += go[s.back() - '0'][s[0] - '0'];
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
long long n, m, v, p, l, r, c, x;
long long a[100000];
int main() {
	scanf("%lld%lld%lld%lld", &n, &m, &v, &p);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
		a[i] *= -1;
	}
	std::sort(a, a + n);
	for (int i = 0; i < n; i++) {
		a[i] *= -1;
	}
	l = p - 1;
	r = n;
	while (r - l > 1) {
		c = (r + l) / 2;
		if (n - (c - p + 1) >= v) {
			if (a[c] + m >= a[p - 1]) {
				l = c;
			}
			else {
				r = c;
			}
		}
		else {
			x = m * (v + c - p + 1 - n);
			for (int i = p - 1; i < c; i++) {
				x += a[i];
			}
			x = (x - 1) / (c - p + 1) + 1;
			if (a[c] + m >= x && (a[c] + m >= a[p - 1])) {
				l = c;
			}
			else {
				r = c;
			}
		}
	}
	printf("%lld\n", r);
}

Measured memory_bytes: 896
//============================================================================
// Name        : HelloCPP.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

	int H,W;
	while(1){
		cin >> H >> W;

		if (H == 0 && W == 0) break;

		for(int i = 0; i < H; i++ ){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 2996
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
v_odd=Counter([v[i] for i in range(n) if i%2==0])
v_eve=Counter([v[i] for i in range(n) if i%2==1])
v_eve[-1]=0
v_odd[-1]=0

eve=[[k,v] for k,v in v_eve.items()]
odd=[[k,v] for k,v in v_odd.items()]
eve.sort(key=lambda x:x[1])
odd.sort(key=lambda x:x[1])

if eve[-1][0]!=odd[-1][0]:
  print(n-eve[-1][1]-odd[-1][1])
else:
  ans0=n-eve[-2][1]-odd[-1][1]
  ans1=n-eve[-1][1]-odd[-2][1]
  print(min(ans0,ans1))

Measured memory_bytes: 24064
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside.
//AVX is better slightly
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))
#define N 100100

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);
const int MAX_BIT = 60;
//CLOCKS_PER_SEC

int fv[100], n;
ll basis[100], a[N], temp, ans;

void insertBasis(ll mask){
    for (int i = MAX_BIT - 1; i>=0; i--){
        if (((1LL << i) & mask) == 0) continue;
        if (!basis[i]){
            basis[i] = mask;
            return;
        }
        mask ^= basis[i];
    }
}

int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0);
    //ifstream cin ("test.in");
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++)
        for (int j=0; j<60; j++)
            if ((1LL << j) & a[i]) fv[j]++;
    for (int j=0; j<MAX_BIT; j++){
        if (fv[j] % 2 == 0) continue;
        temp += (1LL << j);
        for (int i=1; i<=n; i++)
            if (a[i] & (1LL << j)) a[i] -= (1LL << j);
    }
    for (int i=1; i<=n; i++) insertBasis(a[i]);
    for (int i=MAX_BIT - 1; i>=0; i--){
        if (!basis[i]) continue;
        if (ans & (1LL << i)) continue;
        ans ^= basis[i];
    }
    ans += ans + temp;
    cout << ans;
    return 0;
}


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


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

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

    
    long long ans = 0;
    int cnt=0;
    bool zeroflag = false;
    for (int i = 0; i < n; i++)
    {
        if(a[i]<0){
            cnt++;
            a[i]*=-1;
        }else if(a[i]==0){
            zeroflag=true;
        }
    }
    if(zeroflag||cnt%2==0){
            //特にやることはなかった。全部正にできる
    }else{
        sort(a.begin(),a.end());
        a[0]*=-1;
    }
    for (int i = 0; i < n; i++)
    {
        ans +=a[i];
    }
    
    
    cout << ans <<endl;
    return(0);
}

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

const int N=1e5+4;
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	long long s=0;
	long long ans=0;
	for(int i=0;i<n;++i){
		if(a[i]) s+=a[i];
		else{
			ans+=s/2;
			s=0;
		}
	}
	ans+=s/2;
	s=0;
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int a; cin >> a;
	cout << a*a*a + a*a + a << endl;
	return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

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

		int K = sc.nextInt();
		int S = sc.nextInt();
		int ans = 0;

		for (int X = 0; X <= K; X++){

			for (int Y = 0; Y <= K; Y++){

				int Z = S - X - Y;

				if (Z <= K && Z >= 0)
					ans ++;

			}

		}

		System.out.println(ans);

	}

}


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

#define int long long

using Int = long long;
//BEGIN CUT HERE
#define MOD 998244353
#define MAX_P 300005
Int fact[MAX_P],inv[MAX_P],finv[MAX_P];;
Int extgcd(Int a,Int b,Int& x,Int& y){
  Int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}

Int mod_pow(Int x,Int n,Int mod){
  Int res=1;
  while(n){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}

Int mod_inverse2(Int a,Int mod){
  return mod_pow(a,mod-2,mod);
}

void init(Int mod){
  fact[0]=1;
  for(Int i=1;i<MAX_P;i++)
    fact[i]=(fact[i-1]*i)%mod;

  inv[1]=1;
  for(Int i=2;i<MAX_P;i++)
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  
  finv[0]=1;
  for(Int i=1;i<MAX_P;i++)
    finv[i]=finv[i-1]*inv[i]%mod;
}

Int mod_fact(Int n,Int mod,Int& e){
  e=0;
  if(n==0) return 1;
  Int res=mod_fact(n/mod,mod,e);
  e+=n/mod;
  if(n/mod%2!=0)return res*(mod-fact[n%mod]) %mod;
  return res*fact[n%mod]%mod;
}

Int mod_comb(Int n,Int k,Int mod){
  if(n==k||k==0) return 1;
  Int e1,e2,e3;
  Int a1=mod_fact(n,mod,e1),a2=mod_fact(k,mod,e2),a3=mod_fact(n-k,mod,e3);
  if(e1>e2+e3) return 0;
  return a1*mod_inverse(a2*a3%mod,mod)%mod;
}

Int mod_comb2(Int n,Int k,Int mod){
  Int res=1;
  for(Int i=0;i<k;i++){
    res*=(n-i)%mod;
    res%=mod;
    res*=mod_inverse(i+1,mod);
    res%=mod;
  }
  return res;
}

//only for prime mod
Int mod_comb3(Int n,Int k,Int mod){
  if(k<0||k>n) return 0;
  return fact[n]*finv[k]%mod*finv[n-k]%mod;
}

signed main() {
  init(MOD);
  
  int n, a, b, k;
  cin >> n >> a >> b >> k;
  
  int ans = 0;

  for ( int i = 0; i <= n; i++ ) {
    if ( a*i <= k && (k-a*i) % b == 0 ) {
      int j = (k-a*i)/b;
      if ( i > n || j > n ) continue;
      ans += mod_comb3(n, i, MOD)*mod_comb3(n, j, MOD);      
      ans %= MOD;
    }
  }

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


Measured memory_bytes: 7296
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
//USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN THE RESPECTIVE DATA STRUCTURE
//NOTE THAT MEMSET CANT FILL THE DOUBLE VALUES;
//ACCUMULATE DOES NOT WORK PROPERLY IF VALUES START SUMMING BEYOND 1E9...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
 
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000037
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
                         #define ll long long
                         #define int long long
//  #define ll int
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
// #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn =500003;


void solve()
{
    ll n;cin>>n;
    ll ans=0;ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        ans^=a[i];
    }
    for(ll i=0;i<n;i++)
    {
        cout<<(a[i]^ans)<<" ";
    }
}
 
signed main()
{
   Need_for_speed(activated);
    
   
//satisfy
//    {
//  solve();
//   }
    solve();
    
    return 0;
}
 


Measured memory_bytes: 5160