akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
#define MAX 500000
#define SENTINET 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void Merge(int A[] , int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0 ; i < n1; i++)  L[i] = A[left+i];
    for(int j = 0 ; j < n2; j++)  R[j] = A[mid+j];
    L[n1] = R[n2] = SENTINET;
    int i = 0, j = 0;
    for( int k = left; k < right; k++){
        cnt++;
        if(L[i] <= R[j])
            A[k] = L[i++];
        else
            A[k] = R[j++];
    }
}

void mergeSort(int A[] , int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A , left , mid);
        mergeSort(A , mid , right);
        Merge(A , left , mid , right);
    }
}
int main()
{
    int A[MAX], n , i;
    cnt = 0;

    cin >> n;
    for(i = 0 ; i < n ; i++)  cin >> A[i];

    mergeSort(A,0,n);

    for( i = 0 ; i < n ; i++){
        if(i) cout << " ";
        cout << A[i];
    }

    cout << endl;

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 6984
// Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		for(int i=0; i<n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;

			if(pm==100||pe==100||pj==100){
				cout << 'A' << '\n';
			}
			else if((pm+pe)/2>=90){
				cout << 'A' << '\n';
			}
			else if((pm+pe+pj)/3>=80){
				cout << 'A' << '\n';
			}
			else if((pm+pe+pj)/3>=70){
				cout << 'B' << '\n';
			}
			else if((pm+pe+pj)/3>=50&&(pm>=80||pe>=80)){
				cout << 'B' << '\n';
			}
			else{
				cout << 'C' << '\n';
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
/*
  Fuad Ashraful Islam
  University of Asia Pacific,Bangladesh
  Date:12th April 2020
  TODO:
 */
#include<bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pb push_back

using namespace std;
template <class T>
inline void read(T &res)
{
  res = 0; bool bo = 0; char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-');
  if (c == '-') bo = 1; else res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + (c - 48);
  if (bo) res = ~res + 1;
}
typedef long long ll;
const int N=1e5+1;
int len,_,n,k,m,l,c,cs=1;


vector<int>pos[3];

int getIdx(char ch)
{
  if(ch=='R')return 0;
  else if(ch=='G')return 1;
  return 2;
}
bool color[4];
ll bin_search(int idx,int l)
{
  int s=pos[idx].size();
  int lo=lower_bound(all(pos[idx]),l)-pos[idx].begin();
 // cout<<"ret "<<s-lo<<endl;
  return s-lo;
}//end func
void Solve()
{
  string s;
  cin>>n;
  cin>>s;
  len=s.size();
 // cout<<s<<endl;

  for(int i=0;i<len;++i)
  {
    // cout<<getIdx(s[i])<<endl;
    pos[getIdx(s[i])].push_back(i);
  }
  
  ll ans=0LL;
  for(int i=0;i<len;++i)
  {
    for(int j=i+1;j<len;++j)
    {
      if(s[i]==s[j])continue;
      color[0]=0;
      color[1]=0;
      color[2]=0;
      color[getIdx(s[i])]=1;
      color[getIdx(s[j])]=1;
      for(int idx=0;idx<3;++idx)
      {
        if(color[idx])continue;
        ans+=bin_search(idx,j+1);
        int dif=j-i;
        if(j+dif<len)
        {
          if(getIdx(s[j+dif])==idx)ans-=1;
        }
      }
       
    }
  }

  cout<<ans<<"\n";

}
int main()
{
  Solve();
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int a;
  cin >> a, a--;
  cout << a / 2 << "\n";
}

Measured memory_bytes: 3632
def main():
    H, W = map(int, input().split())
    matrix = [list(input()) for _ in range(H)]
    count_matrix = [[0 for _ in range(W)] for _ in range(H)]

    # 横方向についてカウントする
    for i in range(H):
        start = 0
        count = 0
        for j in range(W):
            s = matrix[i][j]
            if s == '.':
                count += 1
                if j == W-1:
                    for k in range(start, j+1):
                        count_matrix[i][k] += count
            else:
                for k in range(start, j):
                    count_matrix[i][k] += count
                start = j+1
                count = 0

    # 縦方向についてカウントする
    for i in range(W):
        start = 0
        count = 0
        for j in range(H):
            s = matrix[j][i]
            if s == '.':
                count += 1
                if j == H-1:
                    for k in range(start, j+1):
                        count_matrix[k][i] += count
            else:
                for k in range(start, j):
                    count_matrix[k][i] += count
                start = j+1
                count = 0
    
    max_val = 0
    for i in range(H):
        for j in range(W):
            max_val = max(max_val, count_matrix[i][j])
    print(max_val-1)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 221832
num = gets.to_i

array = [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]

puts array[num - 1]


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

int main() {
  int N, K, sum = 0;
  cin >> N >> K;

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

    if (K < x) {
      sum += x - K;
    } else if (K/2 < x) {
      sum += K - x;
    } else {
      sum += x;
    }
  }

  cout << sum * 2;
}


Measured memory_bytes: 3608
n, m = map(int, input().split())
a = ['' for _ in range(n)]
for i in range(n):
    x = list(map(int, input().split()))
    a[i] = x
b = sorted(a)
cnt = 0
tmp = 0
ans = 0
for i in range(n):
    tmp += b[i][1]
    if tmp < m:
        ans += b[i][0] * b[i][1]
        cnt = tmp
    else:
        ans += (m - cnt) * b[i][0]
        break
print(ans)


Measured memory_bytes: 28580
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> v[100011];
int d[2][100011],id=0;
void dfs(int idx,int par=-1)
{
	if(~par)//if(par!=-1)
	d[id][idx]=d[id][par]+1;
	for(int i=0;i<v[idx].size();i++)//for(auto &to:g[idx])
	if(v[idx][i]!=par)//if(to!=par)
	dfs(v[idx][i],idx);//dfs(to,idx);
}
int main()
{
	cin >>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin >>a>>b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	id=0;
	dfs(0);
	id=1;
	dfs(n-1);
	int ans=0;
	for(int i=0;i<n;i++)
	if(d[0][i]<=d[1][i])
	ans++;
	if(ans>=n/2+1)
	puts("Fennec");
	else
	puts("Snuke");
	return 0;
}

Measured memory_bytes: 11136
N = int(input())
A = list(map(int,input().split()))
up_lift = [0]*N
down_lift = [0]*N
for i in range(N):
    if i + A[i] < N:
        up_lift[i + A[i]] += 1
    if i - A[i] >= 0:
        down_lift[i - A[i]] += 1


ans = 0
for i in range(N):
    ans += up_lift[i] * down_lift[i]
print(ans)

Measured memory_bytes: 32184
#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
const int N = 3e5 + 233;
int n, S;
pair<int, int> a[N];

main(void) {
  read(n); read(S);
  for (int i = 1; i <= n; i ++) {
    read(a[i].first), read(a[i].second);
  }
  a[++ n] = {S, 1e16};
  sort(a + 1, a + n + 1);
  vector<int> q;
  int l = 1, r = n;
  while (l <= r) {
    if (l == r) {
      q.push_back(l);
      break;
    }
    int &q1 = a[l].second;
    int &q2 = a[r].second;
    if (q1 < q2) q2 += q1, q.push_back(l ++);
    else q1 += q2, q.push_back(r --);
  }

  // for (int u: q) cout << u << " "; puts("");
  reverse(q.begin(), q.end());
  int mx = 0, pos = S;
  for (int u: q) {
    mx += abs(pos - a[u].first);
    pos = a[u].first;
  }
  cout << mx << "\n";
}


Measured memory_bytes: 2936
from collections import Counter 

n = int(input())
a = list(map(int, input().split()))
co = Counter(a)
q = int(input())
ans = 0
for i in co.items():
    ans += i[0] * i[1]
for _ in range(q):
    b, c = map(int, input().split())
    if b in co.keys():
        ans -= b * co[b]
        co[c] += co[b]
        ans += c * co[b]
        co[b] = 0
    print(ans)

Measured memory_bytes: 21604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		for (int i=0; i<n; i++) {
			int val = scan.nextInt();
			if (val>max) {
				max=val;
			}
			if (val<min) {
				min=val;
			}
		}
		System.out.println(max-min);
		scan.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    double A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int maxW = A * 100, maxS = 0;
    double maxC = 0.0;

    for (int m = 0; m <= 30; m++) {
        for (int n = 0; n <= 30; n++) {
            double water = 100 * (A * m + B * n);
            double rest = F - water;
            if (rest <= 0) continue;

            double upperS = min((A * m + B * n) * E, rest);
            double sugar = 0;
            for (int s = 0; C * s <= upperS; s++) {
                int t = (upperS - C * s) / D;
                sugar = max(sugar, C * s + D * t);
            }

            double curC = sugar / (water + sugar);
            if (curC > maxC) { maxC = curC, maxW = water, maxS = sugar; }
        }
    }

    cout << maxW + maxS << ' ' << maxS << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int n, sum = 0;
    cin >> n;
    vector<int>as(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
        sum += as[i];
    }
    sort(as.begin(), as.end());
    if (2 * as[n - 1] < sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=105;
const int INF=0x3f3f3f3f;
int n,r[N],c[N],f[N][N];
int dp(int i,int j){
	if(f[i][j])return f[i][j];
	if(i==j)return f[i][j]=0;
	if(i+1==j)return f[i][j]=r[i]*c[i]*c[j];
	int ans=INF;
	for(int k=i;k<j;k++){
		ans=min(ans,dp(i,k)+dp(k+1,j)+r[i]*c[k]*c[j]);
	}
	return f[i][j]=ans;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&r[i],&c[i]);
	}
	printf("%d\n",dp(1,n));
	return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
     
      long long a, b, k;

      cin >> a >> b >> k;
      if(a >= k) {
        cout << a - k << " " << b << endl;
      }
      else if(a + b >= k) {
        cout << 0 << " " << a + b - k << endl;
      }
      else {
        cout << 0 << " " << 0 << endl;
      }
    }


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

using namespace std;

int main(void) {
  int n, a, b;
  cin >> n >> a >> b;

  if((b - a) % 2 == 0) {
    cout << "Alice" << endl;
  }
  else {
    cout << "Borys" << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  int num = 0;
  rep(i, n) num ^= A[i];
  rep(i, n) {
    int ans;
    ans = num ^ A[i];
    cout << ans;
    if (i < n-1) cout << ' ';
    else cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  int N;
  string S;
  cin >> N >> S;
  //R,G,Bが何番目に来るかそれぞれ記録
  vector<ll> R; 
  vector<ll> G;
  vector<ll> B;
  
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R') {
      R.push_back(i);
    }
    else if (S.at(i) == 'G') {
      G.push_back(i);
    }
    else {
      B.push_back(i);
    }
  }
  ll r = R.size();
  ll g = G.size();
  ll b = B.size(); //r*g*bでとりあえず色が違う選び方になる(条件1)
  
  ll reigai = 0;
  for (int i = 1; i < N-1; i++) {
    char n = S.at(i);
    ll count = 0;
    ll range = 1;
    while ((i-range >=0) && (i+range <= N-1)) {
      if ((S[i-range] != n) && (S[i+range] != n) && (S[i-range] != S[i+range])) {
        count++;
      }
      range++;
    }
    reigai += count;
  }
  
  ll zenbu = r*g*b;
  cout << zenbu - reigai << endl;
}


Measured memory_bytes: 3660
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int[] x = {a, b, c};
		Arrays.sort(x);
		int ans = 0;
		if(x[0] == x[1] && x[1] == x[2]) {
			System.out.println(0);
			return;
		}
		while(x[2] > x[1]) {
			x[1]++;
			x[0]++;
			ans++;
		}
		while(x[1] > x[0]) {
			x[0] += 2;
			ans++;
		}
		if(x[0] == x[1]) {
			System.out.println(ans);
		} else {
			System.out.println(ans + 1);
		}
	}
}


Measured memory_bytes: 21972
# 前日の行動と、当日の行動から最大値を求める。


N = int(input())
dp = [[0, 0, 0] for i in range(N)]
H = []


for i in range(N):
    l = list(map(int, input().split()))
    H.append(l)

dp[0] = [H[0][0], H[0][1], H[0][2]]

for i in range(1, N):
    # 現在の選択肢
    for k in range(3):
        # 過去の選択肢
        for j in range(3):
            if j == k:
                continue
            else:
                dp[i][j] = max(dp[i][j], (dp[i - 1][k] + H[i][j]))
print(max(dp[N - 1]))


Measured memory_bytes: 50308
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a.begin(),a.end());

	cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
// atcoder/abc047/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    bool f = (a + b == c) || (a + c == b) || (b + c == a);
    cout << (f ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
    double r;
    cin>>r;
    cout<<fixed << setprecision(5)<<r*r*M_PI<<' '<<fixed << setprecision(5)<<2*r*M_PI<<endl;
    return 0;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,c;
	cin>>a>>b>>c;
	bool flag=false;
	ll t=c-a-b;
	if(t>0&&t*t>4*a*b){
		flag=true;
	}
	if(flag) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N = input()

if (N[-1:] == '2')|(N[-1:] == '4') | (N[-1:] == '5') |(N[-1:] == '7') |(N[-1:] == '9'):
    print("hon")
elif (N[-1:] == '0') | (N[-1:] == '1') | (N[-1:] == '6') | (N[-1:] == '8'):
    print("pon")
else :
    print("bon")


Measured memory_bytes: 9116
// Problem : B - FizzBuzz Sum
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	long long sum = 0;
	
	int n;
	
	cin >> n;
	
	

	for(int i = 1; i <= n; i++){
		if (i % 3 == 0 && i % 5 == 0){
			continue;
		}else if (i % 3 == 0){
			continue;
		}else if (i % 5 == 0){
			continue;
		}
		sum += i;
	}
	
	cout << sum << endl;
	return 0;	
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define maxn 310
using namespace std;
int arr[maxn][maxn];
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	bool isedge[maxn][maxn];
	int n; cin>>n;
	for (int i = 0; i < n; ++i)
		for(int j = 0; j < n; j++){
			cin>>arr[i][j];
			isedge[i][j] = true;
		}
	bool error = false;

	for (int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; j++){
			if(i >= j) continue;
			for(int k = 0; k < n; k ++){
				if(i == k || j == k)
					continue;
				if(arr[i][k] + arr[k][j] < arr[i][j])
					error = true;
				if(arr[i][k] + arr[k][j] == arr[i][j])
					isedge[i][j] = false;
			}
		}
	}
	if(error){
		cout<<"-1\n";
		return 0;
	}
	long long answer = 0;
	for (int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; j++){
			if(i < j && isedge[i][j])
				answer += arr[i][j];
			// cout<<isedge[i][j]<<" ";
		}
		// cout<<"\n";
	}
	cout<<answer<<endl;
	return 0;
}

Measured memory_bytes: 768
s=input()
n=len(s)
dp=[[0,0] for i in range(n)]
dp[0][0]=1
for i in range(1,n):
    dp[i][0]=dp[i-1][1]+1
    if s[i-1]!=s[i]:
        dp[i][0]=max(dp[i][0],dp[i-1][0]+1)
    if i>1:
        dp[i][1]=dp[i-2][0]+1
        if i>2:
            if s[i-3:i-1]!=s[i-1:i+1]:
                dp[i][1]=max(dp[i][1],dp[i-2][1]+1)
print(max(dp[n-1]))

Measured memory_bytes: 99376
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int dp[22][50010];
int n,m;
int c[22];
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)scanf("%d",&c[i]);
	for(int i=0;i<=m;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=INF;
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<=n;j++){
			dp[i+1][j]=dp[i][j];
			if(j>=c[i])chmin(dp[i+1][j],dp[i+1][j-c[i]]+1);
		}
	}
	/*for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}*/
	cout << dp[m][n] << endl;
	return 0;
}


Measured memory_bytes: 7248
#include<stdio.h>

int odd[100001];
int even[100001];
int n, odd1, odd2, even1, even2, i, j, k;

int max(int a, int b);

int main(){
	if(scanf("%d", &n));
	for(i=0; i<n; i+=2){
		if(scanf("%d%d", &j, &k));
		odd[j]++;
		even[k]++;
	}
	for(i=0; i<100001; i++){
		if(odd[i] > odd[odd1]){
			odd2 = odd1;
			odd1 = i;
		}else if(odd[i] > odd[odd2]){
			odd2 = i;
		}
		if(even[i] > even[even1]){
			even2 = even1;
			even1 = i;
		}else if(even[i] > even[even2]){
			even2 = i;
		}
	}
	if(odd1 == even1){
		i = max(odd[odd1]+even[even2], odd[odd2]+even[even1]);
	}else{
		i = odd[odd1]+even[even1];
	}
	printf("%d", n-i);
	return 0;
}

int max(int a, int b){
	return (a<b?b:a);
}


Measured memory_bytes: 896
#include<bits/stdc++.h> 
using namespace std; 
long long n,m; 
int main()
{
    cin>>m>>n; 
    if(m<=((m*2)+n)/4)
        cout<<((m*2)+n)/4<<endl; 
    else cout<<n/2<<endl; 
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    ll n,k;cin>>n>>k;
    ll arr[n];
    rep(i,0,n)cin>>arr[i];
    sort(arr,arr+n);
    ll ans=0;
    rep(i,0,k)ans+=arr[i];
    cout<<ans;
return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1e+9 + 7;
// --------------------------------------------------------


const int MAX_N = 1e+5;
VI dp(MAX_N, 0);

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

    int N, K; cin >> N >> K;
    VI h(N); REP(i,N) cin >> h[i];

    FOR(i,1,N) {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        FOR(j,2,K+1) {
            if (i-j < 0) continue;
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[N-1] << '\n';

    return 0;
}
// https://atcoder.jp/contests/dp/tasks/dp_b


Measured memory_bytes: 3996
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = 0
for a, b in zip(A, A[1:]):
    cost += abs(a - b)
for i in range(1, N + 1):
    print(cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1])
          + abs(A[i - 1] - A[i + 1]))

Measured memory_bytes: 14048
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main(){
    
    char s[100];
    cin >> s;
    int num = strlen(s);
    int ans=0;
    for(int i=0;i<num/2;i++){
        if(s[i]!=s[num-i-1]){
            ans++;
        }
        else continue;
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 256
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(s) (intt)s.size()

#define ms0(arr) memset(arr,0,sizeof arr)
#define ms63(arr) memset(arr,63,sizeof arr)

#define forn(i,a,b) for(intt i=a;i<=b;i++)
#define rofn(i,a,b) for(intt i=a;i>=b;i--)
#define setf(it,myset) for(set<intt>::iterator it=myset.begin();it!=myset.end();it++)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define VI vector<intt>
#define PII pair<intt,intt>
#define VPII vector< PII >

#define posl(ch) (int)(ch-'a'+1)
#define posL(ch) (int)(ch-'A'+1)

#define IO ios_base::sync_with_stdio(false);cin.tie();
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a,intt b){return __gcd(a, b);}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}

/**************************/
const intt MAX = 100005;

intt xr[MAX];
intt trie[MAX][2], cnt[MAX], nxt = 1;

void add (string s) {
    intt node = 0;
    forn (i, 0, s.size() - 1)
        if (trie[node][s[i] - 48] == 0)
            node = trie[node][s[i] - 48] = nxt;
        else
            node = trie[node][s[i] - 48];
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    /*
    intt n, x, k;
    cin >> n >> x;
    forn (i, 1, n) {
        cin >> k;
        xr[i] = k ^ xr[i - 1];
    }
    */
    intt a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    sort(all(A));
    reverse(all(A));
    ll ans = 0;
    if (A[0] <= N*N) {
        if (A[0] >= N) {
        while (true) {
            bool ok = true;
            rep(i,N) {
                if (i) A[i]++;
                else A[i] -= N;
                if (A[i] >= N) ok = false;
            }
            ans++;
            if (ok) break;
            sort(all(A));
            reverse(all(A));
        }
    }
    }
    for (int i = 1; i < N; i++) {
        if (A[0] < N) break;
        ll val = A[0] - A[i];
        ll cnt = val/(N+1);
        ans += cnt*i;
        rep(j,N) {
            if (j < i) A[j] -= cnt*(N+1-i);
            else A[j] += cnt*i;
        }
        //sort(all(A));
        //reverse(all(A));
    }
    ll K = A[0];
    ans += max(K-3*N,0LL)*N;
    rep(i,N) A[i] -= max(K-3*N,0LL);
    if (A[0] >= N) {
        while (true) {
            bool ok = true;
            rep(i,N) {
                if (i) A[i]++;
                else A[i] -= N;
                if (A[i] >= N) ok = false;
            }
            ans++;
            if (ok) break;
            sort(all(A));
            reverse(all(A));
        }
    }
    cout << ans << ln;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;
int main() {
	int a;
	cin >> a;
	if (a % 2 == 1) cout << ((a + 1) / 2.0)/a << endl;
	else cout << (a / 2.0)/a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
vector< int > ans;
vector< bool > done;
vector< vector< edge > > G;
void dfs(int x, int k) {
	done[x] = true;
	int c = 1;
	rep(i, G[x].size()) {
		edge e = G[x][i];
		if (done[e.to])
			continue;
		if (c == k)
			c++;
		ans[e.d] = c;
		dfs(e.to, c);
		c++;
	}
}
signed main() {
	cin >> N;
	ans.assign(N - 1, 0);
	done.assign(N, false);
	G.assign(N, edges(0));
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		G[a].push_back(edge(a, b, i));
		G[b].push_back(edge(b, a, i));
	}
	dfs(0, 0);
	int ans2 = 0;
	rep(i, N - 1) chmax(ans2, ans[i]);
	cout << ans2 << endl;
	rep(i, N - 1) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 12288
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    K = si()
    ans = 0
    q = [0]*201
    for i in range(1, K+1):
        for j in range(1, K+1):
            q[gcd(i, j)] += 1

    for k in range(1, K+1):
        for i in range(1, K+1):
            ans += gcd(i, k)*q[i]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67832
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int n,k,q,ans;
int a[2010],b[2010],c[2010];

int main(){
	cin >> n >> k >> q;
	int i,j;
	for(i=1;i<=n;i++){
		cin >> a[i];
	}
	ans = 1e9;
	for(i=1;i<n+1;i++){
		int l = 0;
		int cnt = 0;
		for(j=1;j<=n+1;j++){
			if(a[j]<a[i]){
				if(l==0){
					continue;
				}
				int r = j-1;
				for(int p=l;p<=r;p++){
					b[p] = a[p];
				}
				sort(b+l,b+r+1);
				for (int p=l;p+k-1<=r;p++){
					cnt++;
					c[cnt]=b[p];
				}
				l=0;
			}
			else if (l==0){
				l=j;
			}
		}
			if (cnt<q) {
				continue;
			}
			sort(c+1,c+cnt+1);
			ans=min(ans,c[q]-a[i]);
	}
		cout << ans << endl;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define eb emplace_back
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int>
#define sp fixed<<setprecision 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef pair<pii,pii> ppp;
typedef vector< pii > vp;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

template<typename T> 
void swap(T &a,T &b)
{ auto tm=a; a=b; b=tm; }

template<typename T> 
void mina(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void maxa(T& a, T b) { 
    a = max(a, b); 
}

  const int mod=1000000009;
  const int mod2=998244353;
  const int INF=1e18;
  const int N=2e5+25;  
  const int M=1e5+1;           


 void doit()
 { 
  int n; cin>>n;
  vi v;

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

     if(n%i==0){
       int ct=0;
       while(n%i==0) { ct++; n/=i; }
       v.pb(ct);
     }
  }

  int ans=0; if(n!=1) ans++;

  tr(i,v){
     int t=1;
     while(i-t>=0){
       ans++; i-=t; t++; 
     }
  }

  cout<<ans;

 }

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


  
   int tc=1;                         
   // cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
  
   doit();
   if(i<tc)
   cout<<nl;
  }
  
 

 return 0; 
}

Measured memory_bytes: 3636
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a,T  b) { return a<b?(a=b,true):false; }
#define forn(i,x,y) for(int i=(x);i<(int)(y);i++)
#define rep(i,y) for(int i=0;i<(int)(y);i++)
#define repb(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)

const int MAX_N = 200020;
int par[MAX_N]; // 親
int rank2[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n) {
  for (int i=0; i<n; i++) {
    par[i] = i;
    rank2[i] = 0;
  }
}

// 木の根を求める
int find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (rank2[x] < rank2[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank2[x] == rank2[y]) rank2[x]++;
  }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y) {
  return find(x) == find(y);
}

int n,m;
int cnt[200020];
int main() {
    cin >> n >> m;
    init(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        unite(a,b);
    }
    int mx = 0;
    rep(i,n) {
        int gr = find(i);
        cnt[gr]++;
        chmax(mx, cnt[gr]);
    }
    cout << mx << endl;
}

Measured memory_bytes: 5936
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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


// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main()
{
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 3; ++j)
      cin >> a[i][j];

  // 初期化は既に 0 に初期化される
  // 初期条件も既に 0 で OK

  // ループ
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      for (int k = 0; k < 3; ++k)
      {
        if (j == k)
          continue;
        chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
      }
    }
  }

  // 答え
  long long res = 0;
  for (int j = 0; j < 3; ++j)
    chmax(res, dp[N][j]);
  cout << res << endl;
}

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

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
int counter;

bool X[N][N];

void initialize(){
  for ( int i = 0; i < N; i++ ){ row[i] = FREE, col[i] = FREE; }
  for ( int i = 0; i < 2*N - 1; i++ ) { dpos[i] = FREE; dneg[i] = FREE; }
}

void printBoard(){
  for ( int i = 0; i < N; i++ ){
    for ( int j = 0; j < N; j++ ){
      if ( X[i][j] ){
        if ( row[i] != j ) return;
      }
    }
  }
  for ( int i = 0; i < N; i++ ){
    for ( int j = 0; j < N; j++ ){
      cout << (( row[i] == j ) ? "Q" : ".");
    }
    cout << endl;
  }
  counter++;
}

void recursive( int i ){
  if ( i == N ){
    printBoard(); return;
  }
  
  for ( int j = 0; j < N; j++ ){
   
    if ( col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE ) continue;
   
    row[i] = j; col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
   
    recursive( i + 1 );
   
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }

}

int main(){
  initialize();
  counter = 0;
  
  for ( int i = 0; i < N; i++)
    for ( int j = 0; j < N; j++ ) X[i][j] = false;
  
  int k; cin >> k;
  for ( int i = 0; i < k; i++ ){
    int r, c; cin >> r >> c;
    X[r][c] = true;
  }
  
  recursive( 0 );
  
  assert( counter == 1 );
  return 0;
}


Measured memory_bytes: 3116
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
	for j in range(N-i):
		if i+2*j>=N:
			break
		elif S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
			ans-=1
print(ans)


Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

bool check[1001][1001];

int main(void){
    ll h, w;
    cin >> h >> w;

    queue<pair<pair<ll, ll>, ll>> black;
    char map[h][w];
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> map[i][j];
            if(map[i][j] == '#'){
                pair<ll, ll> tmp = pair<ll, ll>(i, j);
                black.push(pair<pair<ll, ll>, ll>(tmp, 0));
                check[i][j] = true;
            }
        }
    }

    ll count = 0;
    while(black.size()){
        ll a = black.front().first.first;
        ll b = black.front().first.second;
        ll c = black.front().second;

        if(a > 0){
            if(!check[a - 1][b]){
                check[a - 1][b] = true;
                pair<ll, ll> tmp = pair<ll, ll>(a - 1, b);
                black.push(pair<pair<ll, ll>, ll>(tmp, c + 1));
            }
        }
        if(a < h - 1){
            if(!check[a + 1][b]){
                check[a + 1][b] = true;
                pair<ll, ll> tmp = pair<ll, ll>(a + 1, b);
                black.push(pair<pair<ll, ll>, ll>(tmp, c + 1));
            }
        }
        if(b > 0){
            if(!check[a][b - 1]){
                check[a][b - 1] = true;
                pair<ll, ll> tmp = pair<ll, ll>(a, b - 1);
                black.push(pair<pair<ll, ll>, ll>(tmp, c + 1));
            }
        }
        if(b < w - 1){
            if(!check[a][b + 1]){
                check[a][b + 1] = true;
                pair<ll, ll> tmp = pair<ll, ll>(a, b + 1);
                black.push(pair<pair<ll, ll>, ll>(tmp, c + 1));
            }
        }

        black.pop();
        count = max(count, c);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 26420
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s, t;
    cin >> s >> t;
    int a=s.size(), ans=0;
    for(int b=0;b<=a;b++){
        if(s[b]!=t[b])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  cout<<(n%2==0 ? n/2 : n/2+1)<<'\n';
  return(0);
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c=parseMap(split(readline()))
    println(ifelse(a+b>=c,"Yes","No"))
end
main()

Measured memory_bytes: 111792
use std::io;
use std::collections::VecDeque;


fn main() {
    let n = read_one::<usize>();
    let mut g = vec![Vec::new(); n];
    for i in 0..n - 1 {
        let (a, b) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1)
        };
        g[a].push((i, b));
        g[b].push((i, a));
    }

    let mut q = VecDeque::new();
    let mut colors = vec![0; n - 1];
    // (index, node, parent)
    q.push_back((0, 0, n + 1));
    while let Some((i, u, p)) = q.pop_front() {
        let mut color = 1;
        for &v in &g[u] {
            if v.1 == p { continue; }
            if colors[i] == color { color += 1; }
            colors[v.0] = color;
            q.push_back((v.0, v.1, u));
            color += 1;
        }
    }
    println!("{}", colors.iter().max().unwrap());
    for c in colors {
        println!("{}", c);
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 14716
def intervals (list)
    acc = []
    for i in 0..list.size - 2 do
        acc << list[i+1] - list[i]
    end
    acc
end

n,m = gets.split.map &:to_i
x   = gets.split.map &:to_i

if m - n <= 0
    puts 0
else
    puts intervals(x.sort).sort.take(m-n).reduce(:+)
end


Measured memory_bytes: 11248
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[5][5];
    int n,b,flag=0;

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) cin>>a[i][j];
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i][j]==b){
                    a[i][j]=0;
                    flag=1;
                    break;
                }
            }
            if(flag==1){ flag=0; break; }
        }
    }

    flag=0;

    if(a[0][0]==a[0][1] && a[0][1]==a[0][2]) flag=1;
    if(a[0][0]==a[1][0] && a[1][0]==a[2][0]) flag=1;
    if(a[0][2]==a[1][2] && a[1][2]==a[2][2]) flag=1;
    if(a[2][0]==a[2][1] && a[2][1]==a[2][2]) flag=1;
    if(a[0][1]==a[1][1] && a[1][1]==a[2][1]) flag=1;
    if(a[1][0]==a[1][1] && a[1][1]==a[1][2]) flag=1;
    if(a[0][0]==a[1][1] && a[1][1]==a[2][2]) flag=1;
    if(a[0][2]==a[1][1] && a[1][1]==a[2][0]) flag=1;
    
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

void solve(){
    int x,a,b;
    cin >> x;
    cin >> a;
    cin >> b;

    int al, bl;
    al = abs(x-a);
    bl = abs(x-b);
    if(al < bl) cout << "A" << endl;
    else cout << "B" << endl;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define N_MAX 100001

int main(void){
  int i, j;

  int n, q;
  long k;
  scanf("%d%ld%d", &n, &k, &q);

  int ans[N_MAX]={};

  int a;
  for(i=0; i<q; i++){
    scanf("%d", &a);
    ans[a]++;
  }

  for(i=1; i<=n; i++){
    if(q-ans[i] < k){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
template <int64_t N>
class modint {
    int64_t x;

public:
    modint(int64_t x = 0) : x((x % N + N) % N) {}
    modint operator-() const { return modint(-x); }
    modint& operator+=(const modint& a) {
        if ((x += a.x) >= N) x -= N;
        return *this;
    }
    modint& operator-=(const modint& a) {
        if ((x += N - a.x) >= N) x -= N;
        return *this;
    }
    modint& operator*=(const modint& a) {
        (x *= a.x) %= N;
        return *this;
    }
    modint operator+(const modint& a) const {
        return modint(*this) += a;
    }
    modint operator-(const modint& a) const {
        return modint(*this) -= a;
    }
    modint operator*(const modint& a) const {
        return modint(*this) *= a;
    }
    modint pow(int64_t t) const {
        if (not t) return 1;
        modint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    modint inv() const { return pow(N - 2); }
    modint& operator/=(const modint& a) {
        return (*this) *= a.inv();
    }
    modint operator/(const modint& a) const {
        return modint(*this) /= a;
    }
    friend ostream& operator<<(ostream& os,
                               const modint& m) {
        os << m.x;
        return os;
    }
};

const int64_t mod = 1e9 + 7;
using mint = modint<mod>;

int main() {
    int s;
    cin >> s;
    vector<mint> dp(s + 1, 0);
    dp[0] = 1;
    for (auto i = 3; i <= s; i++) {
        for (auto j = 0; j <= i - 3; j++) dp[i] += dp[j];
    }
    cout << dp[s] << endl;
    return 0;
}


Measured memory_bytes: 3644