akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll pos=0,neg=0,ans1=0,ans2=0;
    for(int i=0; i<n; i++)
    {
        ll a;
        cin>>a;
        if(!(i%2))
        {
            pos+=a;
            neg+=a;
            if(pos<=0)
            {
                ans1+=((-1)*pos+1);
                pos=1;
            }
            if(neg>=0)
            {
                ans2+=(neg+1);
                neg=-1;
            }
        }
        else
        {
            pos+=a;
            neg+=a;
            if(pos>=0)
            {
                ans1+=(pos+1);
                pos=-1;
            }
            if(neg<=0)
            {
                ans2+=((-1)*neg+1);
                neg=1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

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

using namespace std;
#define endl "\n"

const int MOD = 1e9 + 7;

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


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

	int ans = 0;
	int maxn = arr[0];
	for(int i=0; i<n; i++){
		if(arr[i] <= maxn){
			ans++;
			maxn = arr[i];
		}
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
const int maxn=200010;
const int inf=1e9;
int n;
ll ans;
int pre[maxn], Next[maxn];
int st[maxn], a[maxn];
int cnt[maxn];

void read(int& x){
	x=0; char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
}

void print(){ puts("Impossible"); exit(0); }

int main(){

	read(n);
	for(int i=1;i<=n;i++) read(a[i]), cnt[ a[i] ]++; 
	sort(a+1, a+1+n);
	int Max=a[n];
	int flag=1;
	if(Max&1){
		int r=Max/2+1;
		for(int i=r+1;i<=Max;i++) if(cnt[i]<2) print();
		for(int i=1;i<r;i++) if(cnt[i]) print();
		if(cnt[r]!=2) print();
	}else{
		int r=Max/2;
		for(int i=r+1;i<=Max;i++) if(cnt[i]<2) print();
		for(int i=1;i<r;i++) if(cnt[i]) print();
		if(cnt[r]!=1) print();
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int a[5];
    int min_a = 10, c = 6;
    rep(i, 5){
        cin >> a[i];
        if(a[i]%10 != 0 && min_a > a[i]%10){
            min_a = a[i]%10;
            c = i;
        }
    }

    int ans = 0;
    rep(i, 5){
        if(c == i){
            continue;
        }
        if(a[i]%10 == 0){
            ans += a[i];
        }
        else{
            ans += ((a[i]/10)+1) * 10;
        }
    }
    ans += a[c];

    cout << ans;

    return 0;
}

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

int main() {
  long long N, A, B; cin >> N >> A >> B;

  long long ans = 0;
  ans += (N / (A + B)) * A;

  long long tmp = N - (N / (A + B)) * (A + B);
  if (tmp >= A) ans += A;
  else ans += tmp;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
typedef signed long long ll;
#define FOR(i,to) for(i=0;i<(to);i++)

int64_t n; 

int main() {
	int i,j,k,l,r,x,y; string s;

    ll N;
    cin >> N;
    ll a[N];
    ll b[N];
    FOR(i,N) cin >> a[i] >> b[i];

    sort(a, a+N);
    sort(b, b+N);

    ll ans;
    if(N%2==0){
        if(N==2){
            ans = (b[0]-a[0]+1)+(b[1]-a[1]+1)-1;
            std::cout << ans << "\n";
        }else{
            ans = (b[N/2-1]-a[N/2-1]+1)+(b[N/2]-a[N/2]+1)-1;
            std::cout << ans << "\n";
        }
    }else{
        std::cout << b[(N+1)/2-1]-a[(N+1)/2-1]+1 << "\n";
    }
    return 0;
}


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

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

  vector<float> vec(N);

  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }

  float ave;

  for(int i=0;i<N;i++){
    ave+=vec.at(i)/N;
  }
  //cout << ave << endl;

  vector<float> sa(N);

 for(int i=0;i<N;i++){
    sa.at(i)=max(ave-vec.at(i), vec.at(i)-ave);
  } 

  sort(sa.begin(), sa.end());

 /*for(int i=0;i<N;i++){
    cout << sa.at(i) << endl;
  }*/

  for(int i=0;i<N;i++){
    if(sa.at(0)==max(ave-vec.at(i), vec.at(i)-ave)){
      cout << i << endl;
      break;
    }
  }

  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
	
	int w, s;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe\n";
	else
		cout << "safe\n";
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;


int main()
{
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        cout << 'x';
    }
    cout << endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int n;
   cin >> n;
   int R[n];
   int r;
   for(int i=0;i<n;i++){
       cin >> r;
       R[i]=r;
   }
   int minv = R[0];
   int maxv=R[1]-R[0];
   for(int j=1;j<n;j++){
       if(maxv<R[j]-minv){
           maxv=R[j]-minv;
       }
       if(minv>R[j]){
           minv=R[j];
       }
   }
   cout << maxv << endl; 
}



Measured memory_bytes: 3868
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int N;

	cin >> N;

	int H[N];

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

	int m = H[0];
	int ans = 1;

	for(int i = 1; i<N; i++){
		m = max(m, H[i-1]);
		if(m <= H[i]) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <list>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

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

  vector<int> v(n);
  for (int& e : v) cin >> e;

  vector<int> dp(n, 0);
  for (int i = 1; i < n; i++) {
    int& t = dp[i];
    t = 0x3f3f3f3f;

    for (int j = 1; j <= k; j++) {
      if (i >= j) t = min(t, dp[i - j] + abs(v[i] - v[i - j]));
    }
  }

  cout << dp.back() << endl;

  return 0;
}


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

int main(){
  int X;
  cin >> X;
  int a=360,i=1;
  while(true){
    int b=a*i;
    if(b%X==0){
      cout << b/X << endl;
      break;
    }
    i++;
  }
}

Measured memory_bytes: 3592
//AOJ036
#include <stdio.h>

int main(){
	int i,j,field[11][11],top = -1,left = -1;
	while(1){
		top = -1;
		for(i = 1;i <= 8;i++){
			for(j = 1;j <= 8;j++){
				if(scanf("%1d", &field[i][j]) == EOF) return 0;
				if(field[i][j] == 1 && top == -1){
					top = i;
					left = j;
				}
			}
		}
		if(field[top][left + 1] == 1){
			if(field[top + 1][left - 1] == 1) puts("G");
			else if(field[top][left + 2] == 1) puts("C");
			else if(field[top + 1][left] == 1) puts("A");
			else puts("E");
		}
		else{
			if(field[top + 1][left - 1] == 1) puts("D");
			else if(field[top + 1][left + 1] == 1) puts("F");
			else puts("B");
		}
	}
	return 0;
}

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

void printVector(vector<long long int> v) {
    for (auto x : v) {
        cout << x << ' ';
    }
    cout << '\n';
}

int main() {
    long long int n, m, k;
    cin >> n >> m >> k;
    vector<long long int> A, B;
    for (int i = 0; i <= n - 1; i++) {
        long long int a;
        cin >> a;
        A.push_back(a);
    }
    for (int i = 0; i <= m - 1; i++) {
        long long int a;
        cin >> a;
        B.push_back(a);
    }
    //printVector(A);
    //printVector(B);
    vector<long long int> A_Acc;
    vector<long long int> B_Acc;
    A_Acc.push_back(0);
    B_Acc.push_back(0);
    for (int i = 0; i <= n - 1; i++) {
        A_Acc.push_back(A_Acc[i] + A[i]);
    }
    for (int i = 0; i <= m - 1; i++) {
        B_Acc.push_back(B_Acc[i] + B[i]);
    }
    //printVector(A_Acc);
    //printVector(B_Acc);
    long long int j = m;
    long long int result = 0;
    for (int i = 0; i <= n; i++) {
        if (A_Acc[i] > k) break;
        while (A_Acc[i] + B_Acc[j] > k) {
            j--;
        }
        result = max(result, i + j);
    }
    cout << result << '\n';
    return 0;
}

Measured memory_bytes: 11100
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

bool check(string s){
	int f = 0, l = s.size()-1;
	bool is = true;
	while(f < l){
		if(s[f] == s[l]){
			f++; l--;
		}
		else{
			is = false;
			break;
		}
	}
	// cout << s << endl << is << endl;
	return is;
}

int main(){

	string s;
	cin >> s;
	int n = s.size();
	if(check(s) && check(s.substr(0, ((n-1)/2))) && check(s.substr((n+1)/2, (n-1)/2)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

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

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var N = input[0];
        var D = input[1];
        var D2 = D * D;

        var result = 0;
        for (int i = 0; i < N; i++)
        {
            var input2 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var X = input2[0];
            var Y = input2[1];
            if (X * X + Y * Y <= D2)
            {
                result++;
            }
        }
        Console.WriteLine(result);
    }
}


Measured memory_bytes: 41276
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;
    
    ll price;
    if(2*C>A+B) price=A*X+B*Y;
    else{
        if(X>Y){
            if(2*C>A)price=2*C*Y+A*(X-Y);
            else price=2*C*X;
        }else{
            if(2*C>B)price=2*C*X+B*(Y-X);
            else price=2*C*Y;
        }
    }
    printf("%lld\n",price);
    
    return 0;
}


Measured memory_bytes: 256
/*マージソート*/
#include <stdio.h>
#define N 1000000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);
int count=0;

int main(){
  int n, s[N], i, j;
  
  /*値の入力*/
  scanf("%d", &n);
  for (i=0; i<n; i++){
    scanf("%d", &s[i]);
  }
  
  mergeSort(s, 0, n);
  
  for (i=0; i<n-1; i++){
    printf("%d ", s[i]);
  }
  
  printf("%d\n", s[n-1]);
  
  printf("%d\n", count);
  
  return 0;
}

void merge(int *s, int left, int mid, int right){
  int n1, n2, i, j, k;
  int l[N], r[N];
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0; i<n1; i++){
    l[i] = s[left+i];
  }
  for(i=0; i<n2; i++){
    r[i] = s[mid+i];
  }
  
  l[n1] = 1000000000;
  r[n2] = 1000000000;
  
  i=0;
  j=0;
  
  for(k=left; k<right; k++){
    if (l[i] <= r[j]){
      s[k] = l[i];
      i++;
      count++;
    }
    else{
      s[k] = r[j];
      j++;
      count++;
    }
  }
}

void mergeSort(int *s, int left, int right){
  int mid;
  
  if (left+1 < right){
    mid = (left + right)/2;
    mergeSort(s, left, mid);
    mergeSort(s, mid, right);
    merge(s, left, mid, right);
  } 
  
}



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

int main(){
    int n;
    cin >> n;
    int y = n/15;
    cout << n*800 - y*200 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, P;
  cin >> N >> P;
  vector<int> a(N);
  int cnt0=0, cnt1=0;
  for(int i=0; i<N; i++){
    cin >> a.at(i);
    a.at(i) = a.at(i)%2;
    if(a.at(i) == 0){
      cnt0++;
    }else{
      cnt1++;
    }
  }
  //cout << cnt0 << endl << cnt1 << endl;
  long long int kotae = pow(2,cnt0)*pow(2,cnt1-1);
  if(P==0 && cnt1==0){kotae = pow(2,cnt0);}
  if(P==1 && cnt1==0){kotae=0;}
  cout << kotae << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
int n = 0;
std::vector<int> a;
int main(void){

    while(std::cin >> n, n != 0){
        a.resize(n);
        for(int i=0; i<n; ++i){
            std::cin >> a[i];
        }

        std::sort(a.begin(), a.end());

        int res = INT_MAX;
        for(int i=0; i<n-1; ++i){
            res = std::min(res, a[i+1]-a[i]);
        }
        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 3080
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
def rui(A):
    R=[A[0]]*len(A)
    for i in range(len(A)-1):
        R[i+1]=R[i]+A[i+1]
    return R
R=rui(A)
RR=rui(B)
ans=0
for i in range(n):
    tt=RR[i-1] if i!=0 else 0
    ans=max(ans,R[i]+ RR[-1]-tt)
print(ans)

Measured memory_bytes: 61896
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    char s;
    cin >> a >> b >> c;
    cout << ((((a-c)>=0&&(c-b)>=0)||((b-c)>=0&&(c-a)>0))?("Yes"):("No"));
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            n = int.Parse(Console.ReadLine());
            double a = n / 2 + 1;
            double b = n + 0;
            double c = n / 2;
            
            if (n % 2 == 1)
                Console.WriteLine(a / b);
            else
                Console.WriteLine(c / b);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
S = list(input())
ans = 0
for i in range(N):
  Sp = list(set(S[0 : i + 1]))
  Ss = list(set(S[i + 1 : N]))
  temp = 0
  for x in Sp:
    for y in Ss:
      if x == y:
        temp += 1
        break
  if temp > ans:
    ans = temp
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <climits>
#include <functional>
#define endl '\n'
#define ll long long

using namespace std;

int get(int n)
{
    int ret = 0;
    while(n > 1 && n % 2 == 0)
    {
        n /= 2;
        ret += 1;
    }
    return ret;
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    int ret = INT_MAX;
    for(int i = 0; i < N; i++)
    {
        int temp; cin >> temp;
        ret = min(ret, get(temp));
    }
    
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 384
using System;

class Tester
{
    static void Main(string[] args)
    {
        string x = Console.ReadLine();
        int a, b, c;
        string[] result;

        const char Space = ' ';
        char[] delimiters = new char[] { Space };
        result = x.Split(delimiters);

        a = int.Parse(result[0]);
        b = int.Parse(result[1]);
        c = int.Parse(result[2]);

        int[] src = { a, b, c };
        Array.Sort(src);

        string d = src[0].ToString();
        string e = src[1].ToString();
        string f = src[2].ToString();

        string[] result2 = { d, e, f };

        Console.WriteLine("{0}", string.Join(" ", result2));
    }
}


Measured memory_bytes: 9400
#include<stdio.h>
int main(){
  int i,j,o;
  char w[10001];
  while(scanf("%s",w)!=EOF){
    j=0;
    o=0;
    for(i=0;w[i+2];i++){
      if(w[i]=='J'&&w[i+1]=='O'&&w[i+2]=='I')j++;
      if(w[i]=='I'&&w[i+1]=='O'&&w[i+2]=='I')o++;
    }
    printf("%d\n%d\n",j,o);
  }
  return 0;
}

Measured memory_bytes: 552
package main

import "fmt"

func main() {
	// Code for A - Colorful Slimes 2
	var N int
	fmt.Scanf("%d", &N)

	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
	}

	var count int
	var ans int
	for i := 0; i < N-1; i++ {
		if a[i] == a[i+1] {
			count++
		} else {
			if count%2 != 0 {
				ans += (count + 1) / 2
			} else {
				ans += count / 2
			}
			count = 0
		}
	}

	if count != 0 {
		if count%2 != 0 {
			ans += (count + 1) / 2
		} else {
			ans += count / 2
		}
		count = 0
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1840
#include"bits/stdc++.h"

using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define PI 3.141592653589793
#define scanstr(s) cin>>ws; getline(cin,s);

int lcm( int a, int b )
{
	int g=__gcd(a,b) ;
	return (a/g)*b ;
}

int len(int a, int b, int d)
{
	int start=a/d;
	if(a%d) start++;
	int stop=b/d;
	return ( stop - start ) + 1 ;
}

void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a>b) swap(a,b);
	int m1 = len(a,b,c);
	int m2 = len(a,b,d);
	int l = lcm(c,d);
	int add = len(a,b,l);
	cout<< (b-a+1)-(m1+m2)+add <<nl;
	return ;
}

int32_t main()
{
	FastIO;
	solve();
	return 0;
}


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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    string s;
    cin >> s;
    string t;
    cin >> t;
    for (int i = 0; i < 26; i++) {
        if (t == s + (char)(i + 'a')) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[][] pr = new int[][]{
			new int[]{2,3,5},
			new int[]{2,3,7},
			new int[]{3,5,7},
			new int[]{2,3,11}
		};
		
		foreach(var ar in pr){
			int a = ar[0], b = ar[1], c = ar[2];
			List<long> l = new List<long>();
			for(long i=2;;i++){
				if(i % a == 0|| i % b == 0 || i % c == 0) l.Add(i);
				if(l.Count == N - 1) break;
			}
			
			var sum = l.Sum();
			for(long last = l[l.Count - 1] + 1;;last++){
				if(last > 30000) break;
				if((sum + last) % (a * b * c) == 0 && gcd(sum, last) != 1){l.Add(last); break;}
			}
			if(l.Count == N){
				Console.WriteLine(String.Join(" ",l));
				return;
			}
		}
	}
	
	int N;
	public Sol(){
		N = ri();
	}
	long gcd(long a, long b){
		if(a > b) return gcd(b , a);
		return a == 0 ? b : gcd(b % a, a);
	}
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 14432
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

//1-indexed
template<class T>
struct BinaryIndexedTree2D {
    int H,W;
    vector<vector<T>> bit;
    BinaryIndexedTree2D(int H = 0,int W = 0):H(H),W(W){
        bit.assign(H + 1,vector<T>(W + 1,0));
    }
    // add x to a[h][w]
    void add(int h,int w,T x) {
        for (int i = h; i <= H; i += (i & -i)) {
            for (int j = w; j <= W; j += (j & -j)) {
                bit[i][j] += x;
            }
        }
    }
    // return sum of a[i][j] s.t. (1 <= i <= h and 1 <= j <= w)
    T sum(int h,int w) {
        T ret = 0;
        for (int i = h; i > 0; i -= (i & -i)) {
            for (int j = w; j > 0; j -= (j & -j)) {
                ret += bit[i][j];
            }
        }
        return ret;
    }
    // return sum of a[i][j] s.t. (h1 <= i < h2 and w1 <= j < w2)
    T query(int h1,int h2,int w1,int w2) {
        return sum(h2 - 1,w2 - 1) - sum(h2 - 1,w1 - 1) - sum(h1 - 1,w2 - 1) + sum(h1 - 1,w1 - 1);
    }
};

int main() {
    int H,W,Q;
    ll T;
    cin >> H >> W >> T >> Q;
    BinaryIndexedTree2D<int> bit(H,W);
    BinaryIndexedTree2D<int> bit2(H,W);

    vector<ll> taiyaki;
    vector<P> pos;
    int l = 0;

    rep(i,Q) {
        ll t; 
        int c;
        cin >> t >> c;
        if (c == 0) {
            int h,w; cin >> h >> w;
            bit.add(h,w,1);
            taiyaki.push_back(t);
            pos.emplace_back(h,w);
        } else if (c == 1) {
            int h,w; cin >> h >> w;
            while (l < (int)taiyaki.size() && taiyaki[l] <= t - T) {
                bit2.add(pos[l].first,pos[l].second,1);
                bit.add(pos[l].first,pos[l].second,-1);
                ++l;
            }
            if (bit2.query(h,h + 1,w,w + 1) > 0) {
                bit2.add(h,w,-1);
            }
        } else {
            int h1,h2,w1,w2; cin >> h1 >> w1 >> h2 >> w2;
            while (l < (int)taiyaki.size() && taiyaki[l] <= t - T) {
                bit2.add(pos[l].first,pos[l].second,1);
                bit.add(pos[l].first,pos[l].second,-1);
                ++l;
            }
            int x = bit.query(h1,h2 + 1,w1,w2 + 1);
            int y = bit2.query(h1,h2 + 1,w1,w2 + 1);
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    string s, t; cin >> s >> t;
    int cnt = 0;
    int n = s.size();
    for(int i = 0; i < n; i++)cnt += (s[i] != t[i]);
    cout << cnt << endl;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    long long int a[3*N];
    for (int i = 0; i < 3*N; i++)
    {
        cin >> a[i];
    }
    sort(a, a + 3 * N);

    long long int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        ans += a[3*N-2*i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

// #define NMAX 1000000000
int N,M;
vi A;

ll solve(){
	ll ans = 0;
	rp(i,0,M){
		ans +=A[i];
	}
	ans = N - ans;

	return ans<0?-1:ans;
}

int main(){
	cin>>N>>M;
	A.resize(M);
	rp(i,0,M) cin>>A[i];
	cout<< solve() <<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<math.h>

#define MAXA 100003
#define MAX 2147483647

int a[MAXA], length[MAXA];

int b,n;
 
int min(int, int);
int max(int, int);
void update(int);



 
int main(){
 
    int i,j,x,y,z;
    int q, que; 
    
    scanf("%d %d",&n,&q);
    
    b = sqrt(n);
     
    for(i = 0;i < n;i ++)a[i]=MAX;
    for(i = 0;i < n;i ++)length[i]=-1;
     
    for(j = 0;j < q;j ++){
     
        scanf("%d",&que);

        if(que){
            scanf("%d",&x);
            if(length[x/b] != -1)update(x/b);
            printf("%d\n",a[x]);
        }
         
        else {
            scanf("%d %d %d",&x,&y,&z);
            
            if(length[x/b] != -1)update(x/b);
            for(i = x;i <= min(y,(x/b + 1) * b - 1);i ++)a[i] = z;
            for(i = x/b + 1;i < y/b;i ++)length[i] = z;
            if(length[y/b] != -1)update(y/b);
            for(i = max(x,y/b*b);i <= y;i ++)a[i] = z;
        }
         
    }
     
    return 0;
     
}

int min(int x,int y){
    if (x > y) return y;
    return x;   
}

int max(int x , int y){
    if (x > y) return x;
    return y;   
}


void update(int x){
    for(int i = x*b;i <= min(n-1,(x+1)*b-1);i ++)a[i] = length[x];
    length[x] = -1;
    return;
}




Measured memory_bytes: 2628
//
//AtCoder Beginner Contest 141
//D - Powerful Discount Tickets
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<ll> a(n);
    priority_queue<ll, vector<ll>, less<ll>> qa;
    REP(i, n) {
        cin >> a[i];
        qa.push(a[i]);
    }

    REP(i,m){
        ll tmp = qa.top()/2;
        qa.pop();
        qa.push(tmp);
    }

    ll ans = 0;
    while(!qa.empty()){
        ans+=qa.top();
        qa.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2168
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

typedef long long LL;

int n;

LL encode(const vector<char> &v){
	LL a = 0;
	for(int i = 0; i < n; ++i){
		a |= (LL)v[i] << (i << 2);
	}
	return a;
}

vector<char> decode(LL x){
	vector<char> v(n);
	for(int i = 0; i < n; ++i){
		v[i] = (x >> (i << 2)) & 15;
	}
	return v;
}

int main(){
	scanf("%d", &n);
	
	vector<char> s(n), goal(n);
	int x;
	for(int i = 0; i < n; ++i){
		scanf("%d", &x);
		s[i] = x;
		goal[i] = i + 1;
	}
	
	if( s == goal ){
		puts("0");
		return 0;
	}

	vector<LL> v1, v2;
	v1.push_back( encode(s) );
	v2.push_back( encode(goal) );
	
	set<LL> old;
	old.insert( v1[0] );
	old.insert( v2[0] );

	int a;
	for(int a = 1; ; ++a){
		vector<LL> tmp;
		
		for(int i = 0; i < v1.size(); ++i){
			s = decode( v1[i] );
			for(int j = 0; j < n - 1; ++j)
			for(int k = j + 2; k <= n; ++k){
				vector<char> t = s;
				reverse(t.begin() + j, t.begin() + k);
				LL u = encode(t);

				if( binary_search(v2.begin(), v2.end(), u) ){
					printf("%d\n", a);
					return 0;
				}
				
				if( old.find(u) == old.end() ){
					old.insert(u);
					tmp.push_back(u);
				}
			}
		}
		
		sort(tmp.begin(), tmp.end());
		v1.swap(tmp);
		
		v1.swap(v2);
	}
}

Measured memory_bytes: 28564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
vector<int> a;

ll solve() {
  int i, b;
  ll ans = 0;

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

  sort(a.begin(), a.end());

  if (n % 2 == 0) {
    b = (a[n / 2 - 1] + a[n / 2]) / 2;
  } else {
    b = a[(n - 1) / 2];
  }

  for (i = 0; i < n; i++) {
    ans += abs(a[i] - b);
  }

  return ans;
}

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

  cout << solve() << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


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

    char c = S[K - 1];
    rep(i, N) {
        if (S[i] != c)S[i] = '*';
    }

    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.2.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){  //  nCr (小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){  //  nCr (%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
int stpow(int n){  //  階乗(%MOD)
if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);  //  階乗配列(%MOD)
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  Vi a(n);
  Vin(a);
  
  Vi cost(n);
  cost[0] = 0;
  cost[1] = abs(a[0]-a[1]);
  
  rep(i,2,n){
    cost[i] = min(cost[i-1]+abs(a[i]-a[i-1]),cost[i-2]+abs(a[i]-a[i-2]));
  }
  //Verr(cost);
  cout << cost[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
  int W,H,x,y,r;

  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

  if(x>=-100 && x<=100 && y>=-100 && y<=100 && W>0 && W<=100 && H>0 && H<=100 && r>0 && r<=100){
    if(x-r<0 || y-r<0 || x+r>W || y+r>H)printf("No\n");
    else printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  static const double pi = 3.141592653589793;
  
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double k1, k2, sa;
  k1 = 30*H+30*M/60;
  k2 = 6*M;
  sa = max(k1, k2) - min(k1, k2);
  if(sa>180){
    sa = 360 - sa;
  }
  
  double ans;
  
  ans = sqrt(A*A + B*B - 2*A*B*cos(pi*sa/180));
  
  //cout << ans << endl;
  cout << fixed << setprecision(20) << ans << endl;
  
}

Measured memory_bytes: 4216
#include<iostream>
#include<cmath>

int main(){
  int n;
  double x1,y1,x2,y2,x3,y3,x4,y4;
  const double e = 1e-10;

  std::cin >> n;

  for(int i=0;i<n;i++){
    std::cin >> x1 >> y1
             >> x2 >> y2
             >> x3 >> y3
             >> x4 >> y4;

    if(std::fabs((x1*y3+x2*y4+y2*x3+y1*x4)-(x2*y3+x1*y4+y1*x3+y2*x4))<e){
      std::cout << "YES" << std::endl;
    }else{
      std::cout << "NO" << std::endl;
    }
  }
}

Measured memory_bytes: 3160
from itertools import combinations

def calc(y, z):
    s = 0
    for p, q in zip(y, z):
        s += (p - q)**2
    return s ** (1/2)

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

c = 0
for i in combinations(points, 2):
    d = calc(i[0], i[1])
    if d == int(d):
        c += 1
print(c)


Measured memory_bytes: 3188
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> A(N, 0);

	REP(_, N - 1)
	{
		int a;
		cin >> a;
		a--;
		A[a]++;
	}

	REP(i, N){
		cout << A[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3992
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

	int minb = 1987654321;
	i64 dfsum = 0;
	i64 bs = 0;

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

		if (b > a)
			dfsum += b - a;
		
		if (a > b)
			minb = min(minb, b);
	}

	if (dfsum == 0)
	{
		printf("0\n");
		return 0;
	}

	printf("%lld\n", bs - minb);

	return 0;
}

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

int main(){
  //入力
  int64_t N,M;
  cin>>N>>M;
  vector<int64_t> A(N);
  for(int i=0;i<N;++i){
    cin>>A.at(i);
  }

  sort(A.begin(),A.end());

  //S.at(i)はA.at(i-1)までの和
  vector<int64_t> S(N+1);
  S.at(0)=0;
  for(int i=1;i<=N;++i){
    S.at(i)=S.at(i-1)+A.at(i-1);
  }

  //二分探索で#{(x,y)|A[x]+A[y]>=X}>=MなるXの最大値を求める
  long long X;
  long long left,right;
  //leftはいつでも条件を満たし、rightは満たさない
  left=2;
  right=2*100010;
  while(right-left>1){
    int mid=(right+left)/2;
    //sum=#{(x,y)|A[x]+A[y]>=mid}を計算する
    long long sum=0;
    for(int i=0;i<N;++i){
      sum += A.end()-lower_bound(A.begin(),A.end(),mid-A.at(i));
    }
    //sumが条件を満たすならleft、満たさないならrightにする
    if(sum>=M){
      left=mid;
    }
    else{
      right=mid;
    }

    //最後ならXを求める
    if(right-left==1){
    X=left;
    }
  }

  //求める答えはX*(M-#{(x,y)|A[x]+A[y]>=X+1})と{(x,y)|A[x]+A[y]>=X+1}を渡るΣ(A[x]+A[y])の和
  int64_t ans=0;
  int64_t count=0;
  for(int i=0;i<N;++i){
    int64_t index=A.end()-lower_bound(A.begin(),A.end(),(X+1)-A.at(i));
    ans += index*A.at(i)+(S.at(N)-S.at(N-index));
    count += index;
  }
  ans += X*(M-count);

  //出力
  cout<<ans<<endl;
}

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

auto prime_factorize(int64_t N)
{
  vector<pair<int64_t, int64_t>> res;
  for (int64_t a = 2; a * a <= N; a++)
  {
    if (N % a != 0)
      continue;
    int64_t ex = 0;
    while (N % a == 0)
    {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main()
{
  int64_t N, ans = 0;
  cin >> N;
  const auto res = prime_factorize(N);
  for (auto p : res)
  {
    int64_t n, x;
    tie(n, x) = p;
    for (int i = 1; i < 100; i++)
    {
      if (x < (i * (i + 1) / 2))
      {
        ans += (i - 1);
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
/**
 *      purpose : ABC 99 C
 *      author  : kyomukyomupurin
 *      created : 2019-01-27 15:00:21
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, c; cin >> n >> c;
    int64 D[40][40] = {};
    int64 C[510][510] = {};

    rep(i, c){
        rep(j, c) cin >> D[i][j];
    }

    rep(i, n){
        rep(j, n) cin >> C[i][j];
    }

    int64 sum0[40] = {}, sum1[40] = {}, sum2[40] = {};

    for (int i = 1; i <= c; ++i){
        for (int j = 0; j < n; ++j){
            for (int k = 0; k < n; ++k){
                if ((j + k) % 3 == 0){
                    sum0[i] += D[C[j][k] - 1][i - 1];
                }
                else if ((j + k) % 3 == 1){
                    sum1[i] += D[C[j][k] - 1][i - 1];
                }
                else if ((j + k) % 3 == 2){
                    sum2[i] += D[C[j][k] - 1][i - 1];
                }
            }
        }
    }

    int64 ans = 1e17;

    for (int i = 1; i <= c; ++i){
        for (int j = 1; j <= c; ++j){
            for (int k = 1; k <= c; ++k){
                if (i != j && j != k && k != i){
                    ans = min(ans, sum0[i] + sum1[j] + sum2[k]);
                }
            }
        }
    }

    print(ans);
    
    return 0;
}


Measured memory_bytes: 2304
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = {}
for i in range(N):
    a = A[i]
    if a not in B:
        B[a] = 0
    B[a] += 1
B = list(B.items())
B = sorted(B,key= lambda x:x[1],reverse=True)
cnt = 0
for i in range(K,len(B)):
    cnt += B[i][1]
print(cnt)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005
vi a,b,c;
ll x,y,cc,sum=0;
ll solve(ll x)
{
	ll sum1=0,sum2=0;
	for(ll i=0;i<x;i++)
	{
		sum1+=a[i];
	}
	for(ll i=0,j=cc-1;i<x;i++,j--)
		sum2+=c[j];
	// cout<<x<<" "<<sum1<<" "<<sum2<<endl;
	ll ans=sum+sum2-sum1;
	return ans;
}

ll ts(ll l,ll r)
{
	if(r-l<=2)
	{
		ll mid=(l+r)/2;
		if(solve(mid)>=solve(r)&&solve(mid)>=solve(l))
			return mid;
		if(solve(l)>=solve(r)&&solve(l)>=solve(mid))
			return l;
		return r;
	}
	ll x=(r-l)/3;
	ll mid1=l+x;
	ll mid2=r-x;
	ll v1=solve(mid1);
	ll v2=solve(mid2);
	if(v1>=v2)
		return ts(l,mid2);
	return ts(mid1,r);
}

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	ll aa,bb;
    	vi aaa,bbb;
    	cin>>x>>y>>aa>>bb>>cc;
    	for(i=0;i<aa;i++)
    	{
    		cin>>l;
    		aaa.pb(l);
    	}
    	for(i=0;i<bb;i++)
    	{
    		cin>>l;
    		bbb.pb(l);
    	}
    	sort(all(aaa));sort(all(bbb));
    	reverse(all(aaa));reverse(all(bbb));
    	for(i=0;i<x;i++)
    		a.pb(aaa[i]);
    	for(i=0;i<y;i++)
    		a.pb(bbb[i]);
    	for(i=0;i<cc;i++)
    	{
    		cin>>l;
    		c.pb(l);
    	}
    	for(auto i:a)
    		sum+=i;
    	sort(all(c));
    	sort(all(a));
    	ll ans=ts(0,min(x+y,cc));
    	// cout<<ans<<endl;
    	cout<<solve(ans);
    }
    return 0;
}

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

int main() {
  int N,A,count,C = 100000000;
  cin >> N;
  for (int i = 0;i < N; i++) {
    count = 0;
    cin >> A;
    while ((A % 2) == 0){
    A /= 2;
    count ++;
    }
    if (count <= C) C = count;
  }
  cout << C << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

ll pows[405][405];
ll powsPrefixSum[405][405];
// powsPrefixSum[x][y] is sum of x^y, fixing y
const int MOD = 1000000007;
ll ret[405][405];
int a[405];
int b[405];

void initPows() {
  for(int x = 1; x <= 400; x++) {
    pows[x][0] = 1;
    for(int y = 1; y <= 400; y++) {
      pows[x][y] = (pows[x][y-1] * x) % MOD;
    }
  }
  for(int y = 0; y <= 400; y++) {
    for(int x = 1; x <= 401; x++) {
      powsPrefixSum[x+1][y] = powsPrefixSum[x][y] + pows[x][y];
      powsPrefixSum[x+1][y] %= MOD;
    }
  }
}

int main() {
  initPows();
  int n, c;
  scanf("%d%d", &n, &c);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for(int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  ret[0][0] = 1;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= c; j++) {
      for(int k = 0; j + k <= c; k++) {
        ll temp = powsPrefixSum[b[i] + 1][k];
        temp -= powsPrefixSum[a[i]][k];
        if(temp < 0) temp += MOD;
        ret[i+1][j+k] += ret[i][j] * temp;
        ret[i+1][j+k] %= MOD;
      }
    }
  }
  printf("%lld\n", ret[n][c]);
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int N;
    cin >> N;
    vector<Pii> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i].first >> a[i].second;
    }

    int cnt = 0;
    for (ll i = 0; i < N; i++) {
        auto [x, y] = a[i];
        if (x == y) {
            ++cnt;
        }
        else {
            cnt = 0;
        }
        if (cnt >= 3) {
            prints()("Yes");
            return;
        }
    }
    prints()("No");
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

Measured memory_bytes: 3660