akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main(void){

    int n;
    scanf("%d",&n);

    char s[n][11];
    int cnt=1;
    for (int i=0;i<n;i++){
        scanf("%s",s[i]);
    }

    qsort(s,n,11,int_sort);

    for (int i=1;i<n;i++){
        if (strcmp(s[i],s[i-1])!=0){
            cnt=cnt+1;
        }
    }

    printf("%d\n",cnt);

    return 0;
}

Measured memory_bytes: 5740
a=[]
for _ in range(5):
    a.append(int(input()))
ans=1000
b=[]
for i in range(5):
    if a[i]%10!=0:
        b.append(a[i]-a[i]%10+10)
    else:
        b.append(a[i])
for i in range(5):
    ans = min(ans,sum(b)-b[i]+a[i])
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
int k,n; 
int a[200005];
void solve(){
	
} 
int main(){  
	cin.tie(0);
    ios::sync_with_stdio(false);
	//solve();
	int x=-1;
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	} 
	sort(a+1,a+n+1);
	for(int i=1;i<n;i++){
		if(min(a[i+1]-a[i],k-(a[i+1]-a[i]))>x) x=min(a[i+1]-a[i],k-(a[i+1]-a[i]));
	}
	if(min(a[n]-a[1],k-(a[n]-a[1]))>x) x=min(a[n]-a[1],k-(a[n]-a[1]));

	
	
	printf("%d",k-x); 

    return 0;
}




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

ll K, N;

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

  if(K % 2 == 0) {
    cout << K / 2;
    REP(i, 1, N) cout << " " << K;
    cout << endl;
  } else {
    vector<ll> ans(N, (K + 1) / 2);
    ll j = 0;
    REP(i, 0, N / 2) {
      if(ans[N - 1 - j] > 0) ans[N - 1]--;
      else {
        while(ans[N - 1 - j] == 0) j++;
        if(ans[N - 1 - j] == 1) ans[N - 1 - j] = 0;
        else {
          ans[N - 1 - j]--;
          j--;
          while(j >= 0) {
            ans[N - 1 - j] = K;
            j--;
          }
        }
      }
    }
    cout << ans[0];
    REP(i, 1, N) {
      if(ans[i] == 0) break;
      cout << " " << ans[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 4608
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
int d[60];
int ans;

int main() {
	cin >> N;

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

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

	cout << ans << endl;

	return 0;
}

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

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

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void quickSort(int[] a, int[] b, int l, int r) {
		if (l < r) {
			int w2 = a[(l+r)/2];
			
			int i = l, j = r, temp, temp2;
			while (i < j) {
				while (a[i] > w2) i++;
				while (a[j] < w2) j--;
				if (i <= j) {
					temp = a[i];
					a[i] = a[j]; a[j] = temp;
					temp2 = b[i];
					b[i] = b[j]; b[j] = temp2;
					i++; j--;
				}
			}
			quickSort(a, b, l, j);
			quickSort(a, b, i, r);
		}
	}
	
	void run() {
		while (true) {
			int t = sc.nextInt();
			String number = sc.next();
			if (t == 0 && number.equals("0")) break;
			
			char[] n = number.toCharArray();
			int l = n.length;
			int m = 1<<(l-1);
			int[] num = new int[m];
			int[] cut = new int[m];
			
			int c = 0;
			for (int i = 0; i < 1<<(l-1); i++) {
				int v = 0;
				int value = 0;
				for (int j = 0; j < l-1; j++) {
					v = v*10 + Character.getNumericValue(n[j]);
					if ((i & 1<<j) != 0) {
						value += v;
						v = 0;
					}
				}
				value += v*10 + Character.getNumericValue(n[l-1]);
				if (value <= t) {
					num[c] = value;
					cut[c] = i;
					c++;
				}
			}
			
			quickSort(num, cut, 0, m-1);
			if (num[0] == 0) {
				out.println("error");
			} else if (num.length > 1 && num[0] == num[1]) {
				out.println("rejected");
			} else {
				out.printf("%d", num[0]);
				int v = 0;
				for (int j = 0; j < l-1; j++) {
					v = v*10 + Character.getNumericValue(n[j]);
					if ((cut[0] & 1<<j) != 0) {
						out.printf(" %d", v);
						v = 0;
					}
				}
				out.printf(" %d\n", v*10 + Character.getNumericValue(n[l-1]));
			}
			
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 19968
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int n;cin>>n;
	int left=0,right=n-1;
	string L,R,M;
	cout<<left<<endl;cin>>L;
	cout<<right<<endl;cin>>R;
	lol(i,18){
		int mid=(left+right)/2;
		cout<<mid<<endl;cin>>M;
		bool done=false;
		if(left%2==mid%2){
			if(L!=M)right=mid,R=M,done=true;
		}
		else if(L==M)right=mid,R=M,done=true;
		
		if(done==false){
			left=mid,L=M,done=true;
		}
	}
	return 0;
}


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

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


  bool check = false;
  if(S[0] == S[1] && S[2] == S[3]) check = true;
  if(S[0] == S[2] && S[1] == S[3]) check = true;
  if(S[0] == S[3] && S[1] == S[2]) check = true;

  if(S[0] == S[1] && S[0] == S[2]) check = false;

  if(check) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())

if x1 >= x2 and y2 >= y1:
    x3 = x2 - abs(y2-y1)
    y3 = y2 - abs(x1-x2)
    x4 = x3 + abs(x1 - x2)
    y4 = y3 - abs(y2 - y1)
elif x1 <= x2 and y2 >= y1:
    x3 = x2 - abs(y2-y1)
    y3 = y2 + abs(x1-x2)
    x4 = x3 - abs(x1 - x2)
    y4 = y3 - abs(y2 - y1)
elif x1 >= x2 and y2 <= y1:
    x3 = x2 + abs(y2 - y1)
    y3 = y2 - abs(x1 - x2)
    x4 = x3 + abs(x1 - x2)
    y4 = y3 + abs(y2 - y1)
else:
    x3 = x2 + abs(y2 - y1)
    y3 = y2 + abs(x1 - x2)
    x4 = x3 - abs(x1 - x2)
    y4 = y3 + abs(y2 - y1)

print(x3,y3,x4,y4)

Measured memory_bytes: 9248
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define N 25
 
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	

	int n,m,x,i,j,k;
	int a[N][N];
	int c[N];
	cin>>n>>m>>x;
	for(i=0;i<n;i++){
		cin>>c[i];
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}

	int s = pow(2,n);
	int sum[N],ans=INT_MAX;
	for(i=1;i<s;i++){
		for(j=0;j<m;j++){
			sum[j]=0;
		}
		int fin=0;
		for(j=0;j<n;j++){
			if((1<<j)&i){
				for(k=0;k<m;k++){
					sum[k]+=a[j][k];
				}
				fin+=c[j];
			}

		}
		int val=1;
		for(j=0;j<m;j++){
			if(sum[j]<x)
				val=0;
		}
		if(val)
			ans=min(ans,fin);

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

Measured memory_bytes: 4084
N = int(input())
S = input()
dp = [[0]*(N+1) for _ in range(N+1)]

for l in range(N)[::-1]:
    for r in range(l+1, N)[::-1]:
        dp[l][r] = dp[l+1][r+1]+1 if S[l]==S[r] else 0

ans = 0 
for l in range(N)[::-1]:
    for r in range(l+1, N)[::-1]:
        ans = max(ans, min(r-l, dp[l][r]))
print(ans)

Measured memory_bytes: 230792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
  int total=700;
  string S;
  cin >> S;
  rep(i,3){
    if(S.at(i)=='o'){
      total+=100;
    }
  }
  cout << total << endl;
}
      
      


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    ll ch = 100;
    ll x; cin >> x;
    int i;
    for(i = 0; ch < x; i++){
        ch += ch/100;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int e,y;
	cin>>e>>y;
	switch(e){
	case 0:
		if(1868<=y&&y<=1911)
			cout<<'M'<<y-1867<<endl;
		else if(1912<=y&&y<=1925)
			cout<<'T'<<y-1911<<endl;
		else if(1826<=y&&y<=1988)
			cout<<'S'<<y-1925<<endl;
		else if(1989<=y&&y<=2016)
			cout<<'H'<<y-1988<<endl;
		break;
	case 1:
		cout<<y+1867<<endl;
		break;
	case 2:
		cout<<y+1911<<endl;
		break;
	case 3:
		cout<<y+1925<<endl;
		break;
	case 4:
		cout<<y+1988<<endl;
		break;
	}
	return 0;
}

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

int main() {
  int A;
  cin >> A;
  if(A==000){
    cout << 0 << endl;
  }
  else if(A%3==1){
    cout << 1 << endl;
  }
  else if(A%3==2){
    cout << 2 << endl;
  }
  else {
    cout << 3 << endl;
  }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<int, int> P;
typedef tuple<int, int, int> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;


int main() {
	ll n, m;
	cin >> n >> m;
	map<P, vector<P>> g;
	vector<vector<P>> gToEdge(n);
	rep(i, m) {
		int p, q, c;
		cin >> p >> q >> c;
		p--; q--; c--;
		g[{p, c}].push_back({ q, c });
		g[{q, c}].push_back({ p, c });
		g[{p, c}].push_back({ p, -1 });
		g[{p, -1}].push_back({ p, c });
		g[{q, c}].push_back({ q, -1 });
		g[{q, -1}].push_back({ q, c });
	}
	map<P, int> dp;
	priority_queue<t3, vector<t3>, greater<t3>> qu;
	qu.emplace(0, 0, -1);
	while (!qu.empty()) {
		int node, prev, cost;
		tie(cost, node, prev) = qu.top(); qu.pop();
		P key = { node,prev };
		if (dp.count(key)) {
			auto d = dp[key];
			if (d <= cost) continue;
		}
		dp[key] = cost;
		if (key.first == n - 1) {
			cout << cost << endl;
			return 0;
		}
		if (prev == -1) {
			for (auto p : g[key]) {
				auto ncost = cost + 1;
				if (dp.count(p)) {
					auto d = dp[p];
					if (d <= ncost) continue;
				}
				qu.emplace(ncost, p.first, p.second);
			}
		}
		else {
			for (auto p : g[key]) {
				auto ncost = cost;
				if (dp.count(p)) {
					auto d = dp[p];
					if (d <= ncost) continue;
				}
				qu.emplace(ncost, p.first, p.second);
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 88276
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using lint=int64_t;
using namespace std;

lint N,M;
lint A[100010]={};
lint sum=0;

int main()
{
	cin >> N >> M;
	for(int i=0;i<N;i++)
	{
		cin >> A[i];
		sum+=A[i];
	}

	vector<int> v;
	for(int i=0;i<N;i++)
	{
		while(A[i]>0)
		{
			v.push_back(A[i]-A[i]/2);
			A[i]/=2;
		}
	}

	sort(v.begin(),v.end(),greater<int>());

	lint ans=0;
	for(int i=0;i<(int)v.size() && i<M;i++)
		ans+=v[i];

	cout << max((lint)0,sum-ans) << endl;
	return 0;
}


Measured memory_bytes: 19176
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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 main(){
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int n = s.size();
    map<char,vector<int>> m;
    rep(i,n) m[s[i]].push_back(i);
    rep(i,n) m[s[i]].push_back(i+n);
    
    ll ans = 0;
    int idx = -1;
    rep(i, t.size()) {
        char c = t[i];
        if(m.count(c) == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto idx_itr = lower_bound(m[c].begin(), m[c].end(), idx+1);
        idx = *idx_itr;
        if(*idx_itr >= n) {
            idx -= n;
            ans += n;
        }
    }
    ans += idx+1;
    cout << ans << endl;
}


Measured memory_bytes: 4660
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <fstream>
using namespace std;

int main()
{
    string s1;
    string s2;
    string s3;

    cin >> s1;
    cin >> s2;
    cin >> s3;

    cout << s1[0] << s2[1] <<s3[2] << endl;
}

Measured memory_bytes: 256
nS = int(input())
S = list(map(int,input().split()))
nQ = int(input())
Q = list(map(int,input().split()))

cnt = 0

for i in range(nQ):
    copy_S = S.copy()
    copy_S.append(Q[i])

    j = 0
    while copy_S[j] != Q[i]:
        j += 1
    if j < len(copy_S)-1 : cnt += 1

print(cnt)


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

using namespace std;

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

int const MAXN = 1e3 + 10;

int movex[4] = {-1,1,0,0};
int movey[4] = {0,0,-1,1};

char matrix[MAXN][MAXN];
int val[MAXN][MAXN];

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int h,w; cin >> h >> w;
    string str;
    fill(&val[0][0], &val[0][0] + MAXN*MAXN,1e9);
    queue<piii> q;
    for(int i=0;i<h;++i){
        cin >> str;
        for(int j=0;j<str.size();++j) {
            matrix[i][j] = str[j];
            if(str[j]=='#') q.push(piii(pii(i,j),0)), val[i][j] = 0;
        }
    }
    int ans = 0;
    while(!q.empty()){
        int x = q.front().first.first;
        int y = q.front().first.second;
        int dis = q.front().second;
        //printf("%d %d %d \n",x,y,dis);
        q.pop();
        val[x][y] = dis;
        for(int i=0;i<4;++i){
            int next_x = x + movex[i];
            int next_y = y + movey[i];
            if(next_x<0 or next_x>=h or next_y<0 or next_y>=w) continue;
            if(dis+1<val[next_x][next_y]){
                val[next_x][next_y] = dis+1;
                q.push(piii(pii(next_x,next_y),dis+1));
            }
        }
    }
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j) ans = max(ans,val[i][j]);
    }  
        
    cout << ans << endl;
}

Measured memory_bytes: 17296
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int d;
    cin >> d;
    vector<int> c(26);
    for(int i = 0; i < 26; i++){
        cin >> c[i];
    }
    vector<vector<int> > s(d, vector<int> (26));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(d), satisfaction(d);
    for(int i = 0; i < d; i++){
        cin >> t[i];
    }
    int sat = 0;
    vector<int> last(26);
    for(int i = 0; i < d; i++){
        last[t[i] - 1] = i + 1;
        sat += s[i][t[i] - 1];
        for(int j = 0; j < 26; j++){
            sat -= (i + 1 - last[j]) * c[j];
        }
        satisfaction[i] = sat;
    }
    for(int i = 0; i < d; i++){
        cout << satisfaction[i] << "\n";
    }
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_126
{
    class Program
    {

        static void Main(string[] args)
        {
   
            string data = Console.ReadLine();
            int dataL = int.Parse(data.Substring(0, 2));
            int dataR = int.Parse(data.Substring(2, 2));

            string ret = "NA";
            //月
            if (1 <= dataL && dataL <= 12)
            {
                //月
                if (1 <= dataR && dataR <= 12)
                {
                    ret = "AMBIGUOUS";
                }
                //年
                else
                {
                    ret = "MMYY";
                }
            }
            //年
            else
            {
                //月
                if (1 <= dataR && dataR <= 12)
                {
                    ret = "YYMM";
                }
            }

            Console.WriteLine(ret);

        }

    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n), sum(n+1);
  rep(i, n) {
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
  }
  ll ans = 0;
  rep(i, n) {
    (ans += (sum[n]-sum[i+1]) %mod * A[i] % mod) %= mod;
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 6360
H, W = map(int, input().split())

S = list()
for i in range(H):
  S.append(list(map(lambda x: int(x == '.'), input())))

for i in range(H):
  S[i].append(0)
  S[i].append(0)
S.append([0 for _ in range(W + 2)])


def wfs(loc):
  moved = [
    [
      False for w in range(W + 2)
    ]
    for h in range(H + 2)
  ]
  queue = [(loc, 0)]
  ans = 0
  moved[loc[0]][loc[1]] = True
  while (queue):
    (h, w), move = queue.pop(0)
    for i, j in zip((1, -1, 0, 0), (0, 0, -1, 1)):
      _h, _w = h + i, w + j
      if not moved[_h][_w] and S[_h][_w] == 1:
        moved[_h][_w] = True
        queue.append(((_h, _w), move + 1))
    ans = max(ans, move)
  return ans

ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == 1:
      ans = max(ans, wfs((i, j)))
print(ans)


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

int main(){

  long long int n;

  while(cin >> n, n){

    long long int x,a[10] = {0};

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

      if(x >= 60) a[6]++;
      else if(x >= 50) a[5]++;
      else if(x >= 40) a[4]++;
      else if(x >= 30) a[3]++;
      else if(x >= 20) a[2]++;
      else if(x >= 10) a[1]++;
      else a[0]++;

    }

    for(int i=0;i<7;i++) cout << a[i] << endl;

  }
}

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

int main() { 
  vector<int> a(5);;
  int ans;
  rep(i, 5){cin >> a.at(i);}
  rep(i, 5){
    if (a[i] == 0){
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main(){
    int n;
    cin >> n;
    pair<pair<string,int>,int> p[110];
    string s[110];
    int t[110];
    for(int i = 0; i < n; i++){
        cin >> s[i] >> t[i];
        p[i] = make_pair(make_pair(s[i],-t[i]),i+1);
    }
    sort(p, p+n);
    for(int i = 0; i < n; i++){
        cout << p[i].second << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,x,max1,p1,max2,p2,sum1[100005],sum2[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(i%2) sum1[x]++;
		else sum2[x]++;
	}
	for(int i=0;i<=100000;i++)
	{
		if(sum1[i]>max1)
			max1=sum1[i],p1=i;
		if(sum2[i]>max2)
			max2=sum2[i],p2=i;
	}
	if(p1==p2)
	{
		int max3=0,max4=0;
		for(int i=0;i<=100000;i++)
		{
			if(sum1[i]>max3&&i!=p1)
				max3=sum1[i];
			if(sum2[i]>max4&&i!=p2)
				max4=sum2[i];
		}
		if(max1-max3>max2-max4)
			max2=max4;
		else
			max1=max3;
	}
	cout<<n-(max1+max2)<<endl;
	return 0;
}

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

int main(){
    int n,m,i,j,a,count=0;
    cin >> n >> m;
    vector<int> fav(m,0);
    for(i=0;i<n;i++){
        int k=0;
        cin >> k;
        for(j=0;j<k;j++){
            cin >> a;
            fav.at(a-1)++;
        }
    }
    for(i=0;i<m;i++){
        if(fav.at(i)==n)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
   double x1, x2, x3, xp, y1, y2, y3, yp, key, key12, key23, key13;
   while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF ) {
       if ( x2 < x1 && x1 < x3 ) {
           key = x1;
           x1 = x2;
           x2 = key;
           key = y1;
           y1 = y2;
           y2 = key;
       } else if ( x2 < x3 && x3 < x1 ) {
           key = x3;
           x3 = x1;
           x1 = x2;
           x2 = key;
           key = y3;
           y3 = y1;
           y1 = y2;
           y2 = key;
       } else if ( x3 < x1 && x1 < x2 ) {
           key = x1;
           x1 = x3;
           x3 = x2;
           x2 = key;
           key = y1;
           y1 = y3;
           y3 = y2;
           y2 = key;
       } else if ( x3 < x2 && x2 < x1 ) {
           key = x1;
           x1 = x3;
           x3 = key;
           key = y1;
           y1 = y3;
           y3 = key; 
       } else if ( x1 < x3 && x3 < x2 ) {
           key = x3;
           x3 = x2;
           x2 = key;
           key = y3;
           y3 = y2;
           y2 = key;
       }
       if ( xp <= x1 ) printf("NO\n");
       else if ( x3 <= xp ) printf("NO\n");
       else if ( x1 < xp && xp <= x2 ) {
           key12 = (y2 - y1) * (xp - x1) / (x2 - x1) + y1;
           key13 = (y3 - y1) * (xp - x1) / (x3 - x1) + y1;
           /*printf("%lf %lf\n", key12,key13);*/
           if ( key12 > key13 ) {
               if ( key13 < yp && yp < key12 ) printf("YES\n");
               else printf("NO\n");
           } else if ( key13 > key12 ) {
               if ( key13 > yp && yp > key12 ) printf("YES\n");
               else printf("NO\n");
           } else printf("NO\n");
       } else if ( x2 < xp && xp < x3 ) {
           key23 = (y3 - y2) * (xp - x2) / (x3 - x2) + y2;
           key13 = (y3 - y1) * (xp - x1) / (x3 - x1) + y1;
           /*printf("b%lf %lf\n", key23, key13);*/
           if ( key23 > key13 ) {
               if ( key13 < yp && yp < key23 ) printf("YES\n");
               else printf("NO\n");
           } else if ( key23 < key13 ) {
               if ( key13 > yp && yp > key23 ) printf("YES\n");
               else printf("NO\n");
           } else printf("NO\n");
       } else printf("NO\n");
   }
   return 0;
}

Measured memory_bytes: 1724
//Referred Professors code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
	
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int k = Integer.parseInt(st.nextToken());
		int n = Integer.parseInt(st.nextToken());
		int[] aa = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i=0; i<n; i++)
			aa[i] = Integer.parseInt(st.nextToken());
		int gap = aa[0] + k - aa[n-1];
		for (int i = 1; i < n; i++)
			gap = Math.max(gap, aa[i]-aa[i-1]);
		System.out.println(k-gap);
	}
}

Measured memory_bytes: 48292
n,m=map(int,input().split())
AC=[0]*(n+1)
pen=[0]*(n+1)
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=="AC":
        AC[p]=1
    else:
        if AC[p]==0:
            pen[p]+=1
print(sum(AC),sum([AC[i]*pen[i] for i in range(n+1)]))

Measured memory_bytes: 5528
#import sys
#input = sys.stdin.readline
def main():
    Q = 10**9+7
    N, M = map( int, input().split())
    S = list( map( int, input().split()))
    T = list( map( int, input().split()))
    dp = [ [0]*(M+1) for _ in range(N+1)]
    memo = [ [0]*(M+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]+1)%Q
            else:
                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j])%Q
    print(dp[N][M]+1)
if __name__ == '__main__':
    main()


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

int main(){
	long long n,k;	cin>>n>>k;
	vector<long long> to(n+1),cnt(n+1,0);
	for(int i=1;i<=n;i++)cin>>to[i];

	int pos=1,start=0,end=0, loop=0;

	for(int i=0; i<k; i++){
		if(cnt[ to[pos] ]==0){
			cnt[ to[pos] ] = cnt[pos]+1;
			pos=to[pos];
		}
		else{
			start=to[pos];
			end=pos;

			loop=cnt[end]+1-cnt[start];
			break;
		}
	}
	//cout<<loop<<endl;
	
	if(k<=n){
		pos=1;
		for(int i=0;i<k;i++)pos=to[pos];
	}else{
		k-=cnt[start];	pos=start;
		k%=loop;
		for(int i=0;i<k;i++)pos=to[pos];
	}
	cout<<pos<<endl;

	return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

/*!* [iterutil] *!*/
/*+* イテレータの操作 *+*/
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}

/*!* [bitutil] *!*/
/*+* ビット操作関連 *+*/
int PopCount(i64 x) {
    x = (x & 0x5555555555555555) + (x >>  1 & 0x5555555555555555);
    x = (x & 0x3333333333333333) + (x >>  2 & 0x3333333333333333);
    x = (x & 0x0f0f0f0f0f0f0f0f) + (x >>  4 & 0x0f0f0f0f0f0f0f0f);
    x = (x & 0x00ff00ff00ff00ff) + (x >>  8 & 0x00ff00ff00ff00ff);
    x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
    x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff);
    return int(x);
}
// 一番後ろに立っているビットの位置を取得
int LastBit(i64 x) {
    if (x == 0) return 0;
    for (int i = 0; i < 64; i++) if (x >> i == 1) return i + 1;
    return -1;
}

int main() {
    auto f = [](i64 n) -> int {
        int m = 0;
        while(n) {
            n = n % PopCount(n);
            m++;
        }
        return m;
    };

    int N;
    cin >> N;
    vector<int> X(N);
    for(int &x : X) {
        char c;
        cin >> c;
        x = c - '0';
    }

    reverse(WHOLE(X));
    int pop_all = sum_up(WHOLE(X));
    int R[2] = {0, 0};  // 全体を割ったあまり
    vector<int> Y(N, 0); // １ビットだけを割ったあまり

    // ビットを b ? 降ろす : 立てる
    for(int b = 0; b < 2; b++) {
        int M = pop_all + (b ? -1 : +1);
        int p = 1;
        if(M == 0) continue;
        for(int i = 0; i < N; i++) {
            int x = X[i];
            if(x == b) Y[i] = p * (b ? -1 : +1);
            R[b] = (R[b] + x * p) % M;
            p = (p * 2) % M;
        }
    }

    vector<int> ans(N);
    for(int i = 0; i < N; i++) {
        int x = X[i];
        int M = pop_all + (x ? -1 : +1);
        int n = M ? (R[x] + Y[i] + M) % M : 0;
        ans[i] = f(n) + (M ? 1 : 0);
    }

    reverse(WHOLE(ans));
    for(int a : ans) cout << a << endl;
    return 0;
}

Measured memory_bytes: 5552
n = int(input())
works = []
for i in range(n):
    works.append(list(map(int, input().split())))

works = sorted(works, key=lambda x: x[1])

def ans(works):
    time = 0
    for work in works:
        time += work[0]
        if time > work[1]:
            print("No")
            return
    print("Yes")
    return

ans(works)


Measured memory_bytes: 55180
#include<iostream>
using namespace std;
int main(){
  int N, p[10], max=0;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> p[i];
  }
  sort(p, p+N);
  int ans = 0;
  for(int i=0; i<N-1; i++){
    ans += p[i];
  }
  cout << ans+p[N-1]/2 << endl;
  return 0;
}

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

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

  int num = 0;
  while(N >= K) {
    N /= K;
    num++;
  }

  cout << num+1 << endl;
}


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


using namespace std;


using ll = long long;


int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> member(N, 0);
    vector<ll> foods(N, 0);

    for (ll i = 0; i < N; i++) {
        cin >> member[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> foods[i];
    }

    sort(member.begin(), member.end());
    sort(foods.rbegin(), foods.rend());

    ll l = -1, r = 1200000000000LL;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        ll diff = 0;
        for (ll i = 0; i < N; i++) {
            diff += max(0LL, member[i] - (m / foods[i]));
        }
        if (diff <= K) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << endl;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

vector<int> alphabet(26, 1e9);

int main(){
    int n;
    cin >> n;
    rep(i, n){
        string s;
        cin >> s;
        vector<int> al(26, 0);
        rep(j, s.size()){
            int c = s[j] - 'a';
            al[c]++;
        }
        rep(j, 26){
            alphabet[j] = min(alphabet[j], al[j]);
        }
    }

    rep(i, 26){
        rep(j, alphabet[i]){
            char c = 'a' + i;
            cout << c;
        }
    }
    cout << endl;

    return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 105;

int n;

int main() {

	FAST;

	cin >> n;
	vector <int> cnt(n + 1), num(N);
	for (int i = 2; i <= n; i ++) {
		int tmp = i;
		for (int j = 2; j * j <= i; j ++) {
			if (tmp % j == 0) {
				while (tmp % j == 0) {
					cnt[j] ++;
					tmp /= j;
				}
			}
		}
		if (tmp != 1) cnt[tmp] ++;
	}
	for (int i = n; i >= 0; i --) {
		num[i] = num[i + 1];
		for (int j = 1; j <= n; j ++) {
			if (cnt[j] == i) num[i] ++;
		}
	}
	int ans = num[74];
	ans += num[24] * (num[2] - 1);
	ans += num[14] * (num[4] - 1);
	ans += num[4] * (num[4] - 1) / 2 * (num[2] - 2);
	cout << ans << '\n';
	return 0;
}

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

int bsort(int *A, int N) {
  auto flag = true;
  int temp;
  auto cnt = 0;
  while (flag) {
    flag = false;
    for (auto i = N - 1; i > 0; i--) {
      if (A[i] < A[i-1]) {
        temp = A[i];
        A[i] = A[i-1];
        A[i-1] = temp;
        flag = true;
        cnt++;
      }
    }
  }
  return cnt;
}

int main(void) {
  int N, A[100];
  
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  
  auto cnt = bsort(A, N);
  
  for (int i = 0; i < N; i++) {
    if (i != 0) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3084
#include <iostream>

long long count[200001];

int main()
{
    long long n;
    std::cin>>n;
    long long a;
    for (long long i=1;i<n;i++)
    {
        std::cin>>a;
        count[a]++;
    }
    for (long long i=0;i<n;i++)
    {
        std::cout<<count[i+1]<<"\n";
    }
}

Measured memory_bytes: 5152
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
string a;
int n,zi[200005],mu[200005],_2[200005],_5[200005],sum[105][55],ans;
int gcd(int A,int B)
{
    return A%B?gcd(B,A%B):B;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a;
        mu[i]=1;
        bool g=false;
        for(int j=0;j<(int)a.length();++j)
        {
            if(a[j]=='.')
            {
                g=true;
            }
            if('0'<=a[j]&&a[j]<='9')
            {
                zi[i]=(zi[i]<<3)+(zi[i]<<1)+(a[j]^'0');
                if(g)
                {
                    mu[i]=(mu[i]<<3)+(mu[i]<<1);
                }
            }
        }
        while(zi[i]%2==0)
        {
            zi[i]/=2;
            ++_2[i];
        }
        while(zi[i]%5==0)
        {
            zi[i]/=5;
            ++_5[i];
        }
        while(mu[i]%2==0)
        {
            mu[i]/=2;
            --_2[i];
        }
        while(mu[i]%5==0)
        {
            mu[i]/=5;
            --_5[i];
        }
        ++sum[_2[i]+50][_5[i]+25];
    }
    for(int i=-50;i<=50;++i)
    {
        for(int j=-25;j<=25;++j)
        {
            for(int i1=-i;i1<=50;++i1)
            {
                for(int j1=-j;j1<=25;++j1)
                {
                    ans+=sum[i+50][j+25]*sum[i1+50][j1+25];
                }
            }
        }
    }
    for(int i=1;i<=n;++i)
    {
        if(_2[i]>=0&&_5[i]>=0)
        {
            --ans;
        }
    }
    ans>>=1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9848
#include<stdio.h>

int main(){
  long long n;
  scanf("%lld",&n);
  long long ans[n+1];
  for(long long i=1;i<=n;i++)ans[i]=0;
  
  for(long long a=1;a<=100;a++){
    for(long long b=a;b<=100;b++){
      for(long long c=b;c<=100;c++){
        if((a+b)*(a+b)+(c+b)*(c+b)+(a+c)*(a+c)<=2*n){
          if(a==c){
            ans[((a+b)*(a+b)+(c+b)*(c+b)+(a+c)*(a+c))/2]+=1;
          }else if(a==b || b==c){
            ans[((a+b)*(a+b)+(c+b)*(c+b)+(a+c)*(a+c))/2]+=3;
          }else{
            ans[((a+b)*(a+b)+(c+b)*(c+b)+(a+c)*(a+c))/2]+=6;
          }
        }
      }
    }
  }
  
  for(long long i=1;i<=n-1;i++){
    printf("%lld\n",ans[i]);
  }
  printf("%lld",ans[n]);
  return 0;
}



Measured memory_bytes: 2148
using System;
using System.Linq;

namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
				var h = array[0];
				var w = array[1];

				if( h == 0 && w == 0)
				{
					return;
				}

				for(var i = 0; i < h; i++)
				{
					for(var j = 0; j < w; j++)
					{
						if((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
						{
							Console.Write("#");
						}
						else
						{
							Console.Write(".");
						}
					}
					Console.WriteLine();
				}
				Console.WriteLine();
			}
		}
	}
}



Measured memory_bytes: 18404
/*****************************************************///
/*.......................Faiyaj Bin Amin............................*///
/*...................................................................*///
/*.........................KUET CSE 2K17......................*///
/*...................................................*///
/*****************************************************///


#include<bits/stdc++.h>

#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define sf(n) scanf("%d", &n);
#define sff(n, m) scanf("%d %d", &n, &m);
#define pf(n) printf("%d", n);
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)  /// type rep(t, 1, n+1) when t is to be iterated from 1 to n
#define rrep(q, i, n) for(int q=i; q>n; q--)
#define mems(a,x) memset(a,x,sizeof(a))
#define io ios_base::sync_with_stdio;cin.tie(0);cout.tie(0)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>
#define pll pair<ll,ll>

#define watch(x) cout << (#x) << " is " << (x) << endl

#define gcd(a, b)  __gcd(a, b)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define PI 2*acos(0.0)

#define mx 100005
#define MAX 1000000005
#define inf 1e9
#define INF 1e18
#define MOD 1000000007
////#define MOD 4294967296another
#define MIN 0

////
////------------------------------Graph Moves----------------------------
////const int fx[]={+1,-1,+0,+0}; // Directional
////const int fy[]={+0,+0,+1,-1};
////const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
////const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
////const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
////const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
////---------------------------------------------------------------------
////
////*------------------------------------BITMASK------------------------------------------*
////int Change(int N, int pos){return N= N^(1<<pos);}
////bool Check(int N, int pos){return (bool)(N &(1<<pos));}
////*-----------------------------------------------------------------------------------------------*

using namespace std;


ll l[2003][2003] = {0};

void buildPascal(int k)
{

    l[0][0] = 1;
    for (int i = 1; i <=k; i++)
    {
        l[i][0] = 1;
        for (int j = 1; j <=i; j++)
        {
            l[i][j] = (l[i - 1][j - 1]%MOD + l[i - 1][j]%MOD)%MOD;
        }
    }
}

int main()
{
    int k, n;
    scanf("%d %d", &n, &k);
    buildPascal(2001);

////    rep(i, 0, k+1)
////    {
////        rep(j, 0, k+1)
////        {
////            cout << l[i][j] << " ";
////        }
////        cout << endl;
////    }

    ll a, b, red;
    rep(i, 1, k+1)
    {
        red = n-k;
        a = l[red+1][i];
        b = l[k-1][i-1];
        printf("%lld\n", (a*b)%MOD);
    }

    return 0;
}


Measured memory_bytes: 30080
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 1;
	long X , Y; cin >> X >> Y;

	long beki = X;

	while (beki <= Y) { beki *= 2;res++ ; }

    res--;
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-m;i++){
        if(a[i]<a[i+m]){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}


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

using namespace std;
const int maxn = 1e3 + 5;
int a[maxn];
int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] % 2 == 0)
            cnt++;
    }
    cout << pow(3, n) - pow(2, cnt) << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  int N, Q; cin >> N >> Q;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  vector<ll> sum(N+1), sum2(N+1);
  sum[1] = sum2[1] = v[0];
  for (int i = 2; i < N+1; i++) {
    sum[i] = sum[i-1] + v[i-1];
    sum2[i] = sum2[i-2] + v[i-1];
  }
  map<int, ll> m;
  m[0] = sum[N/2];
  int l = 0, r = N/2;
  for (; l < r;) {
    if (r - l > N - 1 - r) {
      l++; continue;
    }
    int thr = (v[r] + v[l]) / 2 + 1;
    ll s = sum[r+1] - sum[l+1];
    s += sum2[l];
//    cout << l << " " << r << " " << thr << " " << s << endl;
    m[thr-1] = s;
    r++;
  }
  for (auto p : m) {
//    cout << p.first << " " << p.second << endl;
  }
  while (Q--) {
    int x; cin >> x;
    cout << sum[N] - (--m.lower_bound(x))->second << endl;
  }
}

Measured memory_bytes: 6784
n = int(input())
s = [input() for _ in range(n)]
ab = 0
ba = 0
last_a = 0
first_b = 0
for i in range(n):
  if s[i][0] == "B" and s[i][-1] == "A":
    ba += 1
  elif s[i][-1] == "A":
    last_a += 1
  elif s[i][0] == "B":
    first_b += 1
  ab += s[i].count("AB")
if last_a == 0 and first_b == 0:
  print(ab+ba-1) if ba != 0 else print(ab)
else:
  print(ab+ba+min(last_a,first_b))

Measured memory_bytes: 44760
// Hacheylight
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 60 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void print(T a) { cout << a << endl ; exit(0) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
template <class T> void add(T &a, T b) { a = (1ll * a + b) % MOD ; }
template <class T> void mul(T &a, T b) { a = (ll) a * b % MOD ; }
template <class T> T read() {
    int f = 1 ; T x = 0 ;
    char ch = getchar() ;
    while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
    while (isdigit(ch)) { x = x * 10 + ch -'0' ; ch = getchar() ; }
    return x * f ;
}

int n ;
ll ans ;
map <pair<string, string> , int> hsh ;
char s[N] ;

signed main() {
	scanf("%d", &n) ;
	scanf("%s", s) ;
	rep(msk, 0, (1 << n) - 1) {
		string a = "", b = "" ;
		rep(i, 0, n - 1)
		if (msk & (1 << i))
		a += s[i] ;
		per(i, n - 1, 0)
		if (!(msk & (1 << i)))
		b += s[i] ;
		hsh[mp(a, b)]++ ;
	}
	rep (msk, 0, (1 << n) - 1) {
		string a = "", b = "" ;
		rep(i, 0, n - 1)
		if (msk & (1 << i))
		a += s[n + i] ;
		per(i, n - 1, 0)
		if (!(msk & (1 << i)))
		b += s[n + i] ;
		ans += hsh[mp(b, a)] ;
	}
	printf("%lld\n", ans) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/





Measured memory_bytes: 91904
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int ar[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
  int k;
  cin>>k;
  k--;
  cout<<ar[k]<<endl;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    string s;
    cin >> s;
    
    irep(i, s.size()/2) {
        if(s[i] != s[s.size()-i-1]) {
            cout << "No" << endl;
            return 0;
        } 
    }
    cout << "Yes" << endl;
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<string, int> si;
typedef vector<string> vs;
const int INF = 1 << 29;
#define mp make_pair
#define fi first
#define se second

int main() {
    ios::sync_with_stdio(false);
    vs data(100);
    int n, l;
    cin >> n >> l;
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    bool move = true;
    for (int i = 0; move && i < n; i++) {
        move = false;
        for (int j = n - 1; j > i; j--) {
            if (data[j] < data[j - 1]) {
                swap(data[j], data[j - 1]);
                move = true;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << data[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
local n, t = string.match(io.read(), "(%d+) (%d+)")
local na, ta = string.match(io.read(), "(%d+) (%d+)")
n, t = tonumber(n), tonumber(t)
na, ta = tonumber(na), tonumber(ta)

local min = {
    n = na,
    t = ta,
}

for i = 2, n do
    na, ta = string.match(io.read(), "(%d+) (%d+)")
    na, ta = tonumber(na), tonumber(ta)

    if ta <= t and na < min.n then
        min.n = na
        min.t = ta
    end
end

if t < min.t then
    print("TLE")
else
    print(min.n)
end


Measured memory_bytes: 760
#include<iostream>
using namespace std;
int search(int* arr, int m, int i,int n) {
	if (m == 0) return 1;
	if (i > n)	return 0;
	return (search(arr, m, i + 1, n) || search(arr, m - arr[i], i + 1, n));
}
int main() {
	int n;
	cin >> n;
	int* arr = new int[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int m;
	cin >> m;
	int* query = new int[m];
	for (int i = 0; i < m; i++)
		cin >> query[i];
	for (int i = 0; i < m; i++) {
		if (search(arr, query[i], 0, n - 1))
			cout << "yes\n";
		else
			cout << "no\n";
	}
	return 0;
}


Measured memory_bytes: 3092
n, k = gets.chomp.split(" ").map(&:to_i)
inputs = []
count = 0
ans = -1
n.times do
    inputs << gets.chomp.split(" ").map(&:to_i)
end
inputs.sort!{|a, b| a[0] <=> b[0]}

inputs.each do |a, b|
    count += b
    if count >= k
        ans = a
        break
    end
end

puts ans

Measured memory_bytes: 10512
//ABC108C.cpp
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	long long N,K,x,max=0,n,count=0,temp;
	cin>>N>>K;
	if(K%2==0){
		x=K/2;
		for(int i=1;i<=N+1;i++){
			if(i*x>N){
				n=i-1;
				break;
			}
		}
//		cout<<x<<" "<<N<<" "<<K<<endl;
//		cout<<"n="<<n<<endl;
		if(n%2==1){
			temp=(n-1)/2;
			count+=temp*temp*temp;
			temp++;
			count+=temp*temp*temp;
		}else{
			temp=n/2;
			count+=temp*temp*temp;
			count+=temp*temp*temp;
		}
	}else{
		temp=N/K;
		count=temp*temp*temp;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256